Bug 968835 - Cleanup nsHTMLDocument::GetSelection; r=smaug

This commit is contained in:
Ms2ger 2014-04-10 13:24:24 +02:00
parent 243daf581d
commit d6b1a972d6
2 changed files with 13 additions and 16 deletions

View File

@ -9,6 +9,7 @@
#include "mozilla/DebugOnly.h"
#include "mozilla/dom/HTMLAllCollection.h"
#include "nsCOMPtr.h"
#include "nsGlobalWindow.h"
#include "nsXPIDLString.h"
#include "nsPrintfCString.h"
#include "nsReadableUtils.h"
@ -2154,28 +2155,24 @@ NS_IMETHODIMP
nsHTMLDocument::GetSelection(nsISelection** aReturn)
{
ErrorResult rv;
*aReturn = GetSelection(rv).take();
NS_IF_ADDREF(*aReturn = GetSelection(rv));
return rv.ErrorCode();
}
already_AddRefed<Selection>
nsHTMLDocument::GetSelection(ErrorResult& rv)
Selection*
nsHTMLDocument::GetSelection(ErrorResult& aRv)
{
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(GetScopeObject());
nsCOMPtr<nsPIDOMWindow> pwin = do_QueryInterface(window);
if (!pwin) {
return nullptr;
}
NS_ASSERTION(pwin->IsInnerWindow(), "Should have inner window here!");
if (!pwin->GetOuterWindow() ||
pwin->GetOuterWindow()->GetCurrentInnerWindow() != pwin) {
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(GetScopeObject());
if (!window) {
return nullptr;
}
nsCOMPtr<nsISelection> sel;
rv = window->GetSelection(getter_AddRefs(sel));
nsRefPtr<Selection> selection = static_cast<Selection*>(sel.get());
return selection.forget();
NS_ASSERTION(window->IsInnerWindow(), "Should have inner window here!");
if (!window->IsCurrentInnerWindow()) {
return nullptr;
}
return static_cast<nsGlobalWindow*>(window.get())->GetSelection(aRv);
}
NS_IMETHODIMP

View File

@ -233,7 +233,7 @@ public:
{
// Deprecated
}
already_AddRefed<mozilla::Selection> GetSelection(mozilla::ErrorResult& rv);
mozilla::Selection* GetSelection(mozilla::ErrorResult& aRv);
// The XPCOM CaptureEvents works fine for us.
// The XPCOM ReleaseEvents works fine for us.
// We're picking up GetLocation from Document