| 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 if (!constrainsScrollingToContentEdge()) | 274 if (!constrainsScrollingToContentEdge()) |
| 276 return scrollPoint; | 275 return scrollPoint; |
| 277 | 276 |
| 278 IntPoint newScrollPosition = scrollPoint.shrunkTo(maximumScrollPosition()); | 277 IntPoint newScrollPosition = scrollPoint.shrunkTo(maximumScrollPosition()); |
| 279 newScrollPosition = newScrollPosition.expandedTo(minimumScrollPosition()); | 278 newScrollPosition = newScrollPosition.expandedTo(minimumScrollPosition()); |
| 280 return newScrollPosition; | 279 return newScrollPosition; |
| 281 } | 280 } |
| 282 | 281 |
| 283 int ScrollView::scrollSize(ScrollbarOrientation orientation) const | 282 int ScrollView::scrollSize(ScrollbarOrientation orientation) const |
| 284 { | 283 { |
| 285 // If no scrollbars are present, it does not indicate content is not be scro
llable. | 284 Scrollbar* scrollbar = ((orientation == HorizontalScrollbar) ? m_horizontalS
crollbar : m_verticalScrollbar).get(); |
| 286 if (!m_horizontalScrollbar && !m_verticalScrollbar && !prohibitsScrolling())
{ | 285 |
| 286 // If no scrollbars are present, the content may still be scrollable. |
| 287 if (!scrollbar) { |
| 287 IntSize scrollSize = m_contentsSize - visibleContentRect().size(); | 288 IntSize scrollSize = m_contentsSize - visibleContentRect().size(); |
| 288 scrollSize.clampNegativeToZero(); | 289 scrollSize.clampNegativeToZero(); |
| 289 return orientation == HorizontalScrollbar ? scrollSize.width() : scrollS
ize.height(); | 290 return orientation == HorizontalScrollbar ? scrollSize.width() : scrollS
ize.height(); |
| 290 } | 291 } |
| 291 | 292 |
| 292 Scrollbar* scrollbar = ((orientation == HorizontalScrollbar) ? m_horizontalS
crollbar : m_verticalScrollbar).get(); | 293 return scrollbar->totalSize() - scrollbar->visibleSize(); |
| 293 return scrollbar ? (scrollbar->totalSize() - scrollbar->visibleSize()) : 0; | |
| 294 } | 294 } |
| 295 | 295 |
| 296 void ScrollView::notifyPageThatContentAreaWillPaint() const | 296 void ScrollView::notifyPageThatContentAreaWillPaint() const |
| 297 { | 297 { |
| 298 } | 298 } |
| 299 | 299 |
| 300 void ScrollView::setScrollOffset(const IntPoint& offset) | 300 void ScrollView::setScrollOffset(const IntPoint& offset) |
| 301 { | 301 { |
| 302 scrollTo(toIntSize(adjustScrollPositionWithinRange(offset))); | 302 scrollTo(toIntSize(adjustScrollPositionWithinRange(offset))); |
| 303 } | 303 } |
| 304 | 304 |
| 305 void ScrollView::scrollTo(const IntSize& newOffset) | 305 void ScrollView::scrollTo(const IntSize& newOffset) |
| 306 { | 306 { |
| 307 IntSize scrollDelta = newOffset - m_scrollOffset; | 307 IntSize scrollDelta = newOffset - m_scrollOffset; |
| 308 if (scrollDelta == IntSize()) | 308 if (scrollDelta == IntSize()) |
| 309 return; | 309 return; |
| 310 m_scrollOffset = newOffset; | 310 m_scrollOffset = newOffset; |
| 311 | 311 |
| 312 if (scrollbarsSuppressed()) | 312 if (scrollbarsSuppressed()) |
| 313 return; | 313 return; |
| 314 | 314 |
| 315 repaintFixedElementsAfterScrolling(); | 315 repaintFixedElementsAfterScrolling(); |
| 316 scrollContents(scrollDelta); | 316 scrollContents(scrollDelta); |
| 317 updateFixedElementsAfterScrolling(); | 317 updateFixedElementsAfterScrolling(); |
| 318 } | 318 } |
| 319 | 319 |
| 320 int ScrollView::scrollPosition(Scrollbar* scrollbar) const | |
| 321 { | |
| 322 if (scrollbar->orientation() == HorizontalScrollbar) | |
| 323 return scrollPosition().x() + scrollOrigin().x(); | |
| 324 if (scrollbar->orientation() == VerticalScrollbar) | |
| 325 return scrollPosition().y() + scrollOrigin().y(); | |
| 326 return 0; | |
| 327 } | |
| 328 | |
| 329 void ScrollView::setScrollPosition(const IntPoint& scrollPoint) | 320 void ScrollView::setScrollPosition(const IntPoint& scrollPoint) |
| 330 { | 321 { |
| 331 if (prohibitsScrolling()) | |
| 332 return; | |
| 333 | |
| 334 IntPoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint); | 322 IntPoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint); |
| 335 | 323 |
| 336 if (newScrollPosition == scrollPosition()) | 324 if (newScrollPosition == scrollPosition()) |
| 337 return; | 325 return; |
| 338 | 326 |
| 339 updateScrollbars(IntSize(newScrollPosition.x(), newScrollPosition.y())); | 327 updateScrollbars(IntSize(newScrollPosition.x(), newScrollPosition.y())); |
| 340 } | 328 } |
| 341 | 329 |
| 342 bool ScrollView::logicalScroll(ScrollLogicalDirection direction, ScrollGranulari
ty granularity) | 330 bool ScrollView::logicalScroll(ScrollLogicalDirection direction, ScrollGranulari
ty granularity) |
| 343 { | 331 { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 365 | 353 |
| 366 void ScrollView::windowResizerRectChanged() | 354 void ScrollView::windowResizerRectChanged() |
| 367 { | 355 { |
| 368 updateScrollbars(scrollOffset()); | 356 updateScrollbars(scrollOffset()); |
| 369 } | 357 } |
| 370 | 358 |
| 371 static const unsigned cMaxUpdateScrollbarsPass = 2; | 359 static const unsigned cMaxUpdateScrollbarsPass = 2; |
| 372 | 360 |
| 373 void ScrollView::updateScrollbars(const IntSize& desiredOffset) | 361 void ScrollView::updateScrollbars(const IntSize& desiredOffset) |
| 374 { | 362 { |
| 375 if (m_inUpdateScrollbars || prohibitsScrolling()) | 363 if (m_inUpdateScrollbars) |
| 376 return; | 364 return; |
| 377 | 365 |
| 378 // If we came in here with the view already needing a layout, then go ahead
and do that | 366 // If we came in here with the view already needing a layout, then go ahead
and do that |
| 379 // first. (This will be the common case, e.g., when the page changes due to
window resizing for example). | 367 // first. (This will be the common case, e.g., when the page changes due to
window resizing for example). |
| 380 // This layout will not re-enter updateScrollbars and does not count towards
our max layout pass total. | 368 // This layout will not re-enter updateScrollbars and does not count towards
our max layout pass total. |
| 381 if (!m_scrollbarsSuppressed) { | 369 if (!m_scrollbarsSuppressed) { |
| 382 m_inUpdateScrollbars = true; | 370 m_inUpdateScrollbars = true; |
| 383 visibleContentsResized(); | 371 visibleContentsResized(); |
| 384 m_inUpdateScrollbars = false; | 372 m_inUpdateScrollbars = false; |
| 385 } | 373 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 // The layout with the new scroll state had no impact on | 454 // The layout with the new scroll state had no impact on |
| 467 // the document's overall size, so updateScrollbars didn't g
et called. | 455 // the document's overall size, so updateScrollbars didn't g
et called. |
| 468 // Recur manually. | 456 // Recur manually. |
| 469 updateScrollbars(desiredOffset); | 457 updateScrollbars(desiredOffset); |
| 470 } | 458 } |
| 471 m_updateScrollbarsPass--; | 459 m_updateScrollbarsPass--; |
| 472 } | 460 } |
| 473 } | 461 } |
| 474 } | 462 } |
| 475 | 463 |
| 476 // Set up the range (and page step/line step), but only do this if we're not
in a nested call (to avoid | 464 // Set up the range, but only do this if we're not in a nested call (to avoi
d |
| 477 // doing it multiple times). | 465 // doing it multiple times). |
| 478 if (m_updateScrollbarsPass) | 466 if (m_updateScrollbarsPass) |
| 479 return; | 467 return; |
| 480 | 468 |
| 481 m_inUpdateScrollbars = true; | 469 m_inUpdateScrollbars = true; |
| 482 | 470 |
| 483 if (m_horizontalScrollbar) { | 471 if (m_horizontalScrollbar) { |
| 484 int clientWidth = visibleWidth(); | 472 int clientWidth = visibleWidth(); |
| 485 int pageStep = max(max<int>(clientWidth * Scrollbar::minFractionToStepWh
enPaging(), clientWidth - Scrollbar::maxOverlapBetweenPages()), 1); | |
| 486 IntRect oldRect(m_horizontalScrollbar->frameRect()); | 473 IntRect oldRect(m_horizontalScrollbar->frameRect()); |
| 487 IntRect hBarRect(0, | 474 IntRect hBarRect(0, |
| 488 height() - m_horizontalScrollbar->height(), | 475 height() - m_horizontalScrollbar->height(), |
| 489 width() - (m_verticalScrollbar ? m_verticalScrollbar->wi
dth() : 0), | 476 width() - (m_verticalScrollbar ? m_verticalScrollbar->wi
dth() : 0), |
| 490 m_horizontalScrollbar->height()); | 477 m_horizontalScrollbar->height()); |
| 491 m_horizontalScrollbar->setFrameRect(hBarRect); | 478 m_horizontalScrollbar->setFrameRect(hBarRect); |
| 492 if (!m_scrollbarsSuppressed && oldRect != m_horizontalScrollbar->frameRe
ct()) | 479 if (!m_scrollbarsSuppressed && oldRect != m_horizontalScrollbar->frameRe
ct()) |
| 493 m_horizontalScrollbar->invalidate(); | 480 m_horizontalScrollbar->invalidate(); |
| 494 | 481 |
| 495 if (m_scrollbarsSuppressed) | 482 if (m_scrollbarsSuppressed) |
| 496 m_horizontalScrollbar->setSuppressInvalidation(true); | 483 m_horizontalScrollbar->setSuppressInvalidation(true); |
| 497 m_horizontalScrollbar->setEnabled(contentsWidth() > clientWidth); | 484 m_horizontalScrollbar->setEnabled(contentsWidth() > clientWidth); |
| 498 m_horizontalScrollbar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep
); | |
| 499 m_horizontalScrollbar->setProportion(clientWidth, contentsWidth()); | 485 m_horizontalScrollbar->setProportion(clientWidth, contentsWidth()); |
| 500 if (m_scrollbarsSuppressed) | 486 if (m_scrollbarsSuppressed) |
| 501 m_horizontalScrollbar->setSuppressInvalidation(false); | 487 m_horizontalScrollbar->setSuppressInvalidation(false); |
| 502 } | 488 } |
| 503 | 489 |
| 504 if (m_verticalScrollbar) { | 490 if (m_verticalScrollbar) { |
| 505 int clientHeight = visibleHeight(); | 491 int clientHeight = visibleHeight(); |
| 506 int pageStep = max(max<int>(clientHeight * Scrollbar::minFractionToStepW
henPaging(), clientHeight - Scrollbar::maxOverlapBetweenPages()), 1); | |
| 507 IntRect oldRect(m_verticalScrollbar->frameRect()); | 492 IntRect oldRect(m_verticalScrollbar->frameRect()); |
| 508 IntRect vBarRect(width() - m_verticalScrollbar->width(), | 493 IntRect vBarRect(width() - m_verticalScrollbar->width(), |
| 509 0, | 494 0, |
| 510 m_verticalScrollbar->width(), | 495 m_verticalScrollbar->width(), |
| 511 height() - (m_horizontalScrollbar ? m_horizontalScrollb
ar->height() : 0)); | 496 height() - (m_horizontalScrollbar ? m_horizontalScrollb
ar->height() : 0)); |
| 512 m_verticalScrollbar->setFrameRect(vBarRect); | 497 m_verticalScrollbar->setFrameRect(vBarRect); |
| 513 if (!m_scrollbarsSuppressed && oldRect != m_verticalScrollbar->frameRect
()) | 498 if (!m_scrollbarsSuppressed && oldRect != m_verticalScrollbar->frameRect
()) |
| 514 m_verticalScrollbar->invalidate(); | 499 m_verticalScrollbar->invalidate(); |
| 515 | 500 |
| 516 if (m_scrollbarsSuppressed) | 501 if (m_scrollbarsSuppressed) |
| 517 m_verticalScrollbar->setSuppressInvalidation(true); | 502 m_verticalScrollbar->setSuppressInvalidation(true); |
| 518 m_verticalScrollbar->setEnabled(contentsHeight() > clientHeight); | 503 m_verticalScrollbar->setEnabled(contentsHeight() > clientHeight); |
| 519 m_verticalScrollbar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep); | |
| 520 m_verticalScrollbar->setProportion(clientHeight, contentsHeight()); | 504 m_verticalScrollbar->setProportion(clientHeight, contentsHeight()); |
| 521 if (m_scrollbarsSuppressed) | 505 if (m_scrollbarsSuppressed) |
| 522 m_verticalScrollbar->setSuppressInvalidation(false); | 506 m_verticalScrollbar->setSuppressInvalidation(false); |
| 523 } | 507 } |
| 524 | 508 |
| 525 if (hasHorizontalScrollbar != newHasHorizontalScrollbar || hasVerticalScroll
bar != newHasVerticalScrollbar) { | 509 if (hasHorizontalScrollbar != newHasHorizontalScrollbar || hasVerticalScroll
bar != newHasVerticalScrollbar) { |
| 526 // FIXME: Is frameRectsChanged really necessary here? Have any frame rec
ts changed? | 510 // FIXME: Is frameRectsChanged really necessary here? Have any frame rec
ts changed? |
| 527 frameRectsChanged(); | 511 frameRectsChanged(); |
| 528 positionScrollbarLayers(); | 512 positionScrollbarLayers(); |
| 529 updateScrollCorner(); | 513 updateScrollCorner(); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 graphicsLayer->setSize(cornerRect.size()); | 791 graphicsLayer->setSize(cornerRect.size()); |
| 808 } | 792 } |
| 809 | 793 |
| 810 void ScrollView::positionScrollbarLayers() | 794 void ScrollView::positionScrollbarLayers() |
| 811 { | 795 { |
| 812 positionScrollbarLayer(layerForHorizontalScrollbar(), horizontalScrollbar())
; | 796 positionScrollbarLayer(layerForHorizontalScrollbar(), horizontalScrollbar())
; |
| 813 positionScrollbarLayer(layerForVerticalScrollbar(), verticalScrollbar()); | 797 positionScrollbarLayer(layerForVerticalScrollbar(), verticalScrollbar()); |
| 814 positionScrollCornerLayer(layerForScrollCorner(), scrollCornerRect()); | 798 positionScrollCornerLayer(layerForScrollCorner(), scrollCornerRect()); |
| 815 } | 799 } |
| 816 | 800 |
| 801 bool ScrollView::userInputScrollable(ScrollbarOrientation orientation) const |
| 802 { |
| 803 ScrollbarMode mode = (orientation == HorizontalScrollbar) ? |
| 804 m_horizontalScrollbarMode : m_verticalScrollbarMode; |
| 805 |
| 806 return mode == ScrollbarAuto || mode == ScrollbarAlwaysOn; |
| 807 } |
| 808 |
| 817 void ScrollView::repaintContentRectangle(const IntRect& rect) | 809 void ScrollView::repaintContentRectangle(const IntRect& rect) |
| 818 { | 810 { |
| 819 IntRect paintRect = rect; | 811 IntRect paintRect = rect; |
| 820 if (clipsRepaints() && !paintsEntireContents()) | 812 if (clipsRepaints() && !paintsEntireContents()) |
| 821 paintRect.intersect(visibleContentRect()); | 813 paintRect.intersect(visibleContentRect()); |
| 822 if (paintRect.isEmpty()) | 814 if (paintRect.isEmpty()) |
| 823 return; | 815 return; |
| 824 | 816 |
| 825 if (hostWindow()) | 817 if (hostWindow()) |
| 826 hostWindow()->invalidateContentsAndRootView(contentsToWindow(paintRect))
; | 818 hostWindow()->invalidateContentsAndRootView(contentsToWindow(paintRect))
; |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 if (scrollOrigin() == origin) | 1160 if (scrollOrigin() == origin) |
| 1169 return; | 1161 return; |
| 1170 | 1162 |
| 1171 ScrollableArea::setScrollOrigin(origin); | 1163 ScrollableArea::setScrollOrigin(origin); |
| 1172 | 1164 |
| 1173 // Update if the scroll origin changes, since our position will be different
if the content size did not change. | 1165 // Update if the scroll origin changes, since our position will be different
if the content size did not change. |
| 1174 if (updatePositionAtAll && updatePositionSynchronously) | 1166 if (updatePositionAtAll && updatePositionSynchronously) |
| 1175 updateScrollbars(scrollOffset()); | 1167 updateScrollbars(scrollOffset()); |
| 1176 } | 1168 } |
| 1177 | 1169 |
| 1170 int ScrollView::pageStep(ScrollbarOrientation orientation) const |
| 1171 { |
| 1172 int length = (orientation == HorizontalScrollbar) ? visibleWidth() : visible
Height(); |
| 1173 int minPageStep = static_cast<float>(length) * minFractionToStepWhenPaging()
; |
| 1174 int pageStep = std::max(minPageStep, length - maxOverlapBetweenPages()); |
| 1175 |
| 1176 return std::max(pageStep, 1); |
| 1178 } | 1177 } |
| 1178 |
| 1179 } // namespace WebCore |
| OLD | NEW |