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

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

Issue 1173053003: Remove ScrollableArea::notifyScrollPositionChanged and cleanup scroll animators. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase + remove updateScrollbars from FrameView::setScrollPosition Created 5 years, 6 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/platform/scroll/ScrollableArea.h ('k') | Source/platform/scroll/ScrollableAreaTest.cpp » ('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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 157
158 return scrollAnimator()->userScroll(orientation, granularity, step, delta); 158 return scrollAnimator()->userScroll(orientation, granularity, step, delta);
159 } 159 }
160 160
161 void ScrollableArea::setScrollPosition(const DoublePoint& position, ScrollType s crollType, ScrollBehavior behavior) 161 void ScrollableArea::setScrollPosition(const DoublePoint& position, ScrollType s crollType, ScrollBehavior behavior)
162 { 162 {
163 if (behavior == ScrollBehaviorAuto) 163 if (behavior == ScrollBehaviorAuto)
164 behavior = scrollBehaviorStyle(); 164 behavior = scrollBehaviorStyle();
165 165
166 if (scrollType == CompositorScroll) 166 if (scrollType == CompositorScroll)
167 scrollAnimator()->scrollToOffsetWithoutAnimation(toFloatPoint(position), CompositorScroll); 167 scrollPositionChanged(adjustScrollPositionWithinRange(position), Composi torScroll);
168 else if (scrollType == ProgrammaticScroll) 168 else if (scrollType == ProgrammaticScroll)
169 programmaticScrollHelper(position, behavior); 169 programmaticScrollHelper(position, behavior);
170 else if (scrollType == UserScroll) 170 else if (scrollType == UserScroll)
171 userScrollHelper(position, behavior); 171 userScrollHelper(position, behavior);
172 else 172 else
173 ASSERT_NOT_REACHED(); 173 ASSERT_NOT_REACHED();
174 } 174 }
175 175
176 void ScrollableArea::scrollBy(const DoubleSize& delta, ScrollType type, ScrollBe havior behavior) 176 void ScrollableArea::scrollBy(const DoubleSize& delta, ScrollType type, ScrollBe havior behavior)
177 { 177 {
178 setScrollPosition(scrollPositionDouble() + delta, type, behavior); 178 setScrollPosition(scrollPositionDouble() + delta, type, behavior);
179 } 179 }
180 180
181 void ScrollableArea::setScrollPositionSingleAxis(ScrollbarOrientation orientatio n, double position, ScrollType scrollType, ScrollBehavior behavior) 181 void ScrollableArea::setScrollPositionSingleAxis(ScrollbarOrientation orientatio n, double position, ScrollType scrollType, ScrollBehavior behavior)
182 { 182 {
183 DoublePoint newPosition; 183 DoublePoint newPosition;
184 if (orientation == HorizontalScrollbar) 184 if (orientation == HorizontalScrollbar)
185 newPosition = DoublePoint(position, scrollAnimator()->currentPosition(). y()); 185 newPosition = DoublePoint(position, scrollAnimator()->currentPosition(). y());
186 else 186 else
187 newPosition = DoublePoint(scrollAnimator()->currentPosition().x(), posit ion); 187 newPosition = DoublePoint(scrollAnimator()->currentPosition().x(), posit ion);
188 188
189 // TODO(bokan): Note, this doesn't use the derived class versions since this method is currently used 189 // TODO(bokan): Note, this doesn't use the derived class versions since this method is currently used
190 // exclusively by code that adjusts the position by the scroll origin and th e derived class versions 190 // exclusively by code that adjusts the position by the scroll origin and th e derived class versions
191 // differ on whether they take that into account or not. 191 // differ on whether they take that into account or not.
192 ScrollableArea::setScrollPosition(newPosition, scrollType, behavior); 192 ScrollableArea::setScrollPosition(newPosition, scrollType, behavior);
193 } 193 }
194 194
195 void ScrollableArea::programmaticScrollHelper(const DoublePoint& position, Scrol lBehavior scrollBehavior) 195 void ScrollableArea::programmaticScrollHelper(const DoublePoint& position, Scrol lBehavior scrollBehavior)
196 { 196 {
197 if (scrollBehavior == ScrollBehaviorSmooth) { 197 cancelScrollAnimation();
198 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) 198
199 scrollAnimator->cancelAnimations(); 199 if (scrollBehavior == ScrollBehaviorSmooth)
200 programmaticScrollAnimator()->animateToOffset(toFloatPoint(position)); 200 programmaticScrollAnimator()->animateToOffset(toFloatPoint(position));
201 } else { 201 else
202 // TODO(bokan): This should probably use programmaticScrollAnimator. 202 programmaticScrollAnimator()->scrollToOffsetWithoutAnimation(toFloatPoin t(position));
203 cancelProgrammaticScrollAnimation();
204 scrollAnimator()->scrollToOffsetWithoutAnimation(toFloatPoint(position), ProgrammaticScroll);
205 }
206 } 203 }
207 204
208 void ScrollableArea::userScrollHelper(const DoublePoint& position, ScrollBehavio r scrollBehavior) 205 void ScrollableArea::userScrollHelper(const DoublePoint& position, ScrollBehavio r scrollBehavior)
209 { 206 {
210 if (scrollBehavior == ScrollBehaviorSmooth) { 207 cancelProgrammaticScrollAnimation();
211 // TODO(bokan) 208
212 } else { 209 // Smooth user scrolls (keyboard, wheel clicks) are handled via the userScro ll method.
213 cancelProgrammaticScrollAnimation(); 210 // TODO(bokan): The userScroll method should probably be modified to call th is method
214 scrollAnimator()->scrollToOffsetWithoutAnimation(toFloatPoint(position), UserScroll); 211 // and ScrollAnimator to have a simpler animateToOffset method like the
215 } 212 // ProgrammaticScrollAnimator.
213 ASSERT(scrollBehavior == ScrollBehaviorInstant);
214 scrollAnimator()->scrollToOffsetWithoutAnimation(toFloatPoint(position));
216 } 215 }
217 216
218 void ScrollableArea::scrollIntoRect(const LayoutRect& rectInContent, const Float Rect& targetRectInFrame) 217 void ScrollableArea::scrollIntoRect(const LayoutRect& rectInContent, const Float Rect& targetRectInFrame)
219 { 218 {
220 // Use |pixelSnappedIntRect| for rounding to pixel as opposed to |enclosingI ntRect|. It gives a better 219 // Use |pixelSnappedIntRect| for rounding to pixel as opposed to |enclosingI ntRect|. It gives a better
221 // combined (location and size) rounding error resulting in a more accurate scroll offset. 220 // combined (location and size) rounding error resulting in a more accurate scroll offset.
222 // FIXME: It would probably be best to do the whole calculation in LayoutUni ts but contentsToRootFrame 221 // FIXME: It would probably be best to do the whole calculation in LayoutUni ts but contentsToRootFrame
223 // and friends don't have LayoutRect/Point versions yet. 222 // and friends don't have LayoutRect/Point versions yet.
224 IntRect boundsInContent = pixelSnappedIntRect(rectInContent); 223 IntRect boundsInContent = pixelSnappedIntRect(rectInContent);
225 IntRect boundsInFrame(boundsInContent.location() - toIntSize(scrollPosition( )), boundsInContent.size()); 224 IntRect boundsInFrame(boundsInContent.location() - toIntSize(scrollPosition( )), boundsInContent.size());
(...skipping 10 matching lines...) Expand all
236 setScrollPosition(targetOffset, ProgrammaticScroll); 235 setScrollPosition(targetOffset, ProgrammaticScroll);
237 } 236 }
238 237
239 LayoutRect ScrollableArea::scrollIntoView(const LayoutRect& rectInContent, const ScrollAlignment& alignX, const ScrollAlignment& alignY) 238 LayoutRect ScrollableArea::scrollIntoView(const LayoutRect& rectInContent, const ScrollAlignment& alignX, const ScrollAlignment& alignY)
240 { 239 {
241 // TODO(bokan): This should really be implemented here but ScrollAlignment i s in Core which is a dependency violation. 240 // TODO(bokan): This should really be implemented here but ScrollAlignment i s in Core which is a dependency violation.
242 ASSERT_NOT_REACHED(); 241 ASSERT_NOT_REACHED();
243 return LayoutRect(); 242 return LayoutRect();
244 } 243 }
245 244
246 void ScrollableArea::notifyScrollPositionChanged(const DoublePoint& position)
247 {
248 // TODO(bokan): This should probably be something other than CompositorScrol l.
249 scrollPositionChanged(position, CompositorScroll);
250 scrollAnimator()->setCurrentPosition(toFloatPoint(scrollPositionDouble()));
251 }
252
253 void ScrollableArea::scrollPositionChanged(const DoublePoint& position, ScrollTy pe scrollType) 245 void ScrollableArea::scrollPositionChanged(const DoublePoint& position, ScrollTy pe scrollType)
254 { 246 {
255 TRACE_EVENT0("blink", "ScrollableArea::scrollPositionChanged"); 247 TRACE_EVENT0("blink", "ScrollableArea::scrollPositionChanged");
256 248
257 DoublePoint oldPosition = scrollPositionDouble(); 249 DoublePoint oldPosition = scrollPositionDouble();
250 DoublePoint truncatedPosition = shouldUseIntegerScrollOffset() ? flooredIntP oint(position) : position;
251
258 // Tell the derived class to scroll its contents. 252 // Tell the derived class to scroll its contents.
259 setScrollOffset(position, scrollType); 253 setScrollOffset(truncatedPosition, scrollType);
260 254
261 Scrollbar* verticalScrollbar = this->verticalScrollbar(); 255 Scrollbar* verticalScrollbar = this->verticalScrollbar();
262 256
263 // Tell the scrollbars to update their thumb postions. 257 // Tell the scrollbars to update their thumb postions.
264 if (Scrollbar* horizontalScrollbar = this->horizontalScrollbar()) { 258 if (Scrollbar* horizontalScrollbar = this->horizontalScrollbar()) {
265 horizontalScrollbar->offsetDidChange(); 259 horizontalScrollbar->offsetDidChange();
266 if (horizontalScrollbar->isOverlayScrollbar() && !hasLayerForHorizontalS crollbar()) { 260 if (horizontalScrollbar->isOverlayScrollbar() && !hasLayerForHorizontalS crollbar()) {
267 if (!verticalScrollbar) 261 if (!verticalScrollbar)
268 horizontalScrollbar->invalidate(); 262 horizontalScrollbar->invalidate();
269 else { 263 else {
270 // If there is both a horizontalScrollbar and a verticalScrollba r, 264 // If there is both a horizontalScrollbar and a verticalScrollba r,
271 // then we must also invalidate the corner between them. 265 // then we must also invalidate the corner between them.
272 IntRect boundsAndCorner = horizontalScrollbar->boundsRect(); 266 IntRect boundsAndCorner = horizontalScrollbar->boundsRect();
273 boundsAndCorner.setWidth(boundsAndCorner.width() + verticalScrol lbar->width()); 267 boundsAndCorner.setWidth(boundsAndCorner.width() + verticalScrol lbar->width());
274 horizontalScrollbar->invalidateRect(boundsAndCorner); 268 horizontalScrollbar->invalidateRect(boundsAndCorner);
275 } 269 }
276 } 270 }
277 } 271 }
278 if (verticalScrollbar) { 272 if (verticalScrollbar) {
279 verticalScrollbar->offsetDidChange(); 273 verticalScrollbar->offsetDidChange();
280 if (verticalScrollbar->isOverlayScrollbar() && !hasLayerForVerticalScrol lbar()) 274 if (verticalScrollbar->isOverlayScrollbar() && !hasLayerForVerticalScrol lbar())
281 verticalScrollbar->invalidate(); 275 verticalScrollbar->invalidate();
282 } 276 }
283 277
284 if (scrollPositionDouble() != oldPosition) { 278 if (scrollPositionDouble() != oldPosition) {
285 // FIXME: Pass in DoubleSize. crbug.com/414283. 279 // FIXME: Pass in DoubleSize. crbug.com/414283.
286 scrollAnimator()->notifyContentAreaScrolled(toFloatSize(scrollPositionDo uble() - oldPosition)); 280 scrollAnimator()->notifyContentAreaScrolled(toFloatSize(scrollPositionDo uble() - oldPosition));
287 } 281 }
282
283 scrollAnimator()->setCurrentPosition(toFloatPoint(position));
288 } 284 }
289 285
290 bool ScrollableArea::scrollBehaviorFromString(const String& behaviorString, Scro llBehavior& behavior) 286 bool ScrollableArea::scrollBehaviorFromString(const String& behaviorString, Scro llBehavior& behavior)
291 { 287 {
292 if (behaviorString == "auto") 288 if (behaviorString == "auto")
293 behavior = ScrollBehaviorAuto; 289 behavior = ScrollBehaviorAuto;
294 else if (behaviorString == "instant") 290 else if (behaviorString == "instant")
295 behavior = ScrollBehaviorInstant; 291 behavior = ScrollBehaviorInstant;
296 else if (behaviorString == "smooth") 292 else if (behaviorString == "smooth")
297 behavior = ScrollBehaviorSmooth; 293 behavior = ScrollBehaviorSmooth;
(...skipping 28 matching lines...) Expand all
326 if (!constrainsScrollingToContentEdge()) 322 if (!constrainsScrollingToContentEdge())
327 return scrollPoint; 323 return scrollPoint;
328 DoublePoint newScrollPosition = scrollPoint.shrunkTo(maximumScrollPositionDo uble()); 324 DoublePoint newScrollPosition = scrollPoint.shrunkTo(maximumScrollPositionDo uble());
329 newScrollPosition = newScrollPosition.expandedTo(minimumScrollPositionDouble ()); 325 newScrollPosition = newScrollPosition.expandedTo(minimumScrollPositionDouble ());
330 return newScrollPosition; 326 return newScrollPosition;
331 } 327 }
332 328
333 // NOTE: Only called from Internals for testing. 329 // NOTE: Only called from Internals for testing.
334 void ScrollableArea::setScrollOffsetFromInternals(const IntPoint& offset) 330 void ScrollableArea::setScrollOffsetFromInternals(const IntPoint& offset)
335 { 331 {
336 setScrollOffsetFromAnimation(DoublePoint(offset), ProgrammaticScroll); 332 scrollPositionChanged(DoublePoint(offset), ProgrammaticScroll);
337 }
338
339 void ScrollableArea::setScrollOffsetFromAnimation(const DoublePoint& offset, Scr ollType scrollType)
340 {
341 scrollPositionChanged(offset, scrollType);
342 } 333 }
343 334
344 void ScrollableArea::willStartLiveResize() 335 void ScrollableArea::willStartLiveResize()
345 { 336 {
346 if (m_inLiveResize) 337 if (m_inLiveResize)
347 return; 338 return;
348 m_inLiveResize = true; 339 m_inLiveResize = true;
349 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) 340 if (ScrollAnimator* scrollAnimator = existingScrollAnimator())
350 scrollAnimator->willStartLiveResize(); 341 scrollAnimator->willStartLiveResize();
351 } 342 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 if (ProgrammaticScrollAnimator* programmaticScrollAnimator = existingProgram maticScrollAnimator()) 536 if (ProgrammaticScrollAnimator* programmaticScrollAnimator = existingProgram maticScrollAnimator())
546 programmaticScrollAnimator->updateCompositorAnimations(); 537 programmaticScrollAnimator->updateCompositorAnimations();
547 } 538 }
548 539
549 void ScrollableArea::notifyCompositorAnimationFinished(int groupId) 540 void ScrollableArea::notifyCompositorAnimationFinished(int groupId)
550 { 541 {
551 if (ProgrammaticScrollAnimator* programmaticScrollAnimator = existingProgram maticScrollAnimator()) 542 if (ProgrammaticScrollAnimator* programmaticScrollAnimator = existingProgram maticScrollAnimator())
552 programmaticScrollAnimator->notifyCompositorAnimationFinished(groupId); 543 programmaticScrollAnimator->notifyCompositorAnimationFinished(groupId);
553 } 544 }
554 545
546 void ScrollableArea::cancelScrollAnimation()
547 {
548 if (ScrollAnimator* scrollAnimator = existingScrollAnimator())
549 scrollAnimator->cancelAnimations();
550 }
551
555 void ScrollableArea::cancelProgrammaticScrollAnimation() 552 void ScrollableArea::cancelProgrammaticScrollAnimation()
556 { 553 {
557 if (ProgrammaticScrollAnimator* programmaticScrollAnimator = existingProgram maticScrollAnimator()) 554 if (ProgrammaticScrollAnimator* programmaticScrollAnimator = existingProgram maticScrollAnimator())
558 programmaticScrollAnimator->cancelAnimation(); 555 programmaticScrollAnimator->cancelAnimation();
559 } 556 }
560 557
561 DoubleRect ScrollableArea::visibleContentRectDouble(IncludeScrollbarsInRect scro llbarInclusion) const 558 DoubleRect ScrollableArea::visibleContentRectDouble(IncludeScrollbarsInRect scro llbarInclusion) const
562 { 559 {
563 return visibleContentRect(scrollbarInclusion); 560 return visibleContentRect(scrollbarInclusion);
564 } 561 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? verticalBa r->width() : 0; 622 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? verticalBa r->width() : 0;
626 if (Scrollbar* horizontalBar = horizontalScrollbar()) 623 if (Scrollbar* horizontalBar = horizontalScrollbar())
627 horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? horiz ontalBar->height() : 0; 624 horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? horiz ontalBar->height() : 0;
628 625
629 return IntSize(std::max(0, size.width() - verticalScrollbarWidth), 626 return IntSize(std::max(0, size.width() - verticalScrollbarWidth),
630 std::max(0, size.height() - horizontalScrollbarHeight)); 627 std::max(0, size.height() - horizontalScrollbarHeight));
631 628
632 } 629 }
633 630
634 } // namespace blink 631 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/scroll/ScrollableArea.h ('k') | Source/platform/scroll/ScrollableAreaTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698