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/output_change_observer.h"
9 #include "ozone/ui/events/window_change_observer.h"
13 EventConverterInProcess::EventConverterInProcess()
14 : EventConverterOzoneWayland(),
16 output_observer_(NULL) {
19 EventConverterInProcess::~EventConverterInProcess() {
22 void EventConverterInProcess::MotionNotify(float x, float y) {
23 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
24 &EventConverterInProcess::NotifyMotion, this, x, y));
27 void EventConverterInProcess::ButtonNotify(unsigned handle,
32 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
33 &EventConverterInProcess::NotifyButtonPress, this, handle, type,
37 void EventConverterInProcess::AxisNotify(float x,
41 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
42 &EventConverterInProcess::NotifyAxis, this, x, y, xoffset, yoffset));
45 void EventConverterInProcess::PointerEnter(unsigned handle,
48 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
49 &EventConverterInProcess::NotifyPointerEnter, this, handle, x, y));
52 void EventConverterInProcess::PointerLeave(unsigned handle,
55 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
56 &EventConverterInProcess::NotifyPointerLeave, this, handle, x, y));
59 void EventConverterInProcess::KeyNotify(ui::EventType type,
62 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
63 &EventConverterInProcess::NotifyKeyEvent, this, type,
64 ui::KeyboardCodeFromNativeKeysym(code),
65 ui::CharacterCodeFromNativeKeySym(code, modifiers), modifiers));
68 void EventConverterInProcess::TouchNotify(ui::EventType type,
72 uint32_t time_stamp) {
73 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
74 &EventConverterInProcess::NotifyTouchEvent, this, type, x, y, touch_id,
78 void EventConverterInProcess::CloseWidget(unsigned handle) {
79 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
80 &EventConverterInProcess::NotifyCloseWidget, this, handle));
83 void EventConverterInProcess::OutputSizeChanged(unsigned width,
85 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
86 &EventConverterInProcess::NotifyOutputSizeChanged, this, width, height));
89 void EventConverterInProcess::WindowResized(unsigned handle,
92 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
93 &EventConverterInProcess::NotifyWindowResized, this, handle, width,
97 void EventConverterInProcess::WindowUnminimized(unsigned handle) {
98 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
99 &EventConverterInProcess::NotifyWindowUnminimized, this, handle));
102 void EventConverterInProcess::Commit(unsigned handle, const std::string& text) {
103 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
104 &EventConverterInProcess::NotifyCommit, this, handle, text));
107 void EventConverterInProcess::PreeditChanged(unsigned handle,
108 const std::string& text,
109 const std::string& commit) {
110 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
111 &EventConverterInProcess::NotifyPreeditChanged, this, handle, text,
115 void EventConverterInProcess::PreeditEnd() {
116 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
117 &EventConverterInProcess::NotifyPreeditEnd, this));
120 void EventConverterInProcess::PreeditStart() {
121 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
122 &EventConverterInProcess::NotifyPreeditStart, this));
125 void EventConverterInProcess::SetWindowChangeObserver(
126 ui::WindowChangeObserver* observer) {
127 observer_ = observer;
130 void EventConverterInProcess::SetOutputChangeObserver(
131 ui::OutputChangeObserver* observer) {
132 output_observer_ = observer;
135 void EventConverterInProcess::OnDispatcherListChanged() {
137 loop_ = base::MessageLoop::current();
140 void EventConverterInProcess::NotifyMotion(EventConverterInProcess* data,
143 gfx::Point position(x, y);
144 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED,
149 data->DispatchEvent(&mouseev);
152 void EventConverterInProcess::NotifyButtonPress(EventConverterInProcess* data,
155 ui::EventFlags flags,
158 gfx::Point position(x, y);
159 ui::MouseEvent mouseev(type,
164 data->DispatchEvent(&mouseev);
166 if (type == ui::ET_MOUSE_RELEASED && data->observer_)
167 data->observer_->OnWindowFocused(handle);
170 void EventConverterInProcess::NotifyAxis(EventConverterInProcess* data,
175 gfx::Point position(x, y);
176 ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, position, position, 0, 0);
177 ui::MouseWheelEvent wheelev(mouseev, xoffset, yoffset);
179 data->DispatchEvent(&wheelev);
182 void EventConverterInProcess::NotifyPointerEnter(
183 EventConverterInProcess* data, unsigned handle, float x, float y) {
185 data->observer_->OnWindowEnter(handle);
187 gfx::Point position(x, y);
188 ui::MouseEvent mouseev(ui::ET_MOUSE_ENTERED, position, position, 0, 0);
189 data->DispatchEvent(&mouseev);
192 void EventConverterInProcess::NotifyPointerLeave(
193 EventConverterInProcess* data, unsigned handle, float x, float y) {
195 data->observer_->OnWindowLeave(handle);
197 gfx::Point position(x, y);
198 ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, position, position, 0, 0);
199 data->DispatchEvent(&mouseev);
202 void EventConverterInProcess::NotifyKeyEvent(EventConverterInProcess* data,
204 ui::KeyboardCode code,
205 uint16 CharacterCodeFromNativeKey,
206 unsigned modifiers) {
207 ui::KeyEvent keyev(type, code, modifiers);
208 keyev.set_character(CharacterCodeFromNativeKey);
209 data->DispatchEvent(&keyev);
212 void EventConverterInProcess::NotifyTouchEvent(EventConverterInProcess* data,
217 uint32_t time_stamp) {
218 gfx::Point position(x, y);
219 base::TimeDelta time_delta = base::TimeDelta::FromMilliseconds(time_stamp);
220 ui::TouchEvent touchev(type, position, touch_id, time_delta);
221 data->DispatchEvent(&touchev);
224 void EventConverterInProcess::NotifyCloseWidget(
225 EventConverterInProcess* data, unsigned handle) {
227 data->observer_->OnWindowClose(handle);
231 EventConverterInProcess::NotifyOutputSizeChanged(EventConverterInProcess* data,
234 if (data->output_observer_)
235 data->output_observer_->OnOutputSizeChanged(width, height);
239 EventConverterInProcess::NotifyWindowResized(EventConverterInProcess* data,
244 data->observer_->OnWindowResized(handle, width, height);
248 EventConverterInProcess::NotifyWindowUnminimized(EventConverterInProcess* data,
251 data->observer_->OnWindowUnminimized(handle);
255 EventConverterInProcess::NotifyCommit(EventConverterInProcess* data,
257 const std::string& text) {
259 data->observer_->OnCommit(handle, text);
263 EventConverterInProcess::NotifyPreeditChanged(EventConverterInProcess* data,
265 const std::string& text,
266 const std::string& commit) {
268 data->observer_->OnPreeditChanged(handle, text, commit);
272 EventConverterInProcess::NotifyPreeditEnd(EventConverterInProcess* data) {
276 EventConverterInProcess::NotifyPreeditStart(EventConverterInProcess* data) {