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/content/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::SetWindowChangeObserver(
98 ui::WindowChangeObserver* observer) {
102 void EventConverterInProcess::SetOutputChangeObserver(
103 ui::OutputChangeObserver* observer) {
104 output_observer_ = observer;
107 void EventConverterInProcess::SetDispatchCallback(
108 base::Callback<void(void*)> callback) { // NOLINT(readability/function))
109 dispatch_callback_ = callback;
112 void EventConverterInProcess::NotifyMotion(EventConverterInProcess* data,
115 gfx::Point position(x, y);
116 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED,
121 data->dispatch_callback_.Run(&mouseev);
124 void EventConverterInProcess::NotifyButtonPress(EventConverterInProcess* data,
127 ui::EventFlags flags,
130 gfx::Point position(x, y);
131 ui::MouseEvent mouseev(type,
136 data->dispatch_callback_.Run(&mouseev);
138 if (type == ui::ET_MOUSE_RELEASED && data->observer_)
139 data->observer_->OnWindowFocused(handle);
142 void EventConverterInProcess::NotifyAxis(EventConverterInProcess* data,
147 gfx::Point position(x, y);
148 ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, position, position, 0, 0);
149 ui::MouseWheelEvent wheelev(mouseev, xoffset, yoffset);
151 data->dispatch_callback_.Run(&wheelev);
154 void EventConverterInProcess::NotifyPointerEnter(
155 EventConverterInProcess* data, unsigned handle, float x, float y) {
157 data->observer_->OnWindowEnter(handle);
159 gfx::Point position(x, y);
160 ui::MouseEvent mouseev(ui::ET_MOUSE_ENTERED, position, position, 0, 0);
161 data->dispatch_callback_.Run(&mouseev);
164 void EventConverterInProcess::NotifyPointerLeave(
165 EventConverterInProcess* data, unsigned handle, float x, float y) {
167 data->observer_->OnWindowLeave(handle);
169 gfx::Point position(x, y);
170 ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, position, position, 0, 0);
171 data->dispatch_callback_.Run(&mouseev);
174 void EventConverterInProcess::NotifyKeyEvent(EventConverterInProcess* data,
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);
184 void EventConverterInProcess::NotifyTouchEvent(EventConverterInProcess* data,
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);
196 void EventConverterInProcess::NotifyCloseWidget(
197 EventConverterInProcess* data, unsigned handle) {
199 data->observer_->OnWindowClose(handle);
203 EventConverterInProcess::NotifyOutputSizeChanged(EventConverterInProcess* data,
206 if (data->output_observer_)
207 data->output_observer_->OnOutputSizeChanged(width, height);
211 EventConverterInProcess::NotifyWindowResized(EventConverterInProcess* data,
216 data->observer_->OnWindowResized(handle, width, height);
219 } // namespace content