3
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
*
|
|
5 |
* This program is free software: you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU Lesser General Public License as published by
|
|
7 |
* the Free Software Foundation, version 2.1 of the License.
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU Lesser General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU Lesser General Public License
|
|
15 |
* along with this program. If not,
|
|
16 |
* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
|
|
17 |
*
|
|
18 |
* Description:
|
|
19 |
*
|
|
20 |
*/
|
|
21 |
|
|
22 |
#include "ViewportMetaDataParser.h"
|
|
23 |
|
|
24 |
namespace GVA {
|
|
25 |
|
|
26 |
ViewportMetaDataParser::ViewportMetaDataParser(const QRect& clientRect)
|
|
27 |
: m_clientRect(clientRect)
|
|
28 |
{}
|
|
29 |
|
|
30 |
ViewportMetaDataParser::~ViewportMetaDataParser()
|
|
31 |
{}
|
|
32 |
|
16
|
33 |
void ViewportMetaDataParser::parse(const QString& viewportParams, ViewportMetaData& viewportMetaData)
|
3
|
34 |
{
|
16
|
35 |
processArguments(viewportParams, viewportMetaData);
|
|
36 |
//viewportMetaData.adjustViewportData(m_clientRect);
|
|
37 |
return;
|
3
|
38 |
}
|
|
39 |
|
|
40 |
|
|
41 |
//W A R N I N G
|
|
42 |
//FOLLOWING CODE HAS BEEN TAKEN FROM WebCore/dom/Document.cpp
|
|
43 |
//NEED TO REMOVE WHEN QtWebkit provides viewport param API
|
|
44 |
|
|
45 |
// Though isspace() considers \t and \v to be whitespace, Win IE doesn't.
|
|
46 |
bool ViewportMetaDataParser::isSeparator(QChar c)
|
|
47 |
{
|
|
48 |
return c == ' '
|
|
49 |
|| c == '\t'
|
|
50 |
|| c == '\n'
|
|
51 |
|| c == '\r'
|
|
52 |
|| c == '='
|
|
53 |
|| c == ','
|
|
54 |
|| c == '\0'
|
|
55 |
|| c == ';';
|
|
56 |
}
|
|
57 |
|
16
|
58 |
void ViewportMetaDataParser::processArguments(const QString& features, ViewportMetaData& viewportMetaData)
|
3
|
59 |
{
|
|
60 |
int keyBegin, keyEnd;
|
|
61 |
int valueBegin, valueEnd;
|
|
62 |
int i = 0;
|
|
63 |
int length = features.length();
|
|
64 |
QString buffer = features.toLower();
|
|
65 |
|
|
66 |
while (i < length) {
|
|
67 |
// skip to first non-separator, but don't skip past the end of the string
|
|
68 |
while (isSeparator(buffer[i])) {
|
|
69 |
if (i >= length)
|
|
70 |
break;
|
|
71 |
i++;
|
|
72 |
}
|
|
73 |
keyBegin = i;
|
|
74 |
|
|
75 |
// skip to first separator
|
|
76 |
while (!isSeparator(buffer[i]))
|
|
77 |
i++;
|
|
78 |
keyEnd = i;
|
|
79 |
|
|
80 |
// skip to first '=', but don't skip past a ',' or the end of the string
|
|
81 |
while (buffer[i] != '=') {
|
|
82 |
if (buffer[i] == ',' || i >= length)
|
|
83 |
break;
|
|
84 |
i++;
|
|
85 |
}
|
|
86 |
// skip to first non-separator, but don't skip past a ',' or the end of the string
|
|
87 |
while (isSeparator(buffer[i])) {
|
|
88 |
if (buffer[i] == ',' || i >= length)
|
|
89 |
break;
|
|
90 |
i++;
|
|
91 |
}
|
|
92 |
valueBegin = i;
|
|
93 |
|
|
94 |
// skip to first separator
|
|
95 |
while (!isSeparator(buffer[i]))
|
|
96 |
i++;
|
|
97 |
valueEnd = i;
|
|
98 |
|
|
99 |
Q_ASSERT(i <= length);
|
|
100 |
|
|
101 |
QString keyString = buffer.mid(keyBegin, keyEnd - keyBegin);
|
|
102 |
QString valueString = buffer.mid(valueBegin, valueEnd - valueBegin);
|
|
103 |
setViewportFeature(keyString, valueString, viewportMetaData);
|
|
104 |
}
|
16
|
105 |
#ifdef VIEWPORT_ALWAYS_ALLOW_ZOOMING
|
|
106 |
// Hacks to always allow zooming. !!!
|
|
107 |
if(viewportMetaData.m_minimumScale == viewportMetaData.m_maximumScale) {
|
|
108 |
viewportMetaData.m_minimumScale = 0.2;
|
|
109 |
viewportMetaData.m_maximumScale = 5.0;
|
|
110 |
viewportMetaData.m_userScalable = true;
|
|
111 |
viewportMetaData.m_userScalableOverRidden = true;
|
|
112 |
}
|
|
113 |
#endif
|
|
114 |
return;
|
3
|
115 |
}
|
|
116 |
|
|
117 |
void ViewportMetaDataParser::setViewportFeature(const QString& keyString, const QString& valueString, ViewportMetaData& viewportMetaData)
|
|
118 |
{
|
|
119 |
float value = ViewportMetaData::ValueUndefined;
|
|
120 |
|
|
121 |
if (QString::compare(valueString, "device-width", Qt::CaseInsensitive) == 0)
|
|
122 |
value = m_clientRect.width();
|
|
123 |
else if (QString::compare(valueString, "device-height", Qt::CaseInsensitive) == 0)
|
|
124 |
value = m_clientRect.height();
|
|
125 |
else if (QString::compare(valueString, "default", Qt::CaseInsensitive) == 0) {
|
|
126 |
// This allows us to distinguish the omission of a key from asking for the default value.
|
|
127 |
value = -2;
|
|
128 |
}
|
|
129 |
else if (valueString.length()) {
|
|
130 |
// listing a key with no value is shorthand for key=default
|
|
131 |
value = valueString.toDouble();
|
|
132 |
}
|
|
133 |
|
|
134 |
if (keyString == "initial-scale") {
|
|
135 |
viewportMetaData.m_initialScale = value;
|
|
136 |
viewportMetaData.setFlag(ViewportMetaData::UserDefinedInitialScale,true);
|
|
137 |
}
|
|
138 |
else if (keyString == "minimum-scale") {
|
|
139 |
viewportMetaData.m_minimumScale = value;
|
|
140 |
viewportMetaData.m_specifiedData.m_minScale = value;
|
|
141 |
viewportMetaData.setFlag(ViewportMetaData::UserDefinedMinumumScale,true);
|
|
142 |
}
|
|
143 |
else if (keyString == "maximum-scale") {
|
|
144 |
viewportMetaData.m_maximumScale = value;
|
|
145 |
viewportMetaData.setFlag(ViewportMetaData::UserDefinedMaximumScale,true);
|
|
146 |
}
|
|
147 |
else if (keyString == "user-scalable") {
|
|
148 |
if (QString::compare(valueString, "yes", Qt::CaseInsensitive) == 0)
|
|
149 |
viewportMetaData.m_userScalable = true;
|
16
|
150 |
else {
|
|
151 |
#ifdef VIEWPORT_ALWAYS_ALLOW_ZOOMING
|
|
152 |
viewportMetaData.m_userScalable = true;
|
|
153 |
viewportMetaData.m_userScalableOverRidden = true;
|
|
154 |
#else
|
3
|
155 |
viewportMetaData.m_userScalable = false;
|
16
|
156 |
#endif
|
|
157 |
}
|
3
|
158 |
}
|
|
159 |
else if (keyString == "width") {
|
|
160 |
viewportMetaData.m_width = value;
|
|
161 |
viewportMetaData.m_specifiedData.m_width = valueString;
|
|
162 |
}
|
|
163 |
else if (keyString == "height") {
|
|
164 |
viewportMetaData.m_height = value;
|
|
165 |
viewportMetaData.m_specifiedData.m_height = valueString;
|
|
166 |
}
|
|
167 |
}
|
|
168 |
|
|
169 |
} //namespace GVA
|