Commit 2285197c authored by Hidehiko Abe's avatar Hidehiko Abe Committed by Commit Bot

exo: Remove modifier_flags_ from exo::Keyboard.

Now modifiers are tracked in XkbTracker, so remove the cache from
exo::Keyboard.
Instead, it is cached in WaylandKeyboardDelegate for re-sending
purpose.

BUG=1123705
TEST=Ran exo_unittests locally.

Change-Id: I2800f507a030a938d2e0d58163e2e5005f1de299
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426663Reviewed-by: default avatarJun Mukai <mukai@chromium.org>
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810019}
parent c8899cd7
...@@ -33,14 +33,6 @@ namespace { ...@@ -33,14 +33,6 @@ namespace {
// Delay until a key state change expected to be acknowledged is expired. // Delay until a key state change expected to be acknowledged is expired.
const int kExpirationDelayForPendingKeyAcksMs = 1000; const int kExpirationDelayForPendingKeyAcksMs = 1000;
// These modifiers reflect what clients are supposed to be aware of.
// I.e. EF_SCROLL_LOCK_ON is missing because clients are not supposed
// to be aware scroll lock.
const int kModifierMask = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN |
ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN |
ui::EF_ALTGR_DOWN | ui::EF_MOD3_DOWN |
ui::EF_NUM_LOCK_ON | ui::EF_CAPS_LOCK_ON;
// The accelerator keys reserved to be processed by chrome. // The accelerator keys reserved to be processed by chrome.
const struct { const struct {
ui::KeyboardCode keycode; ui::KeyboardCode keycode;
...@@ -286,11 +278,7 @@ void Keyboard::OnKeyEvent(ui::KeyEvent* event) { ...@@ -286,11 +278,7 @@ void Keyboard::OnKeyEvent(ui::KeyEvent* event) {
ConsumedByIme(focus_, event); ConsumedByIme(focus_, event);
// Always update modifiers. // Always update modifiers.
int modifier_flags = event->flags() & kModifierMask; delegate_->OnKeyboardModifiers(event->flags());
if (modifier_flags != modifier_flags_) {
modifier_flags_ = modifier_flags;
delegate_->OnKeyboardModifiers(modifier_flags_);
}
// 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
...@@ -427,9 +415,8 @@ void Keyboard::SetFocus(Surface* surface) { ...@@ -427,9 +415,8 @@ void Keyboard::SetFocus(Surface* surface) {
pending_key_acks_.clear(); pending_key_acks_.clear();
} }
if (surface) { if (surface) {
modifier_flags_ = seat_->modifier_flags() & kModifierMask;
pressed_keys_ = seat_->pressed_keys(); pressed_keys_ = seat_->pressed_keys();
delegate_->OnKeyboardModifiers(modifier_flags_); 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);
......
...@@ -117,9 +117,6 @@ class Keyboard : public ui::EventHandler, ...@@ -117,9 +117,6 @@ class Keyboard : public ui::EventHandler,
// details. // details.
base::flat_map<ui::DomCode, ui::DomCode> pressed_keys_; base::flat_map<ui::DomCode, ui::DomCode> pressed_keys_;
// Current set of modifier flags.
int modifier_flags_ = 0;
// Key state changes that are expected to be acknowledged. // Key state changes that are expected to be acknowledged.
using KeyStateChange = std::pair<ui::KeyEvent, base::TimeTicks>; using KeyStateChange = std::pair<ui::KeyEvent, base::TimeTicks>;
base::flat_map<uint32_t, KeyStateChange> pending_key_acks_; base::flat_map<uint32_t, KeyStateChange> pending_key_acks_;
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <stdint.h> #include <stdint.h>
#include <tuple>
namespace exo { namespace exo {
// Represents keyboard modifiers. // Represents keyboard modifiers.
...@@ -17,6 +19,12 @@ struct KeyboardModifiers { ...@@ -17,6 +19,12 @@ struct KeyboardModifiers {
uint32_t group; uint32_t group;
}; };
inline bool operator==(const KeyboardModifiers& lhs,
const KeyboardModifiers& rhs) {
return std::tie(lhs.depressed, lhs.locked, lhs.latched, lhs.group) ==
std::tie(rhs.depressed, rhs.locked, rhs.latched, rhs.group);
}
} // namespace exo } // namespace exo
#endif // COMPONENTS_EXO_KEYBOARD_MODIFIERS_H_ #endif // COMPONENTS_EXO_KEYBOARD_MODIFIERS_H_
...@@ -90,6 +90,12 @@ uint32_t WaylandKeyboardDelegate::OnKeyboardKey(base::TimeTicks time_stamp, ...@@ -90,6 +90,12 @@ uint32_t WaylandKeyboardDelegate::OnKeyboardKey(base::TimeTicks time_stamp,
void WaylandKeyboardDelegate::OnKeyboardModifiers(int modifier_flags) { void WaylandKeyboardDelegate::OnKeyboardModifiers(int modifier_flags) {
xkb_tracker_->UpdateKeyboardModifiers(modifier_flags); xkb_tracker_->UpdateKeyboardModifiers(modifier_flags);
// Send the update only when they're different.
const KeyboardModifiers modifiers = xkb_tracker_->GetModifiers();
if (current_modifiers_ == modifiers)
return;
current_modifiers_ = modifiers;
SendKeyboardModifiers(); SendKeyboardModifiers();
} }
...@@ -110,12 +116,11 @@ uint32_t WaylandKeyboardDelegate::DomCodeToKey(ui::DomCode code) const { ...@@ -110,12 +116,11 @@ uint32_t WaylandKeyboardDelegate::DomCodeToKey(ui::DomCode code) const {
} }
void WaylandKeyboardDelegate::SendKeyboardModifiers() { void WaylandKeyboardDelegate::SendKeyboardModifiers() {
const KeyboardModifiers modifiers = xkb_tracker_->GetModifiers();
wl_keyboard_send_modifiers( wl_keyboard_send_modifiers(
keyboard_resource_, keyboard_resource_,
serial_tracker_->GetNextSerial(SerialTracker::EventType::OTHER_EVENT), serial_tracker_->GetNextSerial(SerialTracker::EventType::OTHER_EVENT),
modifiers.depressed, modifiers.locked, modifiers.latched, current_modifiers_.depressed, current_modifiers_.locked,
modifiers.group); current_modifiers_.latched, current_modifiers_.group);
wl_client_flush(client()); wl_client_flush(client());
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "build/buildflag.h" #include "build/buildflag.h"
#include "components/exo/keyboard_delegate.h" #include "components/exo/keyboard_delegate.h"
#include "components/exo/keyboard_observer.h" #include "components/exo/keyboard_modifiers.h"
#include "components/exo/wayland/server_util.h" #include "components/exo/wayland/server_util.h"
#include "components/exo/wayland/wayland_input_delegate.h" #include "components/exo/wayland/wayland_input_delegate.h"
#include "ui/base/buildflags.h" #include "ui/base/buildflags.h"
...@@ -79,6 +79,9 @@ class WaylandKeyboardDelegate : public WaylandInputDelegate, ...@@ -79,6 +79,9 @@ class WaylandKeyboardDelegate : public WaylandInputDelegate,
// zwp_text_input. // zwp_text_input.
std::unique_ptr<XkbTracker> xkb_tracker_; std::unique_ptr<XkbTracker> xkb_tracker_;
// Tracks the latest modifiers.
KeyboardModifiers current_modifiers_{};
DISALLOW_COPY_AND_ASSIGN(WaylandKeyboardDelegate); DISALLOW_COPY_AND_ASSIGN(WaylandKeyboardDelegate);
#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