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) | |
Nate Chapin
2015/04/28 23:25:51
This was only ever called immediately before calli
| |
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 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1272 if (!frame() || !frame()->isMainFrame()) | 1241 if (!frame() || !frame()->isMainFrame()) |
1273 return; | 1242 return; |
1274 | 1243 |
1275 FrameHost* host = frame()->host(); | 1244 FrameHost* host = frame()->host(); |
1276 if (!host) | 1245 if (!host) |
1277 return; | 1246 return; |
1278 | 1247 |
1279 IntRect windowRect = host->chrome().windowRect(); | 1248 IntRect windowRect = host->chrome().windowRect(); |
1280 windowRect.move(x, y); | 1249 windowRect.move(x, y); |
1281 // Security check (the spec talks about UniversalBrowserWrite to disable thi s check...) | 1250 // Security check (the spec talks about UniversalBrowserWrite to disable thi s check...) |
1282 host->chrome().setWindowRect(adjustWindowRect(*frame(), windowRect)); | 1251 host->chrome().setWindowRect(frame()->view(), windowRect); |
1283 } | 1252 } |
1284 | 1253 |
1285 void LocalDOMWindow::moveTo(int x, int y, bool hasX, bool hasY) const | 1254 void LocalDOMWindow::moveTo(int x, int y, bool hasX, bool hasY) const |
1286 { | 1255 { |
1287 if (!hasX || !hasY) | 1256 if (!hasX || !hasY) |
1288 UseCounter::count(document(), UseCounter::WindowMoveResizeMissingArgumen ts); | 1257 UseCounter::count(document(), UseCounter::WindowMoveResizeMissingArgumen ts); |
1289 | 1258 |
1290 if (!frame() || !frame()->isMainFrame()) | 1259 if (!frame() || !frame()->isMainFrame()) |
1291 return; | 1260 return; |
1292 | 1261 |
1293 FrameHost* host = frame()->host(); | 1262 FrameHost* host = frame()->host(); |
1294 if (!host) | 1263 if (!host) |
1295 return; | 1264 return; |
1296 | 1265 |
1297 IntRect windowRect = host->chrome().windowRect(); | 1266 IntRect windowRect = host->chrome().windowRect(); |
1298 windowRect.setLocation(IntPoint(hasX ? x : windowRect.x(), hasY ? y : window Rect.y())); | 1267 windowRect.setLocation(IntPoint(hasX ? x : windowRect.x(), hasY ? y : window Rect.y())); |
1299 // Security check (the spec talks about UniversalBrowserWrite to disable thi s check...) | 1268 // Security check (the spec talks about UniversalBrowserWrite to disable thi s check...) |
1300 host->chrome().setWindowRect(adjustWindowRect(*frame(), windowRect)); | 1269 host->chrome().setWindowRect(frame()->view(), windowRect); |
1301 } | 1270 } |
1302 | 1271 |
1303 void LocalDOMWindow::resizeBy(int x, int y, bool hasX, bool hasY) const | 1272 void LocalDOMWindow::resizeBy(int x, int y, bool hasX, bool hasY) const |
1304 { | 1273 { |
1305 if (!hasX || !hasY) | 1274 if (!hasX || !hasY) |
1306 UseCounter::count(document(), UseCounter::WindowMoveResizeMissingArgumen ts); | 1275 UseCounter::count(document(), UseCounter::WindowMoveResizeMissingArgumen ts); |
1307 | 1276 |
1308 if (!frame() || !frame()->isMainFrame()) | 1277 if (!frame() || !frame()->isMainFrame()) |
1309 return; | 1278 return; |
1310 | 1279 |
1311 FrameHost* host = frame()->host(); | 1280 FrameHost* host = frame()->host(); |
1312 if (!host) | 1281 if (!host) |
1313 return; | 1282 return; |
1314 | 1283 |
1315 IntRect fr = host->chrome().windowRect(); | 1284 IntRect fr = host->chrome().windowRect(); |
1316 IntSize dest = fr.size() + IntSize(x, y); | 1285 IntSize dest = fr.size() + IntSize(x, y); |
1317 IntRect update(fr.location(), dest); | 1286 IntRect update(fr.location(), dest); |
1318 host->chrome().setWindowRect(adjustWindowRect(*frame(), update)); | 1287 host->chrome().setWindowRect(frame()->view(), update); |
1319 } | 1288 } |
1320 | 1289 |
1321 void LocalDOMWindow::resizeTo(int width, int height, bool hasWidth, bool hasHeig ht) const | 1290 void LocalDOMWindow::resizeTo(int width, int height, bool hasWidth, bool hasHeig ht) const |
1322 { | 1291 { |
1323 if (!hasWidth || !hasHeight) | 1292 if (!hasWidth || !hasHeight) |
1324 UseCounter::count(document(), UseCounter::WindowMoveResizeMissingArgumen ts); | 1293 UseCounter::count(document(), UseCounter::WindowMoveResizeMissingArgumen ts); |
1325 | 1294 |
1326 if (!frame() || !frame()->isMainFrame()) | 1295 if (!frame() || !frame()->isMainFrame()) |
1327 return; | 1296 return; |
1328 | 1297 |
1329 FrameHost* host = frame()->host(); | 1298 FrameHost* host = frame()->host(); |
1330 if (!host) | 1299 if (!host) |
1331 return; | 1300 return; |
1332 | 1301 |
1333 IntRect fr = host->chrome().windowRect(); | 1302 IntRect fr = host->chrome().windowRect(); |
1334 IntSize dest = IntSize(hasWidth ? width : fr.width(), hasHeight ? height : f r.height()); | 1303 IntSize dest = IntSize(hasWidth ? width : fr.width(), hasHeight ? height : f r.height()); |
1335 IntRect update(fr.location(), dest); | 1304 IntRect update(fr.location(), dest); |
1336 host->chrome().setWindowRect(adjustWindowRect(*frame(), update)); | 1305 host->chrome().setWindowRect(frame()->view(), update); |
1337 } | 1306 } |
1338 | 1307 |
1339 int LocalDOMWindow::requestAnimationFrame(FrameRequestCallback* callback) | 1308 int LocalDOMWindow::requestAnimationFrame(FrameRequestCallback* callback) |
1340 { | 1309 { |
1341 callback->m_useLegacyTimeBase = false; | 1310 callback->m_useLegacyTimeBase = false; |
1342 if (Document* d = document()) | 1311 if (Document* d = document()) |
1343 return d->requestAnimationFrame(callback); | 1312 return d->requestAnimationFrame(callback); |
1344 return 0; | 1313 return 0; |
1345 } | 1314 } |
1346 | 1315 |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1612 return targetFrame->domWindow(); | 1581 return targetFrame->domWindow(); |
1613 | 1582 |
1614 if (urlString.isEmpty()) | 1583 if (urlString.isEmpty()) |
1615 return targetFrame->domWindow(); | 1584 return targetFrame->domWindow(); |
1616 | 1585 |
1617 targetFrame->navigate(*activeDocument, completedURL, false); | 1586 targetFrame->navigate(*activeDocument, completedURL, false); |
1618 return targetFrame->domWindow(); | 1587 return targetFrame->domWindow(); |
1619 } | 1588 } |
1620 | 1589 |
1621 WindowFeatures windowFeatures(windowFeaturesString); | 1590 WindowFeatures windowFeatures(windowFeaturesString); |
1622 LocalFrame* result = createWindow(urlString, frameName, windowFeatures, *cal lingWindow, *firstFrame, *frame()); | 1591 Frame* result = createWindow(urlString, frameName, windowFeatures, *callingW indow, *firstFrame, *frame()); |
1623 return result ? result->domWindow() : nullptr; | 1592 return result ? result->domWindow() : nullptr; |
1624 } | 1593 } |
1625 | 1594 |
1626 DEFINE_TRACE(LocalDOMWindow) | 1595 DEFINE_TRACE(LocalDOMWindow) |
1627 { | 1596 { |
1628 #if ENABLE(OILPAN) | 1597 #if ENABLE(OILPAN) |
1629 visitor->trace(m_frameObserver); | 1598 visitor->trace(m_frameObserver); |
1630 visitor->trace(m_document); | 1599 visitor->trace(m_document); |
1631 visitor->trace(m_properties); | 1600 visitor->trace(m_properties); |
1632 visitor->trace(m_screen); | 1601 visitor->trace(m_screen); |
(...skipping 22 matching lines...) Expand all Loading... | |
1655 return m_frameObserver->frame(); | 1624 return m_frameObserver->frame(); |
1656 } | 1625 } |
1657 | 1626 |
1658 v8::Handle<v8::Object> LocalDOMWindow::wrap(v8::Handle<v8::Object> creationConte xt, v8::Isolate* isolate) | 1627 v8::Handle<v8::Object> LocalDOMWindow::wrap(v8::Handle<v8::Object> creationConte xt, v8::Isolate* isolate) |
1659 { | 1628 { |
1660 ASSERT_NOT_REACHED(); // LocalDOMWindow has [Custom=ToV8]. | 1629 ASSERT_NOT_REACHED(); // LocalDOMWindow has [Custom=ToV8]. |
1661 return v8::Handle<v8::Object>(); | 1630 return v8::Handle<v8::Object>(); |
1662 } | 1631 } |
1663 | 1632 |
1664 } // namespace blink | 1633 } // namespace blink |
OLD | NEW |