af563ede5d1d8336778d678d89ec3906de3ae1f8
[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::Commit(unsigned handle, const std::string& text) {
98   ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
99       &EventConverterInProcess::NotifyCommit, this, handle, text));
100 }
101
102 void EventConverterInProcess::PreeditChanged(unsigned handle,
103                                              const std::string& text,
104                                              const std::string& commit) {
105   ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
106       &EventConverterInProcess::NotifyPreeditChanged, this, handle, text,
107       commit));
108 }
109
110 void EventConverterInProcess::PreeditEnd() {
111   ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
112         &EventConverterInProcess::NotifyPreeditEnd, this));
113 }
114
115 void EventConverterInProcess::PreeditStart() {
116     ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
117         &EventConverterInProcess::NotifyPreeditStart, this));
118 }
119
120 void EventConverterInProcess::SetWindowChangeObserver(
121     ui::WindowChangeObserver* observer) {
122   observer_ = observer;
123 }
124
125 void EventConverterInProcess::SetOutputChangeObserver(
126     ui::OutputChangeObserver* observer) {
127   output_observer_ = observer;
128 }
129
130 void EventConverterInProcess::OnDispatcherListChanged() {
131   if (!loop_)
132     loop_ = base::MessageLoop::current();
133 }
134
135 void EventConverterInProcess::NotifyMotion(EventConverterInProcess* data,
136                                            float x,
137                                            float y) {
138   gfx::Point position(x, y);
139   ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED,
140                          position,
141                          position,
142                          0,
143                          0);
144   data->DispatchEvent(&mouseev);
145 }
146
147 void EventConverterInProcess::NotifyButtonPress(EventConverterInProcess* data,
148                                                 unsigned handle,
149                                                 ui::EventType type,
150                                                 ui::EventFlags flags,
151                                                 float x,
152                                                 float y) {
153     gfx::Point position(x, y);
154     ui::MouseEvent mouseev(type,
155                            position,
156                            position,
157                            flags,
158                            1);
159     data->DispatchEvent(&mouseev);
160
161     if (type == ui::ET_MOUSE_RELEASED && data->observer_)
162       data->observer_->OnWindowFocused(handle);
163 }
164
165 void EventConverterInProcess::NotifyAxis(EventConverterInProcess* data,
166                                          float x,
167                                          float y,
168                                          int xoffset,
169                                          int yoffset) {
170   gfx::Point position(x, y);
171   ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, position, position, 0, 0);
172   ui::MouseWheelEvent wheelev(mouseev, xoffset, yoffset);
173
174   data->DispatchEvent(&wheelev);
175 }
176
177 void EventConverterInProcess::NotifyPointerEnter(
178     EventConverterInProcess* data, unsigned handle, float x, float y) {
179   if (data->observer_)
180     data->observer_->OnWindowEnter(handle);
181
182   gfx::Point position(x, y);
183   ui::MouseEvent mouseev(ui::ET_MOUSE_ENTERED, position, position, 0, 0);
184   data->DispatchEvent(&mouseev);
185 }
186
187 void EventConverterInProcess::NotifyPointerLeave(
188     EventConverterInProcess* data, unsigned handle, float x, float y) {
189   if (data->observer_)
190     data->observer_->OnWindowLeave(handle);
191
192   gfx::Point position(x, y);
193   ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, position, position, 0, 0);
194   data->DispatchEvent(&mouseev);
195 }
196
197 void EventConverterInProcess::NotifyKeyEvent(EventConverterInProcess* data,
198                                              ui::EventType type,
199                                              ui::KeyboardCode code,
200                                              uint16 CharacterCodeFromNativeKey,
201                                              unsigned modifiers) {
202   ui::KeyEvent keyev(type, code, modifiers);
203   keyev.set_character(CharacterCodeFromNativeKey);
204   data->DispatchEvent(&keyev);
205 }
206
207 void EventConverterInProcess::NotifyTouchEvent(EventConverterInProcess* data,
208                                                ui::EventType type,
209                                                float x,
210                                                float y,
211                                                int32_t touch_id,
212                                                uint32_t time_stamp) {
213   gfx::Point position(x, y);
214   base::TimeDelta time_delta = base::TimeDelta::FromMilliseconds(time_stamp);
215   ui::TouchEvent touchev(type, position, touch_id, time_delta);
216   data->DispatchEvent(&touchev);
217 }
218
219 void EventConverterInProcess::NotifyCloseWidget(
220     EventConverterInProcess* data, unsigned handle) {
221   if (data->observer_)
222     data->observer_->OnWindowClose(handle);
223 }
224
225 void
226 EventConverterInProcess::NotifyOutputSizeChanged(EventConverterInProcess* data,
227                                                  unsigned width,
228                                                  unsigned height) {
229   if (data->output_observer_)
230     data->output_observer_->OnOutputSizeChanged(width, height);
231 }
232
233 void
234 EventConverterInProcess::NotifyWindowResized(EventConverterInProcess* data,
235                                              unsigned handle,
236                                              unsigned width,
237                                              unsigned height) {
238   if (data->observer_)
239     data->observer_->OnWindowResized(handle, width, height);
240 }
241
242 void
243 EventConverterInProcess::NotifyCommit(EventConverterInProcess* data,
244                                       unsigned handle,
245                                       const std::string& text) {
246   if (data->observer_)
247     data->observer_->OnCommit(handle, text);
248 }
249
250 void
251 EventConverterInProcess::NotifyPreeditChanged(EventConverterInProcess* data,
252                                               unsigned handle,
253                                               const std::string& text,
254                                               const std::string& commit) {
255   if (data->observer_)
256     data->observer_->OnPreeditChanged(handle, text, commit);
257 }
258
259 void
260 EventConverterInProcess::NotifyPreeditEnd(EventConverterInProcess* data) {
261 }
262
263 void
264 EventConverterInProcess::NotifyPreeditStart(EventConverterInProcess* data) {
265 }
266
267 }  // namespace ui