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/ui/public/ozone_channel_host.h"
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"
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());
27 OzoneChannelHost::~OzoneChannelHost() {
28 delete state_handler_;
31 void OzoneChannelHost::DeleteRemoteStateChangeHandler() {
32 delete state_handler_;
33 state_handler_ = NULL;
36 void OzoneChannelHost::OnChannelEstablished(int host_id, IPC::Sender* sender) {
38 state_handler_->ChannelEstablished(sender);
41 void OzoneChannelHost::OnChannelDestroyed(int host_id) {
43 state_handler_->ChannelDestroyed();
46 bool OzoneChannelHost::OnMessageReceived(const IPC::Message& message) {
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)
73 void OzoneChannelHost::OnMotionNotify(float x, float y) {
74 event_converter_->MotionNotify(x, y);
77 void OzoneChannelHost::OnButtonNotify(unsigned handle,
82 event_converter_->ButtonNotify(handle, type, flags, x, y);
85 void OzoneChannelHost::OnTouchNotify(ui::EventType type,
89 uint32_t time_stamp) {
90 event_converter_->TouchNotify(type, x, y, touch_id, time_stamp);
93 void OzoneChannelHost::OnAxisNotify(float x,
97 event_converter_->AxisNotify(x, y, xoffset, yoffset);
100 void OzoneChannelHost::OnPointerEnter(unsigned handle,
103 event_converter_->PointerEnter(handle, x, y);
106 void OzoneChannelHost::OnPointerLeave(unsigned handle,
109 event_converter_->PointerLeave(handle, x, y);
112 void OzoneChannelHost::OnKeyNotify(ui::EventType type,
114 event_converter_->KeyNotify(type, code);
117 void OzoneChannelHost::OnVirtualKeyNotify(ui::EventType type,
119 uint32_t modifiers) {
120 event_converter_->VirtualKeyNotify(type, key, modifiers);
123 void OzoneChannelHost::OnKeyModifiers(uint32_t mods_depressed,
124 uint32_t mods_latched,
125 uint32_t mods_locked,
127 event_converter_->KeyModifiers(mods_depressed,
133 void OzoneChannelHost::OnOutputSizeChanged(unsigned width,
135 event_converter_->OutputSizeChanged(width, height);
138 void OzoneChannelHost::OnCloseWidget(unsigned handle) {
139 event_converter_->CloseWidget(handle);
142 void OzoneChannelHost::OnWindowResized(unsigned handle,
145 event_converter_->WindowResized(handle, width, height);
148 void OzoneChannelHost::OnWindowUnminimized(unsigned handle) {
149 event_converter_->WindowUnminimized(handle);
152 void OzoneChannelHost::OnCommit(unsigned handle, std::string text) {
153 event_converter_->Commit(handle, text);
156 void OzoneChannelHost::OnPreeditChanged(unsigned handle, std::string text,
157 std::string commit) {
158 event_converter_->PreeditChanged(handle, text, commit);
161 void OzoneChannelHost::OnPreeditEnd() {
164 void OzoneChannelHost::OnPreeditStart() {
167 void OzoneChannelHost::OnInitializeXKB(base::SharedMemoryHandle fd,
169 event_converter_->InitializeXKB(fd, size);