| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | 6 |
| 7 #include "core/frame/RootFrameViewport.h" | 7 #include "core/frame/RootFrameViewport.h" |
| 8 | 8 |
| 9 #include "core/layout/ScrollAlignment.h" | 9 #include "core/layout/ScrollAlignment.h" |
| 10 #include "platform/geometry/DoubleRect.h" | 10 #include "platform/geometry/DoubleRect.h" |
| 11 #include "platform/geometry/LayoutRect.h" | 11 #include "platform/geometry/LayoutRect.h" |
| 12 #include "platform/scroll/ScrollableArea.h" | 12 #include "platform/scroll/ScrollableArea.h" |
| 13 | 13 |
| 14 #include <gtest/gtest.h> | 14 #include <gtest/gtest.h> |
| 15 | 15 |
| 16 #define EXPECT_POINT_EQ(expected, actual) \ | 16 #define EXPECT_POINT_EQ(expected, actual) \ |
| 17 do { \ | 17 do { \ |
| 18 EXPECT_EQ((expected).x(), (actual).x()); \ | 18 EXPECT_EQ((expected).x(), (actual).x()); \ |
| 19 EXPECT_EQ((expected).y(), (actual).y()); \ | 19 EXPECT_EQ((expected).y(), (actual).y()); \ |
| 20 } while (false) | 20 } while (false) |
| 21 #define EXPECT_SIZE_EQ(expected, actual) \ | 21 #define EXPECT_SIZE_EQ(expected, actual) \ |
| 22 do { \ | 22 do { \ |
| 23 EXPECT_EQ((expected).width(), (actual).width()); \ | 23 EXPECT_EQ((expected).width(), (actual).width()); \ |
| 24 EXPECT_EQ((expected).height(), (actual).height()); \ | 24 EXPECT_EQ((expected).height(), (actual).height()); \ |
| 25 } while (false) | 25 } while (false) |
| 26 | 26 |
| 27 namespace blink { | 27 namespace blink { |
| 28 | 28 |
| 29 class ScrollableAreaStub : public ScrollableArea { | 29 class ScrollableAreaStub : public NoBaseWillBeGarbageCollectedFinalized<Scrollab
leAreaStub>, public ScrollableArea { |
| 30 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ScrollableAreaStub); |
| 30 public: | 31 public: |
| 31 ScrollableAreaStub(const IntSize& viewportSize, const IntSize& contentsSize) | 32 static PassOwnPtrWillBeRawPtr<ScrollableAreaStub> create(const IntSize& view
portSize, const IntSize& contentsSize) |
| 32 : m_userInputScrollableX(true) | |
| 33 , m_userInputScrollableY(true) | |
| 34 , m_viewportSize(viewportSize) | |
| 35 , m_contentsSize(contentsSize) | |
| 36 { | 33 { |
| 34 return adoptPtrWillBeNoop(new ScrollableAreaStub(viewportSize, contentsS
ize)); |
| 37 } | 35 } |
| 38 | 36 |
| 39 void setViewportSize(const IntSize& viewportSize) | 37 void setViewportSize(const IntSize& viewportSize) |
| 40 { | 38 { |
| 41 m_viewportSize = viewportSize; | 39 m_viewportSize = viewportSize; |
| 42 } | 40 } |
| 43 | 41 |
| 44 IntSize viewportSize() const { return m_viewportSize; } | 42 IntSize viewportSize() const { return m_viewportSize; } |
| 45 | 43 |
| 46 // ScrollableArea Impl | 44 // ScrollableArea Impl |
| (...skipping 14 matching lines...) Expand all Loading... |
| 61 IntPoint minimumScrollPosition() const override { return IntPoint(); } | 59 IntPoint minimumScrollPosition() const override { return IntPoint(); } |
| 62 DoublePoint minimumScrollPositionDouble() const override { return DoublePoin
t(); } | 60 DoublePoint minimumScrollPositionDouble() const override { return DoublePoin
t(); } |
| 63 IntPoint maximumScrollPosition() const override { return flooredIntPoint(max
imumScrollPositionDouble()); } | 61 IntPoint maximumScrollPosition() const override { return flooredIntPoint(max
imumScrollPositionDouble()); } |
| 64 | 62 |
| 65 IntSize contentsSize() const override { return m_contentsSize; } | 63 IntSize contentsSize() const override { return m_contentsSize; } |
| 66 void setContentSize(const IntSize& contentsSize) | 64 void setContentSize(const IntSize& contentsSize) |
| 67 { | 65 { |
| 68 m_contentsSize = contentsSize; | 66 m_contentsSize = contentsSize; |
| 69 } | 67 } |
| 70 | 68 |
| 69 DEFINE_INLINE_VIRTUAL_TRACE() |
| 70 { |
| 71 ScrollableArea::trace(visitor); |
| 72 } |
| 73 |
| 71 protected: | 74 protected: |
| 75 ScrollableAreaStub(const IntSize& viewportSize, const IntSize& contentsSize) |
| 76 : m_userInputScrollableX(true) |
| 77 , m_userInputScrollableY(true) |
| 78 , m_viewportSize(viewportSize) |
| 79 , m_contentsSize(contentsSize) |
| 80 { |
| 81 } |
| 82 |
| 72 void setScrollOffset(const IntPoint& offset, ScrollType) override { m_scroll
Position = offset; } | 83 void setScrollOffset(const IntPoint& offset, ScrollType) override { m_scroll
Position = offset; } |
| 73 void setScrollOffset(const DoublePoint& offset, ScrollType) override { m_scr
ollPosition = offset; } | 84 void setScrollOffset(const DoublePoint& offset, ScrollType) override { m_scr
ollPosition = offset; } |
| 74 bool shouldUseIntegerScrollOffset() const override { return true; } | 85 bool shouldUseIntegerScrollOffset() const override { return true; } |
| 75 bool isActive() const override { return true; } | 86 bool isActive() const override { return true; } |
| 76 bool isScrollCornerVisible() const override { return true; } | 87 bool isScrollCornerVisible() const override { return true; } |
| 77 IntRect scrollCornerRect() const override { return IntRect(); } | 88 IntRect scrollCornerRect() const override { return IntRect(); } |
| 78 bool scrollbarsCanBeActive() const override { return true; } | 89 bool scrollbarsCanBeActive() const override { return true; } |
| 79 IntRect scrollableAreaBoundingBox() const override { return IntRect(); } | 90 IntRect scrollableAreaBoundingBox() const override { return IntRect(); } |
| 80 bool shouldPlaceVerticalScrollbarOnLeft() const override { return true; } | 91 bool shouldPlaceVerticalScrollbarOnLeft() const override { return true; } |
| 81 void invalidateScrollbarRect(Scrollbar*, const IntRect&) override { } | 92 void invalidateScrollbarRect(Scrollbar*, const IntRect&) override { } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 99 | 110 |
| 100 bool m_userInputScrollableX; | 111 bool m_userInputScrollableX; |
| 101 bool m_userInputScrollableY; | 112 bool m_userInputScrollableY; |
| 102 DoublePoint m_scrollPosition; | 113 DoublePoint m_scrollPosition; |
| 103 IntSize m_viewportSize; | 114 IntSize m_viewportSize; |
| 104 IntSize m_contentsSize; | 115 IntSize m_contentsSize; |
| 105 }; | 116 }; |
| 106 | 117 |
| 107 class RootFrameViewStub : public ScrollableAreaStub { | 118 class RootFrameViewStub : public ScrollableAreaStub { |
| 108 public: | 119 public: |
| 109 RootFrameViewStub(const IntSize& viewportSize, const IntSize& contentsSize) | 120 static PassOwnPtrWillBeRawPtr<RootFrameViewStub> create(const IntSize& viewp
ortSize, const IntSize& contentsSize) |
| 110 : ScrollableAreaStub(viewportSize, contentsSize) | |
| 111 { | 121 { |
| 122 return adoptPtrWillBeNoop(new RootFrameViewStub(viewportSize, contentsSi
ze)); |
| 112 } | 123 } |
| 113 | 124 |
| 114 DoublePoint maximumScrollPositionDouble() const override | 125 DoublePoint maximumScrollPositionDouble() const override |
| 115 { | 126 { |
| 116 return IntPoint(contentsSize() - viewportSize()); | 127 return IntPoint(contentsSize() - viewportSize()); |
| 117 } | 128 } |
| 118 | 129 |
| 119 private: | 130 private: |
| 131 RootFrameViewStub(const IntSize& viewportSize, const IntSize& contentsSize) |
| 132 : ScrollableAreaStub(viewportSize, contentsSize) |
| 133 { |
| 134 } |
| 135 |
| 120 int visibleWidth() const override { return m_viewportSize.width(); } | 136 int visibleWidth() const override { return m_viewportSize.width(); } |
| 121 int visibleHeight() const override { return m_viewportSize.height(); } | 137 int visibleHeight() const override { return m_viewportSize.height(); } |
| 122 }; | 138 }; |
| 123 | 139 |
| 124 class VisualViewportStub : public ScrollableAreaStub { | 140 class VisualViewportStub : public ScrollableAreaStub { |
| 125 public: | 141 public: |
| 126 VisualViewportStub(const IntSize& viewportSize, const IntSize& contentsSize) | 142 static PassOwnPtrWillBeRawPtr<VisualViewportStub> create(const IntSize& view
portSize, const IntSize& contentsSize) |
| 127 : ScrollableAreaStub(viewportSize, contentsSize) | |
| 128 , m_scale(1) | |
| 129 { | 143 { |
| 144 return adoptPtrWillBeNoop(new VisualViewportStub(viewportSize, contentsS
ize)); |
| 130 } | 145 } |
| 131 | 146 |
| 132 DoublePoint maximumScrollPositionDouble() const override | 147 DoublePoint maximumScrollPositionDouble() const override |
| 133 { | 148 { |
| 134 DoubleSize visibleViewport = viewportSize(); | 149 DoubleSize visibleViewport = viewportSize(); |
| 135 visibleViewport.scale(1 / m_scale); | 150 visibleViewport.scale(1 / m_scale); |
| 136 | 151 |
| 137 DoubleSize maxPosition = DoubleSize(contentsSize()) - visibleViewport; | 152 DoubleSize maxPosition = DoubleSize(contentsSize()) - visibleViewport; |
| 138 return DoublePoint(maxPosition); | 153 return DoublePoint(maxPosition); |
| 139 } | 154 } |
| 140 | 155 |
| 141 void setScale(float scale) { m_scale = scale; } | 156 void setScale(float scale) { m_scale = scale; } |
| 142 | 157 |
| 143 private: | 158 private: |
| 159 VisualViewportStub(const IntSize& viewportSize, const IntSize& contentsSize) |
| 160 : ScrollableAreaStub(viewportSize, contentsSize) |
| 161 , m_scale(1) |
| 162 { |
| 163 } |
| 164 |
| 144 int visibleWidth() const override { return m_viewportSize.width() / m_scale;
} | 165 int visibleWidth() const override { return m_viewportSize.width() / m_scale;
} |
| 145 int visibleHeight() const override { return m_viewportSize.height() / m_scal
e; } | 166 int visibleHeight() const override { return m_viewportSize.height() / m_scal
e; } |
| 146 DoubleRect visibleContentRectDouble(IncludeScrollbarsInRect) const override | 167 DoubleRect visibleContentRectDouble(IncludeScrollbarsInRect) const override |
| 147 { | 168 { |
| 148 DoubleSize size = m_viewportSize; | 169 DoubleSize size = m_viewportSize; |
| 149 size.scale(1 / m_scale); | 170 size.scale(1 / m_scale); |
| 150 DoubleRect rect(scrollPositionDouble(), size); | 171 DoubleRect rect(scrollPositionDouble(), size); |
| 151 return rect; | 172 return rect; |
| 152 } | 173 } |
| 153 | 174 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 165 { | 186 { |
| 166 } | 187 } |
| 167 }; | 188 }; |
| 168 | 189 |
| 169 // Tests that scrolling the viewport when the layout viewport is | 190 // Tests that scrolling the viewport when the layout viewport is |
| 170 // !userInputScrollable (as happens when overflow:hidden is set) works | 191 // !userInputScrollable (as happens when overflow:hidden is set) works |
| 171 // correctly, that is, the visual viewport can scroll, but not the layout. | 192 // correctly, that is, the visual viewport can scroll, but not the layout. |
| 172 TEST_F(RootFrameViewportTest, UserInputScrollable) | 193 TEST_F(RootFrameViewportTest, UserInputScrollable) |
| 173 { | 194 { |
| 174 IntSize viewportSize(100, 150); | 195 IntSize viewportSize(100, 150); |
| 175 RootFrameViewStub layoutViewport(viewportSize, IntSize(200, 300)); | 196 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr
eate(viewportSize, IntSize(200, 300)); |
| 176 VisualViewportStub visualViewport(viewportSize, viewportSize); | 197 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub::
create(viewportSize, viewportSize); |
| 177 | 198 |
| 178 OwnPtr<ScrollableArea> rootFrameViewport = | 199 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport = RootFrameViewport::cr
eate(*visualViewport.get(), *layoutViewport.get()); |
| 179 RootFrameViewport::create(visualViewport, layoutViewport); | |
| 180 | 200 |
| 181 visualViewport.setScale(2); | 201 visualViewport->setScale(2); |
| 182 | 202 |
| 183 // Disable just the layout viewport's horizontal scrolling, the | 203 // Disable just the layout viewport's horizontal scrolling, the |
| 184 // RootFrameViewport should remain scrollable overall. | 204 // RootFrameViewport should remain scrollable overall. |
| 185 layoutViewport.setUserInputScrollable(false, true); | 205 layoutViewport->setUserInputScrollable(false, true); |
| 186 visualViewport.setUserInputScrollable(true, true); | 206 visualViewport->setUserInputScrollable(true, true); |
| 187 | 207 |
| 188 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); | 208 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); |
| 189 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); | 209 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); |
| 190 | 210 |
| 191 // Layout viewport shouldn't scroll since it's not horizontally scrollable, | 211 // Layout viewport shouldn't scroll since it's not horizontally scrollable, |
| 192 // but visual viewport should. | 212 // but visual viewport should. |
| 193 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); | 213 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); |
| 194 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); | 214 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble()); |
| 195 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport.scrollPositionDouble()); | 215 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport->scrollPositionDouble()); |
| 196 EXPECT_POINT_EQ(DoublePoint(50, 0), rootFrameViewport->scrollPositionDouble(
)); | 216 EXPECT_POINT_EQ(DoublePoint(50, 0), rootFrameViewport->scrollPositionDouble(
)); |
| 197 | 217 |
| 198 // Disable just the visual viewport's horizontal scrolling, only the layout | 218 // Disable just the visual viewport's horizontal scrolling, only the layout |
| 199 // viewport should scroll. | 219 // viewport should scroll. |
| 200 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); | 220 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); |
| 201 layoutViewport.setUserInputScrollable(true, true); | 221 layoutViewport->setUserInputScrollable(true, true); |
| 202 visualViewport.setUserInputScrollable(false, true); | 222 visualViewport->setUserInputScrollable(false, true); |
| 203 | 223 |
| 204 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); | 224 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); |
| 205 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport.scrollPositionDouble()); | 225 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport->scrollPositionDouble())
; |
| 206 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 226 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble()); |
| 207 EXPECT_POINT_EQ(DoublePoint(100, 0), rootFrameViewport->scrollPositionDouble
()); | 227 EXPECT_POINT_EQ(DoublePoint(100, 0), rootFrameViewport->scrollPositionDouble
()); |
| 208 | 228 |
| 209 // Disable both viewports' horizontal scrolling, all horizontal scrolling | 229 // Disable both viewports' horizontal scrolling, all horizontal scrolling |
| 210 // should now be blocked. | 230 // should now be blocked. |
| 211 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); | 231 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); |
| 212 layoutViewport.setUserInputScrollable(false, true); | 232 layoutViewport->setUserInputScrollable(false, true); |
| 213 visualViewport.setUserInputScrollable(false, true); | 233 visualViewport->setUserInputScrollable(false, true); |
| 214 | 234 |
| 215 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); | 235 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); |
| 216 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); | 236 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble()); |
| 217 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 237 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble()); |
| 218 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); | 238 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); |
| 219 | 239 |
| 220 EXPECT_FALSE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); | 240 EXPECT_FALSE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); |
| 221 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); | 241 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); |
| 222 | 242 |
| 223 // Vertical scrolling should be unaffected. | 243 // Vertical scrolling should be unaffected. |
| 224 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); | 244 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); |
| 225 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport.scrollPositionDouble()); | 245 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport->scrollPositionDouble())
; |
| 226 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport.scrollPositionDouble()); | 246 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport->scrollPositionDouble()); |
| 227 EXPECT_POINT_EQ(DoublePoint(0, 225), rootFrameViewport->scrollPositionDouble
()); | 247 EXPECT_POINT_EQ(DoublePoint(0, 225), rootFrameViewport->scrollPositionDouble
()); |
| 228 | 248 |
| 229 // Try the same checks as above but for the vertical direction. | 249 // Try the same checks as above but for the vertical direction. |
| 230 // =============================================== | 250 // =============================================== |
| 231 | 251 |
| 232 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); | 252 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); |
| 233 | 253 |
| 234 // Disable just the layout viewport's vertical scrolling, the | 254 // Disable just the layout viewport's vertical scrolling, the |
| 235 // RootFrameViewport should remain scrollable overall. | 255 // RootFrameViewport should remain scrollable overall. |
| 236 layoutViewport.setUserInputScrollable(true, false); | 256 layoutViewport->setUserInputScrollable(true, false); |
| 237 visualViewport.setUserInputScrollable(true, true); | 257 visualViewport->setUserInputScrollable(true, true); |
| 238 | 258 |
| 239 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); | 259 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); |
| 240 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); | 260 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); |
| 241 | 261 |
| 242 // Layout viewport shouldn't scroll since it's not vertically scrollable, | 262 // Layout viewport shouldn't scroll since it's not vertically scrollable, |
| 243 // but visual viewport should. | 263 // but visual viewport should. |
| 244 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); | 264 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); |
| 245 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); | 265 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble()); |
| 246 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport.scrollPositionDouble()); | 266 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport->scrollPositionDouble()); |
| 247 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble(
)); | 267 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble(
)); |
| 248 | 268 |
| 249 // Disable just the visual viewport's vertical scrolling, only the layout | 269 // Disable just the visual viewport's vertical scrolling, only the layout |
| 250 // viewport should scroll. | 270 // viewport should scroll. |
| 251 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); | 271 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); |
| 252 layoutViewport.setUserInputScrollable(true, true); | 272 layoutViewport->setUserInputScrollable(true, true); |
| 253 visualViewport.setUserInputScrollable(true, false); | 273 visualViewport->setUserInputScrollable(true, false); |
| 254 | 274 |
| 255 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); | 275 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); |
| 256 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport.scrollPositionDouble()); | 276 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport->scrollPositionDouble())
; |
| 257 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 277 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble()); |
| 258 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble
()); | 278 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble
()); |
| 259 | 279 |
| 260 // Disable both viewports' horizontal scrolling, all vertical scrolling | 280 // Disable both viewports' horizontal scrolling, all vertical scrolling |
| 261 // should now be blocked. | 281 // should now be blocked. |
| 262 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); | 282 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); |
| 263 layoutViewport.setUserInputScrollable(true, false); | 283 layoutViewport->setUserInputScrollable(true, false); |
| 264 visualViewport.setUserInputScrollable(true, false); | 284 visualViewport->setUserInputScrollable(true, false); |
| 265 | 285 |
| 266 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); | 286 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); |
| 267 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); | 287 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble()); |
| 268 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 288 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble()); |
| 269 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); | 289 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); |
| 270 | 290 |
| 271 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); | 291 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); |
| 272 EXPECT_FALSE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); | 292 EXPECT_FALSE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); |
| 273 | 293 |
| 274 // Horizontal scrolling should be unaffected. | 294 // Horizontal scrolling should be unaffected. |
| 275 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); | 295 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); |
| 276 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport.scrollPositionDouble()); | 296 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport->scrollPositionDouble())
; |
| 277 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport.scrollPositionDouble()); | 297 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport->scrollPositionDouble()); |
| 278 EXPECT_POINT_EQ(DoublePoint(150, 0), rootFrameViewport->scrollPositionDouble
()); | 298 EXPECT_POINT_EQ(DoublePoint(150, 0), rootFrameViewport->scrollPositionDouble
()); |
| 279 } | 299 } |
| 280 | 300 |
| 281 // Make sure scrolls using the scroll animator (scroll(), setScrollPosition(), w
heelHandler) | 301 // Make sure scrolls using the scroll animator (scroll(), setScrollPosition(), w
heelHandler) |
| 282 // work correctly when one of the subviewports is explicitly scrolled without us
ing the | 302 // work correctly when one of the subviewports is explicitly scrolled without us
ing the |
| 283 // RootFrameViewport interface. | 303 // RootFrameViewport interface. |
| 284 TEST_F(RootFrameViewportTest, TestScrollAnimatorUpdatedBeforeScroll) | 304 TEST_F(RootFrameViewportTest, TestScrollAnimatorUpdatedBeforeScroll) |
| 285 { | 305 { |
| 286 IntSize viewportSize(100, 150); | 306 IntSize viewportSize(100, 150); |
| 287 RootFrameViewStub layoutViewport(viewportSize, IntSize(200, 300)); | 307 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr
eate(viewportSize, IntSize(200, 300)); |
| 288 VisualViewportStub visualViewport(viewportSize, viewportSize); | 308 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub::
create(viewportSize, viewportSize); |
| 289 | 309 |
| 290 OwnPtr<ScrollableArea> rootFrameViewport = | 310 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport = RootFrameViewport::cr
eate(*visualViewport.get(), *layoutViewport.get()); |
| 291 RootFrameViewport::create(visualViewport, layoutViewport); | |
| 292 | 311 |
| 293 visualViewport.setScale(2); | 312 visualViewport->setScale(2); |
| 294 | 313 |
| 295 visualViewport.setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll); | 314 visualViewport->setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll); |
| 296 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble
()); | 315 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble
()); |
| 297 | 316 |
| 298 // If the scroll animator doesn't update, it will still think it's at (0, 0)
and so it | 317 // If the scroll animator doesn't update, it will still think it's at (0, 0)
and so it |
| 299 // may early exit. | 318 // may early exit. |
| 300 rootFrameViewport->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll); | 319 rootFrameViewport->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll); |
| 301 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); | 320 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); |
| 302 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 321 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble()); |
| 303 | 322 |
| 304 // Try again for scroll() | 323 // Try again for scroll() |
| 305 visualViewport.setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll); | 324 visualViewport->setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll); |
| 306 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble
()); | 325 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble
()); |
| 307 | 326 |
| 308 rootFrameViewport->userScroll(ScrollLeft, ScrollByPixel, 50); | 327 rootFrameViewport->userScroll(ScrollLeft, ScrollByPixel, 50); |
| 309 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble(
)); | 328 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble(
)); |
| 310 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport.scrollPositionDouble()); | 329 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport->scrollPositionDouble()); |
| 311 | 330 |
| 312 // Try again for handleWheel. | 331 // Try again for handleWheel. |
| 313 visualViewport.setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll); | 332 visualViewport->setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll); |
| 314 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble
()); | 333 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble
()); |
| 315 | 334 |
| 316 PlatformWheelEvent wheelEvent( | 335 PlatformWheelEvent wheelEvent( |
| 317 IntPoint(10, 10), IntPoint(10, 10), | 336 IntPoint(10, 10), IntPoint(10, 10), |
| 318 50, 75, | 337 50, 75, |
| 319 0, 0, | 338 0, 0, |
| 320 ScrollByPixelWheelEvent, | 339 ScrollByPixelWheelEvent, |
| 321 false, false, false, false); | 340 false, false, false, false); |
| 322 rootFrameViewport->handleWheel(wheelEvent); | 341 rootFrameViewport->handleWheel(wheelEvent); |
| 323 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); | 342 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble()
); |
| 324 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 343 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble()); |
| 325 | 344 |
| 326 // Make sure the layout viewport is also accounted for. | 345 // Make sure the layout viewport is also accounted for. |
| 327 layoutViewport.setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll); | 346 layoutViewport->setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll)
; |
| 328 EXPECT_POINT_EQ(DoublePoint(100, 150), rootFrameViewport->scrollPositionDoub
le()); | 347 EXPECT_POINT_EQ(DoublePoint(100, 150), rootFrameViewport->scrollPositionDoub
le()); |
| 329 | 348 |
| 330 rootFrameViewport->userScroll(ScrollLeft, ScrollByPixel, 100); | 349 rootFrameViewport->userScroll(ScrollLeft, ScrollByPixel, 100); |
| 331 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble
()); | 350 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble
()); |
| 332 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport.scrollPositionDouble()); | 351 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport->scrollPositionDouble())
; |
| 333 } | 352 } |
| 334 | 353 |
| 335 // Test that the scrollIntoView correctly scrolls the main frame | 354 // Test that the scrollIntoView correctly scrolls the main frame |
| 336 // and pinch viewports such that the given rect is centered in the viewport. | 355 // and pinch viewports such that the given rect is centered in the viewport. |
| 337 TEST_F(RootFrameViewportTest, ScrollIntoView) | 356 TEST_F(RootFrameViewportTest, ScrollIntoView) |
| 338 { | 357 { |
| 339 IntSize viewportSize(100, 150); | 358 IntSize viewportSize(100, 150); |
| 340 RootFrameViewStub layoutViewport(viewportSize, IntSize(200, 300)); | 359 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr
eate(viewportSize, IntSize(200, 300)); |
| 341 VisualViewportStub visualViewport(viewportSize, viewportSize); | 360 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub::
create(viewportSize, viewportSize); |
| 342 | 361 |
| 343 OwnPtr<ScrollableArea> rootFrameViewport = | 362 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport = RootFrameViewport::cr
eate(*visualViewport.get(), *layoutViewport.get()); |
| 344 RootFrameViewport::create(visualViewport, layoutViewport); | |
| 345 | 363 |
| 346 // Test that the visual viewport is scrolled if the viewport has been | 364 // Test that the visual viewport is scrolled if the viewport has been |
| 347 // resized (as is the case when the ChromeOS keyboard comes up) but not | 365 // resized (as is the case when the ChromeOS keyboard comes up) but not |
| 348 // scaled. | 366 // scaled. |
| 349 visualViewport.setViewportSize(IntSize(100, 100)); | 367 visualViewport->setViewportSize(IntSize(100, 100)); |
| 350 rootFrameViewport->scrollIntoView( | 368 rootFrameViewport->scrollIntoView( |
| 351 LayoutRect(100, 250, 50, 50), | 369 LayoutRect(100, 250, 50, 50), |
| 352 ScrollAlignment::alignToEdgeIfNeeded, | 370 ScrollAlignment::alignToEdgeIfNeeded, |
| 353 ScrollAlignment::alignToEdgeIfNeeded); | 371 ScrollAlignment::alignToEdgeIfNeeded); |
| 354 EXPECT_POINT_EQ(DoublePoint(50, 150), layoutViewport.scrollPositionDouble())
; | 372 EXPECT_POINT_EQ(DoublePoint(50, 150), layoutViewport->scrollPositionDouble()
); |
| 355 EXPECT_POINT_EQ(DoublePoint(0, 50), visualViewport.scrollPositionDouble()); | 373 EXPECT_POINT_EQ(DoublePoint(0, 50), visualViewport->scrollPositionDouble()); |
| 356 | 374 |
| 357 rootFrameViewport->scrollIntoView( | 375 rootFrameViewport->scrollIntoView( |
| 358 LayoutRect(25, 75, 50, 50), | 376 LayoutRect(25, 75, 50, 50), |
| 359 ScrollAlignment::alignToEdgeIfNeeded, | 377 ScrollAlignment::alignToEdgeIfNeeded, |
| 360 ScrollAlignment::alignToEdgeIfNeeded); | 378 ScrollAlignment::alignToEdgeIfNeeded); |
| 361 EXPECT_POINT_EQ(DoublePoint(25, 25), layoutViewport.scrollPositionDouble()); | 379 EXPECT_POINT_EQ(DoublePoint(25, 25), layoutViewport->scrollPositionDouble())
; |
| 362 EXPECT_POINT_EQ(DoublePoint(0, 50), visualViewport.scrollPositionDouble()); | 380 EXPECT_POINT_EQ(DoublePoint(0, 50), visualViewport->scrollPositionDouble()); |
| 363 | 381 |
| 364 // Reset the pinch viewport's size, scale the page and repeat the test | 382 // Reset the pinch viewport's size, scale the page and repeat the test |
| 365 visualViewport.setViewportSize(IntSize(100, 150)); | 383 visualViewport->setViewportSize(IntSize(100, 150)); |
| 366 visualViewport.setScale(2); | 384 visualViewport->setScale(2); |
| 367 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); | 385 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); |
| 368 | 386 |
| 369 rootFrameViewport->scrollIntoView( | 387 rootFrameViewport->scrollIntoView( |
| 370 LayoutRect(50, 75, 50, 75), | 388 LayoutRect(50, 75, 50, 75), |
| 371 ScrollAlignment::alignToEdgeIfNeeded, | 389 ScrollAlignment::alignToEdgeIfNeeded, |
| 372 ScrollAlignment::alignToEdgeIfNeeded); | 390 ScrollAlignment::alignToEdgeIfNeeded); |
| 373 EXPECT_POINT_EQ(DoublePoint(50, 75), layoutViewport.scrollPositionDouble()); | 391 EXPECT_POINT_EQ(DoublePoint(50, 75), layoutViewport->scrollPositionDouble())
; |
| 374 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 392 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble()); |
| 375 | 393 |
| 376 rootFrameViewport->scrollIntoView( | 394 rootFrameViewport->scrollIntoView( |
| 377 LayoutRect(190, 290, 10, 10), | 395 LayoutRect(190, 290, 10, 10), |
| 378 ScrollAlignment::alignToEdgeIfNeeded, | 396 ScrollAlignment::alignToEdgeIfNeeded, |
| 379 ScrollAlignment::alignToEdgeIfNeeded); | 397 ScrollAlignment::alignToEdgeIfNeeded); |
| 380 EXPECT_POINT_EQ(DoublePoint(100, 150), layoutViewport.scrollPositionDouble()
); | 398 EXPECT_POINT_EQ(DoublePoint(100, 150), layoutViewport->scrollPositionDouble(
)); |
| 381 EXPECT_POINT_EQ(DoublePoint(50, 75), visualViewport.scrollPositionDouble()); | 399 EXPECT_POINT_EQ(DoublePoint(50, 75), visualViewport->scrollPositionDouble())
; |
| 382 | 400 |
| 383 // Scrolling into view the viewport rect itself should be a no-op. | 401 // Scrolling into view the viewport rect itself should be a no-op. |
| 384 visualViewport.setViewportSize(IntSize(100, 100)); | 402 visualViewport->setViewportSize(IntSize(100, 100)); |
| 385 visualViewport.setScale(1.5f); | 403 visualViewport->setScale(1.5f); |
| 386 visualViewport.setScrollPosition(DoublePoint(0, 10), ProgrammaticScroll); | 404 visualViewport->setScrollPosition(DoublePoint(0, 10), ProgrammaticScroll); |
| 387 layoutViewport.setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll); | 405 layoutViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll); |
| 388 rootFrameViewport->setScrollPosition(rootFrameViewport->scrollPositionDouble
(), ProgrammaticScroll); | 406 rootFrameViewport->setScrollPosition(rootFrameViewport->scrollPositionDouble
(), ProgrammaticScroll); |
| 389 | 407 |
| 390 rootFrameViewport->scrollIntoView( | 408 rootFrameViewport->scrollIntoView( |
| 391 LayoutRect(rootFrameViewport->visibleContentRectDouble(ExcludeScrollbars
)), | 409 LayoutRect(rootFrameViewport->visibleContentRectDouble(ExcludeScrollbars
)), |
| 392 ScrollAlignment::alignToEdgeIfNeeded, | 410 ScrollAlignment::alignToEdgeIfNeeded, |
| 393 ScrollAlignment::alignToEdgeIfNeeded); | 411 ScrollAlignment::alignToEdgeIfNeeded); |
| 394 EXPECT_POINT_EQ(DoublePoint(50, 50), layoutViewport.scrollPositionDouble()); | 412 EXPECT_POINT_EQ(DoublePoint(50, 50), layoutViewport->scrollPositionDouble())
; |
| 395 EXPECT_POINT_EQ(DoublePoint(0, 10), visualViewport.scrollPositionDouble()); | 413 EXPECT_POINT_EQ(DoublePoint(0, 10), visualViewport->scrollPositionDouble()); |
| 396 | 414 |
| 397 rootFrameViewport->scrollIntoView( | 415 rootFrameViewport->scrollIntoView( |
| 398 LayoutRect(rootFrameViewport->visibleContentRectDouble(ExcludeScrollbars
)), | 416 LayoutRect(rootFrameViewport->visibleContentRectDouble(ExcludeScrollbars
)), |
| 399 ScrollAlignment::alignCenterAlways, | 417 ScrollAlignment::alignCenterAlways, |
| 400 ScrollAlignment::alignCenterAlways); | 418 ScrollAlignment::alignCenterAlways); |
| 401 EXPECT_POINT_EQ(DoublePoint(50, 50), layoutViewport.scrollPositionDouble()); | 419 EXPECT_POINT_EQ(DoublePoint(50, 50), layoutViewport->scrollPositionDouble())
; |
| 402 EXPECT_POINT_EQ(DoublePoint(0, 10), visualViewport.scrollPositionDouble()); | 420 EXPECT_POINT_EQ(DoublePoint(0, 10), visualViewport->scrollPositionDouble()); |
| 403 | 421 |
| 404 rootFrameViewport->scrollIntoView( | 422 rootFrameViewport->scrollIntoView( |
| 405 LayoutRect(rootFrameViewport->visibleContentRectDouble(ExcludeScrollbars
)), | 423 LayoutRect(rootFrameViewport->visibleContentRectDouble(ExcludeScrollbars
)), |
| 406 ScrollAlignment::alignTopAlways, | 424 ScrollAlignment::alignTopAlways, |
| 407 ScrollAlignment::alignTopAlways); | 425 ScrollAlignment::alignTopAlways); |
| 408 EXPECT_POINT_EQ(DoublePoint(50, 50), layoutViewport.scrollPositionDouble()); | 426 EXPECT_POINT_EQ(DoublePoint(50, 50), layoutViewport->scrollPositionDouble())
; |
| 409 EXPECT_POINT_EQ(DoublePoint(0, 10), visualViewport.scrollPositionDouble()); | 427 EXPECT_POINT_EQ(DoublePoint(0, 10), visualViewport->scrollPositionDouble()); |
| 410 } | 428 } |
| 411 | 429 |
| 412 // Tests that the setScrollPosition method works correctly with both viewports. | 430 // Tests that the setScrollPosition method works correctly with both viewports. |
| 413 TEST_F(RootFrameViewportTest, SetScrollPosition) | 431 TEST_F(RootFrameViewportTest, SetScrollPosition) |
| 414 { | 432 { |
| 415 IntSize viewportSize(500, 500); | 433 IntSize viewportSize(500, 500); |
| 416 RootFrameViewStub layoutViewport(viewportSize, IntSize(1000, 2000)); | 434 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr
eate(viewportSize, IntSize(1000, 2000)); |
| 417 VisualViewportStub visualViewport(viewportSize, viewportSize); | 435 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub::
create(viewportSize, viewportSize); |
| 418 | 436 |
| 419 OwnPtr<ScrollableArea> rootFrameViewport = | 437 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport = RootFrameViewport::cr
eate(*visualViewport.get(), *layoutViewport.get()); |
| 420 RootFrameViewport::create(visualViewport, layoutViewport); | |
| 421 | 438 |
| 422 visualViewport.setScale(2); | 439 visualViewport->setScale(2); |
| 423 | 440 |
| 424 // Ensure that the layout viewport scrolls first. | 441 // Ensure that the layout viewport scrolls first. |
| 425 rootFrameViewport->setScrollPosition(DoublePoint(100, 100), ProgrammaticScro
ll); | 442 rootFrameViewport->setScrollPosition(DoublePoint(100, 100), ProgrammaticScro
ll); |
| 426 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 443 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble()); |
| 427 EXPECT_POINT_EQ(DoublePoint(100, 100), layoutViewport.scrollPositionDouble()
); | 444 EXPECT_POINT_EQ(DoublePoint(100, 100), layoutViewport->scrollPositionDouble(
)); |
| 428 | 445 |
| 429 // Scroll to the layout viewport's extent, the visual viewport should scroll
the | 446 // Scroll to the layout viewport's extent, the visual viewport should scroll
the |
| 430 // remainder. | 447 // remainder. |
| 431 rootFrameViewport->setScrollPosition(DoublePoint(700, 1700), ProgrammaticScr
oll); | 448 rootFrameViewport->setScrollPosition(DoublePoint(700, 1700), ProgrammaticScr
oll); |
| 432 EXPECT_POINT_EQ(DoublePoint(200, 200), visualViewport.scrollPositionDouble()
); | 449 EXPECT_POINT_EQ(DoublePoint(200, 200), visualViewport->scrollPositionDouble(
)); |
| 433 EXPECT_POINT_EQ(DoublePoint(500, 1500), layoutViewport.scrollPositionDouble(
)); | 450 EXPECT_POINT_EQ(DoublePoint(500, 1500), layoutViewport->scrollPositionDouble
()); |
| 434 | 451 |
| 435 // Only the visual viewport should scroll further. Make sure it doesn't scro
ll | 452 // Only the visual viewport should scroll further. Make sure it doesn't scro
ll |
| 436 // out of bounds. | 453 // out of bounds. |
| 437 rootFrameViewport->setScrollPosition(DoublePoint(780, 1780), ProgrammaticScr
oll); | 454 rootFrameViewport->setScrollPosition(DoublePoint(780, 1780), ProgrammaticScr
oll); |
| 438 EXPECT_POINT_EQ(DoublePoint(250, 250), visualViewport.scrollPositionDouble()
); | 455 EXPECT_POINT_EQ(DoublePoint(250, 250), visualViewport->scrollPositionDouble(
)); |
| 439 EXPECT_POINT_EQ(DoublePoint(500, 1500), layoutViewport.scrollPositionDouble(
)); | 456 EXPECT_POINT_EQ(DoublePoint(500, 1500), layoutViewport->scrollPositionDouble
()); |
| 440 | 457 |
| 441 // Scroll all the way back. | 458 // Scroll all the way back. |
| 442 rootFrameViewport->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll); | 459 rootFrameViewport->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll); |
| 443 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport.scrollPositionDouble()); | 460 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble()); |
| 444 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport.scrollPositionDouble()); | 461 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble()); |
| 445 } | 462 } |
| 446 | 463 |
| 447 // Tests that the visible rect (i.e. visual viewport rect) is correctly | 464 // Tests that the visible rect (i.e. visual viewport rect) is correctly |
| 448 // calculated, taking into account both viewports and page scale. | 465 // calculated, taking into account both viewports and page scale. |
| 449 TEST_F(RootFrameViewportTest, VisibleContentRect) | 466 TEST_F(RootFrameViewportTest, VisibleContentRect) |
| 450 { | 467 { |
| 451 IntSize viewportSize(500, 401); | 468 IntSize viewportSize(500, 401); |
| 452 RootFrameViewStub layoutViewport(viewportSize, IntSize(1000, 2000)); | 469 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr
eate(viewportSize, IntSize(1000, 2000)); |
| 453 VisualViewportStub visualViewport(viewportSize, viewportSize); | 470 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub::
create(viewportSize, viewportSize); |
| 454 | 471 |
| 455 OwnPtr<ScrollableArea> rootFrameViewport = | 472 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport = RootFrameViewport::cr
eate(*visualViewport.get(), *layoutViewport.get()); |
| 456 RootFrameViewport::create(visualViewport, layoutViewport); | |
| 457 | 473 |
| 458 rootFrameViewport->setScrollPosition(DoublePoint(100, 75), ProgrammaticScrol
l); | 474 rootFrameViewport->setScrollPosition(DoublePoint(100, 75), ProgrammaticScrol
l); |
| 459 | 475 |
| 460 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRect(
).location()); | 476 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRect(
).location()); |
| 461 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRectD
ouble().location()); | 477 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRectD
ouble().location()); |
| 462 EXPECT_SIZE_EQ(DoubleSize(500, 401), rootFrameViewport->visibleContentRect()
.size()); | 478 EXPECT_SIZE_EQ(DoubleSize(500, 401), rootFrameViewport->visibleContentRect()
.size()); |
| 463 EXPECT_SIZE_EQ(DoubleSize(500, 401), rootFrameViewport->visibleContentRectDo
uble().size()); | 479 EXPECT_SIZE_EQ(DoubleSize(500, 401), rootFrameViewport->visibleContentRectDo
uble().size()); |
| 464 | 480 |
| 465 visualViewport.setScale(2); | 481 visualViewport->setScale(2); |
| 466 | 482 |
| 467 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRect(
).location()); | 483 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRect(
).location()); |
| 468 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRectD
ouble().location()); | 484 EXPECT_POINT_EQ(DoublePoint(100, 75), rootFrameViewport->visibleContentRectD
ouble().location()); |
| 469 EXPECT_SIZE_EQ(DoubleSize(250, 201), rootFrameViewport->visibleContentRect()
.size()); | 485 EXPECT_SIZE_EQ(DoubleSize(250, 201), rootFrameViewport->visibleContentRect()
.size()); |
| 470 EXPECT_SIZE_EQ(DoubleSize(250, 200.5), rootFrameViewport->visibleContentRect
Double().size()); | 486 EXPECT_SIZE_EQ(DoubleSize(250, 200.5), rootFrameViewport->visibleContentRect
Double().size()); |
| 471 } | 487 } |
| 472 | 488 |
| 473 // Tests that wheel events are correctly handled in the non-root layer scrolls | 489 // Tests that wheel events are correctly handled in the non-root layer scrolls |
| 474 // path. | 490 // path. |
| 475 TEST_F(RootFrameViewportTest, BasicWheelEvent) | 491 TEST_F(RootFrameViewportTest, BasicWheelEvent) |
| 476 { | 492 { |
| 477 IntSize viewportSize(100, 100); | 493 IntSize viewportSize(100, 100); |
| 478 RootFrameViewStub layoutViewport(viewportSize, IntSize(200, 300)); | 494 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr
eate(viewportSize, IntSize(200, 300)); |
| 479 VisualViewportStub visualViewport(viewportSize, viewportSize); | 495 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub::
create(viewportSize, viewportSize); |
| 480 | 496 |
| 481 OwnPtr<ScrollableArea> rootFrameViewport = | 497 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport = RootFrameViewport::cr
eate(*visualViewport.get(), *layoutViewport.get()); |
| 482 RootFrameViewport::create(visualViewport, layoutViewport); | |
| 483 | 498 |
| 484 visualViewport.setScale(2); | 499 visualViewport->setScale(2); |
| 485 | 500 |
| 486 PlatformWheelEvent wheelEvent( | 501 PlatformWheelEvent wheelEvent( |
| 487 IntPoint(10, 10), IntPoint(10, 10), | 502 IntPoint(10, 10), IntPoint(10, 10), |
| 488 -500, -500, | 503 -500, -500, |
| 489 0, 0, | 504 0, 0, |
| 490 ScrollByPixelWheelEvent, | 505 ScrollByPixelWheelEvent, |
| 491 false, false, false, false); | 506 false, false, false, false); |
| 492 | 507 |
| 493 ScrollResult result = rootFrameViewport->handleWheel(wheelEvent); | 508 ScrollResult result = rootFrameViewport->handleWheel(wheelEvent); |
| 494 | 509 |
| 495 EXPECT_TRUE(result.didScroll()); | 510 EXPECT_TRUE(result.didScroll()); |
| 496 EXPECT_POINT_EQ(DoublePoint(50, 50), visualViewport.scrollPositionDouble()); | 511 EXPECT_POINT_EQ(DoublePoint(50, 50), visualViewport->scrollPositionDouble())
; |
| 497 EXPECT_POINT_EQ(DoublePoint(100, 200), layoutViewport.scrollPositionDouble()
); | 512 EXPECT_POINT_EQ(DoublePoint(100, 200), layoutViewport->scrollPositionDouble(
)); |
| 498 EXPECT_EQ(350, result.unusedScrollDeltaX); | 513 EXPECT_EQ(350, result.unusedScrollDeltaX); |
| 499 EXPECT_EQ(250, result.unusedScrollDeltaY); | 514 EXPECT_EQ(250, result.unusedScrollDeltaY); |
| 500 } | 515 } |
| 501 | 516 |
| 502 } // namespace blink | 517 } // namespace blink |
| OLD | NEW |