Bug 1547618 - Make dom use mozilla::PresShell rather than via nsIPresShell r=smaug

Additionally, this patch makes `nsContentUtils::DispatchXULCommand()` because
it guarantees the lifetime of **only** `PresShell` in it.  So, we need to check
the lifetime of each argument at each caller here.

Differential Revision: https://phabricator.services.mozilla.com/D29199

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-04-30 01:35:30 +00:00
Родитель 42078ccd2f
Коммит 663f37d827
29 изменённых файлов: 180 добавлений и 155 удалений

Просмотреть файл

@ -11,7 +11,6 @@
#include "mozilla/WeakPtr.h"
#include "mozilla/dom/VisualViewportBinding.h"
#include "Units.h"
#include "nsIPresShell.h"
namespace mozilla {

Просмотреть файл

@ -6059,7 +6059,7 @@ bool nsContentUtils::CanAccessNativeAnon() {
/* static */
nsresult nsContentUtils::DispatchXULCommand(nsIContent* aTarget, bool aTrusted,
Event* aSourceEvent,
nsIPresShell* aShell, bool aCtrl,
PresShell* aPresShell, bool aCtrl,
bool aAlt, bool aShift, bool aMeta,
uint16_t aInputSource) {
NS_ENSURE_STATE(aTarget);
@ -6073,10 +6073,9 @@ nsresult nsContentUtils::DispatchXULCommand(nsIContent* aTarget, bool aTrusted,
0, aCtrl, aAlt, aShift, aMeta, aSourceEvent,
aInputSource, IgnoreErrors());
if (aShell) {
if (aPresShell) {
nsEventStatus status = nsEventStatus_eIgnore;
nsCOMPtr<nsIPresShell> kungFuDeathGrip = aShell;
return aShell->HandleDOMEventWithTarget(aTarget, xulCommand, &status);
return aPresShell->HandleDOMEventWithTarget(aTarget, xulCommand, &status);
}
ErrorResult rv;
@ -6366,8 +6365,8 @@ void nsContentUtils::PopulateStringFromStringBuffer(nsStringBuffer* aBuf,
aBuf->ToString(stringLen, aResultString);
}
nsIPresShell* nsContentUtils::FindPresShellForDocument(const Document* aDoc) {
const Document* doc = aDoc;
PresShell* nsContentUtils::FindPresShellForDocument(const Document* aDocument) {
const Document* doc = aDocument;
Document* displayDoc = doc->GetDisplayDocument();
if (displayDoc) {
doc = displayDoc;
@ -6396,22 +6395,24 @@ nsIPresShell* nsContentUtils::FindPresShellForDocument(const Document* aDoc) {
return nullptr;
}
nsIWidget* nsContentUtils::WidgetForDocument(const Document* aDoc) {
nsIPresShell* shell = FindPresShellForDocument(aDoc);
if (shell) {
nsViewManager* VM = shell->GetViewManager();
if (VM) {
nsView* rootView = VM->GetRootView();
if (rootView) {
nsView* displayRoot = nsViewManager::GetDisplayRootFor(rootView);
if (displayRoot) {
return displayRoot->GetNearestWidget(nullptr);
}
}
}
nsIWidget* nsContentUtils::WidgetForDocument(const Document* aDocument) {
PresShell* presShell = FindPresShellForDocument(aDocument);
if (!presShell) {
return nullptr;
}
return nullptr;
nsViewManager* vm = presShell->GetViewManager();
if (!vm) {
return nullptr;
}
nsView* rootView = vm->GetRootView();
if (!rootView) {
return nullptr;
}
nsView* displayRoot = nsViewManager::GetDisplayRootFor(rootView);
if (!displayRoot) {
return nullptr;
}
return displayRoot->GetNearestWidget(nullptr);
}
nsIWidget* nsContentUtils::WidgetForContent(const nsIContent* aContent) {
@ -7857,13 +7858,15 @@ mozilla::Modifiers nsContentUtils::GetWidgetModifiers(int32_t aModifiers) {
return result;
}
nsIWidget* nsContentUtils::GetWidget(nsIPresShell* aPresShell,
nsPoint* aOffset) {
if (aPresShell) {
nsIFrame* frame = aPresShell->GetRootFrame();
if (frame) return frame->GetView()->GetNearestWidget(aOffset);
nsIWidget* nsContentUtils::GetWidget(PresShell* aPresShell, nsPoint* aOffset) {
if (!aPresShell) {
return nullptr;
}
return nullptr;
nsIFrame* frame = aPresShell->GetRootFrame();
if (!frame) {
return nullptr;
}
return frame->GetView()->GetNearestWidget(aOffset);
}
int16_t nsContentUtils::GetButtonsFlagForButton(int32_t aButton) {
@ -7896,20 +7899,23 @@ LayoutDeviceIntPoint nsContentUtils::ToWidgetPoint(
aPresContext->AppUnitsPerDevPixel());
}
nsView* nsContentUtils::GetViewToDispatchEvent(nsPresContext* presContext,
nsIPresShell** presShell) {
if (presContext && presShell) {
*presShell = presContext->PresShell();
if (*presShell) {
NS_ADDREF(*presShell);
if (nsViewManager* viewManager = (*presShell)->GetViewManager()) {
if (nsView* view = viewManager->GetRootView()) {
return view;
}
}
}
nsView* nsContentUtils::GetViewToDispatchEvent(nsPresContext* aPresContext,
PresShell** aPresShell) {
if (!aPresContext || !aPresShell) {
return nullptr;
}
return nullptr;
RefPtr<PresShell> presShell = aPresContext->PresShell();
if (NS_WARN_IF(!presShell)) {
*aPresShell = nullptr;
return nullptr;
}
nsViewManager* viewManager = presShell->GetViewManager();
if (!viewManager) {
presShell.forget(aPresShell); // XXX Is this intentional?
return nullptr;
}
presShell.forget(aPresShell);
return viewManager->GetRootView();
}
nsresult nsContentUtils::SendMouseEvent(
@ -7981,7 +7987,7 @@ nsresult nsContentUtils::SendMouseEvent(
nsEventStatus status = nsEventStatus_eIgnore;
if (aToWindow) {
nsCOMPtr<nsIPresShell> presShell;
RefPtr<PresShell> presShell;
nsView* view =
GetViewToDispatchEvent(presContext, getter_AddRefs(presShell));
if (!presShell || !view) {

Просмотреть файл

@ -83,7 +83,6 @@ class nsNameSpaceManager;
class nsIObserver;
class nsIParser;
class nsIPluginTag;
class nsIPresShell;
class nsIPrincipal;
class nsIRequest;
class nsIRunnable;
@ -2149,14 +2148,15 @@ class nsContentUtils {
/**
* This method creates and dispatches "command" event, which implements
* XULCommandEvent.
* If aShell is not null, dispatching goes via
* nsIPresShell::HandleDOMEventWithTarget.
* If aPresShell is not null, dispatching goes via
* PresShell::HandleDOMEventWithTarget().
*/
MOZ_CAN_RUN_SCRIPT
static nsresult DispatchXULCommand(
nsIContent* aTarget, bool aTrusted,
mozilla::dom::Event* aSourceEvent = nullptr,
nsIPresShell* aShell = nullptr, bool aCtrl = false, bool aAlt = false,
bool aShift = false, bool aMeta = false,
mozilla::PresShell* aPresShell = nullptr, bool aCtrl = false,
bool aAlt = false, bool aShift = false, bool aMeta = false,
// Including MouseEventBinding here leads
// to incude loops, unfortunately.
uint16_t inputSource = 0 /* MouseEvent_Binding::MOZ_SOURCE_UNKNOWN */);
@ -2253,7 +2253,8 @@ class nsContentUtils {
* getting generic data like a device context or widget from it is OK, but it
* might not be this document's actual presentation.
*/
static nsIPresShell* FindPresShellForDocument(const Document* aDoc);
static mozilla::PresShell* FindPresShellForDocument(
const Document* aDocument);
/**
* Returns the widget for this document if there is one. Looks at all ancestor
@ -2263,7 +2264,7 @@ class nsContentUtils {
* You should probably use WidgetForContent() instead of this, unless you have
* a good reason to do otherwise.
*/
static nsIWidget* WidgetForDocument(const Document* aDoc);
static nsIWidget* WidgetForDocument(const Document* aDocument);
/**
* Returns the appropriate widget for this element, if there is one. Unlike
@ -2880,13 +2881,13 @@ class nsContentUtils {
// Helpers shared by the implementations of nsContentUtils methods and
// nsIDOMWindowUtils methods.
static mozilla::Modifiers GetWidgetModifiers(int32_t aModifiers);
static nsIWidget* GetWidget(nsIPresShell* aPresShell, nsPoint* aOffset);
static nsIWidget* GetWidget(mozilla::PresShell* aPresShell, nsPoint* aOffset);
static int16_t GetButtonsFlagForButton(int32_t aButton);
static mozilla::LayoutDeviceIntPoint ToWidgetPoint(
const mozilla::CSSPoint& aPoint, const nsPoint& aOffset,
nsPresContext* aPresContext);
static nsView* GetViewToDispatchEvent(nsPresContext* aPresContext,
nsIPresShell** aPresShell);
mozilla::PresShell** aPresShell);
/**
* Synthesize a mouse event to the given widget

Просмотреть файл

@ -834,7 +834,7 @@ nsDOMWindowUtils::SendTouchEventCommon(
nsEventStatus status;
if (aToWindow) {
nsCOMPtr<nsIPresShell> presShell;
RefPtr<PresShell> presShell;
nsView* view = nsContentUtils::GetViewToDispatchEvent(
presContext, getter_AddRefs(presShell));
if (!presShell || !view) {

Просмотреть файл

@ -105,9 +105,9 @@ LazyLogModule gFocusNavigationLog("FocusNavigation");
LOGTAG(gFocusNavigationLog, format, content)
struct nsDelayedBlurOrFocusEvent {
nsDelayedBlurOrFocusEvent(EventMessage aEventMessage,
nsIPresShell* aPresShell, Document* aDocument,
EventTarget* aTarget, EventTarget* aRelatedTarget)
nsDelayedBlurOrFocusEvent(EventMessage aEventMessage, PresShell* aPresShell,
Document* aDocument, EventTarget* aTarget,
EventTarget* aRelatedTarget)
: mPresShell(aPresShell),
mDocument(aDocument),
mTarget(aTarget),
@ -120,7 +120,7 @@ struct nsDelayedBlurOrFocusEvent {
mTarget(aOther.mTarget),
mEventMessage(aOther.mEventMessage) {}
nsCOMPtr<nsIPresShell> mPresShell;
RefPtr<PresShell> mPresShell;
nsCOMPtr<Document> mDocument;
nsCOMPtr<EventTarget> mTarget;
EventMessage mEventMessage;
@ -137,7 +137,9 @@ inline void ImplCycleCollectionUnlink(nsDelayedBlurOrFocusEvent& aField) {
inline void ImplCycleCollectionTraverse(
nsCycleCollectionTraversalCallback& aCallback,
nsDelayedBlurOrFocusEvent& aField, const char* aName, uint32_t aFlags = 0) {
CycleCollectionNoteChild(aCallback, aField.mPresShell.get(), aName, aFlags);
CycleCollectionNoteChild(
aCallback, static_cast<nsIDocumentObserver*>(aField.mPresShell.get()),
aName, aFlags);
CycleCollectionNoteChild(aCallback, aField.mDocument.get(), aName, aFlags);
CycleCollectionNoteChild(aCallback, aField.mTarget.get(), aName, aFlags);
CycleCollectionNoteChild(aCallback, aField.mRelatedTarget.get(), aName,
@ -992,8 +994,7 @@ nsFocusManager::FireDelayedEvents(Document* aDocument) {
} else if (!aDocument->EventHandlingSuppressed()) {
EventMessage message = mDelayedBlurFocusEvents[i].mEventMessage;
nsCOMPtr<EventTarget> target = mDelayedBlurFocusEvents[i].mTarget;
nsCOMPtr<nsIPresShell> presShell =
mDelayedBlurFocusEvents[i].mPresShell;
RefPtr<PresShell> presShell = mDelayedBlurFocusEvents[i].mPresShell;
nsCOMPtr<EventTarget> relatedTarget =
mDelayedBlurFocusEvents[i].mRelatedTarget;
mDelayedBlurFocusEvents.RemoveElementAt(i);
@ -1076,17 +1077,23 @@ void nsFocusManager::EnsureCurrentWidgetFocused() {
// get the main child widget for the focused window and ensure that the
// platform knows that this widget is focused.
nsCOMPtr<nsIDocShell> docShell = mFocusedWindow->GetDocShell();
if (docShell) {
nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
if (presShell) {
nsViewManager* vm = presShell->GetViewManager();
if (vm) {
nsCOMPtr<nsIWidget> widget;
vm->GetRootWidget(getter_AddRefs(widget));
if (widget) widget->SetFocus(false);
}
}
if (!docShell) {
return;
}
RefPtr<PresShell> presShell = docShell->GetPresShell();
if (!presShell) {
return;
}
nsViewManager* vm = presShell->GetViewManager();
if (!vm) {
return;
}
nsCOMPtr<nsIWidget> widget;
vm->GetRootWidget(getter_AddRefs(widget));
if (!widget) {
return;
}
widget->SetFocus(false);
}
bool ActivateOrDeactivateChild(BrowserParent* aParent, void* aArg) {
@ -2019,7 +2026,7 @@ static Document* GetDocumentHelper(EventTarget* aTarget) {
}
void nsFocusManager::FireFocusInOrOutEvent(
EventMessage aEventMessage, nsIPresShell* aPresShell, nsISupports* aTarget,
EventMessage aEventMessage, PresShell* aPresShell, nsISupports* aTarget,
nsPIDOMWindowOuter* aCurrentFocusedWindow,
nsIContent* aCurrentFocusedContent, EventTarget* aRelatedTarget) {
NS_ASSERTION(aEventMessage == eFocusIn || aEventMessage == eFocusOut,
@ -2031,7 +2038,7 @@ void nsFocusManager::FireFocusInOrOutEvent(
}
void nsFocusManager::SendFocusOrBlurEvent(
EventMessage aEventMessage, nsIPresShell* aPresShell, Document* aDocument,
EventMessage aEventMessage, PresShell* aPresShell, Document* aDocument,
nsISupports* aTarget, uint32_t aFocusMethod, bool aWindowRaised,
bool aIsRefocus, EventTarget* aRelatedTarget) {
NS_ASSERTION(aEventMessage == eFocus || aEventMessage == eBlur,
@ -2078,7 +2085,7 @@ void nsFocusManager::SendFocusOrBlurEvent(
}
void nsFocusManager::FireFocusOrBlurEvent(EventMessage aEventMessage,
nsIPresShell* aPresShell,
PresShell* aPresShell,
nsISupports* aTarget,
bool aWindowRaised, bool aIsRefocus,
EventTarget* aRelatedTarget) {
@ -2263,7 +2270,7 @@ void nsFocusManager::UpdateCaret(bool aMoveCaretToFocus, bool aUpdateVisibility,
SetCaretVisible(presShell, browseWithCaret, aContent);
}
void nsFocusManager::MoveCaretToFocus(nsIPresShell* aPresShell,
void nsFocusManager::MoveCaretToFocus(PresShell* aPresShell,
nsIContent* aContent) {
nsCOMPtr<Document> doc = aPresShell->GetDocument();
if (doc) {
@ -2301,8 +2308,8 @@ void nsFocusManager::MoveCaretToFocus(nsIPresShell* aPresShell,
}
}
nsresult nsFocusManager::SetCaretVisible(nsIPresShell* aPresShell,
bool aVisible, nsIContent* aContent) {
nsresult nsFocusManager::SetCaretVisible(PresShell* aPresShell, bool aVisible,
nsIContent* aContent) {
// When browsing with caret, make sure caret is visible after new focus
// Return early if there is no caret. This can happen for the testcase
// for bug 308025 where a window is closed in a blur handler.
@ -2327,13 +2334,9 @@ nsresult nsFocusManager::SetCaretVisible(nsIPresShell* aPresShell,
Selection* domSelection =
docFrameSelection->GetSelection(SelectionType::eNormal);
if (domSelection) {
nsCOMPtr<nsISelectionController> selCon(do_QueryInterface(aPresShell));
if (!selCon) {
return NS_ERROR_FAILURE;
}
// First, hide the caret to prevent attempting to show it in
// SetCaretDOMSelection
selCon->SetCaretEnabled(false);
aPresShell->SetCaretEnabled(false);
// Caret must blink on non-editable elements
caret->SetIgnoreUserModify(true);
@ -2344,8 +2347,8 @@ nsresult nsFocusManager::SetCaretVisible(nsIPresShell* aPresShell,
// fields, which have a different frame selection from the document.
// They will take care of making the caret visible themselves.
selCon->SetCaretReadOnly(false);
selCon->SetCaretEnabled(aVisible);
aPresShell->SetCaretReadOnly(false);
aPresShell->SetCaretEnabled(aVisible);
}
}
@ -2353,7 +2356,7 @@ nsresult nsFocusManager::SetCaretVisible(nsIPresShell* aPresShell,
}
nsresult nsFocusManager::GetSelectionLocation(Document* aDocument,
nsIPresShell* aPresShell,
PresShell* aPresShell,
nsIContent** aStartContent,
nsIContent** aEndContent) {
*aStartContent = *aEndContent = nullptr;
@ -3226,7 +3229,7 @@ static nsIContent* GetTopLevelScopeOwner(nsIContent* aContent) {
}
nsresult nsFocusManager::GetNextTabbableContent(
nsIPresShell* aPresShell, nsIContent* aRootContent,
PresShell* aPresShell, nsIContent* aRootContent,
nsIContent* aOriginalStartContent, nsIContent* aStartContent, bool aForward,
int32_t aCurrentTabIndex, bool aIgnoreTabIndex, bool aForDocumentNavigation,
nsIContent** aResultContent) {

Просмотреть файл

@ -351,7 +351,7 @@ class nsFocusManager final : public nsIFocusManager,
* aWindowRaised should only be true if called from WindowRaised.
*/
void SendFocusOrBlurEvent(
mozilla::EventMessage aEventMessage, nsIPresShell* aPresShell,
mozilla::EventMessage aEventMessage, mozilla::PresShell* aPresShell,
Document* aDocument, nsISupports* aTarget, uint32_t aFocusMethod,
bool aWindowRaised, bool aIsRefocus = false,
mozilla::dom::EventTarget* aRelatedTarget = nullptr);
@ -365,7 +365,7 @@ class nsFocusManager final : public nsIFocusManager,
* aWindowRaised should only be true if called from WindowRaised.
*/
void FireFocusOrBlurEvent(
mozilla::EventMessage aEventMessage, nsIPresShell* aPresShell,
mozilla::EventMessage aEventMessage, mozilla::PresShell* aPresShell,
nsISupports* aTarget, bool aWindowRaised, bool aIsRefocus = false,
mozilla::dom::EventTarget* aRelatedTarget = nullptr);
@ -387,7 +387,7 @@ class nsFocusManager final : public nsIFocusManager,
* losing focus for focusin, the object getting focus for focusout).
*/
void FireFocusInOrOutEvent(
mozilla::EventMessage aEventMessage, nsIPresShell* aPresShell,
mozilla::EventMessage aEventMessage, mozilla::PresShell* aPresShell,
nsISupports* aTarget, nsPIDOMWindowOuter* aCurrentFocusedWindow,
nsIContent* aCurrentFocusedContent,
mozilla::dom::EventTarget* aRelatedTarget = nullptr);
@ -418,12 +418,12 @@ class nsFocusManager final : public nsIFocusManager,
/**
* Helper method to move the caret to the focused element aContent.
*/
void MoveCaretToFocus(nsIPresShell* aPresShell, nsIContent* aContent);
void MoveCaretToFocus(mozilla::PresShell* aPresShell, nsIContent* aContent);
/**
* Makes the caret visible or not, depending on aVisible.
*/
nsresult SetCaretVisible(nsIPresShell* aPresShell, bool aVisible,
nsresult SetCaretVisible(mozilla::PresShell* aPresShell, bool aVisible,
nsIContent* aContent);
// the remaining functions are used for tab key and document-navigation
@ -432,7 +432,8 @@ class nsFocusManager final : public nsIFocusManager,
* Retrieves the start and end points of the current selection for
* aDocument and stores them in aStartContent and aEndContent.
*/
nsresult GetSelectionLocation(Document* aDocument, nsIPresShell* aPresShell,
nsresult GetSelectionLocation(Document* aDocument,
mozilla::PresShell* aPresShell,
nsIContent** aStartContent,
nsIContent** aEndContent);
@ -539,7 +540,7 @@ class nsFocusManager final : public nsIFocusManager,
* focusable, since it doesn't really have a defined tab index.
*/
nsresult GetNextTabbableContent(
nsIPresShell* aPresShell, nsIContent* aRootContent,
mozilla::PresShell* aPresShell, nsIContent* aRootContent,
nsIContent* aOriginalStartContent, nsIContent* aStartContent,
bool aForward, int32_t aCurrentTabIndex, bool aIgnoreTabIndex,
bool aForDocumentNavigation, nsIContent** aResultContent);

Просмотреть файл

@ -23,6 +23,7 @@
#include "mozilla/InternalMutationEvent.h"
#include "mozilla/Likely.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/PresShell.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/Telemetry.h"
#include "mozilla/TextEditor.h"
@ -67,7 +68,6 @@
#include "nsILinkHandler.h"
#include "mozilla/dom/NodeInfo.h"
#include "mozilla/dom/NodeInfoInlines.h"
#include "nsIPresShell.h"
#include "nsIScriptError.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptSecurityManager.h"
@ -314,7 +314,7 @@ static nsIContent* GetRootForContentSubtree(nsIContent* aContent) {
return aContent;
}
nsIContent* nsINode::GetSelectionRootContent(nsIPresShell* aPresShell) {
nsIContent* nsINode::GetSelectionRootContent(PresShell* aPresShell) {
NS_ENSURE_TRUE(aPresShell, nullptr);
if (IsDocument()) return AsDocument()->GetRootElement();

Просмотреть файл

@ -45,7 +45,6 @@ class nsIHTMLCollection;
class nsIMutationObserver;
class nsINode;
class nsINodeList;
class nsIPresShell;
class nsIPrincipal;
class nsIURI;
class nsNodeSupportsWeakRefTearoff;
@ -56,6 +55,7 @@ struct RawServoSelectorList;
namespace mozilla {
class EventListenerManager;
class PresShell;
class TextEditor;
namespace dom {
/**
@ -1180,7 +1180,7 @@ class nsINode : public mozilla::dom::EventTarget {
* node. Be aware that if this node and the computed selection limiter are
* not in same subtree, this returns the root content of the closeset subtree.
*/
nsIContent* GetSelectionRootContent(nsIPresShell* aPresShell);
nsIContent* GetSelectionRootContent(mozilla::PresShell* aPresShell);
nsINodeList* ChildNodes();

Просмотреть файл

@ -1008,21 +1008,26 @@ class CanvasRenderingContext2D final : public nsICanvasRenderingContextInternal,
// other helpers
void GetAppUnitsValues(int32_t* aPerDevPixel, int32_t* aPerCSSPixel) {
// If we don't have a canvas element, we just return something generic.
int32_t devPixel = 60;
int32_t cssPixel = 60;
nsIPresShell* ps = GetPresShell();
nsPresContext* pc;
if (!ps) goto FINISH;
pc = ps->GetPresContext();
if (!pc) goto FINISH;
devPixel = pc->AppUnitsPerDevPixel();
cssPixel = AppUnitsPerCSSPixel();
FINISH:
if (aPerDevPixel) *aPerDevPixel = devPixel;
if (aPerCSSPixel) *aPerCSSPixel = cssPixel;
if (aPerDevPixel) {
*aPerDevPixel = 60;
}
if (aPerCSSPixel) {
*aPerCSSPixel = 60;
}
PresShell* presShell = GetPresShell();
if (!presShell) {
return;
}
nsPresContext* presContext = presShell->GetPresContext();
if (!presContext) {
return;
}
if (aPerDevPixel) {
*aPerDevPixel = presContext->AppUnitsPerDevPixel();
}
if (aPerCSSPixel) {
*aPerCSSPixel = AppUnitsPerCSSPixel();
}
}
friend struct CanvasBidiProcessor;

Просмотреть файл

@ -599,11 +599,11 @@ CSSIntPoint Event::GetClientCoords(nsPresContext* aPresContext,
return aDefaultPoint;
}
nsIPresShell* shell = aPresContext->GetPresShell();
if (!shell) {
PresShell* presShell = aPresContext->GetPresShell();
if (!presShell) {
return CSSIntPoint(0, 0);
}
nsIFrame* rootFrame = shell->GetRootFrame();
nsIFrame* rootFrame = presShell->GetRootFrame();
if (!rootFrame) {
return CSSIntPoint(0, 0);
}

Просмотреть файл

@ -4852,9 +4852,9 @@ bool EventStateManager::EventCausesClickEvents(
nsresult EventStateManager::InitAndDispatchClickEvent(
WidgetMouseEvent* aMouseUpEvent, nsEventStatus* aStatus,
EventMessage aMessage, nsIPresShell* aPresShell,
nsIContent* aMouseUpContent, AutoWeakFrame aCurrentTarget,
bool aNoContentDispatch, nsIContent* aOverrideClickTarget) {
EventMessage aMessage, PresShell* aPresShell, nsIContent* aMouseUpContent,
AutoWeakFrame aCurrentTarget, bool aNoContentDispatch,
nsIContent* aOverrideClickTarget) {
MOZ_ASSERT(aMouseUpEvent);
MOZ_ASSERT(EventCausesClickEvents(*aMouseUpEvent));
MOZ_ASSERT(aMouseUpContent || aCurrentTarget || aOverrideClickTarget);
@ -4974,7 +4974,7 @@ nsresult EventStateManager::PostHandleMouseUp(
}
nsresult EventStateManager::DispatchClickEvents(
nsIPresShell* aPresShell, WidgetMouseEvent* aMouseUpEvent,
PresShell* aPresShell, WidgetMouseEvent* aMouseUpEvent,
nsEventStatus* aStatus, nsIContent* aClickTarget,
nsIContent* aOverrideClickTarget) {
MOZ_ASSERT(aPresShell);
@ -5021,7 +5021,7 @@ nsresult EventStateManager::DispatchClickEvents(
}
nsresult EventStateManager::HandleMiddleClickPaste(
nsIPresShell* aPresShell, WidgetMouseEvent* aMouseEvent,
PresShell* aPresShell, WidgetMouseEvent* aMouseEvent,
nsEventStatus* aStatus, TextEditor* aTextEditor) {
MOZ_ASSERT(aPresShell);
MOZ_ASSERT(aMouseEvent);
@ -5060,8 +5060,7 @@ nsresult EventStateManager::HandleMiddleClickPaste(
nsCOMPtr<nsIContent> container;
int32_t offset;
nsLayoutUtils::GetContainerAndOffsetAtEvent(
static_cast<PresShell*>(aPresShell), aMouseEvent,
getter_AddRefs(container), &offset);
aPresShell, aMouseEvent, getter_AddRefs(container), &offset);
if (container) {
// XXX If readonly or disabled <input> or <textarea> in contenteditable
// designMode editor is clicked, the point is in the editor.
@ -5087,8 +5086,7 @@ nsresult EventStateManager::HandleMiddleClickPaste(
// Fire ePaste event by ourselves since we need to dispatch "paste" event
// even if the middle click event was consumed for compatibility with
// Chromium.
if (!nsCopySupport::FireClipboardEvent(ePaste, clipboardType,
static_cast<PresShell*>(aPresShell),
if (!nsCopySupport::FireClipboardEvent(ePaste, clipboardType, aPresShell,
selection)) {
*aStatus = nsEventStatus_eConsumeNoDefault;
return NS_OK;

Просмотреть файл

@ -370,7 +370,7 @@ class EventStateManager : public nsSupportsWeakReference, public nsIObserver {
* set nullptr.
*/
MOZ_CAN_RUN_SCRIPT
nsresult HandleMiddleClickPaste(nsIPresShell* aPresShell,
nsresult HandleMiddleClickPaste(PresShell* aPresShell,
WidgetMouseEvent* aMouseEvent,
nsEventStatus* aStatus,
TextEditor* aTextEditor);
@ -492,9 +492,9 @@ class EventStateManager : public nsSupportsWeakReference, public nsIObserver {
MOZ_CAN_RUN_SCRIPT
static nsresult InitAndDispatchClickEvent(
WidgetMouseEvent* aMouseUpEvent, nsEventStatus* aStatus,
EventMessage aMessage, nsIPresShell* aPresShell,
nsIContent* aMouseUpContent, AutoWeakFrame aCurrentTarget,
bool aNoContentDispatch, nsIContent* aOverrideClickTarget);
EventMessage aMessage, PresShell* aPresShell, nsIContent* aMouseUpContent,
AutoWeakFrame aCurrentTarget, bool aNoContentDispatch,
nsIContent* aOverrideClickTarget);
nsresult SetClickCount(WidgetMouseEvent* aEvent, nsEventStatus* aStatus,
nsIContent* aOverrideClickTarget = nullptr);
@ -545,7 +545,7 @@ class EventStateManager : public nsSupportsWeakReference, public nsIObserver {
* current target frame of the ESM are ignored.
*/
MOZ_CAN_RUN_SCRIPT
nsresult DispatchClickEvents(nsIPresShell* aPresShell,
nsresult DispatchClickEvents(PresShell* aPresShell,
WidgetMouseEvent* aMouseUpEvent,
nsEventStatus* aStatus,
nsIContent* aMouseUpContent,

Просмотреть файл

@ -258,7 +258,7 @@ nsresult HTMLButtonElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
nsEventStatus status = nsEventStatus_eIgnore;
RefPtr<PresShell> presShell = aVisitor.mPresContext->GetPresShell();
// If |nsIPresShell::Destroy| has been called due to
// If |PresShell::Destroy| has been called due to
// handling the event, the pres context will return
// a null pres shell. See bug 125624.
//

Просмотреть файл

@ -2854,8 +2854,8 @@ nsresult HTMLInputElement::MaybeSubmitForm(nsPresContext* aPresContext) {
return NS_OK;
}
nsCOMPtr<nsIPresShell> shell = aPresContext->GetPresShell();
if (!shell) {
RefPtr<PresShell> presShell = aPresContext->GetPresShell();
if (!presShell) {
return NS_OK;
}
@ -2868,7 +2868,7 @@ nsresult HTMLInputElement::MaybeSubmitForm(nsPresContext* aPresContext) {
// submitting the form.
WidgetMouseEvent event(true, eMouseClick, nullptr, WidgetMouseEvent::eReal);
nsEventStatus status = nsEventStatus_eIgnore;
shell->HandleDOMEventWithTarget(submitContent, &event, &status);
presShell->HandleDOMEventWithTarget(submitContent, &event, &status);
} else if (!mForm->ImplicitSubmissionIsDisabled() &&
mForm->SubmissionCanProceed(nullptr)) {
// TODO: removing this code and have the submit event sent by the form,
@ -2878,7 +2878,7 @@ nsresult HTMLInputElement::MaybeSubmitForm(nsPresContext* aPresContext) {
RefPtr<mozilla::dom::HTMLFormElement> form = mForm;
InternalFormEvent event(true, eFormSubmit);
nsEventStatus status = nsEventStatus_eIgnore;
shell->HandleDOMEventWithTarget(form, &event, &status);
presShell->HandleDOMEventWithTarget(form, &event, &status);
}
return NS_OK;
@ -3710,11 +3710,10 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
InternalUIEvent actEvent(true, eLegacyDOMActivate, mouseEvent);
actEvent.mDetail = 1;
nsCOMPtr<nsIPresShell> shell = aVisitor.mPresContext->GetPresShell();
if (shell) {
if (RefPtr<PresShell> presShell = aVisitor.mPresContext->GetPresShell()) {
nsEventStatus status = nsEventStatus_eIgnore;
mInInternalActivate = true;
rv = shell->HandleDOMEventWithTarget(this, &actEvent, &status);
rv = presShell->HandleDOMEventWithTarget(this, &actEvent, &status);
mInInternalActivate = false;
// If activate is cancelled, we must do the same as when click is
@ -4119,10 +4118,10 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
event.mOriginator = this;
nsEventStatus status = nsEventStatus_eIgnore;
nsCOMPtr<nsIPresShell> presShell =
RefPtr<PresShell> presShell =
aVisitor.mPresContext->GetPresShell();
// If |nsIPresShell::Destroy| has been called due to
// If |PresShell::Destroy| has been called due to
// handling the event the pres context will return a null
// pres shell. See bug 125624.
// TODO: removing this code and have the submit event sent by the

Просмотреть файл

@ -941,7 +941,7 @@ interface nsIDOMWindowUtils : nsISupports {
readonly attribute float fullZoom;
/**
* Dispatches aEvent as a trusted event via the nsIPresShell object of the
* Dispatches aEvent as a trusted event via the PresShell object of the
* window's document.
* The event is dispatched to aTarget, which should be an object
* which implements nsIContent interface (#element, #text, etc).

Просмотреть файл

@ -3137,7 +3137,7 @@ nsPluginInstanceOwner::GetContentsScaleFactor(double* result) {
// pixels.
#if defined(XP_MACOSX) || defined(XP_WIN)
nsCOMPtr<nsIContent> content = do_QueryReferent(mContent);
nsIPresShell* presShell =
PresShell* presShell =
nsContentUtils::FindPresShellForDocument(content->OwnerDoc());
if (presShell) {
scaleFactor = double(AppUnitsPerCSSPixel()) /
@ -3152,7 +3152,7 @@ nsPluginInstanceOwner::GetContentsScaleFactor(double* result) {
void nsPluginInstanceOwner::GetCSSZoomFactor(float* result) {
nsCOMPtr<nsIContent> content = do_QueryReferent(mContent);
nsIPresShell* presShell =
PresShell* presShell =
nsContentUtils::FindPresShellForDocument(content->OwnerDoc());
if (presShell) {
*result = presShell->GetPresContext()->DeviceContext()->GetFullZoom();

Просмотреть файл

@ -202,6 +202,7 @@ class nsXBLPrototypeHandler {
MOZ_CAN_RUN_SCRIPT
nsresult DispatchXBLCommand(mozilla::dom::EventTarget* aTarget,
mozilla::dom::Event* aEvent);
MOZ_CAN_RUN_SCRIPT
nsresult DispatchXULKeyCommand(mozilla::dom::Event* aEvent);
nsresult EnsureEventHandler(mozilla::dom::AutoJSAPI& jsapi, nsAtom* aName,
JS::MutableHandle<JSObject*> aHandler);

Просмотреть файл

@ -1028,9 +1028,9 @@ nsresult nsXULElement::DispatchXULCommand(const EventChainVisitor& aVisitor,
}
WidgetInputEvent* orig = aVisitor.mEvent->AsInputEvent();
nsContentUtils::DispatchXULCommand(
commandElt, orig->IsTrusted(), aVisitor.mDOMEvent, nullptr,
orig->IsControl(), orig->IsAlt(), orig->IsShift(), orig->IsMeta(),
inputSource);
commandElt, orig->IsTrusted(), MOZ_KnownLive(aVisitor.mDOMEvent),
nullptr, orig->IsControl(), orig->IsAlt(), orig->IsShift(),
orig->IsMeta(), inputSource);
} else {
NS_WARNING("A XUL element is attached to a command that doesn't exist!\n");
}
@ -1190,7 +1190,8 @@ void nsXULElement::ClickWithInputSource(uint16_t aInputSource,
void nsXULElement::DoCommand() {
nsCOMPtr<Document> doc = GetComposedDoc(); // strong just in case
if (doc) {
nsContentUtils::DispatchXULCommand(this, true);
RefPtr<nsXULElement> self = this;
nsContentUtils::DispatchXULCommand(self, true);
}
}

Просмотреть файл

@ -324,6 +324,7 @@ class nsXULElement : public nsStyledElement {
// nsINode
void GetEventTargetParent(mozilla::EventChainPreVisitor& aVisitor) override;
MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual nsresult PreHandleEvent(
mozilla::EventChainVisitor& aVisitor) override;
// nsIContent
@ -515,7 +516,7 @@ class nsXULElement : public nsStyledElement {
already_AddRefed<mozilla::dom::BoxObject> GetBoxObject(
mozilla::ErrorResult& rv);
void Click(mozilla::dom::CallerType aCallerType);
void DoCommand();
MOZ_CAN_RUN_SCRIPT_BOUNDARY void DoCommand();
// Style() inherited from nsStyledElement
nsINode* GetScopeChainParent() const override {
@ -624,6 +625,7 @@ class nsXULElement : public nsStyledElement {
bool IsEventStoppedFromAnonymousScrollbar(mozilla::EventMessage aMessage);
MOZ_CAN_RUN_SCRIPT
nsresult DispatchXULCommand(const mozilla::EventChainVisitor& aVisitor,
nsAutoString& aCommand);
};

Просмотреть файл

@ -199,12 +199,12 @@ void nsButtonBoxFrame::MouseClicked(WidgetGUIEvent* aEvent) {
}
// Execute the oncommand event handler.
nsCOMPtr<nsIContent> content = mContent;
WidgetInputEvent* inputEvent = aEvent->AsInputEvent();
WidgetMouseEventBase* mouseEvent = aEvent->AsMouseEventBase();
nsContentUtils::DispatchXULCommand(
mContent, aEvent->IsTrusted(), nullptr, presShell,
inputEvent->IsControl(), inputEvent->IsAlt(), inputEvent->IsShift(),
inputEvent->IsMeta(),
content, aEvent->IsTrusted(), nullptr, presShell, inputEvent->IsControl(),
inputEvent->IsAlt(), inputEvent->IsShift(), inputEvent->IsMeta(),
mouseEvent ? mouseEvent->mInputSource
: MouseEvent_Binding::MOZ_SOURCE_UNKNOWN);
}

Просмотреть файл

@ -35,6 +35,7 @@ class nsButtonBoxFrame : public nsBoxFrame {
mozilla::WidgetGUIEvent* aEvent,
nsEventStatus* aEventStatus) override;
MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual void MouseClicked(mozilla::WidgetGUIEvent* aEvent);
void Blurred();

Просмотреть файл

@ -1948,9 +1948,11 @@ nsMenuPopupFrame::ChangeMenuItem(nsMenuFrame* aMenuItem, bool aSelectFirstItem,
// Fire a command event as the new item, but we don't want to close
// the menu, blink it, or update any other state of the menuitem. The
// command event will cause the item to be selected.
nsContentUtils::DispatchXULCommand(
aMenuItem->GetContent(), /* aTrusted = */ true, nullptr, PresShell(),
false, false, false, false);
nsCOMPtr<nsIContent> menuItemContent = aMenuItem->GetContent();
RefPtr<mozilla::PresShell> presShell = PresShell();
nsContentUtils::DispatchXULCommand(menuItemContent, /* aTrusted = */ true,
nullptr, presShell, false, false,
false, false);
}
#endif
}

Просмотреть файл

@ -180,6 +180,7 @@ class nsMenuPopupFrame final : public nsBoxFrame,
virtual nsMenuFrame* GetCurrentMenuItem() override;
NS_IMETHOD SetCurrentMenuItem(nsMenuFrame* aMenuItem) override;
virtual void CurrentMenuIsBeingDestroyed() override;
MOZ_CAN_RUN_SCRIPT_BOUNDARY
NS_IMETHOD ChangeMenuItem(nsMenuFrame* aMenuItem, bool aSelectFirstItem,
bool aFromKey) override;

Просмотреть файл

@ -528,7 +528,8 @@ nsResizerFrame::Direction nsResizerFrame::GetDirection() {
void nsResizerFrame::MouseClicked(WidgetMouseEvent* aEvent) {
// Execute the oncommand event handler.
nsCOMPtr<nsIContent> content = mContent;
nsContentUtils::DispatchXULCommand(
mContent, false, nullptr, nullptr, aEvent->IsControl(), aEvent->IsAlt(),
content, false, nullptr, nullptr, aEvent->IsControl(), aEvent->IsAlt(),
aEvent->IsShift(), aEvent->IsMeta(), aEvent->mInputSource);
}

Просмотреть файл

@ -38,6 +38,7 @@ class nsResizerFrame final : public nsTitleBarFrame {
mozilla::WidgetGUIEvent* aEvent,
nsEventStatus* aEventStatus) override;
MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual void MouseClicked(mozilla::WidgetMouseEvent* aEvent) override;
protected:

Просмотреть файл

@ -156,7 +156,8 @@ nsresult nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext,
void nsTitleBarFrame::MouseClicked(WidgetMouseEvent* aEvent) {
// Execute the oncommand event handler.
nsCOMPtr<nsIContent> content = mContent;
nsContentUtils::DispatchXULCommand(
mContent, false, nullptr, nullptr, aEvent->IsControl(), aEvent->IsAlt(),
content, false, nullptr, nullptr, aEvent->IsControl(), aEvent->IsAlt(),
aEvent->IsShift(), aEvent->IsMeta(), aEvent->mInputSource);
}

Просмотреть файл

@ -31,6 +31,7 @@ class nsTitleBarFrame : public nsBoxFrame {
mozilla::WidgetGUIEvent* aEvent,
nsEventStatus* aEventStatus) override;
MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual void MouseClicked(mozilla::WidgetMouseEvent* aEvent);
void UpdateMouseThrough() override {

Просмотреть файл

@ -2669,7 +2669,8 @@ nsXULMenuCommandEvent::Run() {
AutoHandlingUserInputStatePusher userInpStatePusher(
mUserInput, nullptr, presShell->GetDocument());
nsContentUtils::DispatchXULCommand(mMenu, mIsTrusted, nullptr, presShell,
RefPtr<Element> menu = mMenu;
nsContentUtils::DispatchXULCommand(menu, mIsTrusted, nullptr, presShell,
mControl, mAlt, mShift, mMeta);
}

Просмотреть файл

@ -300,7 +300,7 @@ class nsXULMenuCommandEvent : public mozilla::Runnable {
"null menu supplied to nsXULMenuCommandEvent constructor");
}
NS_IMETHOD Run() override;
MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD Run() override;
void SetCloseMenuMode(CloseMenuMode aCloseMenuMode) {
mCloseMenuMode = aCloseMenuMode;