OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "core/page/scrolling/TopDocumentRootScrollerController.h" | |
6 | |
7 #include "core/dom/Document.h" | |
8 #include "core/dom/Element.h" | |
9 #include "core/frame/FrameHost.h" | |
10 #include "core/frame/FrameView.h" | |
11 #include "core/page/ChromeClient.h" | |
12 #include "core/page/scrolling/OverscrollController.h" | |
13 #include "core/page/scrolling/ViewportScrollCallback.h" | |
14 #include "platform/scroll/ScrollableArea.h" | |
15 | |
16 namespace blink { | |
17 | |
18 // static | |
19 TopDocumentRootScrollerController* TopDocumentRootScrollerController::create( | |
20 Document& document) | |
21 { | |
22 return new TopDocumentRootScrollerController(document); | |
23 } | |
24 | |
25 TopDocumentRootScrollerController::TopDocumentRootScrollerController( | |
26 Document& document) | |
27 : RootScrollerController(document) | |
28 { | |
29 } | |
30 | |
31 DEFINE_TRACE(TopDocumentRootScrollerController) | |
32 { | |
33 visitor->trace(m_viewportApplyScroll); | |
34 visitor->trace(m_currentViewportApplyScrollHost); | |
35 RootScrollerController::trace(visitor); | |
36 } | |
37 | |
38 void TopDocumentRootScrollerController::updateEffectiveRootScroller() | |
39 { | |
40 RootScrollerController::updateEffectiveRootScroller(); | |
41 setViewportApplyScrollOnRootScroller(); | |
42 } | |
43 | |
44 void TopDocumentRootScrollerController::setViewportApplyScrollOnRootScroller() | |
45 { | |
46 if (!m_viewportApplyScroll || !effectiveRootScroller()) | |
47 return; | |
48 | |
49 ScrollableArea* targetScroller = | |
50 scrollableAreaFor(*effectiveRootScroller()); | |
51 | |
52 if (!targetScroller) | |
53 return; | |
54 | |
55 if (m_currentViewportApplyScrollHost) | |
56 m_currentViewportApplyScrollHost->removeApplyScroll(); | |
57 | |
58 // Use disable-native-scroll since the ViewportScrollCallback needs to | |
59 // apply scroll actions both before (TopControls) and after (overscroll) | |
60 // scrolling the element so it will apply scroll to the element itself. | |
61 effectiveRootScroller()->setApplyScroll( | |
62 m_viewportApplyScroll, "disable-native-scroll"); | |
63 | |
64 m_currentViewportApplyScrollHost = effectiveRootScroller(); | |
65 | |
66 // Ideally, scroll customization would pass the current element to scroll to | |
67 // the apply scroll callback but this doesn't happen today so we set it | |
68 // through a back door here. This is also needed by the | |
69 // ViewportScrollCallback to swap the target into the layout viewport | |
70 // in RootFrameViewport. | |
71 m_viewportApplyScroll->setScroller(targetScroller); | |
72 } | |
73 | |
74 void TopDocumentRootScrollerController::didUpdateCompositing() | |
75 { | |
76 FrameHost* frameHost = m_document->frameHost(); | |
77 | |
78 // Let the compositor-side counterpart know about this change. | |
79 if (frameHost) | |
80 frameHost->chromeClient().registerViewportLayers(); | |
81 } | |
82 | |
83 void TopDocumentRootScrollerController::didAttachDocument() | |
84 { | |
85 FrameHost* frameHost = m_document->frameHost(); | |
86 FrameView* frameView = m_document->view(); | |
87 | |
88 if (!frameHost || !frameView) | |
89 return; | |
90 | |
91 RootFrameViewport* rootFrameViewport = frameView->getRootFrameViewport(); | |
92 DCHECK(rootFrameViewport); | |
93 | |
94 m_viewportApplyScroll = ViewportScrollCallback::create( | |
95 &frameHost->topControls(), | |
96 &frameHost->overscrollController(), | |
97 *rootFrameViewport); | |
98 | |
99 updateEffectiveRootScroller(); | |
100 } | |
101 | |
102 bool TopDocumentRootScrollerController::isViewportScrollCallback( | |
103 const ScrollStateCallback* callback) const | |
104 { | |
105 if (!callback) | |
106 return false; | |
107 | |
108 return callback == m_viewportApplyScroll.get(); | |
109 } | |
110 | |
111 } // namespace blink | |
OLD | NEW |