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

Side by Side Diff: Source/core/platform/ScrollableArea.cpp

Issue 16982005: Allow objects without scrollbars to be scrollable (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed ScrollbarGroup pageStep Created 7 years, 4 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
« no previous file with comments | « Source/core/platform/ScrollableArea.h ('k') | Source/core/platform/Scrollbar.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010, Google Inc. All rights reserved. 2 * Copyright (c) 2010, Google Inc. All rights reserved.
3 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved. 3 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 22 matching lines...) Expand all
33 #include "core/platform/ScrollableArea.h" 33 #include "core/platform/ScrollableArea.h"
34 34
35 #include "core/platform/ScrollAnimator.h" 35 #include "core/platform/ScrollAnimator.h"
36 #include "core/platform/ScrollbarTheme.h" 36 #include "core/platform/ScrollbarTheme.h"
37 #include "core/platform/graphics/FloatPoint.h" 37 #include "core/platform/graphics/FloatPoint.h"
38 #include "core/platform/graphics/GraphicsLayer.h" 38 #include "core/platform/graphics/GraphicsLayer.h"
39 #include "wtf/PassOwnPtr.h" 39 #include "wtf/PassOwnPtr.h"
40 40
41 #include "core/platform/chromium/TraceEvent.h" 41 #include "core/platform/chromium/TraceEvent.h"
42 42
43 static const int kPixelsPerLineStep = 40;
44 static const float kMinFractionToStepWhenPaging = 0.875f;
45
43 namespace WebCore { 46 namespace WebCore {
44 47
45 struct SameSizeAsScrollableArea { 48 struct SameSizeAsScrollableArea {
46 virtual ~SameSizeAsScrollableArea(); 49 virtual ~SameSizeAsScrollableArea();
47 void* pointer; 50 void* pointer;
48 unsigned bitfields : 16; 51 unsigned bitfields : 16;
49 IntPoint origin; 52 IntPoint origin;
50 }; 53 };
51 54
52 COMPILE_ASSERT(sizeof(ScrollableArea) == sizeof(SameSizeAsScrollableArea), Scrol lableArea_should_stay_small); 55 COMPILE_ASSERT(sizeof(ScrollableArea) == sizeof(SameSizeAsScrollableArea), Scrol lableArea_should_stay_small);
53 56
57 int ScrollableArea::pixelsPerLineStep()
58 {
59 return kPixelsPerLineStep;
60 }
61
62 float ScrollableArea::minFractionToStepWhenPaging()
63 {
64 return kMinFractionToStepWhenPaging;
65 }
66
67 int ScrollableArea::maxOverlapBetweenPages()
68 {
69 static int maxOverlapBetweenPages = ScrollbarTheme::theme()->maxOverlapBetwe enPages();
70 return maxOverlapBetweenPages;
71 }
72
54 ScrollableArea::ScrollableArea() 73 ScrollableArea::ScrollableArea()
55 : m_constrainsScrollingToContentEdge(true) 74 : m_constrainsScrollingToContentEdge(true)
56 , m_inLiveResize(false) 75 , m_inLiveResize(false)
57 , m_verticalScrollElasticity(ScrollElasticityNone) 76 , m_verticalScrollElasticity(ScrollElasticityNone)
58 , m_horizontalScrollElasticity(ScrollElasticityNone) 77 , m_horizontalScrollElasticity(ScrollElasticityNone)
59 , m_scrollbarOverlayStyle(ScrollbarOverlayStyleDefault) 78 , m_scrollbarOverlayStyle(ScrollbarOverlayStyleDefault)
60 , m_scrollOriginChanged(false) 79 , m_scrollOriginChanged(false)
61 { 80 {
62 } 81 }
63 82
(...skipping 13 matching lines...) Expand all
77 { 96 {
78 if (m_scrollOrigin != origin) { 97 if (m_scrollOrigin != origin) {
79 m_scrollOrigin = origin; 98 m_scrollOrigin = origin;
80 m_scrollOriginChanged = true; 99 m_scrollOriginChanged = true;
81 } 100 }
82 } 101 }
83 102
84 bool ScrollableArea::scroll(ScrollDirection direction, ScrollGranularity granula rity, float multiplier) 103 bool ScrollableArea::scroll(ScrollDirection direction, ScrollGranularity granula rity, float multiplier)
85 { 104 {
86 ScrollbarOrientation orientation; 105 ScrollbarOrientation orientation;
87 Scrollbar* scrollbar; 106
88 if (direction == ScrollUp || direction == ScrollDown) { 107 if (direction == ScrollUp || direction == ScrollDown)
89 orientation = VerticalScrollbar; 108 orientation = VerticalScrollbar;
90 scrollbar = verticalScrollbar(); 109 else
91 } else {
92 orientation = HorizontalScrollbar; 110 orientation = HorizontalScrollbar;
93 scrollbar = horizontalScrollbar();
94 }
95 111
96 if (!scrollbar) 112 if (!userInputScrollable(orientation))
97 return false; 113 return false;
98 114
99 float step = 0; 115 float step = 0;
100 switch (granularity) { 116 switch (granularity) {
101 case ScrollByLine: 117 case ScrollByLine:
102 step = scrollbar->lineStep(); 118 step = lineStep(orientation);
103 break; 119 break;
104 case ScrollByPage: 120 case ScrollByPage:
105 step = scrollbar->pageStep(); 121 step = pageStep(orientation);
106 break; 122 break;
107 case ScrollByDocument: 123 case ScrollByDocument:
108 step = scrollbar->totalSize(); 124 step = documentStep(orientation);
109 break; 125 break;
110 case ScrollByPixel: 126 case ScrollByPixel:
111 case ScrollByPrecisePixel: 127 case ScrollByPrecisePixel:
112 step = scrollbar->pixelStep(); 128 step = pixelStep(orientation);
113 break; 129 break;
114 } 130 }
115 131
116 if (direction == ScrollUp || direction == ScrollLeft) 132 if (direction == ScrollUp || direction == ScrollLeft)
117 multiplier = -multiplier; 133 multiplier = -multiplier;
118 134
119 return scrollAnimator()->scroll(orientation, granularity, step, multiplier); 135 return scrollAnimator()->scroll(orientation, granularity, step, multiplier);
120 } 136 }
121 137
122 void ScrollableArea::scrollToOffsetWithoutAnimation(const FloatPoint& offset) 138 void ScrollableArea::scrollToOffsetWithoutAnimation(const FloatPoint& offset)
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 { 372 {
357 return layerForScrollCorner(); 373 return layerForScrollCorner();
358 } 374 }
359 375
360 void ScrollableArea::serviceScrollAnimations() 376 void ScrollableArea::serviceScrollAnimations()
361 { 377 {
362 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) 378 if (ScrollAnimator* scrollAnimator = existingScrollAnimator())
363 scrollAnimator->serviceScrollAnimations(); 379 scrollAnimator->serviceScrollAnimations();
364 } 380 }
365 381
366 IntPoint ScrollableArea::scrollPosition() const
367 {
368 int x = horizontalScrollbar() ? horizontalScrollbar()->value() : 0;
369 int y = verticalScrollbar() ? verticalScrollbar()->value() : 0;
370 return IntPoint(x, y);
371 }
372
373 IntPoint ScrollableArea::minimumScrollPosition() const
374 {
375 return IntPoint();
376 }
377
378 IntPoint ScrollableArea::maximumScrollPosition() const
379 {
380 return IntPoint(contentsSize().width() - visibleWidth(), contentsSize().heig ht() - visibleHeight());
381 }
382
383 IntRect ScrollableArea::visibleContentRect(VisibleContentRectIncludesScrollbars scrollbarInclusion) const 382 IntRect ScrollableArea::visibleContentRect(VisibleContentRectIncludesScrollbars scrollbarInclusion) const
384 { 383 {
385 int verticalScrollbarWidth = 0; 384 int verticalScrollbarWidth = 0;
386 int horizontalScrollbarHeight = 0; 385 int horizontalScrollbarHeight = 0;
387 386
388 if (scrollbarInclusion == IncludeScrollbars) { 387 if (scrollbarInclusion == IncludeScrollbars) {
389 if (Scrollbar* verticalBar = verticalScrollbar()) 388 if (Scrollbar* verticalBar = verticalScrollbar())
390 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? vertic alBar->width() : 0; 389 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? vertic alBar->width() : 0;
391 if (Scrollbar* horizontalBar = horizontalScrollbar()) 390 if (Scrollbar* horizontalBar = horizontalScrollbar())
392 horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? h orizontalBar->height() : 0; 391 horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? h orizontalBar->height() : 0;
393 } 392 }
394 393
395 return IntRect(scrollPosition().x(), 394 return IntRect(scrollPosition().x(),
396 scrollPosition().y(), 395 scrollPosition().y(),
397 std::max(0, visibleWidth() + verticalScrollbarWidth), 396 std::max(0, visibleWidth() + verticalScrollbarWidth),
398 std::max(0, visibleHeight() + horizontalScrollbarHeight)); 397 std::max(0, visibleHeight() + horizontalScrollbarHeight));
399 } 398 }
400 399
401 IntPoint ScrollableArea::clampScrollPosition(const IntPoint& scrollPosition) con st 400 IntPoint ScrollableArea::clampScrollPosition(const IntPoint& scrollPosition) con st
402 { 401 {
403 return scrollPosition.shrunkTo(maximumScrollPosition()).expandedTo(minimumSc rollPosition()); 402 return scrollPosition.shrunkTo(maximumScrollPosition()).expandedTo(minimumSc rollPosition());
404 } 403 }
405 404
405 int ScrollableArea::lineStep(ScrollbarOrientation) const
406 {
407 return pixelsPerLineStep();
408 }
409
410 int ScrollableArea::documentStep(ScrollbarOrientation orientation) const
411 {
412 return scrollSize(orientation);
413 }
414
415 float ScrollableArea::pixelStep(ScrollbarOrientation) const
416 {
417 return 1;
418 }
419
406 } // namespace WebCore 420 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/platform/ScrollableArea.h ('k') | Source/core/platform/Scrollbar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698