OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google Inc. All rights reserved. |
3 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved. | 3 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "platform/scroll/ProgrammaticScrollAnimator.h" | 37 #include "platform/scroll/ProgrammaticScrollAnimator.h" |
38 #include "platform/scroll/ScrollbarTheme.h" | 38 #include "platform/scroll/ScrollbarTheme.h" |
39 | 39 |
40 #include "platform/tracing/TraceEvent.h" | 40 #include "platform/tracing/TraceEvent.h" |
41 | 41 |
42 static const int kPixelsPerLineStep = 40; | 42 static const int kPixelsPerLineStep = 40; |
43 static const float kMinFractionToStepWhenPaging = 0.875f; | 43 static const float kMinFractionToStepWhenPaging = 0.875f; |
44 | 44 |
45 namespace blink { | 45 namespace blink { |
46 | 46 |
47 struct SameSizeAsScrollableArea { | |
48 virtual ~SameSizeAsScrollableArea(); | |
49 #if ENABLE(ASSERT) | |
50 VerifyEagerFinalization verifyEager; | |
51 #endif | |
52 Member<void*> pointer[2]; | |
53 unsigned bitfields : 17; | |
54 IntPoint origin; | |
55 }; | |
56 | |
57 static_assert(sizeof(ScrollableArea) == sizeof(SameSizeAsScrollableArea), | |
58 "ScrollableArea should stay small"); | |
59 | |
60 int ScrollableArea::pixelsPerLineStep(HostWindow* host) { | 47 int ScrollableArea::pixelsPerLineStep(HostWindow* host) { |
61 if (!host) | 48 if (!host) |
62 return kPixelsPerLineStep; | 49 return kPixelsPerLineStep; |
63 return host->windowToViewportScalar(kPixelsPerLineStep); | 50 return host->windowToViewportScalar(kPixelsPerLineStep); |
64 } | 51 } |
65 | 52 |
66 float ScrollableArea::minFractionToStepWhenPaging() { | 53 float ScrollableArea::minFractionToStepWhenPaging() { |
67 return kMinFractionToStepWhenPaging; | 54 return kMinFractionToStepWhenPaging; |
68 } | 55 } |
69 | 56 |
70 int ScrollableArea::maxOverlapBetweenPages() { | 57 int ScrollableArea::maxOverlapBetweenPages() { |
71 static int maxOverlapBetweenPages = | 58 static int maxOverlapBetweenPages = |
72 ScrollbarTheme::theme().maxOverlapBetweenPages(); | 59 ScrollbarTheme::theme().maxOverlapBetweenPages(); |
73 return maxOverlapBetweenPages; | 60 return maxOverlapBetweenPages; |
74 } | 61 } |
75 | 62 |
76 ScrollableArea::ScrollableArea() | 63 ScrollableArea::ScrollableArea() |
77 : m_scrollbarOverlayColorTheme(ScrollbarOverlayColorThemeDark), | 64 : m_scrollbarOverlayColorTheme(ScrollbarOverlayColorThemeDark), |
78 m_scrollOriginChanged(false), | 65 m_scrollOriginChanged(false), |
79 m_horizontalScrollbarNeedsPaintInvalidation(false), | 66 m_horizontalScrollbarNeedsPaintInvalidation(false), |
80 m_verticalScrollbarNeedsPaintInvalidation(false), | 67 m_verticalScrollbarNeedsPaintInvalidation(false), |
81 m_scrollCornerNeedsPaintInvalidation(false), | 68 m_scrollCornerNeedsPaintInvalidation(false), |
82 m_scrollbarsHidden(false) {} | 69 m_scrollbarsHidden(false), |
| 70 m_scrollbarCaptured(false) {} |
83 | 71 |
84 ScrollableArea::~ScrollableArea() {} | 72 ScrollableArea::~ScrollableArea() {} |
85 | 73 |
86 void ScrollableArea::clearScrollAnimators() { | 74 void ScrollableArea::clearScrollableArea() { |
87 #if OS(MACOSX) | 75 #if OS(MACOSX) |
88 if (m_scrollAnimator) | 76 if (m_scrollAnimator) |
89 m_scrollAnimator->dispose(); | 77 m_scrollAnimator->dispose(); |
90 #endif | 78 #endif |
91 m_scrollAnimator.clear(); | 79 m_scrollAnimator.clear(); |
92 m_programmaticScrollAnimator.clear(); | 80 m_programmaticScrollAnimator.clear(); |
| 81 if (m_fadeOverlayScrollbarsTimer) |
| 82 m_fadeOverlayScrollbarsTimer->stop(); |
93 } | 83 } |
94 | 84 |
95 ScrollAnimatorBase& ScrollableArea::scrollAnimator() const { | 85 ScrollAnimatorBase& ScrollableArea::scrollAnimator() const { |
96 if (!m_scrollAnimator) | 86 if (!m_scrollAnimator) |
97 m_scrollAnimator = | 87 m_scrollAnimator = |
98 ScrollAnimatorBase::create(const_cast<ScrollableArea*>(this)); | 88 ScrollAnimatorBase::create(const_cast<ScrollableArea*>(this)); |
99 | 89 |
100 return *m_scrollAnimator; | 90 return *m_scrollAnimator; |
101 } | 91 } |
102 | 92 |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 void ScrollableArea::mouseExitedContentArea() const { | 315 void ScrollableArea::mouseExitedContentArea() const { |
326 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) | 316 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) |
327 scrollAnimator->mouseEnteredContentArea(); | 317 scrollAnimator->mouseEnteredContentArea(); |
328 } | 318 } |
329 | 319 |
330 void ScrollableArea::mouseMovedInContentArea() const { | 320 void ScrollableArea::mouseMovedInContentArea() const { |
331 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) | 321 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) |
332 scrollAnimator->mouseMovedInContentArea(); | 322 scrollAnimator->mouseMovedInContentArea(); |
333 } | 323 } |
334 | 324 |
335 void ScrollableArea::mouseEnteredScrollbar(Scrollbar& scrollbar) const { | 325 void ScrollableArea::mouseEnteredScrollbar(Scrollbar& scrollbar) { |
336 scrollAnimator().mouseEnteredScrollbar(scrollbar); | 326 scrollAnimator().mouseEnteredScrollbar(scrollbar); |
| 327 // Restart the fade out timer. |
| 328 showOverlayScrollbars(); |
337 } | 329 } |
338 | 330 |
339 void ScrollableArea::mouseExitedScrollbar(Scrollbar& scrollbar) const { | 331 void ScrollableArea::mouseExitedScrollbar(Scrollbar& scrollbar) { |
340 scrollAnimator().mouseExitedScrollbar(scrollbar); | 332 scrollAnimator().mouseExitedScrollbar(scrollbar); |
341 } | 333 } |
342 | 334 |
| 335 void ScrollableArea::mouseCapturedScrollbar() { |
| 336 m_scrollbarCaptured = true; |
| 337 showOverlayScrollbars(); |
| 338 if (m_fadeOverlayScrollbarsTimer) |
| 339 m_fadeOverlayScrollbarsTimer->stop(); |
| 340 } |
| 341 |
| 342 void ScrollableArea::mouseReleasedScrollbar() { |
| 343 m_scrollbarCaptured = false; |
| 344 // This will kick off the fade out timer. |
| 345 showOverlayScrollbars(); |
| 346 } |
| 347 |
343 void ScrollableArea::contentAreaDidShow() const { | 348 void ScrollableArea::contentAreaDidShow() const { |
344 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) | 349 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) |
345 scrollAnimator->contentAreaDidShow(); | 350 scrollAnimator->contentAreaDidShow(); |
346 } | 351 } |
347 | 352 |
348 void ScrollableArea::contentAreaDidHide() const { | 353 void ScrollableArea::contentAreaDidHide() const { |
349 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) | 354 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) |
350 scrollAnimator->contentAreaDidHide(); | 355 scrollAnimator->contentAreaDidHide(); |
351 } | 356 } |
352 | 357 |
(...skipping 18 matching lines...) Expand all Loading... |
371 ScrollbarOrientation orientation) { | 376 ScrollbarOrientation orientation) { |
372 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) { | 377 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) { |
373 if (orientation == VerticalScrollbar) | 378 if (orientation == VerticalScrollbar) |
374 scrollAnimator->willRemoveVerticalScrollbar(scrollbar); | 379 scrollAnimator->willRemoveVerticalScrollbar(scrollbar); |
375 else | 380 else |
376 scrollAnimator->willRemoveHorizontalScrollbar(scrollbar); | 381 scrollAnimator->willRemoveHorizontalScrollbar(scrollbar); |
377 } | 382 } |
378 } | 383 } |
379 | 384 |
380 void ScrollableArea::contentsResized() { | 385 void ScrollableArea::contentsResized() { |
| 386 showOverlayScrollbars(); |
381 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) | 387 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) |
382 scrollAnimator->contentsResized(); | 388 scrollAnimator->contentsResized(); |
383 } | 389 } |
384 | 390 |
385 bool ScrollableArea::hasOverlayScrollbars() const { | 391 bool ScrollableArea::hasOverlayScrollbars() const { |
386 Scrollbar* vScrollbar = verticalScrollbar(); | 392 Scrollbar* vScrollbar = verticalScrollbar(); |
387 if (vScrollbar && vScrollbar->isOverlayScrollbar()) | 393 if (vScrollbar && vScrollbar->isOverlayScrollbar()) |
388 return true; | 394 return true; |
389 Scrollbar* hScrollbar = horizontalScrollbar(); | 395 Scrollbar* hScrollbar = horizontalScrollbar(); |
390 return hScrollbar && hScrollbar->isOverlayScrollbar(); | 396 return hScrollbar && hScrollbar->isOverlayScrollbar(); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 return true; | 537 return true; |
532 } | 538 } |
533 | 539 |
534 bool ScrollableArea::scrollbarsHidden() const { | 540 bool ScrollableArea::scrollbarsHidden() const { |
535 return hasOverlayScrollbars() && m_scrollbarsHidden; | 541 return hasOverlayScrollbars() && m_scrollbarsHidden; |
536 } | 542 } |
537 | 543 |
538 void ScrollableArea::setScrollbarsHidden(bool hidden) { | 544 void ScrollableArea::setScrollbarsHidden(bool hidden) { |
539 if (m_scrollbarsHidden == static_cast<unsigned>(hidden)) | 545 if (m_scrollbarsHidden == static_cast<unsigned>(hidden)) |
540 return; | 546 return; |
| 547 |
541 m_scrollbarsHidden = hidden; | 548 m_scrollbarsHidden = hidden; |
542 didChangeScrollbarsHidden(); | 549 scrollbarVisibilityChanged(); |
| 550 } |
| 551 |
| 552 void ScrollableArea::fadeOverlayScrollbarsTimerFired(TimerBase*) { |
| 553 setScrollbarsHidden(true); |
| 554 } |
| 555 |
| 556 void ScrollableArea::showOverlayScrollbars() { |
| 557 if (!ScrollbarTheme::theme().usesOverlayScrollbars()) |
| 558 return; |
| 559 |
| 560 setScrollbarsHidden(false); |
| 561 |
| 562 const double timeUntilDisable = |
| 563 ScrollbarTheme::theme().overlayScrollbarFadeOutDelaySeconds() + |
| 564 ScrollbarTheme::theme().overlayScrollbarFadeOutDurationSeconds(); |
| 565 |
| 566 // If the overlay scrollbars don't fade out, don't do anything. This is the |
| 567 // case for the mock overlays used in tests and on Mac, where the fade-out is |
| 568 // animated in ScrollAnimatorMac. |
| 569 if (!timeUntilDisable) |
| 570 return; |
| 571 |
| 572 if (!m_fadeOverlayScrollbarsTimer) { |
| 573 m_fadeOverlayScrollbarsTimer.reset(new Timer<ScrollableArea>( |
| 574 this, &ScrollableArea::fadeOverlayScrollbarsTimerFired)); |
| 575 } |
| 576 |
| 577 if (!m_scrollbarCaptured) { |
| 578 m_fadeOverlayScrollbarsTimer->startOneShot(timeUntilDisable, |
| 579 BLINK_FROM_HERE); |
| 580 } |
543 } | 581 } |
544 | 582 |
545 IntRect ScrollableArea::visibleContentRect( | 583 IntRect ScrollableArea::visibleContentRect( |
546 IncludeScrollbarsInRect scrollbarInclusion) const { | 584 IncludeScrollbarsInRect scrollbarInclusion) const { |
547 int scrollbarWidth = | 585 int scrollbarWidth = |
548 scrollbarInclusion == IncludeScrollbars ? verticalScrollbarWidth() : 0; | 586 scrollbarInclusion == IncludeScrollbars ? verticalScrollbarWidth() : 0; |
549 int scrollbarHeight = | 587 int scrollbarHeight = |
550 scrollbarInclusion == IncludeScrollbars ? horizontalScrollbarHeight() : 0; | 588 scrollbarInclusion == IncludeScrollbars ? horizontalScrollbarHeight() : 0; |
551 | 589 |
552 return enclosingIntRect( | 590 return enclosingIntRect( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 return IntSize(std::max(0, size.width() - verticalScrollbarWidth()), | 642 return IntSize(std::max(0, size.width() - verticalScrollbarWidth()), |
605 std::max(0, size.height() - horizontalScrollbarHeight())); | 643 std::max(0, size.height() - horizontalScrollbarHeight())); |
606 } | 644 } |
607 | 645 |
608 DEFINE_TRACE(ScrollableArea) { | 646 DEFINE_TRACE(ScrollableArea) { |
609 visitor->trace(m_scrollAnimator); | 647 visitor->trace(m_scrollAnimator); |
610 visitor->trace(m_programmaticScrollAnimator); | 648 visitor->trace(m_programmaticScrollAnimator); |
611 } | 649 } |
612 | 650 |
613 } // namespace blink | 651 } // namespace blink |
OLD | NEW |