Backed out changeset 93b9da069dde (bug 1735076) for causing failures in browser_searchbar_openpopup.js CLOSED TREE

This commit is contained in:
Noemi Erli 2021-12-21 21:53:42 +02:00
Родитель 3cd9fb733c
Коммит 70d14084ab
5 изменённых файлов: 41 добавлений и 50 удалений

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

@ -462,17 +462,22 @@ nsFocusManager::GetFocusedElement(Element** aFocusedElement) {
return NS_OK;
}
uint32_t nsFocusManager::GetLastFocusMethod(nsPIDOMWindowOuter* aWindow) const {
nsPIDOMWindowOuter* window = aWindow ? aWindow : mFocusedWindow.get();
uint32_t method = window ? window->GetFocusMethod() : 0;
NS_ASSERTION((method & METHOD_MASK) == method, "invalid focus method");
return method;
}
NS_IMETHODIMP
nsFocusManager::GetLastFocusMethod(mozIDOMWindowProxy* aWindow,
uint32_t* aLastFocusMethod) {
*aLastFocusMethod = GetLastFocusMethod(nsPIDOMWindowOuter::From(aWindow));
// the focus method is stored on the inner window
nsCOMPtr<nsPIDOMWindowOuter> window;
if (aWindow) {
window = nsPIDOMWindowOuter::From(aWindow);
}
if (!window) {
window = mFocusedWindow;
}
*aLastFocusMethod = window ? window->GetFocusMethod() : 0;
NS_ASSERTION((*aLastFocusMethod & METHOD_MASK) == *aLastFocusMethod,
"invalid focus method");
return NS_OK;
}

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

@ -163,9 +163,6 @@ class nsFocusManager final : public nsIFocusManager,
*/
void UpdateCaretForCaretBrowsingMode();
/** @see nsIFocusManager.getLastFocusMethod() */
uint32_t GetLastFocusMethod(nsPIDOMWindowOuter*) const;
/**
* Returns the content node that would be focused if aWindow was in an
* active window. This will traverse down the frame hierarchy, starting at

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

@ -3755,18 +3755,11 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
!aVisitor.mEvent->AsFocusEvent()->mFromRaise &&
SelectTextFieldOnFocus()) {
if (Document* document = GetComposedDoc()) {
uint32_t lastFocusMethod =
fm->GetLastFocusMethod(document->GetWindow());
const bool shouldSelectAllOnFocus = [&] {
if (lastFocusMethod & nsIFocusManager::FLAG_BYMOVEFOCUS) {
return true;
}
if (lastFocusMethod & nsIFocusManager::FLAG_BYJS) {
return false;
}
return bool(lastFocusMethod & nsIFocusManager::FLAG_BYKEY);
}();
if (shouldSelectAllOnFocus) {
uint32_t lastFocusMethod;
fm->GetLastFocusMethod(document->GetWindow(), &lastFocusMethod);
if (lastFocusMethod & (nsIFocusManager::FLAG_BYKEY |
nsIFocusManager::FLAG_BYMOVEFOCUS) &&
!(lastFocusMethod & nsIFocusManager::FLAG_BYJS)) {
RefPtr<nsPresContext> presContext =
GetPresContext(eForComposedDoc);
DispatchSelectEvent(presContext);

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

@ -27,7 +27,6 @@
#include "mozilla/BasicEvents.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ElementBinding.h"
using namespace mozilla;
using mozilla::dom::Document;
@ -193,30 +192,30 @@ nsXULCommandDispatcher::AdvanceFocus() {
return AdvanceFocusIntoSubtree(nullptr);
}
NS_IMETHODIMP
nsXULCommandDispatcher::AdvanceFocusIntoSubtree(Element* aElt) {
return MoveFocusIntoSubtree(aElt, /* aForward = */ true);
}
NS_IMETHODIMP
nsXULCommandDispatcher::RewindFocus() {
return MoveFocusIntoSubtree(nullptr, /* aForward = */ false);
}
nsresult nsXULCommandDispatcher::MoveFocusIntoSubtree(Element* aElt,
bool aForward) {
nsCOMPtr<nsPIDOMWindowOuter> win;
GetRootFocusedContentAndWindow(getter_AddRefs(win));
RefPtr<Element> result;
nsFocusManager* fm = nsFocusManager::GetFocusManager();
if (!fm) {
if (fm)
return fm->MoveFocus(win, nullptr, nsIFocusManager::MOVEFOCUS_BACKWARD, 0,
getter_AddRefs(result));
return NS_OK;
}
NS_IMETHODIMP
nsXULCommandDispatcher::AdvanceFocusIntoSubtree(Element* aElt) {
nsCOMPtr<nsPIDOMWindowOuter> win;
GetRootFocusedContentAndWindow(getter_AddRefs(win));
RefPtr<Element> result;
nsFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm)
return fm->MoveFocus(win, aElt, nsIFocusManager::MOVEFOCUS_FORWARD, 0,
getter_AddRefs(result));
return NS_OK;
}
auto flags = nsFocusManager::ProgrammaticFocusFlags(dom::FocusOptions());
auto type = aForward ? nsIFocusManager::MOVEFOCUS_FORWARD
: nsIFocusManager::MOVEFOCUS_BACKWARD;
return fm->MoveFocus(win, aElt, type, flags, getter_AddRefs(result));
}
NS_IMETHODIMP

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

@ -32,11 +32,8 @@ class Element;
class nsXULCommandDispatcher : public nsIDOMXULCommandDispatcher,
public nsSupportsWeakReference {
using Document = mozilla::dom::Document;
using Element = mozilla::dom::Element;
public:
explicit nsXULCommandDispatcher(Document* aDocument);
explicit nsXULCommandDispatcher(mozilla::dom::Document* aDocument);
// nsISupports
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
@ -53,21 +50,21 @@ class nsXULCommandDispatcher : public nsIDOMXULCommandDispatcher,
already_AddRefed<nsPIWindowRoot> GetWindowRoot();
Element* GetRootFocusedContentAndWindow(nsPIDOMWindowOuter** aWindow);
nsresult MoveFocusIntoSubtree(Element*, bool aForward);
mozilla::dom::Element* GetRootFocusedContentAndWindow(
nsPIDOMWindowOuter** aWindow);
RefPtr<Document> mDocument;
RefPtr<mozilla::dom::Document> mDocument;
class Updater {
public:
Updater(Element* aElement, const nsAString& aEvents,
Updater(mozilla::dom::Element* aElement, const nsAString& aEvents,
const nsAString& aTargets)
: mElement(aElement),
mEvents(aEvents),
mTargets(aTargets),
mNext(nullptr) {}
RefPtr<Element> mElement;
RefPtr<mozilla::dom::Element> mElement;
nsString mEvents;
nsString mTargets;
Updater* mNext;