Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: ui/ozone/platform/drm/host/drm_window_host.cc

Issue 1285183008: Ozone integration. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add missing license header Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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/drm/host/drm_window_host.h"
6
7 #include "base/bind.h"
8 #include "ui/events/devices/device_data_manager.h"
9 #include "ui/events/event.h"
10 #include "ui/events/ozone/evdev/event_factory_evdev.h"
11 #include "ui/events/ozone/events_ozone.h"
12 #include "ui/events/platform/platform_event_source.h"
13 #include "ui/gfx/display.h"
14 #include "ui/ozone/platform/drm/host/drm_cursor.h"
15 #include "ui/ozone/platform/drm/host/drm_display_host.h"
16 #include "ui/ozone/platform/drm/host/drm_display_host_manager.h"
17 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h"
18 #include "ui/ozone/platform/drm/host/drm_window_host_manager.h"
19 #include "ui/platform_window/platform_window_delegate.h"
20
21 namespace ui {
22
23 DrmWindowHost::DrmWindowHost(PlatformWindowDelegate* delegate,
24 const gfx::Rect& bounds,
25 DrmGpuPlatformSupportHost* sender,
26 EventFactoryEvdev* event_factory,
27 DrmCursor* cursor,
28 DrmWindowHostManager* window_manager,
29 DrmDisplayHostManager* display_manager)
30 : delegate_(delegate),
31 sender_(sender),
32 event_factory_(event_factory),
33 cursor_(cursor),
34 window_manager_(window_manager),
35 display_manager_(display_manager),
36 bounds_(bounds),
37 widget_(window_manager->NextAcceleratedWidget()) {
38 window_manager_->AddWindow(widget_, this);
39 }
40
41 DrmWindowHost::~DrmWindowHost() {
42 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
43 window_manager_->RemoveWindow(widget_);
44 cursor_->OnWindowRemoved(widget_);
45
46 sender_->RemoveChannelObserver(this);
47 sender_->DestroyWindow(widget_);
48 }
49
50 void DrmWindowHost::Initialize() {
51 sender_->AddChannelObserver(this);
52 PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
53 cursor_->OnWindowAdded(widget_, bounds_, GetCursorConfinedBounds());
54 delegate_->OnAcceleratedWidgetAvailable(widget_);
55 }
56
57 gfx::AcceleratedWidget DrmWindowHost::GetAcceleratedWidget() {
58 return widget_;
59 }
60
61 gfx::Rect DrmWindowHost::GetCursorConfinedBounds() const {
62 return cursor_confined_bounds_.IsEmpty() ? gfx::Rect(bounds_.size())
63 : cursor_confined_bounds_;
64 }
65
66 void DrmWindowHost::Show() {
67 }
68
69 void DrmWindowHost::Hide() {
70 }
71
72 void DrmWindowHost::Close() {
73 }
74
75 void DrmWindowHost::SetBounds(const gfx::Rect& bounds) {
76 bounds_ = bounds;
77 delegate_->OnBoundsChanged(bounds);
78 SendBoundsChange();
79 }
80
81 gfx::Rect DrmWindowHost::GetBounds() {
82 return bounds_;
83 }
84
85 void DrmWindowHost::SetCapture() {
86 window_manager_->GrabEvents(widget_);
87 }
88
89 void DrmWindowHost::ReleaseCapture() {
90 window_manager_->UngrabEvents(widget_);
91 }
92
93 void DrmWindowHost::ToggleFullscreen() {
94 }
95
96 void DrmWindowHost::Maximize() {
97 }
98
99 void DrmWindowHost::Minimize() {
100 }
101
102 void DrmWindowHost::Restore() {
103 }
104
105 void DrmWindowHost::SetCursor(PlatformCursor cursor) {
106 cursor_->SetCursor(widget_, cursor);
107 }
108
109 void DrmWindowHost::MoveCursorTo(const gfx::Point& location) {
110 event_factory_->WarpCursorTo(widget_, location);
111 }
112
113 void DrmWindowHost::ConfineCursorToBounds(const gfx::Rect& bounds) {
114 if (cursor_confined_bounds_ == bounds)
115 return;
116
117 cursor_confined_bounds_ = bounds;
118 cursor_->CommitBoundsChange(widget_, bounds_, bounds);
119 }
120
121 bool DrmWindowHost::CanDispatchEvent(const PlatformEvent& ne) {
122 DCHECK(ne);
123 Event* event = static_cast<Event*>(ne);
124
125 // If there is a grab, capture events here.
126 gfx::AcceleratedWidget grabber = window_manager_->event_grabber();
127 if (grabber != gfx::kNullAcceleratedWidget)
128 return grabber == widget_;
129
130 if (event->IsTouchEvent()) {
131 // Dispatch the event if it is from the touchscreen associated with the
132 // DrmWindowHost. We cannot check the event's location because if the
133 // touchscreen has a bezel, touches in the bezel have a location outside of
134 // |bounds_|.
135 int64_t display_id =
136 DeviceDataManager::GetInstance()->GetTargetDisplayForTouchDevice(
137 event->source_device_id());
138
139 if (display_id == gfx::Display::kInvalidDisplayID)
140 return false;
141
142 DrmDisplayHost* display = display_manager_->GetDisplay(display_id);
143 if (!display)
144 return false;
145
146 DisplaySnapshot* snapshot = display->snapshot();
147 if (!snapshot->current_mode())
148 return false;
149
150 gfx::Rect display_bounds(snapshot->origin(),
151 snapshot->current_mode()->size());
152 return display_bounds == bounds_;
153 } else if (event->IsLocatedEvent()) {
154 LocatedEvent* located_event = static_cast<LocatedEvent*>(event);
155 return bounds_.Contains(gfx::ToFlooredPoint(located_event->location()));
156 }
157
158 // TODO(spang): For non-ash builds we would need smarter keyboard focus.
159 return true;
160 }
161
162 uint32_t DrmWindowHost::DispatchEvent(const PlatformEvent& native_event) {
163 DCHECK(native_event);
164
165 Event* event = static_cast<Event*>(native_event);
166 if (event->IsLocatedEvent()) {
167 // Make the event location relative to this window's origin.
168 LocatedEvent* located_event = static_cast<LocatedEvent*>(event);
169 gfx::PointF location = located_event->location();
170 location -= bounds_.OffsetFromOrigin();
171 located_event->set_location(location);
172 located_event->set_root_location(location);
173 }
174 DispatchEventFromNativeUiEvent(
175 native_event, base::Bind(&PlatformWindowDelegate::DispatchEvent,
176 base::Unretained(delegate_)));
177 return POST_DISPATCH_STOP_PROPAGATION;
178 }
179
180 void DrmWindowHost::OnChannelEstablished() {
181 sender_->CreateWindow(widget_);
182 SendBoundsChange();
183 }
184
185 void DrmWindowHost::OnChannelDestroyed() {
186 }
187
188 void DrmWindowHost::SendBoundsChange() {
189 // Update the cursor before the window so that the cursor stays within the
190 // window bounds when the window size shrinks.
191 cursor_->CommitBoundsChange(widget_, bounds_, GetCursorConfinedBounds());
192 sender_->WindowBoundsChanged(widget_, bounds_);
193 }
194
195 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/host/drm_window_host.h ('k') | ui/ozone/platform/drm/host/drm_window_host_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698