Commit 6dbadbf0 authored by Alexander Alekseev's avatar Alexander Alekseev Committed by Commit Bot

Revert "exo: Move XkbTracker from WaylandKeyboardDelegate to Seat."

This reverts commit c1744bc0.

Reason for revert: Broke build: https://crbug.com/1132766

Original change's description:
> exo: Move XkbTracker from WaylandKeyboardDelegate to Seat.
>
> This is preparation to share XkbTracker with wayland IME server.
>
> BUG=1123705
> TEST=Built locally. Run exo_unittests.
>
> Change-Id: I7859c2193578cc5a18fa39a96c3fe86d2f39f4dc
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2428505
> Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
> Reviewed-by: Jun Mukai <mukai@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#810863}

TBR=mukai@chromium.org,hidehiko@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 1123705,1132766
Change-Id: I92c8df6383ea569ca2b88780c6017c619e26d1af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2434097
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811383}
parent a293ccad
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "components/exo/buffer.h" #include "components/exo/buffer.h"
#include "components/exo/keyboard.h" #include "components/exo/keyboard.h"
#include "components/exo/keyboard_delegate.h" #include "components/exo/keyboard_delegate.h"
#include "components/exo/keyboard_modifiers.h"
#include "components/exo/notification_surface.h" #include "components/exo/notification_surface.h"
#include "components/exo/seat.h" #include "components/exo/seat.h"
#include "components/exo/surface.h" #include "components/exo/surface.h"
...@@ -76,15 +75,15 @@ class MockKeyboardDelegate : public exo::KeyboardDelegate { ...@@ -76,15 +75,15 @@ class MockKeyboardDelegate : public exo::KeyboardDelegate {
OnKeyboardKey, OnKeyboardKey,
(base::TimeTicks, ui::DomCode, bool), (base::TimeTicks, ui::DomCode, bool),
(override)); (override));
MOCK_METHOD(void, MOCK_METHOD(void, OnKeyboardModifiers, (int), (override));
OnKeyboardModifiers,
(const exo::KeyboardModifiers&),
(override));
MOCK_METHOD(void, MOCK_METHOD(void,
OnKeyRepeatSettingsChanged, OnKeyRepeatSettingsChanged,
(bool, base::TimeDelta, base::TimeDelta), (bool, base::TimeDelta, base::TimeDelta),
(override)); (override));
MOCK_METHOD(void, OnKeyboardLayoutUpdated, (base::StringPiece), (override)); MOCK_METHOD(void,
OnKeyboardLayoutUpdated,
(const std::string& layout_name),
(override));
}; };
class FakeNotificationSurface : public exo::NotificationSurface { class FakeNotificationSurface : public exo::NotificationSurface {
......
...@@ -2,17 +2,9 @@ ...@@ -2,17 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import("//build/config/linux/pkg_config.gni")
import("//build/config/ui.gni") import("//build/config/ui.gni")
import("//chrome/common/features.gni") import("//chrome/common/features.gni")
import("//testing/test.gni") import("//testing/test.gni")
import("//ui/base/ui_features.gni")
if (use_xkbcommon) {
pkg_config("xkbcommon") {
packages = [ "xkbcommon" ]
}
}
static_library("exo") { static_library("exo") {
sources = [ sources = [
...@@ -168,7 +160,6 @@ static_library("exo") { ...@@ -168,7 +160,6 @@ static_library("exo") {
"xkb_tracker.cc", "xkb_tracker.cc",
"xkb_tracker.h", "xkb_tracker.h",
] ]
configs += [ ":xkbcommon" ]
} }
if (is_chromecast) { if (is_chromecast) {
......
...@@ -14,13 +14,11 @@ ...@@ -14,13 +14,11 @@
#include "components/exo/input_trace.h" #include "components/exo/input_trace.h"
#include "components/exo/keyboard_delegate.h" #include "components/exo/keyboard_delegate.h"
#include "components/exo/keyboard_device_configuration_delegate.h" #include "components/exo/keyboard_device_configuration_delegate.h"
#include "components/exo/keyboard_modifiers.h"
#include "components/exo/seat.h" #include "components/exo/seat.h"
#include "components/exo/shell_surface.h" #include "components/exo/shell_surface.h"
#include "components/exo/shell_surface_util.h" #include "components/exo/shell_surface_util.h"
#include "components/exo/surface.h" #include "components/exo/surface.h"
#include "components/exo/wm_helper.h" #include "components/exo/wm_helper.h"
#include "components/exo/xkb_tracker.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/focus_client.h" #include "ui/aura/client/focus_client.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
...@@ -171,7 +169,7 @@ Keyboard::Keyboard(std::unique_ptr<KeyboardDelegate> delegate, Seat* seat) ...@@ -171,7 +169,7 @@ Keyboard::Keyboard(std::unique_ptr<KeyboardDelegate> delegate, Seat* seat)
ash::ImeControllerImpl* ime_controller = ash::Shell::Get()->ime_controller(); ash::ImeControllerImpl* ime_controller = ash::Shell::Get()->ime_controller();
ime_controller->AddObserver(this); ime_controller->AddObserver(this);
delegate_->OnKeyboardLayoutUpdated(seat_->xkb_tracker()->GetKeymap().get()); delegate_->OnKeyboardLayoutUpdated(ime_controller->keyboard_layout_name());
OnSurfaceFocused(seat_->GetFocusedSurface()); OnSurfaceFocused(seat_->GetFocusedSurface());
OnKeyRepeatSettingsChanged( OnKeyRepeatSettingsChanged(
ash::KeyboardController::Get()->GetKeyRepeatSettings()); ash::KeyboardController::Get()->GetKeyRepeatSettings());
...@@ -280,9 +278,7 @@ void Keyboard::OnKeyEvent(ui::KeyEvent* event) { ...@@ -280,9 +278,7 @@ void Keyboard::OnKeyEvent(ui::KeyEvent* event) {
ConsumedByIme(focus_, event); ConsumedByIme(focus_, event);
// Always update modifiers. // Always update modifiers.
// XkbTracker must be updated in the Seat, before calling this method. delegate_->OnKeyboardModifiers(event->flags());
// Ensured by the observer registration order.
delegate_->OnKeyboardModifiers(seat_->xkb_tracker()->GetModifiers());
// TODO(yhanada): This is a quick fix for https://crbug.com/859071. Remove // TODO(yhanada): This is a quick fix for https://crbug.com/859071. Remove
// ARC-specific code path once we can find a way to manage press/release // ARC-specific code path once we can find a way to manage press/release
...@@ -405,9 +401,7 @@ void Keyboard::OnKeyRepeatSettingsChanged( ...@@ -405,9 +401,7 @@ void Keyboard::OnKeyRepeatSettingsChanged(
void Keyboard::OnCapsLockChanged(bool enabled) {} void Keyboard::OnCapsLockChanged(bool enabled) {}
void Keyboard::OnKeyboardLayoutNameChanged(const std::string& layout_name) { void Keyboard::OnKeyboardLayoutNameChanged(const std::string& layout_name) {
// XkbTracker must be updated in the Seat, before calling this method. delegate_->OnKeyboardLayoutUpdated(layout_name);
// Ensured by the observer registration order.
delegate_->OnKeyboardLayoutUpdated(seat_->xkb_tracker()->GetKeymap().get());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -422,7 +416,7 @@ void Keyboard::SetFocus(Surface* surface) { ...@@ -422,7 +416,7 @@ void Keyboard::SetFocus(Surface* surface) {
} }
if (surface) { if (surface) {
pressed_keys_ = seat_->pressed_keys(); pressed_keys_ = seat_->pressed_keys();
delegate_->OnKeyboardModifiers(seat_->xkb_tracker()->GetModifiers()); delegate_->OnKeyboardModifiers(seat_->modifier_flags());
delegate_->OnKeyboardEnter(surface, pressed_keys_); delegate_->OnKeyboardEnter(surface, pressed_keys_);
focus_ = surface; focus_ = surface;
focus_->AddSurfaceObserver(this); focus_->AddSurfaceObserver(this);
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "base/containers/flat_set.h" #include "base/containers/flat_set.h"
#include "base/strings/string_piece.h"
#include "base/time/time.h" #include "base/time/time.h"
namespace ui { namespace ui {
...@@ -15,7 +14,6 @@ enum class DomCode; ...@@ -15,7 +14,6 @@ enum class DomCode;
} }
namespace exo { namespace exo {
struct KeyboardModifiers;
class Surface; class Surface;
// Handles events on keyboards in context-specific ways. // Handles events on keyboards in context-specific ways.
...@@ -44,7 +42,7 @@ class KeyboardDelegate { ...@@ -44,7 +42,7 @@ class KeyboardDelegate {
bool pressed) = 0; bool pressed) = 0;
// Called when keyboard modifier state changed. // Called when keyboard modifier state changed.
virtual void OnKeyboardModifiers(const KeyboardModifiers& modifiers) = 0; virtual void OnKeyboardModifiers(int modifier_flags) = 0;
// Called when key repeat settings are changed. // Called when key repeat settings are changed.
virtual void OnKeyRepeatSettingsChanged(bool enabled, virtual void OnKeyRepeatSettingsChanged(bool enabled,
...@@ -52,7 +50,9 @@ class KeyboardDelegate { ...@@ -52,7 +50,9 @@ class KeyboardDelegate {
base::TimeDelta interval) = 0; base::TimeDelta interval) = 0;
// Called when keyboard layout is updated. // Called when keyboard layout is updated.
virtual void OnKeyboardLayoutUpdated(base::StringPiece keymap) = 0; // TODO(hidehiko): Update the argument to pass the keymap
// when XkbTracker is moved out from WaylandKeyboardDelegate.
virtual void OnKeyboardLayoutUpdated(const std::string& layout_name) = 0;
}; };
} // namespace exo } // namespace exo
......
This diff is collapsed.
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "components/exo/shell_surface_util.h" #include "components/exo/shell_surface_util.h"
#include "components/exo/surface.h" #include "components/exo/surface.h"
#include "components/exo/wm_helper.h" #include "components/exo/wm_helper.h"
#include "components/exo/xkb_tracker.h"
#include "services/data_decoder/public/cpp/decode_image.h" #include "services/data_decoder/public/cpp/decode_image.h"
#include "ui/aura/client/focus_client.h" #include "ui/aura/client/focus_client.h"
#include "ui/base/clipboard/clipboard_data_endpoint.h" #include "ui/base/clipboard/clipboard_data_endpoint.h"
...@@ -63,14 +62,6 @@ Seat::Seat() : changing_clipboard_data_to_selection_source_(false) { ...@@ -63,14 +62,6 @@ Seat::Seat() : changing_clipboard_data_to_selection_source_(false) {
ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this);
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
ui_lock_controller_ = std::make_unique<UILockController>(this); ui_lock_controller_ = std::make_unique<UILockController>(this);
// Seat needs to be registered as observers before any Keyboard,
// because Keyboard expects that the XkbTracker is up-to-date when its
// observer method is called.
xkb_tracker_ = std::make_unique<XkbTracker>();
ash::ImeControllerImpl* ime_controller = ash::Shell::Get()->ime_controller();
xkb_tracker_->UpdateKeyboardLayout(ime_controller->keyboard_layout_name());
ime_controller->AddObserver(this);
#endif #endif
} }
...@@ -83,9 +74,6 @@ void Seat::Shutdown() { ...@@ -83,9 +74,6 @@ void Seat::Shutdown() {
return; return;
shutdown_ = true; shutdown_ = true;
DCHECK(!selection_source_) << "DataSource must be released before Seat"; DCHECK(!selection_source_) << "DataSource must be released before Seat";
#if defined(OS_CHROMEOS)
ash::Shell::Get()->ime_controller()->RemoveObserver(this);
#endif
WMHelper::GetInstance()->RemoveFocusObserver(this); WMHelper::GetInstance()->RemoveFocusObserver(this);
WMHelper::GetInstance()->RemovePreTargetHandler(this); WMHelper::GetInstance()->RemovePreTargetHandler(this);
ui::ClipboardMonitor::GetInstance()->RemoveObserver(this); ui::ClipboardMonitor::GetInstance()->RemoveObserver(this);
...@@ -303,9 +291,7 @@ void Seat::OnKeyEvent(ui::KeyEvent* event) { ...@@ -303,9 +291,7 @@ void Seat::OnKeyEvent(ui::KeyEvent* event) {
break; break;
} }
} }
#if defined(OS_CHROMEOS) modifier_flags_ = event->flags();
xkb_tracker_->UpdateKeyboardModifiers(event->flags());
#endif
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -318,17 +304,6 @@ void Seat::OnClipboardDataChanged() { ...@@ -318,17 +304,6 @@ void Seat::OnClipboardDataChanged() {
selection_source_.reset(); selection_source_.reset();
} }
#if defined(OS_CHROMEOS)
////////////////////////////////////////////////////////////////////////////////
// ash::ImeControllerImpl::Observer overrides:
void Seat::OnCapsLockChanged(bool enabled) {}
void Seat::OnKeyboardLayoutNameChanged(const std::string& layout_name) {
xkb_tracker_->UpdateKeyboardLayout(layout_name);
}
#endif
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// DataSourceObserver overrides: // DataSourceObserver overrides:
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "ui/events/platform/platform_event_observer.h" #include "ui/events/platform/platform_event_observer.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "ash/ime/ime_controller_impl.h"
#include "components/exo/ui_lock_controller.h" #include "components/exo/ui_lock_controller.h"
#endif #endif
...@@ -33,7 +32,6 @@ class DragDropOperation; ...@@ -33,7 +32,6 @@ class DragDropOperation;
class ScopedDataSource; class ScopedDataSource;
class SeatObserver; class SeatObserver;
class Surface; class Surface;
class XkbTracker;
// The maximum number of different data types that we will write to the // The maximum number of different data types that we will write to the
// clipboard (plain text, RTF, HTML, image) // clipboard (plain text, RTF, HTML, image)
...@@ -45,9 +43,6 @@ class Seat : public aura::client::FocusChangeObserver, ...@@ -45,9 +43,6 @@ class Seat : public aura::client::FocusChangeObserver,
public ui::PlatformEventObserver, public ui::PlatformEventObserver,
public ui::EventHandler, public ui::EventHandler,
public ui::ClipboardObserver, public ui::ClipboardObserver,
#if defined(OS_CHROMEOS)
public ash::ImeControllerImpl::Observer,
#endif
public DataSourceObserver { public DataSourceObserver {
public: public:
Seat(); Seat();
...@@ -67,9 +62,8 @@ class Seat : public aura::client::FocusChangeObserver, ...@@ -67,9 +62,8 @@ class Seat : public aura::client::FocusChangeObserver,
return pressed_keys_; return pressed_keys_;
} }
#if defined(OS_CHROMEOS) // Returns current set of modifier flags.
const XkbTracker* xkb_tracker() const { return xkb_tracker_.get(); } int modifier_flags() const { return modifier_flags_; }
#endif
// Returns physical code for the currently processing event. // Returns physical code for the currently processing event.
ui::DomCode physical_code_for_currently_processing_event() const { ui::DomCode physical_code_for_currently_processing_event() const {
...@@ -108,12 +102,6 @@ class Seat : public aura::client::FocusChangeObserver, ...@@ -108,12 +102,6 @@ class Seat : public aura::client::FocusChangeObserver,
// Overridden from DataSourceObserver: // Overridden from DataSourceObserver:
void OnDataSourceDestroying(DataSource* source) override; void OnDataSourceDestroying(DataSource* source) override;
#if defined(OS_CHROMEOS)
// Overridden from ash::ImeControllerImpl::Observer:
void OnCapsLockChanged(bool enabled) override;
void OnKeyboardLayoutNameChanged(const std::string& layout_name) override;
#endif
void set_physical_code_for_currently_processing_event_for_testing( void set_physical_code_for_currently_processing_event_for_testing(
ui::DomCode physical_code_for_currently_processing_event) { ui::DomCode physical_code_for_currently_processing_event) {
physical_code_for_currently_processing_event_ = physical_code_for_currently_processing_event_ =
...@@ -161,6 +149,7 @@ class Seat : public aura::client::FocusChangeObserver, ...@@ -161,6 +149,7 @@ class Seat : public aura::client::FocusChangeObserver,
// physical key press generated. // physical key press generated.
base::flat_map<ui::DomCode, ui::DomCode> pressed_keys_; base::flat_map<ui::DomCode, ui::DomCode> pressed_keys_;
ui::DomCode physical_code_for_currently_processing_event_ = ui::DomCode::NONE; ui::DomCode physical_code_for_currently_processing_event_ = ui::DomCode::NONE;
int modifier_flags_ = 0;
// Data source being used as a clipboard content. // Data source being used as a clipboard content.
std::unique_ptr<ScopedDataSource> selection_source_; std::unique_ptr<ScopedDataSource> selection_source_;
...@@ -176,7 +165,6 @@ class Seat : public aura::client::FocusChangeObserver, ...@@ -176,7 +165,6 @@ class Seat : public aura::client::FocusChangeObserver,
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
std::unique_ptr<UILockController> ui_lock_controller_; std::unique_ptr<UILockController> ui_lock_controller_;
std::unique_ptr<XkbTracker> xkb_tracker_;
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
base::WeakPtrFactory<Seat> weak_ptr_factory_{this}; base::WeakPtrFactory<Seat> weak_ptr_factory_{this};
......
...@@ -2,12 +2,19 @@ ...@@ -2,12 +2,19 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import("//build/config/linux/pkg_config.gni")
import("//build/config/ui.gni") import("//build/config/ui.gni")
import("//gpu/vulkan/features.gni") import("//gpu/vulkan/features.gni")
import("//testing/test.gni") import("//testing/test.gni")
import("//ui/base/ui_features.gni") import("//ui/base/ui_features.gni")
import("//ui/ozone/ozone.gni") import("//ui/ozone/ozone.gni")
if (use_xkbcommon) {
pkg_config("xkbcommon") {
packages = [ "xkbcommon" ]
}
}
source_set("wayland") { source_set("wayland") {
sources = [ sources = [
"scoped_wl.cc", "scoped_wl.cc",
...@@ -129,6 +136,7 @@ source_set("wayland") { ...@@ -129,6 +136,7 @@ source_set("wayland") {
} }
if (use_xkbcommon) { if (use_xkbcommon) {
configs += [ ":xkbcommon" ]
deps += [ "//ui/events/keycodes:xkb" ] deps += [ "//ui/events/keycodes:xkb" ]
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "components/exo/wayland/fuzzer/harness.h" #include "components/exo/wayland/fuzzer/harness.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/macros.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/exo/display.h" #include "components/exo/display.h"
...@@ -12,36 +13,20 @@ ...@@ -12,36 +13,20 @@
#include "components/exo/wayland/fuzzer/actions.pb.h" #include "components/exo/wayland/fuzzer/actions.pb.h"
#include "components/exo/wayland/server.h" #include "components/exo/wayland/server.h"
#if defined(OS_CHROMEOS)
#include "components/exo/test/exo_test_base.h"
#endif
namespace exo { namespace exo {
namespace wayland_fuzzer { namespace wayland_fuzzer {
namespace { namespace {
// Use ExoTestBase on Chrome OS because Server starts to depends on ash::Shell, class WaylandFuzzerTest : public test::ExoTestBaseViews {
// which is unavailable on other platforms so then ExoTestBaseViews instead.
using TestBase =
#if defined(OS_CHROMEOS)
test::ExoTestBase
#else
test::ExoTestBaseViews
#endif
;
class WaylandFuzzerTest : public TestBase {
protected: protected:
WaylandFuzzerTest() = default; WaylandFuzzerTest() = default;
WaylandFuzzerTest(const WaylandFuzzerTest&) = delete;
WaylandFuzzerTest& operator=(const WaylandFuzzerTest&) = delete;
~WaylandFuzzerTest() override = default; ~WaylandFuzzerTest() override = default;
void SetUp() override { void SetUp() override {
ASSERT_TRUE(xdg_temp_dir_.CreateUniqueTempDir()); ASSERT_TRUE(xdg_temp_dir_.CreateUniqueTempDir());
setenv("XDG_RUNTIME_DIR", xdg_temp_dir_.GetPath().MaybeAsASCII().c_str(), setenv("XDG_RUNTIME_DIR", xdg_temp_dir_.GetPath().MaybeAsASCII().c_str(),
1 /* overwrite */); 1 /* overwrite */);
TestBase::SetUp(); test::ExoTestBaseViews::SetUp();
display_ = std::make_unique<exo::Display>(); display_ = std::make_unique<exo::Display>();
server_ = wayland::Server::Create(display_.get()); server_ = wayland::Server::Create(display_.get());
} }
...@@ -49,12 +34,15 @@ class WaylandFuzzerTest : public TestBase { ...@@ -49,12 +34,15 @@ class WaylandFuzzerTest : public TestBase {
void TearDown() override { void TearDown() override {
server_.reset(); server_.reset();
display_.reset(); display_.reset();
TestBase::TearDown(); test::ExoTestBaseViews::TearDown();
} }
base::ScopedTempDir xdg_temp_dir_; base::ScopedTempDir xdg_temp_dir_;
std::unique_ptr<exo::Display> display_; std::unique_ptr<exo::Display> display_;
std::unique_ptr<wayland::Server> server_; std::unique_ptr<wayland::Server> server_;
private:
DISALLOW_COPY_AND_ASSIGN(WaylandFuzzerTest);
}; };
void RunHarness(Harness* harness, base::WaitableEvent* event) { void RunHarness(Harness* harness, base::WaitableEvent* event) {
......
...@@ -20,10 +20,6 @@ ...@@ -20,10 +20,6 @@
#include "components/exo/test/exo_test_base_views.h" #include "components/exo/test/exo_test_base_views.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_CHROMEOS)
#include "components/exo/test/exo_test_base.h"
#endif
namespace exo { namespace exo {
namespace wayland { namespace wayland {
namespace { namespace {
...@@ -35,32 +31,22 @@ std::string GetUniqueSocketName() { ...@@ -35,32 +31,22 @@ std::string GetUniqueSocketName() {
g_next_socket_id.GetNext()); g_next_socket_id.GetNext());
} }
// Use ExoTestBase on Chrome OS because Server starts to depends on ash::Shell, class ServerTest : public test::ExoTestBaseViews {
// which is unavailable on other platforms so then ExoTestBaseViews instead.
using TestBase =
#if defined(OS_CHROMEOS)
test::ExoTestBase
#else
test::ExoTestBaseViews
#endif
;
class ServerTest : public TestBase {
public: public:
ServerTest() = default; ServerTest() {}
ServerTest(const ServerTest&) = delete; ~ServerTest() override {}
ServerTest& operator=(const ServerTest&) = delete;
~ServerTest() override = default;
void SetUp() override { void SetUp() override {
ASSERT_TRUE(xdg_temp_dir_.CreateUniqueTempDir()); ASSERT_TRUE(xdg_temp_dir_.CreateUniqueTempDir());
setenv("XDG_RUNTIME_DIR", xdg_temp_dir_.GetPath().MaybeAsASCII().c_str(), setenv("XDG_RUNTIME_DIR", xdg_temp_dir_.GetPath().MaybeAsASCII().c_str(),
1 /* overwrite */); 1 /* overwrite */);
TestBase::SetUp(); test::ExoTestBaseViews::SetUp();
} }
private: private:
base::ScopedTempDir xdg_temp_dir_; base::ScopedTempDir xdg_temp_dir_;
DISALLOW_COPY_AND_ASSIGN(ServerTest);
}; };
TEST_F(ServerTest, AddSocket) { TEST_F(ServerTest, AddSocket) {
......
...@@ -10,13 +10,11 @@ ...@@ -10,13 +10,11 @@
#include <wayland-server-protocol-core.h> #include <wayland-server-protocol-core.h>
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "components/exo/keyboard_modifiers.h"
#include "components/exo/wayland/serial_tracker.h" #include "components/exo/wayland/serial_tracker.h"
#include "components/exo/xkb_tracker.h"
#include "ui/events/keycodes/dom/dom_code.h" #include "ui/events/keycodes/dom/dom_code.h"
#if BUILDFLAG(USE_XKBCOMMON)
#include <xkbcommon/xkbcommon.h>
#endif
namespace exo { namespace exo {
namespace wayland { namespace wayland {
...@@ -24,7 +22,9 @@ namespace wayland { ...@@ -24,7 +22,9 @@ namespace wayland {
WaylandKeyboardDelegate::WaylandKeyboardDelegate(wl_resource* keyboard_resource, WaylandKeyboardDelegate::WaylandKeyboardDelegate(wl_resource* keyboard_resource,
SerialTracker* serial_tracker) SerialTracker* serial_tracker)
: keyboard_resource_(keyboard_resource), serial_tracker_(serial_tracker) {} : keyboard_resource_(keyboard_resource),
serial_tracker_(serial_tracker),
xkb_tracker_(std::make_unique<XkbTracker>()) {}
WaylandKeyboardDelegate::~WaylandKeyboardDelegate() = default; WaylandKeyboardDelegate::~WaylandKeyboardDelegate() = default;
...@@ -88,9 +88,11 @@ uint32_t WaylandKeyboardDelegate::OnKeyboardKey(base::TimeTicks time_stamp, ...@@ -88,9 +88,11 @@ uint32_t WaylandKeyboardDelegate::OnKeyboardKey(base::TimeTicks time_stamp,
return serial; return serial;
} }
void WaylandKeyboardDelegate::OnKeyboardModifiers( void WaylandKeyboardDelegate::OnKeyboardModifiers(int modifier_flags) {
const KeyboardModifiers& modifiers) { xkb_tracker_->UpdateKeyboardModifiers(modifier_flags);
// Send the update only when they're different. // Send the update only when they're different.
const KeyboardModifiers modifiers = xkb_tracker_->GetModifiers();
if (current_modifiers_ == modifiers) if (current_modifiers_ == modifiers)
return; return;
current_modifiers_ = modifiers; current_modifiers_ = modifiers;
...@@ -98,23 +100,9 @@ void WaylandKeyboardDelegate::OnKeyboardModifiers( ...@@ -98,23 +100,9 @@ void WaylandKeyboardDelegate::OnKeyboardModifiers(
} }
void WaylandKeyboardDelegate::OnKeyboardLayoutUpdated( void WaylandKeyboardDelegate::OnKeyboardLayoutUpdated(
base::StringPiece keymap) { const std::string& layout_name) {
// Sent the content of |keymap| with trailing '\0' termination via shared xkb_tracker_->UpdateKeyboardLayout(layout_name);
// memory. SendLayout();
base::UnsafeSharedMemoryRegion shared_keymap_region =
base::UnsafeSharedMemoryRegion::Create(keymap.size() + 1);
base::WritableSharedMemoryMapping shared_keymap = shared_keymap_region.Map();
base::subtle::PlatformSharedMemoryRegion platform_shared_keymap =
base::UnsafeSharedMemoryRegion::TakeHandleForSerialization(
std::move(shared_keymap_region));
DCHECK(shared_keymap.IsValid());
std::memcpy(shared_keymap.memory(), keymap.data(), keymap.size());
static_cast<uint8_t*>(shared_keymap.memory())[keymap.size()] = '\0';
wl_keyboard_send_keymap(keyboard_resource_, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
platform_shared_keymap.GetPlatformHandle().fd,
keymap.size() + 1);
wl_client_flush(client());
} }
uint32_t WaylandKeyboardDelegate::DomCodeToKey(ui::DomCode code) const { uint32_t WaylandKeyboardDelegate::DomCodeToKey(ui::DomCode code) const {
...@@ -136,6 +124,25 @@ void WaylandKeyboardDelegate::SendKeyboardModifiers() { ...@@ -136,6 +124,25 @@ void WaylandKeyboardDelegate::SendKeyboardModifiers() {
wl_client_flush(client()); wl_client_flush(client());
} }
void WaylandKeyboardDelegate::SendLayout() {
auto keymap = xkb_tracker_->GetKeymap();
size_t keymap_size = strlen(keymap.get()) + 1;
base::UnsafeSharedMemoryRegion shared_keymap_region =
base::UnsafeSharedMemoryRegion::Create(keymap_size);
base::WritableSharedMemoryMapping shared_keymap = shared_keymap_region.Map();
base::subtle::PlatformSharedMemoryRegion platform_shared_keymap =
base::UnsafeSharedMemoryRegion::TakeHandleForSerialization(
std::move(shared_keymap_region));
DCHECK(shared_keymap.IsValid());
std::memcpy(shared_keymap.memory(), keymap.get(), keymap_size);
wl_keyboard_send_keymap(keyboard_resource_, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
platform_shared_keymap.GetPlatformHandle().fd,
keymap_size);
wl_client_flush(client());
}
// Convert from ChromeOS's key repeat interval to Wayland's key repeat rate. // Convert from ChromeOS's key repeat interval to Wayland's key repeat rate.
// For example, an interval of 500ms is a rate of 1000/500 = 2 Hz. // For example, an interval of 500ms is a rate of 1000/500 = 2 Hz.
// //
......
...@@ -16,10 +16,18 @@ ...@@ -16,10 +16,18 @@
#include "ui/base/buildflags.h" #include "ui/base/buildflags.h"
#include "ui/events/keycodes/dom/keycode_converter.h" #include "ui/events/keycodes/dom/keycode_converter.h"
#if BUILDFLAG(USE_XKBCOMMON)
#include <xkbcommon/xkbcommon.h>
#include "ui/events/keycodes/scoped_xkb.h" // nogncheck
#endif
struct wl_client; struct wl_client;
struct wl_resource; struct wl_resource;
namespace exo { namespace exo {
class XkbTracker;
namespace wayland { namespace wayland {
class SerialTracker; class SerialTracker;
...@@ -42,11 +50,11 @@ class WaylandKeyboardDelegate : public WaylandInputDelegate, ...@@ -42,11 +50,11 @@ class WaylandKeyboardDelegate : public WaylandInputDelegate,
uint32_t OnKeyboardKey(base::TimeTicks time_stamp, uint32_t OnKeyboardKey(base::TimeTicks time_stamp,
ui::DomCode key, ui::DomCode key,
bool pressed) override; bool pressed) override;
void OnKeyboardModifiers(const KeyboardModifiers& modifiers) override; void OnKeyboardModifiers(int modifier_flags) override;
void OnKeyRepeatSettingsChanged(bool enabled, void OnKeyRepeatSettingsChanged(bool enabled,
base::TimeDelta delay, base::TimeDelta delay,
base::TimeDelta interval) override; base::TimeDelta interval) override;
void OnKeyboardLayoutUpdated(base::StringPiece keymap) override; void OnKeyboardLayoutUpdated(const std::string& layout_name) override;
private: private:
// Returns the corresponding key given a dom code. // Returns the corresponding key given a dom code.
...@@ -55,6 +63,9 @@ class WaylandKeyboardDelegate : public WaylandInputDelegate, ...@@ -55,6 +63,9 @@ class WaylandKeyboardDelegate : public WaylandInputDelegate,
// Sends the current modifiers to the client. // Sends the current modifiers to the client.
void SendKeyboardModifiers(); void SendKeyboardModifiers();
// Send the current keyboard layout to the client.
void SendLayout();
// The client who own this keyboard instance. // The client who own this keyboard instance.
wl_client* client() const; wl_client* client() const;
...@@ -64,6 +75,10 @@ class WaylandKeyboardDelegate : public WaylandInputDelegate, ...@@ -64,6 +75,10 @@ class WaylandKeyboardDelegate : public WaylandInputDelegate,
// Owned by Server, which always outlives this delegate. // Owned by Server, which always outlives this delegate.
SerialTracker* const serial_tracker_; SerialTracker* const serial_tracker_;
// TODO(hidehiko): Move this to the server in order to share it with
// zwp_text_input.
std::unique_ptr<XkbTracker> xkb_tracker_;
// Tracks the latest modifiers. // Tracks the latest modifiers.
KeyboardModifiers current_modifiers_{}; KeyboardModifiers current_modifiers_{};
......
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