1 // Copyright 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ozone/ui/events/event_converter_in_process.h"
8 #include "ozone/ui/events/keyboard_code_conversion_ozone.h"
9 #include "ozone/ui/events/output_change_observer.h"
10 #include "ozone/ui/events/window_change_observer.h"
12 namespace ozonewayland {
14 EventConverterInProcess::EventConverterInProcess()
15 : EventConverterOzoneWayland(),
19 EventConverterInProcess::~EventConverterInProcess() {
22 void EventConverterInProcess::MotionNotify(float x, float y) {
23 gfx::Point position(x, y);
24 scoped_ptr<ui::MouseEvent> mouseev(new ui::MouseEvent(ui::ET_MOUSE_MOVED,
30 PostTaskOnMainLoop(base::Bind(
31 &EventConverterInProcess::DispatchEventHelper, base::Passed(
32 mouseev.PassAs<ui::Event>())));
35 void EventConverterInProcess::ButtonNotify(unsigned handle,
40 gfx::Point position(x, y);
41 scoped_ptr<ui::MouseEvent> mouseev(new ui::MouseEvent(type,
46 PostTaskOnMainLoop(base::Bind(
47 &EventConverterInProcess::DispatchEventHelper, base::Passed(
48 mouseev.PassAs<ui::Event>())));
50 if (type == ui::ET_MOUSE_RELEASED)
51 PostTaskOnMainLoop(base::Bind(
52 &EventConverterInProcess::NotifyButtonPress, this, handle));
55 void EventConverterInProcess::AxisNotify(float x,
59 gfx::Point position(x, y);
60 ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, position, position, 0, 0);
62 scoped_ptr<ui::MouseWheelEvent> wheelev(new ui::MouseWheelEvent(mouseev,
66 PostTaskOnMainLoop(base::Bind(
67 &EventConverterInProcess::DispatchEventHelper, base::Passed(
68 wheelev.PassAs<ui::Event>())));
71 void EventConverterInProcess::PointerEnter(unsigned handle,
74 gfx::Point position(x, y);
75 scoped_ptr<ui::MouseEvent> mouseev(new ui::MouseEvent(ui::ET_MOUSE_ENTERED,
80 PostTaskOnMainLoop(base::Bind(
81 &EventConverterInProcess::NotifyPointerEnter, this, handle));
83 PostTaskOnMainLoop(base::Bind(
84 &EventConverterInProcess::DispatchEventHelper, base::Passed(
85 mouseev.PassAs<ui::Event>())));
88 void EventConverterInProcess::PointerLeave(unsigned handle,
91 gfx::Point position(x, y);
92 scoped_ptr<ui::MouseEvent> mouseev(new ui::MouseEvent(ui::ET_MOUSE_EXITED,
98 PostTaskOnMainLoop(base::Bind(
99 &EventConverterInProcess::NotifyPointerLeave, this, handle));
101 PostTaskOnMainLoop(base::Bind(
102 &EventConverterInProcess::DispatchEventHelper, base::Passed(
103 mouseev.PassAs<ui::Event>())));
106 void EventConverterInProcess::KeyNotify(ui::EventType type,
108 unsigned modifiers) {
109 scoped_ptr<ui::KeyEvent> keyev(new ui::KeyEvent(type,
110 KeyboardCodeFromNativeKeysym(code), modifiers, true));
112 keyev.get()->set_character(CharacterCodeFromNativeKeySym(code, modifiers));
114 PostTaskOnMainLoop(base::Bind(
115 &EventConverterInProcess::DispatchEventHelper, base::Passed(
116 keyev.PassAs<ui::Event>())));
119 void EventConverterInProcess::CloseWidget(unsigned handle) {
120 PostTaskOnMainLoop(base::Bind(
121 &EventConverterInProcess::NotifyCloseWidget, this, handle));
124 void EventConverterInProcess::OutputSizeChanged(unsigned width,
126 PostTaskOnMainLoop(base::Bind(
127 &EventConverterInProcess::NotifyOutputSizeChanged, this, width, height));
130 void EventConverterInProcess::WindowResized(unsigned handle,
133 PostTaskOnMainLoop(base::Bind(
134 &EventConverterInProcess::NotifyWindowResized, this, handle, width,
138 void EventConverterInProcess::SetWindowChangeObserver(
139 WindowChangeObserver* observer) {
140 observer_ = observer;
143 void EventConverterInProcess::SetOutputChangeObserver(
144 OutputChangeObserver* observer) {
145 output_observer_ = observer;
148 void EventConverterInProcess::NotifyPointerEnter(
149 EventConverterInProcess* data, unsigned handle) {
151 data->observer_->OnWindowEnter(handle);
154 void EventConverterInProcess::NotifyPointerLeave(
155 EventConverterInProcess* data, unsigned handle) {
157 data->observer_->OnWindowLeave(handle);
160 void EventConverterInProcess::NotifyButtonPress(
161 EventConverterInProcess* data, unsigned handle) {
163 data->observer_->OnWindowFocused(handle);
166 void EventConverterInProcess::NotifyCloseWidget(
167 EventConverterInProcess* data, unsigned handle) {
169 data->observer_->OnWindowClose(handle);
173 EventConverterInProcess::NotifyOutputSizeChanged(EventConverterInProcess* data,
176 if (data->output_observer_)
177 data->output_observer_->OnOutputSizeChanged(width, height);
181 EventConverterInProcess::NotifyWindowResized(EventConverterInProcess* data,
186 data->observer_->OnWindowResized(handle, width, height);
189 void EventConverterInProcess::DispatchEventHelper(
190 scoped_ptr<ui::Event> key) {
191 base::MessagePumpOzone::Current()->Dispatch(key.get());
194 } // namespace ozonewayland