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/platform/dri/dri_cursor.h"
13 #include "ui/ozone/platform/dri/dri_window_delegate.h"
14 #include "ui/ozone/platform/dri/dri_window_delegate_manager.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
DriWindow(PlatformWindowDelegate * delegate,const gfx::Rect & bounds,scoped_ptr<DriWindowDelegate> dri_window_delegate,EventFactoryEvdev * event_factory,DriWindowDelegateManager * window_delegate_manager,DriWindowManager * window_manager)20 DriWindow::DriWindow(PlatformWindowDelegate* delegate,
21 const gfx::Rect& bounds,
22 scoped_ptr<DriWindowDelegate> dri_window_delegate,
23 EventFactoryEvdev* event_factory,
24 DriWindowDelegateManager* window_delegate_manager,
25 DriWindowManager* window_manager)
26 : delegate_(delegate),
27 bounds_(bounds),
28 widget_(dri_window_delegate->GetAcceleratedWidget()),
29 dri_window_delegate_(dri_window_delegate.get()),
30 event_factory_(event_factory),
31 window_delegate_manager_(window_delegate_manager),
32 window_manager_(window_manager) {
33 window_delegate_manager_->AddWindowDelegate(widget_,
34 dri_window_delegate.Pass());
35 window_manager_->AddWindow(widget_, this);
36 }
37
~DriWindow()38 DriWindow::~DriWindow() {
39 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
40 dri_window_delegate_->Shutdown();
41 window_manager_->RemoveWindow(widget_);
42 window_delegate_manager_->RemoveWindowDelegate(widget_);
43 }
44
Initialize()45 void DriWindow::Initialize() {
46 dri_window_delegate_->Initialize();
47 dri_window_delegate_->OnBoundsChanged(bounds_);
48 delegate_->OnAcceleratedWidgetAvailable(widget_);
49 PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
50 }
51
Show()52 void DriWindow::Show() {}
53
Hide()54 void DriWindow::Hide() {}
55
Close()56 void DriWindow::Close() {}
57
SetBounds(const gfx::Rect & bounds)58 void DriWindow::SetBounds(const gfx::Rect& bounds) {
59 bounds_ = bounds;
60 delegate_->OnBoundsChanged(bounds);
61 if (window_manager_->cursor()->GetCursorWindow() == widget_)
62 window_manager_->cursor()->HideCursor();
63
64 dri_window_delegate_->OnBoundsChanged(bounds);
65
66 if (window_manager_->cursor()->GetCursorWindow() == widget_)
67 window_manager_->cursor()->ShowCursor();
68 }
69
GetBounds()70 gfx::Rect DriWindow::GetBounds() {
71 return bounds_;
72 }
73
SetCapture()74 void DriWindow::SetCapture() {}
75
ReleaseCapture()76 void DriWindow::ReleaseCapture() {}
77
ToggleFullscreen()78 void DriWindow::ToggleFullscreen() {}
79
Maximize()80 void DriWindow::Maximize() {}
81
Minimize()82 void DriWindow::Minimize() {}
83
Restore()84 void DriWindow::Restore() {}
85
SetCursor(PlatformCursor cursor)86 void DriWindow::SetCursor(PlatformCursor cursor) {
87 window_manager_->cursor()->SetCursor(widget_, cursor);
88 }
89
MoveCursorTo(const gfx::Point & location)90 void DriWindow::MoveCursorTo(const gfx::Point& location) {
91 event_factory_->WarpCursorTo(widget_, location);
92 }
93
CanDispatchEvent(const PlatformEvent & ne)94 bool DriWindow::CanDispatchEvent(const PlatformEvent& ne) {
95 DCHECK(ne);
96 Event* event = static_cast<Event*>(ne);
97 if (event->IsMouseEvent() || event->IsScrollEvent())
98 return window_manager_->cursor()->GetCursorWindow() == widget_;
99
100 return true;
101 }
102
DispatchEvent(const PlatformEvent & native_event)103 uint32_t DriWindow::DispatchEvent(const PlatformEvent& native_event) {
104 DispatchEventFromNativeUiEvent(
105 native_event,
106 base::Bind(&PlatformWindowDelegate::DispatchEvent,
107 base::Unretained(delegate_)));
108 return POST_DISPATCH_STOP_PROPAGATION;
109 }
110
111 } // namespace ui
112