Upstream version 9.38.204.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_OutputSize, OnOutputSizeChanged)
57   IPC_MESSAGE_HANDLER(WaylandInput_CloseWidget, OnCloseWidget)
58   IPC_MESSAGE_HANDLER(WaylandWindow_Resized, OnWindowResized)
59   IPC_MESSAGE_HANDLER(WaylandWindow_Unminimized, OnWindowUnminimized)
60   IPC_MESSAGE_HANDLER(WaylandInput_Commit, OnCommit)
61   IPC_MESSAGE_HANDLER(WaylandInput_PreeditChanged, OnPreeditChanged)
62   IPC_MESSAGE_HANDLER(WaylandInput_PreeditEnd, OnPreeditEnd)
63   IPC_MESSAGE_HANDLER(WaylandInput_PreeditStart, OnPreeditStart)
64   IPC_MESSAGE_UNHANDLED(handled = false)
65   IPC_END_MESSAGE_MAP()
66
67   return handled;
68 }
69
70 void OzoneChannelHost::OnMotionNotify(float x, float y) {
71   event_converter_->MotionNotify(x, y);
72 }
73
74 void OzoneChannelHost::OnButtonNotify(unsigned handle,
75                                       ui::EventType type,
76                                       ui::EventFlags flags,
77                                       float x,
78                                       float y) {
79   event_converter_->ButtonNotify(handle, type, flags, x, y);
80 }
81
82 void OzoneChannelHost::OnTouchNotify(ui::EventType type,
83                                      float x,
84                                      float y,
85                                      int32_t touch_id,
86                                      uint32_t time_stamp) {
87   event_converter_->TouchNotify(type, x, y, touch_id, time_stamp);
88 }
89
90 void OzoneChannelHost::OnAxisNotify(float x,
91                                     float y,
92                                     int xoffset,
93                                     int yoffset) {
94   event_converter_->AxisNotify(x, y, xoffset, yoffset);
95 }
96
97 void OzoneChannelHost::OnPointerEnter(unsigned handle,
98                                       float x,
99                                       float y) {
100   event_converter_->PointerEnter(handle, x, y);
101 }
102
103 void OzoneChannelHost::OnPointerLeave(unsigned handle,
104                                       float x,
105                                       float y) {
106   event_converter_->PointerLeave(handle, x, y);
107 }
108
109 void OzoneChannelHost::OnKeyNotify(ui::EventType type,
110                                    unsigned code,
111                                    unsigned modifiers) {
112   event_converter_->KeyNotify(type, code, modifiers);
113 }
114
115 void OzoneChannelHost::OnOutputSizeChanged(unsigned width,
116                                            unsigned height) {
117   event_converter_->OutputSizeChanged(width, height);
118 }
119
120 void OzoneChannelHost::OnCloseWidget(unsigned handle) {
121   event_converter_->CloseWidget(handle);
122 }
123
124 void OzoneChannelHost::OnWindowResized(unsigned handle,
125                                        unsigned width,
126                                        unsigned height) {
127   event_converter_->WindowResized(handle, width, height);
128 }
129
130 void OzoneChannelHost::OnWindowUnminimized(unsigned handle) {
131   event_converter_->WindowUnminimized(handle);
132 }
133
134 void OzoneChannelHost::OnCommit(unsigned handle, std::string text) {
135   event_converter_->Commit(handle, text);
136 }
137
138 void OzoneChannelHost::OnPreeditChanged(unsigned handle, std::string text,
139                                         std::string commit) {
140   event_converter_->PreeditChanged(handle, text, commit);
141 }
142
143 void OzoneChannelHost::OnPreeditEnd() {
144 }
145
146 void OzoneChannelHost::OnPreeditStart() {
147 }
148
149 }  // namespace ui