зеркало из https://github.com/mozilla/pjs.git
Bug 545775 part.2 Refactor GetPIDOMEventTarget() r=ehsan
This commit is contained in:
Родитель
bc3dcb3c02
Коммит
7f1bf189ca
|
@ -326,6 +326,13 @@ nsEditor::InstallEventListeners()
|
|||
{
|
||||
NS_ENSURE_TRUE(mDocWeak && mPresShellWeak && mEventListener,
|
||||
NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
// Initialize the event target.
|
||||
nsCOMPtr<nsIContent> rootContent = do_QueryInterface(GetRoot());
|
||||
NS_ENSURE_TRUE(rootContent, NS_ERROR_NOT_AVAILABLE);
|
||||
mEventTarget = do_QueryInterface(rootContent->GetParent());
|
||||
NS_ENSURE_TRUE(mEventTarget, NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
nsEditorEventListener* listener =
|
||||
reinterpret_cast<nsEditorEventListener*>(mEventListener.get());
|
||||
return listener->Connect(this);
|
||||
|
@ -338,6 +345,7 @@ nsEditor::RemoveEventListeners()
|
|||
return;
|
||||
}
|
||||
reinterpret_cast<nsEditorEventListener*>(mEventListener.get())->Disconnect();
|
||||
mEventTarget = nsnull;
|
||||
}
|
||||
|
||||
PRBool
|
||||
|
@ -5090,47 +5098,6 @@ nsEditor::HandleInlineSpellCheck(PRInt32 action,
|
|||
aEndOffset) : NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<nsPIDOMEventTarget>
|
||||
nsEditor::GetPIDOMEventTarget()
|
||||
{
|
||||
nsPIDOMEventTarget* piTarget = mEventTarget;
|
||||
if (piTarget)
|
||||
{
|
||||
NS_ADDREF(piTarget);
|
||||
return piTarget;
|
||||
}
|
||||
|
||||
nsIDOMElement *rootElement = GetRoot();
|
||||
|
||||
// Now hack to make sure we are not anonymous content.
|
||||
// If we are grab the parent of root element for our observer.
|
||||
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(rootElement);
|
||||
|
||||
if (content && content->IsRootOfNativeAnonymousSubtree())
|
||||
{
|
||||
mEventTarget = do_QueryInterface(content->GetParent());
|
||||
piTarget = mEventTarget;
|
||||
NS_IF_ADDREF(piTarget);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Don't use getDocument here, because we have no way of knowing
|
||||
// if Init() was ever called. So we need to get the document
|
||||
// ourselves, if it exists.
|
||||
if (mDocWeak)
|
||||
{
|
||||
CallQueryReferent(mDocWeak.get(), &piTarget);
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_ERROR("not initialized yet");
|
||||
}
|
||||
}
|
||||
|
||||
return piTarget;
|
||||
}
|
||||
|
||||
nsIDOMElement *
|
||||
nsEditor::GetRoot()
|
||||
{
|
||||
|
|
|
@ -581,7 +581,7 @@ public:
|
|||
nsIDOMNode *aEndNode,
|
||||
PRInt32 aEndOffset);
|
||||
|
||||
already_AddRefed<nsPIDOMEventTarget> GetPIDOMEventTarget();
|
||||
virtual already_AddRefed<nsPIDOMEventTarget> GetPIDOMEventTarget() = 0;
|
||||
|
||||
// Fast non-refcounting editor root element accessor
|
||||
nsIDOMElement *GetRoot();
|
||||
|
|
|
@ -389,6 +389,10 @@ nsHTMLEditor::InstallEventListeners()
|
|||
{
|
||||
NS_ENSURE_TRUE(mDocWeak && mPresShellWeak && mEventListener,
|
||||
NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
// NOTE: nsHTMLEditor doesn't need to initialize mEventTarget here because
|
||||
// the target must be document node and it must be referenced as weak pointer.
|
||||
|
||||
nsHTMLEditorEventListener* listener =
|
||||
reinterpret_cast<nsHTMLEditorEventListener*>(mEventListener.get());
|
||||
return listener->Connect(this);
|
||||
|
@ -5743,6 +5747,17 @@ nsHTMLEditor::HasFocus()
|
|||
return OurWindowHasFocus();
|
||||
}
|
||||
|
||||
already_AddRefed<nsPIDOMEventTarget>
|
||||
nsHTMLEditor::GetPIDOMEventTarget()
|
||||
{
|
||||
// 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<nsPIDOMEventTarget> piTarget = do_QueryReferent(mDocWeak.get());
|
||||
return piTarget.forget();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTMLEditor::GetBodyElement(nsIDOMHTMLElement** aBody)
|
||||
{
|
||||
|
|
|
@ -148,6 +148,7 @@ public:
|
|||
NS_IMETHODIMP BeginningOfDocument();
|
||||
virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent);
|
||||
virtual PRBool HasFocus();
|
||||
virtual already_AddRefed<nsPIDOMEventTarget> GetPIDOMEventTarget();
|
||||
|
||||
/* ------------ nsIEditorIMESupport overrides ------------ */
|
||||
NS_IMETHOD GetPreferredIMEState(PRUint32 *aState);
|
||||
|
|
|
@ -1754,6 +1754,13 @@ nsPlaintextEditor::SelectEntireDocument(nsISelection *aSelection)
|
|||
return nsEditor::SelectEntireDocument(aSelection);
|
||||
}
|
||||
|
||||
already_AddRefed<nsPIDOMEventTarget>
|
||||
nsPlaintextEditor::GetPIDOMEventTarget()
|
||||
{
|
||||
NS_IF_ADDREF(mEventTarget);
|
||||
return mEventTarget.get();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
|
|
|
@ -150,6 +150,8 @@ public:
|
|||
|
||||
virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent);
|
||||
|
||||
virtual already_AddRefed<nsPIDOMEventTarget> GetPIDOMEventTarget();
|
||||
|
||||
/* ------------ Utility Routines, not part of public API -------------- */
|
||||
NS_IMETHOD TypedText(const nsAString& aString, PRInt32 aAction);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче