2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-08-03 14:35:14 +04:00
|
|
|
/* 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 23:37:49 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-08-03 14:35:14 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2013-05-02 18:58:00 +04:00
|
|
|
#include "nsIDOMEventListener.h"
|
2012-08-03 14:35:14 +04:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2013-05-02 18:58:00 +04:00
|
|
|
#include "nsRefreshDriver.h"
|
2012-08-03 14:35:14 +04:00
|
|
|
|
|
|
|
class nsIContent;
|
2014-02-14 10:40:53 +04:00
|
|
|
class nsIScrollbarMediator;
|
2012-08-03 14:35:14 +04:00
|
|
|
class nsITimer;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2018-04-05 20:42:40 +03:00
|
|
|
|
|
|
|
namespace dom {
|
2018-06-15 21:00:36 +03:00
|
|
|
class Element;
|
2018-04-05 20:42:40 +03:00
|
|
|
class EventTarget;
|
|
|
|
} // namespace dom
|
|
|
|
|
2013-05-02 18:58:00 +04:00
|
|
|
namespace layout {
|
2012-08-03 14:35:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ScrollbarActivity
|
|
|
|
*
|
2013-05-02 18:58:00 +04: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 14:35:14 +04:00
|
|
|
*
|
2013-05-02 18:58:00 +04: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 14:35:14 +04: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 18:58:00 +04: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 14:35:14 +04:00
|
|
|
*/
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class ScrollbarActivity final : public nsIDOMEventListener,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsARefreshObserver {
|
2012-08-03 14:35:14 +04:00
|
|
|
public:
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit ScrollbarActivity(nsIScrollbarMediator* aScrollableFrame)
|
2013-05-02 18:58:00 +04:00
|
|
|
: mScrollableFrame(aScrollableFrame),
|
|
|
|
mNestedActivityCounter(0),
|
|
|
|
mIsActive(false),
|
|
|
|
mIsFading(false),
|
2013-07-02 14:02:21 +04:00
|
|
|
mListeningForScrollbarEvents(false),
|
|
|
|
mListeningForScrollAreaEvents(false),
|
2013-05-02 18:58:00 +04:00
|
|
|
mHScrollbarHovered(false),
|
|
|
|
mVScrollbarHovered(false),
|
2013-07-02 14:02:21 +04:00
|
|
|
mDisplayOnMouseMove(false),
|
|
|
|
mScrollbarFadeBeginDelay(0),
|
|
|
|
mScrollbarFadeDuration(0) {
|
|
|
|
QueryLookAndFeelVals();
|
|
|
|
}
|
2012-08-03 14:35:14 +04:00
|
|
|
|
2013-05-02 18:58:00 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
|
|
|
|
|
|
|
void Destroy();
|
|
|
|
|
2012-08-03 14:35:14 +04:00
|
|
|
void ActivityOccurred();
|
2013-05-02 18:58:00 +04:00
|
|
|
void ActivityStarted();
|
|
|
|
void ActivityStopped();
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void WillRefresh(TimeStamp aTime) override;
|
2013-05-02 18:58:00 +04:00
|
|
|
|
|
|
|
static void FadeBeginTimerFired(nsITimer* aTimer, void* aSelf) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ScrollbarActivity> scrollbarActivity(
|
2013-08-01 05:43:56 +04:00
|
|
|
reinterpret_cast<ScrollbarActivity*>(aSelf));
|
|
|
|
scrollbarActivity->BeginFade();
|
2013-05-02 18:58:00 +04:00
|
|
|
}
|
|
|
|
|
2012-08-03 14:35:14 +04:00
|
|
|
protected:
|
2020-03-17 12:38:32 +03:00
|
|
|
virtual ~ScrollbarActivity() = default;
|
2012-08-03 14:35:14 +04:00
|
|
|
|
2013-05-02 18:58:00 +04:00
|
|
|
bool IsActivityOngoing() { return mNestedActivityCounter > 0; }
|
|
|
|
bool IsStillFading(TimeStamp aTime);
|
2013-07-02 14:02:21 +04:00
|
|
|
void QueryLookAndFeelVals();
|
2012-08-03 14:35:14 +04:00
|
|
|
|
2013-05-02 18:58:00 +04:00
|
|
|
void HandleEventForScrollbar(const nsAString& aType, nsIContent* aTarget,
|
2017-12-05 20:05:51 +03:00
|
|
|
dom::Element* aScrollbar,
|
2013-05-02 18:58:00 +04:00
|
|
|
bool* aStoredHoverState);
|
2012-08-03 14:35:14 +04:00
|
|
|
|
|
|
|
void SetIsActive(bool aNewActive);
|
2013-06-10 07:38:45 +04:00
|
|
|
bool SetIsFading(bool aNewFading); // returns false if 'this' was destroyed
|
2013-05-02 15:52:25 +04:00
|
|
|
|
2013-05-02 18:58:00 +04:00
|
|
|
void BeginFade();
|
|
|
|
void EndFade();
|
|
|
|
|
|
|
|
void StartFadeBeginTimer();
|
|
|
|
void CancelFadeBeginTimer();
|
2013-07-02 14:02:21 +04:00
|
|
|
|
|
|
|
void StartListeningForScrollbarEvents();
|
|
|
|
void StartListeningForScrollAreaEvents();
|
|
|
|
void StopListeningForScrollbarEvents();
|
|
|
|
void StopListeningForScrollAreaEvents();
|
2018-04-05 20:42:40 +03:00
|
|
|
void AddScrollbarEventListeners(dom::EventTarget* aScrollbar);
|
|
|
|
void RemoveScrollbarEventListeners(dom::EventTarget* aScrollbar);
|
2013-07-02 14:02:21 +04:00
|
|
|
|
2013-05-02 18:58:00 +04:00
|
|
|
void RegisterWithRefreshDriver();
|
|
|
|
void UnregisterFromRefreshDriver();
|
|
|
|
|
2013-06-09 01:05:33 +04:00
|
|
|
bool UpdateOpacity(TimeStamp aTime); // returns false if 'this' was destroyed
|
2017-12-05 20:05:51 +03:00
|
|
|
void HoveredScrollbar(dom::Element* aScrollbar);
|
2012-08-03 14:35:14 +04:00
|
|
|
|
2013-05-02 18:58:00 +04:00
|
|
|
nsRefreshDriver* GetRefreshDriver();
|
2017-12-05 20:05:51 +03:00
|
|
|
dom::Element* GetScrollbarContent(bool aVertical);
|
|
|
|
dom::Element* GetHorizontalScrollbar() { return GetScrollbarContent(false); }
|
|
|
|
dom::Element* GetVerticalScrollbar() { return GetScrollbarContent(true); }
|
2013-05-02 18:58:00 +04:00
|
|
|
|
2013-07-02 14:02:21 +04:00
|
|
|
const TimeDuration FadeDuration() {
|
|
|
|
return TimeDuration::FromMilliseconds(mScrollbarFadeDuration);
|
2012-08-03 14:35:14 +04:00
|
|
|
}
|
2013-05-02 18:58:00 +04:00
|
|
|
|
2014-02-14 10:40:53 +04:00
|
|
|
nsIScrollbarMediator* mScrollableFrame;
|
2013-05-02 18:58:00 +04:00
|
|
|
TimeStamp mFadeBeginTime;
|
|
|
|
nsCOMPtr<nsITimer> mFadeBeginTimer;
|
2018-04-05 20:42:40 +03:00
|
|
|
nsCOMPtr<dom::EventTarget> mHorizontalScrollbar; // null while inactive
|
|
|
|
nsCOMPtr<dom::EventTarget> mVerticalScrollbar; // null while inactive
|
2013-05-02 18:58:00 +04:00
|
|
|
int mNestedActivityCounter;
|
|
|
|
bool mIsActive;
|
|
|
|
bool mIsFading;
|
2013-07-02 14:02:21 +04:00
|
|
|
bool mListeningForScrollbarEvents;
|
|
|
|
bool mListeningForScrollAreaEvents;
|
2013-05-02 18:58:00 +04:00
|
|
|
bool mHScrollbarHovered;
|
|
|
|
bool mVScrollbarHovered;
|
2013-07-02 14:02:21 +04:00
|
|
|
|
|
|
|
// LookAndFeel values we load on creation
|
|
|
|
bool mDisplayOnMouseMove;
|
|
|
|
int mScrollbarFadeBeginDelay;
|
|
|
|
int mScrollbarFadeDuration;
|
2012-08-03 14:35:14 +04:00
|
|
|
};
|
|
|
|
|
2013-05-02 18:58:00 +04:00
|
|
|
} // namespace layout
|
2012-08-03 14:35:14 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* ScrollbarActivity_h___ */
|