2012-08-03 03:35:14 -07: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 12:37:49 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-08-03 03:35:14 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2013-05-02 07:58:00 -07:00
|
|
|
#include "nsIDOMEventListener.h"
|
2012-08-03 03:35:14 -07:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2013-05-02 07:58:00 -07:00
|
|
|
#include "nsRefreshDriver.h"
|
2012-08-03 03:35:14 -07:00
|
|
|
|
|
|
|
class nsIContent;
|
2014-02-13 22:40:53 -08:00
|
|
|
class nsIScrollbarMediator;
|
2012-08-03 03:35:14 -07:00
|
|
|
class nsITimer;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2013-05-02 07:58:00 -07:00
|
|
|
namespace layout {
|
2012-08-03 03:35:14 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ScrollbarActivity
|
|
|
|
*
|
2013-05-02 07:58:00 -07: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 03:35:14 -07:00
|
|
|
*
|
2013-05-02 07:58:00 -07: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 03:35:14 -07: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 07:58:00 -07: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 03:35:14 -07:00
|
|
|
*/
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
class ScrollbarActivity final : public nsIDOMEventListener,
|
2015-03-27 11:52:19 -07:00
|
|
|
public nsARefreshObserver
|
|
|
|
{
|
2012-08-03 03:35:14 -07:00
|
|
|
public:
|
2014-08-31 20:36:37 -07:00
|
|
|
explicit ScrollbarActivity(nsIScrollbarMediator* aScrollableFrame)
|
2013-05-02 07:58:00 -07:00
|
|
|
: mScrollableFrame(aScrollableFrame)
|
|
|
|
, mNestedActivityCounter(0)
|
|
|
|
, mIsActive(false)
|
|
|
|
, mIsFading(false)
|
2013-07-02 03:02:21 -07:00
|
|
|
, mListeningForScrollbarEvents(false)
|
|
|
|
, mListeningForScrollAreaEvents(false)
|
2013-05-02 07:58:00 -07:00
|
|
|
, mHScrollbarHovered(false)
|
|
|
|
, mVScrollbarHovered(false)
|
2013-07-02 03:02:21 -07:00
|
|
|
, mDisplayOnMouseMove(false)
|
|
|
|
, mScrollbarFadeBeginDelay(0)
|
|
|
|
, mScrollbarFadeDuration(0)
|
|
|
|
{
|
|
|
|
QueryLookAndFeelVals();
|
|
|
|
}
|
2012-08-03 03:35:14 -07:00
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
|
|
|
|
|
|
|
void Destroy();
|
|
|
|
|
2012-08-03 03:35:14 -07:00
|
|
|
void ActivityOccurred();
|
2013-05-02 07:58:00 -07:00
|
|
|
void ActivityStarted();
|
|
|
|
void ActivityStopped();
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual void WillRefresh(TimeStamp aTime) override;
|
2013-05-02 07:58:00 -07:00
|
|
|
|
|
|
|
static void FadeBeginTimerFired(nsITimer* aTimer, void* aSelf) {
|
2013-07-31 18:43:56 -07:00
|
|
|
nsRefPtr<ScrollbarActivity> scrollbarActivity(
|
|
|
|
reinterpret_cast<ScrollbarActivity*>(aSelf));
|
|
|
|
scrollbarActivity->BeginFade();
|
2013-05-02 07:58:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-03 03:35:14 -07:00
|
|
|
protected:
|
2014-06-23 15:40:01 -07:00
|
|
|
virtual ~ScrollbarActivity() {}
|
2012-08-03 03:35:14 -07:00
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
bool IsActivityOngoing()
|
|
|
|
{ return mNestedActivityCounter > 0; }
|
|
|
|
bool IsStillFading(TimeStamp aTime);
|
2013-07-02 03:02:21 -07:00
|
|
|
void QueryLookAndFeelVals();
|
2012-08-03 03:35:14 -07:00
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
void HandleEventForScrollbar(const nsAString& aType,
|
|
|
|
nsIContent* aTarget,
|
|
|
|
nsIContent* aScrollbar,
|
|
|
|
bool* aStoredHoverState);
|
2012-08-03 03:35:14 -07:00
|
|
|
|
|
|
|
void SetIsActive(bool aNewActive);
|
2013-06-09 20:38:45 -07:00
|
|
|
bool SetIsFading(bool aNewFading); // returns false if 'this' was destroyed
|
2013-05-02 04:52:25 -07:00
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
void BeginFade();
|
|
|
|
void EndFade();
|
|
|
|
|
|
|
|
void StartFadeBeginTimer();
|
|
|
|
void CancelFadeBeginTimer();
|
2013-07-02 03:02:21 -07:00
|
|
|
|
|
|
|
void StartListeningForScrollbarEvents();
|
|
|
|
void StartListeningForScrollAreaEvents();
|
|
|
|
void StopListeningForScrollbarEvents();
|
|
|
|
void StopListeningForScrollAreaEvents();
|
|
|
|
void AddScrollbarEventListeners(nsIDOMEventTarget* aScrollbar);
|
|
|
|
void RemoveScrollbarEventListeners(nsIDOMEventTarget* aScrollbar);
|
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
void RegisterWithRefreshDriver();
|
|
|
|
void UnregisterFromRefreshDriver();
|
|
|
|
|
2013-06-08 14:05:33 -07:00
|
|
|
bool UpdateOpacity(TimeStamp aTime); // returns false if 'this' was destroyed
|
2013-05-02 07:58:00 -07:00
|
|
|
void HoveredScrollbar(nsIContent* aScrollbar);
|
2012-08-03 03:35:14 -07:00
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
nsRefreshDriver* GetRefreshDriver();
|
2012-08-03 03:35:14 -07:00
|
|
|
nsIContent* GetScrollbarContent(bool aVertical);
|
2013-05-02 07:58:00 -07:00
|
|
|
nsIContent* GetHorizontalScrollbar() { return GetScrollbarContent(false); }
|
|
|
|
nsIContent* GetVerticalScrollbar() { return GetScrollbarContent(true); }
|
|
|
|
|
2013-07-02 03:02:21 -07:00
|
|
|
const TimeDuration FadeDuration() {
|
|
|
|
return TimeDuration::FromMilliseconds(mScrollbarFadeDuration);
|
2012-08-03 03:35:14 -07:00
|
|
|
}
|
2013-05-02 07:58:00 -07:00
|
|
|
|
2014-02-13 22:40:53 -08:00
|
|
|
nsIScrollbarMediator* mScrollableFrame;
|
2013-05-02 07:58:00 -07: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 03:02:21 -07:00
|
|
|
bool mListeningForScrollbarEvents;
|
|
|
|
bool mListeningForScrollAreaEvents;
|
2013-05-02 07:58:00 -07:00
|
|
|
bool mHScrollbarHovered;
|
|
|
|
bool mVScrollbarHovered;
|
2013-07-02 03:02:21 -07:00
|
|
|
|
|
|
|
// LookAndFeel values we load on creation
|
|
|
|
bool mDisplayOnMouseMove;
|
|
|
|
int mScrollbarFadeBeginDelay;
|
|
|
|
int mScrollbarFadeDuration;
|
2012-08-03 03:35:14 -07:00
|
|
|
};
|
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
} // namespace layout
|
2012-08-03 03:35:14 -07:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* ScrollbarActivity_h___ */
|