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

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

Issue 2773593005: Move logic of recording main thread scrolling reasons from cc to blink::ScrollManager (Closed)
Patch Set: nit Created 3 years, 9 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/events/GestureEvent.h" 9 #include "core/events/GestureEvent.h"
10 #include "core/frame/BrowserControls.h" 10 #include "core/frame/BrowserControls.h"
11 #include "core/frame/FrameView.h" 11 #include "core/frame/FrameView.h"
12 #include "core/html/HTMLFrameOwnerElement.h" 12 #include "core/html/HTMLFrameOwnerElement.h"
13 #include "core/input/EventHandler.h" 13 #include "core/input/EventHandler.h"
14 #include "core/input/EventHandlingUtil.h" 14 #include "core/input/EventHandlingUtil.h"
15 #include "core/layout/LayoutBlock.h" 15 #include "core/layout/LayoutBlock.h"
16 #include "core/layout/LayoutPart.h" 16 #include "core/layout/LayoutPart.h"
17 #include "core/layout/api/LayoutViewItem.h" 17 #include "core/layout/api/LayoutViewItem.h"
18 #include "core/loader/DocumentLoader.h" 18 #include "core/loader/DocumentLoader.h"
19 #include "core/page/AutoscrollController.h" 19 #include "core/page/AutoscrollController.h"
20 #include "core/page/Page.h" 20 #include "core/page/Page.h"
21 #include "core/page/scrolling/OverscrollController.h" 21 #include "core/page/scrolling/OverscrollController.h"
22 #include "core/page/scrolling/RootScrollerController.h" 22 #include "core/page/scrolling/RootScrollerController.h"
23 #include "core/page/scrolling/ScrollState.h" 23 #include "core/page/scrolling/ScrollState.h"
24 #include "core/paint/PaintLayer.h" 24 #include "core/paint/PaintLayer.h"
25 #include "platform/Histogram.h"
25 #include "platform/RuntimeEnabledFeatures.h" 26 #include "platform/RuntimeEnabledFeatures.h"
26 #include "wtf/PtrUtil.h" 27 #include "wtf/PtrUtil.h"
27 28
28 namespace blink { 29 namespace blink {
29 30
30 ScrollManager::ScrollManager(LocalFrame& frame) : m_frame(frame) { 31 ScrollManager::ScrollManager(LocalFrame& frame) : m_frame(frame) {
31 clear(); 32 clear();
32 } 33 }
33 34
34 void ScrollManager::clear() { 35 void ScrollManager::clear() {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 if (scrollState.deltaX() || scrollState.deltaY()) 190 if (scrollState.deltaX() || scrollState.deltaY())
190 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 191 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
191 192
192 if (m_currentScrollChain.empty()) 193 if (m_currentScrollChain.empty())
193 recomputeScrollChain(startNode, m_currentScrollChain); 194 recomputeScrollChain(startNode, m_currentScrollChain);
194 scrollState.setScrollChain(m_currentScrollChain); 195 scrollState.setScrollChain(m_currentScrollChain);
195 196
196 scrollState.distributeToScrollChainDescendant(); 197 scrollState.distributeToScrollChainDescendant();
197 } 198 }
198 199
200 uint32_t ScrollManager::computeMainThreadScrollingReasons(const Node& node) {
201 if (!m_frame || !m_frame->view())
202 return 0;
203 uint32_t reasons = m_frame->view()->mainThreadScrollingReasons();
204 LayoutBox* curBox = node.layoutObject()->enclosingBox();
205 Element* documentElement = m_frame->document()->documentElement();
206 while (curBox) {
207 Node* curNode = curBox->node();
208 Element* curElement = nullptr;
209 // FIXME: this should reject more elements, as part of crbug.com/410974.
210 if (curNode && curNode->isElementNode()) {
211 curElement = toElement(curNode);
212 } else if (curNode && curNode->isDocumentNode()) {
213 // In normal circumastances, the documentElement will be the root
214 // scroller but the documentElement itself isn't a containing block,
215 // that'll be the document node rather than the element.
216 curElement = documentElement;
bokan 2017/03/24 17:55:54 Document-scrolling is always composited so we don'
yigu 2017/03/27 21:02:07 Done.
217 } else {
218 curBox = curBox->containingBlock();
219 continue;
220 }
221 if (curElement) {
222 if (isViewportScrollingElement(*curElement) ||
223 curElement == documentElement)
224 break;
225 }
226 if (curNode->layoutBoxModelObject() &&
227 curNode->layoutBoxModelObject()->getScrollableArea()) {
228 reasons |= curNode->layoutBoxModelObject()
bokan 2017/03/24 17:55:54 Given that I think since we'll record the other ma
yigu 2017/03/27 21:02:07 Done.
229 ->getScrollableArea()
230 ->getStyleRelatedMainThreadScrollingReasons();
231 }
232 curBox = curBox->containingBlock();
233 }
234 return reasons;
235 }
236
237 void ScrollManager::recordMainThreadScrollingReasons(
238 const uint32_t reasons,
239 const WebGestureDevice device) {
240 uint32_t mainThreadScrollingReasonEnumMax =
241 MainThreadScrollingReason::kMainThreadScrollingReasonCount + 1;
242 for (uint32_t i = 0;
243 i < MainThreadScrollingReason::kMainThreadScrollingReasonCount; ++i) {
244 unsigned val = 1 << i;
245 if (reasons & val) {
246 if (val == MainThreadScrollingReason::kHandlingScrollFromMainThread) {
247 // We only want to record "Handling scroll from main thread" reason if
248 // it's the only reason. If it's not the only reason, the "real"
249 // reason for scrolling on main is something else, and we only want to
250 // pay attention to that reason.
251 if (reasons & ~val)
252 continue;
253 }
254 if (device == WebGestureDeviceTouchscreen) {
255 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchHistogram,
256 ("Renderer4.MainThreadGestureScrollReason",
257 mainThreadScrollingReasonEnumMax));
258 touchHistogram.count(i + 1);
259 } else {
260 DEFINE_STATIC_LOCAL(EnumerationHistogram, wheelHistogram,
261 ("Renderer4.MainThreadWheelScrollReason",
262 mainThreadScrollingReasonEnumMax));
263 wheelHistogram.count(i + 1);
264 }
265 }
266 }
267 }
268
199 WebInputEventResult ScrollManager::handleGestureScrollBegin( 269 WebInputEventResult ScrollManager::handleGestureScrollBegin(
200 const WebGestureEvent& gestureEvent) { 270 const WebGestureEvent& gestureEvent) {
201 Document* document = m_frame->document(); 271 Document* document = m_frame->document();
202 272
203 if (document->layoutViewItem().isNull()) 273 if (document->layoutViewItem().isNull())
204 return WebInputEventResult::NotHandled; 274 return WebInputEventResult::NotHandled;
205 275
206 // If there's no layoutObject on the node, send the event to the nearest 276 // If there's no layoutObject on the node, send the event to the nearest
207 // ancestor with a layoutObject. Needed for <option> and <optgroup> elements 277 // ancestor with a layoutObject. Needed for <option> and <optgroup> elements
208 // so we can touch scroll <select>s 278 // so we can touch scroll <select>s
209 while (m_scrollGestureHandlingNode && 279 while (m_scrollGestureHandlingNode &&
210 !m_scrollGestureHandlingNode->layoutObject()) 280 !m_scrollGestureHandlingNode->layoutObject())
211 m_scrollGestureHandlingNode = 281 m_scrollGestureHandlingNode =
212 m_scrollGestureHandlingNode->parentOrShadowHostNode(); 282 m_scrollGestureHandlingNode->parentOrShadowHostNode();
213 283
214 if (!m_scrollGestureHandlingNode) 284 if (!m_scrollGestureHandlingNode)
215 m_scrollGestureHandlingNode = m_frame->document()->documentElement(); 285 m_scrollGestureHandlingNode = m_frame->document()->documentElement();
216 286
217 if (!m_scrollGestureHandlingNode || 287 if (!m_scrollGestureHandlingNode ||
218 !m_scrollGestureHandlingNode->layoutObject()) 288 !m_scrollGestureHandlingNode->layoutObject())
219 return WebInputEventResult::NotHandled; 289 return WebInputEventResult::NotHandled;
220 290
221 passScrollGestureEvent(gestureEvent, 291 passScrollGestureEvent(gestureEvent,
222 m_scrollGestureHandlingNode->layoutObject()); 292 m_scrollGestureHandlingNode->layoutObject());
223 293
294 if (m_scrollGestureHandlingNode->layoutObject() &&
295 (gestureEvent.sourceDevice == WebGestureDeviceTouchpad ||
296 gestureEvent.sourceDevice == WebGestureDeviceTouchscreen)) {
297 uint32_t reasons =
298 computeMainThreadScrollingReasons(*m_scrollGestureHandlingNode);
299 if (reasons)
bokan 2017/03/24 17:55:54 Move all the additions above into recordMainThread
300 recordMainThreadScrollingReasons(reasons, gestureEvent.sourceDevice);
301 }
302
224 m_currentScrollChain.clear(); 303 m_currentScrollChain.clear();
225 std::unique_ptr<ScrollStateData> scrollStateData = 304 std::unique_ptr<ScrollStateData> scrollStateData =
226 WTF::makeUnique<ScrollStateData>(); 305 WTF::makeUnique<ScrollStateData>();
227 IntPoint position = flooredIntPoint(gestureEvent.positionInRootFrame()); 306 IntPoint position = flooredIntPoint(gestureEvent.positionInRootFrame());
228 scrollStateData->position_x = position.x(); 307 scrollStateData->position_x = position.x();
229 scrollStateData->position_y = position.y(); 308 scrollStateData->position_y = position.y();
230 scrollStateData->is_beginning = true; 309 scrollStateData->is_beginning = true;
231 scrollStateData->from_user_input = true; 310 scrollStateData->from_user_input = true;
232 scrollStateData->is_direct_manipulation = 311 scrollStateData->is_direct_manipulation =
233 gestureEvent.sourceDevice == WebGestureDeviceTouchscreen; 312 gestureEvent.sourceDevice == WebGestureDeviceTouchscreen;
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 if (scrollbar->gestureEvent(targetedEvent.event(), &shouldUpdateCapture)) { 632 if (scrollbar->gestureEvent(targetedEvent.event(), &shouldUpdateCapture)) {
554 if (shouldUpdateCapture) 633 if (shouldUpdateCapture)
555 m_scrollbarHandlingScrollGesture = scrollbar; 634 m_scrollbarHandlingScrollGesture = scrollbar;
556 return true; 635 return true;
557 } 636 }
558 } 637 }
559 return false; 638 return false;
560 } 639 }
561 640
562 } // namespace blink 641 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698