Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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. |
|
tdanderson
2013/07/15 23:17:44
I know you didn't write this comment in the first
bokan
2013/07/22 15:08:47
Done.
| |
| 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 } |
| 306 | 306 |
| 307 void ScrollView::scrollTo(const IntSize& newOffset) | 307 void ScrollView::scrollTo(const IntSize& newOffset) |
| 308 { | 308 { |
| 309 IntSize scrollDelta = newOffset - m_scrollOffset; | 309 IntSize scrollDelta = newOffset - m_scrollOffset; |
| 310 if (scrollDelta == IntSize()) | 310 if (scrollDelta == IntSize()) |
| 311 return; | 311 return; |
| 312 m_scrollOffset = newOffset; | 312 m_scrollOffset = newOffset; |
| 313 | 313 |
| 314 if (scrollbarsSuppressed()) | 314 if (scrollbarsSuppressed()) |
| 315 return; | 315 return; |
| 316 | 316 |
| 317 repaintFixedElementsAfterScrolling(); | 317 repaintFixedElementsAfterScrolling(); |
| 318 scrollContents(scrollDelta); | 318 scrollContents(scrollDelta); |
| 319 updateFixedElementsAfterScrolling(); | 319 updateFixedElementsAfterScrolling(); |
| 320 } | 320 } |
| 321 | 321 |
| 322 int ScrollView::scrollPosition(Scrollbar* scrollbar) const | |
| 323 { | |
| 324 if (scrollbar->orientation() == HorizontalScrollbar) | |
| 325 return scrollPosition().x() + scrollOrigin().x(); | |
| 326 if (scrollbar->orientation() == VerticalScrollbar) | |
| 327 return scrollPosition().y() + scrollOrigin().y(); | |
| 328 return 0; | |
| 329 } | |
| 330 | |
| 331 void ScrollView::setScrollPosition(const IntPoint& scrollPoint) | 322 void ScrollView::setScrollPosition(const IntPoint& scrollPoint) |
| 332 { | 323 { |
| 333 if (prohibitsScrolling()) | |
| 334 return; | |
| 335 | |
| 336 IntPoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint); | 324 IntPoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint); |
| 337 | 325 |
| 338 if (newScrollPosition == scrollPosition()) | 326 if (newScrollPosition == scrollPosition()) |
| 339 return; | 327 return; |
| 340 | 328 |
| 341 updateScrollbars(IntSize(newScrollPosition.x(), newScrollPosition.y())); | 329 updateScrollbars(IntSize(newScrollPosition.x(), newScrollPosition.y())); |
| 342 } | 330 } |
| 343 | 331 |
| 344 bool ScrollView::logicalScroll(ScrollLogicalDirection direction, ScrollGranulari ty granularity) | 332 bool ScrollView::logicalScroll(ScrollLogicalDirection direction, ScrollGranulari ty granularity) |
| 345 { | 333 { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 367 | 355 |
| 368 void ScrollView::windowResizerRectChanged() | 356 void ScrollView::windowResizerRectChanged() |
| 369 { | 357 { |
| 370 updateScrollbars(scrollOffset()); | 358 updateScrollbars(scrollOffset()); |
| 371 } | 359 } |
| 372 | 360 |
| 373 static const unsigned cMaxUpdateScrollbarsPass = 2; | 361 static const unsigned cMaxUpdateScrollbarsPass = 2; |
| 374 | 362 |
| 375 void ScrollView::updateScrollbars(const IntSize& desiredOffset) | 363 void ScrollView::updateScrollbars(const IntSize& desiredOffset) |
| 376 { | 364 { |
| 377 if (m_inUpdateScrollbars || prohibitsScrolling()) | 365 if (m_inUpdateScrollbars) |
| 378 return; | 366 return; |
| 379 | 367 |
| 380 // If we came in here with the view already needing a layout, then go ahead and do that | 368 // 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). | 369 // 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. | 370 // This layout will not re-enter updateScrollbars and does not count towards our max layout pass total. |
| 383 if (!m_scrollbarsSuppressed) { | 371 if (!m_scrollbarsSuppressed) { |
| 384 m_inUpdateScrollbars = true; | 372 m_inUpdateScrollbars = true; |
| 385 visibleContentsResized(); | 373 visibleContentsResized(); |
| 386 m_inUpdateScrollbars = false; | 374 m_inUpdateScrollbars = false; |
| 387 } | 375 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 // The layout with the new scroll state had no impact on | 456 // The layout with the new scroll state had no impact on |
| 469 // the document's overall size, so updateScrollbars didn't g et called. | 457 // the document's overall size, so updateScrollbars didn't g et called. |
| 470 // Recur manually. | 458 // Recur manually. |
| 471 updateScrollbars(desiredOffset); | 459 updateScrollbars(desiredOffset); |
| 472 } | 460 } |
| 473 m_updateScrollbarsPass--; | 461 m_updateScrollbarsPass--; |
| 474 } | 462 } |
| 475 } | 463 } |
| 476 } | 464 } |
| 477 | 465 |
| 478 // Set up the range (and page step/line step), but only do this if we're not in a nested call (to avoid | 466 // Set up the range, but only do this if we're not in a nested call (to avoi d |
| 479 // doing it multiple times). | 467 // doing it multiple times). |
| 480 if (m_updateScrollbarsPass) | 468 if (m_updateScrollbarsPass) |
| 481 return; | 469 return; |
| 482 | 470 |
| 483 m_inUpdateScrollbars = true; | 471 m_inUpdateScrollbars = true; |
| 484 | 472 |
| 485 if (m_horizontalScrollbar) { | 473 if (m_horizontalScrollbar) { |
| 486 int clientWidth = visibleWidth(); | 474 int clientWidth = visibleWidth(); |
| 487 int pageStep = max(max<int>(clientWidth * Scrollbar::minFractionToStepWh enPaging(), clientWidth - Scrollbar::maxOverlapBetweenPages()), 1); | |
| 488 IntRect oldRect(m_horizontalScrollbar->frameRect()); | 475 IntRect oldRect(m_horizontalScrollbar->frameRect()); |
| 489 IntRect hBarRect(0, | 476 IntRect hBarRect(0, |
| 490 height() - m_horizontalScrollbar->height(), | 477 height() - m_horizontalScrollbar->height(), |
| 491 width() - (m_verticalScrollbar ? m_verticalScrollbar->wi dth() : 0), | 478 width() - (m_verticalScrollbar ? m_verticalScrollbar->wi dth() : 0), |
| 492 m_horizontalScrollbar->height()); | 479 m_horizontalScrollbar->height()); |
| 493 m_horizontalScrollbar->setFrameRect(hBarRect); | 480 m_horizontalScrollbar->setFrameRect(hBarRect); |
| 494 if (!m_scrollbarsSuppressed && oldRect != m_horizontalScrollbar->frameRe ct()) | 481 if (!m_scrollbarsSuppressed && oldRect != m_horizontalScrollbar->frameRe ct()) |
| 495 m_horizontalScrollbar->invalidate(); | 482 m_horizontalScrollbar->invalidate(); |
| 496 | 483 |
| 497 if (m_scrollbarsSuppressed) | 484 if (m_scrollbarsSuppressed) |
| 498 m_horizontalScrollbar->setSuppressInvalidation(true); | 485 m_horizontalScrollbar->setSuppressInvalidation(true); |
| 499 m_horizontalScrollbar->setEnabled(contentsWidth() > clientWidth); | 486 m_horizontalScrollbar->setEnabled(contentsWidth() > clientWidth); |
| 500 m_horizontalScrollbar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep ); | |
| 501 m_horizontalScrollbar->setProportion(clientWidth, contentsWidth()); | 487 m_horizontalScrollbar->setProportion(clientWidth, contentsWidth()); |
| 502 if (m_scrollbarsSuppressed) | 488 if (m_scrollbarsSuppressed) |
| 503 m_horizontalScrollbar->setSuppressInvalidation(false); | 489 m_horizontalScrollbar->setSuppressInvalidation(false); |
| 504 } | 490 } |
| 505 | 491 |
| 506 if (m_verticalScrollbar) { | 492 if (m_verticalScrollbar) { |
| 507 int clientHeight = visibleHeight(); | 493 int clientHeight = visibleHeight(); |
| 508 int pageStep = max(max<int>(clientHeight * Scrollbar::minFractionToStepW henPaging(), clientHeight - Scrollbar::maxOverlapBetweenPages()), 1); | |
| 509 IntRect oldRect(m_verticalScrollbar->frameRect()); | 494 IntRect oldRect(m_verticalScrollbar->frameRect()); |
| 510 IntRect vBarRect(width() - m_verticalScrollbar->width(), | 495 IntRect vBarRect(width() - m_verticalScrollbar->width(), |
| 511 0, | 496 0, |
| 512 m_verticalScrollbar->width(), | 497 m_verticalScrollbar->width(), |
| 513 height() - (m_horizontalScrollbar ? m_horizontalScrollb ar->height() : 0)); | 498 height() - (m_horizontalScrollbar ? m_horizontalScrollb ar->height() : 0)); |
| 514 m_verticalScrollbar->setFrameRect(vBarRect); | 499 m_verticalScrollbar->setFrameRect(vBarRect); |
| 515 if (!m_scrollbarsSuppressed && oldRect != m_verticalScrollbar->frameRect ()) | 500 if (!m_scrollbarsSuppressed && oldRect != m_verticalScrollbar->frameRect ()) |
| 516 m_verticalScrollbar->invalidate(); | 501 m_verticalScrollbar->invalidate(); |
| 517 | 502 |
| 518 if (m_scrollbarsSuppressed) | 503 if (m_scrollbarsSuppressed) |
| 519 m_verticalScrollbar->setSuppressInvalidation(true); | 504 m_verticalScrollbar->setSuppressInvalidation(true); |
| 520 m_verticalScrollbar->setEnabled(contentsHeight() > clientHeight); | 505 m_verticalScrollbar->setEnabled(contentsHeight() > clientHeight); |
| 521 m_verticalScrollbar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep); | |
| 522 m_verticalScrollbar->setProportion(clientHeight, contentsHeight()); | 506 m_verticalScrollbar->setProportion(clientHeight, contentsHeight()); |
| 523 if (m_scrollbarsSuppressed) | 507 if (m_scrollbarsSuppressed) |
| 524 m_verticalScrollbar->setSuppressInvalidation(false); | 508 m_verticalScrollbar->setSuppressInvalidation(false); |
| 525 } | 509 } |
| 526 | 510 |
| 527 if (hasHorizontalScrollbar != newHasHorizontalScrollbar || hasVerticalScroll bar != newHasVerticalScrollbar) { | 511 if (hasHorizontalScrollbar != newHasHorizontalScrollbar || hasVerticalScroll bar != newHasVerticalScrollbar) { |
| 528 // FIXME: Is frameRectsChanged really necessary here? Have any frame rec ts changed? | 512 // FIXME: Is frameRectsChanged really necessary here? Have any frame rec ts changed? |
| 529 frameRectsChanged(); | 513 frameRectsChanged(); |
| 530 positionScrollbarLayers(); | 514 positionScrollbarLayers(); |
| 531 updateScrollCorner(); | 515 updateScrollCorner(); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 815 graphicsLayer->setSize(cornerRect.size()); | 799 graphicsLayer->setSize(cornerRect.size()); |
| 816 } | 800 } |
| 817 | 801 |
| 818 void ScrollView::positionScrollbarLayers() | 802 void ScrollView::positionScrollbarLayers() |
| 819 { | 803 { |
| 820 positionScrollbarLayer(layerForHorizontalScrollbar(), horizontalScrollbar()) ; | 804 positionScrollbarLayer(layerForHorizontalScrollbar(), horizontalScrollbar()) ; |
| 821 positionScrollbarLayer(layerForVerticalScrollbar(), verticalScrollbar()); | 805 positionScrollbarLayer(layerForVerticalScrollbar(), verticalScrollbar()); |
| 822 positionScrollCornerLayer(layerForScrollCorner(), scrollCornerRect()); | 806 positionScrollCornerLayer(layerForScrollCorner(), scrollCornerRect()); |
| 823 } | 807 } |
| 824 | 808 |
| 809 bool ScrollView::userInputScrollable(ScrollbarOrientation orientation) const | |
| 810 { | |
| 811 ScrollbarMode mode = (orientation == HorizontalScrollbar) ? | |
| 812 m_horizontalScrollbarMode : m_verticalScrollbarMode; | |
| 813 | |
| 814 return mode == ScrollbarAuto || mode == ScrollbarAlwaysOn; | |
| 815 } | |
| 816 | |
| 825 void ScrollView::repaintContentRectangle(const IntRect& rect) | 817 void ScrollView::repaintContentRectangle(const IntRect& rect) |
| 826 { | 818 { |
| 827 IntRect paintRect = rect; | 819 IntRect paintRect = rect; |
| 828 if (clipsRepaints() && !paintsEntireContents()) | 820 if (clipsRepaints() && !paintsEntireContents()) |
| 829 paintRect.intersect(visibleContentRect()); | 821 paintRect.intersect(visibleContentRect()); |
| 830 if (paintRect.isEmpty()) | 822 if (paintRect.isEmpty()) |
| 831 return; | 823 return; |
| 832 | 824 |
| 833 if (hostWindow()) | 825 if (hostWindow()) |
| 834 hostWindow()->invalidateContentsAndRootView(contentsToWindow(paintRect)) ; | 826 hostWindow()->invalidateContentsAndRootView(contentsToWindow(paintRect)) ; |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1252 | 1244 |
| 1253 void ScrollView::platformRepaintContentRectangle(const IntRect&) | 1245 void ScrollView::platformRepaintContentRectangle(const IntRect&) |
| 1254 { | 1246 { |
| 1255 } | 1247 } |
| 1256 | 1248 |
| 1257 bool ScrollView::platformIsOffscreen() const | 1249 bool ScrollView::platformIsOffscreen() const |
| 1258 { | 1250 { |
| 1259 return false; | 1251 return false; |
| 1260 } | 1252 } |
| 1261 | 1253 |
| 1254 int ScrollView::pageStep(ScrollbarOrientation orientation) const | |
| 1255 { | |
| 1256 int length = (orientation == HorizontalScrollbar) ? visibleWidth() : visible Height(); | |
| 1257 int minPageStep = static_cast<float>(length) * minFractionToStepWhenPaging() ; | |
| 1258 int pageStep = std::max(minPageStep, length - maxOverlapBetweenPages()); | |
| 1262 | 1259 |
| 1260 return std::max(pageStep, 1); | |
| 1263 } | 1261 } |
| 1262 | |
| 1263 } // namespace WebCore | |
| OLD | NEW |