OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/mus/native_widget_mus.h" | 5 #include "ui/views/mus/native_widget_mus.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "ui/aura/client/window_tree_client.h" | 21 #include "ui/aura/client/window_tree_client.h" |
22 #include "ui/aura/env.h" | 22 #include "ui/aura/env.h" |
23 #include "ui/aura/layout_manager.h" | 23 #include "ui/aura/layout_manager.h" |
24 #include "ui/aura/mus/mus_util.h" | 24 #include "ui/aura/mus/mus_util.h" |
25 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
26 #include "ui/aura/window_property.h" | 26 #include "ui/aura/window_property.h" |
27 #include "ui/base/hit_test.h" | 27 #include "ui/base/hit_test.h" |
28 #include "ui/events/event.h" | 28 #include "ui/events/event.h" |
29 #include "ui/gfx/canvas.h" | 29 #include "ui/gfx/canvas.h" |
30 #include "ui/gfx/geometry/mojo/geometry_type_converters.h" | 30 #include "ui/gfx/geometry/mojo/geometry_type_converters.h" |
| 31 #include "ui/gfx/native_widget_types.h" |
31 #include "ui/gfx/path.h" | 32 #include "ui/gfx/path.h" |
32 #include "ui/native_theme/native_theme_aura.h" | 33 #include "ui/native_theme/native_theme_aura.h" |
33 #include "ui/platform_window/platform_window_delegate.h" | 34 #include "ui/platform_window/platform_window_delegate.h" |
34 #include "ui/views/mus/platform_window_mus.h" | |
35 #include "ui/views/mus/surface_context_factory.h" | 35 #include "ui/views/mus/surface_context_factory.h" |
36 #include "ui/views/mus/window_manager_constants_converters.h" | 36 #include "ui/views/mus/window_manager_constants_converters.h" |
37 #include "ui/views/mus/window_manager_frame_values.h" | 37 #include "ui/views/mus/window_manager_frame_values.h" |
38 #include "ui/views/mus/window_tree_host_mus.h" | 38 #include "ui/views/mus/window_tree_host_mus.h" |
39 #include "ui/views/widget/native_widget_aura.h" | 39 #include "ui/views/widget/native_widget_aura.h" |
40 #include "ui/views/widget/widget_delegate.h" | 40 #include "ui/views/widget/widget_delegate.h" |
41 #include "ui/views/window/custom_frame_view.h" | 41 #include "ui/views/window/custom_frame_view.h" |
42 #include "ui/wm/core/base_focus_rules.h" | 42 #include "ui/wm/core/base_focus_rules.h" |
43 #include "ui/wm/core/capture_controller.h" | 43 #include "ui/wm/core/capture_controller.h" |
44 #include "ui/wm/core/cursor_manager.h" | 44 #include "ui/wm/core/cursor_manager.h" |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 case mus::mojom::ShowState::FULLSCREEN: | 406 case mus::mojom::ShowState::FULLSCREEN: |
407 state = ui::PLATFORM_WINDOW_STATE_FULLSCREEN; | 407 state = ui::PLATFORM_WINDOW_STATE_FULLSCREEN; |
408 break; | 408 break; |
409 } | 409 } |
410 platform_window_delegate()->OnWindowStateChanged(state); | 410 platform_window_delegate()->OnWindowStateChanged(state); |
411 } | 411 } |
412 void OnWindowDestroyed(mus::Window* window) override { | 412 void OnWindowDestroyed(mus::Window* window) override { |
413 DCHECK_EQ(mus_window(), window); | 413 DCHECK_EQ(mus_window(), window); |
414 platform_window_delegate()->OnClosed(); | 414 platform_window_delegate()->OnClosed(); |
415 } | 415 } |
| 416 void OnWindowBoundsChanging(mus::Window* window, |
| 417 const gfx::Rect& old_bounds, |
| 418 const gfx::Rect& new_bounds) override { |
| 419 DCHECK_EQ(window, mus_window()); |
| 420 window_tree_host()->SetBounds(new_bounds); |
| 421 } |
416 void OnWindowFocusChanged(mus::Window* gained_focus, | 422 void OnWindowFocusChanged(mus::Window* gained_focus, |
417 mus::Window* lost_focus) override { | 423 mus::Window* lost_focus) override { |
418 if (gained_focus == mus_window()) | 424 if (gained_focus == mus_window()) |
419 platform_window_delegate()->OnActivationChanged(true); | 425 platform_window_delegate()->OnActivationChanged(true); |
420 else if (lost_focus == mus_window()) | 426 else if (lost_focus == mus_window()) |
421 platform_window_delegate()->OnActivationChanged(false); | 427 platform_window_delegate()->OnActivationChanged(false); |
422 } | 428 } |
423 void OnRequestClose(mus::Window* window) override { | 429 void OnRequestClose(mus::Window* window) override { |
424 platform_window_delegate()->OnCloseRequest(); | 430 platform_window_delegate()->OnCloseRequest(); |
425 } | 431 } |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 | 638 |
633 //////////////////////////////////////////////////////////////////////////////// | 639 //////////////////////////////////////////////////////////////////////////////// |
634 // NativeWidgetMus, internal::NativeWidgetPrivate implementation: | 640 // NativeWidgetMus, internal::NativeWidgetPrivate implementation: |
635 | 641 |
636 NonClientFrameView* NativeWidgetMus::CreateNonClientFrameView() { | 642 NonClientFrameView* NativeWidgetMus::CreateNonClientFrameView() { |
637 return new ClientSideNonClientFrameView(GetWidget()); | 643 return new ClientSideNonClientFrameView(GetWidget()); |
638 } | 644 } |
639 | 645 |
640 void NativeWidgetMus::InitNativeWidget(const Widget::InitParams& params) { | 646 void NativeWidgetMus::InitNativeWidget(const Widget::InitParams& params) { |
641 NativeWidgetAura::RegisterNativeWidgetForWindow(this, content_); | 647 NativeWidgetAura::RegisterNativeWidgetForWindow(this, content_); |
| 648 aura::Window* hosted_window = window_tree_host_->window(); |
642 | 649 |
643 ownership_ = params.ownership; | 650 ownership_ = params.ownership; |
644 window_->SetCanFocus(params.activatable == | 651 window_->SetCanFocus(params.activatable == |
645 Widget::InitParams::ACTIVATABLE_YES); | 652 Widget::InitParams::ACTIVATABLE_YES); |
646 | 653 |
647 window_tree_host_->AddObserver(this); | 654 window_tree_host_->AddObserver(this); |
648 window_tree_host_->InitHost(); | 655 window_tree_host_->InitHost(); |
649 window_tree_host_->window()->SetProperty(kMusWindow, window_); | 656 hosted_window->SetProperty(kMusWindow, window_); |
650 | 657 |
651 focus_client_.reset( | 658 focus_client_.reset( |
652 new wm::FocusController(new FocusRulesImpl(window_tree_host_->window()))); | 659 new wm::FocusController(new FocusRulesImpl(hosted_window))); |
653 | 660 |
654 aura::client::SetFocusClient(window_tree_host_->window(), | 661 aura::client::SetFocusClient(hosted_window, focus_client_.get()); |
655 focus_client_.get()); | 662 aura::client::SetActivationClient(hosted_window, focus_client_.get()); |
656 aura::client::SetActivationClient(window_tree_host_->window(), | |
657 focus_client_.get()); | |
658 screen_position_client_.reset(new ScreenPositionClientMus(window_)); | 663 screen_position_client_.reset(new ScreenPositionClientMus(window_)); |
659 aura::client::SetScreenPositionClient(window_tree_host_->window(), | 664 aura::client::SetScreenPositionClient(hosted_window, |
660 screen_position_client_.get()); | 665 screen_position_client_.get()); |
661 | 666 |
662 // TODO(erg): Remove this check when mash/wm/frame/move_event_handler.cc's | 667 // TODO(erg): Remove this check when mash/wm/frame/move_event_handler.cc's |
663 // direct usage of mus::Window::SetPredefinedCursor() is switched to a | 668 // direct usage of mus::Window::SetPredefinedCursor() is switched to a |
664 // private method on WindowManagerClient. | 669 // private method on WindowManagerClient. |
665 if (surface_type_ == mus::mojom::SurfaceType::DEFAULT) { | 670 if (surface_type_ == mus::mojom::SurfaceType::DEFAULT) { |
666 cursor_manager_.reset(new wm::CursorManager( | 671 cursor_manager_.reset(new wm::CursorManager( |
667 base::WrapUnique(new NativeCursorManagerMus(window_)))); | 672 base::WrapUnique(new NativeCursorManagerMus(window_)))); |
668 aura::client::SetCursorClient(window_tree_host_->window(), | 673 aura::client::SetCursorClient(hosted_window, cursor_manager_.get()); |
669 cursor_manager_.get()); | |
670 } | 674 } |
671 | 675 |
672 window_tree_client_.reset( | 676 window_tree_client_.reset( |
673 new NativeWidgetMusWindowTreeClient(window_tree_host_->window())); | 677 new NativeWidgetMusWindowTreeClient(hosted_window)); |
674 window_tree_host_->window()->AddPreTargetHandler(focus_client_.get()); | 678 hosted_window->AddPreTargetHandler(focus_client_.get()); |
675 window_tree_host_->window()->SetLayoutManager( | 679 hosted_window->SetLayoutManager( |
676 new ContentWindowLayoutManager(window_tree_host_->window(), content_)); | 680 new ContentWindowLayoutManager(hosted_window, content_)); |
677 capture_client_.reset( | 681 capture_client_.reset(new MusCaptureClient(hosted_window, content_, window_)); |
678 new MusCaptureClient(window_tree_host_->window(), content_, window_)); | |
679 | 682 |
680 content_->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 683 content_->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
681 content_->Init(ui::LAYER_TEXTURED); | 684 content_->Init(ui::LAYER_TEXTURED); |
682 if (window_->visible()) | 685 if (window_->visible()) |
683 content_->Show(); | 686 content_->Show(); |
684 content_->SetTransparent(true); | 687 content_->SetTransparent(true); |
685 content_->SetFillsBoundsCompletely(false); | 688 content_->SetFillsBoundsCompletely(false); |
686 window_tree_host_->window()->AddChild(content_); | 689 hosted_window->AddChild(content_); |
687 | 690 |
688 // Set-up transiency if appropriate. | 691 // Set-up transiency if appropriate. |
689 if (params.parent && !params.child) { | 692 if (params.parent && !params.child) { |
690 aura::Window* parent_root = params.parent->GetRootWindow(); | 693 aura::Window* parent_root = params.parent->GetRootWindow(); |
691 mus::Window* parent_mus = parent_root->GetProperty(kMusWindow); | 694 mus::Window* parent_mus = parent_root->GetProperty(kMusWindow); |
692 if (parent_mus) | 695 if (parent_mus) |
693 parent_mus->AddTransientWindow(window_); | 696 parent_mus->AddTransientWindow(window_); |
694 } | 697 } |
695 | 698 |
696 if (params.parent_mus) | 699 if (params.parent_mus) |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 void NativeWidgetMus::SetBounds(const gfx::Rect& bounds) { | 886 void NativeWidgetMus::SetBounds(const gfx::Rect& bounds) { |
884 if (!(window_ && window_tree_host_)) | 887 if (!(window_ && window_tree_host_)) |
885 return; | 888 return; |
886 | 889 |
887 gfx::Size size(bounds.size()); | 890 gfx::Size size(bounds.size()); |
888 const gfx::Size min_size = GetMinimumSize(); | 891 const gfx::Size min_size = GetMinimumSize(); |
889 const gfx::Size max_size = GetMaximumSize(); | 892 const gfx::Size max_size = GetMaximumSize(); |
890 if (!max_size.IsEmpty()) | 893 if (!max_size.IsEmpty()) |
891 size.SetToMin(max_size); | 894 size.SetToMin(max_size); |
892 size.SetToMax(min_size); | 895 size.SetToMax(min_size); |
893 window_tree_host_->SetBounds(gfx::Rect(bounds.origin(), size)); | |
894 window_->SetBounds(gfx::Rect(bounds.origin(), size)); | 896 window_->SetBounds(gfx::Rect(bounds.origin(), size)); |
895 } | 897 } |
896 | 898 |
897 void NativeWidgetMus::SetSize(const gfx::Size& size) { | 899 void NativeWidgetMus::SetSize(const gfx::Size& size) { |
898 if (!window_tree_host_) | 900 if (!window_tree_host_) |
899 return; | 901 return; |
900 | 902 |
901 gfx::Rect bounds = window_tree_host_->GetBounds(); | 903 gfx::Rect bounds = window_tree_host_->GetBounds(); |
902 SetBounds(gfx::Rect(bounds.origin(), size)); | 904 SetBounds(gfx::Rect(bounds.origin(), size)); |
903 } | 905 } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 bool NativeWidgetMus::IsMinimized() const { | 1025 bool NativeWidgetMus::IsMinimized() const { |
1024 return mus_window_observer_ && | 1026 return mus_window_observer_ && |
1025 mus_window_observer_->show_state() == mus::mojom::ShowState::MINIMIZED; | 1027 mus_window_observer_->show_state() == mus::mojom::ShowState::MINIMIZED; |
1026 } | 1028 } |
1027 | 1029 |
1028 void NativeWidgetMus::Restore() { | 1030 void NativeWidgetMus::Restore() { |
1029 SetShowState(mus::mojom::ShowState::NORMAL); | 1031 SetShowState(mus::mojom::ShowState::NORMAL); |
1030 } | 1032 } |
1031 | 1033 |
1032 void NativeWidgetMus::SetFullscreen(bool fullscreen) { | 1034 void NativeWidgetMus::SetFullscreen(bool fullscreen) { |
1033 if (!window_tree_host_ || IsFullscreen() == fullscreen) | 1035 if (IsFullscreen() == fullscreen) |
1034 return; | 1036 return; |
1035 if (fullscreen) { | 1037 if (fullscreen) { |
1036 show_state_before_fullscreen_ = mus_window_observer_->show_state(); | 1038 show_state_before_fullscreen_ = mus_window_observer_->show_state(); |
1037 window_tree_host_->platform_window()->ToggleFullscreen(); | 1039 // TODO(markdittmer): Fullscreen not implemented in mus::Window. |
1038 } else { | 1040 } else { |
1039 switch (show_state_before_fullscreen_) { | 1041 switch (show_state_before_fullscreen_) { |
1040 case mus::mojom::ShowState::MAXIMIZED: | 1042 case mus::mojom::ShowState::MAXIMIZED: |
1041 Maximize(); | 1043 Maximize(); |
1042 break; | 1044 break; |
1043 case mus::mojom::ShowState::MINIMIZED: | 1045 case mus::mojom::ShowState::MINIMIZED: |
1044 Minimize(); | 1046 Minimize(); |
1045 break; | 1047 break; |
1046 case mus::mojom::ShowState::DEFAULT: | 1048 case mus::mojom::ShowState::DEFAULT: |
1047 case mus::mojom::ShowState::NORMAL: | 1049 case mus::mojom::ShowState::NORMAL: |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1359 | 1361 |
1360 gfx::Path mask_path; | 1362 gfx::Path mask_path; |
1361 native_widget_delegate_->GetHitTestMask(&mask_path); | 1363 native_widget_delegate_->GetHitTestMask(&mask_path); |
1362 // TODO(jamescook): Use the full path for the mask. | 1364 // TODO(jamescook): Use the full path for the mask. |
1363 gfx::Rect mask_rect = | 1365 gfx::Rect mask_rect = |
1364 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); | 1366 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); |
1365 window_->SetHitTestMask(mask_rect); | 1367 window_->SetHitTestMask(mask_rect); |
1366 } | 1368 } |
1367 | 1369 |
1368 } // namespace views | 1370 } // namespace views |
OLD | NEW |