From 62bea1e104855bcff32fc359186187af93aaf1e7 Mon Sep 17 00:00:00 2001 From: William Chen Date: Sat, 7 Jun 2014 01:42:54 -0700 Subject: [PATCH] Bug 992521 - Part 4: Make PresShell events work when not in document, but contained by a ShadowRoot with a host in document. r=smaug --- dom/events/EventStateManager.cpp | 7 ++++--- layout/base/nsPresShell.cpp | 16 ++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 50a79fbf4b9..4636834da4b 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -1440,7 +1440,7 @@ EventStateManager::FireContextClick() } } - nsIDocument* doc = mGestureDownContent->GetCurrentDoc(); + nsIDocument* doc = mGestureDownContent->GetCrossShadowCurrentDoc(); AutoHandlingUserInputStatePusher userInpStatePusher(true, &event, doc); // dispatch to DOM @@ -2752,7 +2752,7 @@ EventStateManager::PostHandleEvent(nsPresContext* aPresContext, // NOTE: The newFocus isn't editable that also means it's not in // designMode. In designMode, all contents are not focusable. if (newFocus && !newFocus->IsEditable()) { - nsIDocument *doc = newFocus->GetCurrentDoc(); + nsIDocument *doc = newFocus->GetCrossShadowCurrentDoc(); if (doc && newFocus == doc->GetRootElement()) { nsIContent *bodyContent = nsLayoutUtils::GetEditableRootContentByContentEditable(doc); @@ -4633,7 +4633,8 @@ EventStateManager::SetContentState(nsIContent* aContent, EventStates aState) newHover = aContent; } else { NS_ASSERTION(!aContent || - aContent->GetCurrentDoc() == mPresContext->PresShell()->GetDocument(), + aContent->GetCrossShadowCurrentDoc() == + mPresContext->PresShell()->GetDocument(), "Unexpected document"); nsIFrame *frame = aContent ? aContent->GetPrimaryFrame() : nullptr; if (frame && nsLayoutUtils::IsViewportScrollbarFrame(frame)) { diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index ccde1bfaf57..b10d30fa48e 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -6334,7 +6334,7 @@ nsIContent* PresShell::GetCurrentEventContent() { if (mCurrentEventContent && - mCurrentEventContent->GetCurrentDoc() != mDocument) { + mCurrentEventContent->GetCrossShadowCurrentDoc() != mDocument) { mCurrentEventContent = nullptr; mCurrentEventFrame = nullptr; } @@ -6375,7 +6375,7 @@ PresShell::GetEventTargetContent(WidgetEvent* aEvent) nsIFrame* currentEventFrame = GetCurrentEventFrame(); if (currentEventFrame) { currentEventFrame->GetContentForEvent(aEvent, getter_AddRefs(content)); - NS_ASSERTION(!content || content->GetCurrentDoc() == mDocument, + NS_ASSERTION(!content || content->GetCrossShadowCurrentDoc() == mDocument, "handing out content from a different doc"); } } @@ -6407,7 +6407,7 @@ PresShell::PopCurrentEventInfo() // Don't use it if it has moved to a different document. if (mCurrentEventContent && - mCurrentEventContent->GetCurrentDoc() != mDocument) { + mCurrentEventContent->GetCrossShadowCurrentDoc() != mDocument) { mCurrentEventContent = nullptr; mCurrentEventFrame = nullptr; } @@ -6877,7 +6877,7 @@ PresShell::HandleEvent(nsIFrame* aFrame, } else if (capturingContent) { // if the mouse is being captured then retarget the mouse event at the // document that is being captured. - retargetEventDoc = capturingContent->GetCurrentDoc(); + retargetEventDoc = capturingContent->GetCrossShadowCurrentDoc(); #ifdef ANDROID } else if (aEvent->eventStructType == NS_TOUCH_EVENT) { retargetEventDoc = GetTouchEventTargetDocument(); @@ -6978,7 +6978,7 @@ PresShell::HandleEvent(nsIFrame* aFrame, if (!captureRetarget) { // A check was already done above to ensure that capturingContent is // in this presshell. - NS_ASSERTION(capturingContent->GetCurrentDoc() == GetDocument(), + NS_ASSERTION(capturingContent->GetCrossShadowCurrentDoc() == GetDocument(), "Unexpected document"); nsIFrame* captureFrame = capturingContent->GetPrimaryFrame(); if (captureFrame) { @@ -7127,7 +7127,7 @@ PresShell::HandleEvent(nsIFrame* aFrame, capturingContent))) { // A check was already done above to ensure that capturingContent is // in this presshell. - NS_ASSERTION(capturingContent->GetCurrentDoc() == GetDocument(), + NS_ASSERTION(capturingContent->GetCrossShadowCurrentDoc() == GetDocument(), "Unexpected document"); nsIFrame* capturingFrame = capturingContent->GetPrimaryFrame(); if (capturingFrame) { @@ -7468,12 +7468,12 @@ PresShell::HandleEventWithTarget(WidgetEvent* aEvent, nsIFrame* aFrame, MOZ_ASSERT(!aFrame || aFrame->PresContext()->GetPresShell() == this, "wrong shell"); if (aContent) { - nsIDocument* doc = aContent->GetCurrentDoc(); + nsIDocument* doc = aContent->GetCrossShadowCurrentDoc(); NS_ASSERTION(doc, "event for content that isn't in a document"); NS_ASSERTION(!doc || doc->GetShell() == this, "wrong shell"); } #endif - NS_ENSURE_STATE(!aContent || aContent->GetCurrentDoc() == mDocument); + NS_ENSURE_STATE(!aContent || aContent->GetCrossShadowCurrentDoc() == mDocument); PushCurrentEventInfo(aFrame, aContent); nsresult rv = HandleEventInternal(aEvent, aStatus);