-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathwebenginesettings.cpp
134 lines (106 loc) · 5.09 KB
/
webenginesettings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/****************************************************************************
**
** Copyright (C) 2016 Jolla Ltd.
** Contact: Raine Makelainen <[email protected]>
**
****************************************************************************/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "webenginesettings.h"
#include <silicatheme.h>
#include <QtCore/QLocale>
#include <QtCore/QSettings>
#include <QtCore/QSize>
#include <QtCore/QtMath>
#include <QtGui/QGuiApplication>
#include <QtGui/QScreen>
Q_GLOBAL_STATIC(SailfishOS::WebEngineSettings, webEngineSettingsInstance)
#define SAILFISH_WEBENGINE_DEFAULT_PIXEL_RATIO 1.5
static bool testScreenDimensions(qreal pixelRatio)
{
QScreen *screen = QGuiApplication::primaryScreen();
qreal w = screen->size().width() / pixelRatio;
qreal h = screen->size().height() / pixelRatio;
return fmod(w, 1.0) == 0 && fmod(h, 1.0) == 0;
}
const QSettings &quickSettings()
{
static const QSettings settings(QSettings::SystemScope, QStringLiteral("QtProject"), QStringLiteral("QtQuick2"));
return settings;
}
int getPressAndHoldDelay()
{
return quickSettings().value(QStringLiteral("QuickMouseArea/PressAndHoldDelay"), 800).toInt();
}
const int PressAndHoldDelay(getPressAndHoldDelay());
void SailfishOS::WebEngineSettings::initialize()
{
static bool isInitialized = false;
if (isInitialized) {
return;
}
SailfishOS::WebEngineSettings *engineSettings = instance();
// Standard settings.
engineSettings->setPreference(QStringLiteral("embedlite.azpc.handle.singletap"), QVariant::fromValue<bool>(false));
engineSettings->setPreference(QStringLiteral("embedlite.azpc.json.singletap"), QVariant::fromValue<bool>(true));
engineSettings->setPreference(QStringLiteral("embedlite.azpc.handle.longtap"), QVariant::fromValue<bool>(false));
engineSettings->setPreference(QStringLiteral("embedlite.azpc.json.longtap"), QVariant::fromValue<bool>(true));
engineSettings->setPreference(QStringLiteral("embedlite.azpc.json.viewport"), QVariant::fromValue<bool>(true));
engineSettings->setPreference(QStringLiteral("apz.asyncscroll.throttle"), QVariant::fromValue<int>(15));
engineSettings->setPreference(QStringLiteral("apz.asyncscroll.timeout"), QVariant::fromValue<int>(15));
engineSettings->setPreference(QStringLiteral("apz.fling_stopped_threshold"), QLatin1String("0.13f"));
// Theme settings.
engineSettings->setPreference(QStringLiteral("ui.textSelectBackground"), QLatin1String("#878787"));
// Make long press timeout equal to the one in Qt
engineSettings->setPreference(QStringLiteral("ui.click_hold_context_menus.delay"), QVariant(PressAndHoldDelay));
Silica::Theme *silicaTheme = Silica::Theme::instance();
qreal pixelRatio = SAILFISH_WEBENGINE_DEFAULT_PIXEL_RATIO * silicaTheme->pixelRatio();
// Round to nearest even rounding factor
pixelRatio = qRound(pixelRatio / 0.5) * 0.5;
// If we're on hdpi and calcaluted pixel ratio doesn't result integer dimensions, let's try to floor it.
if (pixelRatio >= 2.0 && !testScreenDimensions(pixelRatio)) {
qreal tempPixelRatio = qFloor(pixelRatio);
if (testScreenDimensions(tempPixelRatio)) {
pixelRatio = tempPixelRatio;
}
}
engineSettings->setPixelRatio(pixelRatio);
int screenWidth = QGuiApplication::primaryScreen()->size().width();
int tileSize = screenWidth;
// With bigger than qHD screen fill with two tiles in row (portrait).
// Landscape will be filled with same tile size.
if (screenWidth > 540) {
tileSize = screenWidth / 2;
}
engineSettings->setTileSize(QSize(tileSize, tileSize));
// Zooming related preferences.
engineSettings->setPreference(QStringLiteral("embedlite.zoomMargin"),
QVariant::fromValue<qreal>(silicaTheme->paddingMedium()));
engineSettings->setPreference(QStringLiteral("embedlite.inputItemSize"),
QVariant::fromValue<qreal>(silicaTheme->fontSizeSmall()));
// Infer and set Accept-Language header from the current system locale
QString langs;
QStringList locale = QLocale::system().name().split("_", QString::SkipEmptyParts);
if (locale.size() > 1) {
langs = QString("%1-%2,%3").arg(locale.at(0)).arg(locale.at(1)).arg(locale.at(0));
} else {
langs = locale.at(0);
}
engineSettings->setPreference(QStringLiteral("intl.accept_languages"),
QVariant::fromValue<QString>(langs));
engineSettings->setPreference(QStringLiteral("browser.enable_automatic_image_resizing"),
QVariant::fromValue<bool>(true));
isInitialized = true;
}
SailfishOS::WebEngineSettings *SailfishOS::WebEngineSettings::instance()
{
return webEngineSettingsInstance();
}
SailfishOS::WebEngineSettings::WebEngineSettings(QObject *parent)
: QMozEngineSettings(parent)
{
}
SailfishOS::WebEngineSettings::~WebEngineSettings()
{
}