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

Side by Side Diff: third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp

Issue 2070563002: Seperate DOMVisualViewport from Blink's VisualViewport class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 4 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) 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 30 matching lines...) Expand all
41 #include "core/dom/SandboxFlags.h" 41 #include "core/dom/SandboxFlags.h"
42 #include "core/dom/custom/CustomElementsRegistry.h" 42 #include "core/dom/custom/CustomElementsRegistry.h"
43 #include "core/editing/Editor.h" 43 #include "core/editing/Editor.h"
44 #include "core/events/DOMWindowEventQueue.h" 44 #include "core/events/DOMWindowEventQueue.h"
45 #include "core/events/HashChangeEvent.h" 45 #include "core/events/HashChangeEvent.h"
46 #include "core/events/MessageEvent.h" 46 #include "core/events/MessageEvent.h"
47 #include "core/events/PageTransitionEvent.h" 47 #include "core/events/PageTransitionEvent.h"
48 #include "core/events/PopStateEvent.h" 48 #include "core/events/PopStateEvent.h"
49 #include "core/events/ScopedEventQueue.h" 49 #include "core/events/ScopedEventQueue.h"
50 #include "core/frame/BarProp.h" 50 #include "core/frame/BarProp.h"
51 #include "core/frame/DOMVisualViewport.h"
51 #include "core/frame/EventHandlerRegistry.h" 52 #include "core/frame/EventHandlerRegistry.h"
52 #include "core/frame/FrameConsole.h" 53 #include "core/frame/FrameConsole.h"
53 #include "core/frame/FrameView.h" 54 #include "core/frame/FrameView.h"
54 #include "core/frame/History.h" 55 #include "core/frame/History.h"
55 #include "core/frame/LocalFrame.h" 56 #include "core/frame/LocalFrame.h"
56 #include "core/frame/Navigator.h" 57 #include "core/frame/Navigator.h"
57 #include "core/frame/Screen.h" 58 #include "core/frame/Screen.h"
58 #include "core/frame/ScrollToOptions.h" 59 #include "core/frame/ScrollToOptions.h"
59 #include "core/frame/Settings.h" 60 #include "core/frame/Settings.h"
60 #include "core/frame/SuspendableTimer.h" 61 #include "core/frame/SuspendableTimer.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 return settings && settings->javaScriptCanOpenWindowsAutomatically(); 296 return settings && settings->javaScriptCanOpenWindowsAutomatically();
296 } 297 }
297 298
298 bool LocalDOMWindow::allowPopUp() 299 bool LocalDOMWindow::allowPopUp()
299 { 300 {
300 return frame() && allowPopUp(*frame()); 301 return frame() && allowPopUp(*frame());
301 } 302 }
302 303
303 LocalDOMWindow::LocalDOMWindow(LocalFrame& frame) 304 LocalDOMWindow::LocalDOMWindow(LocalFrame& frame)
304 : m_frameObserver(WindowFrameObserver::create(this, frame)) 305 : m_frameObserver(WindowFrameObserver::create(this, frame))
306 , m_visualViewport(DOMVisualViewport::create(this))
305 , m_shouldPrintWhenFinishedLoading(false) 307 , m_shouldPrintWhenFinishedLoading(false)
306 { 308 {
307 ThreadState::current()->registerPreFinalizer(this); 309 ThreadState::current()->registerPreFinalizer(this);
308 } 310 }
309 311
310 void LocalDOMWindow::clearDocument() 312 void LocalDOMWindow::clearDocument()
311 { 313 {
312 if (!m_document) 314 if (!m_document)
313 return; 315 return;
314 316
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 if (!host) 923 if (!host)
922 return 0; 924 return 0;
923 925
924 ChromeClient& chromeClient = host->chromeClient(); 926 ChromeClient& chromeClient = host->chromeClient();
925 if (host->settings().reportScreenSizeInPhysicalPixelsQuirk()) 927 if (host->settings().reportScreenSizeInPhysicalPixelsQuirk())
926 return lroundf(chromeClient.windowRect().width() * chromeClient.screenIn fo().deviceScaleFactor); 928 return lroundf(chromeClient.windowRect().width() * chromeClient.screenIn fo().deviceScaleFactor);
927 929
928 return chromeClient.windowRect().width(); 930 return chromeClient.windowRect().width();
929 } 931 }
930 932
931 static FloatSize getViewportSize(LocalFrame* frame) 933 FloatSize LocalDOMWindow::getViewportSize(IncludeScrollbarsInRect scrollbarInclu sion) const
932 { 934 {
933 FrameView* view = frame->view(); 935 if (!frame())
936 return FloatSize();
937
938 FrameView* view = frame()->view();
934 if (!view) 939 if (!view)
935 return FloatSize(); 940 return FloatSize();
936 941
937 FrameHost* host = frame->host(); 942 FrameHost* host = frame()->host();
938 if (!host) 943 if (!host)
939 return FloatSize(); 944 return FloatSize();
940 945
941 // The main frame's viewport size depends on the page scale. Since the 946 // The main frame's viewport size depends on the page scale. Since the
942 // initial page scale depends on the content width and is set after a 947 // initial page scale depends on the content width and is set after a
943 // layout, perform one now so queries during page load will use the up to 948 // layout, perform one now so queries during page load will use the up to
944 // date viewport. 949 // date viewport.
945 if (host->settings().viewportEnabled() && frame->isMainFrame()) 950 if (host->settings().viewportEnabled() && frame()->isMainFrame())
946 frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 951 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets();
947 952
948 // FIXME: This is potentially too much work. We really only need to know the dimensions of the parent frame's layoutObject. 953 // FIXME: This is potentially too much work. We really only need to know the dimensions of the parent frame's layoutObject.
949 if (Frame* parent = frame->tree().parent()) { 954 if (Frame* parent = frame()->tree().parent()) {
950 if (parent && parent->isLocalFrame()) 955 if (parent && parent->isLocalFrame())
951 toLocalFrame(parent)->document()->updateStyleAndLayoutIgnorePendingS tylesheets(); 956 toLocalFrame(parent)->document()->updateStyleAndLayoutIgnorePendingS tylesheets();
952 } 957 }
953 958
954 return frame->isMainFrame() && !host->settings().inertVisualViewport() 959 return frame()->isMainFrame() && !host->settings().inertVisualViewport()
955 ? FloatSize(host->visualViewport().visibleRect().size()) 960 ? FloatSize(host->visualViewport().visibleRect().size())
956 : FloatSize(view->visibleContentRect(IncludeScrollbars).size()); 961 : FloatSize(view->visibleContentRect(scrollbarInclusion).size());
957 } 962 }
958 963
959 int LocalDOMWindow::innerHeight() const 964 int LocalDOMWindow::innerHeight() const
960 { 965 {
961 if (!frame()) 966 if (!frame())
962 return 0; 967 return 0;
963 968
964 FloatSize viewportSize = getViewportSize(frame()); 969 FloatSize viewportSize = getViewportSize(IncludeScrollbars);
965 return adjustForAbsoluteZoom(expandedIntSize(viewportSize).height(), frame() ->pageZoomFactor()); 970 return adjustForAbsoluteZoom(expandedIntSize(viewportSize).height(), frame() ->pageZoomFactor());
966 } 971 }
967 972
968 int LocalDOMWindow::innerWidth() const 973 int LocalDOMWindow::innerWidth() const
969 { 974 {
970 if (!frame()) 975 if (!frame())
971 return 0; 976 return 0;
972 977
973 FloatSize viewportSize = getViewportSize(frame()); 978 FloatSize viewportSize = getViewportSize(IncludeScrollbars);
974 return adjustForAbsoluteZoom(expandedIntSize(viewportSize).width(), frame()- >pageZoomFactor()); 979 return adjustForAbsoluteZoom(expandedIntSize(viewportSize).width(), frame()- >pageZoomFactor());
975 } 980 }
976 981
977 int LocalDOMWindow::screenX() const 982 int LocalDOMWindow::screenX() const
978 { 983 {
979 if (!frame()) 984 if (!frame())
980 return 0; 985 return 0;
981 986
982 FrameHost* host = frame()->host(); 987 FrameHost* host = frame()->host();
983 if (!host) 988 if (!host)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 if (!host) 1042 if (!host)
1038 return 0; 1043 return 0;
1039 1044
1040 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 1045 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets();
1041 1046
1042 ScrollableArea* viewport = host->settings().inertVisualViewport() ? view->la youtViewportScrollableArea() : view->getScrollableArea(); 1047 ScrollableArea* viewport = host->settings().inertVisualViewport() ? view->la youtViewportScrollableArea() : view->getScrollableArea();
1043 double viewportY = viewport->scrollPositionDouble().y(); 1048 double viewportY = viewport->scrollPositionDouble().y();
1044 return adjustScrollForAbsoluteZoom(viewportY, frame()->pageZoomFactor()); 1049 return adjustScrollForAbsoluteZoom(viewportY, frame()->pageZoomFactor());
1045 } 1050 }
1046 1051
1047 VisualViewport* LocalDOMWindow::visualViewport() 1052 DOMVisualViewport* LocalDOMWindow::visualViewport()
1048 { 1053 {
1049 if (!frame()) 1054 if (!frame())
1050 return nullptr; 1055 return nullptr;
1051 1056
1052 FrameHost* host = frame()->host(); 1057 return m_visualViewport;
1053 if (!host)
1054 return nullptr;
1055
1056 return &host->visualViewport();
1057 } 1058 }
1058 1059
1059 const AtomicString& LocalDOMWindow::name() const 1060 const AtomicString& LocalDOMWindow::name() const
1060 { 1061 {
1061 if (!isCurrentlyDisplayedInFrame()) 1062 if (!isCurrentlyDisplayedInFrame())
1062 return nullAtom; 1063 return nullAtom;
1063 1064
1064 return frame()->tree().name(); 1065 return frame()->tree().name();
1065 } 1066 }
1066 1067
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 visitor->trace(m_personalbar); 1551 visitor->trace(m_personalbar);
1551 visitor->trace(m_scrollbars); 1552 visitor->trace(m_scrollbars);
1552 visitor->trace(m_statusbar); 1553 visitor->trace(m_statusbar);
1553 visitor->trace(m_toolbar); 1554 visitor->trace(m_toolbar);
1554 visitor->trace(m_navigator); 1555 visitor->trace(m_navigator);
1555 visitor->trace(m_media); 1556 visitor->trace(m_media);
1556 visitor->trace(m_customElements); 1557 visitor->trace(m_customElements);
1557 visitor->trace(m_applicationCache); 1558 visitor->trace(m_applicationCache);
1558 visitor->trace(m_eventQueue); 1559 visitor->trace(m_eventQueue);
1559 visitor->trace(m_postMessageTimers); 1560 visitor->trace(m_postMessageTimers);
1561 visitor->trace(m_visualViewport);
1560 DOMWindow::trace(visitor); 1562 DOMWindow::trace(visitor);
1561 Supplementable<LocalDOMWindow>::trace(visitor); 1563 Supplementable<LocalDOMWindow>::trace(visitor);
1562 DOMWindowLifecycleNotifier::trace(visitor); 1564 DOMWindowLifecycleNotifier::trace(visitor);
1563 } 1565 }
1564 1566
1565 LocalFrame* LocalDOMWindow::frame() const 1567 LocalFrame* LocalDOMWindow::frame() const
1566 { 1568 {
1567 // If the LocalDOMWindow still has a frame reference, that frame must point 1569 // If the LocalDOMWindow still has a frame reference, that frame must point
1568 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation 1570 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation
1569 // where script execution leaks between different LocalDOMWindows. 1571 // where script execution leaks between different LocalDOMWindows.
1570 if (m_frameObserver->frame()) 1572 if (m_frameObserver->frame())
1571 ASSERT_WITH_SECURITY_IMPLICATION(m_frameObserver->frame()->domWindow() = = this); 1573 ASSERT_WITH_SECURITY_IMPLICATION(m_frameObserver->frame()->domWindow() = = this);
1572 return m_frameObserver->frame(); 1574 return m_frameObserver->frame();
1573 } 1575 }
1574 1576
1575 } // namespace blink 1577 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698