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

Unified Diff: mash/wm/shadow_controller.cc

Issue 1492323003: Updates shadow when active window changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mash/wm/shadow_controller.h ('k') | mash/wm/window_manager_application.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mash/wm/shadow_controller.cc
diff --git a/mash/wm/shadow_controller.cc b/mash/wm/shadow_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b7f91f130149c9a99c111bcf1dbbf1aca5b7d0a9
--- /dev/null
+++ b/mash/wm/shadow_controller.cc
@@ -0,0 +1,66 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mash/wm/shadow_controller.h"
+
+#include "components/mus/public/cpp/window.h"
+#include "components/mus/public/cpp/window_tree_connection.h"
+#include "mash/wm/property_util.h"
+#include "mash/wm/shadow.h"
+
+namespace mash {
+namespace wm {
+namespace {
+
+// Returns the first ancestor of |from| (including |from|) that has a shadow.
+mus::Window* FindAncestorWithShadow(mus::Window* from) {
+ mus::Window* result = from;
+ while (result && !GetShadow(result))
+ result = result->parent();
+ // Small shadows never change.
+ return result && GetShadow(result)->style() != Shadow::STYLE_SMALL ? result
+ : nullptr;
+}
+
+} // namespace
+
+ShadowController::ShadowController(mus::WindowTreeConnection* window_tree)
+ : window_tree_(window_tree), active_window_(nullptr) {
+ window_tree_->AddObserver(this);
+ SetActiveWindow(FindAncestorWithShadow(window_tree_->GetFocusedWindow()));
+}
+
+ShadowController::~ShadowController() {
+ window_tree_->RemoveObserver(this);
+ if (active_window_)
+ active_window_->RemoveObserver(this);
+}
+
+void ShadowController::SetActiveWindow(mus::Window* window) {
+ if (window == active_window_)
+ return;
+
+ if (active_window_) {
+ GetShadow(active_window_)->SetStyle(Shadow::STYLE_INACTIVE);
+ active_window_->RemoveObserver(this);
+ }
+ active_window_ = window;
+ if (active_window_) {
+ GetShadow(active_window_)->SetStyle(Shadow::STYLE_ACTIVE);
+ active_window_->AddObserver(this);
+ }
+}
+
+void ShadowController::OnWindowTreeFocusChanged(mus::Window* gained_focus,
+ mus::Window* lost_focus) {
+ SetActiveWindow(FindAncestorWithShadow(gained_focus));
+}
+
+void ShadowController::OnWindowDestroying(mus::Window* window) {
+ DCHECK_EQ(window, active_window_);
+ SetActiveWindow(nullptr);
+}
+
+} // namespace wm
+} // namespace mash
« no previous file with comments | « mash/wm/shadow_controller.h ('k') | mash/wm/window_manager_application.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698