Bug 1712724 - Cleanup focus method mask usage. r=smaug

No behavior change, since `GetLastFocusMethod` is only checked by `HTMLInputElement.cpp` / `nsGlobalWindowInner.cpp` for FLAG_BYKEY, and some JS code for `FLAG_BYMOUSE`.

But this makes the next patch more straight-forward.

Differential Revision: https://phabricator.services.mozilla.com/D115900
This commit is contained in:
Emilio Cobos Álvarez 2021-05-26 11:21:44 +00:00
Родитель adbf664a69
Коммит d289bd695b
4 изменённых файлов: 24 добавлений и 25 удалений

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

@ -478,7 +478,7 @@ nsFocusManager::GetLastFocusMethod(mozIDOMWindowProxy* aWindow,
*aLastFocusMethod = window ? window->GetFocusMethod() : 0;
NS_ASSERTION((*aLastFocusMethod & FOCUSMETHOD_MASK) == *aLastFocusMethod,
NS_ASSERTION((*aLastFocusMethod & METHOD_MASK) == *aLastFocusMethod,
"invalid focus method");
return NS_OK;
}
@ -527,7 +527,7 @@ nsFocusManager::MoveFocus(mozIDOMWindowProxy* aWindow, Element* aStartElement,
// the other focus methods is already set, or we're just moving to the root
// or caret position.
if (aType != MOVEFOCUS_ROOT && aType != MOVEFOCUS_CARET &&
(aFlags & FOCUSMETHOD_MASK) == 0) {
(aFlags & METHOD_MASK) == 0) {
aFlags |= FLAG_BYMOVEFOCUS;
}
@ -1062,7 +1062,7 @@ void nsFocusManager::WindowHidden(mozIDOMWindowProxy* aWindow,
if (presShell) {
SendFocusOrBlurEvent(eBlur, presShell,
oldFocusedElement->GetComposedDoc(),
oldFocusedElement, 1, false);
oldFocusedElement, false);
}
}
@ -1746,7 +1746,7 @@ void nsFocusManager::SetFocusInner(Element* aNewContent, int32_t aFlags,
// set the focus node and method as needed
uint32_t focusMethod =
aFocusChanged ? aFlags & FOCUSMETHODANDRING_MASK
aFocusChanged ? aFlags & METHODANDRING_MASK
: newWindow->GetFocusMethod() |
(aFlags & (FLAG_SHOWRING | FLAG_NOSHOWRING));
newWindow->SetFocusedElement(elementToFocus, focusMethod);
@ -2346,7 +2346,7 @@ bool nsFocusManager::BlurImpl(BrowsingContext* aBrowsingContextToClear,
}
SendFocusOrBlurEvent(eBlur, presShell, element->GetComposedDoc(), element,
1, false, false, aElementToFocus);
false, false, aElementToFocus);
}
// if we are leaving the document or the window was lowered, make the caret
@ -2387,16 +2387,13 @@ bool nsFocusManager::BlurImpl(BrowsingContext* aBrowsingContextToClear,
SetFocusedWindowInternal(nullptr, aActionId);
mFocusedElement = nullptr;
// pass 1 for the focus method when calling SendFocusOrBlurEvent just so
// that the check is made for suppressed documents. Check to ensure that
// the document isn't null in case someone closed it during the blur above
Document* doc = window->GetExtantDoc();
if (doc) {
SendFocusOrBlurEvent(eBlur, presShell, doc, ToSupports(doc), 1, false);
SendFocusOrBlurEvent(eBlur, presShell, doc, ToSupports(doc), false);
}
if (!GetFocusedBrowsingContext()) {
SendFocusOrBlurEvent(eBlur, presShell, doc,
window->GetCurrentInnerWindow(), 1, false);
window->GetCurrentInnerWindow(), false);
}
// check if a different window was focused
@ -2486,7 +2483,7 @@ void nsFocusManager::Focus(
// Otherwise, just get the current focus method and use that. This ensures
// that the method is set during the document and window focus events.
uint32_t focusMethod = aFocusChanged
? aFlags & FOCUSMETHODANDRING_MASK
? aFlags & METHODANDRING_MASK
: aWindow->GetFocusMethod() |
(aFlags & (FLAG_SHOWRING | FLAG_NOSHOWRING));
@ -2561,13 +2558,13 @@ void nsFocusManager::Focus(
}
if (doc && !focusInOtherContentProcess) {
SendFocusOrBlurEvent(eFocus, presShell, doc, ToSupports(doc),
aFlags & FOCUSMETHOD_MASK, aWindowRaised);
aWindowRaised);
}
if (GetFocusedBrowsingContext() == aWindow->GetBrowsingContext() &&
!mFocusedElement && !focusInOtherContentProcess) {
SendFocusOrBlurEvent(eFocus, presShell, doc,
aWindow->GetCurrentInnerWindow(),
aFlags & FOCUSMETHOD_MASK, aWindowRaised);
aWindowRaised);
}
}
@ -2616,7 +2613,7 @@ void nsFocusManager::Focus(
if (!focusInOtherContentProcess) {
SendFocusOrBlurEvent(
eFocus, presShell, aElement->GetComposedDoc(), aElement,
aFlags & FOCUSMETHOD_MASK, aWindowRaised, isRefocus,
aWindowRaised, isRefocus,
aBlurredElementInfo ? aBlurredElementInfo->mElement.get()
: nullptr);
}
@ -2747,7 +2744,7 @@ void nsFocusManager::FireFocusInOrOutEvent(
void nsFocusManager::SendFocusOrBlurEvent(
EventMessage aEventMessage, PresShell* aPresShell, Document* aDocument,
nsISupports* aTarget, uint32_t aFocusMethod, bool aWindowRaised,
nsISupports* aTarget, bool aWindowRaised,
bool aIsRefocus, EventTarget* aRelatedTarget) {
NS_ASSERTION(aEventMessage == eFocus || aEventMessage == eBlur,
"Wrong event type for SendFocusOrBlurEvent");

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

@ -17,9 +17,6 @@
#include "mozilla/RefPtr.h"
#include "mozilla/StaticPtr.h"
#define FOCUSMETHOD_MASK 0xF000
#define FOCUSMETHODANDRING_MASK 0xF0F000
#define FOCUSMANAGER_CONTRACTID "@mozilla.org/focus-manager;1"
class nsIContent;
@ -474,13 +471,12 @@ class nsFocusManager final : public nsIFocusManager,
* event queue if the document is suppressing events.
*
* aEventMessage should be either eFocus or eBlur.
* For blur events, aFocusMethod should normally be non-zero.
*
* aWindowRaised should only be true if called from WindowRaised.
*/
void SendFocusOrBlurEvent(
mozilla::EventMessage aEventMessage, mozilla::PresShell* aPresShell,
Document* aDocument, nsISupports* aTarget, uint32_t aFocusMethod,
Document* aDocument, nsISupports* aTarget,
bool aWindowRaised, bool aIsRefocus = false,
mozilla::dom::EventTarget* aRelatedTarget = nullptr);
/**

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

@ -4379,7 +4379,7 @@ void nsGlobalWindowInner::SetFocusedElement(Element* aElement,
UpdateCanvasFocus(false, aElement);
mFocusedElement = aElement;
// TODO: Maybe this should be set on refocus too?
mFocusMethod = aFocusMethod & FOCUSMETHOD_MASK;
mFocusMethod = aFocusMethod & nsIFocusManager::METHOD_MASK;
}
if (mFocusedElement) {
@ -4421,7 +4421,9 @@ bool nsGlobalWindowInner::TakeFocus(bool aFocus, uint32_t aFocusMethod) {
return false;
}
if (aFocus) mFocusMethod = aFocusMethod & FOCUSMETHOD_MASK;
if (aFocus) {
mFocusMethod = aFocusMethod & nsIFocusManager::METHOD_MASK;
}
if (mHasFocus != aFocus) {
mHasFocus = aFocus;

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

@ -236,11 +236,15 @@ interface nsIFocusManager : nsISupports
*/
const unsigned long FLAG_BYTOUCH = 0x200000;
/*
* Focus is changing due to a long press operation by touch or mouse.
*/
/** Focus is changing due to a long press operation by touch or mouse. */
const unsigned long FLAG_BYLONGPRESS = 0x800000;
/** Mask with all the focus methods. */
const unsigned long METHOD_MASK = FLAG_BYMOUSE | FLAG_BYKEY | FLAG_BYMOVEFOCUS | FLAG_BYTOUCH | FLAG_BYLONGPRESS;
/** Mask with all the focus methods, plus the SHOW / NOSHOWRING flags. */
const unsigned long METHODANDRING_MASK = METHOD_MASK | FLAG_SHOWRING | FLAG_NOSHOWRING;
// these constants are used with the aType argument to MoveFocus
/** move focus forward one element, used when pressing TAB */