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

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

Issue 610423004: Preserve fractional scroll offset for JS scrolling API (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 if (horizontalLock) 117 if (horizontalLock)
118 setHorizontalScrollbarLock(); 118 setHorizontalScrollbarLock();
119 119
120 if (verticalLock) 120 if (verticalLock)
121 setVerticalScrollbarLock(); 121 setVerticalScrollbarLock();
122 122
123 if (!needsUpdate) 123 if (!needsUpdate)
124 return; 124 return;
125 125
126 updateScrollbars(scrollOffset()); 126 updateScrollbars(scrollOffsetDouble());
127 127
128 if (!layerForScrolling()) 128 if (!layerForScrolling())
129 return; 129 return;
130 blink::WebLayer* layer = layerForScrolling()->platformLayer(); 130 blink::WebLayer* layer = layerForScrolling()->platformLayer();
131 if (!layer) 131 if (!layer)
132 return; 132 return;
133 layer->setUserScrollable(userInputScrollable(HorizontalScrollbar), userInput Scrollable(VerticalScrollbar)); 133 layer->setUserScrollable(userInputScrollable(HorizontalScrollbar), userInput Scrollable(VerticalScrollbar));
134 } 134 }
135 135
136 void ScrollView::scrollbarModes(ScrollbarMode& horizontalMode, ScrollbarMode& ve rticalMode) const 136 void ScrollView::scrollbarModes(ScrollbarMode& horizontalMode, ScrollbarMode& ve rticalMode) const
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 IntSize ScrollView::contentsSize() const 194 IntSize ScrollView::contentsSize() const
195 { 195 {
196 return m_contentsSize; 196 return m_contentsSize;
197 } 197 }
198 198
199 void ScrollView::setContentsSize(const IntSize& newSize) 199 void ScrollView::setContentsSize(const IntSize& newSize)
200 { 200 {
201 if (contentsSize() == newSize) 201 if (contentsSize() == newSize)
202 return; 202 return;
203 m_contentsSize = newSize; 203 m_contentsSize = newSize;
204 updateScrollbars(scrollOffset()); 204 updateScrollbars(scrollOffsetDouble());
205 updateOverhangAreas(); 205 updateOverhangAreas();
206 } 206 }
207 207
208 IntPoint ScrollView::maximumScrollPosition() const 208 IntPoint ScrollView::maximumScrollPosition() const
209 { 209 {
210 IntPoint maximumOffset(contentsWidth() - visibleWidth() - scrollOrigin().x() , contentsHeight() - visibleHeight() - scrollOrigin().y()); 210 IntPoint maximumOffset(contentsWidth() - visibleWidth() - scrollOrigin().x() , contentsHeight() - visibleHeight() - scrollOrigin().y());
211 maximumOffset.clampNegativeToZero(); 211 maximumOffset.clampNegativeToZero();
212 return maximumOffset; 212 return maximumOffset;
213 } 213 }
214 214
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 if (scrollbarsSuppressed()) 288 if (scrollbarsSuppressed())
289 return; 289 return;
290 290
291 // FIXME: Change scrollContents() to take DoubleSize. crbug.com/414283. 291 // FIXME: Change scrollContents() to take DoubleSize. crbug.com/414283.
292 if (isFrameView()) 292 if (isFrameView())
293 m_pendingScrollDelta += scrollDelta; 293 m_pendingScrollDelta += scrollDelta;
294 else 294 else
295 scrollContents(flooredIntSize(scrollDelta)); 295 scrollContents(flooredIntSize(scrollDelta));
296 } 296 }
297 297
298 void ScrollView::setScrollPosition(const IntPoint& scrollPoint, ScrollBehavior s crollBehavior) 298 void ScrollView::setScrollPosition(const DoublePoint& scrollPoint, ScrollBehavio r scrollBehavior)
299 { 299 {
300 IntPoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint); 300 DoublePoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint) ;
301 301
302 if (newScrollPosition == scrollPosition()) 302 if (newScrollPosition == scrollPositionDouble())
303 return; 303 return;
304 304
305 if (scrollBehavior == ScrollBehaviorInstant) 305 if (scrollBehavior == ScrollBehaviorInstant) {
306 updateScrollbars(IntSize(newScrollPosition.x(), newScrollPosition.y())); 306 DoubleSize newOffset(newScrollPosition.x(), newScrollPosition.y());
307 else 307 updateScrollbars(newOffset);
308 programmaticallyScrollSmoothlyToOffset(newScrollPosition); 308 } else {
309 programmaticallyScrollSmoothlyToOffset(toFloatPoint(newScrollPosition));
310 }
309 } 311 }
310 312
311 bool ScrollView::scroll(ScrollDirection direction, ScrollGranularity granularity ) 313 bool ScrollView::scroll(ScrollDirection direction, ScrollGranularity granularity )
312 { 314 {
313 ScrollDirection physicalDirection = 315 ScrollDirection physicalDirection =
314 toPhysicalDirection(direction, isVerticalDocument(), isFlippedDocument() ); 316 toPhysicalDirection(direction, isVerticalDocument(), isFlippedDocument() );
315 317
316 return ScrollableArea::scroll(physicalDirection, granularity); 318 return ScrollableArea::scroll(physicalDirection, granularity);
317 } 319 }
318 320
(...skipping 13 matching lines...) Expand all
332 if (currentScrollPosition.y() < minScrollPosition.y()) 334 if (currentScrollPosition.y() < minScrollPosition.y())
333 stretch.setHeight(currentScrollPosition.y() - minScrollPosition.y()); 335 stretch.setHeight(currentScrollPosition.y() - minScrollPosition.y());
334 if (currentScrollPosition.y() > maxScrollPosition.y()) 336 if (currentScrollPosition.y() > maxScrollPosition.y())
335 stretch.setHeight(currentScrollPosition.y() - maxScrollPosition.y()); 337 stretch.setHeight(currentScrollPosition.y() - maxScrollPosition.y());
336 338
337 return stretch; 339 return stretch;
338 } 340 }
339 341
340 void ScrollView::windowResizerRectChanged() 342 void ScrollView::windowResizerRectChanged()
341 { 343 {
342 updateScrollbars(scrollOffset()); 344 updateScrollbars(scrollOffsetDouble());
343 } 345 }
344 346
345 static bool useOverlayScrollbars() 347 static bool useOverlayScrollbars()
346 { 348 {
347 // FIXME: Need to detect the presence of CSS custom scrollbars, which are no n-overlay regardless the ScrollbarTheme. 349 // FIXME: Need to detect the presence of CSS custom scrollbars, which are no n-overlay regardless the ScrollbarTheme.
348 return ScrollbarTheme::theme()->usesOverlayScrollbars(); 350 return ScrollbarTheme::theme()->usesOverlayScrollbars();
349 } 351 }
350 352
351 void ScrollView::computeScrollbarExistence(bool& newHasHorizontalScrollbar, bool & newHasVerticalScrollbar, const IntSize& docSize, ComputeScrollbarExistenceOpti on option) const 353 void ScrollView::computeScrollbarExistence(bool& newHasHorizontalScrollbar, bool & newHasVerticalScrollbar, const IntSize& docSize, ComputeScrollbarExistenceOpti on option) const
352 { 354 {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 465
464 if (m_scrollbarsSuppressed) 466 if (m_scrollbarsSuppressed)
465 return true; 467 return true;
466 468
467 if (!useOverlayScrollbars()) 469 if (!useOverlayScrollbars())
468 contentsResized(); 470 contentsResized();
469 scrollbarExistenceDidChange(); 471 scrollbarExistenceDidChange();
470 return true; 472 return true;
471 } 473 }
472 474
473 void ScrollView::updateScrollbars(const IntSize& desiredOffset) 475 void ScrollView::updateScrollbars(const DoubleSize& desiredOffset)
474 { 476 {
475 if (scrollbarsDisabled()) { 477 if (scrollbarsDisabled()) {
476 setScrollOffsetFromUpdateScrollbars(desiredOffset); 478 setScrollOffsetFromUpdateScrollbars(desiredOffset);
477 return; 479 return;
478 } 480 }
479 481
480 if (m_inUpdateScrollbars) 482 if (m_inUpdateScrollbars)
481 return; 483 return;
482 InUpdateScrollbarsScope inUpdateScrollbarsScope(this); 484 InUpdateScrollbarsScope inUpdateScrollbarsScope(this);
483 485
(...skipping 23 matching lines...) Expand all
507 invalidateRect(IntRect(0, 0, newVisibleSize.width() - oldVisibleSize .width(), newVisibleSize.height())); 509 invalidateRect(IntRect(0, 0, newVisibleSize.width() - oldVisibleSize .width(), newVisibleSize.height()));
508 else 510 else
509 invalidateRect(IntRect(oldVisibleSize.width(), 0, newVisibleSize.wid th() - oldVisibleSize.width(), newVisibleSize.height())); 511 invalidateRect(IntRect(oldVisibleSize.width(), 0, newVisibleSize.wid th() - oldVisibleSize.width(), newVisibleSize.height()));
510 } 512 }
511 if (newVisibleSize.height() > oldVisibleSize.height()) 513 if (newVisibleSize.height() > oldVisibleSize.height())
512 invalidateRect(IntRect(0, oldVisibleSize.height(), newVisibleSize.width( ), newVisibleSize.height() - oldVisibleSize.height())); 514 invalidateRect(IntRect(0, oldVisibleSize.height(), newVisibleSize.width( ), newVisibleSize.height() - oldVisibleSize.height()));
513 515
514 setScrollOffsetFromUpdateScrollbars(desiredOffset); 516 setScrollOffsetFromUpdateScrollbars(desiredOffset);
515 } 517 }
516 518
517 void ScrollView::setScrollOffsetFromUpdateScrollbars(const IntSize& offset) 519 void ScrollView::setScrollOffsetFromUpdateScrollbars(const DoubleSize& offset)
518 { 520 {
519 IntPoint adjustedScrollPosition = IntPoint(offset); 521 DoublePoint adjustedScrollPosition = DoublePoint(offset);
520 522
521 if (!isRubberBandInProgress()) 523 if (!isRubberBandInProgress())
522 adjustedScrollPosition = adjustScrollPositionWithinRange(adjustedScrollP osition); 524 adjustedScrollPosition = adjustScrollPositionWithinRange(adjustedScrollP osition);
523 525
524 if (adjustedScrollPosition != scrollPosition() || scrollOriginChanged()) { 526 if (adjustedScrollPosition != scrollPositionDouble() || scrollOriginChanged( )) {
525 ScrollableArea::scrollToOffsetWithoutAnimation(adjustedScrollPosition); 527 ScrollableArea::scrollToOffsetWithoutAnimation(toFloatPoint(adjustedScro llPosition));
526 resetScrollOriginChanged(); 528 resetScrollOriginChanged();
527 } 529 }
528 } 530 }
529 531
530 const int panIconSizeLength = 16; 532 const int panIconSizeLength = 16;
531 533
532 IntRect ScrollView::rectToCopyOnScroll() const 534 IntRect ScrollView::rectToCopyOnScroll() const
533 { 535 {
534 IntRect scrollViewRect = convertToContainingWindow(IntRect((shouldPlaceVerti calScrollbarOnLeft() && verticalScrollbar()) ? verticalScrollbar()->width() : 0, 0, visibleWidth(), visibleHeight())); 536 IntRect scrollViewRect = convertToContainingWindow(IntRect((shouldPlaceVerti calScrollbarOnLeft() && verticalScrollbar()) ? verticalScrollbar()->width() : 0, 0, visibleWidth(), visibleHeight()));
535 if (hasOverlayScrollbars()) { 537 if (hasOverlayScrollbars()) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 725
724 void ScrollView::setFrameRect(const IntRect& newRect) 726 void ScrollView::setFrameRect(const IntRect& newRect)
725 { 727 {
726 IntRect oldRect = frameRect(); 728 IntRect oldRect = frameRect();
727 729
728 if (newRect == oldRect) 730 if (newRect == oldRect)
729 return; 731 return;
730 732
731 Widget::setFrameRect(newRect); 733 Widget::setFrameRect(newRect);
732 734
733 updateScrollbars(scrollOffset()); 735 updateScrollbars(scrollOffsetDouble());
734 736
735 frameRectsChanged(); 737 frameRectsChanged();
736 } 738 }
737 739
738 void ScrollView::frameRectsChanged() 740 void ScrollView::frameRectsChanged()
739 { 741 {
740 HashSet<RefPtr<Widget> >::const_iterator end = m_children.end(); 742 HashSet<RefPtr<Widget> >::const_iterator end = m_children.end();
741 for (HashSet<RefPtr<Widget> >::const_iterator current = m_children.begin(); current != end; ++current) 743 for (HashSet<RefPtr<Widget> >::const_iterator current = m_children.begin(); current != end; ++current)
742 (*current)->frameRectsChanged(); 744 (*current)->frameRectsChanged();
743 } 745 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 835
834 bool ScrollView::isScrollCornerVisible() const 836 bool ScrollView::isScrollCornerVisible() const
835 { 837 {
836 return !scrollCornerRect().isEmpty(); 838 return !scrollCornerRect().isEmpty();
837 } 839 }
838 840
839 void ScrollView::scrollbarStyleChanged() 841 void ScrollView::scrollbarStyleChanged()
840 { 842 {
841 adjustScrollbarOpacity(); 843 adjustScrollbarOpacity();
842 contentsResized(); 844 contentsResized();
843 updateScrollbars(scrollOffset()); 845 updateScrollbars(scrollOffsetDouble());
844 positionScrollbarLayers(); 846 positionScrollbarLayers();
845 } 847 }
846 848
847 void ScrollView::updateScrollCorner() 849 void ScrollView::updateScrollCorner()
848 { 850 {
849 } 851 }
850 852
851 void ScrollView::paintScrollCorner(GraphicsContext* context, const IntRect& corn erRect) 853 void ScrollView::paintScrollCorner(GraphicsContext* context, const IntRect& corn erRect)
852 { 854 {
853 ScrollbarTheme::theme()->paintScrollCorner(context, cornerRect); 855 ScrollbarTheme::theme()->paintScrollCorner(context, cornerRect);
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 1131
1130 void ScrollView::setScrollOrigin(const IntPoint& origin, bool updatePositionAtAl l, bool updatePositionSynchronously) 1132 void ScrollView::setScrollOrigin(const IntPoint& origin, bool updatePositionAtAl l, bool updatePositionSynchronously)
1131 { 1133 {
1132 if (scrollOrigin() == origin) 1134 if (scrollOrigin() == origin)
1133 return; 1135 return;
1134 1136
1135 ScrollableArea::setScrollOrigin(origin); 1137 ScrollableArea::setScrollOrigin(origin);
1136 1138
1137 // Update if the scroll origin changes, since our position will be different if the content size did not change. 1139 // Update if the scroll origin changes, since our position will be different if the content size did not change.
1138 if (updatePositionAtAll && updatePositionSynchronously) 1140 if (updatePositionAtAll && updatePositionSynchronously)
1139 updateScrollbars(scrollOffset()); 1141 updateScrollbars(scrollOffsetDouble());
1140 } 1142 }
1141 1143
1142 } // namespace blink 1144 } // namespace blink
OLDNEW
« Source/platform/geometry/DoubleSize.h ('K') | « Source/platform/scroll/ScrollView.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698