Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ozone / content / 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/content/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 content {
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::SetWindowChangeObserver(
98     ui::WindowChangeObserver* observer) {
99   observer_ = observer;
100 }
101
102 void EventConverterInProcess::SetOutputChangeObserver(
103     ui::OutputChangeObserver* observer) {
104   output_observer_ = observer;
105 }
106
107 void EventConverterInProcess::SetDispatchCallback(
108     base::Callback<void(void*)> callback) {  // NOLINT(readability/function))
109   dispatch_callback_ = callback;
110 }
111
112 void EventConverterInProcess::NotifyMotion(EventConverterInProcess* data,
113                                            float x,
114                                            float y) {
115   gfx::Point position(x, y);
116   ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED,
117                          position,
118                          position,
119                          0,
120                          0);
121   data->dispatch_callback_.Run(&mouseev);
122 }
123
124 void EventConverterInProcess::NotifyButtonPress(EventConverterInProcess* data,
125                                                 unsigned handle,
126                                                 ui::EventType type,
127                                                 ui::EventFlags flags,
128                                                 float x,
129                                                 float y) {
130     gfx::Point position(x, y);
131     ui::MouseEvent mouseev(type,
132                            position,
133                            position,
134                            flags,
135                            1);
136     data->dispatch_callback_.Run(&mouseev);
137
138     if (type == ui::ET_MOUSE_RELEASED && data->observer_)
139       data->observer_->OnWindowFocused(handle);
140 }
141
142 void EventConverterInProcess::NotifyAxis(EventConverterInProcess* data,
143                                          float x,
144                                          float y,
145                                          int xoffset,
146                                          int yoffset) {
147   gfx::Point position(x, y);
148   ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, position, position, 0, 0);
149   ui::MouseWheelEvent wheelev(mouseev, xoffset, yoffset);
150
151   data->dispatch_callback_.Run(&wheelev);
152 }
153
154 void EventConverterInProcess::NotifyPointerEnter(
155     EventConverterInProcess* data, unsigned handle, float x, float y) {
156   if (data->observer_)
157     data->observer_->OnWindowEnter(handle);
158
159   gfx::Point position(x, y);
160   ui::MouseEvent mouseev(ui::ET_MOUSE_ENTERED, position, position, 0, 0);
161   data->dispatch_callback_.Run(&mouseev);
162 }
163
164 void EventConverterInProcess::NotifyPointerLeave(
165     EventConverterInProcess* data, unsigned handle, float x, float y) {
166   if (data->observer_)
167     data->observer_->OnWindowLeave(handle);
168
169   gfx::Point position(x, y);
170   ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, position, position, 0, 0);
171   data->dispatch_callback_.Run(&mouseev);
172 }
173
174 void EventConverterInProcess::NotifyKeyEvent(EventConverterInProcess* data,
175                                              ui::EventType type,
176                                              ui::KeyboardCode code,
177                                              uint16 CharacterCodeFromNativeKey,
178                                              unsigned modifiers) {
179   ui::KeyEvent keyev(type, code, modifiers, true);
180   keyev.set_character(CharacterCodeFromNativeKey);
181   data->dispatch_callback_.Run(&keyev);
182 }
183
184 void EventConverterInProcess::NotifyTouchEvent(EventConverterInProcess* data,
185                                                ui::EventType type,
186                                                float x,
187                                                float y,
188                                                int32_t touch_id,
189                                                uint32_t time_stamp) {
190   gfx::Point position(x, y);
191   base::TimeDelta time_delta = base::TimeDelta::FromMilliseconds(time_stamp);
192   ui::TouchEvent touchev(type, position, touch_id, time_delta);
193   data->dispatch_callback_.Run(&touchev);
194 }
195
196 void EventConverterInProcess::NotifyCloseWidget(
197     EventConverterInProcess* data, unsigned handle) {
198   if (data->observer_)
199     data->observer_->OnWindowClose(handle);
200 }
201
202 void
203 EventConverterInProcess::NotifyOutputSizeChanged(EventConverterInProcess* data,
204                                                  unsigned width,
205                                                  unsigned height) {
206   if (data->output_observer_)
207     data->output_observer_->OnOutputSizeChanged(width, height);
208 }
209
210 void
211 EventConverterInProcess::NotifyWindowResized(EventConverterInProcess* data,
212                                              unsigned handle,
213                                              unsigned width,
214                                              unsigned height) {
215   if (data->observer_)
216     data->observer_->OnWindowResized(handle, width, height);
217 }
218
219 }  // namespace content