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

Side by Side Diff: sky/engine/platform/scroll/ScrollableArea.cpp

Issue 879993004: Remove ScrollableArea and Scrollbar (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 | « sky/engine/platform/scroll/ScrollableArea.h ('k') | sky/engine/platform/scroll/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
(Empty)
1 /*
2 * Copyright (c) 2010, Google Inc. All rights reserved.
3 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include "sky/engine/config.h"
33 #include "sky/engine/platform/scroll/ScrollableArea.h"
34
35 #include "sky/engine/platform/HostWindow.h"
36 #include "sky/engine/platform/Logging.h"
37 #include "sky/engine/platform/TraceEvent.h"
38 #include "sky/engine/platform/geometry/FloatPoint.h"
39 #include "sky/engine/platform/scroll/Scrollbar.h"
40 #include "sky/engine/public/platform/WebString.h"
41 #include "sky/engine/wtf/PassOwnPtr.h"
42
43 static const int kPixelsPerLineStep = 40;
44 static const float kMinFractionToStepWhenPaging = 0.875f;
45
46 namespace blink {
47
48 struct SameSizeAsScrollableArea {
49 virtual ~SameSizeAsScrollableArea();
50 void* pointer;
51 unsigned bitfields : 16;
52 IntPoint origin;
53 };
54
55 COMPILE_ASSERT(sizeof(ScrollableArea) == sizeof(SameSizeAsScrollableArea), Scrol lableArea_should_stay_small);
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 = std::numeric_limits<int>::max();
70 return maxOverlapBetweenPages;
71 }
72
73 ScrollableArea::ScrollableArea()
74 : m_constrainsScrollingToContentEdge(true)
75 , m_verticalScrollElasticity(ScrollElasticityNone)
76 , m_horizontalScrollElasticity(ScrollElasticityNone)
77 , m_scrollOriginChanged(false)
78 {
79 }
80
81 ScrollableArea::~ScrollableArea()
82 {
83 }
84
85 ScrollAnimator* ScrollableArea::scrollAnimator() const
86 {
87 if (!m_animators)
88 m_animators = adoptPtr(new ScrollableAreaAnimators);
89
90 if (!m_animators->scrollAnimator)
91 m_animators->scrollAnimator = ScrollAnimator::create(const_cast<Scrollab leArea*>(this));
92
93 return m_animators->scrollAnimator.get();
94 }
95
96 void ScrollableArea::setScrollOrigin(const IntPoint& origin)
97 {
98 if (m_scrollOrigin != origin) {
99 m_scrollOrigin = origin;
100 m_scrollOriginChanged = true;
101 }
102 }
103
104 bool ScrollableArea::scroll(ScrollDirection direction, ScrollGranularity granula rity, float delta)
105 {
106 ScrollbarOrientation orientation;
107
108 if (direction == ScrollUp || direction == ScrollDown)
109 orientation = VerticalScrollbar;
110 else
111 orientation = HorizontalScrollbar;
112
113 if (!userInputScrollable(orientation))
114 return false;
115
116 float step = 0;
117 switch (granularity) {
118 case ScrollByLine:
119 step = lineStep(orientation);
120 break;
121 case ScrollByPage:
122 step = pageStep(orientation);
123 break;
124 case ScrollByDocument:
125 step = documentStep(orientation);
126 break;
127 case ScrollByPixel:
128 case ScrollByPrecisePixel:
129 step = pixelStep(orientation);
130 break;
131 }
132
133 if (direction == ScrollUp || direction == ScrollLeft)
134 delta = -delta;
135
136 return scrollAnimator()->scroll(orientation, granularity, step, delta);
137 }
138
139 void ScrollableArea::scrollToOffsetWithoutAnimation(const FloatPoint& offset)
140 {
141 scrollAnimator()->scrollToOffsetWithoutAnimation(offset);
142 }
143
144 void ScrollableArea::scrollToOffsetWithoutAnimation(ScrollbarOrientation orienta tion, float offset)
145 {
146 if (orientation == HorizontalScrollbar)
147 scrollToOffsetWithoutAnimation(FloatPoint(offset, scrollAnimator()->curr entPosition().y()));
148 else
149 scrollToOffsetWithoutAnimation(FloatPoint(scrollAnimator()->currentPosit ion().x(), offset));
150 }
151
152 void ScrollableArea::scrollPositionChanged(const IntPoint& position)
153 {
154 TRACE_EVENT0("blink", "ScrollableArea::scrollPositionChanged");
155
156 IntPoint oldPosition = scrollPosition();
157 // Tell the derived class to scroll its contents.
158 setScrollOffset(position);
159
160 if (Scrollbar* scrollbar = this->horizontalScrollbar())
161 scrollbar->offsetDidChange();
162
163 if (Scrollbar* scrollbar = this->verticalScrollbar())
164 scrollbar->offsetDidChange();
165
166 if (scrollPosition() != oldPosition)
167 scrollAnimator()->notifyContentAreaScrolled(scrollPosition() - oldPositi on);
168 }
169
170 bool ScrollableArea::scrollBehaviorFromString(const String& behaviorString, Scro llBehavior& behavior)
171 {
172 if (behaviorString == "auto")
173 behavior = ScrollBehaviorAuto;
174 else if (behaviorString == "instant")
175 behavior = ScrollBehaviorInstant;
176 else if (behaviorString == "smooth")
177 behavior = ScrollBehaviorSmooth;
178 else
179 return false;
180
181 return true;
182 }
183
184 void ScrollableArea::setScrollOffsetFromAnimation(const IntPoint& offset)
185 {
186 scrollPositionChanged(offset);
187 }
188
189 void ScrollableArea::contentAreaDidShow() const
190 {
191 if (ScrollAnimator* scrollAnimator = existingScrollAnimator())
192 scrollAnimator->contentAreaDidShow();
193 }
194
195 void ScrollableArea::contentAreaDidHide() const
196 {
197 if (ScrollAnimator* scrollAnimator = existingScrollAnimator())
198 scrollAnimator->contentAreaDidHide();
199 }
200
201 void ScrollableArea::finishCurrentScrollAnimations() const
202 {
203 if (ScrollAnimator* scrollAnimator = existingScrollAnimator())
204 scrollAnimator->finishCurrentScrollAnimations();
205 }
206
207 void ScrollableArea::didAddScrollbar(Scrollbar* scrollbar, ScrollbarOrientation orientation)
208 {
209 if (orientation == VerticalScrollbar)
210 scrollAnimator()->didAddVerticalScrollbar(scrollbar);
211 else
212 scrollAnimator()->didAddHorizontalScrollbar(scrollbar);
213 }
214
215 void ScrollableArea::willRemoveScrollbar(Scrollbar* scrollbar, ScrollbarOrientat ion orientation)
216 {
217 if (orientation == VerticalScrollbar)
218 scrollAnimator()->willRemoveVerticalScrollbar(scrollbar);
219 else
220 scrollAnimator()->willRemoveHorizontalScrollbar(scrollbar);
221 }
222
223 void ScrollableArea::contentsResized()
224 {
225 if (ScrollAnimator* scrollAnimator = existingScrollAnimator())
226 scrollAnimator->contentsResized();
227 }
228
229 bool ScrollableArea::hasOverlayScrollbars() const
230 {
231 Scrollbar* vScrollbar = verticalScrollbar();
232 if (vScrollbar && vScrollbar->isOverlayScrollbar())
233 return true;
234 Scrollbar* hScrollbar = horizontalScrollbar();
235 return hScrollbar && hScrollbar->isOverlayScrollbar();
236 }
237
238 IntPoint ScrollableArea::clampScrollPosition(const IntPoint& scrollPosition) con st
239 {
240 return scrollPosition.shrunkTo(maximumScrollPosition()).expandedTo(minimumSc rollPosition());
241 }
242
243 int ScrollableArea::lineStep(ScrollbarOrientation) const
244 {
245 return pixelsPerLineStep();
246 }
247
248 int ScrollableArea::documentStep(ScrollbarOrientation orientation) const
249 {
250 return scrollSize(orientation);
251 }
252
253 float ScrollableArea::pixelStep(ScrollbarOrientation) const
254 {
255 return 1;
256 }
257
258 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/platform/scroll/ScrollableArea.h ('k') | sky/engine/platform/scroll/Scrollbar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698