1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/generic/ScrollbarActivity.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,161 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef ScrollbarActivity_h___ 1.10 +#define ScrollbarActivity_h___ 1.11 + 1.12 +#include "mozilla/Attributes.h" 1.13 +#include "nsCOMPtr.h" 1.14 +#include "nsIDOMEventListener.h" 1.15 +#include "mozilla/TimeStamp.h" 1.16 +#include "nsRefreshDriver.h" 1.17 + 1.18 +class nsIContent; 1.19 +class nsIScrollbarOwner; 1.20 +class nsITimer; 1.21 +class nsIAtom; 1.22 + 1.23 +namespace mozilla { 1.24 +namespace layout { 1.25 + 1.26 +/** 1.27 + * ScrollbarActivity 1.28 + * 1.29 + * This class manages scrollbar behavior that imitates the native Mac OS X 1.30 + * Lion overlay scrollbar behavior: Scrollbars are only shown while "scrollbar 1.31 + * activity" occurs, and they're hidden with a fade animation after a short 1.32 + * delay. 1.33 + * 1.34 + * Scrollbar activity has these states: 1.35 + * - inactive: 1.36 + * Scrollbars are hidden. 1.37 + * - ongoing activity: 1.38 + * Scrollbars are visible and being operated on in some way, for example 1.39 + * because they're hovered or pressed. 1.40 + * - active, but waiting for fade out 1.41 + * Scrollbars are still completely visible but are about to fade away. 1.42 + * - fading out 1.43 + * Scrollbars are subject to a fade-out animation. 1.44 + * 1.45 + * Initial scrollbar activity needs to be reported by the scrollbar holder that 1.46 + * owns the ScrollbarActivity instance. This needs to happen via a call to 1.47 + * ActivityOccurred(), for example when the current scroll position or the size 1.48 + * of the scroll area changes. 1.49 + * 1.50 + * As soon as scrollbars are visible, the ScrollbarActivity class manages the 1.51 + * rest of the activity behavior: It ensures that mouse motions inside the 1.52 + * scroll area keep the scrollbars visible, and that scrollbars don't fade away 1.53 + * while they're being hovered / dragged. It also sets a sticky hover attribute 1.54 + * on the most recently hovered scrollbar. 1.55 + * 1.56 + * ScrollbarActivity falls into hibernation after the scrollbars have faded 1.57 + * out. It only starts acting after the next call to ActivityOccurred() / 1.58 + * ActivityStarted(). 1.59 + */ 1.60 + 1.61 +class ScrollbarActivity : public nsIDOMEventListener, 1.62 + public nsARefreshObserver { 1.63 +public: 1.64 + ScrollbarActivity(nsIScrollbarOwner* aScrollableFrame) 1.65 + : mScrollableFrame(aScrollableFrame) 1.66 + , mNestedActivityCounter(0) 1.67 + , mIsActive(false) 1.68 + , mIsFading(false) 1.69 + , mListeningForScrollbarEvents(false) 1.70 + , mListeningForScrollAreaEvents(false) 1.71 + , mHScrollbarHovered(false) 1.72 + , mVScrollbarHovered(false) 1.73 + , mDisplayOnMouseMove(false) 1.74 + , mScrollbarFadeBeginDelay(0) 1.75 + , mScrollbarFadeDuration(0) 1.76 + { 1.77 + QueryLookAndFeelVals(); 1.78 + } 1.79 + 1.80 + NS_DECL_ISUPPORTS 1.81 + NS_DECL_NSIDOMEVENTLISTENER 1.82 + 1.83 + virtual ~ScrollbarActivity() {} 1.84 + 1.85 + void Destroy(); 1.86 + 1.87 + void ActivityOccurred(); 1.88 + void ActivityStarted(); 1.89 + void ActivityStopped(); 1.90 + 1.91 + virtual void WillRefresh(TimeStamp aTime) MOZ_OVERRIDE; 1.92 + 1.93 + static void FadeBeginTimerFired(nsITimer* aTimer, void* aSelf) { 1.94 + nsRefPtr<ScrollbarActivity> scrollbarActivity( 1.95 + reinterpret_cast<ScrollbarActivity*>(aSelf)); 1.96 + scrollbarActivity->BeginFade(); 1.97 + } 1.98 + 1.99 +protected: 1.100 + 1.101 + bool IsActivityOngoing() 1.102 + { return mNestedActivityCounter > 0; } 1.103 + bool IsStillFading(TimeStamp aTime); 1.104 + void QueryLookAndFeelVals(); 1.105 + 1.106 + void HandleEventForScrollbar(const nsAString& aType, 1.107 + nsIContent* aTarget, 1.108 + nsIContent* aScrollbar, 1.109 + bool* aStoredHoverState); 1.110 + 1.111 + void SetIsActive(bool aNewActive); 1.112 + bool SetIsFading(bool aNewFading); // returns false if 'this' was destroyed 1.113 + 1.114 + void BeginFade(); 1.115 + void EndFade(); 1.116 + 1.117 + void StartFadeBeginTimer(); 1.118 + void CancelFadeBeginTimer(); 1.119 + 1.120 + void StartListeningForScrollbarEvents(); 1.121 + void StartListeningForScrollAreaEvents(); 1.122 + void StopListeningForScrollbarEvents(); 1.123 + void StopListeningForScrollAreaEvents(); 1.124 + void AddScrollbarEventListeners(nsIDOMEventTarget* aScrollbar); 1.125 + void RemoveScrollbarEventListeners(nsIDOMEventTarget* aScrollbar); 1.126 + 1.127 + void RegisterWithRefreshDriver(); 1.128 + void UnregisterFromRefreshDriver(); 1.129 + 1.130 + bool UpdateOpacity(TimeStamp aTime); // returns false if 'this' was destroyed 1.131 + void HoveredScrollbar(nsIContent* aScrollbar); 1.132 + 1.133 + nsRefreshDriver* GetRefreshDriver(); 1.134 + nsIContent* GetScrollbarContent(bool aVertical); 1.135 + nsIContent* GetHorizontalScrollbar() { return GetScrollbarContent(false); } 1.136 + nsIContent* GetVerticalScrollbar() { return GetScrollbarContent(true); } 1.137 + 1.138 + const TimeDuration FadeDuration() { 1.139 + return TimeDuration::FromMilliseconds(mScrollbarFadeDuration); 1.140 + } 1.141 + 1.142 + nsIScrollbarOwner* mScrollableFrame; 1.143 + TimeStamp mFadeBeginTime; 1.144 + nsCOMPtr<nsITimer> mFadeBeginTimer; 1.145 + nsCOMPtr<nsIDOMEventTarget> mHorizontalScrollbar; // null while inactive 1.146 + nsCOMPtr<nsIDOMEventTarget> mVerticalScrollbar; // null while inactive 1.147 + int mNestedActivityCounter; 1.148 + bool mIsActive; 1.149 + bool mIsFading; 1.150 + bool mListeningForScrollbarEvents; 1.151 + bool mListeningForScrollAreaEvents; 1.152 + bool mHScrollbarHovered; 1.153 + bool mVScrollbarHovered; 1.154 + 1.155 + // LookAndFeel values we load on creation 1.156 + bool mDisplayOnMouseMove; 1.157 + int mScrollbarFadeBeginDelay; 1.158 + int mScrollbarFadeDuration; 1.159 +}; 1.160 + 1.161 +} // namespace layout 1.162 +} // namespace mozilla 1.163 + 1.164 +#endif /* ScrollbarActivity_h___ */