layout/generic/ScrollbarActivity.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial