Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/WebKit/Source/core/frame/RootFrameViewportTest.cpp

Issue 1738243002: Removed main-thread one dimensional scrolling paths. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@removeStepFromUserScroll
Patch Set: Rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "core/frame/RootFrameViewport.h" 5 #include "core/frame/RootFrameViewport.h"
6 6
7 #include "core/layout/ScrollAlignment.h" 7 #include "core/layout/ScrollAlignment.h"
8 #include "platform/geometry/DoubleRect.h" 8 #include "platform/geometry/DoubleRect.h"
9 #include "platform/geometry/LayoutRect.h" 9 #include "platform/geometry/LayoutRect.h"
10 #include "platform/scroll/ScrollableArea.h" 10 #include "platform/scroll/ScrollableArea.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // Disable just the layout viewport's horizontal scrolling, the 199 // Disable just the layout viewport's horizontal scrolling, the
200 // RootFrameViewport should remain scrollable overall. 200 // RootFrameViewport should remain scrollable overall.
201 layoutViewport->setUserInputScrollable(false, true); 201 layoutViewport->setUserInputScrollable(false, true);
202 visualViewport->setUserInputScrollable(true, true); 202 visualViewport->setUserInputScrollable(true, true);
203 203
204 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); 204 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar));
205 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); 205 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar));
206 206
207 // Layout viewport shouldn't scroll since it's not horizontally scrollable, 207 // Layout viewport shouldn't scroll since it's not horizontally scrollable,
208 // but visual viewport should. 208 // but visual viewport should.
209 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); 209 rootFrameViewport->userScroll(ScrollByPixel, FloatSize(300, 0));
210 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble()); 210 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble());
211 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport->scrollPositionDouble()); 211 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport->scrollPositionDouble());
212 EXPECT_POINT_EQ(DoublePoint(50, 0), rootFrameViewport->scrollPositionDouble( )); 212 EXPECT_POINT_EQ(DoublePoint(50, 0), rootFrameViewport->scrollPositionDouble( ));
213 213
214 // Disable just the visual viewport's horizontal scrolling, only the layout
215 // viewport should scroll.
216 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll);
217 layoutViewport->setUserInputScrollable(true, true);
218 visualViewport->setUserInputScrollable(false, true);
219
220 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300);
221 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport->scrollPositionDouble()) ;
222 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble());
223 EXPECT_POINT_EQ(DoublePoint(100, 0), rootFrameViewport->scrollPositionDouble ());
224
225 // Disable both viewports' horizontal scrolling, all horizontal scrolling
226 // should now be blocked.
227 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll);
228 layoutViewport->setUserInputScrollable(false, true);
229 visualViewport->setUserInputScrollable(false, true);
230
231 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300);
232 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble());
233 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble());
234 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble() );
235
236 EXPECT_FALSE(rootFrameViewport->userInputScrollable(HorizontalScrollbar));
237 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar));
238
239 // Vertical scrolling should be unaffected. 214 // Vertical scrolling should be unaffected.
240 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); 215 rootFrameViewport->userScroll(ScrollByPixel, FloatSize(0, 300));
241 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport->scrollPositionDouble()) ; 216 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport->scrollPositionDouble()) ;
242 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport->scrollPositionDouble()); 217 EXPECT_POINT_EQ(DoublePoint(50, 75), visualViewport->scrollPositionDouble()) ;
243 EXPECT_POINT_EQ(DoublePoint(0, 225), rootFrameViewport->scrollPositionDouble ()); 218 EXPECT_POINT_EQ(DoublePoint(50, 225), rootFrameViewport->scrollPositionDoubl e());
244 219
245 // Try the same checks as above but for the vertical direction. 220 // Try the same checks as above but for the vertical direction.
246 // =============================================== 221 // ===============================================
247 222
248 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll); 223 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll);
249 224
250 // Disable just the layout viewport's vertical scrolling, the 225 // Disable just the layout viewport's vertical scrolling, the
251 // RootFrameViewport should remain scrollable overall. 226 // RootFrameViewport should remain scrollable overall.
252 layoutViewport->setUserInputScrollable(true, false); 227 layoutViewport->setUserInputScrollable(true, false);
253 visualViewport->setUserInputScrollable(true, true); 228 visualViewport->setUserInputScrollable(true, true);
254 229
255 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar)); 230 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar));
256 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar)); 231 EXPECT_TRUE(rootFrameViewport->userInputScrollable(VerticalScrollbar));
257 232
258 // Layout viewport shouldn't scroll since it's not vertically scrollable, 233 // Layout viewport shouldn't scroll since it's not vertically scrollable,
259 // but visual viewport should. 234 // but visual viewport should.
260 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300); 235 rootFrameViewport->userScroll(ScrollByPixel, FloatSize(0, 300));
261 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble()); 236 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble());
262 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport->scrollPositionDouble()); 237 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport->scrollPositionDouble());
263 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble( )); 238 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble( ));
264 239
265 // Disable just the visual viewport's vertical scrolling, only the layout
266 // viewport should scroll.
267 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll);
268 layoutViewport->setUserInputScrollable(true, true);
269 visualViewport->setUserInputScrollable(true, false);
270
271 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300);
272 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport->scrollPositionDouble()) ;
273 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble());
274 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble ());
275
276 // Disable both viewports' horizontal scrolling, all vertical scrolling
277 // should now be blocked.
278 rootFrameViewport->setScrollPosition(DoublePoint(), ProgrammaticScroll);
279 layoutViewport->setUserInputScrollable(true, false);
280 visualViewport->setUserInputScrollable(true, false);
281
282 rootFrameViewport->userScroll(ScrollDown, ScrollByPixel, 300);
283 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble());
284 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble());
285 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble() );
286
287 EXPECT_TRUE(rootFrameViewport->userInputScrollable(HorizontalScrollbar));
288 EXPECT_FALSE(rootFrameViewport->userInputScrollable(VerticalScrollbar));
289
290 // Horizontal scrolling should be unaffected. 240 // Horizontal scrolling should be unaffected.
291 rootFrameViewport->userScroll(ScrollRight, ScrollByPixel, 300); 241 rootFrameViewport->userScroll(ScrollByPixel, FloatSize(300, 0));
292 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport->scrollPositionDouble()) ; 242 EXPECT_POINT_EQ(DoublePoint(100, 0), layoutViewport->scrollPositionDouble()) ;
293 EXPECT_POINT_EQ(DoublePoint(50, 0), visualViewport->scrollPositionDouble()); 243 EXPECT_POINT_EQ(DoublePoint(50, 75), visualViewport->scrollPositionDouble()) ;
294 EXPECT_POINT_EQ(DoublePoint(150, 0), rootFrameViewport->scrollPositionDouble ()); 244 EXPECT_POINT_EQ(DoublePoint(150, 75), rootFrameViewport->scrollPositionDoubl e());
295 } 245 }
296 246
297 // Make sure scrolls using the scroll animator (scroll(), setScrollPosition()) 247 // Make sure scrolls using the scroll animator (scroll(), setScrollPosition())
298 // work correctly when one of the subviewports is explicitly scrolled without us ing the 248 // work correctly when one of the subviewports is explicitly scrolled without us ing the
299 // RootFrameViewport interface. 249 // RootFrameViewport interface.
300 TEST_F(RootFrameViewportTest, TestScrollAnimatorUpdatedBeforeScroll) 250 TEST_F(RootFrameViewportTest, TestScrollAnimatorUpdatedBeforeScroll)
301 { 251 {
302 IntSize viewportSize(100, 150); 252 IntSize viewportSize(100, 150);
303 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr eate(viewportSize, IntSize(200, 300)); 253 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr eate(viewportSize, IntSize(200, 300));
304 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub:: create(viewportSize, viewportSize); 254 OwnPtrWillBeRawPtr<VisualViewportStub> visualViewport = VisualViewportStub:: create(viewportSize, viewportSize);
305 255
306 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport = RootFrameViewport::cr eate(*visualViewport.get(), *layoutViewport.get()); 256 OwnPtrWillBeRawPtr<ScrollableArea> rootFrameViewport = RootFrameViewport::cr eate(*visualViewport.get(), *layoutViewport.get());
307 257
308 visualViewport->setScale(2); 258 visualViewport->setScale(2);
309 259
310 visualViewport->setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll); 260 visualViewport->setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll);
311 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble ()); 261 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble ());
312 262
313 // If the scroll animator doesn't update, it will still think it's at (0, 0) and so it 263 // If the scroll animator doesn't update, it will still think it's at (0, 0) and so it
314 // may early exit. 264 // may early exit.
315 rootFrameViewport->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll); 265 rootFrameViewport->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll);
316 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble() ); 266 EXPECT_POINT_EQ(DoublePoint(0, 0), rootFrameViewport->scrollPositionDouble() );
317 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble()); 267 EXPECT_POINT_EQ(DoublePoint(0, 0), visualViewport->scrollPositionDouble());
318 268
319 // Try again for userScroll() 269 // Try again for userScroll()
320 visualViewport->setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll); 270 visualViewport->setScrollPosition(DoublePoint(50, 75), ProgrammaticScroll);
321 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble ()); 271 EXPECT_POINT_EQ(DoublePoint(50, 75), rootFrameViewport->scrollPositionDouble ());
322 272
323 rootFrameViewport->userScroll(ScrollLeft, ScrollByPixel, 50); 273 rootFrameViewport->userScroll(ScrollByPixel, FloatSize(-50, 0));
324 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble( )); 274 EXPECT_POINT_EQ(DoublePoint(0, 75), rootFrameViewport->scrollPositionDouble( ));
325 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport->scrollPositionDouble()); 275 EXPECT_POINT_EQ(DoublePoint(0, 75), visualViewport->scrollPositionDouble());
326 276
327 // Make sure the layout viewport is also accounted for. 277 // Make sure the layout viewport is also accounted for.
328 rootFrameViewport->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll); 278 rootFrameViewport->setScrollPosition(DoublePoint(0, 0), ProgrammaticScroll);
329 layoutViewport->setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll) ; 279 layoutViewport->setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll) ;
330 EXPECT_POINT_EQ(DoublePoint(100, 150), rootFrameViewport->scrollPositionDoub le()); 280 EXPECT_POINT_EQ(DoublePoint(100, 150), rootFrameViewport->scrollPositionDoub le());
331 281
332 rootFrameViewport->userScroll(ScrollLeft, ScrollByPixel, 100); 282 rootFrameViewport->userScroll(ScrollByPixel, FloatSize(-100, 0));
333 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble ()); 283 EXPECT_POINT_EQ(DoublePoint(0, 150), rootFrameViewport->scrollPositionDouble ());
334 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport->scrollPositionDouble()) ; 284 EXPECT_POINT_EQ(DoublePoint(0, 150), layoutViewport->scrollPositionDouble()) ;
335 } 285 }
336 286
337 // Test that the scrollIntoView correctly scrolls the main frame 287 // Test that the scrollIntoView correctly scrolls the main frame
338 // and visual viewport such that the given rect is centered in the viewport. 288 // and visual viewport such that the given rect is centered in the viewport.
339 TEST_F(RootFrameViewportTest, ScrollIntoView) 289 TEST_F(RootFrameViewportTest, ScrollIntoView)
340 { 290 {
341 IntSize viewportSize(100, 150); 291 IntSize viewportSize(100, 150);
342 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr eate(viewportSize, IntSize(200, 300)); 292 OwnPtrWillBeRawPtr<RootFrameViewStub> layoutViewport = RootFrameViewStub::cr eate(viewportSize, IntSize(200, 300));
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 rootFrameViewport->setScrollPosition(DoublePoint(40, 40), UserScroll); 435 rootFrameViewport->setScrollPosition(DoublePoint(40, 40), UserScroll);
486 EXPECT_POINT_EQ(DoublePoint(40, 40), visualViewport->scrollPositionDouble()) ; 436 EXPECT_POINT_EQ(DoublePoint(40, 40), visualViewport->scrollPositionDouble()) ;
487 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble()); 437 EXPECT_POINT_EQ(DoublePoint(0, 0), layoutViewport->scrollPositionDouble());
488 438
489 rootFrameViewport->setScrollPosition(DoublePoint(60, 60), ProgrammaticScroll ); 439 rootFrameViewport->setScrollPosition(DoublePoint(60, 60), ProgrammaticScroll );
490 EXPECT_POINT_EQ(DoublePoint(50, 50), visualViewport->scrollPositionDouble()) ; 440 EXPECT_POINT_EQ(DoublePoint(50, 50), visualViewport->scrollPositionDouble()) ;
491 EXPECT_POINT_EQ(DoublePoint(10, 10), layoutViewport->scrollPositionDouble()) ; 441 EXPECT_POINT_EQ(DoublePoint(10, 10), layoutViewport->scrollPositionDouble()) ;
492 } 442 }
493 443
494 } // namespace blink 444 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/RootFrameViewport.cpp ('k') | third_party/WebKit/Source/core/input/EventHandler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698