OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. |
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 #include "core/page/WindowFocusAllowedIndicator.h" | 94 #include "core/page/WindowFocusAllowedIndicator.h" |
95 #include "core/page/scrolling/ScrollingCoordinator.h" | 95 #include "core/page/scrolling/ScrollingCoordinator.h" |
96 #include "core/storage/Storage.h" | 96 #include "core/storage/Storage.h" |
97 #include "core/storage/StorageArea.h" | 97 #include "core/storage/StorageArea.h" |
98 #include "core/storage/StorageNamespace.h" | 98 #include "core/storage/StorageNamespace.h" |
99 #include "core/timing/Performance.h" | 99 #include "core/timing/Performance.h" |
100 #include "platform/EventDispatchForbiddenScope.h" | 100 #include "platform/EventDispatchForbiddenScope.h" |
101 #include "platform/PlatformScreen.h" | 101 #include "platform/PlatformScreen.h" |
102 #include "platform/RuntimeEnabledFeatures.h" | 102 #include "platform/RuntimeEnabledFeatures.h" |
103 #include "platform/UserGestureIndicator.h" | 103 #include "platform/UserGestureIndicator.h" |
104 #include "platform/geometry/FloatRect.h" | 104 #include "platform/geometry/IntRect.h" |
105 #include "platform/weborigin/KURL.h" | 105 #include "platform/weborigin/KURL.h" |
106 #include "platform/weborigin/SecurityOrigin.h" | 106 #include "platform/weborigin/SecurityOrigin.h" |
107 #include "platform/weborigin/SecurityPolicy.h" | 107 #include "platform/weborigin/SecurityPolicy.h" |
108 #include "public/platform/Platform.h" | 108 #include "public/platform/Platform.h" |
109 #include "wtf/MainThread.h" | 109 #include "wtf/MainThread.h" |
110 #include "wtf/MathExtras.h" | 110 #include "wtf/MathExtras.h" |
111 #include "wtf/text/WTFString.h" | 111 #include "wtf/text/WTFString.h" |
112 #include <algorithm> | 112 #include <algorithm> |
113 | 113 |
114 using std::min; | 114 using std::min; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 return false; | 320 return false; |
321 return frame->isMainFrame(); | 321 return frame->isMainFrame(); |
322 } | 322 } |
323 | 323 |
324 unsigned LocalDOMWindow::pendingUnloadEventListeners() const | 324 unsigned LocalDOMWindow::pendingUnloadEventListeners() const |
325 { | 325 { |
326 return windowsWithUnloadEventListeners().count(const_cast<LocalDOMWindow*>(t
his)); | 326 return windowsWithUnloadEventListeners().count(const_cast<LocalDOMWindow*>(t
his)); |
327 } | 327 } |
328 | 328 |
329 // This function: | 329 // This function: |
330 // 1) Validates the pending changes are not changing any value to NaN; in that c
ase keep original value. | 330 // 1) Constrains the window rect to the minimum window size and no bigger than t
he int rect's dimensions. |
331 // 2) Constrains the window rect to the minimum window size and no bigger than t
he float rect's dimensions. | 331 // 2) Constrains the window rect to within the top and left boundaries of the av
ailable screen rect. |
332 // 3) Constrains the window rect to within the top and left boundaries of the av
ailable screen rect. | 332 // 3) Constrains the window rect to within the bottom and right boundaries of th
e available screen rect. |
333 // 4) Constrains the window rect to within the bottom and right boundaries of th
e available screen rect. | 333 // 4) Translate the window rect coordinates to be within the coordinate space of
the screen. |
334 // 5) Translate the window rect coordinates to be within the coordinate space of
the screen. | 334 IntRect LocalDOMWindow::adjustWindowRect(LocalFrame& frame, const IntRect& pendi
ngChanges) |
335 FloatRect LocalDOMWindow::adjustWindowRect(LocalFrame& frame, const FloatRect& p
endingChanges) | |
336 { | 335 { |
337 FrameHost* host = frame.host(); | 336 FrameHost* host = frame.host(); |
338 ASSERT(host); | 337 ASSERT(host); |
339 | 338 |
340 FloatRect screen = screenAvailableRect(frame.view()); | 339 IntRect screen = screenAvailableRect(frame.view()); |
341 FloatRect window = host->chrome().windowRect(); | 340 IntRect window = pendingChanges; |
342 | 341 |
343 // Make sure we're in a valid state before adjusting dimensions. | 342 IntSize minimumSize = host->chrome().client().minimumWindowSize(); |
344 ASSERT(std::isfinite(screen.x())); | |
345 ASSERT(std::isfinite(screen.y())); | |
346 ASSERT(std::isfinite(screen.width())); | |
347 ASSERT(std::isfinite(screen.height())); | |
348 ASSERT(std::isfinite(window.x())); | |
349 ASSERT(std::isfinite(window.y())); | |
350 ASSERT(std::isfinite(window.width())); | |
351 ASSERT(std::isfinite(window.height())); | |
352 | |
353 // Update window values if new requested values are not NaN. | |
354 if (!std::isnan(pendingChanges.x())) | |
355 window.setX(pendingChanges.x()); | |
356 if (!std::isnan(pendingChanges.y())) | |
357 window.setY(pendingChanges.y()); | |
358 if (!std::isnan(pendingChanges.width())) | |
359 window.setWidth(pendingChanges.width()); | |
360 if (!std::isnan(pendingChanges.height())) | |
361 window.setHeight(pendingChanges.height()); | |
362 | |
363 FloatSize minimumSize = host->chrome().client().minimumWindowSize(); | |
364 // Let size 0 pass through, since that indicates default size, not minimum s
ize. | 343 // Let size 0 pass through, since that indicates default size, not minimum s
ize. |
365 if (window.width()) | 344 if (window.width()) |
366 window.setWidth(min(max(minimumSize.width(), window.width()), screen.wid
th())); | 345 window.setWidth(min(max(minimumSize.width(), window.width()), screen.wid
th())); |
367 if (window.height()) | 346 if (window.height()) |
368 window.setHeight(min(max(minimumSize.height(), window.height()), screen.
height())); | 347 window.setHeight(min(max(minimumSize.height(), window.height()), screen.
height())); |
369 | 348 |
370 // Constrain the window position within the valid screen area. | 349 // Constrain the window position within the valid screen area. |
371 window.setX(max(screen.x(), min(window.x(), screen.maxX() - window.width()))
); | 350 window.setX(max(screen.x(), min(window.x(), screen.maxX() - window.width()))
); |
372 window.setY(max(screen.y(), min(window.y(), screen.maxY() - window.height())
)); | 351 window.setY(max(screen.y(), min(window.y(), screen.maxY() - window.height())
)); |
373 | 352 |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 { | 1042 { |
1064 if (!frame()) | 1043 if (!frame()) |
1065 return 0; | 1044 return 0; |
1066 | 1045 |
1067 FrameHost* host = frame()->host(); | 1046 FrameHost* host = frame()->host(); |
1068 if (!host) | 1047 if (!host) |
1069 return 0; | 1048 return 0; |
1070 | 1049 |
1071 if (host->settings().reportScreenSizeInPhysicalPixelsQuirk()) | 1050 if (host->settings().reportScreenSizeInPhysicalPixelsQuirk()) |
1072 return lroundf(host->chrome().windowRect().height() * host->deviceScaleF
actor()); | 1051 return lroundf(host->chrome().windowRect().height() * host->deviceScaleF
actor()); |
1073 return static_cast<int>(host->chrome().windowRect().height()); | 1052 return host->chrome().windowRect().height(); |
1074 } | 1053 } |
1075 | 1054 |
1076 int LocalDOMWindow::outerWidth() const | 1055 int LocalDOMWindow::outerWidth() const |
1077 { | 1056 { |
1078 if (!frame()) | 1057 if (!frame()) |
1079 return 0; | 1058 return 0; |
1080 | 1059 |
1081 FrameHost* host = frame()->host(); | 1060 FrameHost* host = frame()->host(); |
1082 if (!host) | 1061 if (!host) |
1083 return 0; | 1062 return 0; |
1084 | 1063 |
1085 if (host->settings().reportScreenSizeInPhysicalPixelsQuirk()) | 1064 if (host->settings().reportScreenSizeInPhysicalPixelsQuirk()) |
1086 return lroundf(host->chrome().windowRect().width() * host->deviceScaleFa
ctor()); | 1065 return lroundf(host->chrome().windowRect().width() * host->deviceScaleFa
ctor()); |
1087 return static_cast<int>(host->chrome().windowRect().width()); | 1066 return host->chrome().windowRect().width(); |
1088 } | 1067 } |
1089 | 1068 |
1090 int LocalDOMWindow::innerHeight() const | 1069 int LocalDOMWindow::innerHeight() const |
1091 { | 1070 { |
1092 if (!frame()) | 1071 if (!frame()) |
1093 return 0; | 1072 return 0; |
1094 | 1073 |
1095 FrameView* view = frame()->view(); | 1074 FrameView* view = frame()->view(); |
1096 if (!view) | 1075 if (!view) |
1097 return 0; | 1076 return 0; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 { | 1122 { |
1144 if (!frame()) | 1123 if (!frame()) |
1145 return 0; | 1124 return 0; |
1146 | 1125 |
1147 FrameHost* host = frame()->host(); | 1126 FrameHost* host = frame()->host(); |
1148 if (!host) | 1127 if (!host) |
1149 return 0; | 1128 return 0; |
1150 | 1129 |
1151 if (host->settings().reportScreenSizeInPhysicalPixelsQuirk()) | 1130 if (host->settings().reportScreenSizeInPhysicalPixelsQuirk()) |
1152 return lroundf(host->chrome().windowRect().x() * host->deviceScaleFactor
()); | 1131 return lroundf(host->chrome().windowRect().x() * host->deviceScaleFactor
()); |
1153 return static_cast<int>(host->chrome().windowRect().x()); | 1132 return host->chrome().windowRect().x(); |
1154 } | 1133 } |
1155 | 1134 |
1156 int LocalDOMWindow::screenY() const | 1135 int LocalDOMWindow::screenY() const |
1157 { | 1136 { |
1158 if (!frame()) | 1137 if (!frame()) |
1159 return 0; | 1138 return 0; |
1160 | 1139 |
1161 FrameHost* host = frame()->host(); | 1140 FrameHost* host = frame()->host(); |
1162 if (!host) | 1141 if (!host) |
1163 return 0; | 1142 return 0; |
1164 | 1143 |
1165 if (host->settings().reportScreenSizeInPhysicalPixelsQuirk()) | 1144 if (host->settings().reportScreenSizeInPhysicalPixelsQuirk()) |
1166 return lroundf(host->chrome().windowRect().y() * host->deviceScaleFactor
()); | 1145 return lroundf(host->chrome().windowRect().y() * host->deviceScaleFactor
()); |
1167 return static_cast<int>(host->chrome().windowRect().y()); | 1146 return host->chrome().windowRect().y(); |
1168 } | 1147 } |
1169 | 1148 |
1170 double LocalDOMWindow::scrollX() const | 1149 double LocalDOMWindow::scrollX() const |
1171 { | 1150 { |
1172 if (!frame()) | 1151 if (!frame()) |
1173 return 0; | 1152 return 0; |
1174 | 1153 |
1175 FrameView* view = frame()->view(); | 1154 FrameView* view = frame()->view(); |
1176 if (!view) | 1155 if (!view) |
1177 return 0; | 1156 return 0; |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 if (std::isnan(scrollToOptions.top())) | 1392 if (std::isnan(scrollToOptions.top())) |
1414 return; | 1393 return; |
1415 scaledY = scrollToOptions.top() * frame()->pageZoomFactor(); | 1394 scaledY = scrollToOptions.top() * frame()->pageZoomFactor(); |
1416 } | 1395 } |
1417 | 1396 |
1418 ScrollBehavior scrollBehavior = ScrollBehaviorAuto; | 1397 ScrollBehavior scrollBehavior = ScrollBehaviorAuto; |
1419 ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(), scrollB
ehavior); | 1398 ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(), scrollB
ehavior); |
1420 scrollViewportTo(frame(), DoublePoint(scaledX, scaledY), scrollBehavior); | 1399 scrollViewportTo(frame(), DoublePoint(scaledX, scaledY), scrollBehavior); |
1421 } | 1400 } |
1422 | 1401 |
1423 void LocalDOMWindow::moveBy(float x, float y) const | 1402 void LocalDOMWindow::moveBy(int x, int y) const |
1424 { | 1403 { |
1425 if (!frame() || !frame()->isMainFrame()) | 1404 if (!frame() || !frame()->isMainFrame()) |
1426 return; | 1405 return; |
1427 | 1406 |
1428 FrameHost* host = frame()->host(); | 1407 FrameHost* host = frame()->host(); |
1429 if (!host) | 1408 if (!host) |
1430 return; | 1409 return; |
1431 | 1410 |
1432 FloatRect windowRect = host->chrome().windowRect(); | 1411 IntRect windowRect = host->chrome().windowRect(); |
1433 windowRect.move(x, y); | 1412 windowRect.move(x, y); |
1434 // Security check (the spec talks about UniversalBrowserWrite to disable thi
s check...) | 1413 // Security check (the spec talks about UniversalBrowserWrite to disable thi
s check...) |
1435 host->chrome().setWindowRect(adjustWindowRect(*frame(), windowRect)); | 1414 host->chrome().setWindowRect(adjustWindowRect(*frame(), windowRect)); |
1436 } | 1415 } |
1437 | 1416 |
1438 void LocalDOMWindow::moveTo(float x, float y) const | 1417 void LocalDOMWindow::moveTo(int x, int y, bool hasX, bool hasY) const |
1439 { | 1418 { |
1440 if (!frame() || !frame()->isMainFrame()) | 1419 if (!frame() || !frame()->isMainFrame()) |
1441 return; | 1420 return; |
1442 | 1421 |
1443 FrameHost* host = frame()->host(); | 1422 FrameHost* host = frame()->host(); |
1444 if (!host) | 1423 if (!host) |
1445 return; | 1424 return; |
1446 | 1425 |
1447 FloatRect windowRect = host->chrome().windowRect(); | 1426 IntRect windowRect = host->chrome().windowRect(); |
1448 windowRect.setLocation(FloatPoint(x, y)); | 1427 windowRect.setLocation(IntPoint(hasX ? x : windowRect.x(), hasY ? y : window
Rect.y())); |
1449 // Security check (the spec talks about UniversalBrowserWrite to disable thi
s check...) | 1428 // Security check (the spec talks about UniversalBrowserWrite to disable thi
s check...) |
1450 host->chrome().setWindowRect(adjustWindowRect(*frame(), windowRect)); | 1429 host->chrome().setWindowRect(adjustWindowRect(*frame(), windowRect)); |
1451 } | 1430 } |
1452 | 1431 |
1453 void LocalDOMWindow::resizeBy(float x, float y) const | 1432 void LocalDOMWindow::resizeBy(int x, int y) const |
1454 { | 1433 { |
1455 if (!frame() || !frame()->isMainFrame()) | 1434 if (!frame() || !frame()->isMainFrame()) |
1456 return; | 1435 return; |
1457 | 1436 |
1458 FrameHost* host = frame()->host(); | 1437 FrameHost* host = frame()->host(); |
1459 if (!host) | 1438 if (!host) |
1460 return; | 1439 return; |
1461 | 1440 |
1462 FloatRect fr = host->chrome().windowRect(); | 1441 IntRect fr = host->chrome().windowRect(); |
1463 FloatSize dest = fr.size() + FloatSize(x, y); | 1442 IntSize dest = fr.size() + IntSize(x, y); |
1464 FloatRect update(fr.location(), dest); | 1443 IntRect update(fr.location(), dest); |
1465 host->chrome().setWindowRect(adjustWindowRect(*frame(), update)); | 1444 host->chrome().setWindowRect(adjustWindowRect(*frame(), update)); |
1466 } | 1445 } |
1467 | 1446 |
1468 void LocalDOMWindow::resizeTo(float width, float height) const | 1447 void LocalDOMWindow::resizeTo(int width, int height, bool hasWidth, bool hasHeig
ht) const |
1469 { | 1448 { |
1470 if (!frame() || !frame()->isMainFrame()) | 1449 if (!frame() || !frame()->isMainFrame()) |
1471 return; | 1450 return; |
1472 | 1451 |
1473 FrameHost* host = frame()->host(); | 1452 FrameHost* host = frame()->host(); |
1474 if (!host) | 1453 if (!host) |
1475 return; | 1454 return; |
1476 | 1455 |
1477 FloatRect fr = host->chrome().windowRect(); | 1456 IntRect fr = host->chrome().windowRect(); |
1478 FloatSize dest = FloatSize(width, height); | 1457 IntSize dest = IntSize(hasWidth ? width : fr.width(), hasHeight ? height : f
r.height()); |
1479 FloatRect update(fr.location(), dest); | 1458 IntRect update(fr.location(), dest); |
1480 host->chrome().setWindowRect(adjustWindowRect(*frame(), update)); | 1459 host->chrome().setWindowRect(adjustWindowRect(*frame(), update)); |
1481 } | 1460 } |
1482 | 1461 |
1483 int LocalDOMWindow::requestAnimationFrame(RequestAnimationFrameCallback* callbac
k) | 1462 int LocalDOMWindow::requestAnimationFrame(RequestAnimationFrameCallback* callbac
k) |
1484 { | 1463 { |
1485 callback->m_useLegacyTimeBase = false; | 1464 callback->m_useLegacyTimeBase = false; |
1486 if (Document* d = document()) | 1465 if (Document* d = document()) |
1487 return d->requestAnimationFrame(callback); | 1466 return d->requestAnimationFrame(callback); |
1488 return 0; | 1467 return 0; |
1489 } | 1468 } |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1852 return m_frameObserver->frame(); | 1831 return m_frameObserver->frame(); |
1853 } | 1832 } |
1854 | 1833 |
1855 v8::Handle<v8::Object> LocalDOMWindow::wrap(v8::Handle<v8::Object> creationConte
xt, v8::Isolate* isolate) | 1834 v8::Handle<v8::Object> LocalDOMWindow::wrap(v8::Handle<v8::Object> creationConte
xt, v8::Isolate* isolate) |
1856 { | 1835 { |
1857 ASSERT_NOT_REACHED(); // LocalDOMWindow has [Custom=ToV8]. | 1836 ASSERT_NOT_REACHED(); // LocalDOMWindow has [Custom=ToV8]. |
1858 return v8::Handle<v8::Object>(); | 1837 return v8::Handle<v8::Object>(); |
1859 } | 1838 } |
1860 | 1839 |
1861 } // namespace blink | 1840 } // namespace blink |
OLD | NEW |