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

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

Issue 1991673002: views/mus: Fix window activation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test Created 4 years, 7 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 | « no previous file | 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/macros.h" 7 #include "base/macros.h"
8 #include "base/threading/thread_task_runner_handle.h" 8 #include "base/threading/thread_task_runner_handle.h"
9 #include "components/mus/public/cpp/property_type_converters.h" 9 #include "components/mus/public/cpp/property_type_converters.h"
10 #include "components/mus/public/cpp/window.h" 10 #include "components/mus/public/cpp/window.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 DECLARE_WINDOW_PROPERTY_TYPE(mus::Window*); 44 DECLARE_WINDOW_PROPERTY_TYPE(mus::Window*);
45 45
46 namespace views { 46 namespace views {
47 namespace { 47 namespace {
48 48
49 DEFINE_WINDOW_PROPERTY_KEY(mus::Window*, kMusWindow, nullptr); 49 DEFINE_WINDOW_PROPERTY_KEY(mus::Window*, kMusWindow, nullptr);
50 50
51 MUS_DEFINE_WINDOW_PROPERTY_KEY(NativeWidgetMus*, kNativeWidgetMusKey, nullptr); 51 MUS_DEFINE_WINDOW_PROPERTY_KEY(NativeWidgetMus*, kNativeWidgetMusKey, nullptr);
52 52
53 // TODO: figure out what this should be. 53 // This ensures that only the top-level aura Window can be activated.
54 class FocusRulesImpl : public wm::BaseFocusRules { 54 class FocusRulesImpl : public wm::BaseFocusRules {
55 public: 55 public:
56 FocusRulesImpl() {} 56 explicit FocusRulesImpl(aura::Window* root) : root_(root) {}
57 ~FocusRulesImpl() override {} 57 ~FocusRulesImpl() override {}
58 58
59 bool SupportsChildActivation(aura::Window* window) const override { 59 bool SupportsChildActivation(aura::Window* window) const override {
60 return true; 60 return root_ == window;
61 } 61 }
62 62
63 private: 63 private:
64 aura::Window* root_;
65
64 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl); 66 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl);
65 }; 67 };
66 68
67 class ContentWindowLayoutManager : public aura::LayoutManager { 69 class ContentWindowLayoutManager : public aura::LayoutManager {
68 public: 70 public:
69 ContentWindowLayoutManager(aura::Window* outer, aura::Window* inner) 71 ContentWindowLayoutManager(aura::Window* outer, aura::Window* inner)
70 : outer_(outer), inner_(inner) {} 72 : outer_(outer), inner_(inner) {}
71 ~ContentWindowLayoutManager() override {} 73 ~ContentWindowLayoutManager() override {}
72 74
73 private: 75 private:
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 NativeWidgetAura::RegisterNativeWidgetForWindow(this, content_); 560 NativeWidgetAura::RegisterNativeWidgetForWindow(this, content_);
559 561
560 ownership_ = params.ownership; 562 ownership_ = params.ownership;
561 window_->SetCanFocus(params.activatable == 563 window_->SetCanFocus(params.activatable ==
562 Widget::InitParams::ACTIVATABLE_YES); 564 Widget::InitParams::ACTIVATABLE_YES);
563 565
564 window_tree_host_->AddObserver(this); 566 window_tree_host_->AddObserver(this);
565 window_tree_host_->InitHost(); 567 window_tree_host_->InitHost();
566 window_tree_host_->window()->SetProperty(kMusWindow, window_); 568 window_tree_host_->window()->SetProperty(kMusWindow, window_);
567 569
568 focus_client_.reset(new wm::FocusController(new FocusRulesImpl)); 570 focus_client_.reset(
571 new wm::FocusController(new FocusRulesImpl(window_tree_host_->window())));
569 572
570 aura::client::SetFocusClient(window_tree_host_->window(), 573 aura::client::SetFocusClient(window_tree_host_->window(),
571 focus_client_.get()); 574 focus_client_.get());
572 aura::client::SetActivationClient(window_tree_host_->window(), 575 aura::client::SetActivationClient(window_tree_host_->window(),
573 focus_client_.get()); 576 focus_client_.get());
574 screen_position_client_.reset(new ScreenPositionClientMus(window_)); 577 screen_position_client_.reset(new ScreenPositionClientMus(window_));
575 aura::client::SetScreenPositionClient(window_tree_host_->window(), 578 aura::client::SetScreenPositionClient(window_tree_host_->window(),
576 screen_position_client_.get()); 579 screen_position_client_.get());
577 580
578 // TODO(erg): Remove this check when mash/wm/frame/move_event_handler.cc's 581 // TODO(erg): Remove this check when mash/wm/frame/move_event_handler.cc's
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 return true; 1015 return true;
1013 } 1016 }
1014 1017
1015 void NativeWidgetMus::ClearNativeFocus() { 1018 void NativeWidgetMus::ClearNativeFocus() {
1016 if (!IsActive()) 1019 if (!IsActive())
1017 return; 1020 return;
1018 mus::Window* focused = 1021 mus::Window* focused =
1019 window_ ? window_->connection()->GetFocusedWindow() : nullptr; 1022 window_ ? window_->connection()->GetFocusedWindow() : nullptr;
1020 if (focused && window_->Contains(focused) && focused != window_) 1023 if (focused && window_->Contains(focused) && focused != window_)
1021 window_->SetFocus(); 1024 window_->SetFocus();
1025 // Move aura-focus back to |content_|, so that the Widget still receives
1026 // events correctly.
1027 aura::client::GetFocusClient(content_)->ResetFocusWithinActiveWindow(
1028 content_);
1022 } 1029 }
1023 1030
1024 gfx::Rect NativeWidgetMus::GetWorkAreaBoundsInScreen() const { 1031 gfx::Rect NativeWidgetMus::GetWorkAreaBoundsInScreen() const {
1025 // NOTIMPLEMENTED(); 1032 // NOTIMPLEMENTED();
1026 return gfx::Rect(); 1033 return gfx::Rect();
1027 } 1034 }
1028 1035
1029 Widget::MoveLoopResult NativeWidgetMus::RunMoveLoop( 1036 Widget::MoveLoopResult NativeWidgetMus::RunMoveLoop(
1030 const gfx::Vector2d& drag_offset, 1037 const gfx::Vector2d& drag_offset,
1031 Widget::MoveLoopSource source, 1038 Widget::MoveLoopSource source,
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 GetNativeWindow()->Show(); 1230 GetNativeWindow()->Show();
1224 } else { 1231 } else {
1225 window_tree_host_->Hide(); 1232 window_tree_host_->Hide();
1226 window_->SetVisible(false); 1233 window_->SetVisible(false);
1227 GetNativeWindow()->Hide(); 1234 GetNativeWindow()->Hide();
1228 } 1235 }
1229 native_widget_delegate_->OnNativeWidgetVisibilityChanged(window->visible()); 1236 native_widget_delegate_->OnNativeWidgetVisibilityChanged(window->visible());
1230 } 1237 }
1231 1238
1232 } // namespace views 1239 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/mus/native_widget_mus_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698