2012-08-03 10:35:14 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef ScrollbarActivity_h___
|
|
|
|
#define ScrollbarActivity_h___
|
|
|
|
|
2013-05-29 19:37:49 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-08-03 10:35:14 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2013-05-02 14:58:00 +00:00
|
|
|
#include "nsIDOMEventListener.h"
|
2012-08-03 10:35:14 +00:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2013-05-02 14:58:00 +00:00
|
|
|
#include "nsRefreshDriver.h"
|
2012-08-03 10:35:14 +00:00
|
|
|
|
|
|
|
class nsIContent;
|
2014-02-14 06:40:53 +00:00
|
|
|
class nsIScrollbarMediator;
|
2012-08-03 10:35:14 +00:00
|
|
|
class nsITimer;
|
|
|
|
class nsIAtom;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2013-05-02 14:58:00 +00:00
|
|
|
namespace layout {
|
2012-08-03 10:35:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ScrollbarActivity
|
|
|
|
*
|
2013-05-02 14:58:00 +00:00
|
|
|
* This class manages scrollbar behavior that imitates the native Mac OS X
|
|
|
|
* Lion overlay scrollbar behavior: Scrollbars are only shown while "scrollbar
|
|
|
|
* activity" occurs, and they're hidden with a fade animation after a short
|
|
|
|
* delay.
|
2012-08-03 10:35:14 +00:00
|
|
|
*
|
2013-05-02 14:58:00 +00:00
|
|
|
* Scrollbar activity has these states:
|
|
|
|
* - inactive:
|
|
|
|
* Scrollbars are hidden.
|
|
|
|
* - ongoing activity:
|
|
|
|
* Scrollbars are visible and being operated on in some way, for example
|
|
|
|
* because they're hovered or pressed.
|
|
|
|
* - active, but waiting for fade out
|
|
|
|
* Scrollbars are still completely visible but are about to fade away.
|
|
|
|
* - fading out
|
|
|
|
* Scrollbars are subject to a fade-out animation.
|
|
|
|
*
|
|
|
|
* Initial scrollbar activity needs to be reported by the scrollbar holder that
|
2012-08-03 10:35:14 +00:00
|
|
|
* owns the ScrollbarActivity instance. This needs to happen via a call to
|
|
|
|
* ActivityOccurred(), for example when the current scroll position or the size
|
|
|
|
* of the scroll area changes.
|
|
|
|
*
|
2013-05-02 14:58:00 +00:00
|
|
|
* As soon as scrollbars are visible, the ScrollbarActivity class manages the
|
|
|
|
* rest of the activity behavior: It ensures that mouse motions inside the
|
|
|
|
* scroll area keep the scrollbars visible, and that scrollbars don't fade away
|
|
|
|
* while they're being hovered / dragged. It also sets a sticky hover attribute
|
|
|
|
* on the most recently hovered scrollbar.
|
|
|
|
*
|
|
|
|
* ScrollbarActivity falls into hibernation after the scrollbars have faded
|
|
|
|
* out. It only starts acting after the next call to ActivityOccurred() /
|
|
|
|
* ActivityStarted().
|
2012-08-03 10:35:14 +00:00
|
|
|
*/
|
|
|
|
|
2014-08-05 17:33:55 +00:00
|
|
|
class ScrollbarActivity MOZ_FINAL : public nsIDOMEventListener,
|
|
|
|
public nsARefreshObserver {
|
2012-08-03 10:35:14 +00:00
|
|
|
public:
|
2014-09-01 03:36:37 +00:00
|
|
|
explicit ScrollbarActivity(nsIScrollbarMediator* aScrollableFrame)
|
2013-05-02 14:58:00 +00:00
|
|
|
: mScrollableFrame(aScrollableFrame)
|
|
|
|
, mNestedActivityCounter(0)
|
|
|
|
, mIsActive(false)
|
|
|
|
, mIsFading(false)
|
2013-07-02 10:02:21 +00:00
|
|
|
, mListeningForScrollbarEvents(false)
|
|
|
|
, mListeningForScrollAreaEvents(false)
|
2013-05-02 14:58:00 +00:00
|
|
|
, mHScrollbarHovered(false)
|
|
|
|
, mVScrollbarHovered(false)
|
2013-07-02 10:02:21 +00:00
|
|
|
, mDisplayOnMouseMove(false)
|
|
|
|
, mScrollbarFadeBeginDelay(0)
|
|
|
|
, mScrollbarFadeDuration(0)
|
|
|
|
{
|
|
|
|
QueryLookAndFeelVals();
|
|
|
|
}
|
2012-08-03 10:35:14 +00:00
|
|
|
|
2013-05-02 14:58:00 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
|
|
|
|
|
|
|
void Destroy();
|
|
|
|
|
2012-08-03 10:35:14 +00:00
|
|
|
void ActivityOccurred();
|
2013-05-02 14:58:00 +00:00
|
|
|
void ActivityStarted();
|
|
|
|
void ActivityStopped();
|
|
|
|
|
2013-05-29 19:37:49 +00:00
|
|
|
virtual void WillRefresh(TimeStamp aTime) MOZ_OVERRIDE;
|
2013-05-02 14:58:00 +00:00
|
|
|
|
|
|
|
static void FadeBeginTimerFired(nsITimer* aTimer, void* aSelf) {
|
2013-08-01 01:43:56 +00:00
|
|
|
nsRefPtr<ScrollbarActivity> scrollbarActivity(
|
|
|
|
reinterpret_cast<ScrollbarActivity*>(aSelf));
|
|
|
|
scrollbarActivity->BeginFade();
|
2013-05-02 14:58:00 +00:00
|
|
|
}
|
|
|
|
|
2012-08-03 10:35:14 +00:00
|
|
|
protected:
|
2014-06-23 22:40:01 +00:00
|
|
|
virtual ~ScrollbarActivity() {}
|
2012-08-03 10:35:14 +00:00
|
|
|
|
2013-05-02 14:58:00 +00:00
|
|
|
bool IsActivityOngoing()
|
|
|
|
{ return mNestedActivityCounter > 0; }
|
|
|
|
bool IsStillFading(TimeStamp aTime);
|
2013-07-02 10:02:21 +00:00
|
|
|
void QueryLookAndFeelVals();
|
2012-08-03 10:35:14 +00:00
|
|
|
|
2013-05-02 14:58:00 +00:00
|
|
|
void HandleEventForScrollbar(const nsAString& aType,
|
|
|
|
nsIContent* aTarget,
|
|
|
|
nsIContent* aScrollbar,
|
|
|
|
bool* aStoredHoverState);
|
2012-08-03 10:35:14 +00:00
|
|
|
|
|
|
|
void SetIsActive(bool aNewActive);
|
2013-06-10 03:38:45 +00:00
|
|
|
bool SetIsFading(bool aNewFading); // returns false if 'this' was destroyed
|
2013-05-02 11:52:25 +00:00
|
|
|
|
2013-05-02 14:58:00 +00:00
|
|
|
void BeginFade();
|
|
|
|
void EndFade();
|
|
|
|
|
|
|
|
void StartFadeBeginTimer();
|
|
|
|
void CancelFadeBeginTimer();
|
2013-07-02 10:02:21 +00:00
|
|
|
|
|
|
|
void StartListeningForScrollbarEvents();
|
|
|
|
void StartListeningForScrollAreaEvents();
|
|
|
|
void StopListeningForScrollbarEvents();
|
|
|
|
void StopListeningForScrollAreaEvents();
|
|
|
|
void AddScrollbarEventListeners(nsIDOMEventTarget* aScrollbar);
|
|
|
|
void RemoveScrollbarEventListeners(nsIDOMEventTarget* aScrollbar);
|
|
|
|
|
2013-05-02 14:58:00 +00:00
|
|
|
void RegisterWithRefreshDriver();
|
|
|
|
void UnregisterFromRefreshDriver();
|
|
|
|
|
2013-06-08 21:05:33 +00:00
|
|
|
bool UpdateOpacity(TimeStamp aTime); // returns false if 'this' was destroyed
|
2013-05-02 14:58:00 +00:00
|
|
|
void HoveredScrollbar(nsIContent* aScrollbar);
|
2012-08-03 10:35:14 +00:00
|
|
|
|
2013-05-02 14:58:00 +00:00
|
|
|
nsRefreshDriver* GetRefreshDriver();
|
2012-08-03 10:35:14 +00:00
|
|
|
nsIContent* GetScrollbarContent(bool aVertical);
|
2013-05-02 14:58:00 +00:00
|
|
|
nsIContent* GetHorizontalScrollbar() { return GetScrollbarContent(false); }
|
|
|
|
nsIContent* GetVerticalScrollbar() { return GetScrollbarContent(true); }
|
|
|
|
|
2013-07-02 10:02:21 +00:00
|
|
|
const TimeDuration FadeDuration() {
|
|
|
|
return TimeDuration::FromMilliseconds(mScrollbarFadeDuration);
|
2012-08-03 10:35:14 +00:00
|
|
|
}
|
2013-05-02 14:58:00 +00:00
|
|
|
|
2014-02-14 06:40:53 +00:00
|
|
|
nsIScrollbarMediator* mScrollableFrame;
|
2013-05-02 14:58:00 +00:00
|
|
|
TimeStamp mFadeBeginTime;
|
|
|
|
nsCOMPtr<nsITimer> mFadeBeginTimer;
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> mHorizontalScrollbar; // null while inactive
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> mVerticalScrollbar; // null while inactive
|
|
|
|
int mNestedActivityCounter;
|
|
|
|
bool mIsActive;
|
|
|
|
bool mIsFading;
|
2013-07-02 10:02:21 +00:00
|
|
|
bool mListeningForScrollbarEvents;
|
|
|
|
bool mListeningForScrollAreaEvents;
|
2013-05-02 14:58:00 +00:00
|
|
|
bool mHScrollbarHovered;
|
|
|
|
bool mVScrollbarHovered;
|
2013-07-02 10:02:21 +00:00
|
|
|
|
|
|
|
// LookAndFeel values we load on creation
|
|
|
|
bool mDisplayOnMouseMove;
|
|
|
|
int mScrollbarFadeBeginDelay;
|
|
|
|
int mScrollbarFadeDuration;
|
2012-08-03 10:35:14 +00:00
|
|
|
};
|
|
|
|
|
2013-05-02 14:58:00 +00:00
|
|
|
} // namespace layout
|
2012-08-03 10:35:14 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* ScrollbarActivity_h___ */
|