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

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

Issue 16982005: Allow objects without scrollbars to be scrollable (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: CR Fixes Created 7 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
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 25 matching lines...) Expand all
36 36
37 using namespace std; 37 using namespace std;
38 38
39 namespace WebCore { 39 namespace WebCore {
40 40
41 ScrollView::ScrollView() 41 ScrollView::ScrollView()
42 : m_horizontalScrollbarMode(ScrollbarAuto) 42 : m_horizontalScrollbarMode(ScrollbarAuto)
43 , m_verticalScrollbarMode(ScrollbarAuto) 43 , m_verticalScrollbarMode(ScrollbarAuto)
44 , m_horizontalScrollbarLock(false) 44 , m_horizontalScrollbarLock(false)
45 , m_verticalScrollbarLock(false) 45 , m_verticalScrollbarLock(false)
46 , m_prohibitsScrolling(false)
47 , m_canBlitOnScroll(true) 46 , m_canBlitOnScroll(true)
48 , m_scrollbarsAvoidingResizer(0) 47 , m_scrollbarsAvoidingResizer(0)
49 , m_scrollbarsSuppressed(false) 48 , m_scrollbarsSuppressed(false)
50 , m_inUpdateScrollbars(false) 49 , m_inUpdateScrollbars(false)
51 , m_updateScrollbarsPass(0) 50 , m_updateScrollbarsPass(0)
52 , m_drawPanScrollIcon(false) 51 , m_drawPanScrollIcon(false)
53 , m_useFixedLayout(false) 52 , m_useFixedLayout(false)
54 , m_paintsEntireContents(false) 53 , m_paintsEntireContents(false)
55 , m_clipsRepaints(true) 54 , m_clipsRepaints(true)
56 { 55 {
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 if (!constrainsScrollingToContentEdge()) 276 if (!constrainsScrollingToContentEdge())
278 return scrollPoint; 277 return scrollPoint;
279 278
280 IntPoint newScrollPosition = scrollPoint.shrunkTo(maximumScrollPosition()); 279 IntPoint newScrollPosition = scrollPoint.shrunkTo(maximumScrollPosition());
281 newScrollPosition = newScrollPosition.expandedTo(minimumScrollPosition()); 280 newScrollPosition = newScrollPosition.expandedTo(minimumScrollPosition());
282 return newScrollPosition; 281 return newScrollPosition;
283 } 282 }
284 283
285 int ScrollView::scrollSize(ScrollbarOrientation orientation) const 284 int ScrollView::scrollSize(ScrollbarOrientation orientation) const
286 { 285 {
286 Scrollbar* scrollbar = ((orientation == HorizontalScrollbar) ? m_horizontalS crollbar : m_verticalScrollbar).get();
287
287 // If no scrollbars are present, it does not indicate content is not be scro llable. 288 // If no scrollbars are present, it does not indicate content is not be scro llable.
288 if (!m_horizontalScrollbar && !m_verticalScrollbar && !prohibitsScrolling()) { 289 if (!scrollbar) {
289 IntSize scrollSize = m_contentsSize - visibleContentRect().size(); 290 IntSize scrollSize = m_contentsSize - visibleContentRect().size();
290 scrollSize.clampNegativeToZero(); 291 scrollSize.clampNegativeToZero();
291 return orientation == HorizontalScrollbar ? scrollSize.width() : scrollS ize.height(); 292 return orientation == HorizontalScrollbar ? scrollSize.width() : scrollS ize.height();
292 } 293 }
293 294
294 Scrollbar* scrollbar = ((orientation == HorizontalScrollbar) ? m_horizontalS crollbar : m_verticalScrollbar).get(); 295 return scrollbar->totalSize() - scrollbar->visibleSize();
295 return scrollbar ? (scrollbar->totalSize() - scrollbar->visibleSize()) : 0;
296 } 296 }
297 297
298 void ScrollView::notifyPageThatContentAreaWillPaint() const 298 void ScrollView::notifyPageThatContentAreaWillPaint() const
299 { 299 {
300 } 300 }
301 301
302 void ScrollView::setScrollOffset(const IntPoint& offset) 302 void ScrollView::setScrollOffset(const IntPoint& offset)
303 { 303 {
304 scrollTo(toIntSize(adjustScrollPositionWithinRange(offset))); 304 scrollTo(toIntSize(adjustScrollPositionWithinRange(offset)));
305 } 305 }
(...skipping 17 matching lines...) Expand all
323 { 323 {
324 if (scrollbar->orientation() == HorizontalScrollbar) 324 if (scrollbar->orientation() == HorizontalScrollbar)
325 return scrollPosition().x() + scrollOrigin().x(); 325 return scrollPosition().x() + scrollOrigin().x();
326 if (scrollbar->orientation() == VerticalScrollbar) 326 if (scrollbar->orientation() == VerticalScrollbar)
327 return scrollPosition().y() + scrollOrigin().y(); 327 return scrollPosition().y() + scrollOrigin().y();
328 return 0; 328 return 0;
329 } 329 }
330 330
331 void ScrollView::setScrollPosition(const IntPoint& scrollPoint) 331 void ScrollView::setScrollPosition(const IntPoint& scrollPoint)
332 { 332 {
333 if (prohibitsScrolling())
334 return;
335
336 IntPoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint); 333 IntPoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint);
337 334
338 if (newScrollPosition == scrollPosition()) 335 if (newScrollPosition == scrollPosition())
339 return; 336 return;
340 337
341 updateScrollbars(IntSize(newScrollPosition.x(), newScrollPosition.y())); 338 updateScrollbars(IntSize(newScrollPosition.x(), newScrollPosition.y()));
342 } 339 }
343 340
344 bool ScrollView::logicalScroll(ScrollLogicalDirection direction, ScrollGranulari ty granularity) 341 bool ScrollView::logicalScroll(ScrollLogicalDirection direction, ScrollGranulari ty granularity)
345 { 342 {
(...skipping 21 matching lines...) Expand all
367 364
368 void ScrollView::windowResizerRectChanged() 365 void ScrollView::windowResizerRectChanged()
369 { 366 {
370 updateScrollbars(scrollOffset()); 367 updateScrollbars(scrollOffset());
371 } 368 }
372 369
373 static const unsigned cMaxUpdateScrollbarsPass = 2; 370 static const unsigned cMaxUpdateScrollbarsPass = 2;
374 371
375 void ScrollView::updateScrollbars(const IntSize& desiredOffset) 372 void ScrollView::updateScrollbars(const IntSize& desiredOffset)
376 { 373 {
377 if (m_inUpdateScrollbars || prohibitsScrolling()) 374 if (m_inUpdateScrollbars)
378 return; 375 return;
379 376
380 // If we came in here with the view already needing a layout, then go ahead and do that 377 // If we came in here with the view already needing a layout, then go ahead and do that
381 // first. (This will be the common case, e.g., when the page changes due to window resizing for example). 378 // first. (This will be the common case, e.g., when the page changes due to window resizing for example).
382 // This layout will not re-enter updateScrollbars and does not count towards our max layout pass total. 379 // This layout will not re-enter updateScrollbars and does not count towards our max layout pass total.
383 if (!m_scrollbarsSuppressed) { 380 if (!m_scrollbarsSuppressed) {
384 m_inUpdateScrollbars = true; 381 m_inUpdateScrollbars = true;
385 visibleContentsResized(); 382 visibleContentsResized();
386 m_inUpdateScrollbars = false; 383 m_inUpdateScrollbars = false;
387 } 384 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 474
478 // Set up the range (and page step/line step), but only do this if we're not in a nested call (to avoid 475 // Set up the range (and page step/line step), but only do this if we're not in a nested call (to avoid
479 // doing it multiple times). 476 // doing it multiple times).
480 if (m_updateScrollbarsPass) 477 if (m_updateScrollbarsPass)
481 return; 478 return;
482 479
483 m_inUpdateScrollbars = true; 480 m_inUpdateScrollbars = true;
484 481
485 if (m_horizontalScrollbar) { 482 if (m_horizontalScrollbar) {
486 int clientWidth = visibleWidth(); 483 int clientWidth = visibleWidth();
487 int pageStep = max(max<int>(clientWidth * Scrollbar::minFractionToStepWh enPaging(), clientWidth - Scrollbar::maxOverlapBetweenPages()), 1);
488 IntRect oldRect(m_horizontalScrollbar->frameRect()); 484 IntRect oldRect(m_horizontalScrollbar->frameRect());
489 IntRect hBarRect(0, 485 IntRect hBarRect(0,
490 height() - m_horizontalScrollbar->height(), 486 height() - m_horizontalScrollbar->height(),
491 width() - (m_verticalScrollbar ? m_verticalScrollbar->wi dth() : 0), 487 width() - (m_verticalScrollbar ? m_verticalScrollbar->wi dth() : 0),
492 m_horizontalScrollbar->height()); 488 m_horizontalScrollbar->height());
493 m_horizontalScrollbar->setFrameRect(hBarRect); 489 m_horizontalScrollbar->setFrameRect(hBarRect);
494 if (!m_scrollbarsSuppressed && oldRect != m_horizontalScrollbar->frameRe ct()) 490 if (!m_scrollbarsSuppressed && oldRect != m_horizontalScrollbar->frameRe ct())
495 m_horizontalScrollbar->invalidate(); 491 m_horizontalScrollbar->invalidate();
496 492
497 if (m_scrollbarsSuppressed) 493 if (m_scrollbarsSuppressed)
498 m_horizontalScrollbar->setSuppressInvalidation(true); 494 m_horizontalScrollbar->setSuppressInvalidation(true);
499 m_horizontalScrollbar->setEnabled(contentsWidth() > clientWidth); 495 m_horizontalScrollbar->setEnabled(contentsWidth() > clientWidth);
500 m_horizontalScrollbar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep );
501 m_horizontalScrollbar->setProportion(clientWidth, contentsWidth()); 496 m_horizontalScrollbar->setProportion(clientWidth, contentsWidth());
502 if (m_scrollbarsSuppressed) 497 if (m_scrollbarsSuppressed)
503 m_horizontalScrollbar->setSuppressInvalidation(false); 498 m_horizontalScrollbar->setSuppressInvalidation(false);
504 } 499 }
505 500
506 if (m_verticalScrollbar) { 501 if (m_verticalScrollbar) {
507 int clientHeight = visibleHeight(); 502 int clientHeight = visibleHeight();
508 int pageStep = max(max<int>(clientHeight * Scrollbar::minFractionToStepW henPaging(), clientHeight - Scrollbar::maxOverlapBetweenPages()), 1);
509 IntRect oldRect(m_verticalScrollbar->frameRect()); 503 IntRect oldRect(m_verticalScrollbar->frameRect());
510 IntRect vBarRect(width() - m_verticalScrollbar->width(), 504 IntRect vBarRect(width() - m_verticalScrollbar->width(),
511 0, 505 0,
512 m_verticalScrollbar->width(), 506 m_verticalScrollbar->width(),
513 height() - (m_horizontalScrollbar ? m_horizontalScrollb ar->height() : 0)); 507 height() - (m_horizontalScrollbar ? m_horizontalScrollb ar->height() : 0));
514 m_verticalScrollbar->setFrameRect(vBarRect); 508 m_verticalScrollbar->setFrameRect(vBarRect);
515 if (!m_scrollbarsSuppressed && oldRect != m_verticalScrollbar->frameRect ()) 509 if (!m_scrollbarsSuppressed && oldRect != m_verticalScrollbar->frameRect ())
516 m_verticalScrollbar->invalidate(); 510 m_verticalScrollbar->invalidate();
517 511
518 if (m_scrollbarsSuppressed) 512 if (m_scrollbarsSuppressed)
519 m_verticalScrollbar->setSuppressInvalidation(true); 513 m_verticalScrollbar->setSuppressInvalidation(true);
520 m_verticalScrollbar->setEnabled(contentsHeight() > clientHeight); 514 m_verticalScrollbar->setEnabled(contentsHeight() > clientHeight);
521 m_verticalScrollbar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep);
522 m_verticalScrollbar->setProportion(clientHeight, contentsHeight()); 515 m_verticalScrollbar->setProportion(clientHeight, contentsHeight());
523 if (m_scrollbarsSuppressed) 516 if (m_scrollbarsSuppressed)
524 m_verticalScrollbar->setSuppressInvalidation(false); 517 m_verticalScrollbar->setSuppressInvalidation(false);
525 } 518 }
526 519
527 if (hasHorizontalScrollbar != newHasHorizontalScrollbar || hasVerticalScroll bar != newHasVerticalScrollbar) { 520 if (hasHorizontalScrollbar != newHasHorizontalScrollbar || hasVerticalScroll bar != newHasVerticalScrollbar) {
528 // FIXME: Is frameRectsChanged really necessary here? Have any frame rec ts changed? 521 // FIXME: Is frameRectsChanged really necessary here? Have any frame rec ts changed?
529 frameRectsChanged(); 522 frameRectsChanged();
530 positionScrollbarLayers(); 523 positionScrollbarLayers();
531 updateScrollCorner(); 524 updateScrollCorner();
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 graphicsLayer->setSize(cornerRect.size()); 808 graphicsLayer->setSize(cornerRect.size());
816 } 809 }
817 810
818 void ScrollView::positionScrollbarLayers() 811 void ScrollView::positionScrollbarLayers()
819 { 812 {
820 positionScrollbarLayer(layerForHorizontalScrollbar(), horizontalScrollbar()) ; 813 positionScrollbarLayer(layerForHorizontalScrollbar(), horizontalScrollbar()) ;
821 positionScrollbarLayer(layerForVerticalScrollbar(), verticalScrollbar()); 814 positionScrollbarLayer(layerForVerticalScrollbar(), verticalScrollbar());
822 positionScrollCornerLayer(layerForScrollCorner(), scrollCornerRect()); 815 positionScrollCornerLayer(layerForScrollCorner(), scrollCornerRect());
823 } 816 }
824 817
818 bool ScrollView::userInputScrollable(ScrollbarOrientation orientation) const
819 {
820 ScrollbarMode mode = (orientation == HorizontalScrollbar) ?
821 m_horizontalScrollbarMode : m_verticalScrollbarMode;
822
823 return mode == ScrollbarAuto || mode == ScrollbarAlwaysOn;
824 }
825
825 void ScrollView::repaintContentRectangle(const IntRect& rect) 826 void ScrollView::repaintContentRectangle(const IntRect& rect)
826 { 827 {
827 IntRect paintRect = rect; 828 IntRect paintRect = rect;
828 if (clipsRepaints() && !paintsEntireContents()) 829 if (clipsRepaints() && !paintsEntireContents())
829 paintRect.intersect(visibleContentRect()); 830 paintRect.intersect(visibleContentRect());
830 if (paintRect.isEmpty()) 831 if (paintRect.isEmpty())
831 return; 832 return;
832 833
833 if (hostWindow()) 834 if (hostWindow())
834 hostWindow()->invalidateContentsAndRootView(contentsToWindow(paintRect)) ; 835 hostWindow()->invalidateContentsAndRootView(contentsToWindow(paintRect)) ;
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 { 1255 {
1255 } 1256 }
1256 1257
1257 bool ScrollView::platformIsOffscreen() const 1258 bool ScrollView::platformIsOffscreen() const
1258 { 1259 {
1259 return false; 1260 return false;
1260 } 1261 }
1261 1262
1262 1263
1263 } 1264 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698