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

Side by Side Diff: ui/views/widget/desktop_aura/desktop_window_tree_host_wayland.cc

Issue 2027943002: [WIP] Make content_shell run under Wayland Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: (09.28.2016)Rebase on master Created 4 years, 2 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
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_window_tree_host_wayland.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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/views/widget/desktop_aura/desktop_window_tree_host_wayland.h"
6
7 #include "ui/aura/client/focus_client.h"
8 #include "ui/aura/window.h"
9 #include "ui/aura/window_property.h"
10 #include "ui/aura/window_tree_host.h"
11 #include "ui/display/screen.h"
12 #include "ui/native_theme/native_theme_aura.h"
13 #include "ui/ozone/public/ozone_platform.h"
14 #include "ui/views/corewm/tooltip_aura.h"
15 #include "ui/views/linux_ui/linux_ui.h"
16 #include "ui/views/views_delegate.h"
17 #include "ui/views/views_export.h"
18 #include "ui/views/views_switches.h"
19 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
20 #include "ui/views/widget/desktop_aura/desktop_screen_wayland.h"
21 #include "ui/views/widget/desktop_aura/desktop_window_tree_host.h"
22 #include "ui/wm/core/window_util.h"
23 #include "ui/wm/public/drag_drop_client.h"
24 #include "ui/wm/public/window_move_client.h"
25
26 namespace views {
27
28 std::list<gfx::AcceleratedWidget>*
29 DesktopWindowTreeHostWayland::open_windows_ = NULL;
30
31 std::vector<aura::Window*>*
32 DesktopWindowTreeHostWayland::aura_windows_ = NULL;
33
34 DesktopWindowTreeHostWayland::DesktopWindowTreeHostWayland(
35 internal::NativeWidgetDelegate* native_widget_delegate,
36 DesktopNativeWidgetAura* desktop_native_widget_aura)
37 : aura::WindowTreeHost(),
38 state_(Uninitialized),
39 window_(0),
40 title_(base::string16()),
41 native_widget_delegate_(native_widget_delegate),
42 content_window_(nullptr),
43 desktop_native_widget_aura_(desktop_native_widget_aura),
44 window_parent_(nullptr),
45 window_children_(),
46 close_widget_factory_(this) {
47 }
48
49 DesktopWindowTreeHostWayland::~DesktopWindowTreeHostWayland() {
50 aura::client::SetWindowMoveClient(window(), NULL);
51 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this);
52 DestroyDispatcher();
53 }
54
55 void DesktopWindowTreeHostWayland::CleanUpWindowList() {
56 delete open_windows_;
57 open_windows_ = NULL;
58 if (aura_windows_) {
59 aura_windows_->clear();
60 delete aura_windows_;
61 aura_windows_ = NULL;
62 }
63 }
64
65 gfx::Rect DesktopWindowTreeHostWayland::GetBoundsInScreen() const {
66 return platform_window_->GetBounds();
67 }
68
69 ////////////////////////////////////////////////////////////////////////////////
70 // DesktopWindowTreeHostWayland, DesktopWindowTreeHost implementation:
71
72 void DesktopWindowTreeHostWayland::Init(
73 aura::Window* content_window,
74 const Widget::InitParams& params) {
75 content_window_ = content_window;
76 // In some situations, views tries to make a zero sized window, and that
77 // makes us crash. Make sure we have valid sizes.
78 Widget::InitParams sanitized_params = params;
79 if (sanitized_params.bounds.width() == 0)
80 sanitized_params.bounds.set_width(100);
81 if (sanitized_params.bounds.height() == 0)
82 sanitized_params.bounds.set_height(100);
83
84 platform_window_ =
85 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this,
86 sanitized_params.bounds);
87 DCHECK(window_);
88 }
89
90 void DesktopWindowTreeHostWayland::OnNativeWidgetCreated(
91 const Widget::InitParams& params) {
92 // If we're given a parent, we need to mark ourselves as transient to another
93 // window. Otherwise activation gets screwy.
94 gfx::NativeView parent = params.parent;
95 if (!params.child && params.parent)
96 wm::AddTransientChild(parent, content_window_);
97
98 native_widget_delegate_->OnNativeWidgetCreated(true);
99 open_windows().push_back(window_);
100 if (aura_windows_) {
101 aura_windows_->clear();
102 delete aura_windows_;
103 aura_windows_ = NULL;
104 }
105 }
106
107 std::unique_ptr<corewm::Tooltip>
108 DesktopWindowTreeHostWayland::CreateTooltip() {
109 return std::unique_ptr<views::corewm::Tooltip>(
110 new views::corewm::TooltipAura);
111 }
112
113 std::unique_ptr<aura::client::DragDropClient>
114 DesktopWindowTreeHostWayland::CreateDragDropClient(
115 DesktopNativeCursorManager* cursor_manager) {
116 return nullptr;
117 }
118
119
120 void DesktopWindowTreeHostWayland::Close() {
121 if (!close_widget_factory_.HasWeakPtrs()) {
122 // And we delay the close so that if we are called from an ATL callback,
123 // we don't destroy the window before the callback returned (as the caller
124 // may delete ourselves on destroy and the ATL callback would still
125 // dereference us when the callback returns).
126 base::MessageLoop::current()->task_runner()->PostTask(
127 FROM_HERE,
128 base::Bind(&DesktopWindowTreeHostWayland::CloseNow,
129 close_widget_factory_.GetWeakPtr()));
130 }
131 }
132
133 void DesktopWindowTreeHostWayland::CloseNow() {
134 if (!window_)
135 return;
136
137 unsigned widgetId = window_;
138 ReleaseCapture();
139 native_widget_delegate_->OnNativeWidgetDestroying();
140
141 // If we have children, close them. Use a copy for iteration because they'll
142 // remove themselves.
143 std::set<DesktopWindowTreeHostWayland*> window_children_copy =
144 window_children_;
145 for (std::set<DesktopWindowTreeHostWayland*>::iterator it =
146 window_children_copy.begin(); it != window_children_copy.end();
147 ++it) {
148 (*it)->CloseNow();
149 }
150 DCHECK(window_children_.empty());
151
152 // If we have a parent, remove ourselves from its children list.
153 if (window_parent_) {
154 window_parent_->window_children_.erase(this);
155 window_parent_ = NULL;
156 }
157
158 // Destroy the compositor before destroying the window since shutdown
159 // may try to swap, and the swap without a window causes an X error, which
160 // causes a crash with in-process renderer.
161 DestroyCompositor();
162
163 open_windows().remove(widgetId);
164 if (aura_windows_) {
165 aura_windows_->clear();
166 delete aura_windows_;
167 aura_windows_ = NULL;
168 }
169
170 // Actually free our native resources.
171 platform_window_->Close();
172 window_ = 0;
173 if (open_windows().empty())
174 CleanUpWindowList();
175
176 desktop_native_widget_aura_->OnHostClosed();
177 }
178
179
180 aura::WindowTreeHost* DesktopWindowTreeHostWayland::AsWindowTreeHost() {
181 return this;
182 }
183
184 void DesktopWindowTreeHostWayland::ShowWindowWithState(
185 ui::WindowShowState show_state) {
186 if (compositor())
187 compositor()->SetVisible(true);
188 state_ |= Visible;
189
190 switch (show_state) {
191 case ui::SHOW_STATE_NORMAL:
192 Activate();
193 break;
194 case ui::SHOW_STATE_MAXIMIZED:
195 Maximize();
196 break;
197 case ui::SHOW_STATE_MINIMIZED:
198 Minimize();
199 break;
200 case ui::SHOW_STATE_FULLSCREEN:
201 break;
202 default:
203 break;
204 }
205
206 native_widget_delegate_->AsWidget()->SetInitialFocus(show_state);
207 }
208
209 void DesktopWindowTreeHostWayland::ShowMaximizedWithBounds(
210 const gfx::Rect& restored_bounds) {
211 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED);
212 previous_bounds_ = restored_bounds;
213 }
214
215 bool DesktopWindowTreeHostWayland::IsVisible() const {
216 return state_ & Visible;
217 }
218
219 void DesktopWindowTreeHostWayland::SetSize(const gfx::Size& requested_size) {
220 gfx::Size size_in_pixels = ToPixelRect(gfx::Rect(requested_size)).size();
221 size_in_pixels = AdjustSize(size_in_pixels);
222 gfx::Rect new_bounds = platform_window_->GetBounds();
223 new_bounds.set_size(size_in_pixels);
224 platform_window_->SetBounds(new_bounds);
225 }
226
227 void DesktopWindowTreeHostWayland::StackAbove(aura::Window* window) {
228 }
229
230 void DesktopWindowTreeHostWayland::StackAtTop() {
231 }
232
233 void DesktopWindowTreeHostWayland::CenterWindow(const gfx::Size& size) {
234 gfx::Size size_in_pixels = ToPixelRect(gfx::Rect(size)).size();
235 gfx::Rect parent_bounds_in_pixels = GetWorkAreaBoundsInScreen();
236
237 // If |window_|'s transient parent bounds are big enough to contain |size|,
238 // use them instead.
239 if (wm::GetTransientParent(content_window_)) {
240 gfx::Rect transient_parent_rect =
241 wm::GetTransientParent(content_window_)->GetBoundsInScreen();
242 if (transient_parent_rect.height() >= size.height() &&
243 transient_parent_rect.width() >= size.width()) {
244 parent_bounds_in_pixels = ToPixelRect(transient_parent_rect);
245 }
246 }
247
248 gfx::Rect window_bounds_in_pixels(
249 parent_bounds_in_pixels.x() +
250 (parent_bounds_in_pixels.width() - size_in_pixels.width()) / 2,
251 parent_bounds_in_pixels.y() +
252 (parent_bounds_in_pixels.height() - size_in_pixels.height()) / 2,
253 size_in_pixels.width(), size_in_pixels.height());
254 // Don't size the window bigger than the parent, otherwise the user may not be
255 // able to close or move it.
256 window_bounds_in_pixels.AdjustToFit(parent_bounds_in_pixels);
257
258 SetBounds(window_bounds_in_pixels);
259 }
260
261 void DesktopWindowTreeHostWayland::GetWindowPlacement(
262 gfx::Rect* bounds,
263 ui::WindowShowState* show_state) const {
264 *bounds = GetRestoredBounds();
265
266 if (IsMinimized()) {
267 *show_state = ui::SHOW_STATE_MINIMIZED;
268 } else if (IsFullscreen()) {
269 *show_state = ui::SHOW_STATE_FULLSCREEN;
270 } else if (IsMaximized()) {
271 *show_state = ui::SHOW_STATE_MAXIMIZED;
272 } else if (!IsActive()) {
273 *show_state = ui::SHOW_STATE_INACTIVE;
274 } else {
275 *show_state = ui::SHOW_STATE_NORMAL;
276 }
277 }
278
279 gfx::Rect DesktopWindowTreeHostWayland::GetWindowBoundsInScreen() const {
280 return platform_window_->GetBounds();
281 }
282
283 gfx::Rect DesktopWindowTreeHostWayland::GetClientAreaBoundsInScreen() const {
284 // TODO(erg): The NativeWidgetAura version returns |bounds_|, claiming its
285 // needed for View::ConvertPointToScreen() to work
286 // correctly. DesktopWindowTreeHostWin::GetClientAreaBoundsInScreen() just
287 // asks windows what it thinks the client rect is.
288 //
289 // Attempts to calculate the rect by asking the NonClientFrameView what it
290 // thought its GetBoundsForClientView() were broke combobox drop down
291 // placement.
292 return platform_window_->GetBounds();
293 }
294
295 gfx::Rect DesktopWindowTreeHostWayland::GetRestoredBounds() const {
296 if (!previous_bounds_.IsEmpty())
297 return ToDIPRect(previous_bounds_);
298
299 return GetWindowBoundsInScreen();
300 }
301
302 std::string DesktopWindowTreeHostWayland::GetWorkspace() const {
303 return std::string();
304 }
305
306 gfx::Rect DesktopWindowTreeHostWayland::GetWorkAreaBoundsInScreen() const {
307 display::Screen *screen = display::Screen::GetScreen();
308 if (!screen)
309 NOTREACHED() << "Unable to retrieve valid display::Screen";
310
311 display::Display display = screen->GetPrimaryDisplay();
312 return ToDIPRect(display.bounds());
313 }
314
315 void DesktopWindowTreeHostWayland::SetShape(std::unique_ptr<SkRegion>
316 native_region) {
317 // NOTIMPLEMENTED();
318 }
319
320 void DesktopWindowTreeHostWayland::Activate() {
321 if (state_ & Visible) {
322 OnActivationChanged(true);
323 }
324 }
325
326 void DesktopWindowTreeHostWayland::Deactivate() {
327 OnActivationChanged(false);
328 }
329
330 bool DesktopWindowTreeHostWayland::IsActive() const {
331 return state_ & Active;
332 }
333
334 void DesktopWindowTreeHostWayland::Maximize() {
335 if (state_ & Maximized)
336 return;
337
338 state_ |= Maximized;
339 state_ &= ~Minimized;
340 previous_bounds_ = platform_window_->GetBounds();
341 platform_window_->Maximize();
342 if (IsMinimized())
343 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED);
344 }
345
346 void DesktopWindowTreeHostWayland::Minimize() {
347 if (state_ & Minimized)
348 return;
349
350 state_ |= Minimized;
351 previous_bounds_ = platform_window_->GetBounds();
352 ReleaseCapture();
353 compositor()->SetVisible(false);
354 content_window_->Hide();
355 platform_window_->Minimize();
356 Relayout();
357 }
358
359 void DesktopWindowTreeHostWayland::Restore() {
360 state_ &= ~Maximized;
361 if (state_ & Minimized) {
362 content_window_->Show();
363 compositor()->SetVisible(true);
364 }
365
366 platform_window_->Restore();
367 platform_window_->SetBounds(previous_bounds_);
368 previous_bounds_ = gfx::Rect();
369 Relayout();
370 if (state_ & Minimized) {
371 state_ &= ~Minimized;
372 ShowWindow();
373 }
374 }
375
376 bool DesktopWindowTreeHostWayland::IsMaximized() const {
377 return !IsFullscreen() && (state_ & Maximized);
378 }
379
380 bool DesktopWindowTreeHostWayland::IsMinimized() const {
381 return state_ & Minimized;
382 }
383
384 bool DesktopWindowTreeHostWayland::HasCapture() const {
385 return has_capture_;
386 }
387
388
389 void DesktopWindowTreeHostWayland::SetAlwaysOnTop(bool always_on_top) {
390 always_on_top_ = always_on_top;
391 }
392
393 bool DesktopWindowTreeHostWayland::IsAlwaysOnTop() const {
394 return always_on_top_;
395 }
396
397 void DesktopWindowTreeHostWayland::SetVisibleOnAllWorkspaces(
398 bool always_visible) {
399 NOTIMPLEMENTED();
400 }
401
402 bool DesktopWindowTreeHostWayland::IsVisibleOnAllWorkspaces() const {
403 return false;
404 }
405
406 bool DesktopWindowTreeHostWayland::SetWindowTitle(const base::string16& title) {
407 if (title.compare(title_)) {
408 platform_window_->SetTitle(title);
409 title_ = title;
410 return true;
411 }
412
413 return false;
414 }
415
416 void DesktopWindowTreeHostWayland::ClearNativeFocus() {
417 // This method is weird and misnamed. Instead of clearing the native focus,
418 // it sets the focus to our |content_window_|, which will trigger a cascade
419 // of focus changes into views.
420 if (content_window_ && aura::client::GetFocusClient(content_window_) &&
421 content_window_->Contains(
422 aura::client::GetFocusClient(content_window_)->GetFocusedWindow())) {
423 aura::client::GetFocusClient(content_window_)->FocusWindow(content_window_);
424 }
425 }
426
427 Widget::MoveLoopResult DesktopWindowTreeHostWayland::RunMoveLoop(
428 const gfx::Vector2d& drag_offset,
429 Widget::MoveLoopSource source,
430 Widget::MoveLoopEscapeBehavior escape_behavior) {
431 NOTIMPLEMENTED();
432 return Widget::MOVE_LOOP_SUCCESSFUL;
433 }
434
435
436 void DesktopWindowTreeHostWayland::EndMoveLoop() {
437 NOTIMPLEMENTED();
438 }
439
440 void DesktopWindowTreeHostWayland::SetVisibilityChangedAnimationsEnabled(
441 bool value) {
442 // Much like the previous NativeWidgetGtk, we don't have anything to do here.
443 }
444
445 bool DesktopWindowTreeHostWayland::ShouldUseNativeFrame() const {
446 return false;
447 }
448
449 bool DesktopWindowTreeHostWayland::ShouldWindowContentsBeTransparent() const {
450 return false;
451 }
452
453 void DesktopWindowTreeHostWayland::FrameTypeChanged() {
454 Widget::FrameType new_type =
455 native_widget_delegate_->AsWidget()->frame_type();
456 if (new_type == Widget::FRAME_TYPE_DEFAULT) {
457 // The default is determined by Widget::InitParams::remove_standard_frame
458 // and does not change.
459 return;
460 }
461
462 // Replace the frame and layout the contents. Even though we don't have a
463 // swapable glass frame like on Windows, we still replace the frame because
464 // the button assets don't update otherwise.
465 native_widget_delegate_->AsWidget()->non_client_view()->UpdateFrame();
466 }
467
468 void DesktopWindowTreeHostWayland::SetFullscreen(bool fullscreen) {
469 NOTIMPLEMENTED();
470 }
471
472 bool DesktopWindowTreeHostWayland::IsFullscreen() const {
473 return state_ & FullScreen;
474 }
475
476 void DesktopWindowTreeHostWayland::SetOpacity(float opacity) {
477 content_window_->layer()->SetOpacity(opacity / 255.0);
478 }
479
480 void DesktopWindowTreeHostWayland::SetWindowIcons(
481 const gfx::ImageSkia& window_icon, const gfx::ImageSkia& app_icon) {
482 NOTIMPLEMENTED();
483 }
484
485 void DesktopWindowTreeHostWayland::InitModalType(ui::ModalType modal_type) {
486 switch (modal_type) {
487 case ui::MODAL_TYPE_NONE:
488 break;
489 default:
490 // TODO(erg): Figure out under what situations |modal_type| isn't
491 // none. The comment in desktop_native_widget_aura.cc suggests that this
492 // is rare.
493 NOTIMPLEMENTED();
494 }
495 }
496
497 void DesktopWindowTreeHostWayland::FlashFrame(bool flash_frame) {
498 NOTIMPLEMENTED();
499 }
500
501 void DesktopWindowTreeHostWayland::OnRootViewLayout() {
502 }
503
504 void DesktopWindowTreeHostWayland::OnNativeWidgetFocus() {
505 }
506
507 void DesktopWindowTreeHostWayland::OnNativeWidgetBlur() {
508 }
509
510 bool DesktopWindowTreeHostWayland::IsAnimatingClosed() const {
511 return false;
512 }
513
514 bool DesktopWindowTreeHostWayland::IsTranslucentWindowOpacitySupported() const {
515 return false;
516 }
517
518 void DesktopWindowTreeHostWayland::SizeConstraintsChanged() {
519 }
520
521 ////////////////////////////////////////////////////////////////////////////////
522 // DesktopWindowTreeHostWayland, aura::WindowTreeHost implementation:
523
524 gfx::Transform DesktopWindowTreeHostWayland::GetRootTransform() const {
525 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
526 aura::Window* win = const_cast<aura::Window*>(window());
527 display = display::Screen::GetScreen()->GetDisplayNearestWindow(win);
528
529 float scale = display.device_scale_factor();
530 gfx::Transform transform;
531 transform.Scale(scale, scale);
532 return transform;
533 }
534
535 ui::EventSource* DesktopWindowTreeHostWayland::GetEventSource() {
536 return this;
537 }
538
539 gfx::AcceleratedWidget DesktopWindowTreeHostWayland::GetAcceleratedWidget() {
540 return window_;
541 }
542
543 void DesktopWindowTreeHostWayland::ShowImpl() {
544 if (state_ & Visible)
545 return;
546
547 ShowWindowWithState(ui::SHOW_STATE_NORMAL);
548 native_widget_delegate_->OnNativeWidgetVisibilityChanged(true);
549 }
550
551 void DesktopWindowTreeHostWayland::HideImpl() {
552 if (!(state_ & Visible))
553 return;
554
555 state_ &= ~Visible;
556 platform_window_->Hide();
557 native_widget_delegate_->OnNativeWidgetVisibilityChanged(false);
558 }
559
560 gfx::Rect DesktopWindowTreeHostWayland::GetBounds() const {
561 return platform_window_->GetBounds();
562 }
563
564 void DesktopWindowTreeHostWayland::SetBounds(
565 const gfx::Rect& requested_bounds) {
566 gfx::Rect bounds(requested_bounds.origin(),
567 AdjustSize(requested_bounds.size()));
568 platform_window_->SetBounds(bounds);
569 }
570
571 gfx::Point DesktopWindowTreeHostWayland::GetLocationOnNativeScreen() const {
572 return platform_window_->GetBounds().origin();
573 }
574
575 void DesktopWindowTreeHostWayland::SetCapture() {
576 if (has_capture_)
577 return;
578
579 has_capture_ = true;
580 platform_window_->SetCapture();
581 }
582
583 void DesktopWindowTreeHostWayland::ReleaseCapture() {
584 platform_window_->ReleaseCapture();
585 OnLostCapture();
586 }
587
588 void DesktopWindowTreeHostWayland::ShowWindow() {
589 ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL;
590 if (IsMinimized()) {
591 show_state = ui::SHOW_STATE_MINIMIZED;
592 } else if (IsFullscreen()) {
593 show_state = ui::SHOW_STATE_FULLSCREEN;
594 } else if (IsMaximized()) {
595 show_state = ui::SHOW_STATE_MAXIMIZED;
596 } else if (!IsActive()) {
597 show_state = ui::SHOW_STATE_INACTIVE;
598 }
599
600 ShowWindowWithState(show_state);
601 }
602
603 void DesktopWindowTreeHostWayland::SetCursorNative(gfx::NativeCursor cursor) {
604 platform_window_->SetCursor(cursor.platform());
605 }
606
607 void DesktopWindowTreeHostWayland::MoveCursorToNative(
608 const gfx::Point& location) {
609 platform_window_->MoveCursorTo(location);
610 }
611
612 void DesktopWindowTreeHostWayland::OnCursorVisibilityChangedNative(bool show) {
613 // TODO(erg): Conditional on us enabling touch on desktop linux builds, do
614 // the same tap-to-click disabling here that chromeos does.
615 }
616
617 ////////////////////////////////////////////////////////////////////////////////
618 // ui::PlatformWindowDelegate implementation:
619 void DesktopWindowTreeHostWayland::OnBoundsChanged(
620 const gfx::Rect& new_bounds) {
621
622 native_widget_delegate_->AsWidget()->OnNativeWidgetMove();
623 OnHostResized(new_bounds.size());
624 ResetWindowRegion();
625 }
626
627 void DesktopWindowTreeHostWayland::OnDamageRect(const gfx::Rect& damaged_rect) {
628 compositor()->ScheduleRedrawRect(damaged_rect);
629 }
630
631 void DesktopWindowTreeHostWayland::OnAcceleratedWidgetDestroyed() {
632 gfx::AcceleratedWidget window = compositor()->ReleaseAcceleratedWidget();
633 DCHECK_EQ(window, window_);
634 window_ = gfx::kNullAcceleratedWidget;
635 }
636
637 void DesktopWindowTreeHostWayland::OnActivationChanged(bool active) {
638 if (active == (state_ & Active))
639 return;
640
641 if (active) {
642 // Make sure the stacking order is correct. The activated window should be
643 // first one in list of open windows.
644 std::list<gfx::AcceleratedWidget>& windows = open_windows();
645 DCHECK(windows.size());
646 if (windows.front() != window_) {
647 windows.remove(window_);
648 windows.insert(windows.begin(), window_);
649 }
650
651 state_ |= Active;
652 OnHostActivated();
653 } else {
654 state_ &= ~Active;
655 ReleaseCapture();
656 }
657
658 desktop_native_widget_aura_->HandleActivationChanged(active);
659 native_widget_delegate_->AsWidget()->GetRootView()->SchedulePaint();
660 }
661
662
663 void DesktopWindowTreeHostWayland::OnLostCapture() {
664 OnHostLostWindowCapture();
665 has_capture_ = false;
666 }
667
668 void DesktopWindowTreeHostWayland::OnAcceleratedWidgetAvailable(
669 gfx::AcceleratedWidget widget,
670 float device_pixel_ratio) {
671 window_ = widget;
672 CreateCompositor();
673 WindowTreeHost::OnAcceleratedWidgetAvailable();
674 }
675
676 void DesktopWindowTreeHostWayland::OnCloseRequest() {
677 Close();
678 }
679
680 void DesktopWindowTreeHostWayland::OnClosed() {
681 CloseNow();
682 }
683
684 void DesktopWindowTreeHostWayland::OnWindowStateChanged(
685 ui::PlatformWindowState new_state) {
686
687 switch (new_state) {
688 case ui::PLATFORM_WINDOW_STATE_MAXIMIZED: {
689 if (state_ & Minimized) {
690 content_window_->Show();
691 compositor()->SetVisible(true);
692 state_ &= ~Minimized;
693 }
694 platform_window_->SetBounds(previous_bounds_);
695 previous_bounds_ = gfx::Rect();
696 Relayout();
697 break;
698 }
699 default:
700 break;
701 }
702 }
703
704 void DesktopWindowTreeHostWayland::DispatchEvent(ui::Event* event) {
705 SendEventToProcessor(event);
706 }
707
708 ////////////////////////////////////////////////////////////////////////////////
709 // DesktopWindowTreeHostWayland, private:
710
711 void DesktopWindowTreeHostWayland::Relayout() {
712 Widget* widget = native_widget_delegate_->AsWidget();
713 NonClientView* non_client_view = widget->non_client_view();
714 // non_client_view may be NULL, especially during creation.
715 if (non_client_view) {
716 non_client_view->client_view()->InvalidateLayout();
717 non_client_view->InvalidateLayout();
718 }
719 widget->GetRootView()->Layout();
720 ResetWindowRegion();
721 }
722
723 std::list<gfx::AcceleratedWidget>&
724 DesktopWindowTreeHostWayland::open_windows() {
725 if (!open_windows_)
726 open_windows_ = new std::list<gfx::AcceleratedWidget>();
727 return *open_windows_;
728 }
729
730 gfx::Size DesktopWindowTreeHostWayland::AdjustSize(
731 const gfx::Size& requested_size_in_pixels) {
732
733 std::vector<display::Display> displays =
734 display::Screen::GetScreen()->GetAllDisplays();
735 // Compare against all monitor sizes. The window manager can move the window
736 // to whichever monitor it wants.
737 for (size_t i = 0; i < displays.size(); ++i) {
738 if (requested_size_in_pixels == displays[i].GetSizeInPixel()) {
739 return gfx::Size(requested_size_in_pixels.width() - 1,
740 requested_size_in_pixels.height() - 1);
741 }
742 }
743
744 // Do not request a 0x0 window size.
745 gfx::Size size_in_pixels = requested_size_in_pixels;
746 size_in_pixels.SetToMax(gfx::Size(1, 1));
747 return size_in_pixels;
748 }
749
750 gfx::Rect DesktopWindowTreeHostWayland::ToDIPRect(
751 const gfx::Rect& rect_in_pixels) const {
752 gfx::RectF rect_in_dip = gfx::RectF(rect_in_pixels);
753 GetRootTransform().TransformRectReverse(&rect_in_dip);
754 return gfx::ToEnclosingRect(rect_in_dip);
755 }
756
757 gfx::Rect DesktopWindowTreeHostWayland::ToPixelRect(
758 const gfx::Rect& rect_in_dip) const {
759 gfx::RectF rect_in_pixels = gfx::RectF(rect_in_dip);
760 GetRootTransform().TransformRect(&rect_in_pixels);
761 return gfx::ToEnclosingRect(rect_in_pixels);
762 }
763
764 void DesktopWindowTreeHostWayland::ResetWindowRegion() {
765 if (custom_window_shape_)
766 return;
767
768 gfx::Path window_mask;
769 const gfx::Rect& bounds_in_pixels = platform_window_->GetBounds();
770 if (!IsMaximized() && !IsFullscreen()) {
771 views::Widget* widget = native_widget_delegate_->AsWidget();
772 if (widget->non_client_view()) {
773 // Some frame views define a custom (non-rectangular) window mask. If
774 // so, use it to define the window shape. If not, fall through.
775 widget->non_client_view()->GetWindowMask(bounds_in_pixels.size(),
776 &window_mask);
777 }
778 }
779 }
780
781 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_window_tree_host_wayland.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698