Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / ozone / platform / dri / dri_window.cc
1 // Copyright 2014 The Chromium Authors. 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 "ui/ozone/platform/dri/dri_window.h"
6
7 #include "base/bind.h"
8 #include "ui/events/event.h"
9 #include "ui/events/ozone/evdev/event_factory_evdev.h"
10 #include "ui/events/ozone/events_ozone.h"
11 #include "ui/events/platform/platform_event_source.h"
12 #include "ui/ozone/common/gpu/ozone_gpu_messages.h"
13 #include "ui/ozone/platform/dri/dri_cursor.h"
14 #include "ui/ozone/platform/dri/dri_gpu_platform_support_host.h"
15 #include "ui/ozone/platform/dri/dri_window_manager.h"
16 #include "ui/platform_window/platform_window_delegate.h"
17
18 namespace ui {
19
20 DriWindow::DriWindow(PlatformWindowDelegate* delegate,
21                      const gfx::Rect& bounds,
22                      DriGpuPlatformSupportHost* sender,
23                      EventFactoryEvdev* event_factory,
24                      DriWindowManager* window_manager)
25     : delegate_(delegate),
26       sender_(sender),
27       event_factory_(event_factory),
28       window_manager_(window_manager),
29       bounds_(bounds),
30       widget_(window_manager->NextAcceleratedWidget()) {
31   window_manager_->AddWindow(widget_, this);
32 }
33
34 DriWindow::~DriWindow() {
35   PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
36   window_manager_->RemoveWindow(widget_);
37
38   sender_->RemoveChannelObserver(this);
39   if (!sender_->IsConnected())
40     return;
41
42   sender_->Send(new OzoneGpuMsg_DestroyWindowDelegate(widget_));
43 }
44
45 void DriWindow::Initialize() {
46   sender_->AddChannelObserver(this);
47   delegate_->OnAcceleratedWidgetAvailable(widget_);
48   PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
49 }
50
51 void DriWindow::Show() {}
52
53 void DriWindow::Hide() {}
54
55 void DriWindow::Close() {}
56
57 void DriWindow::SetBounds(const gfx::Rect& bounds) {
58   bounds_ = bounds;
59   delegate_->OnBoundsChanged(bounds);
60
61   if (!sender_->IsConnected())
62     return;
63
64   if (window_manager_->cursor()->GetCursorWindow() == widget_)
65     window_manager_->cursor()->HideCursor();
66
67   sender_->Send(new OzoneGpuMsg_WindowBoundsChanged(widget_, bounds));
68
69   if (window_manager_->cursor()->GetCursorWindow() == widget_)
70     window_manager_->cursor()->ShowCursor();
71 }
72
73 gfx::Rect DriWindow::GetBounds() {
74   return bounds_;
75 }
76
77 void DriWindow::SetCapture() {}
78
79 void DriWindow::ReleaseCapture() {}
80
81 void DriWindow::ToggleFullscreen() {}
82
83 void DriWindow::Maximize() {}
84
85 void DriWindow::Minimize() {}
86
87 void DriWindow::Restore() {}
88
89 void DriWindow::SetCursor(PlatformCursor cursor) {
90   DriCursor* dri_cursor = window_manager_->cursor();
91   dri_cursor->SetCursor(widget_, cursor);
92   // ShowCursor results in a IPC call to GPU. So, we make sure the channel
93   // is connected. OnChannelEstablished guarantees that ShowCursor is called
94   // eventually.
95   if (sender_->IsConnected() && dri_cursor->GetCursorWindow() == widget_)
96     dri_cursor->ShowCursor();
97 }
98
99 void DriWindow::MoveCursorTo(const gfx::Point& location) {
100   event_factory_->WarpCursorTo(widget_, location);
101 }
102
103 bool DriWindow::CanDispatchEvent(const PlatformEvent& ne) {
104   DCHECK(ne);
105   Event* event = static_cast<Event*>(ne);
106   if (event->IsMouseEvent() || event->IsScrollEvent())
107     return window_manager_->cursor()->GetCursorWindow() == widget_;
108
109   return true;
110 }
111
112 uint32_t DriWindow::DispatchEvent(const PlatformEvent& native_event) {
113   DispatchEventFromNativeUiEvent(
114       native_event, base::Bind(&PlatformWindowDelegate::DispatchEvent,
115                                base::Unretained(delegate_)));
116   return POST_DISPATCH_STOP_PROPAGATION;
117 }
118
119 void DriWindow::OnChannelEstablished() {
120   sender_->Send(new OzoneGpuMsg_CreateWindowDelegate(widget_));
121   sender_->Send(new OzoneGpuMsg_WindowBoundsChanged(widget_, bounds_));
122
123   DriCursor* dri_cursor = window_manager_->cursor();
124   if (dri_cursor->GetCursorWindow() == widget_)
125     dri_cursor->ShowCursor();
126 }
127
128 void DriWindow::OnChannelDestroyed() {
129 }
130
131 }  // namespace ui