Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: Source/core/page/WindowFeatures.cpp

Issue 879913003: Use IntRect instead of FloatRect for window positions and sizes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: added FIXME comments Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2000 Harri Porten (porten@kde.org) 2 * Copyright (C) 2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2006 Jon Shier (jshier@iastate.edu) 3 * Copyright (C) 2006 Jon Shier (jshier@iastate.edu)
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights resev ed. 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights resev ed.
5 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
11 * 11 *
12 * This library is distributed in the hope that it will be useful, 12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details. 15 * Lesser General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU Lesser General Public 17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software 18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
20 * USA 20 * USA
21 */ 21 */
22 22
23 #include "config.h" 23 #include "config.h"
24 #include "core/page/WindowFeatures.h" 24 #include "core/page/WindowFeatures.h"
25 25
26 #include "platform/geometry/FloatRect.h" 26 #include "platform/geometry/IntRect.h"
27 #include "wtf/Assertions.h" 27 #include "wtf/Assertions.h"
28 #include "wtf/MathExtras.h" 28 #include "wtf/MathExtras.h"
29 #include "wtf/text/StringHash.h" 29 #include "wtf/text/StringHash.h"
30 30
31 namespace blink { 31 namespace blink {
32 32
33 // Though isspace() considers \t and \v to be whitespace, Win IE doesn't when pa rsing window features. 33 // Though isspace() considers \t and \v to be whitespace, Win IE doesn't when pa rsing window features.
34 static bool isWindowFeaturesSeparator(UChar c) 34 static bool isWindowFeaturesSeparator(UChar c)
35 { 35 {
36 return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '=' || c == ' ,' || c == '\0'; 36 return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '=' || c == ' ,' || c == '\0';
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 else if (keyString == "status") 158 else if (keyString == "status")
159 statusBarVisible = value; 159 statusBarVisible = value;
160 else if (keyString == "fullscreen") 160 else if (keyString == "fullscreen")
161 fullscreen = value; 161 fullscreen = value;
162 else if (keyString == "scrollbars") 162 else if (keyString == "scrollbars")
163 scrollbarsVisible = value; 163 scrollbarsVisible = value;
164 else if (value == 1) 164 else if (value == 1)
165 additionalFeatures.append(keyString); 165 additionalFeatures.append(keyString);
166 } 166 }
167 167
168 WindowFeatures::WindowFeatures(const String& dialogFeaturesString, const FloatRe ct& screenAvailableRect) 168 WindowFeatures::WindowFeatures(const String& dialogFeaturesString, const IntRect & screenAvailableRect)
169 : widthSet(true) 169 : widthSet(true)
170 , heightSet(true) 170 , heightSet(true)
171 , menuBarVisible(false) 171 , menuBarVisible(false)
172 , toolBarVisible(false) 172 , toolBarVisible(false)
173 , locationBarVisible(false) 173 , locationBarVisible(false)
174 , fullscreen(false) 174 , fullscreen(false)
175 , dialog(true) 175 , dialog(true)
176 { 176 {
177 DialogFeaturesMap features; 177 DialogFeaturesMap features;
178 parseDialogFeatures(dialogFeaturesString, features); 178 parseDialogFeatures(dialogFeaturesString, features);
179 179
180 const bool trusted = false; 180 const bool trusted = false;
181 181
182 // The following features from Microsoft's documentation are not implemented : 182 // The following features from Microsoft's documentation are not implemented :
183 // - default font settings 183 // - default font settings
184 // - width, height, left, and top specified in units other than "px" 184 // - width, height, left, and top specified in units other than "px"
185 // - edge (sunken or raised, default is raised) 185 // - edge (sunken or raised, default is raised)
186 // - dialogHide: trusted && boolFeature(features, "dialoghide"), makes dialo g hide when you print 186 // - dialogHide: trusted && boolFeature(features, "dialoghide"), makes dialo g hide when you print
187 // - help: boolFeature(features, "help", true), makes help icon appear in di alog (what does it do on Windows?) 187 // - help: boolFeature(features, "help", true), makes help icon appear in di alog (what does it do on Windows?)
188 // - unadorned: trusted && boolFeature(features, "unadorned"); 188 // - unadorned: trusted && boolFeature(features, "unadorned");
189 189
190 width = floatFeature(features, "dialogwidth", 100, screenAvailableRect.width (), 620); // default here came from frame size of dialog in MacIE 190 width = intFeature(features, "dialogwidth", 100, screenAvailableRect.width() , 620); // default here came from frame size of dialog in MacIE
191 height = floatFeature(features, "dialogheight", 100, screenAvailableRect.hei ght(), 450); // default here came from frame size of dialog in MacIE 191 height = intFeature(features, "dialogheight", 100, screenAvailableRect.heigh t(), 450); // default here came from frame size of dialog in MacIE
192 192
193 x = floatFeature(features, "dialogleft", screenAvailableRect.x(), screenAvai lableRect.maxX() - width, -1); 193 x = intFeature(features, "dialogleft", screenAvailableRect.x(), screenAvaila bleRect.maxX() - width, -1);
194 xSet = x > 0; 194 xSet = x > 0;
195 y = floatFeature(features, "dialogtop", screenAvailableRect.y(), screenAvail ableRect.maxY() - height, -1); 195 y = intFeature(features, "dialogtop", screenAvailableRect.y(), screenAvailab leRect.maxY() - height, -1);
196 ySet = y > 0; 196 ySet = y > 0;
197 197
198 if (boolFeature(features, "center", true)) { 198 if (boolFeature(features, "center", true)) {
199 if (!xSet) { 199 if (!xSet) {
200 x = screenAvailableRect.x() + (screenAvailableRect.width() - width) / 2; 200 x = screenAvailableRect.x() + (screenAvailableRect.width() - width) / 2;
201 xSet = true; 201 xSet = true;
202 } 202 }
203 if (!ySet) { 203 if (!ySet) {
204 y = screenAvailableRect.y() + (screenAvailableRect.height() - height ) / 2; 204 y = screenAvailableRect.y() + (screenAvailableRect.height() - height ) / 2;
205 ySet = true; 205 ySet = true;
206 } 206 }
207 } 207 }
208 208
209 resizable = boolFeature(features, "resizable"); 209 resizable = boolFeature(features, "resizable");
210 scrollbarsVisible = boolFeature(features, "scroll", true); 210 scrollbarsVisible = boolFeature(features, "scroll", true);
211 statusBarVisible = boolFeature(features, "status", !trusted); 211 statusBarVisible = boolFeature(features, "status", !trusted);
212 } 212 }
213 213
214 bool WindowFeatures::boolFeature(const DialogFeaturesMap& features, const char* key, bool defaultValue) 214 bool WindowFeatures::boolFeature(const DialogFeaturesMap& features, const char* key, bool defaultValue)
215 { 215 {
216 DialogFeaturesMap::const_iterator it = features.find(key); 216 DialogFeaturesMap::const_iterator it = features.find(key);
217 if (it == features.end()) 217 if (it == features.end())
218 return defaultValue; 218 return defaultValue;
219 const String& value = it->value; 219 const String& value = it->value;
220 return value.isNull() || value == "1" || value == "yes" || value == "on"; 220 return value.isNull() || value == "1" || value == "yes" || value == "on";
221 } 221 }
222 222
223 float WindowFeatures::floatFeature(const DialogFeaturesMap& features, const char * key, float min, float max, float defaultValue) 223 int WindowFeatures::intFeature(const DialogFeaturesMap& features, const char* ke y, int min, int max, int defaultValue)
224 { 224 {
225 DialogFeaturesMap::const_iterator it = features.find(key); 225 DialogFeaturesMap::const_iterator it = features.find(key);
226 if (it == features.end()) 226 if (it == features.end())
227 return defaultValue; 227 return defaultValue;
228 // FIXME: The toDouble function does not offer a way to tell "0q" from strin g with no digits in it: Both
229 // return the number 0 and false for ok. But "0q" should yield the minimum r ather than the default.
230 bool ok; 228 bool ok;
231 double parsedNumber = it->value.toDouble(&ok); 229 int parsedNumber = it->value.toInt(&ok);
232 if ((!parsedNumber && !ok) || std::isnan(parsedNumber)) 230 if (!ok)
233 return defaultValue; 231 return defaultValue;
234 if (parsedNumber < min || max <= min) 232 if (parsedNumber < min || max <= min)
235 return min; 233 return min;
236 if (parsedNumber > max) 234 if (parsedNumber > max)
237 return max; 235 return max;
238 // FIXME: Seems strange to cast a double to int and then convert back to a f loat. Why is this a good idea? 236 return parsedNumber;
239 return static_cast<int>(parsedNumber);
240 } 237 }
241 238
242 void WindowFeatures::parseDialogFeatures(const String& string, DialogFeaturesMap & map) 239 void WindowFeatures::parseDialogFeatures(const String& string, DialogFeaturesMap & map)
243 { 240 {
244 Vector<String> vector; 241 Vector<String> vector;
245 string.split(';', vector); 242 string.split(';', vector);
246 size_t size = vector.size(); 243 size_t size = vector.size();
247 for (size_t i = 0; i < size; ++i) { 244 for (size_t i = 0; i < size; ++i) {
248 const String& featureString = vector[i]; 245 const String& featureString = vector[i];
249 246
(...skipping 11 matching lines...) Expand all
261 if (separatorPosition != kNotFound) { 258 if (separatorPosition != kNotFound) {
262 value = featureString.substring(separatorPosition + 1).stripWhiteSpa ce().lower(); 259 value = featureString.substring(separatorPosition + 1).stripWhiteSpa ce().lower();
263 value = value.left(value.find(' ')); 260 value = value.left(value.find(' '));
264 } 261 }
265 262
266 map.set(key, value); 263 map.set(key, value);
267 } 264 }
268 } 265 }
269 266
270 } // namespace blink 267 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/page/WindowFeatures.h ('k') | Source/modules/screen_orientation/ScreenOrientationController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698