gecko-dev/dom/ipc/TabContext.cpp
Emilio Cobos Álvarez 56be5080d2 Bug 1807687 - Simplify Windows keyboard indicator setting handling. r=NeilDeakin
The only thing that can explain this is the WM_UPDATEUISTATE state
getting out of sync in a way that we think we need to unconditionally
show focus indicators for a window.

I tried to first make this less error prone (see patch above) but
digging more into these messages, I'm pretty sure we just don't need all
this code. See:

 * https://devblogs.microsoft.com/oldnewthing/20130516-00/?p=4343
 * https://devblogs.microsoft.com/oldnewthing/20130517-00/?p=4323

In particular, this is intended to be a windows feature to not show
keyboard indicators on dialogs until you use the keyboard. But that's
how Gecko dialogs behave already due to how :focus-visible behaves as
per:

  https://searchfox.org/mozilla-central/rev/43ee5e789b079e94837a21336e9ce2420658fd19/toolkit/components/prompts/src/CommonDialog.jsm#319

I haven't been able to repro this state, but sounds believable that it
could happen after opening a native dialog or so on?

The purpose of this code is to implement the 'Underline access keys' in
the Keyboard Accessibility control panel of windows.

There's an easier way of tracking this, via the SPI_GETKEYBOARDCUES SPI,
documented in:

  https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa

Hook that into LookAndFeel rather than using custom IPC and so on.

Differential Revision: https://phabricator.services.mozilla.com/D165578
2023-01-09 18:19:03 +00:00

138 lines
3.7 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/TabContext.h"
#include "mozilla/dom/PTabContext.h"
#include "mozilla/dom/BrowserParent.h"
#include "mozilla/dom/BrowserChild.h"
#include "mozilla/StaticPrefs_dom.h"
#include "nsServiceManagerUtils.h"
using namespace mozilla::dom::ipc;
using namespace mozilla::layout;
namespace mozilla::dom {
TabContext::TabContext()
: mInitialized(false),
mChromeOuterWindowID(0),
mJSPluginID(-1),
mMaxTouchPoints(0) {}
bool TabContext::IsJSPlugin() const { return mJSPluginID >= 0; }
int32_t TabContext::JSPluginId() const { return mJSPluginID; }
uint64_t TabContext::ChromeOuterWindowID() const {
return mChromeOuterWindowID;
}
bool TabContext::SetTabContext(const TabContext& aContext) {
NS_ENSURE_FALSE(mInitialized, false);
*this = aContext;
mInitialized = true;
return true;
}
bool TabContext::UpdateTabContextAfterSwap(const TabContext& aContext) {
// This is only used after already initialized.
MOZ_ASSERT(mInitialized);
// The only permissable changes are to mChromeOuterWindowID. All other fields
// must match for the change to be accepted.
mChromeOuterWindowID = aContext.mChromeOuterWindowID;
return true;
}
bool TabContext::SetTabContext(uint64_t aChromeOuterWindowID,
uint32_t aMaxTouchPoints) {
NS_ENSURE_FALSE(mInitialized, false);
mInitialized = true;
mChromeOuterWindowID = aChromeOuterWindowID;
mMaxTouchPoints = aMaxTouchPoints;
return true;
}
bool TabContext::SetTabContextForJSPluginFrame(int32_t aJSPluginID) {
NS_ENSURE_FALSE(mInitialized, false);
mInitialized = true;
mJSPluginID = aJSPluginID;
return true;
}
IPCTabContext TabContext::AsIPCTabContext() const {
if (IsJSPlugin()) {
return IPCTabContext(JSPluginFrameIPCTabContext(mJSPluginID));
}
return IPCTabContext(
FrameIPCTabContext(mChromeOuterWindowID, mMaxTouchPoints));
}
MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
: mInvalidReason(nullptr) {
uint64_t chromeOuterWindowID = 0;
int32_t jsPluginId = -1;
uint32_t maxTouchPoints = 0;
switch (aParams.type()) {
case IPCTabContext::TPopupIPCTabContext: {
const PopupIPCTabContext& ipcContext = aParams.get_PopupIPCTabContext();
chromeOuterWindowID = ipcContext.chromeOuterWindowID();
break;
}
case IPCTabContext::TJSPluginFrameIPCTabContext: {
const JSPluginFrameIPCTabContext& ipcContext =
aParams.get_JSPluginFrameIPCTabContext();
jsPluginId = ipcContext.jsPluginId();
break;
}
case IPCTabContext::TFrameIPCTabContext: {
const FrameIPCTabContext& ipcContext = aParams.get_FrameIPCTabContext();
chromeOuterWindowID = ipcContext.chromeOuterWindowID();
maxTouchPoints = ipcContext.maxTouchPoints();
break;
}
default: {
MOZ_CRASH();
}
}
bool rv;
if (jsPluginId >= 0) {
rv = mTabContext.SetTabContextForJSPluginFrame(jsPluginId);
} else {
rv = mTabContext.SetTabContext(chromeOuterWindowID, maxTouchPoints);
}
if (!rv) {
mInvalidReason = "Couldn't initialize TabContext.";
}
}
bool MaybeInvalidTabContext::IsValid() { return mInvalidReason == nullptr; }
const char* MaybeInvalidTabContext::GetInvalidReason() {
return mInvalidReason;
}
const TabContext& MaybeInvalidTabContext::GetTabContext() {
if (!IsValid()) {
MOZ_CRASH("Can't GetTabContext() if !IsValid().");
}
return mTabContext;
}
} // namespace mozilla::dom