Bug 1456588 part 1. Change nsIFocusManager::SetFocus to take Element. r=enndeakin

This commit is contained in:
Boris Zbarsky 2018-04-26 10:37:46 -04:00
Родитель 5485dd0a02
Коммит 8a0b50bea8
25 изменённых файлов: 116 добавлений и 95 удалений

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

@ -761,7 +761,9 @@ Accessible::TakeFocus()
nsFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
AutoHandlingUserInputStatePusher inputStatePusher(true, nullptr, focusContent->OwnerDoc());
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(focusContent));
// XXXbz: Can we actually have a non-element content here?
RefPtr<Element> element =
focusContent->IsElement() ? focusContent->AsElement() : nullptr;
fm->SetFocus(element, 0);
}
}

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

@ -338,15 +338,14 @@ Element::TabIndex()
void
Element::Focus(mozilla::ErrorResult& aError)
{
nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(this);
nsFocusManager* fm = nsFocusManager::GetFocusManager();
// Also other browsers seem to have the hack to not re-focus (and flush) when
// the element is already focused.
if (fm && domElement) {
if (fm) {
if (fm->CanSkipFocus(this)) {
fm->NeedsFlushBeforeEventHandling(this);
} else {
aError = fm->SetFocus(domElement, 0);
aError = fm->SetFocus(this, 0);
}
}
}
@ -3306,9 +3305,9 @@ Element::PostHandleEventForLinks(EventChainPostVisitor& aVisitor)
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(this);
fm->SetFocus(elem, nsIFocusManager::FLAG_BYMOUSE |
nsIFocusManager::FLAG_NOSCROLL);
RefPtr<Element> kungFuDeathGrip(this);
fm->SetFocus(kungFuDeathGrip, nsIFocusManager::FLAG_BYMOUSE |
nsIFocusManager::FLAG_NOSCROLL);
}
EventStateManager::SetActiveManager(

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

@ -3737,8 +3737,6 @@ Selection::NotifySelectionListeners()
// focus but only selection range is updated.
if (newEditingHost && newEditingHost != focusedElement) {
MOZ_ASSERT(!newEditingHost->IsInNativeAnonymousSubtree());
nsCOMPtr<nsIDOMElement> domElementToFocus =
do_QueryInterface(newEditingHost->AsDOMNode());
// Note that don't steal focus from focused window if the window doesn't
// have focus and if the window isn't focused window, shouldn't be
// scrolled to the new focused element.
@ -3746,7 +3744,7 @@ Selection::NotifySelectionListeners()
if (focusedWindow != fm->GetFocusedWindow()) {
flags |= nsIFocusManager::FLAG_NOSCROLL;
}
fm->SetFocus(domElementToFocus, flags);
fm->SetFocus(newEditingHost, flags);
}
}
}

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

@ -513,14 +513,13 @@ nsFocusManager::GetLastFocusMethod(mozIDOMWindowProxy* aWindow, uint32_t* aLastF
}
NS_IMETHODIMP
nsFocusManager::SetFocus(nsIDOMElement* aElement, uint32_t aFlags)
nsFocusManager::SetFocus(Element* aElement, uint32_t aFlags)
{
LOGFOCUS(("<<SetFocus begin>>"));
nsCOMPtr<nsIContent> newFocus = do_QueryInterface(aElement);
NS_ENSURE_ARG(newFocus);
NS_ENSURE_ARG(aElement);
SetFocusInner(newFocus, aFlags, true, true);
SetFocusInner(aElement, aFlags, true, true);
LOGFOCUS(("<<SetFocus end>>"));
@ -1105,10 +1104,10 @@ nsFocusManager::FireDelayedEvents(nsIDocument* aDocument)
}
NS_IMETHODIMP
nsFocusManager::FocusPlugin(nsIContent* aContent)
nsFocusManager::FocusPlugin(Element* aPlugin)
{
NS_ENSURE_ARG(aContent);
SetFocusInner(aContent, 0, true, false);
NS_ENSURE_ARG(aPlugin);
SetFocusInner(aPlugin, 0, true, false);
return NS_OK;
}

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

