| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/page/scrolling/RootScroller.h" | 5 #include "core/page/scrolling/RootScrollerController.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/dom/Element.h" | 8 #include "core/dom/Element.h" |
| 9 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
| 10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| 11 #include "core/frame/TopControls.h" | 11 #include "core/frame/TopControls.h" |
| 12 #include "core/layout/LayoutBox.h" | 12 #include "core/layout/LayoutBox.h" |
| 13 #include "core/page/Page.h" | 13 #include "core/page/Page.h" |
| 14 #include "core/page/scrolling/OverscrollController.h" | 14 #include "core/page/scrolling/OverscrollController.h" |
| 15 #include "core/page/scrolling/ViewportScrollCallback.h" | 15 #include "core/page/scrolling/ViewportScrollCallback.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 return false; | 66 return false; |
| 67 | 67 |
| 68 if (!fillsViewport(element)) | 68 if (!fillsViewport(element)) |
| 69 return false; | 69 return false; |
| 70 | 70 |
| 71 return true; | 71 return true; |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 ViewportScrollCallback* RootScroller::createViewportApplyScroll( | 76 ViewportScrollCallback* RootScrollerController::createViewportApplyScroll( |
| 77 TopControls& topControls, OverscrollController& overscrollController) | 77 TopControls& topControls, OverscrollController& overscrollController) |
| 78 { | 78 { |
| 79 return new ViewportScrollCallback(topControls, overscrollController); | 79 return new ViewportScrollCallback(topControls, overscrollController); |
| 80 } | 80 } |
| 81 | 81 |
| 82 RootScroller::RootScroller(Document& document, ViewportScrollCallback* applyScro
llCallback) | 82 RootScrollerController::RootScrollerController(Document& document, ViewportScrol
lCallback* applyScrollCallback) |
| 83 : m_document(&document) | 83 : m_document(&document) |
| 84 , m_viewportApplyScroll(applyScrollCallback) | 84 , m_viewportApplyScroll(applyScrollCallback) |
| 85 { | 85 { |
| 86 } | 86 } |
| 87 | 87 |
| 88 DEFINE_TRACE(RootScroller) | 88 DEFINE_TRACE(RootScrollerController) |
| 89 { | 89 { |
| 90 visitor->trace(m_document); | 90 visitor->trace(m_document); |
| 91 visitor->trace(m_viewportApplyScroll); | 91 visitor->trace(m_viewportApplyScroll); |
| 92 visitor->trace(m_rootScroller); | 92 visitor->trace(m_rootScroller); |
| 93 visitor->trace(m_effectiveRootScroller); | 93 visitor->trace(m_effectiveRootScroller); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void RootScroller::set(Element* newRootScroller) | 96 void RootScrollerController::set(Element* newRootScroller) |
| 97 { | 97 { |
| 98 m_rootScroller = newRootScroller; | 98 m_rootScroller = newRootScroller; |
| 99 updateEffectiveRootScroller(); | 99 updateEffectiveRootScroller(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 Element* RootScroller::get() const | 102 Element* RootScrollerController::get() const |
| 103 { | 103 { |
| 104 return m_rootScroller; | 104 return m_rootScroller; |
| 105 } | 105 } |
| 106 | 106 |
| 107 Element* RootScroller::effectiveRootScroller() const | 107 Element* RootScrollerController::effectiveRootScroller() const |
| 108 { | 108 { |
| 109 return m_effectiveRootScroller; | 109 return m_effectiveRootScroller; |
| 110 } | 110 } |
| 111 | 111 |
| 112 void RootScroller::didUpdateLayout() | 112 void RootScrollerController::didUpdateLayout() |
| 113 { | 113 { |
| 114 updateEffectiveRootScroller(); | 114 updateEffectiveRootScroller(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void RootScroller::updateEffectiveRootScroller() | 117 void RootScrollerController::updateEffectiveRootScroller() |
| 118 { | 118 { |
| 119 bool rootScrollerValid = | 119 bool rootScrollerValid = |
| 120 m_rootScroller && isValidRootScroller(*m_rootScroller); | 120 m_rootScroller && isValidRootScroller(*m_rootScroller); |
| 121 | 121 |
| 122 Element* newEffectiveRootScroller = rootScrollerValid | 122 Element* newEffectiveRootScroller = rootScrollerValid |
| 123 ? m_rootScroller.get() | 123 ? m_rootScroller.get() |
| 124 : defaultEffectiveRootScroller(); | 124 : defaultEffectiveRootScroller(); |
| 125 | 125 |
| 126 if (m_effectiveRootScroller == newEffectiveRootScroller) | 126 if (m_effectiveRootScroller == newEffectiveRootScroller) |
| 127 return; | 127 return; |
| 128 | 128 |
| 129 moveViewportApplyScroll(newEffectiveRootScroller); | 129 moveViewportApplyScroll(newEffectiveRootScroller); |
| 130 m_effectiveRootScroller = newEffectiveRootScroller; | 130 m_effectiveRootScroller = newEffectiveRootScroller; |
| 131 } | 131 } |
| 132 | 132 |
| 133 void RootScroller::moveViewportApplyScroll(Element* target) | 133 void RootScrollerController::moveViewportApplyScroll(Element* target) |
| 134 { | 134 { |
| 135 if (!m_viewportApplyScroll) | 135 if (!m_viewportApplyScroll) |
| 136 return; | 136 return; |
| 137 | 137 |
| 138 if (m_effectiveRootScroller) | 138 if (m_effectiveRootScroller) |
| 139 m_effectiveRootScroller->removeApplyScroll(); | 139 m_effectiveRootScroller->removeApplyScroll(); |
| 140 | 140 |
| 141 ScrollableArea* targetScroller = | 141 ScrollableArea* targetScroller = |
| 142 target ? scrollableAreaFor(*target) : nullptr; | 142 target ? scrollableAreaFor(*target) : nullptr; |
| 143 | 143 |
| 144 if (targetScroller) { | 144 if (targetScroller) { |
| 145 // Use disable-native-scroll since the ViewportScrollCallback needs to | 145 // Use disable-native-scroll since the ViewportScrollCallback needs to |
| 146 // apply scroll actions both before (TopControls) and after (overscroll) | 146 // apply scroll actions both before (TopControls) and after (overscroll) |
| 147 // scrolling the element so it will apply scroll to the element itself. | 147 // scrolling the element so it will apply scroll to the element itself. |
| 148 target->setApplyScroll( | 148 target->setApplyScroll( |
| 149 m_viewportApplyScroll, | 149 m_viewportApplyScroll, |
| 150 "disable-native-scroll"); | 150 "disable-native-scroll"); |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Ideally, scroll customization would pass the current element to scroll to | 153 // Ideally, scroll customization would pass the current element to scroll to |
| 154 // the apply scroll callback but this doesn't happen today so we set it | 154 // the apply scroll callback but this doesn't happen today so we set it |
| 155 // through a back door here. | 155 // through a back door here. |
| 156 m_viewportApplyScroll->setScroller(targetScroller); | 156 m_viewportApplyScroll->setScroller(targetScroller); |
| 157 } | 157 } |
| 158 | 158 |
| 159 Element* RootScroller::defaultEffectiveRootScroller() | 159 Element* RootScrollerController::defaultEffectiveRootScroller() |
| 160 { | 160 { |
| 161 DCHECK(m_document); | 161 DCHECK(m_document); |
| 162 return m_document->documentElement(); | 162 return m_document->documentElement(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 } // namespace blink | 165 } // namespace blink |
| OLD | NEW |