| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010, 2011 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 19 matching lines...) Expand all Loading... |
| 30 #include "platform/Timer.h" | 30 #include "platform/Timer.h" |
| 31 #include "platform/animation/TimingFunction.h" | 31 #include "platform/animation/TimingFunction.h" |
| 32 #include "platform/geometry/FloatRect.h" | 32 #include "platform/geometry/FloatRect.h" |
| 33 #include "platform/geometry/IntRect.h" | 33 #include "platform/geometry/IntRect.h" |
| 34 #include "platform/mac/BlockExceptions.h" | 34 #include "platform/mac/BlockExceptions.h" |
| 35 #include "platform/mac/NSScrollerImpDetails.h" | 35 #include "platform/mac/NSScrollerImpDetails.h" |
| 36 #include "platform/scroll/ScrollableArea.h" | 36 #include "platform/scroll/ScrollableArea.h" |
| 37 #include "platform/scroll/ScrollbarTheme.h" | 37 #include "platform/scroll/ScrollbarTheme.h" |
| 38 #include "platform/scroll/ScrollbarThemeMacCommon.h" | 38 #include "platform/scroll/ScrollbarThemeMacCommon.h" |
| 39 #include "platform/scroll/ScrollbarThemeMacOverlayAPI.h" | 39 #include "platform/scroll/ScrollbarThemeMacOverlayAPI.h" |
| 40 #include "public/platform/Platform.h" |
| 41 #include "public/platform/WebScheduler.h" |
| 40 #include "wtf/MainThread.h" | 42 #include "wtf/MainThread.h" |
| 41 #include "wtf/MathExtras.h" | 43 #include "wtf/MathExtras.h" |
| 42 #include "wtf/PassOwnPtr.h" | 44 #include "wtf/PassOwnPtr.h" |
| 43 | 45 |
| 44 using namespace blink; | 46 using namespace blink; |
| 45 | 47 |
| 46 static bool supportsUIStateTransitionProgress() | 48 static bool supportsUIStateTransitionProgress() |
| 47 { | 49 { |
| 48 // FIXME: This is temporary until all platforms that support ScrollbarPainte
r support this part of the API. | 50 // FIXME: This is temporary until all platforms that support ScrollbarPainte
r support this part of the API. |
| 49 static bool globalSupportsUIStateTransitionProgress = [NSClassFromString(@"N
SScrollerImp") instancesRespondToSelector:@selector(mouseEnteredScroller)]; | 51 static bool globalSupportsUIStateTransitionProgress = [NSClassFromString(@"N
SScrollerImp") instancesRespondToSelector:@selector(mouseEnteredScroller)]; |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 | 679 |
| 678 namespace blink { | 680 namespace blink { |
| 679 | 681 |
| 680 PassOwnPtrWillBeRawPtr<ScrollAnimatorBase> ScrollAnimatorBase::create(Scrollable
Area* scrollableArea) | 682 PassOwnPtrWillBeRawPtr<ScrollAnimatorBase> ScrollAnimatorBase::create(Scrollable
Area* scrollableArea) |
| 681 { | 683 { |
| 682 return adoptPtrWillBeNoop(new ScrollAnimatorMac(scrollableArea)); | 684 return adoptPtrWillBeNoop(new ScrollAnimatorMac(scrollableArea)); |
| 683 } | 685 } |
| 684 | 686 |
| 685 ScrollAnimatorMac::ScrollAnimatorMac(ScrollableArea* scrollableArea) | 687 ScrollAnimatorMac::ScrollAnimatorMac(ScrollableArea* scrollableArea) |
| 686 : ScrollAnimatorBase(scrollableArea) | 688 : ScrollAnimatorBase(scrollableArea) |
| 687 , m_initialScrollbarPaintTimer(this, &ScrollAnimatorMac::initialScrollbarPai
ntTimerFired) | 689 , m_initialScrollbarPaintTaskFactory(CancellableTaskFactory::create(this, &S
crollAnimatorMac::initialScrollbarPaintTask)) |
| 688 , m_sendContentAreaScrolledTimer(this, &ScrollAnimatorMac::sendContentAreaSc
rolledTimerFired) | 690 , m_sendContentAreaScrolledTaskFactory(CancellableTaskFactory::create(this,
&ScrollAnimatorMac::sendContentAreaScrolledTask)) |
| 691 , m_taskRunner(adoptPtr(Platform::current()->currentThread()->scheduler()->t
imerTaskRunner()->clone())) |
| 689 , m_haveScrolledSincePageLoad(false) | 692 , m_haveScrolledSincePageLoad(false) |
| 690 , m_needsScrollerStyleUpdate(false) | 693 , m_needsScrollerStyleUpdate(false) |
| 691 { | 694 { |
| 692 #if ENABLE(OILPAN) | 695 #if ENABLE(OILPAN) |
| 693 ThreadState::current()->registerPreFinalizer(this); | 696 ThreadState::current()->registerPreFinalizer(this); |
| 694 #endif | 697 #endif |
| 695 | 698 |
| 696 m_scrollAnimationHelperDelegate.adoptNS([[BlinkScrollAnimationHelperDelegate
alloc] initWithScrollAnimator:this]); | 699 m_scrollAnimationHelperDelegate.adoptNS([[BlinkScrollAnimationHelperDelegate
alloc] initWithScrollAnimator:this]); |
| 697 m_scrollAnimationHelper.adoptNS([[NSClassFromString(@"NSScrollAnimationHelpe
r") alloc] initWithDelegate:m_scrollAnimationHelperDelegate.get()]); | 700 m_scrollAnimationHelper.adoptNS([[NSClassFromString(@"NSScrollAnimationHelpe
r") alloc] initWithDelegate:m_scrollAnimationHelperDelegate.get()]); |
| 698 | 701 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 715 { | 718 { |
| 716 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) { | 719 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) { |
| 717 BEGIN_BLOCK_OBJC_EXCEPTIONS; | 720 BEGIN_BLOCK_OBJC_EXCEPTIONS; |
| 718 [m_scrollbarPainterControllerDelegate.get() invalidate]; | 721 [m_scrollbarPainterControllerDelegate.get() invalidate]; |
| 719 [m_scrollbarPainterController.get() setDelegate:nil]; | 722 [m_scrollbarPainterController.get() setDelegate:nil]; |
| 720 [m_horizontalScrollbarPainterDelegate.get() invalidate]; | 723 [m_horizontalScrollbarPainterDelegate.get() invalidate]; |
| 721 [m_verticalScrollbarPainterDelegate.get() invalidate]; | 724 [m_verticalScrollbarPainterDelegate.get() invalidate]; |
| 722 [m_scrollAnimationHelperDelegate.get() invalidate]; | 725 [m_scrollAnimationHelperDelegate.get() invalidate]; |
| 723 END_BLOCK_OBJC_EXCEPTIONS; | 726 END_BLOCK_OBJC_EXCEPTIONS; |
| 724 } | 727 } |
| 725 m_initialScrollbarPaintTimer.stop(); | 728 m_initialScrollbarPaintTaskFactory->cancel(); |
| 726 m_sendContentAreaScrolledTimer.stop(); | 729 m_sendContentAreaScrolledTaskFactory->cancel(); |
| 727 } | 730 } |
| 728 | 731 |
| 729 ScrollResultOneDimensional ScrollAnimatorMac::userScroll(ScrollbarOrientation or
ientation, ScrollGranularity granularity, float step, float delta) | 732 ScrollResultOneDimensional ScrollAnimatorMac::userScroll(ScrollbarOrientation or
ientation, ScrollGranularity granularity, float step, float delta) |
| 730 { | 733 { |
| 731 m_haveScrolledSincePageLoad = true; | 734 m_haveScrolledSincePageLoad = true; |
| 732 | 735 |
| 733 if (!m_scrollableArea->scrollAnimatorEnabled()) | 736 if (!m_scrollableArea->scrollAnimatorEnabled()) |
| 734 return ScrollAnimatorBase::userScroll(orientation, granularity, step, de
lta); | 737 return ScrollAnimatorBase::userScroll(orientation, granularity, step, de
lta); |
| 735 | 738 |
| 736 if (granularity == ScrollByPixel || granularity == ScrollByPrecisePixel) | 739 if (granularity == ScrollByPixel || granularity == ScrollByPrecisePixel) |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 // If m_needsScrollerStyleUpdate is true, then the page is restoring from th
e page cache, and | 1124 // If m_needsScrollerStyleUpdate is true, then the page is restoring from th
e page cache, and |
| 1122 // a relayout will happen on its own. Otherwise, we must initiate a re-layou
t ourselves. | 1125 // a relayout will happen on its own. Otherwise, we must initiate a re-layou
t ourselves. |
| 1123 if (!m_needsScrollerStyleUpdate) | 1126 if (!m_needsScrollerStyleUpdate) |
| 1124 scrollableArea()->scrollbarStyleChanged(); | 1127 scrollableArea()->scrollbarStyleChanged(); |
| 1125 | 1128 |
| 1126 m_needsScrollerStyleUpdate = false; | 1129 m_needsScrollerStyleUpdate = false; |
| 1127 } | 1130 } |
| 1128 | 1131 |
| 1129 void ScrollAnimatorMac::startScrollbarPaintTimer() | 1132 void ScrollAnimatorMac::startScrollbarPaintTimer() |
| 1130 { | 1133 { |
| 1131 m_initialScrollbarPaintTimer.startOneShot(0.1, BLINK_FROM_HERE); | 1134 m_taskRunner->postDelayedTask(BLINK_FROM_HERE, m_initialScrollbarPaintTaskFa
ctory->cancelAndCreate(), 0.1); |
| 1132 } | 1135 } |
| 1133 | 1136 |
| 1134 bool ScrollAnimatorMac::scrollbarPaintTimerIsActive() const | 1137 bool ScrollAnimatorMac::scrollbarPaintTimerIsActive() const |
| 1135 { | 1138 { |
| 1136 return m_initialScrollbarPaintTimer.isActive(); | 1139 return m_initialScrollbarPaintTaskFactory->isPending(); |
| 1137 } | 1140 } |
| 1138 | 1141 |
| 1139 void ScrollAnimatorMac::stopScrollbarPaintTimer() | 1142 void ScrollAnimatorMac::stopScrollbarPaintTimer() |
| 1140 { | 1143 { |
| 1141 m_initialScrollbarPaintTimer.stop(); | 1144 m_initialScrollbarPaintTaskFactory->cancel(); |
| 1142 } | 1145 } |
| 1143 | 1146 |
| 1144 void ScrollAnimatorMac::initialScrollbarPaintTimerFired(Timer<ScrollAnimatorMac>
*) | 1147 void ScrollAnimatorMac::initialScrollbarPaintTask() |
| 1145 { | 1148 { |
| 1146 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) { | 1149 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) { |
| 1147 // To force the scrollbars to flash, we have to call hide first. Otherwi
se, the ScrollbarPainterController | 1150 // To force the scrollbars to flash, we have to call hide first. Otherwi
se, the ScrollbarPainterController |
| 1148 // might think that the scrollbars are already showing and bail early. | 1151 // might think that the scrollbars are already showing and bail early. |
| 1149 [m_scrollbarPainterController.get() hideOverlayScrollers]; | 1152 [m_scrollbarPainterController.get() hideOverlayScrollers]; |
| 1150 [m_scrollbarPainterController.get() flashScrollers]; | 1153 [m_scrollbarPainterController.get() flashScrollers]; |
| 1151 } | 1154 } |
| 1152 } | 1155 } |
| 1153 | 1156 |
| 1154 void ScrollAnimatorMac::sendContentAreaScrolledSoon(const FloatSize& delta) | 1157 void ScrollAnimatorMac::sendContentAreaScrolledSoon(const FloatSize& delta) |
| 1155 { | 1158 { |
| 1156 m_contentAreaScrolledTimerScrollDelta = delta; | 1159 m_contentAreaScrolledTimerScrollDelta = delta; |
| 1157 | 1160 |
| 1158 if (!m_sendContentAreaScrolledTimer.isActive()) | 1161 if (!m_sendContentAreaScrolledTaskFactory->isPending()) |
| 1159 m_sendContentAreaScrolledTimer.startOneShot(0, BLINK_FROM_HERE); | 1162 m_taskRunner->postTask(BLINK_FROM_HERE, m_sendContentAreaScrolledTaskFac
tory->cancelAndCreate()); |
| 1160 } | 1163 } |
| 1161 | 1164 |
| 1162 void ScrollAnimatorMac::sendContentAreaScrolledTimerFired(Timer<ScrollAnimatorMa
c>*) | 1165 void ScrollAnimatorMac::sendContentAreaScrolledTask() |
| 1163 { | 1166 { |
| 1164 if (supportsContentAreaScrolledInDirection()) { | 1167 if (supportsContentAreaScrolledInDirection()) { |
| 1165 [m_scrollbarPainterController.get() contentAreaScrolledInDirection:NSMak
ePoint(m_contentAreaScrolledTimerScrollDelta.width(), m_contentAreaScrolledTimer
ScrollDelta.height())]; | 1168 [m_scrollbarPainterController.get() contentAreaScrolledInDirection:NSMak
ePoint(m_contentAreaScrolledTimerScrollDelta.width(), m_contentAreaScrolledTimer
ScrollDelta.height())]; |
| 1166 m_contentAreaScrolledTimerScrollDelta = FloatSize(); | 1169 m_contentAreaScrolledTimerScrollDelta = FloatSize(); |
| 1167 } else | 1170 } else |
| 1168 [m_scrollbarPainterController.get() contentAreaScrolled]; | 1171 [m_scrollbarPainterController.get() contentAreaScrolled]; |
| 1169 } | 1172 } |
| 1170 | 1173 |
| 1171 void ScrollAnimatorMac::setVisibleScrollerThumbRect(const IntRect& scrollerThumb
) | 1174 void ScrollAnimatorMac::setVisibleScrollerThumbRect(const IntRect& scrollerThumb
) |
| 1172 { | 1175 { |
| 1173 IntRect rectInViewCoordinates = scrollerThumb; | 1176 IntRect rectInViewCoordinates = scrollerThumb; |
| 1174 if (Scrollbar* verticalScrollbar = m_scrollableArea->verticalScrollbar()) | 1177 if (Scrollbar* verticalScrollbar = m_scrollableArea->verticalScrollbar()) |
| 1175 rectInViewCoordinates = verticalScrollbar->convertToContainingWidget(scr
ollerThumb); | 1178 rectInViewCoordinates = verticalScrollbar->convertToContainingWidget(scr
ollerThumb); |
| 1176 | 1179 |
| 1177 if (rectInViewCoordinates == m_visibleScrollerThumbRect) | 1180 if (rectInViewCoordinates == m_visibleScrollerThumbRect) |
| 1178 return; | 1181 return; |
| 1179 | 1182 |
| 1180 m_visibleScrollerThumbRect = rectInViewCoordinates; | 1183 m_visibleScrollerThumbRect = rectInViewCoordinates; |
| 1181 } | 1184 } |
| 1182 | 1185 |
| 1183 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() { | 1186 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() { |
| 1184 return ScrollbarThemeMacCommon::isOverlayAPIAvailable(); | 1187 return ScrollbarThemeMacCommon::isOverlayAPIAvailable(); |
| 1185 } | 1188 } |
| 1186 | 1189 |
| 1187 } // namespace blink | 1190 } // namespace blink |
| OLD | NEW |