Upstream version 11.39.252.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 }
26
27 OzoneChannelHost::~OzoneChannelHost() {
28   delete state_handler_;
29 }
30
31 void OzoneChannelHost::DeleteRemoteStateChangeHandler() {
32   delete state_handler_;
33   state_handler_ = NULL;
34 }
35
36 void OzoneChannelHost::OnChannelEstablished(int host_id, IPC::Sender* sender) {
37   if (state_handler_)
38     state_handler_->ChannelEstablished(sender);
39 }
40
41 void OzoneChannelHost::OnChannelDestroyed(int host_id) {
42   if (state_handler_)
43     state_handler_->ChannelDestroyed();
44 }
45
46 bool OzoneChannelHost::OnMessageReceived(const IPC::Message& message) {
47   bool handled = true;
48   IPC_BEGIN_MESSAGE_MAP(OzoneChannelHost, message)
49   IPC_MESSAGE_HANDLER(WaylandInput_MotionNotify, OnMotionNotify)
50   IPC_MESSAGE_HANDLER(WaylandInput_ButtonNotify, OnButtonNotify)
51   IPC_MESSAGE_HANDLER(WaylandInput_TouchNotify, OnTouchNotify)
52   IPC_MESSAGE_HANDLER(WaylandInput_AxisNotify, OnAxisNotify)
53   IPC_MESSAGE_HANDLER(WaylandInput_PointerEnter, OnPointerEnter)
54   IPC_MESSAGE_HANDLER(WaylandInput_PointerLeave, OnPointerLeave)
55   IPC_MESSAGE_HANDLER(WaylandInput_KeyNotify, OnKeyNotify)
56   IPC_MESSAGE_HANDLER(WaylandInput_VirtualKeyNotify, OnVirtualKeyNotify)
57   IPC_MESSAGE_HANDLER(WaylandInput_KeyModifiers, OnKeyModifiers)
58   IPC_MESSAGE_HANDLER(WaylandInput_OutputSize, OnOutputSizeChanged)
59   IPC_MESSAGE_HANDLER(WaylandInput_CloseWidget, OnCloseWidget)
60   IPC_MESSAGE_HANDLER(WaylandWindow_Resized, OnWindowResized)
61   IPC_MESSAGE_HANDLER(WaylandWindow_Unminimized, OnWindowUnminimized)
62   IPC_MESSAGE_HANDLER(WaylandInput_Commit, OnCommit)
63   IPC_MESSAGE_HANDLER(WaylandInput_PreeditChanged, OnPreeditChanged)
64   IPC_MESSAGE_HANDLER(WaylandInput_PreeditEnd, OnPreeditEnd)
65   IPC_MESSAGE_HANDLER(WaylandInput_PreeditStart, OnPreeditStart)
66   IPC_MESSAGE_HANDLER(WaylandInput_InitializeXKB, OnInitializeXKB)
67   IPC_MESSAGE_UNHANDLED(handled = false)
68   IPC_END_MESSAGE_MAP()
69
70   return handled;
71 }
72
73 void OzoneChannelHost::OnMotionNotify(float x, float y) {
74   event_converter_->MotionNotify(x, y);
75 }
76
77 void OzoneChannelHost::OnButtonNotify(unsigned handle,
78                                       ui::EventType type,
79                                       ui::EventFlags flags,
80                                       float x,
81                                       float y) {
82   event_converter_->ButtonNotify(handle, type, flags, x, y);
83 }
84
85 void OzoneChannelHost::OnTouchNotify(ui::EventType type,
86                                      float x,
87                                      float y,
88                                      int32_t touch_id,
89                                      uint32_t time_stamp) {
90   event_converter_->TouchNotify(type, x, y, touch_id, time_stamp);
91 }
92
93 void OzoneChannelHost::OnAxisNotify(float x,
94                                     float y,
95                                     int xoffset,
96                                     int yoffset) {
97   event_converter_->AxisNotify(x, y, xoffset, yoffset);
98 }
99
100 void OzoneChannelHost::OnPointerEnter(unsigned handle,
101                                       float x,
102                                       float y) {
103   event_converter_->PointerEnter(handle, x, y);
104 }
105
106 void OzoneChannelHost::OnPointerLeave(unsigned handle,
107                                       float x,
108                                       float y) {
109   event_converter_->PointerLeave(handle, x, y);
110 }
111
112 void OzoneChannelHost::OnKeyNotify(ui::EventType type,
113                                    unsigned code) {
114   event_converter_->KeyNotify(type, code);
115 }
116
117 void OzoneChannelHost::OnVirtualKeyNotify(ui::EventType type,
118                                           uint32_t key,
119                                           uint32_t modifiers) {
120   event_converter_->VirtualKeyNotify(type, key, modifiers);
121 }
122
123 void OzoneChannelHost::OnKeyModifiers(uint32_t mods_depressed,
124                                       uint32_t mods_latched,
125                                       uint32_t mods_locked,
126                                       uint32_t group) {
127   event_converter_->KeyModifiers(mods_depressed,
128                                  mods_latched,
129                                  mods_locked,
130                                  group);
131 }
132
133 void OzoneChannelHost::OnOutputSizeChanged(unsigned width,
134                                            unsigned height) {
135   event_converter_->OutputSizeChanged(width, height);
136 }
137
138 void OzoneChannelHost::OnCloseWidget(unsigned handle) {
139   event_converter_->CloseWidget(handle);
140 }
141
142 void OzoneChannelHost::OnWindowResized(unsigned handle,
143                                        unsigned width,
144                                        unsigned height) {
145   event_converter_->WindowResized(handle, width, height);
146 }
147
148 void OzoneChannelHost::OnWindowUnminimized(unsigned handle) {
149   event_converter_->WindowUnminimized(handle);
150 }
151
152 void OzoneChannelHost::OnCommit(unsigned handle, std::string text) {
153   event_converter_->Commit(handle, text);
154 }
155
156 void OzoneChannelHost::OnPreeditChanged(unsigned handle, std::string text,
157                                         std::string commit) {
158   event_converter_->PreeditChanged(handle, text, commit);
159 }
160
161 void OzoneChannelHost::OnPreeditEnd() {
162 }
163
164 void OzoneChannelHost::OnPreeditStart() {
165 }
166
167 void OzoneChannelHost::OnInitializeXKB(base::SharedMemoryHandle fd,
168                                        uint32_t size) {
169   event_converter_->InitializeXKB(fd, size);
170 }
171
172 }  // namespace ui