Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / ozone / ui / events / event_converter_in_process.cc
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.
4
5 #include "ozone/ui/events/event_converter_in_process.h"
6
7 #include "base/bind.h"
8 #include "ozone/ui/events/output_change_observer.h"
9 #include "ozone/ui/events/window_change_observer.h"
10
11 namespace ui {
12
13 EventConverterInProcess::EventConverterInProcess()
14     : EventConverterOzoneWayland(),
15       observer_(NULL),
16       output_observer_(NULL) {
17 }
18
19 EventConverterInProcess::~EventConverterInProcess() {
20 }
21
22 void EventConverterInProcess::MotionNotify(float x, float y) {
23   ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
24       &EventConverterInProcess::NotifyMotion, this, x, y));
25 }
26
27 void EventConverterInProcess::ButtonNotify(unsigned handle,
28                                            ui::EventType type,
29                                            ui::EventFlags flags,
30                                            float x,
31                                            float y) {
32   ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
33       &EventConverterInProcess::NotifyButtonPress, this, handle, type,
34           flags, x, y));
35 }
36
37 void EventConverterInProcess::AxisNotify(float x,
38                                          float y,
39                                          int xoffset,
40                                          int yoffset) {
41   ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
42       &EventConverterInProcess::NotifyAxis, this, x, y, xoffset, yoffset));
43 }
44
45 void EventConverterInProcess::PointerEnter(unsigned handle,
46                                            float x,
47                                            float y) {
48   ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
49       &EventConverterInProcess::NotifyPointerEnter, this, handle, x, y));
50 }
51
52 void EventConverterInProcess::PointerLeave(unsigned handle,
53                                            float x,
54                                            float y) {
55   ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
56       &EventConverterInProcess::NotifyPointerLeave, this, handle, x, y));
57 }
58
59 void EventConverterInProcess::KeyNotify(ui::EventType type,
60                                         unsigned code,
61                                         unsigned modifiers) {
62   ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
63       &EventConverterInProcess::NotifyKeyEvent, this, type,
64           ui::KeyboardCodeFromNativeKeysym(code),
65               ui::CharacterCodeFromNativeKeySym(code, modifiers), modifiers));
66 }
67
68 void EventConverterInProcess::TouchNotify(ui::EventType type,
69                                           float x,
70                                           float y,
71                                           int32_t touch_id,
72                                           uint32_t time_stamp) {
73   ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
74       &EventConverterInProcess::NotifyTouchEvent, this, type, x, y, touch_id,
75           time_stamp));
76 }
77
78 void EventConverterInProcess::CloseWidget(unsigned handle) {
79   ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
80       &EventConverterInProcess::NotifyCloseWidget, this, handle));
81 }
82
83 void EventConverterInProcess::OutputSizeChanged(unsigned width,
84                                                 unsigned height) {
85   ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
86       &EventConverterInProcess::NotifyOutputSizeChanged, this, width, height));
87 }
88
89 void EventConverterInProcess::WindowResized(unsigned handle,
90                                             unsigned width,
91                                             unsigned height) {
92   ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
93       &EventConverterInProcess::NotifyWindowResized, this, handle, width,
94           height));
95 }
96
97 void EventConverterInProcess::WindowUnminimized(unsigned handle) {
98   ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
99       &EventConverterInProcess::NotifyWindowUnminimized, this, handle));
100 }
101
102 void EventConverterInProcess::Commit(unsigned handle, const std::string& text) {
103   ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
104       &EventConverterInProcess::NotifyCommit, this, handle, text));
105 }
106
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,
112       commit));
113 }
114
115 void EventConverterInProcess::PreeditEnd() {
116   ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
117         &EventConverterInProcess::NotifyPreeditEnd, this));
118 }
119
120 void EventConverterInProcess::PreeditStart() {
121     ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
122         &EventConverterInProcess::NotifyPreeditStart, this));
123 }
124
125 void EventConverterInProcess::SetWindowChangeObserver(
126     ui::WindowChangeObserver* observer) {
127   observer_ = observer;
128 }
129
130 void EventConverterInProcess::SetOutputChangeObserver(
131     ui::OutputChangeObserver* observer) {
132   output_observer_ = observer;
133 }
134
135 void EventConverterInProcess::OnDispatcherListChanged() {
136   if (!loop_)
137     loop_ = base::MessageLoop::current();
138 }
139
140 void EventConverterInProcess::NotifyMotion(EventConverterInProcess* data,
141                                            float x,
142                                            float y) {
143   gfx::Point position(x, y);
144   ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED,
145                          position,
146                          position,
147                          0,
148                          0);
149   data->DispatchEvent(&mouseev);
150 }
151
152 void EventConverterInProcess::NotifyButtonPress(EventConverterInProcess* data,
153                                                 unsigned handle,
154                                                 ui::EventType type,
155                                                 ui::EventFlags flags,
156                                                 float x,
157                                                 float y) {
158     gfx::Point position(x, y);
159     ui::MouseEvent mouseev(type,
160                            position,
161                            position,
162                            flags,
163                            flags);
164     data->DispatchEvent(&mouseev);
165
166     if (type == ui::ET_MOUSE_RELEASED && data->observer_)
167       data->observer_->OnWindowFocused(handle);
168 }
169
170 void EventConverterInProcess::NotifyAxis(EventConverterInProcess* data,
171                                          float x,
172                                          float y,
173                                          int xoffset,
174                                          int yoffset) {
175   gfx::Point position(x, y);
176   ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, position, position, 0, 0);
177   ui::MouseWheelEvent wheelev(mouseev, xoffset, yoffset);
178
179   data->DispatchEvent(&wheelev);
180 }
181
182 void EventConverterInProcess::NotifyPointerEnter(
183     EventConverterInProcess* data, unsigned handle, float x, float y) {
184   if (data->observer_)
185     data->observer_->OnWindowEnter(handle);
186
187   gfx::Point position(x, y);
188   ui::MouseEvent mouseev(ui::ET_MOUSE_ENTERED, position, position, 0, 0);
189   data->DispatchEvent(&mouseev);
190 }
191
192 void EventConverterInProcess::NotifyPointerLeave(
193     EventConverterInProcess* data, unsigned handle, float x, float y) {
194   if (data->observer_)
195     data->observer_->OnWindowLeave(handle);
196
197   gfx::Point position(x, y);
198   ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, position, position, 0, 0);
199   data->DispatchEvent(&mouseev);
200 }
201
202 void EventConverterInProcess::NotifyKeyEvent(EventConverterInProcess* data,
203                                              ui::EventType type,
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);
210 }
211
212 void EventConverterInProcess::NotifyTouchEvent(EventConverterInProcess* data,
213                                                ui::EventType type,
214                                                float x,
215                                                float y,
216                                                int32_t touch_id,
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);
222 }
223
224 void EventConverterInProcess::NotifyCloseWidget(
225     EventConverterInProcess* data, unsigned handle) {
226   if (data->observer_)
227     data->observer_->OnWindowClose(handle);
228 }
229
230 void
231 EventConverterInProcess::NotifyOutputSizeChanged(EventConverterInProcess* data,
232                                                  unsigned width,
233                                                  unsigned height) {
234   if (data->output_observer_)
235     data->output_observer_->OnOutputSizeChanged(width, height);
236 }
237
238 void
239 EventConverterInProcess::NotifyWindowResized(EventConverterInProcess* data,
240                                              unsigned handle,
241                                              unsigned width,
242                                              unsigned height) {
243   if (data->observer_)
244     data->observer_->OnWindowResized(handle, width, height);
245 }
246
247 void
248 EventConverterInProcess::NotifyWindowUnminimized(EventConverterInProcess* data,
249                                                  unsigned handle) {
250   if (data->observer_)
251     data->observer_->OnWindowUnminimized(handle);
252 }
253
254 void
255 EventConverterInProcess::NotifyCommit(EventConverterInProcess* data,
256                                       unsigned handle,
257                                       const std::string& text) {
258   if (data->observer_)
259     data->observer_->OnCommit(handle, text);
260 }
261
262 void
263 EventConverterInProcess::NotifyPreeditChanged(EventConverterInProcess* data,
264                                               unsigned handle,
265                                               const std::string& text,
266                                               const std::string& commit) {
267   if (data->observer_)
268     data->observer_->OnPreeditChanged(handle, text, commit);
269 }
270
271 void
272 EventConverterInProcess::NotifyPreeditEnd(EventConverterInProcess* data) {
273 }
274
275 void
276 EventConverterInProcess::NotifyPreeditStart(EventConverterInProcess* data) {
277 }
278
279 }  // namespace ui