LCOV - code coverage report
Current view: top level - layout/generic - ScrollbarActivity.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 16 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       5             : 
       6             : #ifndef ScrollbarActivity_h___
       7             : #define ScrollbarActivity_h___
       8             : 
       9             : #include "mozilla/Attributes.h"
      10             : #include "nsCOMPtr.h"
      11             : #include "nsIDOMEventListener.h"
      12             : #include "mozilla/TimeStamp.h"
      13             : #include "nsRefreshDriver.h"
      14             : 
      15             : class nsIContent;
      16             : class nsIScrollbarMediator;
      17             : class nsITimer;
      18             : 
      19             : namespace mozilla {
      20             : namespace layout {
      21             : 
      22             : /**
      23             :  * ScrollbarActivity
      24             :  *
      25             :  * This class manages scrollbar behavior that imitates the native Mac OS X
      26             :  * Lion overlay scrollbar behavior: Scrollbars are only shown while "scrollbar
      27             :  * activity" occurs, and they're hidden with a fade animation after a short
      28             :  * delay.
      29             :  *
      30             :  * Scrollbar activity has these states:
      31             :  *  - inactive:
      32             :  *      Scrollbars are hidden.
      33             :  *  - ongoing activity:
      34             :  *      Scrollbars are visible and being operated on in some way, for example
      35             :  *      because they're hovered or pressed.
      36             :  *  - active, but waiting for fade out
      37             :  *      Scrollbars are still completely visible but are about to fade away.
      38             :  *  - fading out
      39             :  *      Scrollbars are subject to a fade-out animation.
      40             :  *
      41             :  * Initial scrollbar activity needs to be reported by the scrollbar holder that
      42             :  * owns the ScrollbarActivity instance. This needs to happen via a call to
      43             :  * ActivityOccurred(), for example when the current scroll position or the size
      44             :  * of the scroll area changes.
      45             :  *
      46             :  * As soon as scrollbars are visible, the ScrollbarActivity class manages the
      47             :  * rest of the activity behavior: It ensures that mouse motions inside the
      48             :  * scroll area keep the scrollbars visible, and that scrollbars don't fade away
      49             :  * while they're being hovered / dragged. It also sets a sticky hover attribute
      50             :  * on the most recently hovered scrollbar.
      51             :  *
      52             :  * ScrollbarActivity falls into hibernation after the scrollbars have faded
      53             :  * out. It only starts acting after the next call to ActivityOccurred() /
      54             :  * ActivityStarted().
      55             :  */
      56             : 
      57             : class ScrollbarActivity final : public nsIDOMEventListener,
      58             :                                 public nsARefreshObserver
      59             : {
      60             : public:
      61           0 :   explicit ScrollbarActivity(nsIScrollbarMediator* aScrollableFrame)
      62           0 :    : 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           0 :    , mScrollbarFadeDuration(0)
      73             :   {
      74           0 :     QueryLookAndFeelVals();
      75           0 :   }
      76             : 
      77             :   NS_DECL_ISUPPORTS
      78             :   NS_DECL_NSIDOMEVENTLISTENER
      79             : 
      80             :   void Destroy();
      81             : 
      82             :   void ActivityOccurred();
      83             :   void ActivityStarted();
      84             :   void ActivityStopped();
      85             : 
      86             :   virtual void WillRefresh(TimeStamp aTime) override;
      87             : 
      88           0 :   static void FadeBeginTimerFired(nsITimer* aTimer, void* aSelf) {
      89             :     RefPtr<ScrollbarActivity> scrollbarActivity(
      90           0 :       reinterpret_cast<ScrollbarActivity*>(aSelf));
      91           0 :     scrollbarActivity->BeginFade();
      92           0 :   }
      93             : 
      94             : protected:
      95           0 :   virtual ~ScrollbarActivity() {}
      96             : 
      97           0 :   bool IsActivityOngoing()
      98           0 :   { return mNestedActivityCounter > 0; }
      99             :   bool IsStillFading(TimeStamp aTime);
     100             :   void QueryLookAndFeelVals();
     101             : 
     102             :   void HandleEventForScrollbar(const nsAString& aType,
     103             :                                nsIContent* aTarget,
     104             :                                nsIContent* aScrollbar,
     105             :                                bool* aStoredHoverState);
     106             : 
     107             :   void SetIsActive(bool aNewActive);
     108             :   bool SetIsFading(bool aNewFading); // returns false if 'this' was destroyed
     109             : 
     110             :   void BeginFade();
     111             :   void EndFade();
     112             : 
     113             :   void StartFadeBeginTimer();
     114             :   void CancelFadeBeginTimer();
     115             : 
     116             :   void StartListeningForScrollbarEvents();
     117             :   void StartListeningForScrollAreaEvents();
     118             :   void StopListeningForScrollbarEvents();
     119             :   void StopListeningForScrollAreaEvents();
     120             :   void AddScrollbarEventListeners(nsIDOMEventTarget* aScrollbar);
     121             :   void RemoveScrollbarEventListeners(nsIDOMEventTarget* aScrollbar);
     122             : 
     123             :   void RegisterWithRefreshDriver();
     124             :   void UnregisterFromRefreshDriver();
     125             : 
     126             :   bool UpdateOpacity(TimeStamp aTime); // returns false if 'this' was destroyed
     127             :   void HoveredScrollbar(nsIContent* aScrollbar);
     128             : 
     129             :   nsRefreshDriver* GetRefreshDriver();
     130             :   nsIContent* GetScrollbarContent(bool aVertical);
     131           0 :   nsIContent* GetHorizontalScrollbar() { return GetScrollbarContent(false); }
     132           0 :   nsIContent* GetVerticalScrollbar() { return GetScrollbarContent(true); }
     133             : 
     134           0 :   const TimeDuration FadeDuration() {
     135           0 :     return TimeDuration::FromMilliseconds(mScrollbarFadeDuration);
     136             :   }
     137             : 
     138             :   nsIScrollbarMediator* mScrollableFrame;
     139             :   TimeStamp mFadeBeginTime;
     140             :   nsCOMPtr<nsITimer> mFadeBeginTimer;
     141             :   nsCOMPtr<nsIDOMEventTarget> mHorizontalScrollbar; // null while inactive
     142             :   nsCOMPtr<nsIDOMEventTarget> mVerticalScrollbar;   // null while inactive
     143             :   int mNestedActivityCounter;
     144             :   bool mIsActive;
     145             :   bool mIsFading;
     146             :   bool mListeningForScrollbarEvents;
     147             :   bool mListeningForScrollAreaEvents;
     148             :   bool mHScrollbarHovered;
     149             :   bool mVScrollbarHovered;
     150             : 
     151             :   // LookAndFeel values we load on creation
     152             :   bool mDisplayOnMouseMove;
     153             :   int mScrollbarFadeBeginDelay;
     154             :   int mScrollbarFadeDuration;
     155             : };
     156             : 
     157             : } // namespace layout
     158             : } // namespace mozilla
     159             : 
     160             : #endif /* ScrollbarActivity_h___ */

Generated by: LCOV version 1.13