| 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(false); | 99 ScrollResult viewScrollResult(false); |
| 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(false); | 125 return ScrollResult(false); |
| 121 | 126 |
| 122 DoubleSize unusedLocationDelta(locationDelta - usedLocationDelta); | 127 DoubleSize unusedLocationDelta(locationDelta - usedLocationDelta); |
| 123 return ScrollResult(true, -unusedLocationDelta.width(), -unusedLocationDelta
.height()); | 128 return ScrollResult(true, -unusedLocationDelta.width(), -unusedLocationDelta
.height()); |
| 124 } | 129 } |
| 125 | 130 |
| 126 LayoutRect RootFrameViewport::scrollIntoView(const LayoutRect& rectInContent, co
nst ScrollAlignment& alignX, const ScrollAlignment& alignY) | 131 LayoutRect RootFrameViewport::scrollIntoView(const LayoutRect& rectInContent, co
nst ScrollAlignment& alignX, const ScrollAlignment& alignY) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 153 FloatRect visible = | 158 FloatRect visible = |
| 154 LayoutRect(visualViewport().scrollPositionDouble(), visualViewport().vis
ibleContentRect().size()); | 159 LayoutRect(visualViewport().scrollPositionDouble(), visualViewport().vis
ibleContentRect().size()); |
| 155 | 160 |
| 156 float centeringOffsetX = (visible.width() - targetViewport.width()) / 2; | 161 float centeringOffsetX = (visible.width() - targetViewport.width()) / 2; |
| 157 float centeringOffsetY = (visible.height() - targetViewport.height()) / 2; | 162 float centeringOffsetY = (visible.height() - targetViewport.height()) / 2; |
| 158 | 163 |
| 159 DoublePoint targetOffset( | 164 DoublePoint targetOffset( |
| 160 targetViewport.x() - centeringOffsetX, | 165 targetViewport.x() - centeringOffsetX, |
| 161 targetViewport.y() - centeringOffsetY); | 166 targetViewport.y() - centeringOffsetY); |
| 162 | 167 |
| 163 setScrollPosition(targetOffset); | 168 setScrollPosition(targetOffset, ProgrammaticScroll); |
| 164 | 169 |
| 165 // RootFrameViewport only changes the viewport relative to the document so w
e can't change the input | 170 // RootFrameViewport only changes the viewport relative to the document so w
e can't change the input |
| 166 // rect's location relative to the document origin. | 171 // rect's location relative to the document origin. |
| 167 return rectInContent; | 172 return rectInContent; |
| 168 } | 173 } |
| 169 | 174 |
| 170 void RootFrameViewport::setScrollOffset(const IntPoint& offset) | 175 void RootFrameViewport::setScrollOffset(const IntPoint& offset, ScrollType scrol
lType) |
| 171 { | 176 { |
| 172 setScrollOffset(DoublePoint(offset)); | 177 setScrollOffset(DoublePoint(offset), scrollType); |
| 173 } | 178 } |
| 174 | 179 |
| 175 void RootFrameViewport::setScrollOffset(const DoublePoint& offset) | 180 void RootFrameViewport::setScrollOffset(const DoublePoint& offset, ScrollType sc
rollType) |
| 176 { | 181 { |
| 177 // Make sure we use the scroll positions as reported by each viewport's Scro
llAnimator, since its | 182 // Make sure we use the scroll positions as reported by each viewport's Scro
llAnimator, since its |
| 178 // ScrollableArea's position may have the fractional part truncated off. | 183 // ScrollableArea's position may have the fractional part truncated off. |
| 179 DoublePoint oldPosition = scrollOffsetFromScrollAnimators(); | 184 DoublePoint oldPosition = scrollOffsetFromScrollAnimators(); |
| 180 | 185 |
| 181 DoubleSize delta = offset - oldPosition; | 186 DoubleSize delta = offset - oldPosition; |
| 182 | 187 |
| 183 if (delta.isZero()) | 188 if (delta.isZero()) |
| 184 return; | 189 return; |
| 185 | 190 |
| 186 DoublePoint targetPosition = layoutViewport().adjustScrollPositionWithinRang
e(layoutViewport().scrollAnimator()->currentPosition() + delta); | 191 DoublePoint targetPosition = layoutViewport().adjustScrollPositionWithinRang
e(layoutViewport().scrollAnimator()->currentPosition() + delta); |
| 187 layoutViewport().scrollToOffsetWithoutAnimation(toFloatPoint(targetPosition)
); | 192 layoutViewport().setScrollPosition(targetPosition, scrollType); |
| 188 | 193 |
| 189 DoubleSize applied = scrollOffsetFromScrollAnimators() - oldPosition; | 194 DoubleSize applied = scrollOffsetFromScrollAnimators() - oldPosition; |
| 190 delta -= applied; | 195 delta -= applied; |
| 191 | 196 |
| 192 if (delta.isZero()) | 197 if (delta.isZero()) |
| 193 return; | 198 return; |
| 194 | 199 |
| 195 targetPosition = visualViewport().adjustScrollPositionWithinRange(visualView
port().scrollAnimator()->currentPosition() + delta); | 200 targetPosition = visualViewport().adjustScrollPositionWithinRange(visualView
port().scrollAnimator()->currentPosition() + delta); |
| 196 visualViewport().scrollToOffsetWithoutAnimation(toFloatPoint(targetPosition)
); | 201 visualViewport().setScrollPosition(targetPosition, scrollType); |
| 197 } | 202 } |
| 198 | 203 |
| 199 IntPoint RootFrameViewport::scrollPosition() const | 204 IntPoint RootFrameViewport::scrollPosition() const |
| 200 { | 205 { |
| 201 return flooredIntPoint(scrollPositionDouble()); | 206 return flooredIntPoint(scrollPositionDouble()); |
| 202 } | 207 } |
| 203 | 208 |
| 204 DoublePoint RootFrameViewport::scrollPositionDouble() const | 209 DoublePoint RootFrameViewport::scrollPositionDouble() const |
| 205 { | 210 { |
| 206 return layoutViewport().scrollPositionDouble() + toDoubleSize(visualViewport
().scrollPositionDouble()); | 211 return layoutViewport().scrollPositionDouble() + toDoubleSize(visualViewport
().scrollPositionDouble()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 return layoutViewport().hostWindow(); | 314 return layoutViewport().hostWindow(); |
| 310 } | 315 } |
| 311 | 316 |
| 312 void RootFrameViewport::serviceScrollAnimations(double monotonicTime) | 317 void RootFrameViewport::serviceScrollAnimations(double monotonicTime) |
| 313 { | 318 { |
| 314 ScrollableArea::serviceScrollAnimations(monotonicTime); | 319 ScrollableArea::serviceScrollAnimations(monotonicTime); |
| 315 layoutViewport().serviceScrollAnimations(monotonicTime); | 320 layoutViewport().serviceScrollAnimations(monotonicTime); |
| 316 } | 321 } |
| 317 | 322 |
| 318 } // namespace blink | 323 } // namespace blink |
| OLD | NEW |