summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/HTMLEditor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/libeditor/HTMLEditor.cpp')
-rw-r--r--editor/libeditor/HTMLEditor.cpp264
1 files changed, 113 insertions, 151 deletions
diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp
index 532da7a15..c2f0bdc6d 100644
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -63,13 +63,13 @@
#include "nsIWidget.h"
#include "nsIFrame.h"
-#include "nsIParserService.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/DocumentFragment.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/EventTarget.h"
#include "mozilla/dom/HTMLBodyElement.h"
+#include "nsElementTable.h"
#include "nsTextFragment.h"
#include "nsContentList.h"
#include "mozilla/StyleSheet.h"
@@ -165,7 +165,7 @@ HTMLEditor::~HTMLEditor()
// free any default style propItems
RemoveAllDefaultProperties();
- if (mLinkHandler && mDocWeak) {
+ if (mLinkHandler && IsInitialized()) {
nsCOMPtr<nsIPresShell> ps = GetPresShell();
if (ps && ps->GetPresContext()) {
@@ -287,7 +287,7 @@ HTMLEditor::Init(nsIDOMDocument* aDoc,
}
// Init the HTML-CSS utils
- mCSSEditUtils = new CSSEditUtils(this);
+ mCSSEditUtils = MakeUnique<CSSEditUtils>(this);
// disable links
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
@@ -335,7 +335,7 @@ HTMLEditor::PreDestroy(bool aDestroyingFrames)
return NS_OK;
}
- nsCOMPtr<nsINode> document = do_QueryReferent(mDocWeak);
+ nsCOMPtr<nsIDocument> document = GetDocument();
if (document) {
document->RemoveMutationObserver(this);
}
@@ -365,7 +365,7 @@ HTMLEditor::UpdateRootElement()
} else {
// If there is no HTML body element,
// we should use the document root element instead.
- nsCOMPtr<nsIDOMDocument> doc = do_QueryReferent(mDocWeak);
+ nsCOMPtr<nsIDOMDocument> doc = GetDOMDocument();
if (doc) {
doc->GetDocumentElement(getter_AddRefs(rootElement));
}
@@ -430,8 +430,9 @@ HTMLEditor::CreateEventListeners()
nsresult
HTMLEditor::InstallEventListeners()
{
- NS_ENSURE_TRUE(mDocWeak && mEventListener,
- NS_ERROR_NOT_INITIALIZED);
+ if (NS_WARN_IF(!IsInitialized()) || NS_WARN_IF(!mEventListener)) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
// NOTE: HTMLEditor doesn't need to initialize mEventTarget here because
// the target must be document node and it must be referenced as weak pointer.
@@ -444,7 +445,7 @@ HTMLEditor::InstallEventListeners()
void
HTMLEditor::RemoveEventListeners()
{
- if (!mDocWeak) {
+ if (!IsInitialized()) {
return;
}
@@ -506,7 +507,8 @@ HTMLEditor::InitRules()
NS_IMETHODIMP
HTMLEditor::BeginningOfDocument()
{
- if (!mDocWeak) {
+ // XXX Why doesn't this check if the document is alive?
+ if (!IsInitialized()) {
return NS_ERROR_NOT_INITIALIZED;
}
@@ -688,49 +690,6 @@ HTMLEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
return TypedText(str, eTypedText);
}
-static void
-AssertParserServiceIsCorrect(nsIAtom* aTag, bool aIsBlock)
-{
-#ifdef DEBUG
- // Check this against what we would have said with the old code:
- if (aTag == nsGkAtoms::p ||
- aTag == nsGkAtoms::div ||
- aTag == nsGkAtoms::blockquote ||
- aTag == nsGkAtoms::h1 ||
- aTag == nsGkAtoms::h2 ||
- aTag == nsGkAtoms::h3 ||
- aTag == nsGkAtoms::h4 ||
- aTag == nsGkAtoms::h5 ||
- aTag == nsGkAtoms::h6 ||
- aTag == nsGkAtoms::ul ||
- aTag == nsGkAtoms::ol ||
- aTag == nsGkAtoms::dl ||
- aTag == nsGkAtoms::noscript ||
- aTag == nsGkAtoms::form ||
- aTag == nsGkAtoms::hr ||
- aTag == nsGkAtoms::table ||
- aTag == nsGkAtoms::fieldset ||
- aTag == nsGkAtoms::address ||
- aTag == nsGkAtoms::col ||
- aTag == nsGkAtoms::colgroup ||
- aTag == nsGkAtoms::li ||
- aTag == nsGkAtoms::dt ||
- aTag == nsGkAtoms::dd ||
- aTag == nsGkAtoms::legend) {
- if (!aIsBlock) {
- nsAutoString assertmsg (NS_LITERAL_STRING("Parser and editor disagree on blockness: "));
-
- nsAutoString tagName;
- aTag->ToString(tagName);
- assertmsg.Append(tagName);
- char* assertstr = ToNewCString(assertmsg);
- NS_ASSERTION(aIsBlock, assertstr);
- free(assertstr);
- }
- }
-#endif // DEBUG
-}
-
/**
* Returns true if the id represents an element of block type.
* Can be used to determine if a new paragraph should be started.
@@ -740,8 +699,8 @@ HTMLEditor::NodeIsBlockStatic(const nsINode* aElement)
{
MOZ_ASSERT(aElement);
- // Nodes we know we want to treat as block
- // even though the parser says they're not:
+ // We want to treat these as block nodes even though nsHTMLElement says
+ // they're not.
if (aElement->IsAnyOfHTMLElements(nsGkAtoms::body,
nsGkAtoms::head,
nsGkAtoms::tbody,
@@ -750,27 +709,13 @@ HTMLEditor::NodeIsBlockStatic(const nsINode* aElement)
nsGkAtoms::tr,
nsGkAtoms::th,
nsGkAtoms::td,
- nsGkAtoms::li,
nsGkAtoms::dt,
- nsGkAtoms::dd,
- nsGkAtoms::pre)) {
+ nsGkAtoms::dd)) {
return true;
}
- bool isBlock;
-#ifdef DEBUG
- // XXX we can't use DebugOnly here because VC++ is stupid (bug 802884)
- nsresult rv =
-#endif
- nsContentUtils::GetParserService()->
- IsBlock(nsContentUtils::GetParserService()->HTMLAtomTagToId(
- aElement->NodeInfo()->NameAtom()),
- isBlock);
- MOZ_ASSERT(rv == NS_OK);
-
- AssertParserServiceIsCorrect(aElement->NodeInfo()->NameAtom(), isBlock);
-
- return isBlock;
+ return nsHTMLElement::IsBlock(
+ nsHTMLTags::AtomTagToId(aElement->NodeInfo()->NameAtom()));
}
nsresult
@@ -1183,11 +1128,13 @@ HTMLEditor::ReplaceHeadContentsWithHTML(const nsAString& aSourceToInsert)
// Do not use AutoRules -- rules code won't let us insert in <head>. Use
// the head node as a parent and delete/insert directly.
- nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
- NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED);
+ nsCOMPtr<nsIDocument> document = GetDocument();
+ if (NS_WARN_IF(!document)) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
RefPtr<nsContentList> nodeList =
- doc->GetElementsByTagName(NS_LITERAL_STRING("head"));
+ document->GetElementsByTagName(NS_LITERAL_STRING("head"));
NS_ENSURE_TRUE(nodeList, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIContent> headNode = nodeList->Item(0);
@@ -2401,21 +2348,19 @@ HTMLEditor::GetSelectedElement(const nsAString& aTagName,
NS_ENSURE_STATE(range);
nsCOMPtr<nsIDOMNode> startParent;
- int32_t startOffset, endOffset;
nsresult rv = range->GetStartContainer(getter_AddRefs(startParent));
NS_ENSURE_SUCCESS(rv, rv);
- rv = range->GetStartOffset(&startOffset);
- NS_ENSURE_SUCCESS(rv, rv);
+ uint32_t startOffset = range->StartOffset();
nsCOMPtr<nsIDOMNode> endParent;
rv = range->GetEndContainer(getter_AddRefs(endParent));
NS_ENSURE_SUCCESS(rv, rv);
- rv = range->GetEndOffset(&endOffset);
- NS_ENSURE_SUCCESS(rv, rv);
+ uint32_t endOffset = range->EndOffset();
// Optimization for a single selected element
if (startParent && startParent == endParent && endOffset - startOffset == 1) {
- nsCOMPtr<nsIDOMNode> selectedNode = GetChildAt(startParent, startOffset);
+ nsCOMPtr<nsIDOMNode> selectedNode =
+ GetChildAt(startParent, static_cast<int32_t>(startOffset));
NS_ENSURE_SUCCESS(rv, NS_OK);
if (selectedNode) {
selectedNode->GetNodeName(domTagName);
@@ -2705,7 +2650,7 @@ HTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement)
nsresult
HTMLEditor::SetHTMLBackgroundColor(const nsAString& aColor)
{
- NS_PRECONDITION(mDocWeak, "Missing Editor DOM Document");
+ MOZ_ASSERT(IsInitialized(), "The HTMLEditor hasn't been initialized yet");
// Find a selected or enclosing table element to set background on
nsCOMPtr<nsIDOMElement> element;
@@ -2753,7 +2698,7 @@ HTMLEditor::SetBodyAttribute(const nsAString& aAttribute,
{
// TODO: Check selection for Cell, Row, Column or table and do color on appropriate level
- NS_ASSERTION(mDocWeak, "Missing Editor DOM Document");
+ MOZ_ASSERT(IsInitialized(), "The HTMLEditor hasn't been initialized yet");
// Set the background color attribute on the body tag
nsCOMPtr<nsIDOMElement> bodyElement = do_QueryInterface(GetRoot());
@@ -2832,7 +2777,9 @@ HTMLEditor::ReplaceStyleSheet(const nsAString& aURL)
}
// Make sure the pres shell doesn't disappear during the load.
- NS_ENSURE_TRUE(mDocWeak, NS_ERROR_NOT_INITIALIZED);
+ if (NS_WARN_IF(!IsInitialized())) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
nsCOMPtr<nsIPresShell> ps = GetPresShell();
NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
@@ -2941,7 +2888,9 @@ HTMLEditor::RemoveOverrideStyleSheet(const nsAString& aURL)
NS_ENSURE_TRUE(sheet, NS_OK); /// Don't fail if sheet not found
- NS_ENSURE_TRUE(mDocWeak, NS_ERROR_NOT_INITIALIZED);
+ if (NS_WARN_IF(!IsInitialized())) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
nsCOMPtr<nsIPresShell> ps = GetPresShell();
NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
@@ -2960,8 +2909,8 @@ HTMLEditor::EnableStyleSheet(const nsAString& aURL,
NS_ENSURE_TRUE(sheet, NS_OK); // Don't fail if sheet not found
// Ensure the style sheet is owned by our document.
- nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
- sheet->SetOwningDocument(doc);
+ nsCOMPtr<nsIDocument> document = GetDocument();
+ sheet->SetAssociatedDocument(document, StyleSheet::NotOwnedByDocument);
if (sheet->IsServo()) {
// XXXheycam ServoStyleSheets don't support being enabled/disabled yet.
@@ -2982,8 +2931,8 @@ HTMLEditor::EnableExistingStyleSheet(const nsAString& aURL)
}
// Ensure the style sheet is owned by our document.
- nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
- sheet->SetOwningDocument(doc);
+ nsCOMPtr<nsIDocument> document = GetDocument();
+ sheet->SetAssociatedDocument(document, StyleSheet::NotOwnedByDocument);
if (sheet->IsServo()) {
// XXXheycam ServoStyleSheets don't support being enabled/disabled yet.
@@ -3284,8 +3233,8 @@ HTMLEditor::DoContentInserted(nsIDocument* aDocument,
sibling = sibling->GetNextSibling();
}
}
- nsresult rv = range->Set(aContainer, aIndexInContainer,
- aContainer, endIndex);
+ nsresult rv = range->SetStartAndEnd(aContainer, aIndexInContainer,
+ aContainer, endIndex);
if (NS_SUCCEEDED(rv)) {
mInlineSpellChecker->SpellCheckRange(range);
}
@@ -3374,13 +3323,12 @@ HTMLEditor::GetIsSelectionEditable(bool* aIsSelectionEditable)
static nsresult
SetSelectionAroundHeadChildren(Selection* aSelection,
- nsIWeakReference* aDocWeak)
+ nsCOMPtr<nsIDocument>& aDocument)
{
- // Set selection around <head> node
- nsCOMPtr<nsIDocument> doc = do_QueryReferent(aDocWeak);
- NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED);
+ MOZ_ASSERT(aDocument);
- dom::Element* headNode = doc->GetHeadElement();
+ // Set selection around <head> node
+ dom::Element* headNode = aDocument->GetHeadElement();
NS_ENSURE_STATE(headNode);
// Collapse selection to before first child of the head,
@@ -3401,7 +3349,11 @@ HTMLEditor::GetHeadContentsAsHTML(nsAString& aOutputString)
// Save current selection
AutoSelectionRestorer selectionRestorer(selection, this);
- nsresult rv = SetSelectionAroundHeadChildren(selection, mDocWeak);
+ nsCOMPtr<nsIDocument> document = GetDocument();
+ if (NS_WARN_IF(!document)) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
+ nsresult rv = SetSelectionAroundHeadChildren(selection, document);
NS_ENSURE_SUCCESS(rv, rv);
rv = OutputToString(NS_LITERAL_STRING("text/html"),
@@ -3529,17 +3481,15 @@ bool
HTMLEditor::TagCanContainTag(nsIAtom& aParentTag,
nsIAtom& aChildTag)
{
- nsIParserService* parserService = nsContentUtils::GetParserService();
-
int32_t childTagEnum;
// XXX Should this handle #cdata-section too?
if (&aChildTag == nsGkAtoms::textTagName) {
childTagEnum = eHTMLTag_text;
} else {
- childTagEnum = parserService->HTMLAtomTagToId(&aChildTag);
+ childTagEnum = nsHTMLTags::AtomTagToId(&aChildTag);
}
- int32_t parentTagEnum = parserService->HTMLAtomTagToId(&aParentTag);
+ int32_t parentTagEnum = nsHTMLTags::AtomTagToId(&aParentTag);
return HTMLEditUtils::CanContain(parentTagEnum, childTagEnum);
}
@@ -3553,8 +3503,7 @@ HTMLEditor::IsContainer(nsINode* aNode)
if (aNode->IsNodeOfType(nsINode::eTEXT)) {
tagEnum = eHTMLTag_text;
} else {
- tagEnum =
- nsContentUtils::GetParserService()->HTMLStringTagToId(aNode->NodeName());
+ tagEnum = nsHTMLTags::StringTagToId(aNode->NodeName());
}
return HTMLEditUtils::IsContainer(tagEnum);
@@ -3581,15 +3530,11 @@ HTMLEditor::SelectEntireDocument(Selection* aSelection)
// Protect the edit rules object from dying
nsCOMPtr<nsIEditRules> rules(mRules);
- // get editor root node
- nsCOMPtr<nsIDOMElement> rootElement = do_QueryInterface(GetRoot());
-
// is doc empty?
- bool bDocIsEmpty;
- nsresult rv = rules->DocumentIsEmpty(&bDocIsEmpty);
- NS_ENSURE_SUCCESS(rv, rv);
+ if (rules->DocumentIsEmpty()) {
+ // get editor root node
+ Element* rootElement = GetRoot();
- if (bDocIsEmpty) {
// if its empty dont select entire doc - that would select the bogus node
return aSelection->Collapse(rootElement, 0);
}
@@ -4275,10 +4220,11 @@ HTMLEditor::IsVisTextNode(nsIContent* aNode,
uint32_t length = aNode->TextLength();
if (aSafeToAskFrames) {
- nsCOMPtr<nsISelectionController> selCon;
- nsresult rv = GetSelectionController(getter_AddRefs(selCon));
- NS_ENSURE_SUCCESS(rv, rv);
- NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
+ nsCOMPtr<nsISelectionController> selectionController =
+ GetSelectionController();
+ if (NS_WARN_IF(!selectionController)) {
+ return NS_ERROR_FAILURE;
+ }
bool isVisible = false;
// ask the selection controller for information about whether any
// of the data in the node is really rendered. This is really
@@ -4286,7 +4232,8 @@ HTMLEditor::IsVisTextNode(nsIContent* aNode,
// So we put a call in the selection controller interface, since it's already
// in bed with frames anyway. (this is a fix for bug 22227, and a
// partial fix for bug 46209)
- rv = selCon->CheckVisibilityContent(aNode, 0, length, &isVisible);
+ nsresult rv = selectionController->CheckVisibilityContent(aNode, 0, length,
+ &isVisible);
NS_ENSURE_SUCCESS(rv, rv);
if (isVisible) {
*outIsEmptyNode = false;
@@ -4802,7 +4749,9 @@ HTMLEditor::GetElementOrigin(nsIDOMElement* aElement,
aX = 0;
aY = 0;
- NS_ENSURE_TRUE(mDocWeak, NS_ERROR_NOT_INITIALIZED);
+ if (NS_WARN_IF(!IsInitialized())) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
nsCOMPtr<nsIPresShell> ps = GetPresShell();
NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
@@ -4944,28 +4893,29 @@ HTMLEditor::GetReturnInParagraphCreatesNewParagraph(bool* aCreatesNewParagraph)
already_AddRefed<nsIContent>
HTMLEditor::GetFocusedContent()
{
- NS_ENSURE_TRUE(mDocWeak, nullptr);
-
nsFocusManager* fm = nsFocusManager::GetFocusManager();
NS_ENSURE_TRUE(fm, nullptr);
nsCOMPtr<nsIContent> focusedContent = fm->GetFocusedContent();
- nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
- bool inDesignMode = doc->HasFlag(NODE_IS_EDITABLE);
+ nsCOMPtr<nsIDocument> document = GetDocument();
+ if (NS_WARN_IF(!document)) {
+ return nullptr;
+ }
+ bool inDesignMode = document->HasFlag(NODE_IS_EDITABLE);
if (!focusedContent) {
// in designMode, nobody gets focus in most cases.
if (inDesignMode && OurWindowHasFocus()) {
- nsCOMPtr<nsIContent> docRoot = doc->GetRootElement();
- return docRoot.forget();
+ nsCOMPtr<nsIContent> rootContent = document->GetRootElement();
+ return rootContent.forget();
}
return nullptr;
}
if (inDesignMode) {
return OurWindowHasFocus() &&
- nsContentUtils::ContentIsDescendantOf(focusedContent, doc) ?
- focusedContent.forget() : nullptr;
+ nsContentUtils::ContentIsDescendantOf(focusedContent, document) ?
+ focusedContent.forget() : nullptr;
}
// We're HTML editor for contenteditable
@@ -4988,28 +4938,32 @@ HTMLEditor::GetFocusedContentForIME()
return nullptr;
}
- nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
- NS_ENSURE_TRUE(doc, nullptr);
- return doc->HasFlag(NODE_IS_EDITABLE) ? nullptr : focusedContent.forget();
+ nsCOMPtr<nsIDocument> document = GetDocument();
+ if (NS_WARN_IF(!document)) {
+ return nullptr;
+ }
+ return document->HasFlag(NODE_IS_EDITABLE) ? nullptr :
+ focusedContent.forget();
}
bool
HTMLEditor::IsActiveInDOMWindow()
{
- NS_ENSURE_TRUE(mDocWeak, false);
-
nsFocusManager* fm = nsFocusManager::GetFocusManager();
NS_ENSURE_TRUE(fm, false);
- nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
- bool inDesignMode = doc->HasFlag(NODE_IS_EDITABLE);
+ nsCOMPtr<nsIDocument> document = GetDocument();
+ if (NS_WARN_IF(!document)) {
+ return false;
+ }
+ bool inDesignMode = document->HasFlag(NODE_IS_EDITABLE);
// If we're in designMode, we're always active in the DOM window.
if (inDesignMode) {
return true;
}
- nsPIDOMWindowOuter* ourWindow = doc->GetWindow();
+ nsPIDOMWindowOuter* ourWindow = document->GetWindow();
nsCOMPtr<nsPIDOMWindowOuter> win;
nsIContent* content =
nsFocusManager::GetFocusedDescendant(ourWindow, false,
@@ -5032,12 +4986,12 @@ HTMLEditor::IsActiveInDOMWindow()
Element*
HTMLEditor::GetActiveEditingHost()
{
- NS_ENSURE_TRUE(mDocWeak, nullptr);
-
- nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
- NS_ENSURE_TRUE(doc, nullptr);
- if (doc->HasFlag(NODE_IS_EDITABLE)) {
- return doc->GetBodyElement();
+ nsCOMPtr<nsIDocument> document = GetDocument();
+ if (NS_WARN_IF(!document)) {
+ return nullptr;
+ }
+ if (document->HasFlag(NODE_IS_EDITABLE)) {
+ return document->GetBodyElement();
}
// We're HTML editor for contenteditable
@@ -5066,8 +5020,8 @@ HTMLEditor::GetDOMEventTarget()
// Don't use getDocument here, because we have no way of knowing
// whether Init() was ever called. So we need to get the document
// ourselves, if it exists.
- NS_PRECONDITION(mDocWeak, "This editor has not been initialized yet");
- nsCOMPtr<mozilla::dom::EventTarget> target = do_QueryReferent(mDocWeak);
+ MOZ_ASSERT(IsInitialized(), "The HTMLEditor has not been initialized yet");
+ nsCOMPtr<mozilla::dom::EventTarget> target = GetDocument();
return target.forget();
}
@@ -5121,12 +5075,16 @@ HTMLEditor::NotifyRootChanged()
nsresult
HTMLEditor::GetBodyElement(nsIDOMHTMLElement** aBody)
{
- NS_PRECONDITION(mDocWeak, "bad state, null mDocWeak");
- nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryReferent(mDocWeak);
- if (!htmlDoc) {
+ MOZ_ASSERT(IsInitialized(), "The HTMLEditor hasn't been initialized yet");
+ nsCOMPtr<nsIDocument> document = GetDocument();
+ if (NS_WARN_IF(!document)) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
+ nsCOMPtr<nsIDOMHTMLDocument> domHTMLDocument = do_QueryInterface(document);
+ if (!domHTMLDocument) {
return NS_ERROR_NOT_INITIALIZED;
}
- return htmlDoc->GetBody(aBody);
+ return domHTMLDocument->GetBody(aBody);
}
already_AddRefed<nsINode>
@@ -5146,14 +5104,13 @@ HTMLEditor::GetFocusedNode()
return node.forget();
}
- nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
- return doc.forget();
+ nsCOMPtr<nsIDocument> document = GetDocument();
+ return document.forget();
}
bool
HTMLEditor::OurWindowHasFocus()
{
- NS_ENSURE_TRUE(mDocWeak, false);
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
NS_ENSURE_TRUE(fm, false);
nsCOMPtr<mozIDOMWindowProxy> focusedWindow;
@@ -5161,8 +5118,11 @@ HTMLEditor::OurWindowHasFocus()
if (!focusedWindow) {
return false;
}
- nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
- nsPIDOMWindowOuter* ourWindow = doc->GetWindow();
+ nsCOMPtr<nsIDocument> document = GetDocument();
+ if (NS_WARN_IF(!document)) {
+ return false;
+ }
+ nsPIDOMWindowOuter* ourWindow = document->GetWindow();
return ourWindow == focusedWindow;
}
@@ -5180,12 +5140,14 @@ HTMLEditor::IsAcceptableInputEvent(WidgetGUIEvent* aGUIEvent)
return true;
}
- NS_ENSURE_TRUE(mDocWeak, false);
-
nsCOMPtr<nsIDOMEventTarget> target = aGUIEvent->GetDOMEventTarget();
NS_ENSURE_TRUE(target, false);
- nsCOMPtr<nsIDocument> document = do_QueryReferent(mDocWeak);
+ nsCOMPtr<nsIDocument> document = GetDocument();
+ if (NS_WARN_IF(!document)) {
+ return false;
+ }
+
if (document->HasFlag(NODE_IS_EDITABLE)) {
// If this editor is in designMode and the event target is the document,
// the event is for this editor.