@ -4828,13 +4828,12 @@ nsGlobalWindowOuter::FocusOuter(ErrorResult& aError)
return;
}
nsIContent* frame = parentdoc->FindContentForSubDocument(mDoc);
nsCOMPtr<nsIDOMElement> frameElement = do_QueryInterface(frame);
if (frameElement) {
RefPtr<Element> frame = parentdoc->FindContentForSubDocument(mDoc);
if (frame) {
uint32_t flags = nsIFocusManager::FLAG_NOSCROLL;
if (canFocus)
flags |= nsIFocusManager::FLAG_RAISE;
aError = fm->SetFocus(frameElement, flags);
aError = fm->SetFocus(frame, flags);
}
return;
}
@ -7262,7 +7261,9 @@ nsGlobalWindowOuter::RestoreWindowState(nsISupports *aState)
if (nsContentUtils::ContentIsLink(focusedNode)) {
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIDOMElement> focusedElement(do_QueryInterface(focusedNode));
// This AsElement() will go away in a few changesets once we
// convert nsPIDOMWindowInner::mFocusedNode to Element.
RefPtr<Element> focusedElement = focusedNode->AsElement();
fm->SetFocus(focusedElement, nsIFocusManager::FLAG_NOSCROLL |
nsIFocusManager::FLAG_SHOWRING);
}

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

