1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
|
/*
* Copyright (c) 2010, Google Inc. All rights reserved.
* Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "platform/scroll/ScrollableArea.h"
#include "platform/HostWindow.h"
#include "platform/graphics/GraphicsLayer.h"
#include "platform/instrumentation/tracing/TraceEvent.h"
#include "platform/scroll/MainThreadScrollingReason.h"
#include "platform/scroll/ProgrammaticScrollAnimator.h"
#include "platform/scroll/ScrollbarTheme.h"
static const int kPixelsPerLineStep = 40;
static const float kMinFractionToStepWhenPaging = 0.875f;
namespace blink {
int ScrollableArea::pixelsPerLineStep(HostWindow* host) {
if (!host)
return kPixelsPerLineStep;
return host->windowToViewportScalar(kPixelsPerLineStep);
}
float ScrollableArea::minFractionToStepWhenPaging() {
return kMinFractionToStepWhenPaging;
}
int ScrollableArea::maxOverlapBetweenPages() {
static int maxOverlapBetweenPages =
ScrollbarTheme::theme().maxOverlapBetweenPages();
return maxOverlapBetweenPages;
}
ScrollableArea::ScrollableArea()
: m_scrollbarOverlayColorTheme(ScrollbarOverlayColorThemeDark),
m_scrollOriginChanged(false),
m_horizontalScrollbarNeedsPaintInvalidation(false),
m_verticalScrollbarNeedsPaintInvalidation(false),
m_scrollCornerNeedsPaintInvalidation(false),
m_scrollbarsHidden(false),
m_scrollbarCaptured(false),
m_mouseOverScrollbar(false) {}
ScrollableArea::~ScrollableArea() {}
void ScrollableArea::clearScrollableArea() {
#if OS(MACOSX)
if (m_scrollAnimator)
m_scrollAnimator->dispose();
#endif
m_scrollAnimator.clear();
m_programmaticScrollAnimator.clear();
if (m_fadeOverlayScrollbarsTimer)
m_fadeOverlayScrollbarsTimer->stop();
}
ScrollAnimatorBase& ScrollableArea::scrollAnimator() const {
if (!m_scrollAnimator)
m_scrollAnimator =
ScrollAnimatorBase::create(const_cast<ScrollableArea*>(this));
return *m_scrollAnimator;
}
ProgrammaticScrollAnimator& ScrollableArea::programmaticScrollAnimator() const {
if (!m_programmaticScrollAnimator)
m_programmaticScrollAnimator =
ProgrammaticScrollAnimator::create(const_cast<ScrollableArea*>(this));
return *m_programmaticScrollAnimator;
}
void ScrollableArea::setScrollOrigin(const IntPoint& origin) {
if (m_scrollOrigin != origin) {
m_scrollOrigin = origin;
m_scrollOriginChanged = true;
}
}
GraphicsLayer* ScrollableArea::layerForContainer() const {
return layerForScrolling() ? layerForScrolling()->parent() : 0;
}
ScrollbarOrientation ScrollableArea::scrollbarOrientationFromDirection(
ScrollDirectionPhysical direction) const {
return (direction == ScrollUp || direction == ScrollDown)
? VerticalScrollbar
: HorizontalScrollbar;
}
float ScrollableArea::scrollStep(ScrollGranularity granularity,
ScrollbarOrientation orientation) const {
switch (granularity) {
case ScrollByLine:
return lineStep(orientation);
case ScrollByPage:
return pageStep(orientation);
case ScrollByDocument:
return documentStep(orientation);
case ScrollByPixel:
case ScrollByPrecisePixel:
return pixelStep(orientation);
default:
ASSERT_NOT_REACHED();
return 0.0f;
}
}
ScrollResult ScrollableArea::userScroll(ScrollGranularity granularity,
const ScrollOffset& delta) {
float stepX = scrollStep(granularity, HorizontalScrollbar);
float stepY = scrollStep(granularity, VerticalScrollbar);
ScrollOffset pixelDelta(delta);
pixelDelta.scale(stepX, stepY);
ScrollOffset scrollableAxisDelta(
userInputScrollable(HorizontalScrollbar) ? pixelDelta.width() : 0,
userInputScrollable(VerticalScrollbar) ? pixelDelta.height() : 0);
if (scrollableAxisDelta.isZero()) {
return ScrollResult(false, false, pixelDelta.width(), pixelDelta.height());
}
cancelProgrammaticScrollAnimation();
ScrollResult result = scrollAnimator().userScroll(granularity, pixelDelta);
// Delta that wasn't scrolled because the axis is !userInputScrollable
// should count as unusedScrollDelta.
ScrollOffset unscrollableAxisDelta = pixelDelta - scrollableAxisDelta;
result.unusedScrollDeltaX += unscrollableAxisDelta.width();
result.unusedScrollDeltaY += unscrollableAxisDelta.height();
return result;
}
void ScrollableArea::setScrollOffset(const ScrollOffset& offset,
ScrollType scrollType,
ScrollBehavior behavior) {
ScrollOffset clampedOffset = clampScrollOffset(offset);
if (clampedOffset == getScrollOffset())
return;
if (behavior == ScrollBehaviorAuto)
behavior = scrollBehaviorStyle();
switch (scrollType) {
case CompositorScroll:
case ClampingScroll:
scrollOffsetChanged(clampedOffset, scrollType);
break;
case AnchoringScroll:
scrollAnimator().adjustAnimationAndSetScrollOffset(clampedOffset,
scrollType);
break;
case ProgrammaticScroll:
programmaticScrollHelper(clampedOffset, behavior);
break;
case UserScroll:
userScrollHelper(clampedOffset, behavior);
break;
default:
ASSERT_NOT_REACHED();
}
}
void ScrollableArea::scrollBy(const ScrollOffset& delta,
ScrollType type,
ScrollBehavior behavior) {
setScrollOffset(getScrollOffset() + delta, type, behavior);
}
void ScrollableArea::setScrollOffsetSingleAxis(ScrollbarOrientation orientation,
float offset,
ScrollType scrollType,
ScrollBehavior behavior) {
ScrollOffset newOffset;
if (orientation == HorizontalScrollbar)
newOffset = ScrollOffset(offset, scrollAnimator().currentOffset().height());
else
newOffset = ScrollOffset(scrollAnimator().currentOffset().width(), offset);
// TODO(bokan): Note, this doesn't use the derived class versions since this
// method is currently used exclusively by code that adjusts the position by
// the scroll origin and the derived class versions differ on whether they
// take that into account or not.
ScrollableArea::setScrollOffset(newOffset, scrollType, behavior);
}
void ScrollableArea::programmaticScrollHelper(const ScrollOffset& offset,
ScrollBehavior scrollBehavior) {
cancelScrollAnimation();
if (scrollBehavior == ScrollBehaviorSmooth)
programmaticScrollAnimator().animateToOffset(offset);
else
programmaticScrollAnimator().scrollToOffsetWithoutAnimation(offset);
}
void ScrollableArea::userScrollHelper(const ScrollOffset& offset,
ScrollBehavior scrollBehavior) {
cancelProgrammaticScrollAnimation();
float x = userInputScrollable(HorizontalScrollbar)
? offset.width()
: scrollAnimator().currentOffset().width();
float y = userInputScrollable(VerticalScrollbar)
? offset.height()
: scrollAnimator().currentOffset().height();
// Smooth user scrolls (keyboard, wheel clicks) are handled via the userScroll
// method.
// TODO(bokan): The userScroll method should probably be modified to call this
// method and ScrollAnimatorBase to have a simpler
// animateToOffset method like the ProgrammaticScrollAnimator.
ASSERT(scrollBehavior == ScrollBehaviorInstant);
scrollAnimator().scrollToOffsetWithoutAnimation(ScrollOffset(x, y));
}
LayoutRect ScrollableArea::scrollIntoView(const LayoutRect& rectInContent,
const ScrollAlignment& alignX,
const ScrollAlignment& alignY,
ScrollType) {
// TODO(bokan): This should really be implemented here but ScrollAlignment is
// in Core which is a dependency violation.
ASSERT_NOT_REACHED();
return LayoutRect();
}
void ScrollableArea::scrollOffsetChanged(const ScrollOffset& offset,
ScrollType scrollType) {
TRACE_EVENT0("blink", "ScrollableArea::scrollOffsetChanged");
ScrollOffset oldOffset = getScrollOffset();
ScrollOffset truncatedOffset = shouldUseIntegerScrollOffset()
? ScrollOffset(flooredIntSize(offset))
: offset;
// Tell the derived class to scroll its contents.
updateScrollOffset(truncatedOffset, scrollType);
// Tell the scrollbars to update their thumb postions.
// If the scrollbar does not have its own layer, it must always be
// invalidated to reflect the new thumb offset, even if the theme did not
// invalidate any individual part.
if (Scrollbar* horizontalScrollbar = this->horizontalScrollbar())
horizontalScrollbar->offsetDidChange();
if (Scrollbar* verticalScrollbar = this->verticalScrollbar())
verticalScrollbar->offsetDidChange();
if (getScrollOffset() != oldOffset)
scrollAnimator().notifyContentAreaScrolled(getScrollOffset() - oldOffset);
scrollAnimator().setCurrentOffset(offset);
}
bool ScrollableArea::scrollBehaviorFromString(const String& behaviorString,
ScrollBehavior& behavior) {
if (behaviorString == "auto")
behavior = ScrollBehaviorAuto;
else if (behaviorString == "instant")
behavior = ScrollBehaviorInstant;
else if (behaviorString == "smooth")
behavior = ScrollBehaviorSmooth;
else
return false;
return true;
}
// NOTE: Only called from Internals for testing.
void ScrollableArea::updateScrollOffsetFromInternals(const IntSize& offset) {
scrollOffsetChanged(ScrollOffset(offset), ProgrammaticScroll);
}
void ScrollableArea::contentAreaWillPaint() const {
if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator())
scrollAnimator->contentAreaWillPaint();
}
void ScrollableArea::mouseEnteredContentArea() const {
if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator())
scrollAnimator->mouseEnteredContentArea();
}
void ScrollableArea::mouseExitedContentArea() const {
if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator())
scrollAnimator->mouseEnteredContentArea();
}
void ScrollableArea::mouseMovedInContentArea() const {
if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator())
scrollAnimator->mouseMovedInContentArea();
}
void ScrollableArea::mouseEnteredScrollbar(Scrollbar& scrollbar) {
m_mouseOverScrollbar = true;
scrollAnimator().mouseEnteredScrollbar(scrollbar);
showOverlayScrollbars();
if (m_fadeOverlayScrollbarsTimer)
m_fadeOverlayScrollbarsTimer->stop();
}
void ScrollableArea::mouseExitedScrollbar(Scrollbar& scrollbar) {
m_mouseOverScrollbar = false;
scrollAnimator().mouseExitedScrollbar(scrollbar);
if (!m_scrollbarsHidden) {
// This will kick off the fade out timer.
showOverlayScrollbars();
}
}
void ScrollableArea::mouseCapturedScrollbar() {
m_scrollbarCaptured = true;
showOverlayScrollbars();
if (m_fadeOverlayScrollbarsTimer)
m_fadeOverlayScrollbarsTimer->stop();
}
void ScrollableArea::mouseReleasedScrollbar() {
m_scrollbarCaptured = false;
// This will kick off the fade out timer.
showOverlayScrollbars();
}
void ScrollableArea::contentAreaDidShow() const {
if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator())
scrollAnimator->contentAreaDidShow();
}
void ScrollableArea::contentAreaDidHide() const {
if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator())
scrollAnimator->contentAreaDidHide();
}
void ScrollableArea::finishCurrentScrollAnimations() const {
if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator())
scrollAnimator->finishCurrentScrollAnimations();
}
void ScrollableArea::didAddScrollbar(Scrollbar& scrollbar,
ScrollbarOrientation orientation) {
if (orientation == VerticalScrollbar)
scrollAnimator().didAddVerticalScrollbar(scrollbar);
else
scrollAnimator().didAddHorizontalScrollbar(scrollbar);
// <rdar://problem/9797253> AppKit resets the scrollbar's style when you
// attach a scrollbar
setScrollbarOverlayColorTheme(getScrollbarOverlayColorTheme());
}
void ScrollableArea::willRemoveScrollbar(Scrollbar& scrollbar,
ScrollbarOrientation orientation) {
if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) {
if (orientation == VerticalScrollbar)
scrollAnimator->willRemoveVerticalScrollbar(scrollbar);
else
scrollAnimator->willRemoveHorizontalScrollbar(scrollbar);
}
}
void ScrollableArea::contentsResized() {
showOverlayScrollbars();
if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator())
scrollAnimator->contentsResized();
}
bool ScrollableArea::hasOverlayScrollbars() const {
Scrollbar* vScrollbar = verticalScrollbar();
if (vScrollbar && vScrollbar->isOverlayScrollbar())
return true;
Scrollbar* hScrollbar = horizontalScrollbar();
return hScrollbar && hScrollbar->isOverlayScrollbar();
}
void ScrollableArea::setScrollbarOverlayColorTheme(
ScrollbarOverlayColorTheme overlayTheme) {
m_scrollbarOverlayColorTheme = overlayTheme;
if (Scrollbar* scrollbar = horizontalScrollbar()) {
ScrollbarTheme::theme().updateScrollbarOverlayColorTheme(*scrollbar);
scrollbar->setNeedsPaintInvalidation(AllParts);
}
if (Scrollbar* scrollbar = verticalScrollbar()) {
ScrollbarTheme::theme().updateScrollbarOverlayColorTheme(*scrollbar);
scrollbar->setNeedsPaintInvalidation(AllParts);
}
}
void ScrollableArea::recalculateScrollbarOverlayColorTheme(
Color backgroundColor) {
ScrollbarOverlayColorTheme oldOverlayTheme = getScrollbarOverlayColorTheme();
ScrollbarOverlayColorTheme overlayTheme = ScrollbarOverlayColorThemeDark;
// Reduce the background color from RGB to a lightness value
// and determine which scrollbar style to use based on a lightness
// heuristic.
double hue, saturation, lightness;
backgroundColor.getHSL(hue, saturation, lightness);
if (lightness <= .5)
overlayTheme = ScrollbarOverlayColorThemeLight;
if (oldOverlayTheme != overlayTheme)
setScrollbarOverlayColorTheme(overlayTheme);
}
void ScrollableArea::setScrollbarNeedsPaintInvalidation(
ScrollbarOrientation orientation) {
if (orientation == HorizontalScrollbar) {
if (GraphicsLayer* graphicsLayer = layerForHorizontalScrollbar()) {
graphicsLayer->setNeedsDisplay();
graphicsLayer->setContentsNeedsDisplay();
}
m_horizontalScrollbarNeedsPaintInvalidation = true;
} else {
if (GraphicsLayer* graphicsLayer = layerForVerticalScrollbar()) {
graphicsLayer->setNeedsDisplay();
graphicsLayer->setContentsNeedsDisplay();
}
m_verticalScrollbarNeedsPaintInvalidation = true;
}
scrollControlWasSetNeedsPaintInvalidation();
}
void ScrollableArea::setScrollCornerNeedsPaintInvalidation() {
if (GraphicsLayer* graphicsLayer = layerForScrollCorner()) {
graphicsLayer->setNeedsDisplay();
return;
}
m_scrollCornerNeedsPaintInvalidation = true;
scrollControlWasSetNeedsPaintInvalidation();
}
bool ScrollableArea::hasLayerForHorizontalScrollbar() const {
return layerForHorizontalScrollbar();
}
bool ScrollableArea::hasLayerForVerticalScrollbar() const {
return layerForVerticalScrollbar();
}
bool ScrollableArea::hasLayerForScrollCorner() const {
return layerForScrollCorner();
}
void ScrollableArea::layerForScrollingDidChange(
CompositorAnimationTimeline* timeline) {
if (ProgrammaticScrollAnimator* programmaticScrollAnimator =
existingProgrammaticScrollAnimator())
programmaticScrollAnimator->layerForCompositedScrollingDidChange(timeline);
if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator())
scrollAnimator->layerForCompositedScrollingDidChange(timeline);
}
bool ScrollableArea::scheduleAnimation() {
if (HostWindow* window = getHostWindow()) {
window->scheduleAnimation(getWidget());
return true;
}
return false;
}
void ScrollableArea::serviceScrollAnimations(double monotonicTime) {
bool requiresAnimationService = false;
if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) {
scrollAnimator->tickAnimation(monotonicTime);
if (scrollAnimator->hasAnimationThatRequiresService())
requiresAnimationService = true;
}
if (ProgrammaticScrollAnimator* programmaticScrollAnimator =
existingProgrammaticScrollAnimator()) {
programmaticScrollAnimator->tickAnimation(monotonicTime);
if (programmaticScrollAnimator->hasAnimationThatRequiresService())
requiresAnimationService = true;
}
if (!requiresAnimationService)
deregisterForAnimation();
}
void ScrollableArea::updateCompositorScrollAnimations() {
if (ProgrammaticScrollAnimator* programmaticScrollAnimator =
existingProgrammaticScrollAnimator())
programmaticScrollAnimator->updateCompositorAnimations();
if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator())
scrollAnimator->updateCompositorAnimations();
}
void ScrollableArea::cancelScrollAnimation() {
if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator())
scrollAnimator->cancelAnimation();
}
void ScrollableArea::cancelProgrammaticScrollAnimation() {
if (ProgrammaticScrollAnimator* programmaticScrollAnimator =
existingProgrammaticScrollAnimator())
programmaticScrollAnimator->cancelAnimation();
}
bool ScrollableArea::shouldScrollOnMainThread() const {
if (GraphicsLayer* layer = layerForScrolling()) {
uint32_t reasons = layer->platformLayer()->mainThreadScrollingReasons();
// Should scroll on main thread unless the reason is the one that is set
// by the ScrollAnimator, in which case, the animation can still be
// scheduled on the compositor.
// TODO(ymalik): We have a non-transient "main thread scrolling reason"
// that doesn't actually cause shouldScrollOnMainThread() to be true.
// This is confusing and should be cleaned up.
return !!(reasons &
~MainThreadScrollingReason::kHandlingScrollFromMainThread);
}
return true;
}
bool ScrollableArea::scrollbarsHidden() const {
return hasOverlayScrollbars() && m_scrollbarsHidden;
}
void ScrollableArea::setScrollbarsHidden(bool hidden) {
if (m_scrollbarsHidden == static_cast<unsigned>(hidden))
return;
m_scrollbarsHidden = hidden;
scrollbarVisibilityChanged();
}
void ScrollableArea::fadeOverlayScrollbarsTimerFired(TimerBase*) {
setScrollbarsHidden(true);
}
void ScrollableArea::showOverlayScrollbars() {
if (!ScrollbarTheme::theme().usesOverlayScrollbars())
return;
setScrollbarsHidden(false);
const double timeUntilDisable =
ScrollbarTheme::theme().overlayScrollbarFadeOutDelaySeconds() +
ScrollbarTheme::theme().overlayScrollbarFadeOutDurationSeconds();
// If the overlay scrollbars don't fade out, don't do anything. This is the
// case for the mock overlays used in tests and on Mac, where the fade-out is
// animated in ScrollAnimatorMac.
if (!timeUntilDisable)
return;
if (!m_fadeOverlayScrollbarsTimer) {
m_fadeOverlayScrollbarsTimer.reset(new Timer<ScrollableArea>(
this, &ScrollableArea::fadeOverlayScrollbarsTimerFired));
}
if (!m_scrollbarCaptured && !m_mouseOverScrollbar) {
m_fadeOverlayScrollbarsTimer->startOneShot(timeUntilDisable,
BLINK_FROM_HERE);
}
}
IntRect ScrollableArea::visibleContentRect(
IncludeScrollbarsInRect scrollbarInclusion) const {
int scrollbarWidth =
scrollbarInclusion == IncludeScrollbars ? verticalScrollbarWidth() : 0;
int scrollbarHeight =
scrollbarInclusion == IncludeScrollbars ? horizontalScrollbarHeight() : 0;
return enclosingIntRect(
IntRect(getScrollOffset().width(), getScrollOffset().height(),
std::max(0, visibleWidth() + scrollbarWidth),
std::max(0, visibleHeight() + scrollbarHeight)));
}
IntSize ScrollableArea::clampScrollOffset(const IntSize& scrollOffset) const {
return scrollOffset.shrunkTo(maximumScrollOffsetInt())
.expandedTo(minimumScrollOffsetInt());
}
ScrollOffset ScrollableArea::clampScrollOffset(
const ScrollOffset& scrollOffset) const {
return scrollOffset.shrunkTo(maximumScrollOffset())
.expandedTo(minimumScrollOffset());
}
int ScrollableArea::lineStep(ScrollbarOrientation) const {
return pixelsPerLineStep(getHostWindow());
}
int ScrollableArea::pageStep(ScrollbarOrientation orientation) const {
IntRect visibleRect = visibleContentRect(IncludeScrollbars);
int length = (orientation == HorizontalScrollbar) ? visibleRect.width()
: visibleRect.height();
int minPageStep = static_cast<float>(length) * minFractionToStepWhenPaging();
int pageStep = std::max(minPageStep, length - maxOverlapBetweenPages());
return std::max(pageStep, 1);
}
int ScrollableArea::documentStep(ScrollbarOrientation orientation) const {
return scrollSize(orientation);
}
float ScrollableArea::pixelStep(ScrollbarOrientation) const {
return 1;
}
int ScrollableArea::verticalScrollbarWidth(
OverlayScrollbarClipBehavior behavior) const {
DCHECK_EQ(behavior, IgnoreOverlayScrollbarSize);
if (Scrollbar* verticalBar = verticalScrollbar())
return !verticalBar->isOverlayScrollbar() ? verticalBar->width() : 0;
return 0;
}
int ScrollableArea::horizontalScrollbarHeight(
OverlayScrollbarClipBehavior behavior) const {
DCHECK_EQ(behavior, IgnoreOverlayScrollbarSize);
if (Scrollbar* horizontalBar = horizontalScrollbar())
return !horizontalBar->isOverlayScrollbar() ? horizontalBar->height() : 0;
return 0;
}
FloatQuad ScrollableArea::localToVisibleContentQuad(const FloatQuad& quad,
const LayoutObject*,
unsigned) const {
FloatQuad result(quad);
result.move(-getScrollOffset());
return result;
}
IntSize ScrollableArea::excludeScrollbars(const IntSize& size) const {
return IntSize(std::max(0, size.width() - verticalScrollbarWidth()),
std::max(0, size.height() - horizontalScrollbarHeight()));
}
DEFINE_TRACE(ScrollableArea) {
visitor->trace(m_scrollAnimator);
visitor->trace(m_programmaticScrollAnimator);
}
} // namespace blink
|