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 |
47 int ScrollableArea::pixelsPerLineStep(HostWindow* host) { | 60 int ScrollableArea::pixelsPerLineStep(HostWindow* host) { |
48 if (!host) | 61 if (!host) |
49 return kPixelsPerLineStep; | 62 return kPixelsPerLineStep; |
50 return host->windowToViewportScalar(kPixelsPerLineStep); | 63 return host->windowToViewportScalar(kPixelsPerLineStep); |
51 } | 64 } |
52 | 65 |
53 float ScrollableArea::minFractionToStepWhenPaging() { | 66 float ScrollableArea::minFractionToStepWhenPaging() { |
54 return kMinFractionToStepWhenPaging; | 67 return kMinFractionToStepWhenPaging; |
55 } | 68 } |
56 | 69 |
57 int ScrollableArea::maxOverlapBetweenPages() { | 70 int ScrollableArea::maxOverlapBetweenPages() { |
58 static int maxOverlapBetweenPages = | 71 static int maxOverlapBetweenPages = |
59 ScrollbarTheme::theme().maxOverlapBetweenPages(); | 72 ScrollbarTheme::theme().maxOverlapBetweenPages(); |
60 return maxOverlapBetweenPages; | 73 return maxOverlapBetweenPages; |
61 } | 74 } |
62 | 75 |
63 ScrollableArea::ScrollableArea() | 76 ScrollableArea::ScrollableArea() |
64 : m_scrollbarOverlayColorTheme(ScrollbarOverlayColorThemeDark), | 77 : m_scrollbarOverlayColorTheme(ScrollbarOverlayColorThemeDark), |
65 m_scrollOriginChanged(false), | 78 m_scrollOriginChanged(false), |
66 m_horizontalScrollbarNeedsPaintInvalidation(false), | 79 m_horizontalScrollbarNeedsPaintInvalidation(false), |
67 m_verticalScrollbarNeedsPaintInvalidation(false), | 80 m_verticalScrollbarNeedsPaintInvalidation(false), |
68 m_scrollCornerNeedsPaintInvalidation(false), | 81 m_scrollCornerNeedsPaintInvalidation(false), |
69 m_scrollbarsHidden(false), | 82 m_scrollbarsHidden(false) {} |
70 m_scrollbarCaptured(false) {} | |
71 | 83 |
72 ScrollableArea::~ScrollableArea() {} | 84 ScrollableArea::~ScrollableArea() {} |
73 | 85 |
74 void ScrollableArea::clearScrollableArea() { | 86 void ScrollableArea::clearScrollAnimators() { |
75 #if OS(MACOSX) | 87 #if OS(MACOSX) |
76 if (m_scrollAnimator) | 88 if (m_scrollAnimator) |
77 m_scrollAnimator->dispose(); | 89 m_scrollAnimator->dispose(); |
78 #endif | 90 #endif |
79 m_scrollAnimator.clear(); | 91 m_scrollAnimator.clear(); |
80 m_programmaticScrollAnimator.clear(); | 92 m_programmaticScrollAnimator.clear(); |
81 if (m_fadeOverlayScrollbarsTimer) | |
82 m_fadeOverlayScrollbarsTimer->stop(); | |
83 } | 93 } |
84 | 94 |
85 ScrollAnimatorBase& ScrollableArea::scrollAnimator() const { | 95 ScrollAnimatorBase& ScrollableArea::scrollAnimator() const { |
86 if (!m_scrollAnimator) | 96 if (!m_scrollAnimator) |
87 m_scrollAnimator = | 97 m_scrollAnimator = |
88 ScrollAnimatorBase::create(const_cast<ScrollableArea*>(this)); | 98 ScrollAnimatorBase::create(const_cast<ScrollableArea*>(this)); |
89 | 99 |
90 return *m_scrollAnimator; | 100 return *m_scrollAnimator; |
91 } | 101 } |
92 | 102 |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 void ScrollableArea::mouseExitedContentArea() const { | 325 void ScrollableArea::mouseExitedContentArea() const { |
316 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) | 326 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) |
317 scrollAnimator->mouseEnteredContentArea(); | 327 scrollAnimator->mouseEnteredContentArea(); |
318 } | 328 } |
319 | 329 |
320 void ScrollableArea::mouseMovedInContentArea() const { | 330 void ScrollableArea::mouseMovedInContentArea() const { |
321 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) | 331 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) |
322 scrollAnimator->mouseMovedInContentArea(); | 332 scrollAnimator->mouseMovedInContentArea(); |
323 } | 333 } |
324 | 334 |
325 void ScrollableArea::mouseEnteredScrollbar(Scrollbar& scrollbar) { | 335 void ScrollableArea::mouseEnteredScrollbar(Scrollbar& scrollbar) const { |
326 scrollAnimator().mouseEnteredScrollbar(scrollbar); | 336 scrollAnimator().mouseEnteredScrollbar(scrollbar); |
327 // Restart the fade out timer. | |
328 showOverlayScrollbars(); | |
329 } | 337 } |
330 | 338 |
331 void ScrollableArea::mouseExitedScrollbar(Scrollbar& scrollbar) { | 339 void ScrollableArea::mouseExitedScrollbar(Scrollbar& scrollbar) const { |
332 scrollAnimator().mouseExitedScrollbar(scrollbar); | 340 scrollAnimator().mouseExitedScrollbar(scrollbar); |
333 } | 341 } |
334 | 342 |
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 | |
348 void ScrollableArea::contentAreaDidShow() const { | 343 void ScrollableArea::contentAreaDidShow() const { |
349 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) | 344 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) |
350 scrollAnimator->contentAreaDidShow(); | 345 scrollAnimator->contentAreaDidShow(); |
351 } | 346 } |
352 | 347 |
353 void ScrollableArea::contentAreaDidHide() const { | 348 void ScrollableArea::contentAreaDidHide() const { |
354 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) | 349 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) |
355 scrollAnimator->contentAreaDidHide(); | 350 scrollAnimator->contentAreaDidHide(); |
356 } | 351 } |
357 | 352 |
(...skipping 18 matching lines...) Expand all Loading... |
376 ScrollbarOrientation orientation) { | 371 ScrollbarOrientation orientation) { |
377 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) { | 372 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) { |
378 if (orientation == VerticalScrollbar) | 373 if (orientation == VerticalScrollbar) |
379 scrollAnimator->willRemoveVerticalScrollbar(scrollbar); | 374 scrollAnimator->willRemoveVerticalScrollbar(scrollbar); |
380 else | 375 else |
381 scrollAnimator->willRemoveHorizontalScrollbar(scrollbar); | 376 scrollAnimator->willRemoveHorizontalScrollbar(scrollbar); |
382 } | 377 } |
383 } | 378 } |
384 | 379 |
385 void ScrollableArea::contentsResized() { | 380 void ScrollableArea::contentsResized() { |
386 showOverlayScrollbars(); | |
387 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) | 381 if (ScrollAnimatorBase* scrollAnimator = existingScrollAnimator()) |
388 scrollAnimator->contentsResized(); | 382 scrollAnimator->contentsResized(); |
389 } | 383 } |
390 | 384 |
391 bool ScrollableArea::hasOverlayScrollbars() const { | 385 bool ScrollableArea::hasOverlayScrollbars() const { |
392 Scrollbar* vScrollbar = verticalScrollbar(); | 386 Scrollbar* vScrollbar = verticalScrollbar(); |
393 if (vScrollbar && vScrollbar->isOverlayScrollbar()) | 387 if (vScrollbar && vScrollbar->isOverlayScrollbar()) |
394 return true; | 388 return true; |
395 Scrollbar* hScrollbar = horizontalScrollbar(); | 389 Scrollbar* hScrollbar = horizontalScrollbar(); |
396 return hScrollbar && hScrollbar->isOverlayScrollbar(); | 390 return hScrollbar && hScrollbar->isOverlayScrollbar(); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 return true; | 531 return true; |
538 } | 532 } |
539 | 533 |
540 bool ScrollableArea::scrollbarsHidden() const { | 534 bool ScrollableArea::scrollbarsHidden() const { |
541 return hasOverlayScrollbars() && m_scrollbarsHidden; | 535 return hasOverlayScrollbars() && m_scrollbarsHidden; |
542 } | 536 } |
543 | 537 |
544 void ScrollableArea::setScrollbarsHidden(bool hidden) { | 538 void ScrollableArea::setScrollbarsHidden(bool hidden) { |
545 if (m_scrollbarsHidden == static_cast<unsigned>(hidden)) | 539 if (m_scrollbarsHidden == static_cast<unsigned>(hidden)) |
546 return; | 540 return; |
547 | |
548 m_scrollbarsHidden = hidden; | 541 m_scrollbarsHidden = hidden; |
549 scrollbarVisibilityChanged(); | 542 didChangeScrollbarsHidden(); |
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 } | |
581 } | 543 } |
582 | 544 |
583 IntRect ScrollableArea::visibleContentRect( | 545 IntRect ScrollableArea::visibleContentRect( |
584 IncludeScrollbarsInRect scrollbarInclusion) const { | 546 IncludeScrollbarsInRect scrollbarInclusion) const { |
585 int scrollbarWidth = | 547 int scrollbarWidth = |
586 scrollbarInclusion == IncludeScrollbars ? verticalScrollbarWidth() : 0; | 548 scrollbarInclusion == IncludeScrollbars ? verticalScrollbarWidth() : 0; |
587 int scrollbarHeight = | 549 int scrollbarHeight = |
588 scrollbarInclusion == IncludeScrollbars ? horizontalScrollbarHeight() : 0; | 550 scrollbarInclusion == IncludeScrollbars ? horizontalScrollbarHeight() : 0; |
589 | 551 |
590 return enclosingIntRect( | 552 return enclosingIntRect( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 return IntSize(std::max(0, size.width() - verticalScrollbarWidth()), | 604 return IntSize(std::max(0, size.width() - verticalScrollbarWidth()), |
643 std::max(0, size.height() - horizontalScrollbarHeight())); | 605 std::max(0, size.height() - horizontalScrollbarHeight())); |
644 } | 606 } |
645 | 607 |
646 DEFINE_TRACE(ScrollableArea) { | 608 DEFINE_TRACE(ScrollableArea) { |
647 visitor->trace(m_scrollAnimator); | 609 visitor->trace(m_scrollAnimator); |
648 visitor->trace(m_programmaticScrollAnimator); | 610 visitor->trace(m_programmaticScrollAnimator); |
649 } | 611 } |
650 | 612 |
651 } // namespace blink | 613 } // namespace blink |
OLD | NEW |