Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ozone / ui / public / ozone_channel_host.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/public/ozone_channel_host.h"
6
7 #include "ozone/ui/events/event_converter_in_process.h"
8 #include "ozone/ui/events/event_factory_ozone_wayland.h"
9 #include "ozone/ui/events/remote_state_change_handler.h"
10 #include "ozone/ui/public/messages.h"
11
12 namespace ui {
13
14 OzoneChannelHost::OzoneChannelHost()
15     : state_handler_(NULL) {
16   event_converter_ = new EventConverterInProcess();
17   ui::EventFactoryOzoneWayland* event_factory =
18       ui::EventFactoryOzoneWayland::GetInstance();
19   event_factory->SetEventConverterOzoneWayland(event_converter_);
20   state_handler_ = new RemoteStateChangeHandler();
21   event_converter_->SetWindowChangeObserver(
22     event_factory->GetWindowChangeObserver());
23   event_converter_->SetOutputChangeObserver(
24     event_factory->GetOutputChangeObserver());
25   event_converter_->SetIMEChangeObserver(
26     event_factory->GetIMEChangeObserver());
27 }
28
29 OzoneChannelHost::~OzoneChannelHost() {
30   delete state_handler_;
31 }
32
33 void OzoneChannelHost::DeleteRemoteStateChangeHandler() {
34   delete state_handler_;
35   state_handler_ = NULL;
36 }
37
38 void OzoneChannelHost::OnChannelEstablished(int host_id, IPC::Sender* sender) {
39   if (state_handler_)
40     state_handler_->ChannelEstablished(sender);
41 }
42
43 void OzoneChannelHost::OnChannelDestroyed(int host_id) {
44   if (state_handler_)
45     state_handler_->ChannelDestroyed();
46 }
47
48 bool OzoneChannelHost::OnMessageReceived(const IPC::Message& message) {
49   bool handled = true;
50   IPC_BEGIN_MESSAGE_MAP(OzoneChannelHost, message)
51   IPC_MESSAGE_HANDLER(WaylandInput_MotionNotify, OnMotionNotify)
52   IPC_MESSAGE_HANDLER(WaylandInput_ButtonNotify, OnButtonNotify)
53   IPC_MESSAGE_HANDLER(WaylandInput_TouchNotify, OnTouchNotify)
54   IPC_MESSAGE_HANDLER(WaylandInput_AxisNotify, OnAxisNotify)
55   IPC_MESSAGE_HANDLER(WaylandInput_PointerEnter, OnPointerEnter)
56   IPC_MESSAGE_HANDLER(WaylandInput_PointerLeave, OnPointerLeave)
57   IPC_MESSAGE_HANDLER(WaylandInput_KeyNotify, OnKeyNotify)
58   IPC_MESSAGE_HANDLER(WaylandInput_VirtualKeyNotify, OnVirtualKeyNotify)
59   IPC_MESSAGE_HANDLER(WaylandInput_KeyModifiers, OnKeyModifiers)
60   IPC_MESSAGE_HANDLER(WaylandInput_OutputSize, OnOutputSizeChanged)
61   IPC_MESSAGE_HANDLER(WaylandInput_CloseWidget, OnCloseWidget)
62   IPC_MESSAGE_HANDLER(WaylandWindow_Resized, OnWindowResized)
63   IPC_MESSAGE_HANDLER(WaylandWindow_Activated, OnWindowActivated)
64   IPC_MESSAGE_HANDLER(WaylandWindow_DeActivated, OnWindowDeActivated)
65   IPC_MESSAGE_HANDLER(WaylandWindow_Unminimized, OnWindowUnminimized)
66   IPC_MESSAGE_HANDLER(WaylandInput_Commit, OnCommit)
67   IPC_MESSAGE_HANDLER(WaylandInput_PreeditChanged, OnPreeditChanged)
68   IPC_MESSAGE_HANDLER(WaylandInput_PreeditEnd, OnPreeditEnd)
69   IPC_MESSAGE_HANDLER(WaylandInput_PreeditStart, OnPreeditStart)
70   IPC_MESSAGE_HANDLER(WaylandInput_InitializeXKB, OnInitializeXKB)
71   IPC_MESSAGE_UNHANDLED(handled = false)
72   IPC_END_MESSAGE_MAP()
73
74   return handled;
75 }
76
77 void OzoneChannelHost::OnMotionNotify(float x, float y) {
78   event_converter_->MotionNotify(x, y);
79 }
80
81 void OzoneChannelHost::OnButtonNotify(unsigned handle,
82                                       ui::EventType type,
83                                       ui::EventFlags flags,
84                                       float x,
85                                       float y) {
86   event_converter_->ButtonNotify(handle, type, flags, x, y);
87 }
88
89 void OzoneChannelHost::OnTouchNotify(ui::EventType type,
90                                      float x,
91                                      float y,
92                                      int32_t touch_id,
93                                      uint32_t time_stamp) {
94   event_converter_->TouchNotify(type, x, y, touch_id, time_stamp);
95 }
96
97 void OzoneChannelHost::OnAxisNotify(float x,
98                                     float y,
99                                     int xoffset,
100                                     int yoffset) {
101   event_converter_->AxisNotify(x, y, xoffset, yoffset);
102 }
103
104 void OzoneChannelHost::OnPointerEnter(unsigned handle,
105                                       float x,
106                                       float y) {
107   event_converter_->PointerEnter(handle, x, y);
108 }
109
110 void OzoneChannelHost::OnPointerLeave(unsigned handle,
111                                       float x,
112                                       float y) {
113   event_converter_->PointerLeave(handle, x, y);
114 }
115
116 void OzoneChannelHost::OnKeyNotify(ui::EventType type,
117                                    unsigned code) {
118   event_converter_->KeyNotify(type, code);
119 }
120
121 void OzoneChannelHost::OnVirtualKeyNotify(ui::EventType type,
122                                           uint32_t key,
123                                           uint32_t modifiers) {
124   event_converter_->VirtualKeyNotify(type, key, modifiers);
125 }
126
127 void OzoneChannelHost::OnKeyModifiers(uint32_t mods_depressed,
128                                       uint32_t mods_latched,
129                                       uint32_t mods_locked,
130                                       uint32_t group) {
131   event_converter_->KeyModifiers(mods_depressed,
132                                  mods_latched,
133                                  mods_locked,
134                                  group);
135 }
136
137 void OzoneChannelHost::OnOutputSizeChanged(unsigned width,
138                                            unsigned height) {
139   event_converter_->OutputSizeChanged(width, height);
140 }
141
142 void OzoneChannelHost::OnCloseWidget(unsigned handle) {
143   event_converter_->CloseWidget(handle);
144 }
145
146 void OzoneChannelHost::OnWindowResized(unsigned handle,
147                                        unsigned width,
148                                        unsigned height) {
149   event_converter_->WindowResized(handle, width, height);
150 }
151
152 void OzoneChannelHost::OnWindowUnminimized(unsigned handle) {
153   event_converter_->WindowUnminimized(handle);
154 }
155
156 void OzoneChannelHost::OnWindowActivated(unsigned handle) {
157   event_converter_->WindowActivated(handle);
158 }
159
160 void OzoneChannelHost::OnWindowDeActivated(unsigned handle) {
161   event_converter_->WindowDeActivated(handle);
162 }
163
164 void OzoneChannelHost::OnCommit(unsigned handle, std::string text) {
165   event_converter_->Commit(handle, text);
166 }
167
168 void OzoneChannelHost::OnPreeditChanged(unsigned handle, std::string text,
169                                         std::string commit) {
170   event_converter_->PreeditChanged(handle, text, commit);
171 }
172
173 void OzoneChannelHost::OnPreeditEnd() {
174 }
175
176 void OzoneChannelHost::OnPreeditStart() {
177 }
178
179 void OzoneChannelHost::OnInitializeXKB(base::SharedMemoryHandle fd,
180                                        uint32_t size) {
181   event_converter_->InitializeXKB(fd, size);
182 }
183
184 }  // namespace ui