Bug 1457156. Rename nsPIDOMWindow::mFocusedNode to reflect that it's an Element now. r=mccr8

This commit is contained in:
Boris Zbarsky 2018-04-26 15:28:30 -04:00
Родитель d46ebbf915
Коммит cb54ece0d5
10 изменённых файлов: 74 добавлений и 73 удалений

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

@ -9356,7 +9356,7 @@ public:
}
// Don't steal focus from the user.
if (mTopWindow->GetFocusedNode()) {
if (mTopWindow->GetFocusedElement()) {
return NS_OK;
}

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

@ -315,7 +315,7 @@ nsFocusManager::GetFocusedDescendant(nsPIDOMWindowOuter* aWindow,
nsPIDOMWindowOuter* window = aWindow;
for (;;) {
*aFocusedWindow = window;
currentContent = window->GetFocusedNode();
currentContent = window->GetFocusedElement();
if (!currentContent || aSearchRange == eOnlyCurrentWindow) {
break;
}
@ -468,7 +468,7 @@ NS_IMETHODIMP nsFocusManager::SetFocusedWindow(mozIDOMWindowProxy* aWindowToFocu
// clear the focus. Otherwise, focus should already be in this frame, or
// already cleared. This ensures that focus will be in this frame and not
// in a child.
nsIContent* content = windowToFocus->GetFocusedNode();
nsIContent* content = windowToFocus->GetFocusedElement();
if (content) {
if (nsCOMPtr<nsPIDOMWindowOuter> childWindow = GetContentWindow(content))
ClearFocus(windowToFocus);
@ -625,7 +625,7 @@ nsFocusManager::ClearFocus(mozIDOMWindowProxy* aWindow)
}
}
else {
window->SetFocusedNode(nullptr);
window->SetFocusedElement(nullptr);
}
LOGFOCUS(("<<ClearFocus end>>"));
@ -681,7 +681,7 @@ nsFocusManager::MoveCaretToFocus(mozIDOMWindowProxy* aWindow)
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(aWindow);
nsCOMPtr<nsIContent> content = window->GetFocusedNode();
nsCOMPtr<nsIContent> content = window->GetFocusedElement();
if (content)
MoveCaretToFocus(presShell, content);
}
@ -851,10 +851,10 @@ nsFocusManager::ContentRemoved(nsIDocument* aDocument, nsIContent* aContent)
// if the content is currently focused in the window, or is an
// shadow-including inclusive ancestor of the currently focused element,
// reset the focus within that window.
nsIContent* content = window->GetFocusedNode();
nsIContent* content = window->GetFocusedElement();
if (content && nsContentUtils::ContentIsHostIncludingDescendantOf(content, aContent)) {
bool shouldShowFocusRing = window->ShouldShowFocusRing();
window->SetFocusedNode(nullptr);
window->SetFocusedElement(nullptr);
// if this window is currently focused, clear the global focused
// element as well, but don't fire any events.
@ -1056,7 +1056,7 @@ nsFocusManager::WindowHidden(mozIDOMWindowProxy* aWindow)
dsti->GetParent(getter_AddRefs(parentDsti));
if (parentDsti) {
if (nsCOMPtr<nsPIDOMWindowOuter> parentWindow = parentDsti->GetWindow())
parentWindow->SetFocusedNode(nullptr);
parentWindow->SetFocusedElement(nullptr);
}
}
@ -1412,7 +1412,7 @@ nsFocusManager::SetFocusInner(Element* aNewContent, int32_t aFlags,
// set the focus node and method as needed
uint32_t focusMethod = aFocusChanged ? aFlags & FOCUSMETHODANDRING_MASK :
newWindow->GetFocusMethod() | (aFlags & FLAG_SHOWRING);
newWindow->SetFocusedNode(contentToFocus, focusMethod);
newWindow->SetFocusedElement(contentToFocus, focusMethod);
if (aFocusChanged) {
nsCOMPtr<nsIDocShell> docShell = newWindow->GetDocShell();
@ -1532,7 +1532,7 @@ nsFocusManager::AdjustWindowFocus(nsPIDOMWindowOuter* aWindow,
break;
}
window->SetFocusedNode(frameElement);
window->SetFocusedElement(frameElement);
}
}
}
@ -1706,7 +1706,7 @@ nsFocusManager::Blur(nsPIDOMWindowOuter* aWindowToClear,
mFocusedContent = nullptr;
bool shouldShowFocusRing = window->ShouldShowFocusRing();
if (aWindowToClear)
aWindowToClear->SetFocusedNode(nullptr);
aWindowToClear->SetFocusedElement(nullptr);
LOGCONTENT("Element %s has been blurred", content.get());
@ -1799,7 +1799,7 @@ nsFocusManager::Blur(nsPIDOMWindowOuter* aWindowToClear,
// state. Pass true because aAncestorWindowToFocus is thought to be
// focused at this point.
if (aAncestorWindowToFocus)
aAncestorWindowToFocus->SetFocusedNode(nullptr, 0, true);
aAncestorWindowToFocus->SetFocusedElement(nullptr, 0, true);
SetFocusedWindowInternal(nullptr);
mFocusedContent = nullptr;
@ -1870,7 +1870,7 @@ nsFocusManager::Focus(nsPIDOMWindowOuter* aWindow,
// if the window isn't visible, for instance because it is a hidden tab,
// update the current focus and scroll it into view but don't do anything else
if (CheckIfFocusable(aContent, aFlags)) {
aWindow->SetFocusedNode(aContent, focusMethod);
aWindow->SetFocusedElement(aContent, focusMethod);
if (aFocusChanged)
ScrollIntoView(presShell, aContent, aFlags);
}
@ -1953,10 +1953,10 @@ nsFocusManager::Focus(nsPIDOMWindowOuter* aWindow,
mFocusedWindow == aWindow && mFocusedContent == nullptr) {
mFocusedContent = aContent;
nsIContent* focusedNode = aWindow->GetFocusedNode();
nsIContent* focusedNode = aWindow->GetFocusedElement();
bool isRefocus = focusedNode && focusedNode->IsEqualNode(aContent);
aWindow->SetFocusedNode(aContent, focusMethod);
aWindow->SetFocusedElement(aContent, focusMethod);
// if the focused element changed, scroll it into view
if (aContent && aFocusChanged) {
@ -2109,7 +2109,7 @@ public:
NS_IMETHOD Run() override
{
nsCOMPtr<nsIContent> originalWindowFocus = mOriginalFocusedWindow ?
mOriginalFocusedWindow->GetFocusedNode() :
mOriginalFocusedWindow->GetFocusedElement() :
nullptr;
// Blink does not check that focus is the same after blur, but WebKit does.
// Opt to follow Blink's behavior (see bug 687787).
@ -2232,7 +2232,7 @@ nsFocusManager::FireFocusOrBlurEvent(EventMessage aEventMessage,
nsCOMPtr<nsPIDOMWindowInner> targetWindow = do_QueryInterface(aTarget);
nsCOMPtr<nsIDocument> targetDocument = do_QueryInterface(aTarget);
nsCOMPtr<nsIContent> currentFocusedContent = currentWindow ?
currentWindow->GetFocusedNode() : nullptr;
currentWindow->GetFocusedElement() : nullptr;
bool dontDispatchEvent =
eventTargetDoc && nsContentUtils::IsUserFocusIgnored(eventTargetDoc);
@ -2687,7 +2687,7 @@ nsFocusManager::DetermineElementToMoveFocus(nsPIDOMWindowOuter* aWindow,
// then we are document-navigating backwards from chrome to the content
// process, and we don't want to use this so that we start from the end
// of the document.
startContent = aWindow->GetFocusedNode();
startContent = aWindow->GetFocusedElement();
}
}
@ -3017,10 +3017,10 @@ nsFocusManager::DetermineElementToMoveFocus(nsPIDOMWindowOuter* aWindow,
// If the tree owner took the focus, blur the current content.
if (tookFocus) {
nsCOMPtr<nsPIDOMWindowOuter> window = docShell->GetWindow();
if (window->GetFocusedNode() == mFocusedContent)
if (window->GetFocusedElement() == mFocusedContent)
Blur(mFocusedWindow, nullptr, true, true);
else
window->SetFocusedNode(nullptr);
window->SetFocusedElement(nullptr);
return NS_OK;
}
@ -3957,7 +3957,7 @@ nsFocusManager::GetFocusInSelection(nsPIDOMWindowOuter* aWindow,
nsCOMPtr<nsIContent> testContent = aStartSelection;
nsCOMPtr<nsIContent> nextTestContent = aEndSelection;
nsCOMPtr<nsIContent> currentFocus = aWindow->GetFocusedNode();
nsCOMPtr<nsIContent> currentFocus = aWindow->GetFocusedElement();
// We now have the correct start node in selectionContent!
// Search for focusable elements, starting with selectionContent
@ -4165,7 +4165,7 @@ nsFocusManager::CanSkipFocus(nsIContent* aContent)
root ? root->GetWindow() : nullptr;
if (mActiveWindow != newRootWindow) {
nsPIDOMWindowOuter* outerWindow = aContent->OwnerDoc()->GetWindow();
if (outerWindow && outerWindow->GetFocusedNode() == aContent) {
if (outerWindow && outerWindow->GetFocusedElement() == aContent) {
return true;
}
}

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

@ -1219,7 +1219,7 @@ nsGlobalWindowInner::FreeInnerObjects()
}
// Remove our reference to the document and the document principal.
mFocusedNode = nullptr;
mFocusedElement = nullptr;
if (mApplicationCache) {
static_cast<nsDOMOfflineResourceList*>(mApplicationCache.get())->Disconnect();
@ -1451,7 +1451,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowInner)
// Traverse stuff from nsPIDOMWindow
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChromeEventHandler)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParentTarget)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFocusedNode)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFocusedElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMenubar)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mToolbar)
@ -1539,7 +1539,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner)
// Unlink stuff from nsPIDOMWindow
NS_IMPL_CYCLE_COLLECTION_UNLINK(mChromeEventHandler)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mParentTarget)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFocusedNode)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFocusedElement)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mMenubar)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mToolbar)
@ -1700,7 +1700,7 @@ nsGlobalWindowInner::InnerSetNewDocument(JSContext* aCx, nsIDocument* aDocument)
mDoc = aDocument;
ClearDocumentDependentSlots(aCx);
mFocusedNode = nullptr;
mFocusedElement = nullptr;
mLocalStorage = nullptr;
mSessionStorage = nullptr;
@ -4652,28 +4652,28 @@ static bool ShouldShowFocusRingIfFocusedByMouse(nsIContent* aNode)
}
void
nsGlobalWindowInner::SetFocusedNode(Element* aNode,
uint32_t aFocusMethod,
bool aNeedsFocus)
nsGlobalWindowInner::SetFocusedElement(Element* aElement,
uint32_t aFocusMethod,
bool aNeedsFocus)
{
if (aNode && aNode->GetComposedDoc() != mDoc) {
if (aElement && aElement->GetComposedDoc() != mDoc) {
NS_WARNING("Trying to set focus to a node from a wrong document");
return;
}
if (IsDying()) {
NS_ASSERTION(!aNode, "Trying to focus cleaned up window!");
aNode = nullptr;
NS_ASSERTION(!aElement, "Trying to focus cleaned up window!");
aElement = nullptr;
aNeedsFocus = false;
}
if (mFocusedNode != aNode) {
UpdateCanvasFocus(false, aNode);
mFocusedNode = aNode;
if (mFocusedElement != aElement) {
UpdateCanvasFocus(false, aElement);
mFocusedElement = aElement;
mFocusMethod = aFocusMethod & FOCUSMETHOD_MASK;
mShowFocusRingForContent = false;
}
if (mFocusedNode) {
if (mFocusedElement) {
// if a node was focused by a keypress, turn on focus rings for the
// window.
if (mFocusMethod & nsIFocusManager::FLAG_BYKEY) {
@ -4685,7 +4685,7 @@ nsGlobalWindowInner::SetFocusedNode(Element* aNode,
// are only visible on some elements.
#ifndef XP_WIN
!(mFocusMethod & nsIFocusManager::FLAG_BYMOUSE) ||
ShouldShowFocusRingIfFocusedByMouse(aNode) ||
ShouldShowFocusRingIfFocusedByMouse(aElement) ||
#endif
aFocusMethod & nsIFocusManager::FLAG_SHOWRING) {
mShowFocusRingForContent = true;
@ -4725,7 +4725,7 @@ nsGlobalWindowInner::TakeFocus(bool aFocus, uint32_t aFocusMethod)
if (mHasFocus != aFocus) {
mHasFocus = aFocus;
UpdateCanvasFocus(true, mFocusedNode);
UpdateCanvasFocus(true, mFocusedElement);
}
// if mNeedsFocus is true, then the document has not yet received a
@ -4941,7 +4941,7 @@ nsGlobalWindowInner::UpdateCanvasFocus(bool aFocusChanged, nsIContent* aNewConte
Element *rootElement = mDoc->GetRootElement();
if (rootElement) {
if ((mHasFocus || aFocusChanged) &&
(mFocusedNode == rootElement || aNewContent == rootElement)) {
(mFocusedElement == rootElement || aNewContent == rootElement)) {
nsIFrame* frame = rootElement->GetPrimaryFrame();
if (frame) {
frame = frame->GetParent();

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

@ -1197,9 +1197,9 @@ public:
bool IsInModalState();
virtual void SetFocusedNode(mozilla::dom::Element* aNode,
uint32_t aFocusMethod = 0,
bool aNeedsFocus = false) override;
virtual void SetFocusedElement(mozilla::dom::Element* aElement,
uint32_t aFocusMethod = 0,
bool aNeedsFocus = false) override;
virtual uint32_t GetFocusMethod() override;

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

@ -6626,11 +6626,12 @@ nsGlobalWindowOuter::SetChromeEventHandler(EventTarget* aChromeEventHandler)
}
void
nsGlobalWindowOuter::SetFocusedNode(Element* aNode,
uint32_t aFocusMethod,
bool aNeedsFocus)
nsGlobalWindowOuter::SetFocusedElement(Element* aElement,
uint32_t aFocusMethod,
bool aNeedsFocus)
{
FORWARD_TO_INNER_VOID(SetFocusedNode, (aNode, aFocusMethod, aNeedsFocus));
FORWARD_TO_INNER_VOID(SetFocusedElement,
(aElement, aFocusMethod, aNeedsFocus));
}
uint32_t
@ -6677,13 +6678,13 @@ nsGlobalWindowOuter::SetKeyboardIndicators(UIStateChangeType aShowAccelerators,
bool newShouldShowFocusRing = ShouldShowFocusRing();
if (mInnerWindow && nsGlobalWindowInner::Cast(mInnerWindow)->mHasFocus &&
mInnerWindow->mFocusedNode &&
mInnerWindow->mFocusedElement &&
oldShouldShowFocusRing != newShouldShowFocusRing) {
// Update focusedNode's state.
if (newShouldShowFocusRing) {
mInnerWindow->mFocusedNode->AddStates(NS_EVENT_STATE_FOCUSRING);
mInnerWindow->mFocusedElement->AddStates(NS_EVENT_STATE_FOCUSRING);
} else {
mInnerWindow->mFocusedNode->RemoveStates(NS_EVENT_STATE_FOCUSRING);
mInnerWindow->mFocusedElement->RemoveStates(NS_EVENT_STATE_FOCUSRING);
}
}
}
@ -7258,14 +7259,14 @@ nsGlobalWindowOuter::RestoreWindowState(nsISupports *aState)
// if a link is focused, refocus with the FLAG_SHOWRING flag set. This makes
// it easy to tell which link was last clicked when going back a page.
Element* focusedNode = inner->GetFocusedNode();
if (nsContentUtils::ContentIsLink(focusedNode)) {
Element* focusedElement = inner->GetFocusedElement();
if (nsContentUtils::ContentIsLink(focusedElement)) {
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
// XXXbz Do we need the stack strong ref here?
RefPtr<Element> focusedElement = focusedNode;
fm->SetFocus(focusedElement, nsIFocusManager::FLAG_NOSCROLL |
nsIFocusManager::FLAG_SHOWRING);
RefPtr<Element> kungFuDeathGrip(focusedElement);
fm->SetFocus(kungFuDeathGrip, nsIFocusManager::FLAG_NOSCROLL |
nsIFocusManager::FLAG_SHOWRING);
}
}

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

@ -979,9 +979,9 @@ public:
nsIntSize DevToCSSIntPixels(nsIntSize px);
nsIntSize CSSToDevIntPixels(nsIntSize px);
virtual void SetFocusedNode(mozilla::dom::Element* aNode,
uint32_t aFocusMethod = 0,
bool aNeedsFocus = false) override;
virtual void SetFocusedElement(mozilla::dom::Element* aElement,
uint32_t aFocusMethod = 0,
bool aNeedsFocus = false) override;
virtual uint32_t GetFocusMethod() override;

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

@ -484,10 +484,10 @@ public:
* DO NOT CALL EITHER OF THESE METHODS DIRECTLY. USE THE FOCUS MANAGER
* INSTEAD.
*/
inline mozilla::dom::Element* GetFocusedNode() const;
virtual void SetFocusedNode(mozilla::dom::Element* aNode,
uint32_t aFocusMethod = 0,
bool aNeedsFocus = false) = 0;
inline mozilla::dom::Element* GetFocusedElement() const;
virtual void SetFocusedElement(mozilla::dom::Element* aElement,
uint32_t aFocusMethod = 0,
bool aNeedsFocus = false) = 0;
/**
* Retrieves the method that was used to focus the current node.
@ -658,9 +658,9 @@ protected:
// Our inner window's outer window.
nsCOMPtr<nsPIDOMWindowOuter> mOuterWindow;
// the element within the document that is currently focused when this
// The element within the document that is currently focused when this
// window is active.
RefPtr<mozilla::dom::Element> mFocusedNode;
RefPtr<mozilla::dom::Element> mFocusedElement;
// The AudioContexts created for the current document, if any.
nsTArray<mozilla::dom::AudioContext*> mAudioContexts; // Weak
@ -973,10 +973,10 @@ public:
* DO NOT CALL EITHER OF THESE METHODS DIRECTLY. USE THE FOCUS MANAGER
* INSTEAD.
*/
inline mozilla::dom::Element* GetFocusedNode() const;
virtual void SetFocusedNode(mozilla::dom::Element* aNode,
uint32_t aFocusMethod = 0,
bool aNeedsFocus = false) = 0;
inline mozilla::dom::Element* GetFocusedElement() const;
virtual void SetFocusedElement(mozilla::dom::Element* aElement,
uint32_t aFocusMethod = 0,
bool aNeedsFocus = false) = 0;
/**
* Retrieves the method that was used to focus the current node.

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

@ -90,13 +90,13 @@ nsPIDOMWindowInner::GetDocShell() const
}
mozilla::dom::Element*
nsPIDOMWindowOuter::GetFocusedNode() const
nsPIDOMWindowOuter::GetFocusedElement() const
{
return mInnerWindow ? mInnerWindow->GetFocusedNode() : nullptr;
return mInnerWindow ? mInnerWindow->GetFocusedElement() : nullptr;
}
mozilla::dom::Element*
nsPIDOMWindowInner::GetFocusedNode() const
nsPIDOMWindowInner::GetFocusedElement() const
{
return mFocusedNode;
return mFocusedElement;
}

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

@ -2570,7 +2570,7 @@ nsGenericHTMLElement::PerformAccesskey(bool aKeyCausesActivation,
// Return true if the element became the current focus within its window.
nsPIDOMWindowOuter* window = OwnerDoc()->GetWindow();
focused = (window && window->GetFocusedNode());
focused = (window && window->GetFocusedElement());
}
if (aKeyCausesActivation) {

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

@ -598,7 +598,7 @@ nsXULElement::PerformAccesskey(bool aKeyCausesActivation,
// Return true if the element became focused.
nsPIDOMWindowOuter* window = OwnerDoc()->GetWindow();
focused = (window && window->GetFocusedNode());
focused = (window && window->GetFocusedElement());
}
}
}