Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef ScrollbarActivity_h___ |
michael@0 | 7 | #define ScrollbarActivity_h___ |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/Attributes.h" |
michael@0 | 10 | #include "nsCOMPtr.h" |
michael@0 | 11 | #include "nsIDOMEventListener.h" |
michael@0 | 12 | #include "mozilla/TimeStamp.h" |
michael@0 | 13 | #include "nsRefreshDriver.h" |
michael@0 | 14 | |
michael@0 | 15 | class nsIContent; |
michael@0 | 16 | class nsIScrollbarOwner; |
michael@0 | 17 | class nsITimer; |
michael@0 | 18 | class nsIAtom; |
michael@0 | 19 | |
michael@0 | 20 | namespace mozilla { |
michael@0 | 21 | namespace layout { |
michael@0 | 22 | |
michael@0 | 23 | /** |
michael@0 | 24 | * ScrollbarActivity |
michael@0 | 25 | * |
michael@0 | 26 | * This class manages scrollbar behavior that imitates the native Mac OS X |
michael@0 | 27 | * Lion overlay scrollbar behavior: Scrollbars are only shown while "scrollbar |
michael@0 | 28 | * activity" occurs, and they're hidden with a fade animation after a short |
michael@0 | 29 | * delay. |
michael@0 | 30 | * |
michael@0 | 31 | * Scrollbar activity has these states: |
michael@0 | 32 | * - inactive: |
michael@0 | 33 | * Scrollbars are hidden. |
michael@0 | 34 | * - ongoing activity: |
michael@0 | 35 | * Scrollbars are visible and being operated on in some way, for example |
michael@0 | 36 | * because they're hovered or pressed. |
michael@0 | 37 | * - active, but waiting for fade out |
michael@0 | 38 | * Scrollbars are still completely visible but are about to fade away. |
michael@0 | 39 | * - fading out |
michael@0 | 40 | * Scrollbars are subject to a fade-out animation. |
michael@0 | 41 | * |
michael@0 | 42 | * Initial scrollbar activity needs to be reported by the scrollbar holder that |
michael@0 | 43 | * owns the ScrollbarActivity instance. This needs to happen via a call to |
michael@0 | 44 | * ActivityOccurred(), for example when the current scroll position or the size |
michael@0 | 45 | * of the scroll area changes. |
michael@0 | 46 | * |
michael@0 | 47 | * As soon as scrollbars are visible, the ScrollbarActivity class manages the |
michael@0 | 48 | * rest of the activity behavior: It ensures that mouse motions inside the |
michael@0 | 49 | * scroll area keep the scrollbars visible, and that scrollbars don't fade away |
michael@0 | 50 | * while they're being hovered / dragged. It also sets a sticky hover attribute |
michael@0 | 51 | * on the most recently hovered scrollbar. |
michael@0 | 52 | * |
michael@0 | 53 | * ScrollbarActivity falls into hibernation after the scrollbars have faded |
michael@0 | 54 | * out. It only starts acting after the next call to ActivityOccurred() / |
michael@0 | 55 | * ActivityStarted(). |
michael@0 | 56 | */ |
michael@0 | 57 | |
michael@0 | 58 | class ScrollbarActivity : public nsIDOMEventListener, |
michael@0 | 59 | public nsARefreshObserver { |
michael@0 | 60 | public: |
michael@0 | 61 | ScrollbarActivity(nsIScrollbarOwner* aScrollableFrame) |
michael@0 | 62 | : mScrollableFrame(aScrollableFrame) |
michael@0 | 63 | , mNestedActivityCounter(0) |
michael@0 | 64 | , mIsActive(false) |
michael@0 | 65 | , mIsFading(false) |
michael@0 | 66 | , mListeningForScrollbarEvents(false) |
michael@0 | 67 | , mListeningForScrollAreaEvents(false) |
michael@0 | 68 | , mHScrollbarHovered(false) |
michael@0 | 69 | , mVScrollbarHovered(false) |
michael@0 | 70 | , mDisplayOnMouseMove(false) |
michael@0 | 71 | , mScrollbarFadeBeginDelay(0) |
michael@0 | 72 | , mScrollbarFadeDuration(0) |
michael@0 | 73 | { |
michael@0 | 74 | QueryLookAndFeelVals(); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | NS_DECL_ISUPPORTS |
michael@0 | 78 | NS_DECL_NSIDOMEVENTLISTENER |
michael@0 | 79 | |
michael@0 | 80 | virtual ~ScrollbarActivity() {} |
michael@0 | 81 | |
michael@0 | 82 | void Destroy(); |
michael@0 | 83 | |
michael@0 | 84 | void ActivityOccurred(); |
michael@0 | 85 | void ActivityStarted(); |
michael@0 | 86 | void ActivityStopped(); |
michael@0 | 87 | |
michael@0 | 88 | virtual void WillRefresh(TimeStamp aTime) MOZ_OVERRIDE; |
michael@0 | 89 | |
michael@0 | 90 | static void FadeBeginTimerFired(nsITimer* aTimer, void* aSelf) { |
michael@0 | 91 | nsRefPtr<ScrollbarActivity> scrollbarActivity( |
michael@0 | 92 | reinterpret_cast<ScrollbarActivity*>(aSelf)); |
michael@0 | 93 | scrollbarActivity->BeginFade(); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | protected: |
michael@0 | 97 | |
michael@0 | 98 | bool IsActivityOngoing() |
michael@0 | 99 | { return mNestedActivityCounter > 0; } |
michael@0 | 100 | bool IsStillFading(TimeStamp aTime); |
michael@0 | 101 | void QueryLookAndFeelVals(); |
michael@0 | 102 | |
michael@0 | 103 | void HandleEventForScrollbar(const nsAString& aType, |
michael@0 | 104 | nsIContent* aTarget, |
michael@0 | 105 | nsIContent* aScrollbar, |
michael@0 | 106 | bool* aStoredHoverState); |
michael@0 | 107 | |
michael@0 | 108 | void SetIsActive(bool aNewActive); |
michael@0 | 109 | bool SetIsFading(bool aNewFading); // returns false if 'this' was destroyed |
michael@0 | 110 | |
michael@0 | 111 | void BeginFade(); |
michael@0 | 112 | void EndFade(); |
michael@0 | 113 | |
michael@0 | 114 | void StartFadeBeginTimer(); |
michael@0 | 115 | void CancelFadeBeginTimer(); |
michael@0 | 116 | |
michael@0 | 117 | void StartListeningForScrollbarEvents(); |
michael@0 | 118 | void StartListeningForScrollAreaEvents(); |
michael@0 | 119 | void StopListeningForScrollbarEvents(); |
michael@0 | 120 | void StopListeningForScrollAreaEvents(); |
michael@0 | 121 | void AddScrollbarEventListeners(nsIDOMEventTarget* aScrollbar); |
michael@0 | 122 | void RemoveScrollbarEventListeners(nsIDOMEventTarget* aScrollbar); |
michael@0 | 123 | |
michael@0 | 124 | void RegisterWithRefreshDriver(); |
michael@0 | 125 | void UnregisterFromRefreshDriver(); |
michael@0 | 126 | |
michael@0 | 127 | bool UpdateOpacity(TimeStamp aTime); // returns false if 'this' was destroyed |
michael@0 | 128 | void HoveredScrollbar(nsIContent* aScrollbar); |
michael@0 | 129 | |
michael@0 | 130 | nsRefreshDriver* GetRefreshDriver(); |
michael@0 | 131 | nsIContent* GetScrollbarContent(bool aVertical); |
michael@0 | 132 | nsIContent* GetHorizontalScrollbar() { return GetScrollbarContent(false); } |
michael@0 | 133 | nsIContent* GetVerticalScrollbar() { return GetScrollbarContent(true); } |
michael@0 | 134 | |
michael@0 | 135 | const TimeDuration FadeDuration() { |
michael@0 | 136 | return TimeDuration::FromMilliseconds(mScrollbarFadeDuration); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | nsIScrollbarOwner* mScrollableFrame; |
michael@0 | 140 | TimeStamp mFadeBeginTime; |
michael@0 | 141 | nsCOMPtr<nsITimer> mFadeBeginTimer; |
michael@0 | 142 | nsCOMPtr<nsIDOMEventTarget> mHorizontalScrollbar; // null while inactive |
michael@0 | 143 | nsCOMPtr<nsIDOMEventTarget> mVerticalScrollbar; // null while inactive |
michael@0 | 144 | int mNestedActivityCounter; |
michael@0 | 145 | bool mIsActive; |
michael@0 | 146 | bool mIsFading; |
michael@0 | 147 | bool mListeningForScrollbarEvents; |
michael@0 | 148 | bool mListeningForScrollAreaEvents; |
michael@0 | 149 | bool mHScrollbarHovered; |
michael@0 | 150 | bool mVScrollbarHovered; |
michael@0 | 151 | |
michael@0 | 152 | // LookAndFeel values we load on creation |
michael@0 | 153 | bool mDisplayOnMouseMove; |
michael@0 | 154 | int mScrollbarFadeBeginDelay; |
michael@0 | 155 | int mScrollbarFadeDuration; |
michael@0 | 156 | }; |
michael@0 | 157 | |
michael@0 | 158 | } // namespace layout |
michael@0 | 159 | } // namespace mozilla |
michael@0 | 160 | |
michael@0 | 161 | #endif /* ScrollbarActivity_h___ */ |