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/. */
|
|
|
|
|
|
|
|
#include "ScrollbarActivity.h"
|
2013-05-02 07:58:00 -07:00
|
|
|
#include "nsIScrollbarOwner.h"
|
2013-10-01 14:00:38 -07:00
|
|
|
#include "nsIContent.h"
|
2013-05-02 07:58:00 -07:00
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "nsIDOMElementCSSInlineStyle.h"
|
|
|
|
#include "nsIDOMCSSStyleDeclaration.h"
|
2013-05-02 05:33:54 -07:00
|
|
|
#include "nsIFrame.h"
|
2013-05-02 07:58:00 -07:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsAString.h"
|
|
|
|
#include "nsQueryFrame.h"
|
2013-03-17 00:55:15 -07:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2013-07-02 03:02:21 -07:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2014-03-19 19:12:46 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-08-03 03:35:14 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-05-02 07:58:00 -07:00
|
|
|
namespace layout {
|
2012-08-03 03:35:14 -07:00
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(ScrollbarActivity, nsIDOMEventListener)
|
2013-05-02 07:58:00 -07:00
|
|
|
|
2014-03-19 19:12:46 -07:00
|
|
|
static bool
|
|
|
|
GetForceAlwaysVisiblePref()
|
|
|
|
{
|
|
|
|
static bool sForceAlwaysVisible;
|
|
|
|
static bool sForceAlwaysVisiblePrefCached = false;
|
|
|
|
if (!sForceAlwaysVisiblePrefCached) {
|
|
|
|
Preferences::AddBoolVarCache(&sForceAlwaysVisible,
|
|
|
|
"layout.testing.overlay-scrollbars.always-visible");
|
|
|
|
sForceAlwaysVisiblePrefCached = true;
|
|
|
|
}
|
|
|
|
return sForceAlwaysVisible;
|
|
|
|
}
|
|
|
|
|
2013-07-02 03:02:21 -07:00
|
|
|
void
|
|
|
|
ScrollbarActivity::QueryLookAndFeelVals()
|
|
|
|
{
|
|
|
|
// Fade animation constants
|
|
|
|
mScrollbarFadeBeginDelay =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_ScrollbarFadeBeginDelay);
|
|
|
|
mScrollbarFadeDuration =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_ScrollbarFadeDuration);
|
|
|
|
// Controls whether we keep the mouse move listener so we can display the
|
|
|
|
// scrollbars whenever the user moves the mouse within the scroll area.
|
|
|
|
mDisplayOnMouseMove =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_ScrollbarDisplayOnMouseMove);
|
|
|
|
}
|
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
void
|
|
|
|
ScrollbarActivity::Destroy()
|
2012-08-03 03:35:14 -07:00
|
|
|
{
|
2013-07-02 03:02:21 -07:00
|
|
|
StopListeningForScrollbarEvents();
|
|
|
|
StopListeningForScrollAreaEvents();
|
2013-05-02 07:58:00 -07:00
|
|
|
UnregisterFromRefreshDriver();
|
|
|
|
CancelFadeBeginTimer();
|
2012-08-03 03:35:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ScrollbarActivity::ActivityOccurred()
|
|
|
|
{
|
2013-05-02 07:58:00 -07:00
|
|
|
ActivityStarted();
|
|
|
|
ActivityStopped();
|
|
|
|
}
|
2012-08-03 03:35:14 -07:00
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
void
|
|
|
|
ScrollbarActivity::ActivityStarted()
|
|
|
|
{
|
|
|
|
mNestedActivityCounter++;
|
|
|
|
CancelFadeBeginTimer();
|
2013-06-09 20:38:45 -07:00
|
|
|
if (!SetIsFading(false)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-05-02 07:58:00 -07:00
|
|
|
UnregisterFromRefreshDriver();
|
2013-07-02 03:02:21 -07:00
|
|
|
StartListeningForScrollbarEvents();
|
|
|
|
StartListeningForScrollAreaEvents();
|
2012-08-03 03:35:14 -07:00
|
|
|
SetIsActive(true);
|
2013-05-02 07:58:00 -07:00
|
|
|
|
2012-08-03 03:35:14 -07:00
|
|
|
NS_ASSERTION(mIsActive, "need to be active during activity");
|
2013-05-02 07:58:00 -07:00
|
|
|
NS_ASSERTION(!mIsFading, "must not be fading during activity");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ScrollbarActivity::ActivityStopped()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(IsActivityOngoing(), "activity stopped while none was going on");
|
|
|
|
NS_ASSERTION(mIsActive, "need to be active during activity");
|
|
|
|
NS_ASSERTION(!mIsFading, "must not be fading during ongoing activity");
|
|
|
|
|
|
|
|
mNestedActivityCounter--;
|
|
|
|
|
|
|
|
if (!IsActivityOngoing()) {
|
|
|
|
StartFadeBeginTimer();
|
|
|
|
|
|
|
|
NS_ASSERTION(mIsActive, "need to be active right after activity");
|
|
|
|
NS_ASSERTION(!mIsFading, "must not be fading right after activity");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ScrollbarActivity::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
2013-07-02 03:02:21 -07:00
|
|
|
if (!mDisplayOnMouseMove && !mIsActive)
|
2013-05-02 07:58:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsAutoString type;
|
|
|
|
aEvent->GetType(type);
|
|
|
|
|
|
|
|
if (type.EqualsLiteral("mousemove")) {
|
|
|
|
// Mouse motions anywhere in the scrollable frame should keep the
|
|
|
|
// scrollbars visible.
|
|
|
|
ActivityOccurred();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target;
|
|
|
|
aEvent->GetOriginalTarget(getter_AddRefs(target));
|
|
|
|
nsCOMPtr<nsIContent> targetContent = do_QueryInterface(target);
|
|
|
|
|
|
|
|
HandleEventForScrollbar(type, targetContent, GetHorizontalScrollbar(),
|
|
|
|
&mHScrollbarHovered);
|
|
|
|
HandleEventForScrollbar(type, targetContent, GetVerticalScrollbar(),
|
|
|
|
&mVScrollbarHovered);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ScrollbarActivity::WillRefresh(TimeStamp aTime)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mIsActive, "should only fade while scrollbars are visible");
|
|
|
|
NS_ASSERTION(!IsActivityOngoing(), "why weren't we unregistered from the refresh driver when scrollbar activity started?");
|
|
|
|
NS_ASSERTION(mIsFading, "should only animate fading during fade");
|
|
|
|
|
2013-06-08 14:05:33 -07:00
|
|
|
if (!UpdateOpacity(aTime)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-05-02 07:58:00 -07:00
|
|
|
|
|
|
|
if (!IsStillFading(aTime)) {
|
|
|
|
EndFade();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ScrollbarActivity::IsStillFading(TimeStamp aTime)
|
|
|
|
{
|
|
|
|
return !mFadeBeginTime.IsNull() && (aTime - mFadeBeginTime < FadeDuration());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ScrollbarActivity::HandleEventForScrollbar(const nsAString& aType,
|
|
|
|
nsIContent* aTarget,
|
|
|
|
nsIContent* aScrollbar,
|
|
|
|
bool* aStoredHoverState)
|
|
|
|
{
|
|
|
|
if (!aTarget || !aScrollbar ||
|
|
|
|
!nsContentUtils::ContentIsDescendantOf(aTarget, aScrollbar))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (aType.EqualsLiteral("mousedown")) {
|
|
|
|
ActivityStarted();
|
|
|
|
} else if (aType.EqualsLiteral("mouseup")) {
|
|
|
|
ActivityStopped();
|
|
|
|
} else if (aType.EqualsLiteral("mouseover") ||
|
|
|
|
aType.EqualsLiteral("mouseout")) {
|
|
|
|
bool newHoveredState = aType.EqualsLiteral("mouseover");
|
|
|
|
if (newHoveredState && !*aStoredHoverState) {
|
|
|
|
ActivityStarted();
|
|
|
|
HoveredScrollbar(aScrollbar);
|
|
|
|
} else if (*aStoredHoverState && !newHoveredState) {
|
|
|
|
ActivityStopped();
|
|
|
|
// Don't call HoveredScrollbar(nullptr) here because we want the hover
|
|
|
|
// attribute to stick until the scrollbars are hidden.
|
|
|
|
}
|
|
|
|
*aStoredHoverState = newHoveredState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-02 03:02:21 -07:00
|
|
|
ScrollbarActivity::StartListeningForScrollbarEvents()
|
2013-05-02 07:58:00 -07:00
|
|
|
{
|
2013-07-02 03:02:21 -07:00
|
|
|
if (mListeningForScrollbarEvents)
|
2013-05-02 07:58:00 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
mHorizontalScrollbar = do_QueryInterface(GetHorizontalScrollbar());
|
|
|
|
mVerticalScrollbar = do_QueryInterface(GetVerticalScrollbar());
|
|
|
|
|
2013-07-02 03:02:21 -07:00
|
|
|
AddScrollbarEventListeners(mHorizontalScrollbar);
|
|
|
|
AddScrollbarEventListeners(mVerticalScrollbar);
|
|
|
|
|
|
|
|
mListeningForScrollbarEvents = true;
|
2013-07-01 19:42:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-02 03:02:21 -07:00
|
|
|
ScrollbarActivity::StopListeningForScrollbarEvents()
|
2013-07-01 19:42:00 -07:00
|
|
|
{
|
2013-07-02 03:02:21 -07:00
|
|
|
if (!mListeningForScrollbarEvents)
|
|
|
|
return;
|
|
|
|
|
|
|
|
RemoveScrollbarEventListeners(mHorizontalScrollbar);
|
|
|
|
RemoveScrollbarEventListeners(mVerticalScrollbar);
|
|
|
|
|
|
|
|
mHorizontalScrollbar = nullptr;
|
|
|
|
mVerticalScrollbar = nullptr;
|
|
|
|
mListeningForScrollbarEvents = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ScrollbarActivity::StartListeningForScrollAreaEvents()
|
|
|
|
{
|
|
|
|
if (mListeningForScrollAreaEvents)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIFrame* scrollArea = do_QueryFrame(mScrollableFrame);
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> scrollAreaTarget
|
|
|
|
= do_QueryInterface(scrollArea->GetContent());
|
|
|
|
if (scrollAreaTarget) {
|
|
|
|
scrollAreaTarget->AddEventListener(NS_LITERAL_STRING("mousemove"), this,
|
|
|
|
true);
|
2013-07-01 11:29:24 -07:00
|
|
|
}
|
2013-07-02 03:02:21 -07:00
|
|
|
mListeningForScrollAreaEvents = true;
|
2013-05-02 07:58:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-02 03:02:21 -07:00
|
|
|
ScrollbarActivity::StopListeningForScrollAreaEvents()
|
2013-07-01 11:50:25 -07:00
|
|
|
{
|
2013-07-02 03:02:21 -07:00
|
|
|
if (!mListeningForScrollAreaEvents)
|
2013-07-01 11:50:25 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
nsIFrame* scrollArea = do_QueryFrame(mScrollableFrame);
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> scrollAreaTarget = do_QueryInterface(scrollArea->GetContent());
|
|
|
|
if (scrollAreaTarget) {
|
|
|
|
scrollAreaTarget->RemoveEventListener(NS_LITERAL_STRING("mousemove"), this, true);
|
|
|
|
}
|
2013-07-02 03:02:21 -07:00
|
|
|
mListeningForScrollAreaEvents = false;
|
|
|
|
}
|
2013-07-01 11:50:25 -07:00
|
|
|
|
2013-07-02 03:02:21 -07:00
|
|
|
void
|
|
|
|
ScrollbarActivity::AddScrollbarEventListeners(nsIDOMEventTarget* aScrollbar)
|
|
|
|
{
|
|
|
|
if (aScrollbar) {
|
|
|
|
aScrollbar->AddEventListener(NS_LITERAL_STRING("mousedown"), this, true);
|
|
|
|
aScrollbar->AddEventListener(NS_LITERAL_STRING("mouseup"), this, true);
|
|
|
|
aScrollbar->AddEventListener(NS_LITERAL_STRING("mouseover"), this, true);
|
|
|
|
aScrollbar->AddEventListener(NS_LITERAL_STRING("mouseout"), this, true);
|
|
|
|
}
|
2013-07-01 11:50:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-02 03:02:21 -07:00
|
|
|
ScrollbarActivity::RemoveScrollbarEventListeners(nsIDOMEventTarget* aScrollbar)
|
2013-05-02 07:58:00 -07:00
|
|
|
{
|
|
|
|
if (aScrollbar) {
|
|
|
|
aScrollbar->RemoveEventListener(NS_LITERAL_STRING("mousedown"), this, true);
|
|
|
|
aScrollbar->RemoveEventListener(NS_LITERAL_STRING("mouseup"), this, true);
|
|
|
|
aScrollbar->RemoveEventListener(NS_LITERAL_STRING("mouseover"), this, true);
|
|
|
|
aScrollbar->RemoveEventListener(NS_LITERAL_STRING("mouseout"), this, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ScrollbarActivity::BeginFade()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mIsActive, "can't begin fade when we're already inactive");
|
|
|
|
NS_ASSERTION(!IsActivityOngoing(), "why wasn't the fade begin timer cancelled when scrollbar activity started?");
|
|
|
|
NS_ASSERTION(!mIsFading, "shouldn't be fading just yet");
|
|
|
|
|
|
|
|
CancelFadeBeginTimer();
|
|
|
|
mFadeBeginTime = TimeStamp::Now();
|
2013-06-09 20:38:45 -07:00
|
|
|
if (!SetIsFading(true)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-05-02 07:58:00 -07:00
|
|
|
RegisterWithRefreshDriver();
|
|
|
|
|
|
|
|
NS_ASSERTION(mIsActive, "only fade while scrollbars are visible");
|
|
|
|
NS_ASSERTION(mIsFading, "should be fading now");
|
2012-08-03 03:35:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-02 07:58:00 -07:00
|
|
|
ScrollbarActivity::EndFade()
|
2012-08-03 03:35:14 -07:00
|
|
|
{
|
2013-05-02 07:58:00 -07:00
|
|
|
NS_ASSERTION(mIsActive, "still need to be active at this point");
|
|
|
|
NS_ASSERTION(!IsActivityOngoing(), "why wasn't the fade end timer cancelled when scrollbar activity started?");
|
|
|
|
|
2013-06-09 20:38:45 -07:00
|
|
|
if (!SetIsFading(false)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-08-03 03:35:14 -07:00
|
|
|
SetIsActive(false);
|
2013-05-02 07:58:00 -07:00
|
|
|
UnregisterFromRefreshDriver();
|
2013-07-02 03:02:21 -07:00
|
|
|
StopListeningForScrollbarEvents();
|
|
|
|
if (!mDisplayOnMouseMove) {
|
|
|
|
StopListeningForScrollAreaEvents();
|
|
|
|
}
|
2013-05-02 07:58:00 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(!mIsActive, "should have gone inactive after fade end");
|
|
|
|
NS_ASSERTION(!mIsFading, "shouldn't be fading anymore");
|
2012-08-03 03:35:14 -07:00
|
|
|
}
|
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
void
|
|
|
|
ScrollbarActivity::RegisterWithRefreshDriver()
|
|
|
|
{
|
|
|
|
nsRefreshDriver* refreshDriver = GetRefreshDriver();
|
|
|
|
if (refreshDriver) {
|
|
|
|
refreshDriver->AddRefreshObserver(this, Flush_Style);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ScrollbarActivity::UnregisterFromRefreshDriver()
|
|
|
|
{
|
|
|
|
nsRefreshDriver* refreshDriver = GetRefreshDriver();
|
|
|
|
if (refreshDriver) {
|
|
|
|
refreshDriver->RemoveRefreshObserver(this, Flush_Style);
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 03:35:14 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
SetBooleanAttribute(nsIContent* aContent, nsIAtom* aAttribute, bool aValue)
|
|
|
|
{
|
|
|
|
if (aContent) {
|
|
|
|
if (aValue) {
|
|
|
|
aContent->SetAttr(kNameSpaceID_None, aAttribute,
|
|
|
|
NS_LITERAL_STRING("true"), true);
|
|
|
|
} else {
|
|
|
|
aContent->UnsetAttr(kNameSpaceID_None, aAttribute, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ScrollbarActivity::SetIsActive(bool aNewActive)
|
|
|
|
{
|
|
|
|
if (mIsActive == aNewActive)
|
|
|
|
return;
|
2013-05-02 07:58:00 -07:00
|
|
|
|
2012-08-03 03:35:14 -07:00
|
|
|
mIsActive = aNewActive;
|
2013-05-02 07:58:00 -07:00
|
|
|
if (!mIsActive) {
|
|
|
|
// Clear sticky scrollbar hover status.
|
|
|
|
HoveredScrollbar(nullptr);
|
|
|
|
}
|
2012-08-03 03:35:14 -07:00
|
|
|
|
|
|
|
SetBooleanAttribute(GetHorizontalScrollbar(), nsGkAtoms::active, mIsActive);
|
|
|
|
SetBooleanAttribute(GetVerticalScrollbar(), nsGkAtoms::active, mIsActive);
|
|
|
|
}
|
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
static void
|
|
|
|
SetOpacityOnElement(nsIContent* aContent, double aOpacity)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyleContent =
|
|
|
|
do_QueryInterface(aContent);
|
|
|
|
if (inlineStyleContent) {
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> decl;
|
|
|
|
inlineStyleContent->GetStyle(getter_AddRefs(decl));
|
|
|
|
if (decl) {
|
|
|
|
nsAutoString str;
|
|
|
|
str.AppendFloat(aOpacity);
|
|
|
|
decl->SetProperty(NS_LITERAL_STRING("opacity"), str, EmptyString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-08 14:05:33 -07:00
|
|
|
bool
|
2013-05-02 07:58:00 -07:00
|
|
|
ScrollbarActivity::UpdateOpacity(TimeStamp aTime)
|
|
|
|
{
|
|
|
|
double progress = (aTime - mFadeBeginTime) / FadeDuration();
|
|
|
|
double opacity = 1.0 - std::max(0.0, std::min(1.0, progress));
|
2013-06-08 14:05:33 -07:00
|
|
|
|
|
|
|
// 'this' may be getting destroyed during SetOpacityOnElement calls.
|
|
|
|
nsWeakFrame weakFrame((do_QueryFrame(mScrollableFrame)));
|
2013-05-02 07:58:00 -07:00
|
|
|
SetOpacityOnElement(GetHorizontalScrollbar(), opacity);
|
2013-06-08 14:05:33 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-02 07:58:00 -07:00
|
|
|
SetOpacityOnElement(GetVerticalScrollbar(), opacity);
|
2013-06-08 14:05:33 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2013-05-02 07:58:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
UnsetOpacityOnElement(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyleContent =
|
|
|
|
do_QueryInterface(aContent);
|
|
|
|
if (inlineStyleContent) {
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> decl;
|
|
|
|
inlineStyleContent->GetStyle(getter_AddRefs(decl));
|
|
|
|
if (decl) {
|
|
|
|
nsAutoString dummy;
|
|
|
|
decl->RemoveProperty(NS_LITERAL_STRING("opacity"), dummy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-09 20:38:45 -07:00
|
|
|
bool
|
2013-05-02 07:58:00 -07:00
|
|
|
ScrollbarActivity::SetIsFading(bool aNewFading)
|
|
|
|
{
|
|
|
|
if (mIsFading == aNewFading)
|
2013-06-09 20:38:45 -07:00
|
|
|
return true;
|
2013-05-02 07:58:00 -07:00
|
|
|
|
|
|
|
mIsFading = aNewFading;
|
|
|
|
if (!mIsFading) {
|
|
|
|
mFadeBeginTime = TimeStamp();
|
2013-06-09 20:38:45 -07:00
|
|
|
// 'this' may be getting destroyed during UnsetOpacityOnElement calls.
|
|
|
|
nsWeakFrame weakFrame((do_QueryFrame(mScrollableFrame)));
|
2013-05-02 07:58:00 -07:00
|
|
|
UnsetOpacityOnElement(GetHorizontalScrollbar());
|
2013-06-09 20:38:45 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-02 07:58:00 -07:00
|
|
|
UnsetOpacityOnElement(GetVerticalScrollbar());
|
2013-06-09 20:38:45 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-02 07:58:00 -07:00
|
|
|
}
|
2013-06-09 20:38:45 -07:00
|
|
|
return true;
|
2013-05-02 07:58:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-03 03:35:14 -07:00
|
|
|
void
|
2013-05-02 07:58:00 -07:00
|
|
|
ScrollbarActivity::StartFadeBeginTimer()
|
2012-08-03 03:35:14 -07:00
|
|
|
{
|
2014-03-19 19:12:46 -07:00
|
|
|
if (GetForceAlwaysVisiblePref()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-07-02 03:02:21 -07:00
|
|
|
if (!mFadeBeginTimer) {
|
|
|
|
mFadeBeginTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
}
|
2013-05-02 07:58:00 -07:00
|
|
|
mFadeBeginTimer->InitWithFuncCallback(FadeBeginTimerFired, this,
|
2013-07-02 03:02:21 -07:00
|
|
|
mScrollbarFadeBeginDelay,
|
2013-05-02 07:58:00 -07:00
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
2012-08-03 03:35:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-05-02 07:58:00 -07:00
|
|
|
ScrollbarActivity::CancelFadeBeginTimer()
|
2012-08-03 03:35:14 -07:00
|
|
|
{
|
2013-05-02 07:58:00 -07:00
|
|
|
if (mFadeBeginTimer) {
|
|
|
|
mFadeBeginTimer->Cancel();
|
2012-08-03 03:35:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-02 07:58:00 -07:00
|
|
|
void
|
|
|
|
ScrollbarActivity::HoveredScrollbar(nsIContent* aScrollbar)
|
|
|
|
{
|
|
|
|
SetBooleanAttribute(GetHorizontalScrollbar(), nsGkAtoms::hover, false);
|
|
|
|
SetBooleanAttribute(GetVerticalScrollbar(), nsGkAtoms::hover, false);
|
|
|
|
SetBooleanAttribute(aScrollbar, nsGkAtoms::hover, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefreshDriver*
|
|
|
|
ScrollbarActivity::GetRefreshDriver()
|
|
|
|
{
|
2013-07-22 19:46:27 -07:00
|
|
|
nsIFrame* scrollableFrame = do_QueryFrame(mScrollableFrame);
|
|
|
|
return scrollableFrame->PresContext()->RefreshDriver();
|
2013-05-02 07:58:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-03 03:35:14 -07:00
|
|
|
nsIContent*
|
|
|
|
ScrollbarActivity::GetScrollbarContent(bool aVertical)
|
|
|
|
{
|
|
|
|
nsIFrame* box = mScrollableFrame->GetScrollbarBox(aVertical);
|
2012-08-12 03:43:47 -07:00
|
|
|
return box ? box->GetContent() : nullptr;
|
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
|