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/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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 return GetAutoscrollController() && | 78 return GetAutoscrollController() && |
78 GetAutoscrollController()->MiddleClickAutoscrollInProgress(); | 79 GetAutoscrollController()->MiddleClickAutoscrollInProgress(); |
79 } | 80 } |
80 | 81 |
81 AutoscrollController* ScrollManager::GetAutoscrollController() const { | 82 AutoscrollController* ScrollManager::GetAutoscrollController() const { |
82 if (Page* page = frame_->GetPage()) | 83 if (Page* page = frame_->GetPage()) |
83 return &page->GetAutoscrollController(); | 84 return &page->GetAutoscrollController(); |
84 return nullptr; | 85 return nullptr; |
85 } | 86 } |
86 | 87 |
| 88 static bool CanPropagate(const ScrollState& scroll_state, |
| 89 const Element& element) { |
| 90 // ScrollBoundaryBehavior may have different values on x-axis and y-axis. |
| 91 // We need to find out the dominant axis of user's intended scroll to decide |
| 92 // which node's ScrollBoundaryBehavior should be applied, i.e. which the |
| 93 // scroll should be propagated from this node given its relevant* |
| 94 // ScrollBoundaryBehavior value. * relevant here depends on the dominant |
| 95 // axis of scroll gesture. |
| 96 bool x_dominant = |
| 97 std::abs(scroll_state.deltaXHint()) > std::abs(scroll_state.deltaYHint()); |
| 98 return (x_dominant && element.GetComputedStyle()->ScrollBoundaryBehaviorX() == |
| 99 EScrollBoundaryBehavior::kAuto) || |
| 100 (!x_dominant && |
| 101 element.GetComputedStyle()->ScrollBoundaryBehaviorY() == |
| 102 EScrollBoundaryBehavior::kAuto); |
| 103 } |
| 104 |
87 void ScrollManager::RecomputeScrollChain(const Node& start_node, | 105 void ScrollManager::RecomputeScrollChain(const Node& start_node, |
88 const ScrollState& scroll_state, | 106 const ScrollState& scroll_state, |
89 std::deque<int>& scroll_chain) { | 107 std::deque<int>& scroll_chain) { |
90 DCHECK(!scroll_chain.size()); | 108 DCHECK(!scroll_chain.size()); |
91 scroll_chain.clear(); | 109 scroll_chain.clear(); |
92 | 110 |
93 DCHECK(start_node.GetLayoutObject()); | 111 DCHECK(start_node.GetLayoutObject()); |
94 LayoutBox* cur_box = start_node.GetLayoutObject()->EnclosingBox(); | 112 LayoutBox* cur_box = start_node.GetLayoutObject()->EnclosingBox(); |
95 Element* document_element = frame_->GetDocument()->documentElement(); | 113 Element* document_element = frame_->GetDocument()->documentElement(); |
96 | 114 |
(...skipping 13 matching lines...) Expand all Loading... |
110 // that'll be the document node rather than the element. | 128 // that'll be the document node rather than the element. |
111 cur_element = document_element; | 129 cur_element = document_element; |
112 } | 130 } |
113 | 131 |
114 if (cur_element) { | 132 if (cur_element) { |
115 if (CanScroll(scroll_state, *cur_element)) | 133 if (CanScroll(scroll_state, *cur_element)) |
116 scroll_chain.push_front(DOMNodeIds::IdForNode(cur_element)); | 134 scroll_chain.push_front(DOMNodeIds::IdForNode(cur_element)); |
117 if (IsViewportScrollingElement(*cur_element) || | 135 if (IsViewportScrollingElement(*cur_element) || |
118 cur_element == document_element) | 136 cur_element == document_element) |
119 break; | 137 break; |
| 138 |
| 139 if (!CanPropagate(scroll_state, *cur_element)) |
| 140 break; |
120 } | 141 } |
121 | 142 |
122 cur_box = cur_box->ContainingBlock(); | 143 cur_box = cur_box->ContainingBlock(); |
123 } | 144 } |
124 } | 145 } |
125 | 146 |
126 bool ScrollManager::CanScroll(const ScrollState& scroll_state, | 147 bool ScrollManager::CanScroll(const ScrollState& scroll_state, |
127 const Element& current_element) { | 148 const Element& current_element) { |
128 const double delta_x = scroll_state.isBeginning() ? scroll_state.deltaXHint() | 149 const double delta_x = scroll_state.isBeginning() ? scroll_state.deltaXHint() |
129 : scroll_state.deltaX(); | 150 : scroll_state.deltaX(); |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 &should_update_capture)) { | 727 &should_update_capture)) { |
707 if (should_update_capture) | 728 if (should_update_capture) |
708 scrollbar_handling_scroll_gesture_ = scrollbar; | 729 scrollbar_handling_scroll_gesture_ = scrollbar; |
709 return true; | 730 return true; |
710 } | 731 } |
711 } | 732 } |
712 return false; | 733 return false; |
713 } | 734 } |
714 | 735 |
715 } // namespace blink | 736 } // namespace blink |
OLD | NEW |