Chromium Code Reviews| 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/default_capture_client.h" | 21 #include "ui/aura/client/default_capture_client.h" |
| 22 #include "ui/aura/client/window_tree_client.h" | 22 #include "ui/aura/client/window_tree_client.h" |
| 23 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
| 24 #include "ui/aura/layout_manager.h" | 24 #include "ui/aura/layout_manager.h" |
| 25 #include "ui/aura/mus/mus_util.h" | 25 #include "ui/aura/mus/mus_util.h" |
| 26 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
| 27 #include "ui/aura/window_property.h" | 27 #include "ui/aura/window_property.h" |
| 28 #include "ui/base/hit_test.h" | 28 #include "ui/base/hit_test.h" |
| 29 #include "ui/events/event.h" | 29 #include "ui/events/event.h" |
| 30 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.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, |
| 656 aura::client::SetActivationClient(window_tree_host_->window(), | |
| 657 focus_client_.get()); | 663 focus_client_.get()); |
| 658 screen_position_client_.reset(new ScreenPositionClientMus(window_)); | 664 screen_position_client_.reset(new ScreenPositionClientMus(window_)); |
| 659 aura::client::SetScreenPositionClient(window_tree_host_->window(), | 665 aura::client::SetScreenPositionClient(hosted_window, |
| 660 screen_position_client_.get()); | 666 screen_position_client_.get()); |
| 661 | 667 |
| 662 // TODO(erg): Remove this check when mash/wm/frame/move_event_handler.cc's | 668 // 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 | 669 // direct usage of mus::Window::SetPredefinedCursor() is switched to a |
| 664 // private method on WindowManagerClient. | 670 // private method on WindowManagerClient. |
| 665 if (surface_type_ == mus::mojom::SurfaceType::DEFAULT) { | 671 if (surface_type_ == mus::mojom::SurfaceType::DEFAULT) { |
| 666 cursor_manager_.reset(new wm::CursorManager( | 672 cursor_manager_.reset(new wm::CursorManager( |
| 667 base::WrapUnique(new NativeCursorManagerMus(window_)))); | 673 base::WrapUnique(new NativeCursorManagerMus(window_)))); |
| 668 aura::client::SetCursorClient(window_tree_host_->window(), | 674 aura::client::SetCursorClient(hosted_window, |
| 669 cursor_manager_.get()); | 675 cursor_manager_.get()); |
| 670 } | 676 } |
| 671 | 677 |
| 672 window_tree_client_.reset( | 678 window_tree_client_.reset( |
| 673 new NativeWidgetMusWindowTreeClient(window_tree_host_->window())); | 679 new NativeWidgetMusWindowTreeClient(hosted_window)); |
| 674 window_tree_host_->window()->AddPreTargetHandler(focus_client_.get()); | 680 hosted_window->AddPreTargetHandler(focus_client_.get()); |
| 675 window_tree_host_->window()->SetLayoutManager( | 681 hosted_window->SetLayoutManager( |
| 676 new ContentWindowLayoutManager(window_tree_host_->window(), content_)); | 682 new ContentWindowLayoutManager(hosted_window, content_)); |
| 677 capture_client_.reset( | 683 capture_client_.reset( |
| 678 new MusCaptureClient(window_tree_host_->window(), content_, window_)); | 684 new MusCaptureClient(hosted_window, content_, window_)); |
| 679 | 685 |
| 680 content_->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 686 content_->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
| 681 content_->Init(ui::LAYER_TEXTURED); | 687 content_->Init(ui::LAYER_TEXTURED); |
| 682 if (window_->visible()) | 688 if (window_->visible()) |
| 683 content_->Show(); | 689 content_->Show(); |
| 684 content_->SetTransparent(true); | 690 content_->SetTransparent(true); |
| 685 content_->SetFillsBoundsCompletely(false); | 691 content_->SetFillsBoundsCompletely(false); |
| 686 window_tree_host_->window()->AddChild(content_); | 692 hosted_window->AddChild(content_); |
| 687 | 693 |
| 688 // Set-up transiency if appropriate. | 694 // Set-up transiency if appropriate. |
| 689 if (params.parent && !params.child) { | 695 if (params.parent && !params.child) { |
| 690 aura::Window* parent_root = params.parent->GetRootWindow(); | 696 aura::Window* parent_root = params.parent->GetRootWindow(); |
| 691 mus::Window* parent_mus = parent_root->GetProperty(kMusWindow); | 697 mus::Window* parent_mus = parent_root->GetProperty(kMusWindow); |
| 692 if (parent_mus) | 698 if (parent_mus) |
| 693 parent_mus->AddTransientWindow(window_); | 699 parent_mus->AddTransientWindow(window_); |
| 694 } | 700 } |
| 695 | 701 |
| 696 if (params.parent_mus) | 702 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) { | 889 void NativeWidgetMus::SetBounds(const gfx::Rect& bounds) { |
| 884 if (!(window_ && window_tree_host_)) | 890 if (!(window_ && window_tree_host_)) |
| 885 return; | 891 return; |
| 886 | 892 |
| 887 gfx::Size size(bounds.size()); | 893 gfx::Size size(bounds.size()); |
| 888 const gfx::Size min_size = GetMinimumSize(); | 894 const gfx::Size min_size = GetMinimumSize(); |
| 889 const gfx::Size max_size = GetMaximumSize(); | 895 const gfx::Size max_size = GetMaximumSize(); |
| 890 if (!max_size.IsEmpty()) | 896 if (!max_size.IsEmpty()) |
| 891 size.SetToMin(max_size); | 897 size.SetToMin(max_size); |
| 892 size.SetToMax(min_size); | 898 size.SetToMax(min_size); |
| 893 window_tree_host_->SetBounds(gfx::Rect(bounds.origin(), size)); | |
|
sadrul
2016/05/26 01:31:01
Would it make sense to keep this here, but to over
Mark Dittmer
2016/05/26 13:37:33
I have to admit I don't understand the suggestion.
| |
| 894 window_->SetBounds(gfx::Rect(bounds.origin(), size)); | 899 window_->SetBounds(gfx::Rect(bounds.origin(), size)); |
| 895 } | 900 } |
| 896 | 901 |
| 897 void NativeWidgetMus::SetSize(const gfx::Size& size) { | 902 void NativeWidgetMus::SetSize(const gfx::Size& size) { |
| 898 if (!window_tree_host_) | 903 if (!window_tree_host_) |
| 899 return; | 904 return; |
| 900 | 905 |
| 901 gfx::Rect bounds = window_tree_host_->GetBounds(); | 906 gfx::Rect bounds = window_tree_host_->GetBounds(); |
| 902 SetBounds(gfx::Rect(bounds.origin(), size)); | 907 SetBounds(gfx::Rect(bounds.origin(), size)); |
| 903 } | 908 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1023 bool NativeWidgetMus::IsMinimized() const { | 1028 bool NativeWidgetMus::IsMinimized() const { |
| 1024 return mus_window_observer_ && | 1029 return mus_window_observer_ && |
| 1025 mus_window_observer_->show_state() == mus::mojom::ShowState::MINIMIZED; | 1030 mus_window_observer_->show_state() == mus::mojom::ShowState::MINIMIZED; |
| 1026 } | 1031 } |
| 1027 | 1032 |
| 1028 void NativeWidgetMus::Restore() { | 1033 void NativeWidgetMus::Restore() { |
| 1029 SetShowState(mus::mojom::ShowState::NORMAL); | 1034 SetShowState(mus::mojom::ShowState::NORMAL); |
| 1030 } | 1035 } |
| 1031 | 1036 |
| 1032 void NativeWidgetMus::SetFullscreen(bool fullscreen) { | 1037 void NativeWidgetMus::SetFullscreen(bool fullscreen) { |
| 1033 if (!window_tree_host_ || IsFullscreen() == fullscreen) | 1038 if (IsFullscreen() == fullscreen) |
| 1034 return; | 1039 return; |
| 1035 if (fullscreen) { | 1040 if (fullscreen) { |
| 1036 show_state_before_fullscreen_ = mus_window_observer_->show_state(); | 1041 show_state_before_fullscreen_ = mus_window_observer_->show_state(); |
| 1037 window_tree_host_->platform_window()->ToggleFullscreen(); | 1042 // TODO(markdittmer): Fullscreen not implemented in mus::Window. |
| 1038 } else { | 1043 } else { |
| 1039 switch (show_state_before_fullscreen_) { | 1044 switch (show_state_before_fullscreen_) { |
| 1040 case mus::mojom::ShowState::MAXIMIZED: | 1045 case mus::mojom::ShowState::MAXIMIZED: |
| 1041 Maximize(); | 1046 Maximize(); |
| 1042 break; | 1047 break; |
| 1043 case mus::mojom::ShowState::MINIMIZED: | 1048 case mus::mojom::ShowState::MINIMIZED: |
| 1044 Minimize(); | 1049 Minimize(); |
| 1045 break; | 1050 break; |
| 1046 case mus::mojom::ShowState::DEFAULT: | 1051 case mus::mojom::ShowState::DEFAULT: |
| 1047 case mus::mojom::ShowState::NORMAL: | 1052 case mus::mojom::ShowState::NORMAL: |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1359 | 1364 |
| 1360 gfx::Path mask_path; | 1365 gfx::Path mask_path; |
| 1361 native_widget_delegate_->GetHitTestMask(&mask_path); | 1366 native_widget_delegate_->GetHitTestMask(&mask_path); |
| 1362 // TODO(jamescook): Use the full path for the mask. | 1367 // TODO(jamescook): Use the full path for the mask. |
| 1363 gfx::Rect mask_rect = | 1368 gfx::Rect mask_rect = |
| 1364 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); | 1369 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); |
| 1365 window_->SetHitTestMask(mask_rect); | 1370 window_->SetHitTestMask(mask_rect); |
| 1366 } | 1371 } |
| 1367 | 1372 |
| 1368 } // namespace views | 1373 } // namespace views |
| OLD | NEW |