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

Side by Side Diff: ash/mus/shadow_controller.cc

Issue 2539363005: Converts ash to use aura-mus (Closed)
Patch Set: merge Created 4 years 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
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 "ash/mus/shadow_controller.h" 5 #include "ash/mus/shadow_controller.h"
6 6
7 #include "ash/mus/property_util.h"
8 #include "ash/mus/shadow.h" 7 #include "ash/mus/shadow.h"
9 #include "services/ui/public/cpp/window.h" 8 #include "ui/aura/client/focus_client.h"
10 #include "services/ui/public/cpp/window_tree_client.h" 9 #include "ui/aura/env.h"
10 #include "ui/aura/window.h"
11 11
12 namespace ash { 12 namespace ash {
13 namespace mus { 13 namespace mus {
14 namespace { 14 namespace {
15 15
16 // Returns the first ancestor of |from| (including |from|) that has a shadow. 16 // Returns the first ancestor of |from| (including |from|) that has a shadow.
17 ui::Window* FindAncestorWithShadow(ui::Window* from) { 17 aura::Window* FindAncestorWithShadow(aura::Window* from) {
18 ui::Window* result = from; 18 aura::Window* result = from;
19 while (result && !GetShadow(result)) 19 while (result && !Shadow::Get(result))
20 result = result->parent(); 20 result = result->parent();
21 // Small shadows never change. 21 // Small shadows never change.
22 return result && GetShadow(result)->style() != Shadow::STYLE_SMALL ? result 22 return result && Shadow::Get(result)->style() != Shadow::STYLE_SMALL
23 : nullptr; 23 ? result
24 : nullptr;
24 } 25 }
25 26
26 } // namespace 27 } // namespace
27 28
28 ShadowController::ShadowController(ui::WindowTreeClient* window_tree) 29 ShadowController::ShadowController() {
29 : window_tree_(window_tree), active_window_(nullptr) { 30 aura::Env::GetInstance()->AddObserver(this);
30 window_tree_->AddObserver(this); 31 SetFocusClient(aura::Env::GetInstance()->active_focus_client());
31 SetActiveWindow(FindAncestorWithShadow(window_tree_->GetFocusedWindow()));
32 } 32 }
33 33
34 ShadowController::~ShadowController() { 34 ShadowController::~ShadowController() {
35 window_tree_->RemoveObserver(this); 35 aura::Env::GetInstance()->RemoveObserver(this);
36 if (active_window_) 36 if (active_window_)
37 active_window_->RemoveObserver(this); 37 active_window_->RemoveObserver(this);
38 if (active_focus_client_)
39 active_focus_client_->RemoveObserver(this);
38 } 40 }
39 41
40 void ShadowController::SetActiveWindow(ui::Window* window) { 42 void ShadowController::SetActiveWindow(aura::Window* window) {
43 window = FindAncestorWithShadow(window);
41 if (window == active_window_) 44 if (window == active_window_)
42 return; 45 return;
43 46
44 if (active_window_) { 47 if (active_window_) {
45 if (GetShadow(active_window_)) 48 if (Shadow::Get(active_window_))
46 GetShadow(active_window_)->SetStyle(Shadow::STYLE_INACTIVE); 49 Shadow::Get(active_window_)->SetStyle(Shadow::STYLE_INACTIVE);
47 active_window_->RemoveObserver(this); 50 active_window_->RemoveObserver(this);
48 } 51 }
49 active_window_ = window; 52 active_window_ = window;
50 if (active_window_) { 53 if (active_window_) {
51 GetShadow(active_window_)->SetStyle(Shadow::STYLE_ACTIVE); 54 Shadow::Get(active_window_)->SetStyle(Shadow::STYLE_ACTIVE);
52 active_window_->AddObserver(this); 55 active_window_->AddObserver(this);
53 } 56 }
54 } 57 }
55 58
56 void ShadowController::OnWindowTreeFocusChanged(ui::Window* gained_focus, 59 void ShadowController::SetFocusClient(aura::client::FocusClient* focus_client) {
57 ui::Window* lost_focus) { 60 if (active_focus_client_)
58 SetActiveWindow(FindAncestorWithShadow(gained_focus)); 61 active_focus_client_->RemoveObserver(this);
62 active_focus_client_ = focus_client;
63 if (active_focus_client_) {
64 active_focus_client_->AddObserver(this);
65 SetActiveWindow(active_focus_client_->GetFocusedWindow());
66 } else {
67 SetActiveWindow(nullptr);
68 }
59 } 69 }
60 70
61 void ShadowController::OnWindowDestroying(ui::Window* window) { 71 void ShadowController::OnWindowInitialized(aura::Window* window) {}
72
73 void ShadowController::OnActiveFocusClientChanged(
74 aura::client::FocusClient* focus_client,
75 aura::Window* window) {
76 SetFocusClient(focus_client);
77 }
78
79 void ShadowController::OnWindowFocused(aura::Window* gained_focus,
80 aura::Window* lost_focus) {
81 SetActiveWindow(gained_focus);
82 }
83
84 void ShadowController::OnWindowDestroying(aura::Window* window) {
62 DCHECK_EQ(window, active_window_); 85 DCHECK_EQ(window, active_window_);
63 SetActiveWindow(nullptr); 86 SetActiveWindow(nullptr);
64 } 87 }
65 88
66 } // namespace mus 89 } // namespace mus
67 } // namespace ash 90 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698