- add sources.
[platform/framework/web/crosswalk.git] / src / ozone / impl / ipc / browser_process_dispatcher_delegate.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/impl/ipc/browser_process_dispatcher_delegate.h"
6
7 #include "base/bind.h"
8 #include "ozone/wayland/input/kbd_conversion.h"
9 #include "ozone/wayland/window_change_observer.h"
10
11 namespace ozonewayland {
12
13 BrowserProcessDispatcherDelegate::BrowserProcessDispatcherDelegate()
14     : WaylandDispatcherDelegate(),
15       observer_(NULL) {
16 }
17
18 BrowserProcessDispatcherDelegate::~BrowserProcessDispatcherDelegate() {
19 }
20
21 void BrowserProcessDispatcherDelegate::MotionNotify(float x, float y) {
22   gfx::Point position = gfx::Point(x, y);
23   scoped_ptr<ui::MouseEvent> mouseev(new ui::MouseEvent(ui::ET_MOUSE_MOVED,
24                                                         position,
25                                                         position,
26                                                         0));
27
28   PostTaskOnMainLoop(base::Bind(
29       &BrowserProcessDispatcherDelegate::DispatchEventHelper, base::Passed(
30           mouseev.PassAs<ui::Event>())));
31 }
32
33 void BrowserProcessDispatcherDelegate::ButtonNotify(unsigned handle,
34                                                     int state,
35                                                     int flags,
36                                                     float x,
37                                                     float y) {
38   ui::EventType type;
39   if (state == 1)
40     type = ui::ET_MOUSE_PRESSED;
41   else
42     type = ui::ET_MOUSE_RELEASED;
43
44   gfx::Point position = gfx::Point(x, y);
45   scoped_ptr<ui::MouseEvent> mouseev(new ui::MouseEvent(type,
46                                                         position,
47                                                         position,
48                                                         flags));
49   PostTaskOnMainLoop(base::Bind(
50       &BrowserProcessDispatcherDelegate::NotifyButtonPress, this, handle));
51
52   PostTaskOnMainLoop(base::Bind(
53       &BrowserProcessDispatcherDelegate::DispatchEventHelper, base::Passed(
54           mouseev.PassAs<ui::Event>())));
55 }
56
57 void BrowserProcessDispatcherDelegate::AxisNotify(float x,
58                                                   float y,
59                                                   float xoffset,
60                                                   float yoffset) {
61   gfx::Point position = gfx::Point(x, y);
62   ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, position, position, 0);
63
64   scoped_ptr<ui::MouseWheelEvent> wheelev(new ui::MouseWheelEvent(mouseev,
65                                                                   xoffset,
66                                                                   yoffset));
67
68   PostTaskOnMainLoop(base::Bind(
69       &BrowserProcessDispatcherDelegate::DispatchEventHelper, base::Passed(
70           wheelev.PassAs<ui::Event>())));
71 }
72
73 void BrowserProcessDispatcherDelegate::PointerEnter(unsigned handle,
74                                                     float x,
75                                                     float y) {
76   gfx::Point position = gfx::Point(x, y);
77   scoped_ptr<ui::MouseEvent> mouseev(new ui::MouseEvent(ui::ET_MOUSE_ENTERED,
78                                                         position,
79                                                         position,
80                                                         handle));
81   PostTaskOnMainLoop(base::Bind(
82       &BrowserProcessDispatcherDelegate::NotifyPointerEnter, this, handle));
83
84   PostTaskOnMainLoop(base::Bind(
85       &BrowserProcessDispatcherDelegate::DispatchEventHelper, base::Passed(
86           mouseev.PassAs<ui::Event>())));
87 }
88
89 void BrowserProcessDispatcherDelegate::PointerLeave(unsigned handle,
90                                                     float x,
91                                                     float y) {
92   gfx::Point position = gfx::Point(x, y);
93   scoped_ptr<ui::MouseEvent> mouseev(new ui::MouseEvent(ui::ET_MOUSE_EXITED,
94                                                         position,
95                                                         position,
96                                                         0));
97
98   PostTaskOnMainLoop(base::Bind(
99       &BrowserProcessDispatcherDelegate::NotifyPointerLeave, this, handle));
100
101   PostTaskOnMainLoop(base::Bind(
102       &BrowserProcessDispatcherDelegate::DispatchEventHelper, base::Passed(
103           mouseev.PassAs<ui::Event>())));
104 }
105
106 void BrowserProcessDispatcherDelegate::KeyNotify(unsigned state,
107                                                  unsigned code,
108                                                  unsigned modifiers) {
109   ui::EventType type;
110   if (state)
111     type = ui::ET_KEY_PRESSED;
112   else
113     type = ui::ET_KEY_RELEASED;
114
115   scoped_ptr<ui::KeyEvent> keyev(new ui::KeyEvent(type,
116                                                   KeyboardCodeFromXKeysym(code),
117                                                   modifiers,
118                                                   true));
119
120   PostTaskOnMainLoop(base::Bind(
121       &BrowserProcessDispatcherDelegate::DispatchEventHelper, base::Passed(
122           keyev.PassAs<ui::Event>())));
123 }
124
125 void BrowserProcessDispatcherDelegate::SetWindowChangeObserver(
126     WindowChangeObserver* observer) {
127   observer_ = observer;
128 }
129
130 void BrowserProcessDispatcherDelegate::NotifyPointerEnter(
131     BrowserProcessDispatcherDelegate* data, unsigned handle) {
132   if (data->observer_)
133     data->observer_->OnWindowEnter(handle);
134 }
135
136 void BrowserProcessDispatcherDelegate::NotifyPointerLeave(
137     BrowserProcessDispatcherDelegate* data, unsigned handle) {
138   if (data->observer_)
139     data->observer_->OnWindowLeave(handle);
140 }
141
142
143 void BrowserProcessDispatcherDelegate::NotifyButtonPress(
144     BrowserProcessDispatcherDelegate* data, unsigned handle) {
145   if (data->observer_)
146     data->observer_->OnWindowFocused(handle);
147 }
148
149 void BrowserProcessDispatcherDelegate::DispatchEventHelper(
150     scoped_ptr<ui::Event> key) {
151   base::MessagePumpOzone::Current()->Dispatch(key.get());
152 }
153
154 }  // namespace ozonewayland