Chromium Code Reviews| 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/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 Loading... | |
| 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::computeNonCompositedMainThreadScrollingReasons() { | |
| 201 // When scrolling on the main thread, the scrollableArea may or may not be | |
| 202 // composited. If it's composited and has the main thread scrolling reasons | |
| 203 // stored in its layer, the reasons have been recorded on cc side. If it | |
| 204 // dosen't have existing reasons but scrolls on main, we walk up its | |
| 205 // containing scroll chain to find the first non composited region and record | |
|
bokan
2017/04/06 14:25:24
I think this line and the section below are out of
| |
| 206 // reasons accordingly. If no such region is found or it doesn't have any main | |
| 207 // thread scrolling reason, we record the reason kUnknownNonCompositedRegion. | |
| 208 // If it's not composited, we have recorded "NonFastScrollableRegion" on | |
| 209 // the cc side. Here we try to record additional reasons that prevent | |
| 210 // promotion. | |
| 211 if (!m_scrollGestureHandlingNode->layoutObject() || !m_frame->view()) | |
| 212 return 0; | |
| 213 | |
| 214 uint32_t reasons = 0; | |
|
bokan
2017/04/06 14:25:24
rename to nonCompositedReasons or similar.
| |
| 215 bool hasScrollsOverflowAreaInChain = false; | |
| 216 | |
| 217 for (auto* curBox = | |
| 218 m_scrollGestureHandlingNode->layoutObject()->enclosingBox(); | |
| 219 curBox; curBox = curBox->containingBlock()) { | |
| 220 PaintLayerScrollableArea* scrollableArea = curBox->getScrollableArea(); | |
| 221 | |
| 222 if (!scrollableArea || !scrollableArea->scrollsOverflow()) | |
| 223 continue; | |
| 224 | |
| 225 hasScrollsOverflowAreaInChain = true; | |
| 226 uint32_t nonCompositedMainThreadScrollingReasons = | |
| 227 scrollableArea->getNonCompositedMainThreadScrollingReasons(); | |
| 228 if (scrollableArea->usesCompositedScrolling()) { | |
| 229 DCHECK(!nonCompositedMainThreadScrollingReasons); | |
|
bokan
2017/04/06 14:25:24
You shouldn't branch just because you have a DCHEC
| |
| 230 } else { | |
| 231 reasons |= nonCompositedMainThreadScrollingReasons; | |
| 232 } | |
| 233 } | |
| 234 | |
| 235 if (!reasons && hasScrollsOverflowAreaInChain && | |
| 236 !m_frame->view()->mainThreadScrollingReasons()) | |
| 237 return MainThreadScrollingReason::kUnknownNonCompositedRegion; | |
|
bokan
2017/04/06 14:25:24
Add a comment here describing this reason. i.e. Th
| |
| 238 | |
| 239 return reasons; | |
| 240 } | |
| 241 | |
| 242 void ScrollManager::recordNonCompositedMainThreadScrollingReasons( | |
| 243 const WebGestureDevice device) { | |
| 244 if (device != WebGestureDeviceTouchpad && | |
| 245 device != WebGestureDeviceTouchscreen) { | |
| 246 return; | |
| 247 } | |
| 248 | |
| 249 uint32_t reasons = computeNonCompositedMainThreadScrollingReasons(); | |
| 250 if (!reasons) | |
| 251 return; | |
| 252 DCHECK(MainThreadScrollingReason::NonCompositedScrollReasons(reasons)); | |
| 253 | |
| 254 uint32_t mainThreadScrollingReasonEnumMax = | |
| 255 MainThreadScrollingReason::kMainThreadScrollingReasonCount + 1; | |
| 256 for (uint32_t i = MainThreadScrollingReason::kNonCompositedReasonsFirst; | |
| 257 i <= MainThreadScrollingReason::kNonCompositedReasonsLast; ++i) { | |
| 258 unsigned val = 1 << i; | |
| 259 if (reasons & val) { | |
| 260 if (device == WebGestureDeviceTouchscreen) { | |
| 261 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchHistogram, | |
| 262 ("Renderer4.MainThreadGestureScrollReason", | |
| 263 mainThreadScrollingReasonEnumMax)); | |
| 264 touchHistogram.count(i + 1); | |
| 265 } else { | |
| 266 DEFINE_STATIC_LOCAL(EnumerationHistogram, wheelHistogram, | |
| 267 ("Renderer4.MainThreadWheelScrollReason", | |
| 268 mainThreadScrollingReasonEnumMax)); | |
| 269 wheelHistogram.count(i + 1); | |
| 270 } | |
| 271 } | |
| 272 } | |
| 273 } | |
| 274 | |
| 199 WebInputEventResult ScrollManager::handleGestureScrollBegin( | 275 WebInputEventResult ScrollManager::handleGestureScrollBegin( |
| 200 const WebGestureEvent& gestureEvent) { | 276 const WebGestureEvent& gestureEvent) { |
| 201 Document* document = m_frame->document(); | 277 Document* document = m_frame->document(); |
| 202 | 278 |
| 203 if (document->layoutViewItem().isNull()) | 279 if (document->layoutViewItem().isNull()) |
| 204 return WebInputEventResult::NotHandled; | 280 return WebInputEventResult::NotHandled; |
| 205 | 281 |
| 206 // If there's no layoutObject on the node, send the event to the nearest | 282 // 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 | 283 // ancestor with a layoutObject. Needed for <option> and <optgroup> elements |
| 208 // so we can touch scroll <select>s | 284 // so we can touch scroll <select>s |
| 209 while (m_scrollGestureHandlingNode && | 285 while (m_scrollGestureHandlingNode && |
| 210 !m_scrollGestureHandlingNode->layoutObject()) | 286 !m_scrollGestureHandlingNode->layoutObject()) |
| 211 m_scrollGestureHandlingNode = | 287 m_scrollGestureHandlingNode = |
| 212 m_scrollGestureHandlingNode->parentOrShadowHostNode(); | 288 m_scrollGestureHandlingNode->parentOrShadowHostNode(); |
| 213 | 289 |
| 214 if (!m_scrollGestureHandlingNode) | 290 if (!m_scrollGestureHandlingNode) |
| 215 m_scrollGestureHandlingNode = m_frame->document()->documentElement(); | 291 m_scrollGestureHandlingNode = m_frame->document()->documentElement(); |
| 216 | 292 |
| 217 if (!m_scrollGestureHandlingNode || | 293 if (!m_scrollGestureHandlingNode || |
| 218 !m_scrollGestureHandlingNode->layoutObject()) | 294 !m_scrollGestureHandlingNode->layoutObject()) |
| 219 return WebInputEventResult::NotHandled; | 295 return WebInputEventResult::NotHandled; |
| 220 | 296 |
| 221 passScrollGestureEvent(gestureEvent, | 297 passScrollGestureEvent(gestureEvent, |
| 222 m_scrollGestureHandlingNode->layoutObject()); | 298 m_scrollGestureHandlingNode->layoutObject()); |
| 223 | 299 |
| 300 recordNonCompositedMainThreadScrollingReasons(gestureEvent.sourceDevice); | |
| 301 | |
| 224 m_currentScrollChain.clear(); | 302 m_currentScrollChain.clear(); |
| 225 std::unique_ptr<ScrollStateData> scrollStateData = | 303 std::unique_ptr<ScrollStateData> scrollStateData = |
| 226 WTF::makeUnique<ScrollStateData>(); | 304 WTF::makeUnique<ScrollStateData>(); |
| 227 IntPoint position = flooredIntPoint(gestureEvent.positionInRootFrame()); | 305 IntPoint position = flooredIntPoint(gestureEvent.positionInRootFrame()); |
| 228 scrollStateData->position_x = position.x(); | 306 scrollStateData->position_x = position.x(); |
| 229 scrollStateData->position_y = position.y(); | 307 scrollStateData->position_y = position.y(); |
| 230 scrollStateData->is_beginning = true; | 308 scrollStateData->is_beginning = true; |
| 231 scrollStateData->from_user_input = true; | 309 scrollStateData->from_user_input = true; |
| 232 scrollStateData->is_direct_manipulation = | 310 scrollStateData->is_direct_manipulation = |
| 233 gestureEvent.sourceDevice == WebGestureDeviceTouchscreen; | 311 gestureEvent.sourceDevice == WebGestureDeviceTouchscreen; |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 if (scrollbar->gestureEvent(targetedEvent.event(), &shouldUpdateCapture)) { | 638 if (scrollbar->gestureEvent(targetedEvent.event(), &shouldUpdateCapture)) { |
| 561 if (shouldUpdateCapture) | 639 if (shouldUpdateCapture) |
| 562 m_scrollbarHandlingScrollGesture = scrollbar; | 640 m_scrollbarHandlingScrollGesture = scrollbar; |
| 563 return true; | 641 return true; |
| 564 } | 642 } |
| 565 } | 643 } |
| 566 return false; | 644 return false; |
| 567 } | 645 } |
| 568 | 646 |
| 569 } // namespace blink | 647 } // namespace blink |
| OLD | NEW |