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

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

Issue 2049723002: views/mus: Chaneg how Widget activation works in mus. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/wm/core/focus_controller.h » ('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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 bool SupportsChildActivation(aura::Window* window) const override { 66 bool SupportsChildActivation(aura::Window* window) const override {
67 return root_ == window; 67 return root_ == window;
68 } 68 }
69 69
70 private: 70 private:
71 aura::Window* root_; 71 aura::Window* root_;
72 72
73 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl); 73 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl);
74 }; 74 };
75 75
76 // This makes sure that an aura::Window focused (or activated) through the
77 // aura::client::FocusClient (or ActivationClient) focuses (or activates) the
78 // corresponding mus::Window too.
79 class FocusControllerMus : public wm::FocusController {
80 public:
81 explicit FocusControllerMus(wm::FocusRules* rules) : FocusController(rules) {}
82 ~FocusControllerMus() override {}
83
84 private:
85 void FocusWindow(aura::Window* window) override {
86 FocusController::FocusWindow(window);
87 if (window) {
88 mus::Window* mus_window =
89 window->GetRootWindow()->GetProperty(kMusWindow);
90 if (mus_window)
91 mus_window->SetFocus();
92 }
93 }
94
95 DISALLOW_COPY_AND_ASSIGN(FocusControllerMus);
96 };
97
76 class ContentWindowLayoutManager : public aura::LayoutManager { 98 class ContentWindowLayoutManager : public aura::LayoutManager {
77 public: 99 public:
78 ContentWindowLayoutManager(aura::Window* outer, aura::Window* inner) 100 ContentWindowLayoutManager(aura::Window* outer, aura::Window* inner)
79 : outer_(outer), inner_(inner) {} 101 : outer_(outer), inner_(inner) {}
80 ~ContentWindowLayoutManager() override {} 102 ~ContentWindowLayoutManager() override {}
81 103
82 private: 104 private:
83 // aura::LayoutManager: 105 // aura::LayoutManager:
84 void OnWindowResized() override { inner_->SetBounds(outer_->bounds()); } 106 void OnWindowResized() override { inner_->SetBounds(outer_->bounds()); }
85 void OnWindowAddedToLayout(aura::Window* child) override { 107 void OnWindowAddedToLayout(aura::Window* child) override {
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 678
657 ownership_ = params.ownership; 679 ownership_ = params.ownership;
658 window_->SetCanFocus(params.activatable == 680 window_->SetCanFocus(params.activatable ==
659 Widget::InitParams::ACTIVATABLE_YES); 681 Widget::InitParams::ACTIVATABLE_YES);
660 682
661 window_tree_host_->AddObserver(this); 683 window_tree_host_->AddObserver(this);
662 window_tree_host_->InitHost(); 684 window_tree_host_->InitHost();
663 hosted_window->SetProperty(kMusWindow, window_); 685 hosted_window->SetProperty(kMusWindow, window_);
664 686
665 focus_client_.reset( 687 focus_client_.reset(
666 new wm::FocusController(new FocusRulesImpl(hosted_window))); 688 new FocusControllerMus(new FocusRulesImpl(hosted_window)));
667 689
668 aura::client::SetFocusClient(hosted_window, focus_client_.get()); 690 aura::client::SetFocusClient(hosted_window, focus_client_.get());
669 aura::client::SetActivationClient(hosted_window, focus_client_.get()); 691 aura::client::SetActivationClient(hosted_window, focus_client_.get());
670 screen_position_client_.reset(new ScreenPositionClientMus(window_)); 692 screen_position_client_.reset(new ScreenPositionClientMus(window_));
671 aura::client::SetScreenPositionClient(hosted_window, 693 aura::client::SetScreenPositionClient(hosted_window,
672 screen_position_client_.get()); 694 screen_position_client_.get());
673 695
674 // TODO(erg): Remove this check when ash/mus/frame/move_event_handler.cc's 696 // TODO(erg): Remove this check when ash/mus/frame/move_event_handler.cc's
675 // direct usage of mus::Window::SetPredefinedCursor() is switched to a 697 // direct usage of mus::Window::SetPredefinedCursor() is switched to a
676 // private method on WindowManagerClient. 698 // private method on WindowManagerClient.
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 GetWidget()->SetInitialFocus(state); 996 GetWidget()->SetInitialFocus(state);
975 } 997 }
976 } 998 }
977 999
978 bool NativeWidgetMus::IsVisible() const { 1000 bool NativeWidgetMus::IsVisible() const {
979 // TODO(beng): this should probably be wired thru PlatformWindow. 1001 // TODO(beng): this should probably be wired thru PlatformWindow.
980 return window_ && window_->visible(); 1002 return window_ && window_->visible();
981 } 1003 }
982 1004
983 void NativeWidgetMus::Activate() { 1005 void NativeWidgetMus::Activate() {
984 if (window_)
985 window_->SetFocus();
986 static_cast<aura::client::ActivationClient*>(focus_client_.get()) 1006 static_cast<aura::client::ActivationClient*>(focus_client_.get())
987 ->ActivateWindow(content_); 1007 ->ActivateWindow(content_);
1008 // FocusControllerMus should have focused |window_| when |content_| is
1009 // activated.
1010 DCHECK(!window_ || window_->HasFocus());
988 } 1011 }
989 1012
990 void NativeWidgetMus::Deactivate() { 1013 void NativeWidgetMus::Deactivate() {
991 if (IsActive()) 1014 if (IsActive())
992 window_->window_tree()->ClearFocus(); 1015 window_->window_tree()->ClearFocus();
993 } 1016 }
994 1017
995 bool NativeWidgetMus::IsActive() const { 1018 bool NativeWidgetMus::IsActive() const {
996 mus::Window* focused = 1019 mus::Window* focused =
997 window_ ? window_->window_tree()->GetFocusedWindow() : nullptr; 1020 window_ ? window_->window_tree()->GetFocusedWindow() : nullptr;
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 1392
1370 gfx::Path mask_path; 1393 gfx::Path mask_path;
1371 native_widget_delegate_->GetHitTestMask(&mask_path); 1394 native_widget_delegate_->GetHitTestMask(&mask_path);
1372 // TODO(jamescook): Use the full path for the mask. 1395 // TODO(jamescook): Use the full path for the mask.
1373 gfx::Rect mask_rect = 1396 gfx::Rect mask_rect =
1374 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); 1397 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds()));
1375 window_->SetHitTestMask(mask_rect); 1398 window_->SetHitTestMask(mask_rect);
1376 } 1399 }
1377 1400
1378 } // namespace views 1401 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/BUILD.gn ('k') | ui/wm/core/focus_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698