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

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: rebase 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
« no previous file with comments | « Source/platform/scroll/ScrollView.h ('k') | Source/platform/scroll/ScrollableArea.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) 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 124
125 if (horizontalLock) 125 if (horizontalLock)
126 setHorizontalScrollbarLock(); 126 setHorizontalScrollbarLock();
127 127
128 if (verticalLock) 128 if (verticalLock)
129 setVerticalScrollbarLock(); 129 setVerticalScrollbarLock();
130 130
131 if (!needsUpdate) 131 if (!needsUpdate)
132 return; 132 return;
133 133
134 updateScrollbars(scrollOffset()); 134 updateScrollbars(scrollOffsetDouble());
135 135
136 if (!layerForScrolling()) 136 if (!layerForScrolling())
137 return; 137 return;
138 blink::WebLayer* layer = layerForScrolling()->platformLayer(); 138 blink::WebLayer* layer = layerForScrolling()->platformLayer();
139 if (!layer) 139 if (!layer)
140 return; 140 return;
141 layer->setUserScrollable(userInputScrollable(HorizontalScrollbar), userInput Scrollable(VerticalScrollbar)); 141 layer->setUserScrollable(userInputScrollable(HorizontalScrollbar), userInput Scrollable(VerticalScrollbar));
142 } 142 }
143 143
144 void ScrollView::scrollbarModes(ScrollbarMode& horizontalMode, ScrollbarMode& ve rticalMode) const 144 void ScrollView::scrollbarModes(ScrollbarMode& horizontalMode, ScrollbarMode& ve rticalMode) const
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 IntSize ScrollView::contentsSize() const 202 IntSize ScrollView::contentsSize() const
203 { 203 {
204 return m_contentsSize; 204 return m_contentsSize;
205 } 205 }
206 206
207 void ScrollView::setContentsSize(const IntSize& newSize) 207 void ScrollView::setContentsSize(const IntSize& newSize)
208 { 208 {
209 if (contentsSize() == newSize) 209 if (contentsSize() == newSize)
210 return; 210 return;
211 m_contentsSize = newSize; 211 m_contentsSize = newSize;
212 updateScrollbars(scrollOffset()); 212 updateScrollbars(scrollOffsetDouble());
213 updateOverhangAreas(); 213 updateOverhangAreas();
214 } 214 }
215 215
216 IntPoint ScrollView::maximumScrollPosition() const 216 IntPoint ScrollView::maximumScrollPosition() const
217 { 217 {
218 IntPoint maximumOffset(contentsWidth() - visibleWidth() - scrollOrigin().x() , contentsHeight() - visibleHeight() - scrollOrigin().y()); 218 IntPoint maximumOffset(contentsWidth() - visibleWidth() - scrollOrigin().x() , contentsHeight() - visibleHeight() - scrollOrigin().y());
219 maximumOffset.clampNegativeToZero(); 219 maximumOffset.clampNegativeToZero();
220 return maximumOffset; 220 return maximumOffset;
221 } 221 }
222 222
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 if (scrollbarsSuppressed()) 296 if (scrollbarsSuppressed())
297 return; 297 return;
298 298
299 // FIXME: Change scrollContents() to take DoubleSize. crbug.com/414283. 299 // FIXME: Change scrollContents() to take DoubleSize. crbug.com/414283.
300 if (isFrameView()) 300 if (isFrameView())
301 m_pendingScrollDelta += scrollDelta; 301 m_pendingScrollDelta += scrollDelta;
302 else 302 else
303 scrollContents(flooredIntSize(scrollDelta)); 303 scrollContents(flooredIntSize(scrollDelta));
304 } 304 }
305 305
306 void ScrollView::setScrollPosition(const IntPoint& scrollPoint, ScrollBehavior s crollBehavior) 306 void ScrollView::setScrollPosition(const DoublePoint& scrollPoint, ScrollBehavio r scrollBehavior)
307 { 307 {
308 IntPoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint); 308 DoublePoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint) ;
309 309
310 if (newScrollPosition == scrollPosition()) 310 if (newScrollPosition == scrollPositionDouble())
311 return; 311 return;
312 312
313 if (scrollBehavior == ScrollBehaviorInstant) 313 if (scrollBehavior == ScrollBehaviorInstant) {
314 updateScrollbars(IntSize(newScrollPosition.x(), newScrollPosition.y())); 314 DoubleSize newOffset(newScrollPosition.x(), newScrollPosition.y());
315 else 315 updateScrollbars(newOffset);
316 programmaticallyScrollSmoothlyToOffset(newScrollPosition); 316 } else {
317 programmaticallyScrollSmoothlyToOffset(toFloatPoint(newScrollPosition));
318 }
317 } 319 }
318 320
319 bool ScrollView::scroll(ScrollDirection direction, ScrollGranularity granularity ) 321 bool ScrollView::scroll(ScrollDirection direction, ScrollGranularity granularity )
320 { 322 {
321 ScrollDirection physicalDirection = 323 ScrollDirection physicalDirection =
322 toPhysicalDirection(direction, isVerticalDocument(), isFlippedDocument() ); 324 toPhysicalDirection(direction, isVerticalDocument(), isFlippedDocument() );
323 325
324 return ScrollableArea::scroll(physicalDirection, granularity); 326 return ScrollableArea::scroll(physicalDirection, granularity);
325 } 327 }
326 328
(...skipping 13 matching lines...) Expand all
340 if (currentScrollPosition.y() < minScrollPosition.y()) 342 if (currentScrollPosition.y() < minScrollPosition.y())
341 stretch.setHeight(currentScrollPosition.y() - minScrollPosition.y()); 343 stretch.setHeight(currentScrollPosition.y() - minScrollPosition.y());
342 if (currentScrollPosition.y() > maxScrollPosition.y()) 344 if (currentScrollPosition.y() > maxScrollPosition.y())
343 stretch.setHeight(currentScrollPosition.y() - maxScrollPosition.y()); 345 stretch.setHeight(currentScrollPosition.y() - maxScrollPosition.y());
344 346
345 return stretch; 347 return stretch;
346 } 348 }
347 349
348 void ScrollView::windowResizerRectChanged() 350 void ScrollView::windowResizerRectChanged()
349 { 351 {
350 updateScrollbars(scrollOffset()); 352 updateScrollbars(scrollOffsetDouble());
351 } 353 }
352 354
353 static bool useOverlayScrollbars() 355 static bool useOverlayScrollbars()
354 { 356 {
355 // FIXME: Need to detect the presence of CSS custom scrollbars, which are no n-overlay regardless the ScrollbarTheme. 357 // FIXME: Need to detect the presence of CSS custom scrollbars, which are no n-overlay regardless the ScrollbarTheme.
356 return ScrollbarTheme::theme()->usesOverlayScrollbars(); 358 return ScrollbarTheme::theme()->usesOverlayScrollbars();
357 } 359 }
358 360
359 void ScrollView::computeScrollbarExistence(bool& newHasHorizontalScrollbar, bool & newHasVerticalScrollbar, const IntSize& docSize, ComputeScrollbarExistenceOpti on option) const 361 void ScrollView::computeScrollbarExistence(bool& newHasHorizontalScrollbar, bool & newHasVerticalScrollbar, const IntSize& docSize, ComputeScrollbarExistenceOpti on option) const
360 { 362 {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 504
503 if (m_scrollbarsSuppressed) 505 if (m_scrollbarsSuppressed)
504 return true; 506 return true;
505 507
506 if (!useOverlayScrollbars()) 508 if (!useOverlayScrollbars())
507 contentsResized(); 509 contentsResized();
508 scrollbarExistenceDidChange(); 510 scrollbarExistenceDidChange();
509 return true; 511 return true;
510 } 512 }
511 513
512 void ScrollView::updateScrollbars(const IntSize& desiredOffset) 514 void ScrollView::updateScrollbars(const DoubleSize& desiredOffset)
513 { 515 {
514 if (scrollbarsDisabled()) { 516 if (scrollbarsDisabled()) {
515 setScrollOffsetFromUpdateScrollbars(desiredOffset); 517 setScrollOffsetFromUpdateScrollbars(desiredOffset);
516 return; 518 return;
517 } 519 }
518 520
519 if (m_inUpdateScrollbars) 521 if (m_inUpdateScrollbars)
520 return; 522 return;
521 InUpdateScrollbarsScope inUpdateScrollbarsScope(this); 523 InUpdateScrollbarsScope inUpdateScrollbarsScope(this);
522 524
(...skipping 23 matching lines...) Expand all
546 invalidateRect(IntRect(0, 0, newVisibleSize.width() - oldVisibleSize .width(), newVisibleSize.height())); 548 invalidateRect(IntRect(0, 0, newVisibleSize.width() - oldVisibleSize .width(), newVisibleSize.height()));
547 else 549 else
548 invalidateRect(IntRect(oldVisibleSize.width(), 0, newVisibleSize.wid th() - oldVisibleSize.width(), newVisibleSize.height())); 550 invalidateRect(IntRect(oldVisibleSize.width(), 0, newVisibleSize.wid th() - oldVisibleSize.width(), newVisibleSize.height()));
549 } 551 }
550 if (newVisibleSize.height() > oldVisibleSize.height()) 552 if (newVisibleSize.height() > oldVisibleSize.height())
551 invalidateRect(IntRect(0, oldVisibleSize.height(), newVisibleSize.width( ), newVisibleSize.height() - oldVisibleSize.height())); 553 invalidateRect(IntRect(0, oldVisibleSize.height(), newVisibleSize.width( ), newVisibleSize.height() - oldVisibleSize.height()));
552 554
553 setScrollOffsetFromUpdateScrollbars(desiredOffset); 555 setScrollOffsetFromUpdateScrollbars(desiredOffset);
554 } 556 }
555 557
556 void ScrollView::setScrollOffsetFromUpdateScrollbars(const IntSize& offset) 558 void ScrollView::setScrollOffsetFromUpdateScrollbars(const DoubleSize& offset)
557 { 559 {
558 IntPoint adjustedScrollPosition = IntPoint(offset); 560 DoublePoint adjustedScrollPosition = DoublePoint(offset);
559 561
560 if (!isRubberBandInProgress()) 562 if (!isRubberBandInProgress())
561 adjustedScrollPosition = adjustScrollPositionWithinRange(adjustedScrollP osition); 563 adjustedScrollPosition = adjustScrollPositionWithinRange(adjustedScrollP osition);
562 564
563 if (adjustedScrollPosition != scrollPosition() || scrollOriginChanged()) { 565 if (adjustedScrollPosition != scrollPositionDouble() || scrollOriginChanged( )) {
564 ScrollableArea::scrollToOffsetWithoutAnimation(adjustedScrollPosition); 566 ScrollableArea::scrollToOffsetWithoutAnimation(toFloatPoint(adjustedScro llPosition));
565 resetScrollOriginChanged(); 567 resetScrollOriginChanged();
566 } 568 }
567 } 569 }
568 570
569 const int panIconSizeLength = 16; 571 const int panIconSizeLength = 16;
570 572
571 IntRect ScrollView::rectToCopyOnScroll() const 573 IntRect ScrollView::rectToCopyOnScroll() const
572 { 574 {
573 IntRect scrollViewRect = convertToContainingWindow(IntRect((shouldPlaceVerti calScrollbarOnLeft() && verticalScrollbar()) ? verticalScrollbar()->width() : 0, 0, visibleWidth(), visibleHeight())); 575 IntRect scrollViewRect = convertToContainingWindow(IntRect((shouldPlaceVerti calScrollbarOnLeft() && verticalScrollbar()) ? verticalScrollbar()->width() : 0, 0, visibleWidth(), visibleHeight()));
574 if (hasOverlayScrollbars()) { 576 if (hasOverlayScrollbars()) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 764
763 void ScrollView::setFrameRect(const IntRect& newRect) 765 void ScrollView::setFrameRect(const IntRect& newRect)
764 { 766 {
765 IntRect oldRect = frameRect(); 767 IntRect oldRect = frameRect();
766 768
767 if (newRect == oldRect) 769 if (newRect == oldRect)
768 return; 770 return;
769 771
770 Widget::setFrameRect(newRect); 772 Widget::setFrameRect(newRect);
771 773
772 updateScrollbars(scrollOffset()); 774 updateScrollbars(scrollOffsetDouble());
773 775
774 frameRectsChanged(); 776 frameRectsChanged();
775 } 777 }
776 778
777 void ScrollView::frameRectsChanged() 779 void ScrollView::frameRectsChanged()
778 { 780 {
779 HashSet<RefPtr<Widget> >::const_iterator end = m_children.end(); 781 HashSet<RefPtr<Widget> >::const_iterator end = m_children.end();
780 for (HashSet<RefPtr<Widget> >::const_iterator current = m_children.begin(); current != end; ++current) 782 for (HashSet<RefPtr<Widget> >::const_iterator current = m_children.begin(); current != end; ++current)
781 (*current)->frameRectsChanged(); 783 (*current)->frameRectsChanged();
782 } 784 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 874
873 bool ScrollView::isScrollCornerVisible() const 875 bool ScrollView::isScrollCornerVisible() const
874 { 876 {
875 return !scrollCornerRect().isEmpty(); 877 return !scrollCornerRect().isEmpty();
876 } 878 }
877 879
878 void ScrollView::scrollbarStyleChanged() 880 void ScrollView::scrollbarStyleChanged()
879 { 881 {
880 adjustScrollbarOpacity(); 882 adjustScrollbarOpacity();
881 contentsResized(); 883 contentsResized();
882 updateScrollbars(scrollOffset()); 884 updateScrollbars(scrollOffsetDouble());
883 positionScrollbarLayers(); 885 positionScrollbarLayers();
884 } 886 }
885 887
886 void ScrollView::updateScrollCorner() 888 void ScrollView::updateScrollCorner()
887 { 889 {
888 } 890 }
889 891
890 void ScrollView::paintScrollCorner(GraphicsContext* context, const IntRect& corn erRect) 892 void ScrollView::paintScrollCorner(GraphicsContext* context, const IntRect& corn erRect)
891 { 893 {
892 ScrollbarTheme::theme()->paintScrollCorner(context, cornerRect); 894 ScrollbarTheme::theme()->paintScrollCorner(context, cornerRect);
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 1170
1169 void ScrollView::setScrollOrigin(const IntPoint& origin, bool updatePositionAtAl l, bool updatePositionSynchronously) 1171 void ScrollView::setScrollOrigin(const IntPoint& origin, bool updatePositionAtAl l, bool updatePositionSynchronously)
1170 { 1172 {
1171 if (scrollOrigin() == origin) 1173 if (scrollOrigin() == origin)
1172 return; 1174 return;
1173 1175
1174 ScrollableArea::setScrollOrigin(origin); 1176 ScrollableArea::setScrollOrigin(origin);
1175 1177
1176 // Update if the scroll origin changes, since our position will be different if the content size did not change. 1178 // Update if the scroll origin changes, since our position will be different if the content size did not change.
1177 if (updatePositionAtAll && updatePositionSynchronously) 1179 if (updatePositionAtAll && updatePositionSynchronously)
1178 updateScrollbars(scrollOffset()); 1180 updateScrollbars(scrollOffsetDouble());
1179 } 1181 }
1180 1182
1181 } // namespace blink 1183 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/scroll/ScrollView.h ('k') | Source/platform/scroll/ScrollableArea.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698