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

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

Issue 2905283003: Remove a bunch of dead code around WindowFeatures (Closed)
Patch Set: Add missing #include Created 3 years, 6 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 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights
5 * reseved. 5 * reseved.
6 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 6 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 28 matching lines...) Expand all
39 39
40 WindowFeatures::WindowFeatures(const String& features) 40 WindowFeatures::WindowFeatures(const String& features)
41 : x(0), 41 : x(0),
42 x_set(false), 42 x_set(false),
43 y(0), 43 y(0),
44 y_set(false), 44 y_set(false),
45 width(0), 45 width(0),
46 width_set(false), 46 width_set(false),
47 height(0), 47 height(0),
48 height_set(false), 48 height_set(false),
49 resizable(true), 49 noopener(false),
50 fullscreen(false), 50 background(false),
51 dialog(false), 51 persistent(false) {
52 noopener(false) { 52 // The IE rule is: all features except for channelmode default
53 /* 53 // to YES, but if the user specifies a feature string, all features default to
54 The IE rule is: all features except for channelmode and fullscreen default 54 // NO. (There is no public standard that applies to this method.)
Nate Chapin 2017/05/31 16:55:13 I guess there is a spec for this now, kind of. The
55 to YES, but if the user specifies a feature string, all features default to 55 // <http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/open_0.a sp>
56 NO. (There is no public standard that applies to this method.)
57
58 <http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/open_0.a sp>
59 We always allow a window to be resized, which is consistent with Firefox.
60 */
61
62 if (features.IsEmpty()) { 56 if (features.IsEmpty()) {
63 menu_bar_visible = true; 57 menu_bar_visible = true;
64 status_bar_visible = true; 58 status_bar_visible = true;
65 tool_bar_visible = true; 59 tool_bar_visible = true;
66 location_bar_visible = true;
67 scrollbars_visible = true; 60 scrollbars_visible = true;
68 return; 61 return;
69 } 62 }
70 63
71 menu_bar_visible = false; 64 menu_bar_visible = false;
72 status_bar_visible = false; 65 status_bar_visible = false;
73 tool_bar_visible = false; 66 tool_bar_visible = false;
74 location_bar_visible = false;
75 scrollbars_visible = false; 67 scrollbars_visible = false;
76 68
77 // Tread lightly in this code -- it was specifically designed to mimic Win 69 // Tread lightly in this code -- it was specifically designed to mimic Win
78 // IE's parsing behavior. 70 // IE's parsing behavior.
79 unsigned key_begin, key_end; 71 unsigned key_begin, key_end;
80 unsigned value_begin, value_end; 72 unsigned value_begin, value_end;
81 73
82 String buffer = features.DeprecatedLower(); 74 String buffer = features.DeprecatedLower();
83 unsigned length = buffer.length(); 75 unsigned length = buffer.length();
84 for (unsigned i = 0; i < length;) { 76 for (unsigned i = 0; i < length;) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 void WindowFeatures::SetWindowFeature(const String& key_string, 123 void WindowFeatures::SetWindowFeature(const String& key_string,
132 const String& value_string) { 124 const String& value_string) {
133 int value; 125 int value;
134 126
135 // Listing a key with no value is shorthand for key=yes 127 // Listing a key with no value is shorthand for key=yes
136 if (value_string.IsEmpty() || value_string == "yes") 128 if (value_string.IsEmpty() || value_string == "yes")
137 value = 1; 129 value = 1;
138 else 130 else
139 value = value_string.ToInt(); 131 value = value_string.ToInt();
140 132
141 // We treat keyString of "resizable" here as an additional feature rather than
142 // setting resizeable to true. This is consistent with Firefox, but could
143 // also be handled at another level.
144
145 if (key_string == "left" || key_string == "screenx") { 133 if (key_string == "left" || key_string == "screenx") {
146 x_set = true; 134 x_set = true;
147 x = value; 135 x = value;
148 } else if (key_string == "top" || key_string == "screeny") { 136 } else if (key_string == "top" || key_string == "screeny") {
149 y_set = true; 137 y_set = true;
150 y = value; 138 y = value;
151 } else if (key_string == "width" || key_string == "innerwidth") { 139 } else if (key_string == "width" || key_string == "innerwidth") {
152 width_set = true; 140 width_set = true;
153 width = value; 141 width = value;
154 } else if (key_string == "height" || key_string == "innerheight") { 142 } else if (key_string == "height" || key_string == "innerheight") {
155 height_set = true; 143 height_set = true;
156 height = value; 144 height = value;
157 } else if (key_string == "menubar") { 145 } else if (key_string == "menubar") {
158 menu_bar_visible = value; 146 menu_bar_visible = value;
159 } else if (key_string == "toolbar") { 147 } else if (key_string == "toolbar" || key_string == "location") {
160 tool_bar_visible = value; 148 tool_bar_visible |= static_cast<bool>(value);
161 } else if (key_string == "location") {
162 location_bar_visible = value;
163 } else if (key_string == "status") { 149 } else if (key_string == "status") {
164 status_bar_visible = value; 150 status_bar_visible = value;
165 } else if (key_string == "fullscreen") {
166 fullscreen = value;
167 } else if (key_string == "scrollbars") { 151 } else if (key_string == "scrollbars") {
168 scrollbars_visible = value; 152 scrollbars_visible = value;
169 } else if (key_string == "noopener") { 153 } else if (key_string == "noopener") {
170 noopener = true; 154 noopener = true;
171 } else if (value == 1) { 155 } else if (key_string == "background") {
172 additional_features.push_back(key_string); 156 background = true;
157 } else if (key_string == "persistent") {
158 persistent = true;
173 } 159 }
174 } 160 }
175 161
176 WindowFeatures::WindowFeatures(const String& dialog_features_string,
177 const IntRect& screen_available_rect)
178 : width_set(true),
179 height_set(true),
180 menu_bar_visible(false),
181 tool_bar_visible(false),
182 location_bar_visible(false),
183 fullscreen(false),
184 dialog(true),
185 noopener(false) {
186 DialogFeaturesMap features;
187 ParseDialogFeatures(dialog_features_string, features);
188
189 const bool kTrusted = false;
190
191 // The following features from Microsoft's documentation are not implemented:
192 // - default font settings
193 // - width, height, left, and top specified in units other than "px"
194 // - edge (sunken or raised, default is raised)
195 // - dialogHide: trusted && boolFeature(features, "dialoghide"), makes dialog
196 // hide when you print
197 // - help: boolFeature(features, "help", true), makes help icon appear in
198 // dialog (what does it do on Windows?)
199 // - unadorned: trusted && boolFeature(features, "unadorned");
200
201 // default here came from frame size of dialog in MacIE
202 width = IntFeature(features, "dialogwidth", 100,
203 screen_available_rect.Width(), 620);
204 // default here came from frame size of dialog in MacIE
205 height = IntFeature(features, "dialogheight", 100,
206 screen_available_rect.Height(), 450);
207
208 x = IntFeature(features, "dialogleft", screen_available_rect.X(),
209 screen_available_rect.MaxX() - width, -1);
210 x_set = x > 0;
211 y = IntFeature(features, "dialogtop", screen_available_rect.Y(),
212 screen_available_rect.MaxY() - height, -1);
213 y_set = y > 0;
214
215 if (BoolFeature(features, "center", true)) {
216 if (!x_set) {
217 x = screen_available_rect.X() +
218 (screen_available_rect.Width() - width) / 2;
219 x_set = true;
220 }
221 if (!y_set) {
222 y = screen_available_rect.Y() +
223 (screen_available_rect.Height() - height) / 2;
224 y_set = true;
225 }
226 }
227
228 resizable = BoolFeature(features, "resizable");
229 scrollbars_visible = BoolFeature(features, "scroll", true);
230 status_bar_visible = BoolFeature(features, "status", !kTrusted);
231 }
232
233 bool WindowFeatures::BoolFeature(const DialogFeaturesMap& features,
234 const char* key,
235 bool default_value) {
236 DialogFeaturesMap::const_iterator it = features.find(key);
237 if (it == features.end())
238 return default_value;
239 const String& value = it->value;
240 return value.IsNull() || value == "1" || value == "yes" || value == "on";
241 }
242
243 int WindowFeatures::IntFeature(const DialogFeaturesMap& features,
244 const char* key,
245 int min,
246 int max,
247 int default_value) {
248 DialogFeaturesMap::const_iterator it = features.find(key);
249 if (it == features.end())
250 return default_value;
251 bool ok;
252 int parsed_number = it->value.ToInt(&ok);
253 if (!ok)
254 return default_value;
255 if (parsed_number < min || max <= min)
256 return min;
257 if (parsed_number > max)
258 return max;
259 return parsed_number;
260 }
261
262 void WindowFeatures::ParseDialogFeatures(const String& string,
263 DialogFeaturesMap& map) {
264 Vector<String> vector;
265 string.Split(';', vector);
266 size_t size = vector.size();
267 for (size_t i = 0; i < size; ++i) {
268 const String& feature_string = vector[i];
269
270 size_t separator_position = feature_string.find('=');
271 size_t colon_position = feature_string.find(':');
272 if (separator_position != kNotFound && colon_position != kNotFound)
273 continue; // ignore strings that have both = and :
274 if (separator_position == kNotFound)
275 separator_position = colon_position;
276
277 String key = feature_string.Left(separator_position)
278 .StripWhiteSpace()
279 .DeprecatedLower();
280
281 // Null string for value indicates key without value.
282 String value;
283 if (separator_position != kNotFound) {
284 value = feature_string.Substring(separator_position + 1)
285 .StripWhiteSpace()
286 .DeprecatedLower();
287 value = value.Left(value.find(' '));
288 }
289
290 map.Set(key, value);
291 }
292 }
293
294 } // namespace blink 162 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698