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

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

Issue 2769793002: Implement CSS: scroll-boundary-behavior (Closed)
Patch Set: Update promises tests and Scroll Manager Created 3 years, 5 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/LocalFrameView.h" 12 #include "core/frame/LocalFrameView.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/LayoutEmbeddedContent.h" 17 #include "core/layout/LayoutEmbeddedContent.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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // that'll be the document node rather than the element. 111 // that'll be the document node rather than the element.
111 cur_element = document_element; 112 cur_element = document_element;
112 } 113 }
113 114
114 if (cur_element) { 115 if (cur_element) {
115 if (CanScroll(scroll_state, *cur_element)) 116 if (CanScroll(scroll_state, *cur_element))
116 scroll_chain.push_front(DOMNodeIds::IdForNode(cur_element)); 117 scroll_chain.push_front(DOMNodeIds::IdForNode(cur_element));
117 if (IsViewportScrollingElement(*cur_element) || 118 if (IsViewportScrollingElement(*cur_element) ||
118 cur_element == document_element) 119 cur_element == document_element)
119 break; 120 break;
121
122 if (!CanPropagate(scroll_state, *cur_element))
123 break;
120 } 124 }
121 125
122 cur_box = cur_box->ContainingBlock(); 126 cur_box = cur_box->ContainingBlock();
123 } 127 }
124 } 128 }
125 129
126 bool ScrollManager::CanScroll(const ScrollState& scroll_state, 130 bool ScrollManager::CanScroll(const ScrollState& scroll_state,
127 const Element& current_element) { 131 const Element& current_element) {
128 const double delta_x = scroll_state.isBeginning() ? scroll_state.deltaXHint() 132 const double delta_x = scroll_state.isBeginning() ? scroll_state.deltaXHint()
129 : scroll_state.deltaX(); 133 : scroll_state.deltaX();
(...skipping 15 matching lines...) Expand all
145 if (!scrollable_area) 149 if (!scrollable_area)
146 return false; 150 return false;
147 151
148 ScrollOffset current_offset = scrollable_area->GetScrollOffset(); 152 ScrollOffset current_offset = scrollable_area->GetScrollOffset();
149 ScrollOffset target_offset = current_offset + ScrollOffset(delta_x, delta_y); 153 ScrollOffset target_offset = current_offset + ScrollOffset(delta_x, delta_y);
150 ScrollOffset clamped_offset = 154 ScrollOffset clamped_offset =
151 scrollable_area->ClampScrollOffset(target_offset); 155 scrollable_area->ClampScrollOffset(target_offset);
152 return clamped_offset != current_offset; 156 return clamped_offset != current_offset;
153 } 157 }
154 158
159 bool ScrollManager::CanPropagate(const ScrollState& scroll_state,
160 const Element& current_element) {
majidvp 2017/07/14 14:29:44 ditto. This function does not need to be a member
sunyunjia 2017/07/14 22:07:24 Done.
161 // ScrollBoundaryBehavior may have different values on x-axis and y-axis.
162 // We need to find out the dominant axis of user's intended scroll to decide
163 // which ScrollBoundaryBehavior should be applied, i.e. which node should
164 // be scrolled.
majidvp 2017/07/14 14:29:44 ditto. the last sentence of the comment is not acc
sunyunjia 2017/07/14 22:07:24 Done.
165 bool x_dominant =
166 std::abs(scroll_state.deltaXHint()) > std::abs(scroll_state.deltaYHint());
167 return (x_dominant &&
168 current_element.GetComputedStyle()->ScrollBoundaryBehaviorX() ==
169 EScrollBoundaryBehavior::kAuto) ||
170 (!x_dominant &&
171 current_element.GetComputedStyle()->ScrollBoundaryBehaviorY() ==
172 EScrollBoundaryBehavior::kAuto);
173 }
174
155 bool ScrollManager::LogicalScroll(ScrollDirection direction, 175 bool ScrollManager::LogicalScroll(ScrollDirection direction,
156 ScrollGranularity granularity, 176 ScrollGranularity granularity,
157 Node* start_node, 177 Node* start_node,
158 Node* mouse_press_node) { 178 Node* mouse_press_node) {
159 Node* node = start_node; 179 Node* node = start_node;
160 180
161 if (!node) 181 if (!node)
162 node = frame_->GetDocument()->FocusedElement(); 182 node = frame_->GetDocument()->FocusedElement();
163 183
164 if (!node) 184 if (!node)
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 &should_update_capture)) { 726 &should_update_capture)) {
707 if (should_update_capture) 727 if (should_update_capture)
708 scrollbar_handling_scroll_gesture_ = scrollbar; 728 scrollbar_handling_scroll_gesture_ = scrollbar;
709 return true; 729 return true;
710 } 730 }
711 } 731 }
712 return false; 732 return false;
713 } 733 }
714 734
715 } // namespace blink 735 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698