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 "mash/wm/shadow_controller.h" |
| 6 |
| 7 #include "components/mus/public/cpp/window.h" |
| 8 #include "components/mus/public/cpp/window_tree_connection.h" |
| 9 #include "mash/wm/property_util.h" |
| 10 #include "mash/wm/shadow.h" |
| 11 |
| 12 namespace mash { |
| 13 namespace wm { |
| 14 namespace { |
| 15 |
| 16 // Returns the first ancestor of |from| (including |from|) that has a shadow. |
| 17 mus::Window* FindAncestorWithShadow(mus::Window* from) { |
| 18 mus::Window* result = from; |
| 19 while (result && !GetShadow(result)) |
| 20 result = result->parent(); |
| 21 // Small shadows never change. |
| 22 return result && GetShadow(result)->style() != Shadow::STYLE_SMALL ? result |
| 23 : nullptr; |
| 24 } |
| 25 |
| 26 } // namespace |
| 27 |
| 28 ShadowController::ShadowController(mus::WindowTreeConnection* window_tree) |
| 29 : window_tree_(window_tree), active_window_(nullptr) { |
| 30 window_tree_->AddObserver(this); |
| 31 SetActiveWindow(FindAncestorWithShadow(window_tree_->GetFocusedWindow())); |
| 32 } |
| 33 |
| 34 ShadowController::~ShadowController() { |
| 35 window_tree_->RemoveObserver(this); |
| 36 if (active_window_) |
| 37 active_window_->RemoveObserver(this); |
| 38 } |
| 39 |
| 40 void ShadowController::SetActiveWindow(mus::Window* window) { |
| 41 if (window == active_window_) |
| 42 return; |
| 43 |
| 44 if (active_window_) { |
| 45 GetShadow(active_window_)->SetStyle(Shadow::STYLE_INACTIVE); |
| 46 active_window_->RemoveObserver(this); |
| 47 } |
| 48 active_window_ = window; |
| 49 if (active_window_) { |
| 50 GetShadow(active_window_)->SetStyle(Shadow::STYLE_ACTIVE); |
| 51 active_window_->AddObserver(this); |
| 52 } |
| 53 } |
| 54 |
| 55 void ShadowController::OnWindowTreeFocusChanged(mus::Window* gained_focus, |
| 56 mus::Window* lost_focus) { |
| 57 SetActiveWindow(FindAncestorWithShadow(gained_focus)); |
| 58 } |
| 59 |
| 60 void ShadowController::OnWindowDestroying(mus::Window* window) { |
| 61 DCHECK_EQ(window, active_window_); |
| 62 SetActiveWindow(nullptr); |
| 63 } |
| 64 |
| 65 } // namespace wm |
| 66 } // namespace mash |
OLD | NEW |