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 // When scrolling on the main thread, the scrollableArea may or may not be | |
| 201 // composited. | |
|
bokan
2017/03/31 16:55:53
super-nit: No need for an early line break here, w
| |
| 202 // 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 dosen't | |
| 204 // have existing reasons but scrolls on main, we walk up its containing scroll | |
| 205 // chain to find the first non composited region and record reaons accordingly. | |
|
bokan
2017/03/31 16:55:53
nit: reaons->reasons
| |
| 206 // If no such region is found or it doesn't have any main thread scorlling | |
|
bokan
2017/03/31 16:55:53
nit: scorlling->scrolling
| |
| 207 // 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 promotion. | |
| 210 uint32_t ScrollManager::computeNonCompositedMainThreadScrollingReasons() { | |
| 211 if (!m_scrollGestureHandlingNode->layoutObject() || !m_frame->view()) | |
| 212 return 0; | |
| 213 uint32_t reasons = 0; | |
| 214 LayoutBox* curBox = | |
| 215 m_scrollGestureHandlingNode->layoutObject()->enclosingBox(); | |
| 216 bool compositedMainThreadScrollForUnknownReasons = false; | |
| 217 | |
| 218 while (curBox) { | |
| 219 if (auto* scrollableArea = curBox->getScrollableArea()) { | |
|
bokan
2017/03/31 16:55:52
The repeated indents here make the code harder to
| |
| 220 if (scrollableArea->usesCompositedScrolling()) { | |
| 221 if (m_frame->view()->mainThreadScrollingReasons()) { | |
| 222 return 0; | |
|
bokan
2017/03/31 16:55:53
I don't think you need this early return since it
| |
| 223 } | |
| 224 compositedMainThreadScrollForUnknownReasons = true; | |
|
bokan
2017/03/31 16:55:53
We want to record "Unknown" if and only if we didn
| |
| 225 } else { | |
| 226 reasons = scrollableArea->getNonCompositedMainThreadScrollingReasons(); | |
|
bokan
2017/03/31 16:55:53
Add a DCHECK here that we have a reason.
| |
| 227 break; | |
| 228 } | |
| 229 } | |
| 230 curBox = curBox->containingBlock(); | |
| 231 } | |
| 232 | |
| 233 if (!reasons && compositedMainThreadScrollForUnknownReasons) | |
| 234 return MainThreadScrollingReason::kUnknownNonCompositedRegion; | |
| 235 | |
| 236 return reasons; | |
|
bokan
2017/03/31 16:55:53
Add a DCHECK here that reasons only contains NonCo
| |
| 237 } | |
| 238 | |
| 239 void ScrollManager::recordNonCompositedMainThreadScrollingReasons( | |
| 240 const WebGestureDevice device) { | |
| 241 if (device != WebGestureDeviceTouchpad && | |
| 242 device != WebGestureDeviceTouchscreen) { | |
| 243 return; | |
| 244 } | |
| 245 | |
| 246 uint32_t reasons = computeNonCompositedMainThreadScrollingReasons(); | |
| 247 if (!reasons) | |
| 248 return; | |
| 249 | |
| 250 uint32_t mainThreadScrollingReasonEnumMax = | |
| 251 MainThreadScrollingReason::kMainThreadScrollingReasonCount + 1; | |
| 252 for (uint32_t i = 0; | |
| 253 i < MainThreadScrollingReason::kMainThreadScrollingReasonCount; ++i) { | |
|
bokan
2017/03/31 16:55:52
You only need to loop over the NonCompositedScroll
| |
| 254 unsigned val = 1 << i; | |
| 255 if (reasons & val) { | |
| 256 if (device == WebGestureDeviceTouchscreen) { | |
| 257 DEFINE_STATIC_LOCAL(EnumerationHistogram, touchHistogram, | |
| 258 ("Renderer4.MainThreadGestureScrollReason", | |
| 259 mainThreadScrollingReasonEnumMax)); | |
| 260 touchHistogram.count(i + 1); | |
| 261 } else { | |
| 262 DEFINE_STATIC_LOCAL(EnumerationHistogram, wheelHistogram, | |
| 263 ("Renderer4.MainThreadWheelScrollReason", | |
| 264 mainThreadScrollingReasonEnumMax)); | |
| 265 wheelHistogram.count(i + 1); | |
| 266 } | |
| 267 } | |
| 268 } | |
| 269 } | |
| 270 | |
| 199 WebInputEventResult ScrollManager::handleGestureScrollBegin( | 271 WebInputEventResult ScrollManager::handleGestureScrollBegin( |
| 200 const WebGestureEvent& gestureEvent) { | 272 const WebGestureEvent& gestureEvent) { |
| 201 Document* document = m_frame->document(); | 273 Document* document = m_frame->document(); |
| 202 | 274 |
| 203 if (document->layoutViewItem().isNull()) | 275 if (document->layoutViewItem().isNull()) |
| 204 return WebInputEventResult::NotHandled; | 276 return WebInputEventResult::NotHandled; |
| 205 | 277 |
| 206 // If there's no layoutObject on the node, send the event to the nearest | 278 // 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 | 279 // ancestor with a layoutObject. Needed for <option> and <optgroup> elements |
| 208 // so we can touch scroll <select>s | 280 // so we can touch scroll <select>s |
| 209 while (m_scrollGestureHandlingNode && | 281 while (m_scrollGestureHandlingNode && |
| 210 !m_scrollGestureHandlingNode->layoutObject()) | 282 !m_scrollGestureHandlingNode->layoutObject()) |
| 211 m_scrollGestureHandlingNode = | 283 m_scrollGestureHandlingNode = |
| 212 m_scrollGestureHandlingNode->parentOrShadowHostNode(); | 284 m_scrollGestureHandlingNode->parentOrShadowHostNode(); |
| 213 | 285 |
| 214 if (!m_scrollGestureHandlingNode) | 286 if (!m_scrollGestureHandlingNode) |
| 215 m_scrollGestureHandlingNode = m_frame->document()->documentElement(); | 287 m_scrollGestureHandlingNode = m_frame->document()->documentElement(); |
| 216 | 288 |
| 217 if (!m_scrollGestureHandlingNode || | 289 if (!m_scrollGestureHandlingNode || |
| 218 !m_scrollGestureHandlingNode->layoutObject()) | 290 !m_scrollGestureHandlingNode->layoutObject()) |
| 219 return WebInputEventResult::NotHandled; | 291 return WebInputEventResult::NotHandled; |
| 220 | 292 |
| 221 passScrollGestureEvent(gestureEvent, | 293 passScrollGestureEvent(gestureEvent, |
| 222 m_scrollGestureHandlingNode->layoutObject()); | 294 m_scrollGestureHandlingNode->layoutObject()); |
| 223 | 295 |
| 296 recordNonCompositedMainThreadScrollingReasons(gestureEvent.sourceDevice); | |
| 297 | |
| 224 m_currentScrollChain.clear(); | 298 m_currentScrollChain.clear(); |
| 225 std::unique_ptr<ScrollStateData> scrollStateData = | 299 std::unique_ptr<ScrollStateData> scrollStateData = |
| 226 WTF::makeUnique<ScrollStateData>(); | 300 WTF::makeUnique<ScrollStateData>(); |
| 227 IntPoint position = flooredIntPoint(gestureEvent.positionInRootFrame()); | 301 IntPoint position = flooredIntPoint(gestureEvent.positionInRootFrame()); |
| 228 scrollStateData->position_x = position.x(); | 302 scrollStateData->position_x = position.x(); |
| 229 scrollStateData->position_y = position.y(); | 303 scrollStateData->position_y = position.y(); |
| 230 scrollStateData->is_beginning = true; | 304 scrollStateData->is_beginning = true; |
| 231 scrollStateData->from_user_input = true; | 305 scrollStateData->from_user_input = true; |
| 232 scrollStateData->is_direct_manipulation = | 306 scrollStateData->is_direct_manipulation = |
| 233 gestureEvent.sourceDevice == WebGestureDeviceTouchscreen; | 307 gestureEvent.sourceDevice == WebGestureDeviceTouchscreen; |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 if (scrollbar->gestureEvent(targetedEvent.event(), &shouldUpdateCapture)) { | 634 if (scrollbar->gestureEvent(targetedEvent.event(), &shouldUpdateCapture)) { |
| 561 if (shouldUpdateCapture) | 635 if (shouldUpdateCapture) |
| 562 m_scrollbarHandlingScrollGesture = scrollbar; | 636 m_scrollbarHandlingScrollGesture = scrollbar; |
| 563 return true; | 637 return true; |
| 564 } | 638 } |
| 565 } | 639 } |
| 566 return false; | 640 return false; |
| 567 } | 641 } |
| 568 | 642 |
| 569 } // namespace blink | 643 } // namespace blink |
| OLD | NEW |