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/keyboard_code_conversion_ozone.h"
9 #include "ozone/ui/events/output_change_observer.h"
10 #include "ozone/ui/events/window_change_observer.h"
14 EventConverterInProcess::EventConverterInProcess()
15 : EventConverterOzoneWayland(),
17 output_observer_(NULL) {
20 EventConverterInProcess::~EventConverterInProcess() {
23 void EventConverterInProcess::MotionNotify(float x, float y) {
24 gfx::Point position(x, y);
25 scoped_ptr<ui::MouseEvent> mouseev(new ui::MouseEvent(ui::ET_MOUSE_MOVED,
31 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
32 &EventConverterInProcess::DispatchEventHelper, base::Passed(
33 mouseev.PassAs<ui::Event>())));
36 void EventConverterInProcess::ButtonNotify(unsigned handle,
41 gfx::Point position(x, y);
42 scoped_ptr<ui::MouseEvent> mouseev(new ui::MouseEvent(type,
47 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
48 &EventConverterInProcess::DispatchEventHelper, base::Passed(
49 mouseev.PassAs<ui::Event>())));
51 if (type == ui::ET_MOUSE_RELEASED)
52 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
53 &EventConverterInProcess::NotifyButtonPress, this, handle));
56 void EventConverterInProcess::AxisNotify(float x,
60 gfx::Point position(x, y);
61 ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, position, position, 0, 0);
63 scoped_ptr<ui::MouseWheelEvent> wheelev(new ui::MouseWheelEvent(mouseev,
67 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
68 &EventConverterInProcess::DispatchEventHelper, base::Passed(
69 wheelev.PassAs<ui::Event>())));
72 void EventConverterInProcess::PointerEnter(unsigned handle,
75 gfx::Point position(x, y);
76 scoped_ptr<ui::MouseEvent> mouseev(new ui::MouseEvent(ui::ET_MOUSE_ENTERED,
81 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
82 &EventConverterInProcess::NotifyPointerEnter, this, handle));
84 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
85 &EventConverterInProcess::DispatchEventHelper, base::Passed(
86 mouseev.PassAs<ui::Event>())));
89 void EventConverterInProcess::PointerLeave(unsigned handle,
92 gfx::Point position(x, y);
93 scoped_ptr<ui::MouseEvent> mouseev(new ui::MouseEvent(ui::ET_MOUSE_EXITED,
99 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
100 &EventConverterInProcess::NotifyPointerLeave, this, handle));
102 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
103 &EventConverterInProcess::DispatchEventHelper, base::Passed(
104 mouseev.PassAs<ui::Event>())));
107 void EventConverterInProcess::KeyNotify(ui::EventType type,
109 unsigned modifiers) {
110 scoped_ptr<ui::KeyEvent> keyev(new ui::KeyEvent(type,
111 ui::KeyboardCodeFromNativeKeysym(code), modifiers, true));
113 keyev.get()->set_character(
114 ui::CharacterCodeFromNativeKeySym(code, modifiers));
116 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
117 &EventConverterInProcess::DispatchEventHelper, base::Passed(
118 keyev.PassAs<ui::Event>())));
121 void EventConverterInProcess::TouchNotify(ui::EventType type,
125 uint32_t time_stamp) {
126 gfx::Point position(x, y);
127 base::TimeDelta time_delta = base::TimeDelta::FromMilliseconds(time_stamp);
128 scoped_ptr<ui::TouchEvent> touchev(new ui::TouchEvent(type,
133 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
134 &EventConverterInProcess::DispatchEventHelper, base::Passed(
135 touchev.PassAs<ui::Event>())));
138 void EventConverterInProcess::CloseWidget(unsigned handle) {
139 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
140 &EventConverterInProcess::NotifyCloseWidget, this, handle));
143 void EventConverterInProcess::OutputSizeChanged(unsigned width,
145 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
146 &EventConverterInProcess::NotifyOutputSizeChanged, this, width, height));
149 void EventConverterInProcess::WindowResized(unsigned handle,
152 ui::EventConverterOzoneWayland::PostTaskOnMainLoop(base::Bind(
153 &EventConverterInProcess::NotifyWindowResized, this, handle, width,
157 void EventConverterInProcess::SetWindowChangeObserver(
158 ui::WindowChangeObserver* observer) {
159 observer_ = observer;
162 void EventConverterInProcess::SetOutputChangeObserver(
163 ui::OutputChangeObserver* observer) {
164 output_observer_ = observer;
167 void EventConverterInProcess::NotifyPointerEnter(
168 EventConverterInProcess* data, unsigned handle) {
170 data->observer_->OnWindowEnter(handle);
173 void EventConverterInProcess::NotifyPointerLeave(
174 EventConverterInProcess* data, unsigned handle) {
176 data->observer_->OnWindowLeave(handle);
179 void EventConverterInProcess::NotifyButtonPress(
180 EventConverterInProcess* data, unsigned handle) {
182 data->observer_->OnWindowFocused(handle);
185 void EventConverterInProcess::NotifyCloseWidget(
186 EventConverterInProcess* data, unsigned handle) {
188 data->observer_->OnWindowClose(handle);
192 EventConverterInProcess::NotifyOutputSizeChanged(EventConverterInProcess* data,
195 if (data->output_observer_)
196 data->output_observer_->OnOutputSizeChanged(width, height);
200 EventConverterInProcess::NotifyWindowResized(EventConverterInProcess* data,
205 data->observer_->OnWindowResized(handle, width, height);
208 void EventConverterInProcess::DispatchEventHelper(
209 scoped_ptr<ui::Event> key) {
210 base::MessagePumpOzone::Current()->Dispatch(key.get());
213 } // namespace content