2015-05-03 12:32:37 -07: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: */
|
2014-03-31 21:09:22 -07: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/. */
|
|
|
|
|
|
|
|
#include "WheelHandlingHelper.h"
|
|
|
|
|
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-03-31 21:09:23 -07:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-03-31 21:09:22 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "Units.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
/* mozilla::DeltaValues */
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
DeltaValues::DeltaValues(WidgetWheelEvent* aEvent)
|
|
|
|
: deltaX(aEvent->deltaX)
|
|
|
|
, deltaY(aEvent->deltaY)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
/* mozilla::WheelHandlingUtils */
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
WheelHandlingUtils::CanScrollInRange(nscoord aMin, nscoord aValue, nscoord aMax,
|
|
|
|
double aDirection)
|
|
|
|
{
|
|
|
|
return aDirection > 0.0 ? aValue < static_cast<double>(aMax) :
|
|
|
|
static_cast<double>(aMin) < aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
WheelHandlingUtils::CanScrollOn(nsIScrollableFrame* aScrollFrame,
|
|
|
|
double aDirectionX, double aDirectionY)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aScrollFrame);
|
|
|
|
NS_ASSERTION(aDirectionX || aDirectionY,
|
|
|
|
"One of the delta values must be non-zero at least");
|
|
|
|
|
|
|
|
nsPoint scrollPt = aScrollFrame->GetScrollPosition();
|
|
|
|
nsRect scrollRange = aScrollFrame->GetScrollRange();
|
|
|
|
uint32_t directions = aScrollFrame->GetPerceivedScrollingDirections();
|
|
|
|
|
|
|
|
return (aDirectionX && (directions & nsIScrollableFrame::HORIZONTAL) &&
|
|
|
|
CanScrollInRange(scrollRange.x, scrollPt.x,
|
|
|
|
scrollRange.XMost(), aDirectionX)) ||
|
|
|
|
(aDirectionY && (directions & nsIScrollableFrame::VERTICAL) &&
|
|
|
|
CanScrollInRange(scrollRange.y, scrollPt.y,
|
|
|
|
scrollRange.YMost(), aDirectionY));
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************/
|
2014-03-31 21:09:22 -07:00
|
|
|
/* mozilla::WheelTransaction */
|
2014-03-31 21:09:22 -07:00
|
|
|
/******************************************************************/
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
nsWeakFrame WheelTransaction::sTargetFrame(nullptr);
|
|
|
|
uint32_t WheelTransaction::sTime = 0;
|
|
|
|
uint32_t WheelTransaction::sMouseMoved = 0;
|
|
|
|
nsITimer* WheelTransaction::sTimer = nullptr;
|
|
|
|
int32_t WheelTransaction::sScrollSeriesCounter = 0;
|
|
|
|
bool WheelTransaction::sOwnScrollbars = false;
|
2014-03-31 21:09:22 -07:00
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ bool
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::OutOfTime(uint32_t aBaseTime, uint32_t aThreshold)
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
uint32_t now = PR_IntervalToMilliseconds(PR_IntervalNow());
|
|
|
|
return (now - aBaseTime > aThreshold);
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ void
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::OwnScrollbars(bool aOwn)
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
sOwnScrollbars = aOwn;
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ void
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::BeginTransaction(nsIFrame* aTargetFrame,
|
|
|
|
WidgetWheelEvent* aEvent)
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!sTargetFrame, "previous transaction is not finished!");
|
2015-09-10 09:59:54 -07:00
|
|
|
MOZ_ASSERT(aEvent->mMessage == eWheel,
|
2014-03-31 21:09:22 -07:00
|
|
|
"Transaction must be started with a wheel event");
|
2014-03-31 21:09:22 -07:00
|
|
|
ScrollbarsForWheel::OwnWheelTransaction(false);
|
2014-03-31 21:09:22 -07:00
|
|
|
sTargetFrame = aTargetFrame;
|
|
|
|
sScrollSeriesCounter = 0;
|
|
|
|
if (!UpdateTransaction(aEvent)) {
|
|
|
|
NS_ERROR("BeginTransaction is called even cannot scroll the frame");
|
|
|
|
EndTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ bool
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::UpdateTransaction(WidgetWheelEvent* aEvent)
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
nsIScrollableFrame* sf = GetTargetFrame()->GetScrollTargetFrame();
|
|
|
|
NS_ENSURE_TRUE(sf, false);
|
|
|
|
|
|
|
|
if (!WheelHandlingUtils::CanScrollOn(sf, aEvent->deltaX, aEvent->deltaY)) {
|
|
|
|
OnFailToScrollTarget();
|
|
|
|
// We should not modify the transaction state when the view will not be
|
|
|
|
// scrolled actually.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetTimeout();
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
if (sScrollSeriesCounter != 0 && OutOfTime(sTime, kScrollSeriesTimeout)) {
|
2014-03-31 21:09:22 -07:00
|
|
|
sScrollSeriesCounter = 0;
|
2014-03-31 21:09:22 -07:00
|
|
|
}
|
2014-03-31 21:09:22 -07:00
|
|
|
sScrollSeriesCounter++;
|
|
|
|
|
|
|
|
// We should use current time instead of WidgetEvent.time.
|
|
|
|
// 1. Some events doesn't have the correct creation time.
|
|
|
|
// 2. If the computer runs slowly by other processes eating the CPU resource,
|
|
|
|
// the event creation time doesn't keep real time.
|
|
|
|
sTime = PR_IntervalToMilliseconds(PR_IntervalNow());
|
|
|
|
sMouseMoved = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ void
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::MayEndTransaction()
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
2014-03-31 21:09:22 -07:00
|
|
|
if (!sOwnScrollbars && ScrollbarsForWheel::IsActive()) {
|
|
|
|
ScrollbarsForWheel::OwnWheelTransaction(true);
|
2014-03-31 21:09:22 -07:00
|
|
|
} else {
|
|
|
|
EndTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ void
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::EndTransaction()
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
2014-03-31 21:09:22 -07:00
|
|
|
if (sTimer) {
|
2014-03-31 21:09:22 -07:00
|
|
|
sTimer->Cancel();
|
2014-03-31 21:09:22 -07:00
|
|
|
}
|
2014-03-31 21:09:22 -07:00
|
|
|
sTargetFrame = nullptr;
|
|
|
|
sScrollSeriesCounter = 0;
|
|
|
|
if (sOwnScrollbars) {
|
|
|
|
sOwnScrollbars = false;
|
2014-03-31 21:09:22 -07:00
|
|
|
ScrollbarsForWheel::OwnWheelTransaction(false);
|
|
|
|
ScrollbarsForWheel::Inactivate();
|
2014-03-31 21:09:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ void
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::OnEvent(WidgetEvent* aEvent)
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
2014-03-31 21:09:22 -07:00
|
|
|
if (!sTargetFrame) {
|
2014-03-31 21:09:22 -07:00
|
|
|
return;
|
2014-03-31 21:09:22 -07:00
|
|
|
}
|
2014-03-31 21:09:22 -07:00
|
|
|
|
|
|
|
if (OutOfTime(sTime, GetTimeoutTime())) {
|
|
|
|
// Even if the scroll event which is handled after timeout, but onTimeout
|
|
|
|
// was not fired by timer, then the scroll event will scroll old frame,
|
|
|
|
// therefore, we should call OnTimeout here and ensure to finish the old
|
|
|
|
// transaction.
|
|
|
|
OnTimeout(nullptr, nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-21 18:34:51 -07:00
|
|
|
switch (aEvent->mMessage) {
|
2015-09-10 09:59:54 -07:00
|
|
|
case eWheel:
|
2014-03-31 21:09:22 -07:00
|
|
|
if (sMouseMoved != 0 &&
|
|
|
|
OutOfTime(sMouseMoved, GetIgnoreMoveDelayTime())) {
|
|
|
|
// Terminate the current mousewheel transaction if the mouse moved more
|
|
|
|
// than ignoremovedelay milliseconds ago
|
|
|
|
EndTransaction();
|
|
|
|
}
|
|
|
|
return;
|
2015-08-28 16:58:29 -07:00
|
|
|
case eMouseMove:
|
2015-09-01 23:08:02 -07:00
|
|
|
case eDragOver: {
|
2014-03-31 21:09:22 -07:00
|
|
|
WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
|
|
|
|
if (mouseEvent->IsReal()) {
|
|
|
|
// If the cursor is moving to be outside the frame,
|
|
|
|
// terminate the scrollwheel transaction.
|
|
|
|
nsIntPoint pt = GetScreenPoint(mouseEvent);
|
|
|
|
nsIntRect r = sTargetFrame->GetScreenRectExternal();
|
|
|
|
if (!r.Contains(pt)) {
|
|
|
|
EndTransaction();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the cursor is moving inside the frame, and it is less than
|
|
|
|
// ignoremovedelay milliseconds since the last scroll operation, ignore
|
|
|
|
// the mouse move; otherwise, record the current mouse move time to be
|
|
|
|
// checked later
|
2014-03-31 21:09:22 -07:00
|
|
|
if (!sMouseMoved && OutOfTime(sTime, GetIgnoreMoveDelayTime())) {
|
|
|
|
sMouseMoved = PR_IntervalToMilliseconds(PR_IntervalNow());
|
2014-03-31 21:09:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2015-08-28 16:58:27 -07:00
|
|
|
case eKeyPress:
|
2015-08-28 16:58:27 -07:00
|
|
|
case eKeyUp:
|
2015-08-28 16:58:27 -07:00
|
|
|
case eKeyDown:
|
2015-08-28 16:58:30 -07:00
|
|
|
case eMouseUp:
|
2015-08-28 16:58:30 -07:00
|
|
|
case eMouseDown:
|
2015-08-28 16:58:31 -07:00
|
|
|
case eMouseDoubleClick:
|
2015-08-28 16:58:32 -07:00
|
|
|
case eMouseClick:
|
2015-08-31 08:20:06 -07:00
|
|
|
case eContextMenu:
|
2015-09-01 23:08:01 -07:00
|
|
|
case eDrop:
|
2014-03-31 21:09:22 -07:00
|
|
|
EndTransaction();
|
|
|
|
return;
|
2015-08-26 05:56:59 -07:00
|
|
|
default:
|
|
|
|
break;
|
2014-03-31 21:09:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ void
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::Shutdown()
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
NS_IF_RELEASE(sTimer);
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ void
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::OnFailToScrollTarget()
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(sTargetFrame, "We don't have mouse scrolling transaction");
|
|
|
|
|
|
|
|
if (Preferences::GetBool("test.mousescroll", false)) {
|
|
|
|
// This event is used for automated tests, see bug 442774.
|
|
|
|
nsContentUtils::DispatchTrustedEvent(
|
|
|
|
sTargetFrame->GetContent()->OwnerDoc(),
|
|
|
|
sTargetFrame->GetContent(),
|
|
|
|
NS_LITERAL_STRING("MozMouseScrollFailed"),
|
|
|
|
true, true);
|
|
|
|
}
|
|
|
|
// The target frame might be destroyed in the event handler, at that time,
|
|
|
|
// we need to finish the current transaction
|
|
|
|
if (!sTargetFrame) {
|
|
|
|
EndTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ void
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::OnTimeout(nsITimer* aTimer, void* aClosure)
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
if (!sTargetFrame) {
|
|
|
|
// The transaction target was destroyed already
|
|
|
|
EndTransaction();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Store the sTargetFrame, the variable becomes null in EndTransaction.
|
|
|
|
nsIFrame* frame = sTargetFrame;
|
|
|
|
// We need to finish current transaction before DOM event firing. Because
|
|
|
|
// the next DOM event might create strange situation for us.
|
|
|
|
MayEndTransaction();
|
|
|
|
|
|
|
|
if (Preferences::GetBool("test.mousescroll", false)) {
|
|
|
|
// This event is used for automated tests, see bug 442774.
|
|
|
|
nsContentUtils::DispatchTrustedEvent(
|
|
|
|
frame->GetContent()->OwnerDoc(),
|
|
|
|
frame->GetContent(),
|
|
|
|
NS_LITERAL_STRING("MozMouseScrollTransactionTimeout"),
|
|
|
|
true, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ void
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::SetTimeout()
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
if (!sTimer) {
|
|
|
|
nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID);
|
2014-03-31 21:09:22 -07:00
|
|
|
if (!timer) {
|
2014-03-31 21:09:22 -07:00
|
|
|
return;
|
2014-03-31 21:09:22 -07:00
|
|
|
}
|
2014-03-31 21:09:22 -07:00
|
|
|
timer.swap(sTimer);
|
|
|
|
}
|
|
|
|
sTimer->Cancel();
|
2014-03-31 21:09:22 -07:00
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
sTimer->InitWithFuncCallback(OnTimeout, nullptr, GetTimeoutTime(),
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
2014-03-31 21:09:22 -07:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "nsITimer::InitWithFuncCallback failed");
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ nsIntPoint
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::GetScreenPoint(WidgetGUIEvent* aEvent)
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aEvent, "aEvent is null");
|
|
|
|
NS_ASSERTION(aEvent->widget, "aEvent-widget is null");
|
2015-02-04 12:21:03 -08:00
|
|
|
return LayoutDeviceIntPoint::ToUntyped(aEvent->refPoint +
|
|
|
|
aEvent->widget->WidgetToScreenOffset());
|
2014-03-31 21:09:22 -07:00
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ uint32_t
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::GetTimeoutTime()
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
return Preferences::GetUint("mousewheel.transaction.timeout", 1500);
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ uint32_t
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::GetIgnoreMoveDelayTime()
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
return Preferences::GetUint("mousewheel.transaction.ignoremovedelay", 100);
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ DeltaValues
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::AccelerateWheelDelta(WidgetWheelEvent* aEvent,
|
|
|
|
bool aAllowScrollSpeedOverride)
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
DeltaValues result(aEvent);
|
|
|
|
|
|
|
|
// Don't accelerate the delta values if the event isn't line scrolling.
|
|
|
|
if (aEvent->deltaMode != nsIDOMWheelEvent::DOM_DELTA_LINE) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aAllowScrollSpeedOverride) {
|
|
|
|
result = OverrideSystemScrollSpeed(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Accelerate by the sScrollSeriesCounter
|
|
|
|
int32_t start = GetAccelerationStart();
|
|
|
|
if (start >= 0 && sScrollSeriesCounter >= start) {
|
|
|
|
int32_t factor = GetAccelerationFactor();
|
|
|
|
if (factor > 0) {
|
|
|
|
result.deltaX = ComputeAcceleratedWheelDelta(result.deltaX, factor);
|
|
|
|
result.deltaY = ComputeAcceleratedWheelDelta(result.deltaY, factor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ double
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::ComputeAcceleratedWheelDelta(double aDelta,
|
|
|
|
int32_t aFactor)
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
if (aDelta == 0.0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (aDelta * sScrollSeriesCounter * (double)aFactor / 10);
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ int32_t
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::GetAccelerationStart()
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
return Preferences::GetInt("mousewheel.acceleration.start", -1);
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ int32_t
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::GetAccelerationFactor()
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
return Preferences::GetInt("mousewheel.acceleration.factor", -1);
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ DeltaValues
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::OverrideSystemScrollSpeed(WidgetWheelEvent* aEvent)
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(sTargetFrame, "We don't have mouse scrolling transaction");
|
|
|
|
MOZ_ASSERT(aEvent->deltaMode == nsIDOMWheelEvent::DOM_DELTA_LINE);
|
|
|
|
|
|
|
|
// If the event doesn't scroll to both X and Y, we don't need to do anything
|
|
|
|
// here.
|
|
|
|
if (!aEvent->deltaX && !aEvent->deltaY) {
|
|
|
|
return DeltaValues(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We shouldn't override the scrolling speed on non root scroll frame.
|
|
|
|
if (sTargetFrame !=
|
|
|
|
sTargetFrame->PresContext()->PresShell()->GetRootScrollFrame()) {
|
|
|
|
return DeltaValues(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the overridden speed to nsIWidget. The widget can check the
|
|
|
|
// conditions (e.g., checking the prefs, and also whether the user customized
|
|
|
|
// the system settings of the mouse wheel scrolling or not), and can limit
|
|
|
|
// the speed for preventing the unexpected high speed scrolling.
|
|
|
|
nsCOMPtr<nsIWidget> widget(sTargetFrame->GetNearestWidget());
|
|
|
|
NS_ENSURE_TRUE(widget, DeltaValues(aEvent));
|
|
|
|
DeltaValues overriddenDeltaValues(0.0, 0.0);
|
|
|
|
nsresult rv =
|
|
|
|
widget->OverrideSystemMouseScrollSpeed(aEvent->deltaX, aEvent->deltaY,
|
|
|
|
overriddenDeltaValues.deltaX,
|
|
|
|
overriddenDeltaValues.deltaY);
|
|
|
|
return NS_FAILED(rv) ? DeltaValues(aEvent) : overriddenDeltaValues;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************/
|
2014-03-31 21:09:22 -07:00
|
|
|
/* mozilla::ScrollbarsForWheel */
|
2014-03-31 21:09:22 -07:00
|
|
|
/******************************************************************/
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
const DeltaValues ScrollbarsForWheel::directions[kNumberOfTargets] = {
|
2014-03-31 21:09:22 -07:00
|
|
|
DeltaValues(-1, 0), DeltaValues(+1, 0), DeltaValues(0, -1), DeltaValues(0, +1)
|
|
|
|
};
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
nsWeakFrame ScrollbarsForWheel::sActiveOwner = nullptr;
|
|
|
|
nsWeakFrame ScrollbarsForWheel::sActivatedScrollTargets[kNumberOfTargets] = {
|
2014-03-31 21:09:22 -07:00
|
|
|
nullptr, nullptr, nullptr, nullptr
|
|
|
|
};
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
bool ScrollbarsForWheel::sHadWheelStart = false;
|
|
|
|
bool ScrollbarsForWheel::sOwnWheelTransaction = false;
|
2014-03-31 21:09:22 -07:00
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ void
|
2014-03-31 21:09:23 -07:00
|
|
|
ScrollbarsForWheel::PrepareToScrollText(EventStateManager* aESM,
|
2014-03-31 21:09:22 -07:00
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
WidgetWheelEvent* aEvent)
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
2015-09-10 09:59:55 -07:00
|
|
|
if (aEvent->mMessage == eWheelOperationStart) {
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::OwnScrollbars(false);
|
2014-03-31 21:09:22 -07:00
|
|
|
if (!IsActive()) {
|
|
|
|
TemporarilyActivateAllPossibleScrollTargets(aESM, aTargetFrame, aEvent);
|
|
|
|
sHadWheelStart = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DeactivateAllTemporarilyActivatedScrollTargets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ void
|
2014-03-31 21:09:22 -07:00
|
|
|
ScrollbarsForWheel::SetActiveScrollTarget(nsIScrollableFrame* aScrollTarget)
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
if (!sHadWheelStart) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-13 22:40:53 -08:00
|
|
|
nsIScrollbarMediator* scrollbarMediator = do_QueryFrame(aScrollTarget);
|
|
|
|
if (!scrollbarMediator) {
|
2014-03-31 21:09:22 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
sHadWheelStart = false;
|
|
|
|
sActiveOwner = do_QueryFrame(aScrollTarget);
|
2014-02-13 22:40:53 -08:00
|
|
|
scrollbarMediator->ScrollbarActivityStarted();
|
2014-03-31 21:09:22 -07:00
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ void
|
2014-03-31 21:09:22 -07:00
|
|
|
ScrollbarsForWheel::MayInactivate()
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
2014-03-31 21:09:22 -07:00
|
|
|
if (!sOwnWheelTransaction && WheelTransaction::GetTargetFrame()) {
|
|
|
|
WheelTransaction::OwnScrollbars(true);
|
2014-03-31 21:09:22 -07:00
|
|
|
} else {
|
|
|
|
Inactivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ void
|
2014-03-31 21:09:22 -07:00
|
|
|
ScrollbarsForWheel::Inactivate()
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
2014-02-13 22:40:53 -08:00
|
|
|
nsIScrollbarMediator* scrollbarMediator = do_QueryFrame(sActiveOwner);
|
|
|
|
if (scrollbarMediator) {
|
|
|
|
scrollbarMediator->ScrollbarActivityStopped();
|
2014-03-31 21:09:22 -07:00
|
|
|
}
|
|
|
|
sActiveOwner = nullptr;
|
|
|
|
DeactivateAllTemporarilyActivatedScrollTargets();
|
|
|
|
if (sOwnWheelTransaction) {
|
|
|
|
sOwnWheelTransaction = false;
|
2014-03-31 21:09:22 -07:00
|
|
|
WheelTransaction::OwnScrollbars(false);
|
|
|
|
WheelTransaction::EndTransaction();
|
2014-03-31 21:09:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ bool
|
2014-03-31 21:09:22 -07:00
|
|
|
ScrollbarsForWheel::IsActive()
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
if (sActiveOwner) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < kNumberOfTargets; ++i) {
|
|
|
|
if (sActivatedScrollTargets[i]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ void
|
2014-03-31 21:09:22 -07:00
|
|
|
ScrollbarsForWheel::OwnWheelTransaction(bool aOwn)
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
sOwnWheelTransaction = aOwn;
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ void
|
2014-03-31 21:09:22 -07:00
|
|
|
ScrollbarsForWheel::TemporarilyActivateAllPossibleScrollTargets(
|
2014-03-31 21:09:23 -07:00
|
|
|
EventStateManager* aESM,
|
2014-03-31 21:09:22 -07:00
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
WidgetWheelEvent* aEvent)
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < kNumberOfTargets; i++) {
|
|
|
|
const DeltaValues *dir = &directions[i];
|
|
|
|
nsWeakFrame* scrollTarget = &sActivatedScrollTargets[i];
|
|
|
|
MOZ_ASSERT(!*scrollTarget, "scroll target still temporarily activated!");
|
|
|
|
nsIScrollableFrame* target =
|
2014-03-31 21:09:22 -07:00
|
|
|
aESM->ComputeScrollTarget(aTargetFrame, dir->deltaX, dir->deltaY, aEvent,
|
2014-03-31 21:09:23 -07:00
|
|
|
EventStateManager::COMPUTE_DEFAULT_ACTION_TARGET);
|
2014-02-13 22:40:53 -08:00
|
|
|
nsIScrollbarMediator* scrollbarMediator = do_QueryFrame(target);
|
|
|
|
if (scrollbarMediator) {
|
2014-03-31 21:09:22 -07:00
|
|
|
nsIFrame* targetFrame = do_QueryFrame(target);
|
|
|
|
*scrollTarget = targetFrame;
|
2014-02-13 22:40:53 -08:00
|
|
|
scrollbarMediator->ScrollbarActivityStarted();
|
2014-03-31 21:09:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-31 21:09:22 -07:00
|
|
|
/* static */ void
|
2014-03-31 21:09:22 -07:00
|
|
|
ScrollbarsForWheel::DeactivateAllTemporarilyActivatedScrollTargets()
|
2014-03-31 21:09:22 -07:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < kNumberOfTargets; i++) {
|
|
|
|
nsWeakFrame* scrollTarget = &sActivatedScrollTargets[i];
|
|
|
|
if (*scrollTarget) {
|
2014-02-13 22:40:53 -08:00
|
|
|
nsIScrollbarMediator* scrollbarMediator = do_QueryFrame(*scrollTarget);
|
|
|
|
if (scrollbarMediator) {
|
|
|
|
scrollbarMediator->ScrollbarActivityStopped();
|
2014-03-31 21:09:22 -07:00
|
|
|
}
|
|
|
|
*scrollTarget = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-31 21:09:22 -07:00
|
|
|
|
|
|
|
} // namespace mozilla
|