Commit 54ebdf1a authored by sadrul@chromium.org's avatar sadrul@chromium.org

x11: Simplify some more event-rewrite code.

The WindowTreeHost implementation for X11 currently receives an event from X11
when the keyboard mapping changes in the system. The implementation then calls
into WindowTreeHost::OnKeyboardMappingChanged(), which triggers the
corresponding method in all WindowTreeHostObservers. The EventRewriter is a
WindowTreeHostObserver, and so it can then reset the keycodes it maintains.

But the EventRewriter is also a MessagePumpObserver, which means it already
receives the X11 MappingNotify event, and so the plumbing of the event through
aura is unnecessary.  There is no other consumer of
WindowTreeHostObserver::OnKeyboardMappingChanged(), so remove it from the api.

BUG=343639
R=oshima@chromium.org, sky@chromium.org

Review URL: https://codereview.chromium.org/183893031

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255185 0039d316-1c4b-4281-b951-d872f2087c98
parent fdf7b472
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include <vector> #include <vector>
#include "ash/shell.h"
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
#include "ash/wm/window_util.h" #include "ash/wm/window_util.h"
#include "base/command_line.h" #include "base/command_line.h"
...@@ -31,7 +30,6 @@ ...@@ -31,7 +30,6 @@
#include "chromeos/chromeos_switches.h" #include "chromeos/chromeos_switches.h"
#include "chromeos/ime/input_method_manager.h" #include "chromeos/ime/input_method_manager.h"
#include "chromeos/ime/xkeyboard.h" #include "chromeos/ime/xkeyboard.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/x/x11_util.h" #include "ui/base/x/x11_util.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/event_utils.h" #include "ui/events/event_utils.h"
...@@ -141,10 +139,6 @@ EventRewriter::EventRewriter() ...@@ -141,10 +139,6 @@ EventRewriter::EventRewriter()
xkeyboard_for_testing_(NULL), xkeyboard_for_testing_(NULL),
keyboard_driven_event_rewriter_(new KeyboardDrivenEventRewriter), keyboard_driven_event_rewriter_(new KeyboardDrivenEventRewriter),
pref_service_for_testing_(NULL) { pref_service_for_testing_(NULL) {
// The ash shell isn't instantiated for our unit tests.
if (ash::Shell::HasInstance()) {
ash::Shell::GetPrimaryRootWindow()->GetHost()->AddObserver(this);
}
base::MessageLoopForUI::current()->AddObserver(this); base::MessageLoopForUI::current()->AddObserver(this);
if (base::SysInfo::IsRunningOnChromeOS()) { if (base::SysInfo::IsRunningOnChromeOS()) {
XInputHierarchyChangedEventListener::GetInstance()->AddObserver(this); XInputHierarchyChangedEventListener::GetInstance()->AddObserver(this);
...@@ -154,9 +148,6 @@ EventRewriter::EventRewriter() ...@@ -154,9 +148,6 @@ EventRewriter::EventRewriter()
EventRewriter::~EventRewriter() { EventRewriter::~EventRewriter() {
base::MessageLoopForUI::current()->RemoveObserver(this); base::MessageLoopForUI::current()->RemoveObserver(this);
if (ash::Shell::HasInstance()) {
ash::Shell::GetPrimaryRootWindow()->GetHost()->RemoveObserver(this);
}
if (base::SysInfo::IsRunningOnChromeOS()) { if (base::SysInfo::IsRunningOnChromeOS()) {
XInputHierarchyChangedEventListener::GetInstance()->RemoveObserver(this); XInputHierarchyChangedEventListener::GetInstance()->RemoveObserver(this);
} }
...@@ -194,17 +185,19 @@ void EventRewriter::RewriteForTesting(XEvent* event) { ...@@ -194,17 +185,19 @@ void EventRewriter::RewriteForTesting(XEvent* event) {
Rewrite(event); Rewrite(event);
} }
void EventRewriter::OnKeyboardMappingChanged(const aura::WindowTreeHost* host) {
RefreshKeycodes();
}
base::EventStatus EventRewriter::WillProcessEvent( base::EventStatus EventRewriter::WillProcessEvent(
const base::NativeEvent& event) { const base::NativeEvent& event) {
XEvent* xevent = event; XEvent* xevent = event;
if (xevent->type == KeyPress || xevent->type == KeyRelease) if (xevent->type == KeyPress || xevent->type == KeyRelease) {
Rewrite(xevent); Rewrite(xevent);
else if (xevent->type == GenericEvent) } else if (xevent->type == GenericEvent) {
RewriteLocatedEvent(xevent); RewriteLocatedEvent(xevent);
} else if (xevent->type == MappingNotify) {
if (xevent->xmapping.request == MappingModifier ||
xevent->xmapping.request == MappingKeyboard) {
RefreshKeycodes();
}
}
return base::EVENT_CONTINUE; return base::EVENT_CONTINUE;
} }
......
...@@ -15,24 +15,18 @@ ...@@ -15,24 +15,18 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_pump_observer.h" #include "base/message_loop/message_pump_observer.h"
#include "chrome/browser/chromeos/device_hierarchy_observer.h" #include "chrome/browser/chromeos/device_hierarchy_observer.h"
#include "ui/aura/window_tree_host_observer.h"
#include "ui/events/keycodes/keyboard_codes.h" #include "ui/events/keycodes/keyboard_codes.h"
class PrefService; class PrefService;
typedef union _XEvent XEvent; typedef union _XEvent XEvent;
namespace aura {
class RootWindow;
}
namespace chromeos { namespace chromeos {
class KeyboardDrivenEventRewriter; class KeyboardDrivenEventRewriter;
namespace input_method { namespace input_method {
class XKeyboard; class XKeyboard;
} }
class EventRewriter : public aura::WindowTreeHostObserver, class EventRewriter : public DeviceHierarchyObserver,
public DeviceHierarchyObserver,
public base::MessagePumpObserver { public base::MessagePumpObserver {
public: public:
enum DeviceType { enum DeviceType {
...@@ -69,10 +63,6 @@ class EventRewriter : public aura::WindowTreeHostObserver, ...@@ -69,10 +63,6 @@ class EventRewriter : public aura::WindowTreeHostObserver,
friend class EventRewriterAshTest; friend class EventRewriterAshTest;
friend class EventRewriterTest; friend class EventRewriterTest;
// aura::WindowTreeHostObserver overrides:
virtual void OnKeyboardMappingChanged(
const aura::WindowTreeHost* host) OVERRIDE;
// base::MessagePumpObserver overrides: // base::MessagePumpObserver overrides:
virtual base::EventStatus WillProcessEvent( virtual base::EventStatus WillProcessEvent(
const base::NativeEvent& event) OVERRIDE; const base::NativeEvent& event) OVERRIDE;
......
...@@ -290,11 +290,6 @@ void WindowTreeHost::OnHostCloseRequested() { ...@@ -290,11 +290,6 @@ void WindowTreeHost::OnHostCloseRequested() {
OnHostCloseRequested(this)); OnHostCloseRequested(this));
} }
void WindowTreeHost::OnKeyboardMappingChanged() {
FOR_EACH_OBSERVER(WindowTreeHostObserver, observers_,
OnKeyboardMappingChanged(this));
}
void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location, void WindowTreeHost::MoveCursorToInternal(const gfx::Point& root_location,
const gfx::Point& host_location) { const gfx::Point& host_location) {
MoveCursorToNative(host_location); MoveCursorToNative(host_location);
......
...@@ -185,7 +185,6 @@ class AURA_EXPORT WindowTreeHost { ...@@ -185,7 +185,6 @@ class AURA_EXPORT WindowTreeHost {
void OnHostMoved(const gfx::Point& new_location); void OnHostMoved(const gfx::Point& new_location);
void OnHostResized(const gfx::Size& new_size); void OnHostResized(const gfx::Size& new_size);
void OnHostCloseRequested(); void OnHostCloseRequested();
void OnKeyboardMappingChanged();
// Sets the currently displayed cursor. // Sets the currently displayed cursor.
virtual void SetCursorNative(gfx::NativeCursor cursor) = 0; virtual void SetCursorNative(gfx::NativeCursor cursor) = 0;
......
...@@ -27,9 +27,6 @@ class AURA_EXPORT WindowTreeHostObserver { ...@@ -27,9 +27,6 @@ class AURA_EXPORT WindowTreeHostObserver {
// Called when the native window system sends the host request to close. // Called when the native window system sends the host request to close.
virtual void OnHostCloseRequested(const WindowTreeHost* host) {} virtual void OnHostCloseRequested(const WindowTreeHost* host) {}
// Called when the keyboard mapping has changed.
virtual void OnKeyboardMappingChanged(const WindowTreeHost* host) {}
protected: protected:
virtual ~WindowTreeHostObserver() {} virtual ~WindowTreeHostObserver() {}
}; };
......
...@@ -487,7 +487,6 @@ uint32_t WindowTreeHostX11::Dispatch(const base::NativeEvent& event) { ...@@ -487,7 +487,6 @@ uint32_t WindowTreeHostX11::Dispatch(const base::NativeEvent& event) {
case MappingModifier: case MappingModifier:
case MappingKeyboard: case MappingKeyboard:
XRefreshKeyboardMapping(&xev->xmapping); XRefreshKeyboardMapping(&xev->xmapping);
OnKeyboardMappingChanged();
break; break;
case MappingPointer: case MappingPointer:
ui::DeviceDataManager::GetInstance()->UpdateButtonMap(); ui::DeviceDataManager::GetInstance()->UpdateButtonMap();
......
...@@ -1520,7 +1520,6 @@ uint32_t DesktopWindowTreeHostX11::Dispatch(const base::NativeEvent& event) { ...@@ -1520,7 +1520,6 @@ uint32_t DesktopWindowTreeHostX11::Dispatch(const base::NativeEvent& event) {
case MappingModifier: case MappingModifier:
case MappingKeyboard: case MappingKeyboard:
XRefreshKeyboardMapping(&xev->xmapping); XRefreshKeyboardMapping(&xev->xmapping);
OnKeyboardMappingChanged();
break; break;
case MappingPointer: case MappingPointer:
ui::DeviceDataManager::GetInstance()->UpdateButtonMap(); ui::DeviceDataManager::GetInstance()->UpdateButtonMap();
......
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