| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/frame/RootFrameViewport.h" | 6 #include "core/frame/RootFrameViewport.h" |
| 7 | 7 |
| 8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 9 #include "core/layout/ScrollAlignment.h" | 9 #include "core/layout/ScrollAlignment.h" |
| 10 #include "platform/geometry/DoubleRect.h" | 10 #include "platform/geometry/DoubleRect.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 DoublePoint clampedPosition = clampScrollPosition(position); | 87 DoublePoint clampedPosition = clampScrollPosition(position); |
| 88 ScrollableArea::setScrollPosition(clampedPosition, scrollType, scrollBehavio
r); | 88 ScrollableArea::setScrollPosition(clampedPosition, scrollType, scrollBehavio
r); |
| 89 } | 89 } |
| 90 | 90 |
| 91 ScrollBehavior RootFrameViewport::scrollBehaviorStyle() const | 91 ScrollBehavior RootFrameViewport::scrollBehaviorStyle() const |
| 92 { | 92 { |
| 93 return layoutViewport().scrollBehaviorStyle(); | 93 return layoutViewport().scrollBehaviorStyle(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 ScrollResult RootFrameViewport::handleWheel(const PlatformWheelEvent& event) | |
| 97 { | |
| 98 updateScrollAnimator(); | |
| 99 | |
| 100 ScrollableArea& primary = !m_invertScrollOrder ? layoutViewport() : visualVi
ewport(); | |
| 101 ScrollableArea& secondary = !m_invertScrollOrder ? visualViewport() : layout
Viewport(); | |
| 102 | |
| 103 ScrollResult viewScrollResult = primary.handleWheel(event); | |
| 104 | |
| 105 // The visual viewport will only accept pixel scrolls. | |
| 106 if (!event.canScroll() || event.granularity() == ScrollByPageWheelEvent) | |
| 107 return viewScrollResult; | |
| 108 | |
| 109 // TODO(sataya.m) : The delta in PlatformWheelEvent is negative when scrolli
ng the | |
| 110 // wheel towards the user, so negate it to get the scroll delta that should
be applied | |
| 111 // to the page. unusedScrollDelta computed in the ScrollResult is also negat
ive. Say | |
| 112 // there is WheelEvent({0, -10} and page scroll by 2px and unusedScrollDelta
computed | |
| 113 // is {0, -8}. Due to which we have to negate the unusedScrollDelta to obtai
n the expected | |
| 114 // animation.Please address http://crbug.com/504389. | |
| 115 DoublePoint oldOffset = secondary.scrollPositionDouble(); | |
| 116 DoublePoint locationDelta; | |
| 117 if (viewScrollResult.didScroll()) { | |
| 118 locationDelta = -DoublePoint(viewScrollResult.unusedScrollDeltaX, viewSc
rollResult.unusedScrollDeltaY); | |
| 119 } else { | |
| 120 if (event.railsMode() != PlatformEvent::RailsModeVertical) | |
| 121 locationDelta.setX(-event.deltaX()); | |
| 122 if (event.railsMode() != PlatformEvent::RailsModeHorizontal) | |
| 123 locationDelta.setY(-event.deltaY()); | |
| 124 } | |
| 125 | |
| 126 DoublePoint targetPosition = secondary.clampScrollPosition( | |
| 127 secondary.scrollPositionDouble() + toDoubleSize(locationDelta)); | |
| 128 secondary.setScrollPosition(targetPosition, UserScroll); | |
| 129 | |
| 130 DoublePoint usedLocationDelta(secondary.scrollPositionDouble() - oldOffset); | |
| 131 | |
| 132 bool didScrollX = viewScrollResult.didScrollX || usedLocationDelta.x(); | |
| 133 bool didScrollY = viewScrollResult.didScrollY || usedLocationDelta.y(); | |
| 134 return ScrollResult(didScrollX, didScrollY, -viewScrollResult.unusedScrollDe
ltaX - usedLocationDelta.x(), -viewScrollResult.unusedScrollDeltaY - usedLocatio
nDelta.y()); | |
| 135 } | |
| 136 | |
| 137 LayoutRect RootFrameViewport::scrollIntoView(const LayoutRect& rectInContent, co
nst ScrollAlignment& alignX, const ScrollAlignment& alignY) | 96 LayoutRect RootFrameViewport::scrollIntoView(const LayoutRect& rectInContent, co
nst ScrollAlignment& alignX, const ScrollAlignment& alignY) |
| 138 { | 97 { |
| 139 // We want to move the rect into the viewport that excludes the scrollbars s
o we intersect | 98 // We want to move the rect into the viewport that excludes the scrollbars s
o we intersect |
| 140 // the visual viewport with the scrollbar-excluded frameView content rect. H
owever, we don't | 99 // the visual viewport with the scrollbar-excluded frameView content rect. H
owever, we don't |
| 141 // use visibleContentRect directly since it floors the scroll position. Inst
ead, we use | 100 // use visibleContentRect directly since it floors the scroll position. Inst
ead, we use |
| 142 // FrameView::scrollPositionDouble and construct a LayoutRect from that (the
FrameView size | 101 // FrameView::scrollPositionDouble and construct a LayoutRect from that (the
FrameView size |
| 143 // is always integer sized. | 102 // is always integer sized. |
| 144 | 103 |
| 145 LayoutRect frameRectInContent = LayoutRect( | 104 LayoutRect frameRectInContent = LayoutRect( |
| 146 layoutViewport().scrollPositionDouble(), | 105 layoutViewport().scrollPositionDouble(), |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 } | 295 } |
| 337 | 296 |
| 338 DEFINE_TRACE(RootFrameViewport) | 297 DEFINE_TRACE(RootFrameViewport) |
| 339 { | 298 { |
| 340 visitor->trace(m_visualViewport); | 299 visitor->trace(m_visualViewport); |
| 341 visitor->trace(m_layoutViewport); | 300 visitor->trace(m_layoutViewport); |
| 342 ScrollableArea::trace(visitor); | 301 ScrollableArea::trace(visitor); |
| 343 } | 302 } |
| 344 | 303 |
| 345 } // namespace blink | 304 } // namespace blink |
| OLD | NEW |