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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 #include "core/page/Chrome.h" | 64 #include "core/page/Chrome.h" |
65 #include "core/page/ChromeClient.h" | 65 #include "core/page/ChromeClient.h" |
66 #include "core/page/CreateWindow.h" | 66 #include "core/page/CreateWindow.h" |
67 #include "core/page/EventHandler.h" | 67 #include "core/page/EventHandler.h" |
68 #include "core/page/Page.h" | 68 #include "core/page/Page.h" |
69 #include "core/page/WindowFeatures.h" | 69 #include "core/page/WindowFeatures.h" |
70 #include "core/page/scrolling/ScrollingCoordinator.h" | 70 #include "core/page/scrolling/ScrollingCoordinator.h" |
71 #include "platform/EventDispatchForbiddenScope.h" | 71 #include "platform/EventDispatchForbiddenScope.h" |
72 #include "platform/PlatformScreen.h" | 72 #include "platform/PlatformScreen.h" |
73 #include "public/platform/Platform.h" | 73 #include "public/platform/Platform.h" |
74 #include <algorithm> | |
75 | |
76 using std::min; | |
77 using std::max; | |
78 | 74 |
79 namespace blink { | 75 namespace blink { |
80 | 76 |
81 LocalDOMWindow::WindowFrameObserver::WindowFrameObserver(LocalDOMWindow* window,
LocalFrame& frame) | 77 LocalDOMWindow::WindowFrameObserver::WindowFrameObserver(LocalDOMWindow* window,
LocalFrame& frame) |
82 : LocalFrameLifecycleObserver(&frame) | 78 : LocalFrameLifecycleObserver(&frame) |
83 , m_window(window) | 79 , m_window(window) |
84 { | 80 { |
85 } | 81 } |
86 | 82 |
87 PassOwnPtrWillBeRawPtr<LocalDOMWindow::WindowFrameObserver> LocalDOMWindow::Wind
owFrameObserver::create(LocalDOMWindow* window, LocalFrame& frame) | 83 PassOwnPtrWillBeRawPtr<LocalDOMWindow::WindowFrameObserver> LocalDOMWindow::Wind
owFrameObserver::create(LocalDOMWindow* window, LocalFrame& frame) |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 if (!frame) | 242 if (!frame) |
247 return false; | 243 return false; |
248 return frame->isMainFrame(); | 244 return frame->isMainFrame(); |
249 } | 245 } |
250 | 246 |
251 unsigned LocalDOMWindow::pendingUnloadEventListeners() const | 247 unsigned LocalDOMWindow::pendingUnloadEventListeners() const |
252 { | 248 { |
253 return windowsWithUnloadEventListeners().count(const_cast<LocalDOMWindow*>(t
his)); | 249 return windowsWithUnloadEventListeners().count(const_cast<LocalDOMWindow*>(t
his)); |
254 } | 250 } |
255 | 251 |
256 // This function: | |
257 // 1) Constrains the window rect to the minimum window size and no bigger than t
he int rect's dimensions. | |
258 // 2) Constrains the window rect to within the top and left boundaries of the av
ailable screen rect. | |
259 // 3) Constrains the window rect to within the bottom and right boundaries of th
e available screen rect. | |
260 // 4) Translate the window rect coordinates to be within the coordinate space of
the screen. | |
261 IntRect LocalDOMWindow::adjustWindowRect(LocalFrame& frame, const IntRect& pendi
ngChanges) | |
262 { | |
263 FrameHost* host = frame.host(); | |
264 ASSERT(host); | |
265 | |
266 IntRect screen = screenAvailableRect(frame.view()); | |
267 IntRect window = pendingChanges; | |
268 | |
269 IntSize minimumSize = host->chrome().client().minimumWindowSize(); | |
270 // Let size 0 pass through, since that indicates default size, not minimum s
ize. | |
271 if (window.width()) | |
272 window.setWidth(min(max(minimumSize.width(), window.width()), screen.wid
th())); | |
273 if (window.height()) | |
274 window.setHeight(min(max(minimumSize.height(), window.height()), screen.
height())); | |
275 | |
276 // Constrain the window position within the valid screen area. | |
277 window.setX(max(screen.x(), min(window.x(), screen.maxX() - window.width()))
); | |
278 window.setY(max(screen.y(), min(window.y(), screen.maxY() - window.height())
)); | |
279 | |
280 return window; | |
281 } | |
282 | |
283 bool LocalDOMWindow::allowPopUp(LocalFrame& firstFrame) | 252 bool LocalDOMWindow::allowPopUp(LocalFrame& firstFrame) |
284 { | 253 { |
285 if (UserGestureIndicator::processingUserGesture()) | 254 if (UserGestureIndicator::processingUserGesture()) |
286 return true; | 255 return true; |
287 | 256 |
288 Settings* settings = firstFrame.settings(); | 257 Settings* settings = firstFrame.settings(); |
289 return settings && settings->javaScriptCanOpenWindowsAutomatically(); | 258 return settings && settings->javaScriptCanOpenWindowsAutomatically(); |
290 } | 259 } |
291 | 260 |
292 bool LocalDOMWindow::allowPopUp() | 261 bool LocalDOMWindow::allowPopUp() |
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1283 if (!frame() || !frame()->isMainFrame()) | 1252 if (!frame() || !frame()->isMainFrame()) |
1284 return; | 1253 return; |
1285 | 1254 |
1286 FrameHost* host = frame()->host(); | 1255 FrameHost* host = frame()->host(); |
1287 if (!host) | 1256 if (!host) |
1288 return; | 1257 return; |
1289 | 1258 |
1290 IntRect windowRect = host->chrome().windowRect(); | 1259 IntRect windowRect = host->chrome().windowRect(); |
1291 windowRect.move(x, y); | 1260 windowRect.move(x, y); |
1292 // Security check (the spec talks about UniversalBrowserWrite to disable thi
s check...) | 1261 // Security check (the spec talks about UniversalBrowserWrite to disable thi
s check...) |
1293 host->chrome().setWindowRect(adjustWindowRect(*frame(), windowRect)); | 1262 host->chrome().setWindowRect(windowRect); |
1294 } | 1263 } |
1295 | 1264 |
1296 void LocalDOMWindow::moveTo(int x, int y, bool hasX, bool hasY) const | 1265 void LocalDOMWindow::moveTo(int x, int y, bool hasX, bool hasY) const |
1297 { | 1266 { |
1298 if (!hasX || !hasY) | 1267 if (!hasX || !hasY) |
1299 UseCounter::count(document(), UseCounter::WindowMoveResizeMissingArgumen
ts); | 1268 UseCounter::count(document(), UseCounter::WindowMoveResizeMissingArgumen
ts); |
1300 | 1269 |
1301 if (!frame() || !frame()->isMainFrame()) | 1270 if (!frame() || !frame()->isMainFrame()) |
1302 return; | 1271 return; |
1303 | 1272 |
1304 FrameHost* host = frame()->host(); | 1273 FrameHost* host = frame()->host(); |
1305 if (!host) | 1274 if (!host) |
1306 return; | 1275 return; |
1307 | 1276 |
1308 IntRect windowRect = host->chrome().windowRect(); | 1277 IntRect windowRect = host->chrome().windowRect(); |
1309 windowRect.setLocation(IntPoint(hasX ? x : windowRect.x(), hasY ? y : window
Rect.y())); | 1278 windowRect.setLocation(IntPoint(hasX ? x : windowRect.x(), hasY ? y : window
Rect.y())); |
1310 // Security check (the spec talks about UniversalBrowserWrite to disable thi
s check...) | 1279 // Security check (the spec talks about UniversalBrowserWrite to disable thi
s check...) |
1311 host->chrome().setWindowRect(adjustWindowRect(*frame(), windowRect)); | 1280 host->chrome().setWindowRect(windowRect); |
1312 } | 1281 } |
1313 | 1282 |
1314 void LocalDOMWindow::resizeBy(int x, int y, bool hasX, bool hasY) const | 1283 void LocalDOMWindow::resizeBy(int x, int y, bool hasX, bool hasY) const |
1315 { | 1284 { |
1316 if (!hasX || !hasY) | 1285 if (!hasX || !hasY) |
1317 UseCounter::count(document(), UseCounter::WindowMoveResizeMissingArgumen
ts); | 1286 UseCounter::count(document(), UseCounter::WindowMoveResizeMissingArgumen
ts); |
1318 | 1287 |
1319 if (!frame() || !frame()->isMainFrame()) | 1288 if (!frame() || !frame()->isMainFrame()) |
1320 return; | 1289 return; |
1321 | 1290 |
1322 FrameHost* host = frame()->host(); | 1291 FrameHost* host = frame()->host(); |
1323 if (!host) | 1292 if (!host) |
1324 return; | 1293 return; |
1325 | 1294 |
1326 IntRect fr = host->chrome().windowRect(); | 1295 IntRect fr = host->chrome().windowRect(); |
1327 IntSize dest = fr.size() + IntSize(x, y); | 1296 IntSize dest = fr.size() + IntSize(x, y); |
1328 IntRect update(fr.location(), dest); | 1297 IntRect update(fr.location(), dest); |
1329 host->chrome().setWindowRect(adjustWindowRect(*frame(), update)); | 1298 host->chrome().setWindowRect(update); |
1330 } | 1299 } |
1331 | 1300 |
1332 void LocalDOMWindow::resizeTo(int width, int height, bool hasWidth, bool hasHeig
ht) const | 1301 void LocalDOMWindow::resizeTo(int width, int height, bool hasWidth, bool hasHeig
ht) const |
1333 { | 1302 { |
1334 if (!hasWidth || !hasHeight) | 1303 if (!hasWidth || !hasHeight) |
1335 UseCounter::count(document(), UseCounter::WindowMoveResizeMissingArgumen
ts); | 1304 UseCounter::count(document(), UseCounter::WindowMoveResizeMissingArgumen
ts); |
1336 | 1305 |
1337 if (!frame() || !frame()->isMainFrame()) | 1306 if (!frame() || !frame()->isMainFrame()) |
1338 return; | 1307 return; |
1339 | 1308 |
1340 FrameHost* host = frame()->host(); | 1309 FrameHost* host = frame()->host(); |
1341 if (!host) | 1310 if (!host) |
1342 return; | 1311 return; |
1343 | 1312 |
1344 IntRect fr = host->chrome().windowRect(); | 1313 IntRect fr = host->chrome().windowRect(); |
1345 IntSize dest = IntSize(hasWidth ? width : fr.width(), hasHeight ? height : f
r.height()); | 1314 IntSize dest = IntSize(hasWidth ? width : fr.width(), hasHeight ? height : f
r.height()); |
1346 IntRect update(fr.location(), dest); | 1315 IntRect update(fr.location(), dest); |
1347 host->chrome().setWindowRect(adjustWindowRect(*frame(), update)); | 1316 host->chrome().setWindowRect(update); |
1348 } | 1317 } |
1349 | 1318 |
1350 int LocalDOMWindow::requestAnimationFrame(FrameRequestCallback* callback) | 1319 int LocalDOMWindow::requestAnimationFrame(FrameRequestCallback* callback) |
1351 { | 1320 { |
1352 callback->m_useLegacyTimeBase = false; | 1321 callback->m_useLegacyTimeBase = false; |
1353 if (Document* d = document()) | 1322 if (Document* d = document()) |
1354 return d->requestAnimationFrame(callback); | 1323 return d->requestAnimationFrame(callback); |
1355 return 0; | 1324 return 0; |
1356 } | 1325 } |
1357 | 1326 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 return targetFrame->domWindow(); | 1514 return targetFrame->domWindow(); |
1546 | 1515 |
1547 if (urlString.isEmpty()) | 1516 if (urlString.isEmpty()) |
1548 return targetFrame->domWindow(); | 1517 return targetFrame->domWindow(); |
1549 | 1518 |
1550 targetFrame->navigate(*activeDocument, completedURL, false); | 1519 targetFrame->navigate(*activeDocument, completedURL, false); |
1551 return targetFrame->domWindow(); | 1520 return targetFrame->domWindow(); |
1552 } | 1521 } |
1553 | 1522 |
1554 WindowFeatures windowFeatures(windowFeaturesString); | 1523 WindowFeatures windowFeatures(windowFeaturesString); |
1555 LocalFrame* result = createWindow(urlString, frameName, windowFeatures, *cal
lingWindow, *firstFrame, *frame()); | 1524 Frame* result = createWindow(urlString, frameName, windowFeatures, *callingW
indow, *firstFrame, *frame()); |
1556 return result ? result->domWindow() : nullptr; | 1525 return result ? result->domWindow() : nullptr; |
1557 } | 1526 } |
1558 | 1527 |
1559 DEFINE_TRACE(LocalDOMWindow) | 1528 DEFINE_TRACE(LocalDOMWindow) |
1560 { | 1529 { |
1561 #if ENABLE(OILPAN) | 1530 #if ENABLE(OILPAN) |
1562 visitor->trace(m_frameObserver); | 1531 visitor->trace(m_frameObserver); |
1563 visitor->trace(m_document); | 1532 visitor->trace(m_document); |
1564 visitor->trace(m_properties); | 1533 visitor->trace(m_properties); |
1565 visitor->trace(m_screen); | 1534 visitor->trace(m_screen); |
(...skipping 16 matching lines...) Expand all Loading... |
1582 DOMWindow::trace(visitor); | 1551 DOMWindow::trace(visitor); |
1583 DOMWindowLifecycleNotifier::trace(visitor); | 1552 DOMWindowLifecycleNotifier::trace(visitor); |
1584 } | 1553 } |
1585 | 1554 |
1586 LocalFrame* LocalDOMWindow::frame() const | 1555 LocalFrame* LocalDOMWindow::frame() const |
1587 { | 1556 { |
1588 return m_frameObserver->frame(); | 1557 return m_frameObserver->frame(); |
1589 } | 1558 } |
1590 | 1559 |
1591 } // namespace blink | 1560 } // namespace blink |
OLD | NEW |