2015-05-03 21:37:00 +00: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: */
|
|
|
|
/* 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 "AccessibleCaretEventHub.h"
|
|
|
|
|
|
|
|
#include "AccessibleCaretLogger.h"
|
|
|
|
#include "AccessibleCaretManager.h"
|
2015-06-04 20:51:10 +00:00
|
|
|
#include "Layers.h"
|
2015-05-03 21:37:00 +00:00
|
|
|
#include "gfxPrefs.h"
|
2016-08-29 07:36:45 +00:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2015-05-03 21:37:00 +00:00
|
|
|
#include "mozilla/MouseEvents.h"
|
|
|
|
#include "mozilla/TextEvents.h"
|
|
|
|
#include "mozilla/TouchEvents.h"
|
2015-10-02 15:10:29 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2015-09-10 10:24:34 +00:00
|
|
|
#include "nsCanvasFrame.h"
|
2015-05-03 21:37:00 +00:00
|
|
|
#include "nsDocShell.h"
|
|
|
|
#include "nsFocusManager.h"
|
|
|
|
#include "nsFrameSelection.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
#undef AC_LOG
|
|
|
|
#define AC_LOG(message, ...) \
|
|
|
|
AC_LOG_BASE("AccessibleCaretEventHub (%p): " message, this, ##__VA_ARGS__);
|
|
|
|
|
|
|
|
#undef AC_LOGV
|
|
|
|
#define AC_LOGV(message, ...) \
|
|
|
|
AC_LOGV_BASE("AccessibleCaretEventHub (%p): " message, this, ##__VA_ARGS__);
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(AccessibleCaretEventHub, nsIReflowObserver, nsIScrollObserver,
|
|
|
|
nsISelectionListener, nsISupportsWeakReference);
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// NoActionState
|
|
|
|
//
|
|
|
|
class AccessibleCaretEventHub::NoActionState
|
|
|
|
: public AccessibleCaretEventHub::State
|
|
|
|
{
|
|
|
|
public:
|
2015-10-05 08:52:29 +00:00
|
|
|
virtual const char* Name() const override { return "NoActionState"; }
|
2015-05-03 21:37:00 +00:00
|
|
|
|
|
|
|
virtual nsEventStatus OnPress(AccessibleCaretEventHub* aContext,
|
2016-08-14 13:39:30 +00:00
|
|
|
const nsPoint& aPoint, int32_t aTouchId,
|
|
|
|
EventClassID aEventClass) override
|
2015-05-03 21:37:00 +00:00
|
|
|
{
|
|
|
|
nsEventStatus rv = nsEventStatus_eIgnore;
|
|
|
|
|
2016-08-14 13:39:30 +00:00
|
|
|
if (NS_SUCCEEDED(aContext->mManager->PressCaret(aPoint, aEventClass))) {
|
2015-05-03 21:37:00 +00:00
|
|
|
aContext->SetState(aContext->PressCaretState());
|
|
|
|
rv = nsEventStatus_eConsumeNoDefault;
|
|
|
|
} else {
|
|
|
|
aContext->SetState(aContext->PressNoCaretState());
|
|
|
|
}
|
|
|
|
|
|
|
|
aContext->mPressPoint = aPoint;
|
|
|
|
aContext->mActiveTouchId = aTouchId;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnScrollStart(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
aContext->mManager->OnScrollStart();
|
|
|
|
aContext->SetState(aContext->ScrollState());
|
|
|
|
}
|
|
|
|
|
2016-02-29 07:51:44 +00:00
|
|
|
virtual void OnScrollPositionChanged(
|
|
|
|
AccessibleCaretEventHub* aContext) override
|
2015-05-03 21:37:00 +00:00
|
|
|
{
|
|
|
|
aContext->mManager->OnScrollPositionChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnSelectionChanged(AccessibleCaretEventHub* aContext,
|
|
|
|
nsIDOMDocument* aDoc, nsISelection* aSel,
|
|
|
|
int16_t aReason) override
|
|
|
|
{
|
|
|
|
aContext->mManager->OnSelectionChanged(aDoc, aSel, aReason);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnBlur(AccessibleCaretEventHub* aContext,
|
|
|
|
bool aIsLeavingDocument) override
|
|
|
|
{
|
|
|
|
aContext->mManager->OnBlur();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnReflow(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
aContext->mManager->OnReflow();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Enter(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
aContext->mPressPoint = nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
aContext->mActiveTouchId = kInvalidTouchId;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// PressCaretState: Always consume the event since we've pressed on the caret.
|
|
|
|
//
|
|
|
|
class AccessibleCaretEventHub::PressCaretState
|
|
|
|
: public AccessibleCaretEventHub::State
|
|
|
|
{
|
|
|
|
public:
|
2015-10-05 08:52:29 +00:00
|
|
|
virtual const char* Name() const override { return "PressCaretState"; }
|
2015-05-03 21:37:00 +00:00
|
|
|
|
|
|
|
virtual nsEventStatus OnMove(AccessibleCaretEventHub* aContext,
|
|
|
|
const nsPoint& aPoint) override
|
|
|
|
{
|
|
|
|
if (aContext->MoveDistanceIsLarge(aPoint)) {
|
|
|
|
if (NS_SUCCEEDED(aContext->mManager->DragCaret(aPoint))) {
|
|
|
|
aContext->SetState(aContext->DragCaretState());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsEventStatus OnRelease(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
aContext->mManager->ReleaseCaret();
|
|
|
|
aContext->mManager->TapCaret(aContext->mPressPoint);
|
|
|
|
aContext->SetState(aContext->NoActionState());
|
|
|
|
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsEventStatus OnLongTap(AccessibleCaretEventHub* aContext,
|
|
|
|
const nsPoint& aPoint) override
|
|
|
|
{
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// DragCaretState: Always consume the event since we've pressed on the caret.
|
|
|
|
//
|
|
|
|
class AccessibleCaretEventHub::DragCaretState
|
|
|
|
: public AccessibleCaretEventHub::State
|
|
|
|
{
|
|
|
|
public:
|
2015-10-05 08:52:29 +00:00
|
|
|
virtual const char* Name() const override { return "DragCaretState"; }
|
2015-05-03 21:37:00 +00:00
|
|
|
|
|
|
|
virtual nsEventStatus OnMove(AccessibleCaretEventHub* aContext,
|
|
|
|
const nsPoint& aPoint) override
|
|
|
|
{
|
|
|
|
aContext->mManager->DragCaret(aPoint);
|
|
|
|
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsEventStatus OnRelease(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
aContext->mManager->ReleaseCaret();
|
|
|
|
aContext->SetState(aContext->NoActionState());
|
|
|
|
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// PressNoCaretState
|
|
|
|
//
|
|
|
|
class AccessibleCaretEventHub::PressNoCaretState
|
|
|
|
: public AccessibleCaretEventHub::State
|
|
|
|
{
|
|
|
|
public:
|
2015-10-05 08:52:29 +00:00
|
|
|
virtual const char* Name() const override { return "PressNoCaretState"; }
|
2015-05-03 21:37:00 +00:00
|
|
|
|
|
|
|
virtual nsEventStatus OnMove(AccessibleCaretEventHub* aContext,
|
|
|
|
const nsPoint& aPoint) override
|
|
|
|
{
|
|
|
|
if (aContext->MoveDistanceIsLarge(aPoint)) {
|
|
|
|
aContext->SetState(aContext->NoActionState());
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsEventStatus OnRelease(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
aContext->SetState(aContext->NoActionState());
|
|
|
|
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsEventStatus OnLongTap(AccessibleCaretEventHub* aContext,
|
|
|
|
const nsPoint& aPoint) override
|
|
|
|
{
|
|
|
|
aContext->SetState(aContext->LongTapState());
|
|
|
|
|
|
|
|
return aContext->GetState()->OnLongTap(aContext, aPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnScrollStart(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
aContext->mManager->OnScrollStart();
|
|
|
|
aContext->SetState(aContext->ScrollState());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnBlur(AccessibleCaretEventHub* aContext,
|
|
|
|
bool aIsLeavingDocument) override
|
|
|
|
{
|
|
|
|
aContext->mManager->OnBlur();
|
|
|
|
if (aIsLeavingDocument) {
|
|
|
|
aContext->SetState(aContext->NoActionState());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnSelectionChanged(AccessibleCaretEventHub* aContext,
|
|
|
|
nsIDOMDocument* aDoc, nsISelection* aSel,
|
|
|
|
int16_t aReason) override
|
|
|
|
{
|
|
|
|
aContext->mManager->OnSelectionChanged(aDoc, aSel, aReason);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnReflow(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
aContext->mManager->OnReflow();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Enter(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
aContext->LaunchLongTapInjector();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Leave(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
aContext->CancelLongTapInjector();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// ScrollState
|
|
|
|
//
|
|
|
|
class AccessibleCaretEventHub::ScrollState
|
|
|
|
: public AccessibleCaretEventHub::State
|
|
|
|
{
|
|
|
|
public:
|
2015-10-05 08:52:29 +00:00
|
|
|
virtual const char* Name() const override { return "ScrollState"; }
|
2015-05-03 21:37:00 +00:00
|
|
|
|
|
|
|
virtual void OnScrollEnd(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
aContext->SetState(aContext->PostScrollState());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnBlur(AccessibleCaretEventHub* aContext,
|
|
|
|
bool aIsLeavingDocument) override
|
|
|
|
{
|
|
|
|
aContext->mManager->OnBlur();
|
|
|
|
if (aIsLeavingDocument) {
|
|
|
|
aContext->SetState(aContext->NoActionState());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2015-10-05 08:52:29 +00:00
|
|
|
// PostScrollState: In this state, we are waiting for another APZ start or press
|
|
|
|
// event.
|
2015-05-03 21:37:00 +00:00
|
|
|
//
|
|
|
|
class AccessibleCaretEventHub::PostScrollState
|
|
|
|
: public AccessibleCaretEventHub::State
|
|
|
|
{
|
|
|
|
public:
|
2015-10-05 08:52:29 +00:00
|
|
|
virtual const char* Name() const override { return "PostScrollState"; }
|
2015-05-03 21:37:00 +00:00
|
|
|
|
|
|
|
virtual nsEventStatus OnPress(AccessibleCaretEventHub* aContext,
|
2016-08-14 13:39:30 +00:00
|
|
|
const nsPoint& aPoint, int32_t aTouchId,
|
|
|
|
EventClassID aEventClass) override
|
2015-05-03 21:37:00 +00:00
|
|
|
{
|
|
|
|
aContext->mManager->OnScrollEnd();
|
|
|
|
aContext->SetState(aContext->NoActionState());
|
|
|
|
|
2016-08-14 13:39:30 +00:00
|
|
|
return aContext->GetState()->OnPress(aContext, aPoint, aTouchId,
|
|
|
|
aEventClass);
|
2015-05-03 21:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnScrollStart(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
aContext->SetState(aContext->ScrollState());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnScrollEnd(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
aContext->mManager->OnScrollEnd();
|
|
|
|
aContext->SetState(aContext->NoActionState());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnBlur(AccessibleCaretEventHub* aContext,
|
|
|
|
bool aIsLeavingDocument) override
|
|
|
|
{
|
|
|
|
aContext->mManager->OnBlur();
|
|
|
|
if (aIsLeavingDocument) {
|
|
|
|
aContext->SetState(aContext->NoActionState());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Enter(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
// Launch the injector to leave PostScrollState.
|
|
|
|
aContext->LaunchScrollEndInjector();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Leave(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
aContext->CancelScrollEndInjector();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// LongTapState
|
|
|
|
//
|
|
|
|
class AccessibleCaretEventHub::LongTapState
|
|
|
|
: public AccessibleCaretEventHub::State
|
|
|
|
{
|
|
|
|
public:
|
2015-10-05 08:52:29 +00:00
|
|
|
virtual const char* Name() const override { return "LongTapState"; }
|
2015-05-03 21:37:00 +00:00
|
|
|
|
|
|
|
virtual nsEventStatus OnLongTap(AccessibleCaretEventHub* aContext,
|
|
|
|
const nsPoint& aPoint) override
|
|
|
|
{
|
2016-08-03 16:00:19 +00:00
|
|
|
// In general text selection is lower-priority than the context menu. If
|
|
|
|
// we consume this long-press event, then it prevents the context menu from
|
|
|
|
// showing up on desktop Firefox (because that happens on long-tap-up, if
|
|
|
|
// the long-tap was not cancelled). So we return eIgnore instead.
|
|
|
|
aContext->mManager->SelectWordOrShortcut(aPoint);
|
|
|
|
return nsEventStatus_eIgnore;
|
2016-01-25 07:50:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsEventStatus OnRelease(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
2015-05-03 21:37:00 +00:00
|
|
|
aContext->SetState(aContext->NoActionState());
|
|
|
|
|
2016-01-25 07:50:28 +00:00
|
|
|
// Do not consume the release since the press is not consumed in
|
|
|
|
// PressNoCaretState either.
|
|
|
|
return nsEventStatus_eIgnore;
|
2015-05-03 21:37:00 +00:00
|
|
|
}
|
|
|
|
|
2016-02-08 08:08:45 +00:00
|
|
|
virtual void OnScrollStart(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
aContext->mManager->OnScrollStart();
|
|
|
|
aContext->SetState(aContext->ScrollState());
|
|
|
|
}
|
|
|
|
|
2015-05-03 21:37:00 +00:00
|
|
|
virtual void OnReflow(AccessibleCaretEventHub* aContext) override
|
|
|
|
{
|
|
|
|
aContext->mManager->OnReflow();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Implementation of AccessibleCaretEventHub methods
|
|
|
|
//
|
|
|
|
AccessibleCaretEventHub::State*
|
|
|
|
AccessibleCaretEventHub::GetState() const
|
|
|
|
{
|
|
|
|
return mState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccessibleCaretEventHub::SetState(State* aState)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aState);
|
|
|
|
|
|
|
|
AC_LOG("%s -> %s", mState->Name(), aState->Name());
|
|
|
|
|
|
|
|
mState->Leave(this);
|
|
|
|
mState = aState;
|
|
|
|
mState->Enter(this);
|
|
|
|
}
|
|
|
|
|
2015-07-30 12:07:00 +00:00
|
|
|
MOZ_IMPL_STATE_CLASS_GETTER(NoActionState)
|
|
|
|
MOZ_IMPL_STATE_CLASS_GETTER(PressCaretState)
|
|
|
|
MOZ_IMPL_STATE_CLASS_GETTER(DragCaretState)
|
|
|
|
MOZ_IMPL_STATE_CLASS_GETTER(PressNoCaretState)
|
|
|
|
MOZ_IMPL_STATE_CLASS_GETTER(ScrollState)
|
|
|
|
MOZ_IMPL_STATE_CLASS_GETTER(PostScrollState)
|
|
|
|
MOZ_IMPL_STATE_CLASS_GETTER(LongTapState)
|
2015-05-03 21:37:00 +00:00
|
|
|
|
2016-10-04 13:31:15 +00:00
|
|
|
bool AccessibleCaretEventHub::sUseLongTapInjector = false;
|
2015-10-02 15:10:29 +00:00
|
|
|
|
2015-11-16 10:16:43 +00:00
|
|
|
AccessibleCaretEventHub::AccessibleCaretEventHub(nsIPresShell* aPresShell)
|
|
|
|
: mPresShell(aPresShell)
|
2015-05-03 21:37:00 +00:00
|
|
|
{
|
2015-10-02 15:10:29 +00:00
|
|
|
static bool prefsAdded = false;
|
|
|
|
if (!prefsAdded) {
|
2016-02-29 07:51:44 +00:00
|
|
|
Preferences::AddBoolVarCache(
|
|
|
|
&sUseLongTapInjector, "layout.accessiblecaret.use_long_tap_injector");
|
2015-10-02 15:10:29 +00:00
|
|
|
prefsAdded = true;
|
|
|
|
}
|
2015-05-03 21:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AccessibleCaretEventHub::~AccessibleCaretEventHub()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-11-16 10:16:43 +00:00
|
|
|
AccessibleCaretEventHub::Init()
|
2015-05-03 21:37:00 +00:00
|
|
|
{
|
2016-07-11 12:16:39 +00:00
|
|
|
if (mInitialized && mManager) {
|
|
|
|
mManager->OnFrameReconstruction();
|
|
|
|
}
|
|
|
|
|
2015-11-16 10:16:43 +00:00
|
|
|
if (mInitialized || !mPresShell || !mPresShell->GetCanvasFrame() ||
|
|
|
|
!mPresShell->GetCanvasFrame()->GetCustomContentContainer()) {
|
2015-05-03 21:37:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Without nsAutoScriptBlocker, the script might be run after constructing
|
|
|
|
// mFirstCaret in AccessibleCaretManager's constructor, which might destructs
|
|
|
|
// the whole frame tree. Therefore we'll fail to construct mSecondCaret
|
|
|
|
// because we cannot get root frame or canvas frame from mPresShell to inject
|
|
|
|
// anonymous content. To avoid that, we protect Init() by nsAutoScriptBlocker.
|
|
|
|
// To reproduce, run "./mach crashtest layout/base/crashtests/897852.html"
|
|
|
|
// without the following scriptBlocker.
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
|
|
|
|
nsPresContext* presContext = mPresShell->GetPresContext();
|
|
|
|
MOZ_ASSERT(presContext, "PresContext should be given in PresShell::Init()");
|
|
|
|
|
|
|
|
nsIDocShell* docShell = presContext->GetDocShell();
|
|
|
|
if (!docShell) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
docShell->AddWeakReflowObserver(this);
|
|
|
|
docShell->AddWeakScrollObserver(this);
|
|
|
|
|
|
|
|
mDocShell = static_cast<nsDocShell*>(docShell);
|
|
|
|
|
2015-10-02 15:10:29 +00:00
|
|
|
if (sUseLongTapInjector) {
|
|
|
|
mLongTapInjectorTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
}
|
|
|
|
|
2015-05-03 21:37:00 +00:00
|
|
|
mScrollEndInjectorTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
|
|
|
|
mManager = MakeUnique<AccessibleCaretManager>(mPresShell);
|
|
|
|
|
|
|
|
mInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccessibleCaretEventHub::Terminate()
|
|
|
|
{
|
|
|
|
if (!mInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsDocShell> docShell(mDocShell.get());
|
2015-05-03 21:37:00 +00:00
|
|
|
if (docShell) {
|
|
|
|
docShell->RemoveWeakReflowObserver(this);
|
|
|
|
docShell->RemoveWeakScrollObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mLongTapInjectorTimer) {
|
|
|
|
mLongTapInjectorTimer->Cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mScrollEndInjectorTimer) {
|
|
|
|
mScrollEndInjectorTimer->Cancel();
|
|
|
|
}
|
|
|
|
|
2016-02-15 07:12:35 +00:00
|
|
|
mManager->Terminate();
|
2015-05-03 21:37:00 +00:00
|
|
|
mPresShell = nullptr;
|
|
|
|
mInitialized = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
|
|
|
AccessibleCaretEventHub::HandleEvent(WidgetEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
if (!mInitialized) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2016-02-19 10:21:16 +00:00
|
|
|
MOZ_ASSERT(mRefCnt.get() > 1, "Expect caller holds us as well!");
|
|
|
|
|
2015-05-03 21:37:00 +00:00
|
|
|
switch (aEvent->mClass) {
|
2016-02-29 07:51:44 +00:00
|
|
|
case eMouseEventClass:
|
|
|
|
status = HandleMouseEvent(aEvent->AsMouseEvent());
|
|
|
|
break;
|
2015-05-03 21:37:00 +00:00
|
|
|
|
2016-02-29 07:51:44 +00:00
|
|
|
case eTouchEventClass:
|
|
|
|
status = HandleTouchEvent(aEvent->AsTouchEvent());
|
|
|
|
break;
|
2015-05-03 21:37:00 +00:00
|
|
|
|
2016-02-29 07:51:44 +00:00
|
|
|
case eKeyboardEventClass:
|
|
|
|
status = HandleKeyboardEvent(aEvent->AsKeyboardEvent());
|
|
|
|
break;
|
2015-05-03 21:37:00 +00:00
|
|
|
|
2016-02-29 07:51:44 +00:00
|
|
|
default:
|
|
|
|
break;
|
2015-05-03 21:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
|
|
|
AccessibleCaretEventHub::HandleMouseEvent(WidgetMouseEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsEventStatus rv = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
if (aEvent->button != WidgetMouseEvent::eLeftButton) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2016-02-29 07:51:44 +00:00
|
|
|
int32_t id =
|
|
|
|
(mActiveTouchId == kInvalidTouchId ? kDefaultTouchId : mActiveTouchId);
|
2015-05-03 21:37:00 +00:00
|
|
|
nsPoint point = GetMouseEventPosition(aEvent);
|
|
|
|
|
2016-10-03 12:57:44 +00:00
|
|
|
if (aEvent->mMessage == eMouseDown ||
|
|
|
|
aEvent->mMessage == eMouseUp ||
|
|
|
|
aEvent->mMessage == eMouseClick ||
|
|
|
|
aEvent->mMessage == eMouseDoubleClick ||
|
|
|
|
aEvent->mMessage == eMouseLongTap) {
|
|
|
|
// Don't reset the source on mouse movement since that can
|
|
|
|
// happen anytime, even randomly during a touch sequence.
|
|
|
|
mManager->SetLastInputSource(aEvent->inputSource);
|
|
|
|
}
|
|
|
|
|
2015-08-22 01:34:51 +00:00
|
|
|
switch (aEvent->mMessage) {
|
2016-02-29 07:51:44 +00:00
|
|
|
case eMouseDown:
|
|
|
|
AC_LOGV("Before eMouseDown, state: %s", mState->Name());
|
2016-08-14 13:39:30 +00:00
|
|
|
rv = mState->OnPress(this, point, id, eMouseEventClass);
|
2016-02-29 07:51:44 +00:00
|
|
|
AC_LOGV("After eMouseDown, state: %s, consume: %d", mState->Name(), rv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eMouseMove:
|
|
|
|
AC_LOGV("Before eMouseMove, state: %s", mState->Name());
|
|
|
|
rv = mState->OnMove(this, point);
|
|
|
|
AC_LOGV("After eMouseMove, state: %s, consume: %d", mState->Name(), rv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eMouseUp:
|
|
|
|
AC_LOGV("Before eMouseUp, state: %s", mState->Name());
|
|
|
|
rv = mState->OnRelease(this);
|
|
|
|
AC_LOGV("After eMouseUp, state: %s, consume: %d", mState->Name(), rv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eMouseLongTap:
|
|
|
|
AC_LOGV("Before eMouseLongTap, state: %s", mState->Name());
|
|
|
|
rv = mState->OnLongTap(this, point);
|
|
|
|
AC_LOGV("After eMouseLongTap, state: %s, consume: %d", mState->Name(),
|
|
|
|
rv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-05-03 21:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
|
|
|
AccessibleCaretEventHub::HandleTouchEvent(WidgetTouchEvent* aEvent)
|
|
|
|
{
|
2016-03-30 09:44:28 +00:00
|
|
|
if (aEvent->mTouches.IsEmpty()) {
|
2016-02-28 15:16:45 +00:00
|
|
|
AC_LOG("%s: Receive a touch event without any touch data!", __FUNCTION__);
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
2015-05-03 21:37:00 +00:00
|
|
|
nsEventStatus rv = nsEventStatus_eIgnore;
|
|
|
|
|
2016-02-29 07:51:44 +00:00
|
|
|
int32_t id =
|
2016-03-30 09:44:28 +00:00
|
|
|
(mActiveTouchId == kInvalidTouchId ? aEvent->mTouches[0]->Identifier()
|
2016-02-29 07:51:44 +00:00
|
|
|
: mActiveTouchId);
|
2015-05-03 21:37:00 +00:00
|
|
|
nsPoint point = GetTouchEventPosition(aEvent, id);
|
|
|
|
|
2016-10-03 12:57:44 +00:00
|
|
|
mManager->SetLastInputSource(nsIDOMMouseEvent::MOZ_SOURCE_TOUCH);
|
|
|
|
|
2015-08-22 01:34:51 +00:00
|
|
|
switch (aEvent->mMessage) {
|
2016-02-29 07:51:44 +00:00
|
|
|
case eTouchStart:
|
|
|
|
AC_LOGV("Before eTouchStart, state: %s", mState->Name());
|
2016-08-14 13:39:30 +00:00
|
|
|
rv = mState->OnPress(this, point, id, eTouchEventClass);
|
2016-02-29 07:51:44 +00:00
|
|
|
AC_LOGV("After eTouchStart, state: %s, consume: %d", mState->Name(), rv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eTouchMove:
|
|
|
|
AC_LOGV("Before eTouchMove, state: %s", mState->Name());
|
|
|
|
rv = mState->OnMove(this, point);
|
|
|
|
AC_LOGV("After eTouchMove, state: %s, consume: %d", mState->Name(), rv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eTouchEnd:
|
|
|
|
AC_LOGV("Before eTouchEnd, state: %s", mState->Name());
|
|
|
|
rv = mState->OnRelease(this);
|
|
|
|
AC_LOGV("After eTouchEnd, state: %s, consume: %d", mState->Name(), rv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eTouchCancel:
|
2016-02-29 07:51:44 +00:00
|
|
|
AC_LOGV("Got eTouchCancel, state: %s", mState->Name());
|
|
|
|
// Do nothing since we don't really care eTouchCancel anyway.
|
2016-02-29 07:51:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-05-03 21:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
|
|
|
AccessibleCaretEventHub::HandleKeyboardEvent(WidgetKeyboardEvent* aEvent)
|
|
|
|
{
|
2016-10-03 12:57:44 +00:00
|
|
|
mManager->SetLastInputSource(nsIDOMMouseEvent::MOZ_SOURCE_KEYBOARD);
|
|
|
|
|
2015-08-22 01:34:51 +00:00
|
|
|
switch (aEvent->mMessage) {
|
2016-02-29 07:51:44 +00:00
|
|
|
case eKeyUp:
|
|
|
|
AC_LOGV("eKeyUp, state: %s", mState->Name());
|
|
|
|
mManager->OnKeyboardEvent();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eKeyDown:
|
|
|
|
AC_LOGV("eKeyDown, state: %s", mState->Name());
|
|
|
|
mManager->OnKeyboardEvent();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eKeyPress:
|
|
|
|
AC_LOGV("eKeyPress, state: %s", mState->Name());
|
|
|
|
mManager->OnKeyboardEvent();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-05-03 21:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AccessibleCaretEventHub::MoveDistanceIsLarge(const nsPoint& aPoint) const
|
|
|
|
{
|
|
|
|
nsPoint delta = aPoint - mPressPoint;
|
|
|
|
return NS_hypot(delta.x, delta.y) >
|
|
|
|
nsPresContext::AppUnitsPerCSSPixel() * kMoveStartToleranceInPixel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccessibleCaretEventHub::LaunchLongTapInjector()
|
|
|
|
{
|
|
|
|
if (!mLongTapInjectorTimer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t longTapDelay = gfxPrefs::UiClickHoldContextMenusDelay();
|
|
|
|
mLongTapInjectorTimer->InitWithFuncCallback(FireLongTap, this, longTapDelay,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccessibleCaretEventHub::CancelLongTapInjector()
|
|
|
|
{
|
|
|
|
if (!mLongTapInjectorTimer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mLongTapInjectorTimer->Cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
AccessibleCaretEventHub::FireLongTap(nsITimer* aTimer,
|
|
|
|
void* aAccessibleCaretEventHub)
|
|
|
|
{
|
2016-01-25 07:50:28 +00:00
|
|
|
auto* self = static_cast<AccessibleCaretEventHub*>(aAccessibleCaretEventHub);
|
2015-05-03 21:37:00 +00:00
|
|
|
self->mState->OnLongTap(self, self->mPressPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
AccessibleCaretEventHub::Reflow(DOMHighResTimeStamp aStart,
|
|
|
|
DOMHighResTimeStamp aEnd)
|
|
|
|
{
|
|
|
|
if (!mInitialized) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-02-19 10:21:16 +00:00
|
|
|
MOZ_ASSERT(mRefCnt.get() > 1, "Expect caller holds us as well!");
|
|
|
|
|
2016-08-29 07:36:45 +00:00
|
|
|
if (mIsInReflowCallback) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoRestore<bool> autoRestoreIsInReflowCallback(mIsInReflowCallback);
|
|
|
|
mIsInReflowCallback = true;
|
|
|
|
|
2015-05-03 21:37:00 +00:00
|
|
|
AC_LOG("%s, state: %s", __FUNCTION__, mState->Name());
|
|
|
|
mState->OnReflow(this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
AccessibleCaretEventHub::ReflowInterruptible(DOMHighResTimeStamp aStart,
|
|
|
|
DOMHighResTimeStamp aEnd)
|
|
|
|
{
|
2016-08-29 07:36:45 +00:00
|
|
|
// Defer the error checking to Reflow().
|
2015-05-03 21:37:00 +00:00
|
|
|
return Reflow(aStart, aEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccessibleCaretEventHub::AsyncPanZoomStarted()
|
|
|
|
{
|
|
|
|
if (!mInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-19 10:21:16 +00:00
|
|
|
MOZ_ASSERT(mRefCnt.get() > 1, "Expect caller holds us as well!");
|
|
|
|
|
2015-05-03 21:37:00 +00:00
|
|
|
AC_LOG("%s, state: %s", __FUNCTION__, mState->Name());
|
|
|
|
mState->OnScrollStart(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccessibleCaretEventHub::AsyncPanZoomStopped()
|
|
|
|
{
|
|
|
|
if (!mInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-19 10:21:16 +00:00
|
|
|
MOZ_ASSERT(mRefCnt.get() > 1, "Expect caller holds us as well!");
|
|
|
|
|
2015-05-03 21:37:00 +00:00
|
|
|
AC_LOG("%s, state: %s", __FUNCTION__, mState->Name());
|
|
|
|
mState->OnScrollEnd(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccessibleCaretEventHub::ScrollPositionChanged()
|
|
|
|
{
|
|
|
|
if (!mInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-19 10:21:16 +00:00
|
|
|
MOZ_ASSERT(mRefCnt.get() > 1, "Expect caller holds us as well!");
|
|
|
|
|
2015-05-03 21:37:00 +00:00
|
|
|
AC_LOG("%s, state: %s", __FUNCTION__, mState->Name());
|
|
|
|
mState->OnScrollPositionChanged(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccessibleCaretEventHub::LaunchScrollEndInjector()
|
|
|
|
{
|
|
|
|
if (!mScrollEndInjectorTimer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mScrollEndInjectorTimer->InitWithFuncCallback(
|
|
|
|
FireScrollEnd, this, kScrollEndTimerDelay, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccessibleCaretEventHub::CancelScrollEndInjector()
|
|
|
|
{
|
|
|
|
if (!mScrollEndInjectorTimer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mScrollEndInjectorTimer->Cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
AccessibleCaretEventHub::FireScrollEnd(nsITimer* aTimer,
|
|
|
|
void* aAccessibleCaretEventHub)
|
|
|
|
{
|
2016-01-25 07:50:28 +00:00
|
|
|
auto* self = static_cast<AccessibleCaretEventHub*>(aAccessibleCaretEventHub);
|
2015-05-03 21:37:00 +00:00
|
|
|
self->mState->OnScrollEnd(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
AccessibleCaretEventHub::NotifySelectionChanged(nsIDOMDocument* aDoc,
|
|
|
|
nsISelection* aSel,
|
|
|
|
int16_t aReason)
|
|
|
|
{
|
|
|
|
if (!mInitialized) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-02-19 10:21:16 +00:00
|
|
|
MOZ_ASSERT(mRefCnt.get() > 1, "Expect caller holds us as well!");
|
|
|
|
|
2015-05-03 21:37:00 +00:00
|
|
|
AC_LOG("%s, state: %s, reason: %d", __FUNCTION__, mState->Name(), aReason);
|
|
|
|
mState->OnSelectionChanged(this, aDoc, aSel, aReason);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AccessibleCaretEventHub::NotifyBlur(bool aIsLeavingDocument)
|
|
|
|
{
|
|
|
|
if (!mInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-19 10:21:16 +00:00
|
|
|
MOZ_ASSERT(mRefCnt.get() > 1, "Expect caller holds us as well!");
|
|
|
|
|
2015-05-03 21:37:00 +00:00
|
|
|
AC_LOG("%s, state: %s", __FUNCTION__, mState->Name());
|
|
|
|
mState->OnBlur(this, aIsLeavingDocument);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
|
|
|
AccessibleCaretEventHub::GetTouchEventPosition(WidgetTouchEvent* aEvent,
|
|
|
|
int32_t aIdentifier) const
|
|
|
|
{
|
2016-03-30 09:44:28 +00:00
|
|
|
for (dom::Touch* touch : aEvent->mTouches) {
|
2015-05-03 21:37:00 +00:00
|
|
|
if (touch->Identifier() == aIdentifier) {
|
|
|
|
LayoutDeviceIntPoint touchIntPoint = touch->mRefPoint;
|
|
|
|
|
|
|
|
// Get event coordinate relative to root frame.
|
|
|
|
nsIFrame* rootFrame = mPresShell->GetRootFrame();
|
|
|
|
return nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, touchIntPoint,
|
|
|
|
rootFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
|
|
|
AccessibleCaretEventHub::GetMouseEventPosition(WidgetMouseEvent* aEvent) const
|
|
|
|
{
|
2016-04-18 14:09:02 +00:00
|
|
|
LayoutDeviceIntPoint mouseIntPoint = aEvent->AsGUIEvent()->mRefPoint;
|
2015-05-03 21:37:00 +00:00
|
|
|
|
|
|
|
// Get event coordinate relative to root frame.
|
|
|
|
nsIFrame* rootFrame = mPresShell->GetRootFrame();
|
|
|
|
return nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, mouseIntPoint,
|
|
|
|
rootFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|