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

Side by Side Diff: ui/views/mus/native_widget_mus.cc

Issue 2009853002: Finish eliminating PlatformWindowMus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add DCHECK for bounds change; git cl format 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
« no previous file with comments | « ui/views/mus/BUILD.gn ('k') | ui/views/mus/native_widget_mus_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
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/path.h" 30 #include "ui/gfx/path.h"
31 #include "ui/native_theme/native_theme_aura.h" 31 #include "ui/native_theme/native_theme_aura.h"
32 #include "ui/platform_window/platform_window_delegate.h" 32 #include "ui/platform_window/platform_window_delegate.h"
33 #include "ui/views/mus/platform_window_mus.h"
34 #include "ui/views/mus/surface_context_factory.h" 33 #include "ui/views/mus/surface_context_factory.h"
35 #include "ui/views/mus/window_manager_constants_converters.h" 34 #include "ui/views/mus/window_manager_constants_converters.h"
36 #include "ui/views/mus/window_manager_frame_values.h" 35 #include "ui/views/mus/window_manager_frame_values.h"
37 #include "ui/views/mus/window_tree_host_mus.h" 36 #include "ui/views/mus/window_tree_host_mus.h"
38 #include "ui/views/widget/native_widget_aura.h" 37 #include "ui/views/widget/native_widget_aura.h"
39 #include "ui/views/widget/widget_delegate.h" 38 #include "ui/views/widget/widget_delegate.h"
40 #include "ui/views/window/custom_frame_view.h" 39 #include "ui/views/window/custom_frame_view.h"
41 #include "ui/wm/core/base_focus_rules.h" 40 #include "ui/wm/core/base_focus_rules.h"
42 #include "ui/wm/core/capture_controller.h" 41 #include "ui/wm/core/capture_controller.h"
43 #include "ui/wm/core/cursor_manager.h" 42 #include "ui/wm/core/cursor_manager.h"
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 case mus::mojom::ShowState::FULLSCREEN: 404 case mus::mojom::ShowState::FULLSCREEN:
406 state = ui::PLATFORM_WINDOW_STATE_FULLSCREEN; 405 state = ui::PLATFORM_WINDOW_STATE_FULLSCREEN;
407 break; 406 break;
408 } 407 }
409 platform_window_delegate()->OnWindowStateChanged(state); 408 platform_window_delegate()->OnWindowStateChanged(state);
410 } 409 }
411 void OnWindowDestroyed(mus::Window* window) override { 410 void OnWindowDestroyed(mus::Window* window) override {
412 DCHECK_EQ(mus_window(), window); 411 DCHECK_EQ(mus_window(), window);
413 platform_window_delegate()->OnClosed(); 412 platform_window_delegate()->OnClosed();
414 } 413 }
414 void OnWindowBoundsChanging(mus::Window* window,
415 const gfx::Rect& old_bounds,
416 const gfx::Rect& new_bounds) override {
417 DCHECK_EQ(window, mus_window());
418 window_tree_host()->SetBounds(new_bounds);
419 }
415 void OnWindowFocusChanged(mus::Window* gained_focus, 420 void OnWindowFocusChanged(mus::Window* gained_focus,
416 mus::Window* lost_focus) override { 421 mus::Window* lost_focus) override {
417 if (gained_focus == mus_window()) 422 if (gained_focus == mus_window())
418 platform_window_delegate()->OnActivationChanged(true); 423 platform_window_delegate()->OnActivationChanged(true);
419 else if (lost_focus == mus_window()) 424 else if (lost_focus == mus_window())
420 platform_window_delegate()->OnActivationChanged(false); 425 platform_window_delegate()->OnActivationChanged(false);
421 } 426 }
422 void OnRequestClose(mus::Window* window) override { 427 void OnRequestClose(mus::Window* window) override {
423 platform_window_delegate()->OnCloseRequest(); 428 platform_window_delegate()->OnCloseRequest();
424 } 429 }
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 636
632 //////////////////////////////////////////////////////////////////////////////// 637 ////////////////////////////////////////////////////////////////////////////////
633 // NativeWidgetMus, internal::NativeWidgetPrivate implementation: 638 // NativeWidgetMus, internal::NativeWidgetPrivate implementation:
634 639
635 NonClientFrameView* NativeWidgetMus::CreateNonClientFrameView() { 640 NonClientFrameView* NativeWidgetMus::CreateNonClientFrameView() {
636 return new ClientSideNonClientFrameView(GetWidget()); 641 return new ClientSideNonClientFrameView(GetWidget());
637 } 642 }
638 643
639 void NativeWidgetMus::InitNativeWidget(const Widget::InitParams& params) { 644 void NativeWidgetMus::InitNativeWidget(const Widget::InitParams& params) {
640 NativeWidgetAura::RegisterNativeWidgetForWindow(this, content_); 645 NativeWidgetAura::RegisterNativeWidgetForWindow(this, content_);
646 aura::Window* hosted_window = window_tree_host_->window();
641 647
642 ownership_ = params.ownership; 648 ownership_ = params.ownership;
643 window_->SetCanFocus(params.activatable == 649 window_->SetCanFocus(params.activatable ==
644 Widget::InitParams::ACTIVATABLE_YES); 650 Widget::InitParams::ACTIVATABLE_YES);
645 651
646 window_tree_host_->AddObserver(this); 652 window_tree_host_->AddObserver(this);
647 window_tree_host_->InitHost(); 653 window_tree_host_->InitHost();
648 window_tree_host_->window()->SetProperty(kMusWindow, window_); 654 hosted_window->SetProperty(kMusWindow, window_);
649 655
650 focus_client_.reset( 656 focus_client_.reset(
651 new wm::FocusController(new FocusRulesImpl(window_tree_host_->window()))); 657 new wm::FocusController(new FocusRulesImpl(hosted_window)));
652 658
653 aura::client::SetFocusClient(window_tree_host_->window(), 659 aura::client::SetFocusClient(hosted_window, focus_client_.get());
654 focus_client_.get()); 660 aura::client::SetActivationClient(hosted_window, focus_client_.get());
655 aura::client::SetActivationClient(window_tree_host_->window(),
656 focus_client_.get());
657 screen_position_client_.reset(new ScreenPositionClientMus(window_)); 661 screen_position_client_.reset(new ScreenPositionClientMus(window_));
658 aura::client::SetScreenPositionClient(window_tree_host_->window(), 662 aura::client::SetScreenPositionClient(hosted_window,
659 screen_position_client_.get()); 663 screen_position_client_.get());
660 664
661 // TODO(erg): Remove this check when mash/wm/frame/move_event_handler.cc's 665 // TODO(erg): Remove this check when mash/wm/frame/move_event_handler.cc's
662 // direct usage of mus::Window::SetPredefinedCursor() is switched to a 666 // direct usage of mus::Window::SetPredefinedCursor() is switched to a
663 // private method on WindowManagerClient. 667 // private method on WindowManagerClient.
664 if (surface_type_ == mus::mojom::SurfaceType::DEFAULT) { 668 if (surface_type_ == mus::mojom::SurfaceType::DEFAULT) {
665 cursor_manager_.reset(new wm::CursorManager( 669 cursor_manager_.reset(new wm::CursorManager(
666 base::WrapUnique(new NativeCursorManagerMus(window_)))); 670 base::WrapUnique(new NativeCursorManagerMus(window_))));
667 aura::client::SetCursorClient(window_tree_host_->window(), 671 aura::client::SetCursorClient(hosted_window, cursor_manager_.get());
668 cursor_manager_.get());
669 } 672 }
670 673
671 window_tree_client_.reset( 674 window_tree_client_.reset(new NativeWidgetMusWindowTreeClient(hosted_window));
672 new NativeWidgetMusWindowTreeClient(window_tree_host_->window())); 675 hosted_window->AddPreTargetHandler(focus_client_.get());
673 window_tree_host_->window()->AddPreTargetHandler(focus_client_.get()); 676 hosted_window->SetLayoutManager(
674 window_tree_host_->window()->SetLayoutManager( 677 new ContentWindowLayoutManager(hosted_window, content_));
675 new ContentWindowLayoutManager(window_tree_host_->window(), content_)); 678 capture_client_.reset(new MusCaptureClient(hosted_window, content_, window_));
676 capture_client_.reset(
677 new MusCaptureClient(window_tree_host_->window(), content_, window_));
678 679
679 content_->SetType(ui::wm::WINDOW_TYPE_NORMAL); 680 content_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
680 content_->Init(ui::LAYER_TEXTURED); 681 content_->Init(ui::LAYER_TEXTURED);
681 if (window_->visible()) 682 if (window_->visible())
682 content_->Show(); 683 content_->Show();
683 content_->SetTransparent(true); 684 content_->SetTransparent(true);
684 content_->SetFillsBoundsCompletely(false); 685 content_->SetFillsBoundsCompletely(false);
685 window_tree_host_->window()->AddChild(content_); 686 hosted_window->AddChild(content_);
686 687
687 // Set-up transiency if appropriate. 688 // Set-up transiency if appropriate.
688 if (params.parent && !params.child) { 689 if (params.parent && !params.child) {
689 aura::Window* parent_root = params.parent->GetRootWindow(); 690 aura::Window* parent_root = params.parent->GetRootWindow();
690 mus::Window* parent_mus = parent_root->GetProperty(kMusWindow); 691 mus::Window* parent_mus = parent_root->GetProperty(kMusWindow);
691 if (parent_mus) 692 if (parent_mus)
692 parent_mus->AddTransientWindow(window_); 693 parent_mus->AddTransientWindow(window_);
693 } 694 }
694 695
695 if (params.parent_mus) 696 if (params.parent_mus)
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 void NativeWidgetMus::SetBounds(const gfx::Rect& bounds) { 883 void NativeWidgetMus::SetBounds(const gfx::Rect& bounds) {
883 if (!(window_ && window_tree_host_)) 884 if (!(window_ && window_tree_host_))
884 return; 885 return;
885 886
886 gfx::Size size(bounds.size()); 887 gfx::Size size(bounds.size());
887 const gfx::Size min_size = GetMinimumSize(); 888 const gfx::Size min_size = GetMinimumSize();
888 const gfx::Size max_size = GetMaximumSize(); 889 const gfx::Size max_size = GetMaximumSize();
889 if (!max_size.IsEmpty()) 890 if (!max_size.IsEmpty())
890 size.SetToMin(max_size); 891 size.SetToMin(max_size);
891 size.SetToMax(min_size); 892 size.SetToMax(min_size);
892 window_tree_host_->SetBounds(gfx::Rect(bounds.origin(), size));
893 window_->SetBounds(gfx::Rect(bounds.origin(), size)); 893 window_->SetBounds(gfx::Rect(bounds.origin(), size));
894 // Observer on |window_tree_host_| expected to synchronously update bounds.
895 DCHECK(window_->bounds() == window_tree_host_->GetBounds());
894 } 896 }
895 897
896 void NativeWidgetMus::SetSize(const gfx::Size& size) { 898 void NativeWidgetMus::SetSize(const gfx::Size& size) {
897 if (!window_tree_host_) 899 if (!window_tree_host_)
898 return; 900 return;
899 901
900 gfx::Rect bounds = window_tree_host_->GetBounds(); 902 gfx::Rect bounds = window_tree_host_->GetBounds();
901 SetBounds(gfx::Rect(bounds.origin(), size)); 903 SetBounds(gfx::Rect(bounds.origin(), size));
902 } 904 }
903 905
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 bool NativeWidgetMus::IsMinimized() const { 1024 bool NativeWidgetMus::IsMinimized() const {
1023 return mus_window_observer_ && 1025 return mus_window_observer_ &&
1024 mus_window_observer_->show_state() == mus::mojom::ShowState::MINIMIZED; 1026 mus_window_observer_->show_state() == mus::mojom::ShowState::MINIMIZED;
1025 } 1027 }
1026 1028
1027 void NativeWidgetMus::Restore() { 1029 void NativeWidgetMus::Restore() {
1028 SetShowState(mus::mojom::ShowState::NORMAL); 1030 SetShowState(mus::mojom::ShowState::NORMAL);
1029 } 1031 }
1030 1032
1031 void NativeWidgetMus::SetFullscreen(bool fullscreen) { 1033 void NativeWidgetMus::SetFullscreen(bool fullscreen) {
1032 if (!window_tree_host_ || IsFullscreen() == fullscreen) 1034 if (IsFullscreen() == fullscreen)
1033 return; 1035 return;
1034 if (fullscreen) { 1036 if (fullscreen) {
1035 show_state_before_fullscreen_ = mus_window_observer_->show_state(); 1037 show_state_before_fullscreen_ = mus_window_observer_->show_state();
1036 window_tree_host_->platform_window()->ToggleFullscreen(); 1038 // TODO(markdittmer): Fullscreen not implemented in mus::Window.
1037 } else { 1039 } else {
1038 switch (show_state_before_fullscreen_) { 1040 switch (show_state_before_fullscreen_) {
1039 case mus::mojom::ShowState::MAXIMIZED: 1041 case mus::mojom::ShowState::MAXIMIZED:
1040 Maximize(); 1042 Maximize();
1041 break; 1043 break;
1042 case mus::mojom::ShowState::MINIMIZED: 1044 case mus::mojom::ShowState::MINIMIZED:
1043 Minimize(); 1045 Minimize();
1044 break; 1046 break;
1045 case mus::mojom::ShowState::DEFAULT: 1047 case mus::mojom::ShowState::DEFAULT:
1046 case mus::mojom::ShowState::NORMAL: 1048 case mus::mojom::ShowState::NORMAL:
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 1360
1359 gfx::Path mask_path; 1361 gfx::Path mask_path;
1360 native_widget_delegate_->GetHitTestMask(&mask_path); 1362 native_widget_delegate_->GetHitTestMask(&mask_path);
1361 // TODO(jamescook): Use the full path for the mask. 1363 // TODO(jamescook): Use the full path for the mask.
1362 gfx::Rect mask_rect = 1364 gfx::Rect mask_rect =
1363 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); 1365 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds()));
1364 window_->SetHitTestMask(mask_rect); 1366 window_->SetHitTestMask(mask_rect);
1365 } 1367 }
1366 1368
1367 } // namespace views 1369 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/BUILD.gn ('k') | ui/views/mus/native_widget_mus_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698