зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1133492 - Extract some of nsPresShell into a separate TouchManager class. r=smaug
This commit is contained in:
Родитель
0002fc671c
Коммит
4a533d3199
|
@ -2227,7 +2227,7 @@ TabChild::UpdateTapState(const WidgetTouchEvent& aEvent, nsEventStatus aStatus)
|
|||
return;
|
||||
}
|
||||
if (aStatus == nsEventStatus_eConsumeNoDefault ||
|
||||
nsIPresShell::gPreventMouseEvents ||
|
||||
TouchManager::gPreventMouseEvents ||
|
||||
aEvent.mFlags.mMultipleActionsPrevented) {
|
||||
return;
|
||||
}
|
||||
|
@ -2268,7 +2268,7 @@ TabChild::UpdateTapState(const WidgetTouchEvent& aEvent, nsEventStatus aStatus)
|
|||
return;
|
||||
|
||||
case NS_TOUCH_END:
|
||||
if (!nsIPresShell::gPreventMouseEvents) {
|
||||
if (!TouchManager::gPreventMouseEvents) {
|
||||
APZCCallbackHelper::DispatchSynthesizedMouseEvent(NS_MOUSE_MOVE, time, currentPoint, mWidget);
|
||||
APZCCallbackHelper::DispatchSynthesizedMouseEvent(NS_MOUSE_BUTTON_DOWN, time, currentPoint, mWidget);
|
||||
APZCCallbackHelper::DispatchSynthesizedMouseEvent(NS_MOUSE_BUTTON_UP, time, currentPoint, mWidget);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "nsITimer.h"
|
||||
#include "nsIWeakReferenceUtils.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "TouchManager.h"
|
||||
|
||||
#define APZES_LOG(...)
|
||||
// #define APZES_LOG(...) printf_stderr("APZCCH: " __VA_ARGS__)
|
||||
|
@ -189,7 +190,7 @@ APZEventState::ProcessTouchEvent(const WidgetTouchEvent& aEvent,
|
|||
mActiveElementManager->SetTargetElement(aEvent.touches[0]->GetTarget());
|
||||
}
|
||||
|
||||
bool isTouchPrevented = nsIPresShell::gPreventMouseEvents ||
|
||||
bool isTouchPrevented = TouchManager::gPreventMouseEvents ||
|
||||
aEvent.mFlags.mMultipleActionsPrevented;
|
||||
switch (aEvent.message) {
|
||||
case NS_TOUCH_START: {
|
||||
|
|
|
@ -359,6 +359,7 @@ include('/ipc/chromium/chromium-config.mozbuild')
|
|||
|
||||
LOCAL_INCLUDES += [
|
||||
'/docshell/base', # for nsDocShell.h
|
||||
'/layout/base', # for TouchManager.h
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
|
|
@ -8,6 +8,24 @@
|
|||
#include "TouchManager.h"
|
||||
#include "nsPresShell.h"
|
||||
|
||||
bool TouchManager::gPreventMouseEvents = false;
|
||||
nsRefPtrHashtable<nsUint32HashKey, dom::Touch>* TouchManager::gCaptureTouchList;
|
||||
|
||||
/*static*/ void
|
||||
TouchManager::InitializeStatics()
|
||||
{
|
||||
NS_ASSERTION(!gCaptureTouchList, "InitializeStatics called multiple times!");
|
||||
gCaptureTouchList = new nsRefPtrHashtable<nsUint32HashKey, dom::Touch>;
|
||||
}
|
||||
|
||||
/*static*/ void
|
||||
TouchManager::ReleaseStatics()
|
||||
{
|
||||
NS_ASSERTION(gCaptureTouchList, "ReleaseStatics called without Initialize!");
|
||||
delete gCaptureTouchList;
|
||||
gCaptureTouchList = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
TouchManager::Init(PresShell* aPresShell, nsIDocument* aDocument)
|
||||
{
|
||||
|
@ -51,9 +69,8 @@ EvictTouchPoint(nsRefPtr<dom::Touch>& aTouch,
|
|||
}
|
||||
}
|
||||
if (!node || !aLimitToDocument || node->OwnerDoc() == aLimitToDocument) {
|
||||
// We couldn't dispatch touchend. Remove the touch from gCaptureTouchList
|
||||
// explicitly.
|
||||
nsIPresShell::gCaptureTouchList->Remove(aTouch->Identifier());
|
||||
// We couldn't dispatch touchend. Remove the touch from gCaptureTouchList explicitly.
|
||||
TouchManager::gCaptureTouchList->Remove(aTouch->Identifier());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,7 +88,7 @@ void
|
|||
TouchManager::EvictTouches()
|
||||
{
|
||||
WidgetTouchEvent::AutoTouchArray touches;
|
||||
PresShell::gCaptureTouchList->Enumerate(&AppendToTouchList, &touches);
|
||||
gCaptureTouchList->Enumerate(&AppendToTouchList, &touches);
|
||||
for (uint32_t i = 0; i < touches.Length(); ++i) {
|
||||
EvictTouchPoint(touches[i], mDocument);
|
||||
}
|
||||
|
@ -93,7 +110,7 @@ TouchManager::PreHandleEvent(WidgetEvent* aEvent,
|
|||
// queue
|
||||
if (touchEvent->touches.Length() == 1) {
|
||||
WidgetTouchEvent::AutoTouchArray touches;
|
||||
PresShell::gCaptureTouchList->Enumerate(&AppendToTouchList, (void *)&touches);
|
||||
gCaptureTouchList->Enumerate(&AppendToTouchList, (void *)&touches);
|
||||
for (uint32_t i = 0; i < touches.Length(); ++i) {
|
||||
EvictTouchPoint(touches[i]);
|
||||
}
|
||||
|
@ -102,12 +119,12 @@ TouchManager::PreHandleEvent(WidgetEvent* aEvent,
|
|||
for (uint32_t i = 0; i < touchEvent->touches.Length(); ++i) {
|
||||
dom::Touch* touch = touchEvent->touches[i];
|
||||
int32_t id = touch->Identifier();
|
||||
if (!PresShell::gCaptureTouchList->Get(id, nullptr)) {
|
||||
if (!gCaptureTouchList->Get(id, nullptr)) {
|
||||
// If it is not already in the queue, it is a new touch
|
||||
touch->mChanged = true;
|
||||
}
|
||||
touch->mMessage = aEvent->message;
|
||||
PresShell::gCaptureTouchList->Put(id, touch);
|
||||
gCaptureTouchList->Put(id, touch);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -125,7 +142,7 @@ TouchManager::PreHandleEvent(WidgetEvent* aEvent,
|
|||
int32_t id = touch->Identifier();
|
||||
touch->mMessage = aEvent->message;
|
||||
|
||||
nsRefPtr<dom::Touch> oldTouch = PresShell::gCaptureTouchList->GetWeak(id);
|
||||
nsRefPtr<dom::Touch> oldTouch = gCaptureTouchList->GetWeak(id);
|
||||
if (!oldTouch) {
|
||||
touches.RemoveElementAt(i);
|
||||
continue;
|
||||
|
@ -142,7 +159,7 @@ TouchManager::PreHandleEvent(WidgetEvent* aEvent,
|
|||
}
|
||||
touch->SetTarget(targetPtr);
|
||||
|
||||
PresShell::gCaptureTouchList->Put(id, touch);
|
||||
gCaptureTouchList->Put(id, touch);
|
||||
// if we're moving from touchstart to touchmove for this touch
|
||||
// we allow preventDefault to prevent mouse events
|
||||
if (oldTouch->mMessage != touch->mMessage) {
|
||||
|
@ -165,7 +182,7 @@ TouchManager::PreHandleEvent(WidgetEvent* aEvent,
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (PresShell::gPreventMouseEvents) {
|
||||
if (gPreventMouseEvents) {
|
||||
*aStatus = nsEventStatus_eConsumeNoDefault;
|
||||
}
|
||||
return false;
|
||||
|
@ -190,7 +207,7 @@ TouchManager::PreHandleEvent(WidgetEvent* aEvent,
|
|||
touch->mChanged = true;
|
||||
|
||||
int32_t id = touch->Identifier();
|
||||
nsRefPtr<dom::Touch> oldTouch = PresShell::gCaptureTouchList->GetWeak(id);
|
||||
nsRefPtr<dom::Touch> oldTouch = gCaptureTouchList->GetWeak(id);
|
||||
if (!oldTouch) {
|
||||
continue;
|
||||
}
|
||||
|
@ -198,10 +215,10 @@ TouchManager::PreHandleEvent(WidgetEvent* aEvent,
|
|||
|
||||
aCurrentEventContent = do_QueryInterface(targetPtr);
|
||||
touch->SetTarget(targetPtr);
|
||||
PresShell::gCaptureTouchList->Remove(id);
|
||||
gCaptureTouchList->Remove(id);
|
||||
}
|
||||
// add any touches left in the touch list, but ensure changed=false
|
||||
PresShell::gCaptureTouchList->Enumerate(&AppendToTouchList, (void *)&touches);
|
||||
gCaptureTouchList->Enumerate(&AppendToTouchList, (void *)&touches);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -17,6 +17,10 @@ class nsIDocument;
|
|||
|
||||
class TouchManager {
|
||||
public:
|
||||
// Initialize and release static variables
|
||||
static void InitializeStatics();
|
||||
static void ReleaseStatics();
|
||||
|
||||
void Init(PresShell* aPresShell, nsIDocument* aDocument);
|
||||
void Destroy();
|
||||
|
||||
|
@ -26,6 +30,9 @@ public:
|
|||
bool& aIsHandlingUserInput,
|
||||
nsCOMPtr<nsIContent>& aCurrentEventContent);
|
||||
|
||||
static bool gPreventMouseEvents;
|
||||
static nsRefPtrHashtable<nsUint32HashKey, mozilla::dom::Touch>* gCaptureTouchList;
|
||||
|
||||
private:
|
||||
void EvictTouches();
|
||||
|
||||
|
|
|
@ -1242,12 +1242,8 @@ public:
|
|||
}
|
||||
|
||||
// mouse capturing
|
||||
|
||||
static CapturingContentInfo gCaptureInfo;
|
||||
|
||||
static nsRefPtrHashtable<nsUint32HashKey, mozilla::dom::Touch>* gCaptureTouchList;
|
||||
static bool gPreventMouseEvents;
|
||||
|
||||
struct PointerCaptureInfo
|
||||
{
|
||||
nsCOMPtr<nsIContent> mPendingContent;
|
||||
|
|
|
@ -96,6 +96,7 @@
|
|||
#include "FrameLayerBuilder.h"
|
||||
#include "mozilla/layers/APZCTreeManager.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "mozilla/EventDispatcher.h"
|
||||
|
||||
#ifdef MOZ_XUL
|
||||
#include "nsXULPopupManager.h"
|
||||
|
|
|
@ -201,10 +201,8 @@ CapturingContentInfo nsIPresShell::gCaptureInfo =
|
|||
{ false /* mAllowed */, false /* mPointerLock */, false /* mRetargetToElement */,
|
||||
false /* mPreventDrag */, nullptr /* mContent */ };
|
||||
nsIContent* nsIPresShell::gKeyDownTarget;
|
||||
nsRefPtrHashtable<nsUint32HashKey, dom::Touch>* nsIPresShell::gCaptureTouchList;
|
||||
nsClassHashtable<nsUint32HashKey, nsIPresShell::PointerCaptureInfo>* nsIPresShell::gPointerCaptureList;
|
||||
nsClassHashtable<nsUint32HashKey, nsIPresShell::PointerInfo>* nsIPresShell::gActivePointersIds;
|
||||
bool nsIPresShell::gPreventMouseEvents = false;
|
||||
|
||||
// convert a color value to a string, in the CSS format #RRGGBB
|
||||
// * - initially created for bugs 31816, 20760, 22963
|
||||
|
@ -7482,10 +7480,10 @@ PresShell::HandleEvent(nsIFrame* aFrame,
|
|||
// in the same document by taking the target of the events already in
|
||||
// the capture list
|
||||
nsCOMPtr<nsIContent> anyTarget;
|
||||
if (gCaptureTouchList->Count() > 0 && touchEvent->touches.Length() > 1) {
|
||||
gCaptureTouchList->Enumerate(&FindAnyTarget, &anyTarget);
|
||||
if (TouchManager::gCaptureTouchList->Count() > 0 && touchEvent->touches.Length() > 1) {
|
||||
TouchManager::gCaptureTouchList->Enumerate(&FindAnyTarget, &anyTarget);
|
||||
} else {
|
||||
gPreventMouseEvents = false;
|
||||
TouchManager::gPreventMouseEvents = false;
|
||||
}
|
||||
|
||||
for (int32_t i = touchEvent->touches.Length(); i; ) {
|
||||
|
@ -7493,7 +7491,7 @@ PresShell::HandleEvent(nsIFrame* aFrame,
|
|||
dom::Touch* touch = touchEvent->touches[i];
|
||||
|
||||
int32_t id = touch->Identifier();
|
||||
if (!gCaptureTouchList->Get(id, nullptr)) {
|
||||
if (!TouchManager::gCaptureTouchList->Get(id, nullptr)) {
|
||||
// find the target for this touch
|
||||
eventPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent,
|
||||
touch->mRefPoint,
|
||||
|
@ -7547,7 +7545,7 @@ PresShell::HandleEvent(nsIFrame* aFrame,
|
|||
touch->mChanged = false;
|
||||
int32_t id = touch->Identifier();
|
||||
|
||||
nsRefPtr<dom::Touch> oldTouch = gCaptureTouchList->GetWeak(id);
|
||||
nsRefPtr<dom::Touch> oldTouch = TouchManager::gCaptureTouchList->GetWeak(id);
|
||||
if (oldTouch) {
|
||||
touch->SetTarget(oldTouch->mTarget);
|
||||
}
|
||||
|
@ -7653,7 +7651,7 @@ PresShell::HandleEvent(nsIFrame* aFrame,
|
|||
}
|
||||
|
||||
nsRefPtr<dom::Touch> oldTouch =
|
||||
gCaptureTouchList->GetWeak(touch->Identifier());
|
||||
TouchManager::gCaptureTouchList->GetWeak(touch->Identifier());
|
||||
if (!oldTouch) {
|
||||
break;
|
||||
}
|
||||
|
@ -8276,10 +8274,10 @@ PresShell::DispatchTouchEventToDOM(WidgetEvent* aEvent,
|
|||
// and this is touchstart, or the first touchmove, widget should consume
|
||||
// other events that would be associated with this touch session
|
||||
if (preventDefault && canPrevent) {
|
||||
gPreventMouseEvents = true;
|
||||
TouchManager::gPreventMouseEvents = true;
|
||||
}
|
||||
|
||||
if (gPreventMouseEvents) {
|
||||
if (TouchManager::gPreventMouseEvents) {
|
||||
*aStatus = nsEventStatus_eConsumeNoDefault;
|
||||
} else {
|
||||
*aStatus = nsEventStatus_eIgnore;
|
||||
|
@ -10698,17 +10696,14 @@ nsIPresShell::AccService()
|
|||
|
||||
void nsIPresShell::InitializeStatics()
|
||||
{
|
||||
NS_ASSERTION(!gCaptureTouchList, "InitializeStatics called multiple times!");
|
||||
gCaptureTouchList = new nsRefPtrHashtable<nsUint32HashKey, dom::Touch>;
|
||||
NS_ASSERTION(!gPointerCaptureList, "InitializeStatics called multiple times!");
|
||||
gPointerCaptureList = new nsClassHashtable<nsUint32HashKey, PointerCaptureInfo>;
|
||||
gActivePointersIds = new nsClassHashtable<nsUint32HashKey, PointerInfo>;
|
||||
}
|
||||
|
||||
void nsIPresShell::ReleaseStatics()
|
||||
{
|
||||
NS_ASSERTION(gCaptureTouchList, "ReleaseStatics called without Initialize!");
|
||||
delete gCaptureTouchList;
|
||||
gCaptureTouchList = nullptr;
|
||||
NS_ASSERTION(gPointerCaptureList, "ReleaseStatics called without Initialize!");
|
||||
delete gPointerCaptureList;
|
||||
gPointerCaptureList = nullptr;
|
||||
delete gActivePointersIds;
|
||||
|
|
|
@ -134,6 +134,7 @@ using namespace mozilla::system;
|
|||
#include "nsDocument.h"
|
||||
#include "mozilla/dom/HTMLVideoElement.h"
|
||||
#include "CameraPreferences.h"
|
||||
#include "TouchManager.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::net;
|
||||
|
@ -267,6 +268,7 @@ nsLayoutStatics::Initialize()
|
|||
mozilla::dom::FallbackEncoding::Initialize();
|
||||
nsLayoutUtils::Initialize();
|
||||
nsIPresShell::InitializeStatics();
|
||||
TouchManager::InitializeStatics();
|
||||
nsRefreshDriver::InitializeStatics();
|
||||
|
||||
nsCORSListenerProxy::Startup();
|
||||
|
@ -403,6 +405,8 @@ nsLayoutStatics::Shutdown()
|
|||
|
||||
nsIPresShell::ReleaseStatics();
|
||||
|
||||
TouchManager::ReleaseStatics();
|
||||
|
||||
nsTreeSanitizer::ReleaseStatics();
|
||||
|
||||
nsHtml5Module::ReleaseStatics();
|
||||
|
|
Загрузка…
Ссылка в новой задаче