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

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: rebase on tonikitoo's CL (included) Created 4 years, 6 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 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()->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(SkRegion* native_region) {
316 // NOTIMPLEMENTED();
317 }
318
319 void DesktopWindowTreeHostWayland::Activate() {
320 if (state_ & Visible) {
321 OnActivationChanged(true);
322 }
323 }
324
325 void DesktopWindowTreeHostWayland::Deactivate() {
326 OnActivationChanged(false);
327 }
328
329 bool DesktopWindowTreeHostWayland::IsActive() const {
330 return state_ & Active;
331 }
332
333 void DesktopWindowTreeHostWayland::Maximize() {
334 if (state_ & Maximized)
335 return;
336
337 state_ |= Maximized;
338 state_ &= ~Minimized;
339 previous_bounds_ = platform_window_->GetBounds();
340 platform_window_->Maximize();
341 if (IsMinimized())
342 ShowWindowWithState(ui::SHOW_STATE_MAXIMIZED);
343 }
344
345 void DesktopWindowTreeHostWayland::Minimize() {
346 if (state_ & Minimized)
347 return;
348
349 state_ |= Minimized;
350 previous_bounds_ = platform_window_->GetBounds();
351 ReleaseCapture();
352 compositor()->SetVisible(false);
353 content_window_->Hide();
354 platform_window_->Minimize();
355 Relayout();
356 }
357
358 void DesktopWindowTreeHostWayland::Restore() {
359 state_ &= ~Maximized;
360 if (state_ & Minimized) {
361 content_window_->Show();
362 compositor()->SetVisible(true);
363 }
364
365 platform_window_->Restore();
366 platform_window_->SetBounds(previous_bounds_);
367 previous_bounds_ = gfx::Rect();
368 Relayout();
369 if (state_ & Minimized) {
370 state_ &= ~Minimized;
371 ShowWindow();
372 }
373 }
374
375 bool DesktopWindowTreeHostWayland::IsMaximized() const {
376 return !IsFullscreen() && (state_ & Maximized);
377 }
378
379 bool DesktopWindowTreeHostWayland::IsMinimized() const {
380 return state_ & Minimized;
381 }
382
383 bool DesktopWindowTreeHostWayland::HasCapture() const {
384 return has_capture_;
385 }
386
387
388 void DesktopWindowTreeHostWayland::SetAlwaysOnTop(bool always_on_top) {
389 always_on_top_ = always_on_top;
390 }
391
392 bool DesktopWindowTreeHostWayland::IsAlwaysOnTop() const {
393 return always_on_top_;
394 }
395
396 void DesktopWindowTreeHostWayland::SetVisibleOnAllWorkspaces(
397 bool always_visible) {
398 NOTIMPLEMENTED();
399 }
400
401 bool DesktopWindowTreeHostWayland::SetWindowTitle(const base::string16& title) {
402 if (title.compare(title_)) {
403 platform_window_->SetTitle(title);
404 title_ = title;
405 return true;
406 }
407
408 return false;
409 }
410
411 void DesktopWindowTreeHostWayland::ClearNativeFocus() {
412 // This method is weird and misnamed. Instead of clearing the native focus,
413 // it sets the focus to our |content_window_|, which will trigger a cascade
414 // of focus changes into views.
415 if (content_window_ && aura::client::GetFocusClient(content_window_) &&
416 content_window_->Contains(
417 aura::client::GetFocusClient(content_window_)->GetFocusedWindow())) {
418 aura::client::GetFocusClient(content_window_)->FocusWindow(content_window_);
419 }
420 }
421
422 Widget::MoveLoopResult DesktopWindowTreeHostWayland::RunMoveLoop(
423 const gfx::Vector2d& drag_offset,
424 Widget::MoveLoopSource source,
425 Widget::MoveLoopEscapeBehavior escape_behavior) {
426 NOTIMPLEMENTED();
427 return Widget::MOVE_LOOP_SUCCESSFUL;
428 }
429
430
431 void DesktopWindowTreeHostWayland::EndMoveLoop() {
432 NOTIMPLEMENTED();
433 }
434
435 void DesktopWindowTreeHostWayland::SetVisibilityChangedAnimationsEnabled(
436 bool value) {
437 // Much like the previous NativeWidgetGtk, we don't have anything to do here.
438 }
439
440 bool DesktopWindowTreeHostWayland::ShouldUseNativeFrame() const {
441 return false;
442 }
443
444 bool DesktopWindowTreeHostWayland::ShouldWindowContentsBeTransparent() const {
445 return false;
446 }
447
448 void DesktopWindowTreeHostWayland::FrameTypeChanged() {
449 Widget::FrameType new_type =
450 native_widget_delegate_->AsWidget()->frame_type();
451 if (new_type == Widget::FRAME_TYPE_DEFAULT) {
452 // The default is determined by Widget::InitParams::remove_standard_frame
453 // and does not change.
454 return;
455 }
456
457 // Replace the frame and layout the contents. Even though we don't have a
458 // swapable glass frame like on Windows, we still replace the frame because
459 // the button assets don't update otherwise.
460 native_widget_delegate_->AsWidget()->non_client_view()->UpdateFrame();
461 }
462
463 void DesktopWindowTreeHostWayland::SetFullscreen(bool fullscreen) {
464 NOTIMPLEMENTED();
465 }
466
467 bool DesktopWindowTreeHostWayland::IsFullscreen() const {
468 return state_ & FullScreen;
469 }
470
471 void DesktopWindowTreeHostWayland::SetOpacity(float opacity) {
472 content_window_->layer()->SetOpacity(opacity / 255.0);
473 }
474
475 void DesktopWindowTreeHostWayland::SetWindowIcons(
476 const gfx::ImageSkia& window_icon, const gfx::ImageSkia& app_icon) {
477 NOTIMPLEMENTED();
478 }
479
480 void DesktopWindowTreeHostWayland::InitModalType(ui::ModalType modal_type) {
481 switch (modal_type) {
482 case ui::MODAL_TYPE_NONE:
483 break;
484 default:
485 // TODO(erg): Figure out under what situations |modal_type| isn't
486 // none. The comment in desktop_native_widget_aura.cc suggests that this
487 // is rare.
488 NOTIMPLEMENTED();
489 }
490 }
491
492 void DesktopWindowTreeHostWayland::FlashFrame(bool flash_frame) {
493 NOTIMPLEMENTED();
494 }
495
496 void DesktopWindowTreeHostWayland::OnRootViewLayout() {
497 }
498
499 void DesktopWindowTreeHostWayland::OnNativeWidgetFocus() {
500 }
501
502 void DesktopWindowTreeHostWayland::OnNativeWidgetBlur() {
503 }
504
505 bool DesktopWindowTreeHostWayland::IsAnimatingClosed() const {
506 return false;
507 }
508
509 bool DesktopWindowTreeHostWayland::IsTranslucentWindowOpacitySupported() const {
510 return false;
511 }
512
513 void DesktopWindowTreeHostWayland::SizeConstraintsChanged() {
514 }
515
516 ////////////////////////////////////////////////////////////////////////////////
517 // DesktopWindowTreeHostWayland, aura::WindowTreeHost implementation:
518
519 gfx::Transform DesktopWindowTreeHostWayland::GetRootTransform() const {
520 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
521 aura::Window* win = const_cast<aura::Window*>(window());
522 display = display::Screen::GetScreen()->GetDisplayNearestWindow(win);
523
524 float scale = display.device_scale_factor();
525 gfx::Transform transform;
526 transform.Scale(scale, scale);
527 return transform;
528 }
529
530 ui::EventSource* DesktopWindowTreeHostWayland::GetEventSource() {
531 return this;
532 }
533
534 gfx::AcceleratedWidget DesktopWindowTreeHostWayland::GetAcceleratedWidget() {
535 return window_;
536 }
537
538 void DesktopWindowTreeHostWayland::ShowImpl() {
539 if (state_ & Visible)
540 return;
541
542 ShowWindowWithState(ui::SHOW_STATE_NORMAL);
543 native_widget_delegate_->OnNativeWidgetVisibilityChanged(true);
544 }
545
546 void DesktopWindowTreeHostWayland::HideImpl() {
547 if (!(state_ & Visible))
548 return;
549
550 state_ &= ~Visible;
551 platform_window_->Hide();
552 native_widget_delegate_->OnNativeWidgetVisibilityChanged(false);
553 }
554
555 gfx::Rect DesktopWindowTreeHostWayland::GetBounds() const {
556 return platform_window_->GetBounds();
557 }
558
559 void DesktopWindowTreeHostWayland::SetBounds(
560 const gfx::Rect& requested_bounds) {
561 gfx::Rect bounds(requested_bounds.origin(),
562 AdjustSize(requested_bounds.size()));
563 platform_window_->SetBounds(bounds);
564 }
565
566 gfx::Point DesktopWindowTreeHostWayland::GetLocationOnNativeScreen() const {
567 return platform_window_->GetBounds().origin();
568 }
569
570 void DesktopWindowTreeHostWayland::SetCapture() {
571 if (has_capture_)
572 return;
573
574 has_capture_ = true;
575 platform_window_->SetCapture();
576 }
577
578 void DesktopWindowTreeHostWayland::ReleaseCapture() {
579 platform_window_->ReleaseCapture();
580 OnLostCapture();
581 }
582
583 void DesktopWindowTreeHostWayland::ShowWindow() {
584 ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL;
585 if (IsMinimized()) {
586 show_state = ui::SHOW_STATE_MINIMIZED;
587 } else if (IsFullscreen()) {
588 show_state = ui::SHOW_STATE_FULLSCREEN;
589 } else if (IsMaximized()) {
590 show_state = ui::SHOW_STATE_MAXIMIZED;
591 } else if (!IsActive()) {
592 show_state = ui::SHOW_STATE_INACTIVE;
593 }
594
595 ShowWindowWithState(show_state);
596 }
597
598 void DesktopWindowTreeHostWayland::SetCursorNative(gfx::NativeCursor cursor) {
599 platform_window_->SetCursor(cursor.platform());
600 }
601
602 void DesktopWindowTreeHostWayland::MoveCursorToNative(
603 const gfx::Point& location) {
604 platform_window_->MoveCursorTo(location);
605 }
606
607 void DesktopWindowTreeHostWayland::OnCursorVisibilityChangedNative(bool show) {
608 // TODO(erg): Conditional on us enabling touch on desktop linux builds, do
609 // the same tap-to-click disabling here that chromeos does.
610 }
611
612 ////////////////////////////////////////////////////////////////////////////////
613 // ui::PlatformWindowDelegate implementation:
614 void DesktopWindowTreeHostWayland::OnBoundsChanged(
615 const gfx::Rect& new_bounds) {
616
617 native_widget_delegate_->AsWidget()->OnNativeWidgetMove();
618 OnHostResized(new_bounds.size());
619 ResetWindowRegion();
620 }
621
622 void DesktopWindowTreeHostWayland::OnDamageRect(const gfx::Rect& damaged_rect) {
623 compositor()->ScheduleRedrawRect(damaged_rect);
624 }
625
626 void DesktopWindowTreeHostWayland::OnAcceleratedWidgetDestroyed() {
627 gfx::AcceleratedWidget window = compositor()->ReleaseAcceleratedWidget();
628 DCHECK_EQ(window, window_);
629 window_ = gfx::kNullAcceleratedWidget;
630 }
631
632 void DesktopWindowTreeHostWayland::OnActivationChanged(bool active) {
633 if (active == (state_ & Active))
634 return;
635
636 if (active) {
637 // Make sure the stacking order is correct. The activated window should be
638 // first one in list of open windows.
639 std::list<gfx::AcceleratedWidget>& windows = open_windows();
640 DCHECK(windows.size());
641 if (windows.front() != window_) {
642 windows.remove(window_);
643 windows.insert(windows.begin(), window_);
644 }
645
646 state_ |= Active;
647 OnHostActivated();
648 } else {
649 state_ &= ~Active;
650 ReleaseCapture();
651 }
652
653 desktop_native_widget_aura_->HandleActivationChanged(active);
654 native_widget_delegate_->AsWidget()->GetRootView()->SchedulePaint();
655 }
656
657
658 void DesktopWindowTreeHostWayland::OnLostCapture() {
659 OnHostLostWindowCapture();
660 has_capture_ = false;
661 }
662
663 void DesktopWindowTreeHostWayland::OnAcceleratedWidgetAvailable(
664 gfx::AcceleratedWidget widget,
665 float device_pixel_ratio) {
666 window_ = widget;
667 CreateCompositor();
668 WindowTreeHost::OnAcceleratedWidgetAvailable();
669 }
670
671 void DesktopWindowTreeHostWayland::OnCloseRequest() {
672 Close();
673 }
674
675 void DesktopWindowTreeHostWayland::OnClosed() {
676 CloseNow();
677 }
678
679 void DesktopWindowTreeHostWayland::OnWindowStateChanged(
680 ui::PlatformWindowState new_state) {
681
682 switch (new_state) {
683 case ui::PLATFORM_WINDOW_STATE_MAXIMIZED: {
684 if (state_ & Minimized) {
685 content_window_->Show();
686 compositor()->SetVisible(true);
687 state_ &= ~Minimized;
688 }
689 platform_window_->SetBounds(previous_bounds_);
690 previous_bounds_ = gfx::Rect();
691 Relayout();
692 break;
693 }
694 default:
695 break;
696 }
697 }
698
699 void DesktopWindowTreeHostWayland::DispatchEvent(ui::Event* event) {
700 SendEventToProcessor(event);
701 }
702
703 ////////////////////////////////////////////////////////////////////////////////
704 // DesktopWindowTreeHostWayland, private:
705
706 void DesktopWindowTreeHostWayland::Relayout() {
707 Widget* widget = native_widget_delegate_->AsWidget();
708 NonClientView* non_client_view = widget->non_client_view();
709 // non_client_view may be NULL, especially during creation.
710 if (non_client_view) {
711 non_client_view->client_view()->InvalidateLayout();
712 non_client_view->InvalidateLayout();
713 }
714 widget->GetRootView()->Layout();
715 ResetWindowRegion();
716 }
717
718 std::list<gfx::AcceleratedWidget>&
719 DesktopWindowTreeHostWayland::open_windows() {
720 if (!open_windows_)
721 open_windows_ = new std::list<gfx::AcceleratedWidget>();
722 return *open_windows_;
723 }
724
725 gfx::Size DesktopWindowTreeHostWayland::AdjustSize(
726 const gfx::Size& requested_size_in_pixels) {
727
728 std::vector<display::Display> displays =
729 display::Screen::GetScreen()->GetAllDisplays();
730 // Compare against all monitor sizes. The window manager can move the window
731 // to whichever monitor it wants.
732 for (size_t i = 0; i < displays.size(); ++i) {
733 if (requested_size_in_pixels == displays[i].GetSizeInPixel()) {
734 return gfx::Size(requested_size_in_pixels.width() - 1,
735 requested_size_in_pixels.height() - 1);
736 }
737 }
738
739 // Do not request a 0x0 window size.
740 gfx::Size size_in_pixels = requested_size_in_pixels;
741 size_in_pixels.SetToMax(gfx::Size(1, 1));
742 return size_in_pixels;
743 }
744
745 gfx::Rect DesktopWindowTreeHostWayland::ToDIPRect(
746 const gfx::Rect& rect_in_pixels) const {
747 gfx::RectF rect_in_dip = gfx::RectF(rect_in_pixels);
748 GetRootTransform().TransformRectReverse(&rect_in_dip);
749 return gfx::ToEnclosingRect(rect_in_dip);
750 }
751
752 gfx::Rect DesktopWindowTreeHostWayland::ToPixelRect(
753 const gfx::Rect& rect_in_dip) const {
754 gfx::RectF rect_in_pixels = gfx::RectF(rect_in_dip);
755 GetRootTransform().TransformRect(&rect_in_pixels);
756 return gfx::ToEnclosingRect(rect_in_pixels);
757 }
758
759 void DesktopWindowTreeHostWayland::ResetWindowRegion() {
760 if (custom_window_shape_)
761 return;
762
763 gfx::Path window_mask;
764 const gfx::Rect& bounds_in_pixels = platform_window_->GetBounds();
765 if (!IsMaximized() && !IsFullscreen()) {
766 views::Widget* widget = native_widget_delegate_->AsWidget();
767 if (widget->non_client_view()) {
768 // Some frame views define a custom (non-rectangular) window mask. If
769 // so, use it to define the window shape. If not, fall through.
770 widget->non_client_view()->GetWindowMask(bounds_in_pixels.size(),
771 &window_mask);
772 }
773 }
774 }
775
776 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698