| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/mus/shadow_controller.h" | |
| 6 | |
| 7 #include "ash/mus/shadow.h" | |
| 8 #include "ui/aura/client/focus_client.h" | |
| 9 #include "ui/aura/env.h" | |
| 10 #include "ui/aura/window.h" | |
| 11 | |
| 12 namespace ash { | |
| 13 namespace mus { | |
| 14 namespace { | |
| 15 | |
| 16 // Returns the first ancestor of |from| (including |from|) that has a shadow. | |
| 17 aura::Window* FindAncestorWithShadow(aura::Window* from) { | |
| 18 aura::Window* result = from; | |
| 19 while (result && !Shadow::Get(result)) | |
| 20 result = result->parent(); | |
| 21 // Small shadows never change. | |
| 22 return result && Shadow::Get(result)->style() != Shadow::STYLE_SMALL | |
| 23 ? result | |
| 24 : nullptr; | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 ShadowController::ShadowController() { | |
| 30 aura::Env::GetInstance()->AddObserver(this); | |
| 31 SetFocusClient(aura::Env::GetInstance()->active_focus_client()); | |
| 32 } | |
| 33 | |
| 34 ShadowController::~ShadowController() { | |
| 35 aura::Env::GetInstance()->RemoveObserver(this); | |
| 36 if (active_window_) | |
| 37 active_window_->RemoveObserver(this); | |
| 38 if (active_focus_client_) | |
| 39 active_focus_client_->RemoveObserver(this); | |
| 40 } | |
| 41 | |
| 42 void ShadowController::SetActiveWindow(aura::Window* window) { | |
| 43 window = FindAncestorWithShadow(window); | |
| 44 if (window == active_window_) | |
| 45 return; | |
| 46 | |
| 47 if (active_window_) { | |
| 48 if (Shadow::Get(active_window_)) | |
| 49 Shadow::Get(active_window_)->SetStyle(Shadow::STYLE_INACTIVE); | |
| 50 active_window_->RemoveObserver(this); | |
| 51 } | |
| 52 active_window_ = window; | |
| 53 if (active_window_) { | |
| 54 Shadow::Get(active_window_)->SetStyle(Shadow::STYLE_ACTIVE); | |
| 55 active_window_->AddObserver(this); | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 void ShadowController::SetFocusClient(aura::client::FocusClient* focus_client) { | |
| 60 if (active_focus_client_) | |
| 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 } | |
| 69 } | |
| 70 | |
| 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) { | |
| 85 DCHECK_EQ(window, active_window_); | |
| 86 SetActiveWindow(nullptr); | |
| 87 } | |
| 88 | |
| 89 } // namespace mus | |
| 90 } // namespace ash | |
| OLD | NEW |