Commit 5ee77c39 authored by Alexander Dunaev's avatar Alexander Dunaev Committed by Commit Bot

[ozone] Added propagation of the key event modifiers.

The menus should show mnemonics if Alt is pressed.  This did not work in
Ozone because the platform didn't expose the current status of control
keys (which is delivered with input events as so called modifiers).

This CL introduces a new method that returns the current state of
modifier keys from the platform, and allows the menu mnemonics for two
Ozone platforms.

In addition, one unit tests of the menu controller has been enabled for
all platforms where Aura is available.

Bug: 1085700, 1113086
Change-Id: Ie2857c763d325f85c7f464e69cc22a18bcbf6f61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2333833Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarMaksim Sisov (GMT+3) <msisov@igalia.com>
Commit-Queue: Alexander Dunaev <adunaev@igalia.com>
Cr-Commit-Position: refs/heads/master@{#797578}
parent 924bd5dd
...@@ -788,6 +788,10 @@ bool IsAltPressed() { ...@@ -788,6 +788,10 @@ bool IsAltPressed() {
return XModifierStateWatcher::GetInstance()->state() & Mod1Mask; return XModifierStateWatcher::GetInstance()->state() & Mod1Mask;
} }
int GetModifierKeyState() {
return XModifierStateWatcher::GetInstance()->state();
}
void ResetTimestampRolloverCountersForTesting() { void ResetTimestampRolloverCountersForTesting() {
g_last_seen_timestamp_ms = 0; g_last_seen_timestamp_ms = 0;
g_rollover_ms = 0; g_rollover_ms = 0;
......
...@@ -91,6 +91,10 @@ EVENTS_X_EXPORT bool GetFlingDataFromXEvent(const x11::Event& xev, ...@@ -91,6 +91,10 @@ EVENTS_X_EXPORT bool GetFlingDataFromXEvent(const x11::Event& xev,
// Uses the XModifierStateWatcher to determine if alt is pressed or not. // Uses the XModifierStateWatcher to determine if alt is pressed or not.
EVENTS_X_EXPORT bool IsAltPressed(); EVENTS_X_EXPORT bool IsAltPressed();
// Proxies the XModifierStateWatcher::state() to return the current state of
// modifier keys.
EVENTS_X_EXPORT int GetModifierKeyState();
EVENTS_X_EXPORT void ResetTimestampRolloverCountersForTesting(); EVENTS_X_EXPORT void ResetTimestampRolloverCountersForTesting();
} // namespace ui } // namespace ui
......
...@@ -59,6 +59,8 @@ class WaylandEventSource : public PlatformEventSource, ...@@ -59,6 +59,8 @@ class WaylandEventSource : public PlatformEventSource,
return last_pointer_button_pressed_; return last_pointer_button_pressed_;
} }
int keyboard_modifiers() const { return keyboard_modifiers_; }
// Starts polling for events from the wayland connection file descriptor. // Starts polling for events from the wayland connection file descriptor.
// This method assumes connection is already estabilished and input objects // This method assumes connection is already estabilished and input objects
// are already bound and properly initialized. // are already bound and properly initialized.
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_connector.h" #include "ui/ozone/platform/wayland/host/wayland_buffer_manager_connector.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h" #include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h"
#include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_event_source.h"
#include "ui/ozone/platform/wayland/host/wayland_input_method_context_factory.h" #include "ui/ozone/platform/wayland/host/wayland_input_method_context_factory.h"
#include "ui/ozone/platform/wayland/host/wayland_output_manager.h" #include "ui/ozone/platform/wayland/host/wayland_output_manager.h"
#include "ui/ozone/platform/wayland/host/wayland_window.h" #include "ui/ozone/platform/wayland/host/wayland_window.h"
...@@ -138,6 +139,12 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -138,6 +139,12 @@ class OzonePlatformWayland : public OzonePlatform {
return connection_->clipboard(); return connection_->clipboard();
} }
int GetKeyModifiers() const override {
DCHECK(connection_);
DCHECK(connection_->event_source());
return connection_->event_source()->keyboard_modifiers();
}
std::unique_ptr<InputMethod> CreateInputMethod( std::unique_ptr<InputMethod> CreateInputMethod(
internal::InputMethodDelegate* delegate, internal::InputMethodDelegate* delegate,
gfx::AcceleratedWidget widget) override { gfx::AcceleratedWidget widget) override {
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h" #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
#include "ui/events/platform/x11/x11_event_source.h" #include "ui/events/platform/x11/x11_event_source.h"
#include "ui/events/x/events_x_utils.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11_types.h"
#include "ui/ozone/common/stub_overlay_manager.h" #include "ui/ozone/common/stub_overlay_manager.h"
...@@ -133,6 +134,8 @@ class OzonePlatformX11 : public OzonePlatform, ...@@ -133,6 +134,8 @@ class OzonePlatformX11 : public OzonePlatform,
return gl_egl_utility_.get(); return gl_egl_utility_.get();
} }
int GetKeyModifiers() const override { return GetModifierKeyState(); }
std::unique_ptr<InputMethod> CreateInputMethod( std::unique_ptr<InputMethod> CreateInputMethod(
internal::InputMethodDelegate* delegate, internal::InputMethodDelegate* delegate,
gfx::AcceleratedWidget) override { gfx::AcceleratedWidget) override {
......
...@@ -95,6 +95,11 @@ PlatformGLEGLUtility* OzonePlatform::GetPlatformGLEGLUtility() { ...@@ -95,6 +95,11 @@ PlatformGLEGLUtility* OzonePlatform::GetPlatformGLEGLUtility() {
return nullptr; return nullptr;
} }
int OzonePlatform::GetKeyModifiers() const {
// Platform may override this to provide the current state of modifier keys.
return 0;
}
bool OzonePlatform::IsNativePixmapConfigSupported( bool OzonePlatform::IsNativePixmapConfigSupported(
gfx::BufferFormat format, gfx::BufferFormat format,
gfx::BufferUsage usage) const { gfx::BufferUsage usage) const {
......
...@@ -175,6 +175,10 @@ class COMPONENT_EXPORT(OZONE) OzonePlatform { ...@@ -175,6 +175,10 @@ class COMPONENT_EXPORT(OZONE) OzonePlatform {
gfx::AcceleratedWidget widget) = 0; gfx::AcceleratedWidget widget) = 0;
virtual PlatformGLEGLUtility* GetPlatformGLEGLUtility(); virtual PlatformGLEGLUtility* GetPlatformGLEGLUtility();
// Returns a bitmask of EventFlags showing the state of Alt, Shift and Ctrl
// keys that came with the most recent UI event.
virtual int GetKeyModifiers() const;
// Returns true if the specified buffer format is supported. // Returns true if the specified buffer format is supported.
virtual bool IsNativePixmapConfigSupported(gfx::BufferFormat format, virtual bool IsNativePixmapConfigSupported(gfx::BufferFormat format,
gfx::BufferUsage usage) const; gfx::BufferUsage usage) const;
......
...@@ -877,12 +877,10 @@ class MenuControllerTest : public ViewsTestBase, ...@@ -877,12 +877,10 @@ class MenuControllerTest : public ViewsTestBase,
INSTANTIATE_TEST_SUITE_P(All, MenuControllerTest, testing::Bool()); INSTANTIATE_TEST_SUITE_P(All, MenuControllerTest, testing::Bool());
#if defined(USE_X11) #if defined(USE_AURA)
// Tests that an event targeter which blocks events will be honored by the menu // Tests that an event targeter which blocks events will be honored by the menu
// event dispatcher. // event dispatcher.
TEST_F(MenuControllerTest, EventTargeter) { TEST_F(MenuControllerTest, EventTargeter) {
if (features::IsUsingOzonePlatform())
return;
{ {
// With the aura::NullWindowTargeter instantiated and assigned we expect // With the aura::NullWindowTargeter instantiated and assigned we expect
// the menu to not handle the key event. // the menu to not handle the key event.
...@@ -896,8 +894,7 @@ TEST_F(MenuControllerTest, EventTargeter) { ...@@ -896,8 +894,7 @@ TEST_F(MenuControllerTest, EventTargeter) {
TestAsyncEscapeKey(); TestAsyncEscapeKey();
EXPECT_EQ(MenuController::ExitType::kAll, menu_exit_type()); EXPECT_EQ(MenuController::ExitType::kAll, menu_exit_type());
} }
#endif // defined(USE_AURA)
#endif // defined(USE_X11)
#if defined(USE_X11) #if defined(USE_X11)
// Tests that touch event ids are released correctly. See crbug.com/439051 for // Tests that touch event ids are released correctly. See crbug.com/439051 for
......
...@@ -24,10 +24,15 @@ ...@@ -24,10 +24,15 @@
#endif #endif
#if defined(USE_X11) #if defined(USE_X11)
#include "ui/base/ui_base_features.h"
#include "ui/events/x/events_x_utils.h" // nogncheck #include "ui/events/x/events_x_utils.h" // nogncheck
#endif #endif
#if defined(USE_OZONE)
#include "ui/base/ui_base_features.h"
#include "ui/events/event_constants.h"
#include "ui/ozone/public/ozone_platform.h"
#endif
namespace views { namespace views {
namespace { namespace {
...@@ -45,6 +50,22 @@ void FireFocusAfterMenuClose(base::WeakPtr<Widget> widget) { ...@@ -45,6 +50,22 @@ void FireFocusAfterMenuClose(base::WeakPtr<Widget> widget) {
} }
} }
#if defined(USE_X11) || defined(USE_OZONE)
bool IsAltPressed() {
#if defined(USE_OZONE)
if (features::IsUsingOzonePlatform()) {
return (ui::OzonePlatform::GetInstance()->GetKeyModifiers() &
ui::EF_ALT_DOWN) != 0;
}
#endif
#if defined(USE_X11)
return ui::IsAltPressed();
#else
return false;
#endif
}
#endif // defined(USE_X11) || degined(USE_OZONE)
} // namespace } // namespace
namespace internal { namespace internal {
...@@ -242,10 +263,8 @@ bool MenuRunnerImpl::ShouldShowMnemonics(int32_t run_types) { ...@@ -242,10 +263,8 @@ bool MenuRunnerImpl::ShouldShowMnemonics(int32_t run_types) {
// Show mnemonics if the button has focus or alt is pressed. // Show mnemonics if the button has focus or alt is pressed.
#if defined(OS_WIN) #if defined(OS_WIN)
show_mnemonics |= ui::win::IsAltPressed(); show_mnemonics |= ui::win::IsAltPressed();
#elif defined(USE_X11) #elif defined(USE_X11) || defined(USE_OZONE)
// TODO(https://crbug.com/1098203): fix mnemonics for Ozone/Linux. show_mnemonics |= IsAltPressed();
if (!features::IsUsingOzonePlatform())
show_mnemonics |= ui::IsAltPressed();
#elif defined(OS_APPLE) #elif defined(OS_APPLE)
show_mnemonics = false; show_mnemonics = false;
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment