| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 bool RootFrameViewport::isScrollCornerVisible() const | 61 bool RootFrameViewport::isScrollCornerVisible() const |
| 62 { | 62 { |
| 63 return layoutViewport().isScrollCornerVisible(); | 63 return layoutViewport().isScrollCornerVisible(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 IntRect RootFrameViewport::scrollCornerRect() const | 66 IntRect RootFrameViewport::scrollCornerRect() const |
| 67 { | 67 { |
| 68 return layoutViewport().scrollCornerRect(); | 68 return layoutViewport().scrollCornerRect(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void RootFrameViewport::setScrollPosition(const DoublePoint& position, ScrollBeh
avior scrollBehavior) | 71 void RootFrameViewport::setScrollPosition(const DoublePoint& position, ScrollTyp
e scrollType, ScrollBehavior scrollBehavior) |
| 72 { | 72 { |
| 73 updateScrollAnimator(); | 73 updateScrollAnimator(); |
| 74 | 74 |
| 75 // TODO(bokan): Support smooth scrolling the visual viewport. | 75 // TODO(bokan): Support smooth scrolling the visual viewport. |
| 76 if (scrollBehavior == ScrollBehaviorAuto) | 76 if (scrollBehavior == ScrollBehaviorAuto) |
| 77 scrollBehavior = layoutViewport().scrollBehaviorStyle(); | 77 scrollBehavior = scrollBehaviorStyle(); |
| 78 if (scrollBehavior == ScrollBehaviorSmooth) { | 78 if (scrollBehavior == ScrollBehaviorSmooth) { |
| 79 layoutViewport().setScrollPosition(position, scrollBehavior); | 79 layoutViewport().setScrollPosition(position, scrollType, scrollBehavior)
; |
| 80 return; | 80 return; |
| 81 } | 81 } |
| 82 | 82 |
| 83 if (!layoutViewport().isProgrammaticallyScrollable()) | 83 if (scrollType == ProgrammaticScroll && !layoutViewport().isProgrammatically
Scrollable()) |
| 84 return; | 84 return; |
| 85 | 85 |
| 86 DoublePoint clampedPosition = clampScrollPosition(position); | 86 DoublePoint clampedPosition = clampScrollPosition(position); |
| 87 scrollToOffsetWithoutAnimation(toFloatPoint(clampedPosition)); | 87 ScrollableArea::setScrollPosition(clampedPosition, scrollType, scrollBehavio
r); |
| 88 } |
| 89 |
| 90 ScrollBehavior RootFrameViewport::scrollBehaviorStyle() const |
| 91 { |
| 92 return layoutViewport().scrollBehaviorStyle(); |
| 88 } | 93 } |
| 89 | 94 |
| 90 ScrollResult RootFrameViewport::handleWheel(const PlatformWheelEvent& event) | 95 ScrollResult RootFrameViewport::handleWheel(const PlatformWheelEvent& event) |
| 91 { | 96 { |
| 92 updateScrollAnimator(); | 97 updateScrollAnimator(); |
| 93 | 98 |
| 94 ScrollResult viewScrollResult; | 99 ScrollResult viewScrollResult; |
| 95 if (layoutViewport().isScrollable()) | 100 if (layoutViewport().isScrollable()) |
| 96 viewScrollResult = layoutViewport().handleWheel(event); | 101 viewScrollResult = layoutViewport().handleWheel(event); |
| 97 | 102 |
| 98 // The visual viewport will only accept pixel scrolls. | 103 // The visual viewport will only accept pixel scrolls. |
| 99 if (!event.canScroll() || event.granularity() == ScrollByPageWheelEvent) | 104 if (!event.canScroll() || event.granularity() == ScrollByPageWheelEvent) |
| 100 return viewScrollResult; | 105 return viewScrollResult; |
| 101 | 106 |
| 102 // Move the location by the negative of the remaining scroll delta. | 107 // Move the location by the negative of the remaining scroll delta. |
| 103 DoublePoint oldOffset = visualViewport().scrollPositionDouble(); | 108 DoublePoint oldOffset = visualViewport().scrollPositionDouble(); |
| 104 DoublePoint locationDelta; | 109 DoublePoint locationDelta; |
| 105 if (viewScrollResult.didScroll()) { | 110 if (viewScrollResult.didScroll()) { |
| 106 locationDelta = -DoublePoint(viewScrollResult.unusedScrollDeltaX, viewSc
rollResult.unusedScrollDeltaY); | 111 locationDelta = -DoublePoint(viewScrollResult.unusedScrollDeltaX, viewSc
rollResult.unusedScrollDeltaY); |
| 107 } else { | 112 } else { |
| 108 if (event.railsMode() != PlatformEvent::RailsModeVertical) | 113 if (event.railsMode() != PlatformEvent::RailsModeVertical) |
| 109 locationDelta.setX(-event.deltaX()); | 114 locationDelta.setX(-event.deltaX()); |
| 110 if (event.railsMode() != PlatformEvent::RailsModeHorizontal) | 115 if (event.railsMode() != PlatformEvent::RailsModeHorizontal) |
| 111 locationDelta.setY(-event.deltaY()); | 116 locationDelta.setY(-event.deltaY()); |
| 112 } | 117 } |
| 113 | 118 |
| 114 DoublePoint targetPosition = visualViewport().adjustScrollPositionWithinRang
e( | 119 DoublePoint targetPosition = visualViewport().adjustScrollPositionWithinRang
e( |
| 115 visualViewport().scrollPositionDouble() + toDoubleSize(locationDelta)); | 120 visualViewport().scrollPositionDouble() + toDoubleSize(locationDelta)); |
| 116 visualViewport().scrollToOffsetWithoutAnimation(FloatPoint(targetPosition)); | 121 visualViewport().setScrollPosition(targetPosition, UserScroll); |
| 117 | 122 |
| 118 DoublePoint usedLocationDelta(visualViewport().scrollPositionDouble() - oldO
ffset); | 123 DoublePoint usedLocationDelta(visualViewport().scrollPositionDouble() - oldO
ffset); |
| 119 if (!viewScrollResult.didScroll() && usedLocationDelta == DoublePoint::zero(
)) | 124 if (!viewScrollResult.didScroll() && usedLocationDelta == DoublePoint::zero(
)) |
| 120 return ScrollResult(); | 125 return ScrollResult(); |
| 121 | 126 |
| 122 DoubleSize unusedLocationDelta(locationDelta - usedLocationDelta); | 127 DoubleSize unusedLocationDelta(locationDelta - usedLocationDelta); |
| 123 bool didScrollX = viewScrollResult.didScrollX || unusedLocationDelta.width()
; | 128 bool didScrollX = viewScrollResult.didScrollX || unusedLocationDelta.width()
; |
| 124 bool didScrollY = viewScrollResult.didScrollY || unusedLocationDelta.height(
); | 129 bool didScrollY = viewScrollResult.didScrollY || unusedLocationDelta.height(
); |
| 125 return ScrollResult(didScrollX, didScrollY, -unusedLocationDelta.width(), -u
nusedLocationDelta.height()); | 130 return ScrollResult(didScrollX, didScrollY, -unusedLocationDelta.width(), -u
nusedLocationDelta.height()); |
| 126 } | 131 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 155 FloatRect visible = | 160 FloatRect visible = |
| 156 LayoutRect(visualViewport().scrollPositionDouble(), visualViewport().vis
ibleContentRect().size()); | 161 LayoutRect(visualViewport().scrollPositionDouble(), visualViewport().vis
ibleContentRect().size()); |
| 157 | 162 |
| 158 float centeringOffsetX = (visible.width() - targetViewport.width()) / 2; | 163 float centeringOffsetX = (visible.width() - targetViewport.width()) / 2; |
| 159 float centeringOffsetY = (visible.height() - targetViewport.height()) / 2; | 164 float centeringOffsetY = (visible.height() - targetViewport.height()) / 2; |
| 160 | 165 |
| 161 DoublePoint targetOffset( | 166 DoublePoint targetOffset( |
| 162 targetViewport.x() - centeringOffsetX, | 167 targetViewport.x() - centeringOffsetX, |
| 163 targetViewport.y() - centeringOffsetY); | 168 targetViewport.y() - centeringOffsetY); |
| 164 | 169 |
| 165 setScrollPosition(targetOffset); | 170 setScrollPosition(targetOffset, ProgrammaticScroll); |
| 166 | 171 |
| 167 // RootFrameViewport only changes the viewport relative to the document so w
e can't change the input | 172 // RootFrameViewport only changes the viewport relative to the document so w
e can't change the input |
| 168 // rect's location relative to the document origin. | 173 // rect's location relative to the document origin. |
| 169 return rectInContent; | 174 return rectInContent; |
| 170 } | 175 } |
| 171 | 176 |
| 172 void RootFrameViewport::setScrollOffset(const IntPoint& offset) | 177 void RootFrameViewport::setScrollOffset(const IntPoint& offset, ScrollType scrol
lType) |
| 173 { | 178 { |
| 174 setScrollOffset(DoublePoint(offset)); | 179 setScrollOffset(DoublePoint(offset), scrollType); |
| 175 } | 180 } |
| 176 | 181 |
| 177 void RootFrameViewport::setScrollOffset(const DoublePoint& offset) | 182 void RootFrameViewport::setScrollOffset(const DoublePoint& offset, ScrollType sc
rollType) |
| 178 { | 183 { |
| 179 // Make sure we use the scroll positions as reported by each viewport's Scro
llAnimator, since its | 184 // Make sure we use the scroll positions as reported by each viewport's Scro
llAnimator, since its |
| 180 // ScrollableArea's position may have the fractional part truncated off. | 185 // ScrollableArea's position may have the fractional part truncated off. |
| 181 DoublePoint oldPosition = scrollOffsetFromScrollAnimators(); | 186 DoublePoint oldPosition = scrollOffsetFromScrollAnimators(); |
| 182 | 187 |
| 183 DoubleSize delta = offset - oldPosition; | 188 DoubleSize delta = offset - oldPosition; |
| 184 | 189 |
| 185 if (delta.isZero()) | 190 if (delta.isZero()) |
| 186 return; | 191 return; |
| 187 | 192 |
| 188 DoublePoint targetPosition = layoutViewport().adjustScrollPositionWithinRang
e(layoutViewport().scrollAnimator()->currentPosition() + delta); | 193 DoublePoint targetPosition = layoutViewport().adjustScrollPositionWithinRang
e(layoutViewport().scrollAnimator()->currentPosition() + delta); |
| 189 layoutViewport().scrollToOffsetWithoutAnimation(toFloatPoint(targetPosition)
); | 194 layoutViewport().setScrollPosition(targetPosition, scrollType); |
| 190 | 195 |
| 191 DoubleSize applied = scrollOffsetFromScrollAnimators() - oldPosition; | 196 DoubleSize applied = scrollOffsetFromScrollAnimators() - oldPosition; |
| 192 delta -= applied; | 197 delta -= applied; |
| 193 | 198 |
| 194 if (delta.isZero()) | 199 if (delta.isZero()) |
| 195 return; | 200 return; |
| 196 | 201 |
| 197 targetPosition = visualViewport().adjustScrollPositionWithinRange(visualView
port().scrollAnimator()->currentPosition() + delta); | 202 targetPosition = visualViewport().adjustScrollPositionWithinRange(visualView
port().scrollAnimator()->currentPosition() + delta); |
| 198 visualViewport().scrollToOffsetWithoutAnimation(toFloatPoint(targetPosition)
); | 203 visualViewport().setScrollPosition(targetPosition, scrollType); |
| 199 } | 204 } |
| 200 | 205 |
| 201 IntPoint RootFrameViewport::scrollPosition() const | 206 IntPoint RootFrameViewport::scrollPosition() const |
| 202 { | 207 { |
| 203 return flooredIntPoint(scrollPositionDouble()); | 208 return flooredIntPoint(scrollPositionDouble()); |
| 204 } | 209 } |
| 205 | 210 |
| 206 DoublePoint RootFrameViewport::scrollPositionDouble() const | 211 DoublePoint RootFrameViewport::scrollPositionDouble() const |
| 207 { | 212 { |
| 208 return layoutViewport().scrollPositionDouble() + toDoubleSize(visualViewport
().scrollPositionDouble()); | 213 return layoutViewport().scrollPositionDouble() + toDoubleSize(visualViewport
().scrollPositionDouble()); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 } | 323 } |
| 319 | 324 |
| 320 void RootFrameViewport::updateCompositorScrollAnimations() | 325 void RootFrameViewport::updateCompositorScrollAnimations() |
| 321 { | 326 { |
| 322 ScrollableArea::updateCompositorScrollAnimations(); | 327 ScrollableArea::updateCompositorScrollAnimations(); |
| 323 layoutViewport().updateCompositorScrollAnimations(); | 328 layoutViewport().updateCompositorScrollAnimations(); |
| 324 } | 329 } |
| 325 | 330 |
| 326 | 331 |
| 327 } // namespace blink | 332 } // namespace blink |
| OLD | NEW |