@ -1083,7 +1083,7 @@ EventStateManager::LookForAccessKeyAndExecute(
if (start == -1 && focusedContent->GetBindingParent())
start = mAccessKeys.IndexOf(focusedContent->GetBindingParent());
}
nsIContent *content;
RefPtr<Element> element;
nsIFrame *frame;
int32_t length = mAccessKeys.Count();
for (uint32_t i = 0; i < aAccessCharCodes.Length(); ++i) {
@ -1091,9 +1091,10 @@ EventStateManager::LookForAccessKeyAndExecute(
nsAutoString accessKey;
AppendUCS4ToUTF16(ch, accessKey);
for (count = 1; count <= length; ++count) {
content = mAccessKeys[(start + count) % length];
frame = content->GetPrimaryFrame();
if (IsAccessKeyTarget(content, frame, accessKey)) {
// mAccessKeys always stores Element instances.
element = mAccessKeys[(start + count) % length]->AsElement();
frame = element->GetPrimaryFrame();
if (IsAccessKeyTarget(element, frame, accessKey)) {
if (!aExecute) {
return true;
}
@ -1107,11 +1108,10 @@ EventStateManager::LookForAccessKeyAndExecute(
bool focusChanged = false;
if (shouldActivate) {
focusChanged = content->PerformAccesskey(shouldActivate, aIsTrustedEvent);
focusChanged = element->PerformAccesskey(shouldActivate, aIsTrustedEvent);
} else {
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(content);
fm->SetFocus(element, nsIFocusManager::FLAG_BYKEY);
focusChanged = true;
}
@ -3308,6 +3308,8 @@ EventStateManager::PostHandleEvent(nsPresContext* aPresContext,
}
}
MOZ_ASSERT_IF(newFocus, newFocus->IsElement());
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
// if something was found to focus, focus it. Otherwise, if the
@ -3329,8 +3331,7 @@ EventStateManager::PostHandleEvent(nsPresContext* aPresContext,
if (mouseEvent->inputSource == MouseEventBinding::MOZ_SOURCE_TOUCH) {
flags |= nsIFocusManager::FLAG_BYTOUCH;
}
nsCOMPtr<nsIDOMElement> newFocusElement = do_QueryInterface(newFocus);
fm->SetFocus(newFocusElement, flags);
fm->SetFocus(newFocus->AsElement(), flags);
}
else if (!suppressBlur) {
// clear the focus within the frame and then set it as the

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

@ -3210,7 +3210,7 @@ HTMLInputElement::Focus(ErrorResult& aError)
nsCOMPtr<nsIFormControl> formCtrl =
do_QueryInterface(childFrame->GetContent());
if (formCtrl && formCtrl->ControlType() == NS_FORM_BUTTON_BUTTON) {
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(formCtrl);
nsCOMPtr<Element> element = do_QueryInterface(formCtrl);
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm && element) {
fm->SetFocus(element, 0);

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

@ -61,9 +61,10 @@ HTMLLabelElement::Focus(ErrorResult& aError)
// retarget the focus method at the for content
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIDOMElement> elem = do_QueryObject(GetLabeledElement());
if (elem)
RefPtr<Element> elem = GetLabeledElement();
if (elem) {
fm->SetFocus(elem, 0);
}
}
}
@ -156,12 +157,12 @@ HTMLLabelElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
// pass FLAG_BYMOUSE so that we get correct focus ring behavior,
// but we don't want to pass FLAG_BYMOUSE if this click event was
// caused by the user pressing an accesskey.
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(content);
bool byMouse = (mouseEvent->inputSource != MouseEventBinding::MOZ_SOURCE_KEYBOARD);
bool byTouch = (mouseEvent->inputSource == MouseEventBinding::MOZ_SOURCE_TOUCH);
fm->SetFocus(elem, nsIFocusManager::FLAG_BYMOVEFOCUS |
(byMouse ? nsIFocusManager::FLAG_BYMOUSE : 0) |
(byTouch ? nsIFocusManager::FLAG_BYTOUCH : 0));
fm->SetFocus(content,
nsIFocusManager::FLAG_BYMOVEFOCUS |
(byMouse ? nsIFocusManager::FLAG_BYMOUSE : 0) |
(byTouch ? nsIFocusManager::FLAG_BYTOUCH : 0));
}
}
// Dispatch a new click event to |content|

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

@ -7,7 +7,8 @@
interface mozIDOMWindowProxy;
interface nsIDocument;
interface nsIContent;
webidl Element;
[scriptable, uuid(86e1f1e1-365d-493b-b52a-a649f3f311dc)]
/**
@ -81,7 +82,7 @@ interface nsIFocusManager : nsISupports
* Changes the focused element reference within the window containing
* aElement to aElement.
*/
void setFocus(in nsIDOMElement aElement, in unsigned long aFlags);
void setFocus(in Element aElement, in unsigned long aFlags);
/**
* Move the focus to another element. If aStartElement is specified, then
@ -265,7 +266,7 @@ interface nsIFocusManager : nsISupports
* normal focus except that the widget focus is not changed. Updating the
* widget focus state is the responsibility of the caller.
*/
[noscript] void focusPlugin(in nsIContent aPlugin);
[noscript] void focusPlugin(in Element aPlugin);
/**
* Used in a child process to indicate that the parent window is now

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

@ -10,11 +10,12 @@ interface nsIController;
interface nsIControllers;
interface mozIDOMWindowProxy;
webidl Element;
[scriptable, uuid(a9fa9fd3-8d62-4f94-9ed8-3ea9c3cf0773)]
interface nsIDOMXULCommandDispatcher : nsISupports
{
attribute nsIDOMElement focusedElement;
attribute Element focusedElement;
attribute mozIDOMWindowProxy focusedWindow;
void addCommandUpdater(in nsIDOMElement updater,

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

@ -2029,8 +2029,8 @@ TabParent::RecvRequestFocus(const bool& aCanRaise)
if (aCanRaise)
flags |= nsIFocusManager::FLAG_RAISE;
nsCOMPtr<nsIDOMElement> node = do_QueryInterface(mFrameElement);
fm->SetFocus(node, flags);
RefPtr<Element> element = mFrameElement;
fm->SetFocus(element, flags);
return IPC_OK();
}

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

@ -1481,7 +1481,7 @@ nsPluginInstanceOwner::ProcessMouseDown(Event* aMouseEvent)
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIDOMElement> elem = do_QueryReferent(mContent);
nsCOMPtr<Element> elem = do_QueryReferent(mContent);
fm->SetFocus(elem, 0);
}
}

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

@ -10,6 +10,7 @@
#include "mozilla/BasicEvents.h"
#include "mozilla/Preferences.h"
#include "mozilla/Telemetry.h"
#include "mozilla/dom/Element.h"
#include "PluginInstanceParent.h"
#include "BrowserStreamParent.h"
#include "PluginBackgroundDestroyer.h"
@ -2224,7 +2225,8 @@ PluginInstanceParent::AnswerPluginFocusChange(const bool& gotFocus)
nsCOMPtr<nsIDOMElement> element;
owner->GetDOMElement(getter_AddRefs(element));
if (fm && element) {
fm->SetFocus(element, 0);
nsCOMPtr<dom::Element> domElement(do_QueryInterface(element));
fm->SetFocus(domElement, 0);
}
}
}

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

@ -34,6 +34,7 @@
#include "mozilla/dom/Element.h"
using namespace mozilla;
using mozilla::dom::Element;
static LazyLogModule gCommandLog("nsXULCommandDispatcher");
@ -120,7 +121,7 @@ nsXULCommandDispatcher::GetRootFocusedContentAndWindow(nsPIDOMWindowOuter** aWin
}
NS_IMETHODIMP
nsXULCommandDispatcher::GetFocusedElement(nsIDOMElement** aElement)
nsXULCommandDispatcher::GetFocusedElement(Element** aElement)
{
*aElement = nullptr;
@ -131,7 +132,7 @@ nsXULCommandDispatcher::GetFocusedElement(nsIDOMElement** aElement)
CallQueryInterface(focusedContent, aElement);
// Make sure the caller can access the focused element.
nsCOMPtr<nsINode> node = do_QueryInterface(*aElement);
nsINode* node = *aElement;
if (!node || !nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller()->Subsumes(node->NodePrincipal())) {
// XXX This might want to return null, but we use that return value
// to mean "there is no focused element," so to be clear, throw an
@ -168,13 +169,14 @@ nsXULCommandDispatcher::GetFocusedWindow(mozIDOMWindowProxy** aWindow)
}
NS_IMETHODIMP
nsXULCommandDispatcher::SetFocusedElement(nsIDOMElement* aElement)
nsXULCommandDispatcher::SetFocusedElement(Element* aElement)
{
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
NS_ENSURE_TRUE(fm, NS_ERROR_FAILURE);
if (aElement)
if (aElement) {
return fm->SetFocus(aElement, 0);
}
// if aElement is null, clear the focus in the currently focused child window
nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
@ -197,10 +199,10 @@ nsXULCommandDispatcher::SetFocusedWindow(mozIDOMWindowProxy* aWindow)
// end up focusing whatever is currently focused inside the frame. Since
// setting the command dispatcher's focused window doesn't raise the window,
// setting it to a top-level window doesn't need to do anything.
nsCOMPtr<nsIDOMElement> frameElement =
do_QueryInterface(window->GetFrameElementInternal());
if (frameElement)
RefPtr<Element> frameElement = window->GetFrameElementInternal();
if (frameElement) {
return fm->SetFocus(frameElement, 0);
}
return NS_OK;
}
@ -359,9 +361,8 @@ nsXULCommandDispatcher::UpdateCommands(const nsAString& aEventName)
}
nsAutoString id;
nsCOMPtr<nsIDOMElement> domElement;
GetFocusedElement(getter_AddRefs(domElement));
nsCOMPtr<Element> element = do_QueryInterface(domElement);
RefPtr<Element> element;
GetFocusedElement(getter_AddRefs(element));
if (element) {
element->GetAttribute(NS_LITERAL_STRING("id"), id);
}

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

@ -543,7 +543,7 @@ bool
nsXULElement::PerformAccesskey(bool aKeyCausesActivation,
bool aIsTrustedEvent)
{
nsCOMPtr<nsIContent> content(this);
RefPtr<Element> content(this);
if (IsXULElement(nsGkAtoms::label)) {
nsAutoString control;
@ -577,7 +577,7 @@ nsXULElement::PerformAccesskey(bool aKeyCausesActivation,
if (!content->IsXULElement(nsGkAtoms::toolbarbutton)) {
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIDOMElement> elementToFocus;
nsCOMPtr<Element> elementToFocus;
// for radio buttons, focus the radiogroup instead
if (content->IsXULElement(nsGkAtoms::radio)) {
nsCOMPtr<nsIDOMXULSelectControlItemElement> controlItem(do_QueryInterface(content));
@ -591,7 +591,7 @@ nsXULElement::PerformAccesskey(bool aKeyCausesActivation,
}
}
} else {
elementToFocus = do_QueryInterface(content);
elementToFocus = content;
}
if (elementToFocus) {
fm->SetFocus(elementToFocus, nsIFocusManager::FLAG_BYKEY);

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

@ -11,7 +11,6 @@
#include "nsXULPopupListener.h"
#include "nsCOMPtr.h"
#include "nsGkAtoms.h"
#include "nsIDOMElement.h"
#include "nsContentCID.h"
#include "nsContentUtils.h"
#include "nsXULPopupManager.h"
@ -26,6 +25,7 @@
#include "mozilla/EventStateManager.h"
#include "mozilla/EventStates.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/Event.h" // for Event
#include "mozilla/dom/EventTarget.h"
#include "mozilla/dom/FragmentOrElement.h"
@ -234,33 +234,29 @@ nsXULPopupListener::FireFocusOnTargetContent(nsIDOMNode* aTargetNode, bool aIsTo
const nsStyleUserInterface* ui = targetFrame->StyleUserInterface();
bool suppressBlur = (ui->mUserFocus == StyleUserFocus::Ignore);
nsCOMPtr<nsIDOMElement> element;
nsCOMPtr<nsIContent> newFocus = content;
RefPtr<Element> newFocusElement;
nsIFrame* currFrame = targetFrame;
// Look for the nearest enclosing focusable frame.
while (currFrame) {
int32_t tabIndexUnused;
if (currFrame->IsFocusable(&tabIndexUnused, true)) {
newFocus = currFrame->GetContent();
nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(newFocus));
if (domElement) {
element = domElement;
break;
}
if (currFrame->IsFocusable(&tabIndexUnused, true) &&
currFrame->GetContent()->IsElement()) {
newFocusElement = currFrame->GetContent()->AsElement();
break;
}
currFrame = currFrame->GetParent();
}
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
if (element) {
if (newFocusElement) {
uint32_t focusFlags = nsIFocusManager::FLAG_BYMOUSE |
nsIFocusManager::FLAG_NOSCROLL;
if (aIsTouch) {
focusFlags |= nsIFocusManager::FLAG_BYTOUCH;
}
fm->SetFocus(element, focusFlags);
fm->SetFocus(newFocusElement, focusFlags);
} else if (!suppressBlur) {
nsPIDOMWindowOuter *window = doc->GetWindow();
fm->ClearFocus(window);
@ -268,8 +264,7 @@ nsXULPopupListener::FireFocusOnTargetContent(nsIDOMNode* aTargetNode, bool aIsTo
}
EventStateManager* esm = context->EventStateManager();
nsCOMPtr<nsIContent> focusableContent = do_QueryInterface(element);
esm->SetContentState(focusableContent, NS_EVENT_STATE_ACTIVE);
esm->SetContentState(newFocusElement, NS_EVENT_STATE_ACTIVE);
return NS_OK;
}

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

@ -861,7 +861,8 @@ AccessibleCaretManager::ChangeFocusToOrClearOldFocus(nsIFrame* aFrame) const
if (aFrame) {
nsIContent* focusableContent = aFrame->GetContent();
MOZ_ASSERT(focusableContent, "Focusable frame must have content!");
nsCOMPtr<nsIDOMElement> focusableElement = do_QueryInterface(focusableContent);
RefPtr<Element> focusableElement =
focusableContent->IsElement() ? focusableContent->AsElement() : nullptr;
fm->SetFocus(focusableElement, nsIFocusManager::FLAG_BYMOUSE);
} else {
nsPIDOMWindowOuter* win = mPresShell->GetDocument()->GetWindow();

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

@ -1594,15 +1594,16 @@ nsPluginFrame::HandleEvent(nsPresContext* aPresContext,
if (anEvent->mMessage == ePluginActivate) {
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(GetContent());
if (fm && elem)
if (fm) {
RefPtr<Element> elem = GetContent()->AsElement();
return fm->SetFocus(elem, 0);
}
}
else if (anEvent->mMessage == ePluginFocus) {
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIContent> content = GetContent();
return fm->FocusPlugin(content);
RefPtr<Element> elem = GetContent()->AsElement();
return fm->FocusPlugin(elem);
}
}

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

@ -13,6 +13,7 @@
#include "mozilla/ViewportFrame.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/dom/TabParent.h"
#include "mozilla/layers/CompositorBridgeParent.h"
@ -314,11 +315,7 @@ RenderFrameParent::TakeFocusForClickFromTap()
if (!fm) {
return;
}
nsCOMPtr<nsIContent> owner = mFrameLoader->GetOwnerContent();
if (!owner) {
return;
}
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(owner);
RefPtr<Element> element = mFrameLoader->GetOwnerContent();
if (!element) {
return;
}

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

@ -5,7 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
interface mozIDOMWindowProxy;
interface nsIDOMElement;
webidl Element;
#include "nsISupports.idl"
@ -72,5 +73,5 @@ interface nsIWebBrowserFocus : nsISupports
* The currently focused nsDOMElement when the browser is active,
* or the last focused nsDOMElement when the browser is inactive.
*/
attribute nsIDOMElement focusedElement;
attribute Element focusedElement;
};

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

@ -40,6 +40,8 @@
#include "nsILoadContext.h"
#include "nsDocShell.h"
#include "mozilla/dom/Element.h"
// for painting the background window
#include "mozilla/LookAndFeel.h"
@ -1868,7 +1870,7 @@ nsWebBrowser::SetFocusedWindow(mozIDOMWindowProxy* aFocusedWindow)
}
NS_IMETHODIMP
nsWebBrowser::GetFocusedElement(nsIDOMElement** aFocusedElement)
nsWebBrowser::GetFocusedElement(dom::Element** aFocusedElement)
{
NS_ENSURE_ARG_POINTER(aFocusedElement);
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
@ -1877,13 +1879,27 @@ nsWebBrowser::GetFocusedElement(nsIDOMElement** aFocusedElement)
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
return
fm ? fm->GetFocusedElementForWindow(window, true, nullptr, aFocusedElement) :
NS_OK;
if (!fm) {
*aFocusedElement = nullptr;
return NS_OK;
}
nsCOMPtr<nsIDOMElement> element;
nsresult rv =
fm->GetFocusedElementForWindow(window, true, nullptr,
getter_AddRefs(element));
NS_ENSURE_SUCCESS(rv, rv);
if (!element) {
*aFocusedElement = nullptr;
return NS_OK;
}
return CallQueryInterface(element, aFocusedElement);
}
NS_IMETHODIMP
nsWebBrowser::SetFocusedElement(nsIDOMElement* aFocusedElement)
nsWebBrowser::SetFocusedElement(dom::Element* aFocusedElement)
{
nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
return fm ? fm->SetFocus(aFocusedElement, 0) : NS_OK;

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

@ -48,6 +48,7 @@
#endif
using mozilla::dom::Selection;
using mozilla::dom::Element;
nsWebBrowserFind::nsWebBrowserFind()
: mFindBackwards(false)
@ -399,7 +400,8 @@ nsWebBrowserFind::SetSelectionAndScroll(nsPIDOMWindowOuter* aWindow,
nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
if (fm) {
if (tcFrame) {
nsCOMPtr<nsIDOMElement> newFocusedElement(do_QueryInterface(content));
RefPtr<Element> newFocusedElement =
content->IsElement() ? content->AsElement() : nullptr;
fm->SetFocus(newFocusedElement, nsIFocusManager::FLAG_NOSCROLL);
} else {
nsCOMPtr<nsIDOMElement> result;
@ -842,8 +844,7 @@ nsWebBrowserFind::OnFind(nsPIDOMWindowOuter* aFoundWindow)
if (fm) {
// get the containing frame and focus it. For top-level windows, the right
// window should already be focused.
nsCOMPtr<nsIDOMElement> frameElement =
do_QueryInterface(aFoundWindow->GetFrameElementInternal());
RefPtr<Element> frameElement = aFoundWindow->GetFrameElementInternal();
if (frameElement) {
fm->SetFocus(frameElement, 0);
}

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

@ -15,6 +15,8 @@
interface mozIDOMWindow;
interface nsIDocShell;
webidl Element;
/****************************** nsTypeAheadFind ******************************/
@ -71,7 +73,7 @@ interface nsITypeAheadFind : nsISupports
attribute boolean entireWord; // Search for whole words only
readonly attribute nsIDOMElement foundLink;
// Most recent elem found, if a link
readonly attribute nsIDOMElement foundEditable;
readonly attribute Element foundEditable;
// Most recent elem found, if editable
readonly attribute mozIDOMWindow currentWindow;
// Window of most recent match

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

@ -746,7 +746,7 @@ nsTypeAheadFind::GetFoundLink(nsIDOMElement** aFoundLink)
}
NS_IMETHODIMP
nsTypeAheadFind::GetFoundEditable(nsIDOMElement** aFoundEditable)
nsTypeAheadFind::GetFoundEditable(Element** aFoundEditable)
{
NS_ENSURE_ARG_POINTER(aFoundEditable);
*aFoundEditable = mFoundEditable;

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

@ -26,6 +26,7 @@ class nsRange;
namespace mozilla {
namespace dom {
class Element;
class Selection;
} // namespace dom
} // namespace mozilla
@ -95,7 +96,7 @@ protected:
bool mCaretBrowsingOn;
bool mDidAddObservers;
nsCOMPtr<nsIDOMElement> mFoundLink; // Most recent elem found, if a link
nsCOMPtr<nsIDOMElement> mFoundEditable; // Most recent elem found, if editable
nsCOMPtr<mozilla::dom::Element> mFoundEditable; // Most recent elem found, if editable
RefPtr<nsRange> mFoundRange; // Most recent range found
nsCOMPtr<nsPIDOMWindowInner> mCurrentWindow;
// mLastFindLength is the character length of the last find string. It is used for