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

Side by Side Diff: third_party/WebKit/Source/core/input/ScrollManager.cpp

Issue 2769793002: Implement CSS: scroll-boundary-behavior (Closed)
Patch Set: Use only gpuBenchmarking. Created 3 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 // 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/input/ScrollManager.h" 5 #include "core/input/ScrollManager.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include "core/dom/DOMNodeIds.h" 8 #include "core/dom/DOMNodeIds.h"
9 #include "core/dom/NodeComputedStyle.h"
9 #include "core/events/GestureEvent.h" 10 #include "core/events/GestureEvent.h"
10 #include "core/frame/BrowserControls.h" 11 #include "core/frame/BrowserControls.h"
11 #include "core/frame/FrameView.h" 12 #include "core/frame/FrameView.h"
12 #include "core/html/HTMLFrameOwnerElement.h" 13 #include "core/html/HTMLFrameOwnerElement.h"
13 #include "core/input/EventHandler.h" 14 #include "core/input/EventHandler.h"
14 #include "core/input/EventHandlingUtil.h" 15 #include "core/input/EventHandlingUtil.h"
15 #include "core/layout/LayoutBlock.h" 16 #include "core/layout/LayoutBlock.h"
16 #include "core/layout/LayoutPart.h" 17 #include "core/layout/LayoutPart.h"
17 #include "core/layout/api/LayoutViewItem.h" 18 #include "core/layout/api/LayoutViewItem.h"
18 #include "core/loader/DocumentLoader.h" 19 #include "core/loader/DocumentLoader.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 GetAutoscrollController()->MiddleClickAutoscrollInProgress(); 73 GetAutoscrollController()->MiddleClickAutoscrollInProgress();
73 } 74 }
74 75
75 AutoscrollController* ScrollManager::GetAutoscrollController() const { 76 AutoscrollController* ScrollManager::GetAutoscrollController() const {
76 if (Page* page = frame_->GetPage()) 77 if (Page* page = frame_->GetPage())
77 return &page->GetAutoscrollController(); 78 return &page->GetAutoscrollController();
78 return nullptr; 79 return nullptr;
79 } 80 }
80 81
81 void ScrollManager::RecomputeScrollChain(const Node& start_node, 82 void ScrollManager::RecomputeScrollChain(const Node& start_node,
83 const ScrollState& scroll_state,
82 std::deque<int>& scroll_chain) { 84 std::deque<int>& scroll_chain) {
83 scroll_chain.clear(); 85 scroll_chain.clear();
84 86
85 DCHECK(start_node.GetLayoutObject()); 87 DCHECK(start_node.GetLayoutObject());
86 LayoutBox* cur_box = start_node.GetLayoutObject()->EnclosingBox(); 88 LayoutBox* cur_box = start_node.GetLayoutObject()->EnclosingBox();
87 Element* document_element = frame_->GetDocument()->documentElement(); 89 Element* document_element = frame_->GetDocument()->documentElement();
90 bool x_dominated =
91 (std::abs(scroll_state.deltaX()) > std::abs(scroll_state.deltaY()));
88 92
89 // Scrolling propagates along the containing block chain and ends at the 93 // Scrolling propagates along the containing block chain and ends at the
90 // RootScroller element. The RootScroller element will have a custom 94 // RootScroller element. The RootScroller element will have a custom
91 // applyScroll callback that scrolls the frame or element. 95 // applyScroll callback that scrolls the frame or element.
92 while (cur_box) { 96 while (cur_box) {
93 Node* cur_node = cur_box->GetNode(); 97 Node* cur_node = cur_box->GetNode();
94 Element* cur_element = nullptr; 98 Element* cur_element = nullptr;
95 99
96 // FIXME: this should reject more elements, as part of crbug.com/410974. 100 // FIXME: this should reject more elements, as part of crbug.com/410974.
97 if (cur_node && cur_node->IsElementNode()) { 101 if (cur_node && cur_node->IsElementNode()) {
98 cur_element = ToElement(cur_node); 102 cur_element = ToElement(cur_node);
99 } else if (cur_node && cur_node->IsDocumentNode()) { 103 } else if (cur_node && cur_node->IsDocumentNode()) {
100 // In normal circumastances, the documentElement will be the root 104 // In normal circumastances, the documentElement will be the root
101 // scroller but the documentElement itself isn't a containing block, 105 // scroller but the documentElement itself isn't a containing block,
102 // that'll be the document node rather than the element. 106 // that'll be the document node rather than the element.
103 cur_element = document_element; 107 cur_element = document_element;
104 } 108 }
105 109
106 if (cur_element) { 110 if (cur_element) {
107 scroll_chain.push_front(DOMNodeIds::IdForNode(cur_element)); 111 scroll_chain.push_front(DOMNodeIds::IdForNode(cur_element));
108 if (IsViewportScrollingElement(*cur_element) || 112 if (IsViewportScrollingElement(*cur_element) ||
109 cur_element == document_element) 113 cur_element == document_element)
110 break; 114 break;
115
116 if ((x_dominated &&
117 cur_element->GetComputedStyle()->ScrollBoundaryBehaviorX() !=
118 EScrollBoundaryBehavior::kAuto) ||
119 (!x_dominated &&
120 cur_element->GetComputedStyle()->ScrollBoundaryBehaviorY() !=
121 EScrollBoundaryBehavior::kAuto))
122 break;
111 } 123 }
112 124
113 cur_box = cur_box->ContainingBlock(); 125 cur_box = cur_box->ContainingBlock();
114 } 126 }
115 } 127 }
116 128
117 bool ScrollManager::LogicalScroll(ScrollDirection direction, 129 bool ScrollManager::LogicalScroll(ScrollDirection direction,
118 ScrollGranularity granularity, 130 ScrollGranularity granularity,
119 Node* start_node, 131 Node* start_node,
120 Node* mouse_press_node) { 132 Node* mouse_press_node) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 void ScrollManager::SetFrameWasScrolledByUser() { 193 void ScrollManager::SetFrameWasScrolledByUser() {
182 if (DocumentLoader* document_loader = frame_->Loader().GetDocumentLoader()) 194 if (DocumentLoader* document_loader = frame_->Loader().GetDocumentLoader())
183 document_loader->GetInitialScrollState().was_scrolled_by_user = true; 195 document_loader->GetInitialScrollState().was_scrolled_by_user = true;
184 } 196 }
185 197
186 void ScrollManager::CustomizedScroll(const Node& start_node, 198 void ScrollManager::CustomizedScroll(const Node& start_node,
187 ScrollState& scroll_state) { 199 ScrollState& scroll_state) {
188 if (scroll_state.FullyConsumed()) 200 if (scroll_state.FullyConsumed())
189 return; 201 return;
190 202
191 if (scroll_state.deltaX() || scroll_state.deltaY()) 203 if (scroll_state.deltaX() || scroll_state.deltaY()) {
192 frame_->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); 204 frame_->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
205 if (current_scroll_chain_.empty())
206 RecomputeScrollChain(start_node, scroll_state, current_scroll_chain_);
207 scroll_state.SetScrollChain(current_scroll_chain_);
193 208
194 if (current_scroll_chain_.empty()) 209 scroll_state.distributeToScrollChainDescendant();
195 RecomputeScrollChain(start_node, current_scroll_chain_); 210 }
196 scroll_state.SetScrollChain(current_scroll_chain_);
197
198 scroll_state.distributeToScrollChainDescendant();
199 } 211 }
200 212
201 void ScrollManager::ComputeScrollRelatedMetrics( 213 void ScrollManager::ComputeScrollRelatedMetrics(
202 uint32_t* non_composited_main_thread_scrolling_reasons, 214 uint32_t* non_composited_main_thread_scrolling_reasons,
203 int* scroller_size) { 215 int* scroller_size) {
204 // When scrolling on the main thread, the scrollableArea may or may not be 216 // When scrolling on the main thread, the scrollableArea may or may not be
205 // composited. Either way, we have recorded either the reasons stored in 217 // composited. Either way, we have recorded either the reasons stored in
206 // its layer or the reason NonFastScrollableRegion from the compositor 218 // its layer or the reason NonFastScrollableRegion from the compositor
207 // side. Here we record scrolls that occurred on main thread due to a 219 // side. Here we record scrolls that occurred on main thread due to a
208 // non-composited scroller. 220 // non-composited scroller.
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 &should_update_capture)) { 666 &should_update_capture)) {
655 if (should_update_capture) 667 if (should_update_capture)
656 scrollbar_handling_scroll_gesture_ = scrollbar; 668 scrollbar_handling_scroll_gesture_ = scrollbar;
657 return true; 669 return true;
658 } 670 }
659 } 671 }
660 return false; 672 return false;
661 } 673 }
662 674
663 } // namespace blink 675 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698