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

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: address review comments 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 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 if (!host) 910 if (!host)
909 return 0; 911 return 0;
910 912
911 ChromeClient& chromeClient = host->chromeClient(); 913 ChromeClient& chromeClient = host->chromeClient();
912 if (host->settings().reportScreenSizeInPhysicalPixelsQuirk()) 914 if (host->settings().reportScreenSizeInPhysicalPixelsQuirk())
913 return lroundf(chromeClient.windowRect().width() * chromeClient.screenIn fo().deviceScaleFactor); 915 return lroundf(chromeClient.windowRect().width() * chromeClient.screenIn fo().deviceScaleFactor);
914 916
915 return chromeClient.windowRect().width(); 917 return chromeClient.windowRect().width();
916 } 918 }
917 919
918 static FloatSize getViewportSize(LocalFrame* frame) 920 FloatSize LocalDOMWindow::getViewportSize(IncludeScrollbarsInRect scrollbarInclu sion) const
919 { 921 {
920 FrameView* view = frame->view(); 922 if (!frame())
923 return FloatSize();
924
925 FrameView* view = frame()->view();
921 if (!view) 926 if (!view)
922 return FloatSize(); 927 return FloatSize();
923 928
924 FrameHost* host = frame->host(); 929 FrameHost* host = frame()->host();
925 if (!host) 930 if (!host)
926 return FloatSize(); 931 return FloatSize();
927 932
928 // The main frame's viewport size depends on the page scale. Since the 933 // The main frame's viewport size depends on the page scale. Since the
929 // initial page scale depends on the content width and is set after a 934 // initial page scale depends on the content width and is set after a
930 // layout, perform one now so queries during page load will use the up to 935 // layout, perform one now so queries during page load will use the up to
931 // date viewport. 936 // date viewport.
932 if (host->settings().viewportEnabled() && frame->isMainFrame()) 937 if (host->settings().viewportEnabled() && frame()->isMainFrame())
933 frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 938 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets();
934 939
935 // FIXME: This is potentially too much work. We really only need to know the dimensions of the parent frame's layoutObject. 940 // FIXME: This is potentially too much work. We really only need to know the dimensions of the parent frame's layoutObject.
936 if (Frame* parent = frame->tree().parent()) { 941 if (Frame* parent = frame()->tree().parent()) {
937 if (parent && parent->isLocalFrame()) 942 if (parent && parent->isLocalFrame())
938 toLocalFrame(parent)->document()->updateStyleAndLayoutIgnorePendingS tylesheets(); 943 toLocalFrame(parent)->document()->updateStyleAndLayoutIgnorePendingS tylesheets();
939 } 944 }
940 945
941 return frame->isMainFrame() && !host->settings().inertVisualViewport() 946 return frame()->isMainFrame() && !host->settings().inertVisualViewport()
942 ? FloatSize(host->visualViewport().visibleRect().size()) 947 ? FloatSize(host->visualViewport().visibleRect().size())
943 : FloatSize(view->visibleContentRect(IncludeScrollbars).size()); 948 : FloatSize(view->visibleContentRect(scrollbarInclusion).size());
944 } 949 }
945 950
946 int LocalDOMWindow::innerHeight() const 951 int LocalDOMWindow::innerHeight() const
947 { 952 {
948 if (!frame()) 953 if (!frame())
949 return 0; 954 return 0;
950 955
951 FloatSize viewportSize = getViewportSize(frame()); 956 FloatSize viewportSize = getViewportSize(IncludeScrollbars);
952 return adjustForAbsoluteZoom(expandedIntSize(viewportSize).height(), frame() ->pageZoomFactor()); 957 return adjustForAbsoluteZoom(expandedIntSize(viewportSize).height(), frame() ->pageZoomFactor());
953 } 958 }
954 959
955 int LocalDOMWindow::innerWidth() const 960 int LocalDOMWindow::innerWidth() const
956 { 961 {
957 if (!frame()) 962 if (!frame())
958 return 0; 963 return 0;
959 964
960 FloatSize viewportSize = getViewportSize(frame()); 965 FloatSize viewportSize = getViewportSize(IncludeScrollbars);
961 return adjustForAbsoluteZoom(expandedIntSize(viewportSize).width(), frame()- >pageZoomFactor()); 966 return adjustForAbsoluteZoom(expandedIntSize(viewportSize).width(), frame()- >pageZoomFactor());
962 } 967 }
963 968
964 int LocalDOMWindow::screenX() const 969 int LocalDOMWindow::screenX() const
965 { 970 {
966 if (!frame()) 971 if (!frame())
967 return 0; 972 return 0;
968 973
969 FrameHost* host = frame()->host(); 974 FrameHost* host = frame()->host();
970 if (!host) 975 if (!host)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 if (!host) 1029 if (!host)
1025 return 0; 1030 return 0;
1026 1031
1027 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 1032 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets();
1028 1033
1029 ScrollableArea* viewport = host->settings().inertVisualViewport() ? view->la youtViewportScrollableArea() : view->getScrollableArea(); 1034 ScrollableArea* viewport = host->settings().inertVisualViewport() ? view->la youtViewportScrollableArea() : view->getScrollableArea();
1030 double viewportY = viewport->scrollPositionDouble().y(); 1035 double viewportY = viewport->scrollPositionDouble().y();
1031 return adjustScrollForAbsoluteZoom(viewportY, frame()->pageZoomFactor()); 1036 return adjustScrollForAbsoluteZoom(viewportY, frame()->pageZoomFactor());
1032 } 1037 }
1033 1038
1034 VisualViewport* LocalDOMWindow::visualViewport() 1039 DOMVisualViewport* LocalDOMWindow::visualViewport()
1035 { 1040 {
1036 if (!frame()) 1041 if (!frame())
1037 return nullptr; 1042 return nullptr;
1038 1043
1039 FrameHost* host = frame()->host(); 1044 return m_visualViewport;
1040 if (!host)
1041 return nullptr;
1042
1043 return &host->visualViewport();
1044 } 1045 }
1045 1046
1046 const AtomicString& LocalDOMWindow::name() const 1047 const AtomicString& LocalDOMWindow::name() const
1047 { 1048 {
1048 if (!isCurrentlyDisplayedInFrame()) 1049 if (!isCurrentlyDisplayedInFrame())
1049 return nullAtom; 1050 return nullAtom;
1050 1051
1051 return frame()->tree().name(); 1052 return frame()->tree().name();
1052 } 1053 }
1053 1054
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 visitor->trace(m_personalbar); 1535 visitor->trace(m_personalbar);
1535 visitor->trace(m_scrollbars); 1536 visitor->trace(m_scrollbars);
1536 visitor->trace(m_statusbar); 1537 visitor->trace(m_statusbar);
1537 visitor->trace(m_toolbar); 1538 visitor->trace(m_toolbar);
1538 visitor->trace(m_navigator); 1539 visitor->trace(m_navigator);
1539 visitor->trace(m_media); 1540 visitor->trace(m_media);
1540 visitor->trace(m_customElements); 1541 visitor->trace(m_customElements);
1541 visitor->trace(m_applicationCache); 1542 visitor->trace(m_applicationCache);
1542 visitor->trace(m_eventQueue); 1543 visitor->trace(m_eventQueue);
1543 visitor->trace(m_postMessageTimers); 1544 visitor->trace(m_postMessageTimers);
1545 visitor->trace(m_visualViewport);
1544 DOMWindow::trace(visitor); 1546 DOMWindow::trace(visitor);
1545 Supplementable<LocalDOMWindow>::trace(visitor); 1547 Supplementable<LocalDOMWindow>::trace(visitor);
1546 DOMWindowLifecycleNotifier::trace(visitor); 1548 DOMWindowLifecycleNotifier::trace(visitor);
1547 } 1549 }
1548 1550
1549 LocalFrame* LocalDOMWindow::frame() const 1551 LocalFrame* LocalDOMWindow::frame() const
1550 { 1552 {
1551 // If the LocalDOMWindow still has a frame reference, that frame must point 1553 // If the LocalDOMWindow still has a frame reference, that frame must point
1552 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation 1554 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation
1553 // where script execution leaks between different LocalDOMWindows. 1555 // where script execution leaks between different LocalDOMWindows.
1554 if (m_frameObserver->frame()) 1556 if (m_frameObserver->frame())
1555 ASSERT_WITH_SECURITY_IMPLICATION(m_frameObserver->frame()->domWindow() = = this); 1557 ASSERT_WITH_SECURITY_IMPLICATION(m_frameObserver->frame()->domWindow() = = this);
1556 return m_frameObserver->frame(); 1558 return m_frameObserver->frame();
1557 } 1559 }
1558 1560
1559 } // namespace blink 1561 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698