summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-26 19:45:53 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-26 19:45:53 +0000
commit55af5186e92169f066df06d3b099f90ca413b4db (patch)
tree24ecada46e0a47f0c9abe52ef04fc09ffae11d77 /ash
parent9f1cc3d4e433d6b5f1f1f39238fa53cd73e0d0ed (diff)
downloadchromium_src-55af5186e92169f066df06d3b099f90ca413b4db.zip
chromium_src-55af5186e92169f066df06d3b099f90ca413b4db.tar.gz
chromium_src-55af5186e92169f066df06d3b099f90ca413b4db.tar.bz2
Prevent a transient with 'kHideOnDeactivate' set from causing its transient parent to lose its active shadow.
http://crbug.com/120210 TEST=see bug Review URL: https://chromiumcodereview.appspot.com/9853030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128979 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/wm/shadow_controller.cc47
-rw-r--r--ash/wm/shadow_controller.h5
-rw-r--r--ash/wm/shadow_controller_unittest.cc37
3 files changed, 75 insertions, 14 deletions
diff --git a/ash/wm/shadow_controller.cc b/ash/wm/shadow_controller.cc
index 5b0a58b..6220a2f 100644
--- a/ash/wm/shadow_controller.cc
+++ b/ash/wm/shadow_controller.cc
@@ -49,6 +49,23 @@ bool ShouldUseSmallShadowForWindow(aura::Window* window) {
return false;
}
+// Returns the shadow style to be applied to |losing_active| when it is losing
+// active to |gaining_active|. |gaining_active| may be of a type that hides when
+// inactive, and as such we do not want to render |losing_active| as inactive.
+Shadow::Style GetShadowStyleForWindowLosingActive(
+ aura::Window* losing_active,
+ aura::Window* gaining_active) {
+ if (gaining_active && aura::client::GetHideOnDeactivate(gaining_active)) {
+ aura::Window::Windows::const_iterator it =
+ std::find(losing_active->transient_children().begin(),
+ losing_active->transient_children().end(),
+ gaining_active);
+ if (it != losing_active->transient_children().end())
+ return Shadow::STYLE_ACTIVE;
+ }
+ return Shadow::STYLE_INACTIVE;
+}
+
} // namespace
ShadowController::ShadowController() {
@@ -80,13 +97,9 @@ void ShadowController::OnWindowPropertyChanged(aura::Window* window,
return;
}
if (key == aura::client::kRootWindowActiveWindowKey) {
- aura::Window* inactive = reinterpret_cast<aura::Window*>(old);
- if (inactive)
- HandleWindowActivationChange(inactive, false);
- aura::Window* active =
- window->GetProperty(aura::client::kRootWindowActiveWindowKey);
- if (active)
- HandleWindowActivationChange(active, true);
+ HandleWindowActivationChange(
+ window->GetProperty(aura::client::kRootWindowActiveWindowKey),
+ reinterpret_cast<aura::Window*>(old));
return;
}
}
@@ -120,11 +133,21 @@ Shadow* ShadowController::GetShadowForWindow(aura::Window* window) {
return it != window_shadows_.end() ? it->second.get() : NULL;
}
-void ShadowController::HandleWindowActivationChange(aura::Window* window,
- bool active) {
- Shadow* shadow = GetShadowForWindow(window);
- if (shadow && !ShouldUseSmallShadowForWindow(window))
- shadow->SetStyle(active ? Shadow::STYLE_ACTIVE : Shadow::STYLE_INACTIVE);
+void ShadowController::HandleWindowActivationChange(
+ aura::Window* gaining_active,
+ aura::Window* losing_active) {
+ if (gaining_active) {
+ Shadow* shadow = GetShadowForWindow(gaining_active);
+ if (shadow && !ShouldUseSmallShadowForWindow(gaining_active))
+ shadow->SetStyle(Shadow::STYLE_ACTIVE);
+ }
+ if (losing_active) {
+ Shadow* shadow = GetShadowForWindow(losing_active);
+ if (shadow && !ShouldUseSmallShadowForWindow(losing_active)) {
+ shadow->SetStyle(GetShadowStyleForWindowLosingActive(losing_active,
+ gaining_active));
+ }
+ }
}
void ShadowController::HandlePossibleShadowVisibilityChange(
diff --git a/ash/wm/shadow_controller.h b/ash/wm/shadow_controller.h
index ea3862d..2a880c9 100644
--- a/ash/wm/shadow_controller.h
+++ b/ash/wm/shadow_controller.h
@@ -70,8 +70,9 @@ class ASH_EXPORT ShadowController : public aura::EnvObserver,
// exists.
Shadow* GetShadowForWindow(aura::Window* window);
- // Updates the shadow style for |window| based on whether it is |active|.
- void HandleWindowActivationChange(aura::Window* window, bool active);
+ // Updates the shadow styles for windows when activation changes.
+ void HandleWindowActivationChange(aura::Window* gaining_active,
+ aura::Window* losing_active);
// Shows or hides |window|'s shadow as needed (creating the shadow if
// necessary).
diff --git a/ash/wm/shadow_controller_unittest.cc b/ash/wm/shadow_controller_unittest.cc
index 8503168..db1edfc 100644
--- a/ash/wm/shadow_controller_unittest.cc
+++ b/ash/wm/shadow_controller_unittest.cc
@@ -14,6 +14,7 @@
#include "ash/wm/window_properties.h"
#include "ash/wm/window_util.h"
#include "base/memory/scoped_ptr.h"
+#include "ui/aura/client/activation_client.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/gfx/compositor/layer.h"
@@ -150,5 +151,41 @@ TEST_F(ShadowControllerTest, SmallShadowsForTooltipsAndMenus) {
EXPECT_EQ(Shadow::STYLE_SMALL, menu_shadow->style());
}
+// http://crbug.com/120210 - transient parents of certain types of transients
+// should not lose their shadow when they lose activation to the transient.
+TEST_F(ShadowControllerTest, TransientParentKeepsActiveShadow) {
+ ShadowController::TestApi api(
+ ash::Shell::GetInstance()->shadow_controller());
+
+ scoped_ptr<aura::Window> window1(new aura::Window(NULL));
+ window1->SetType(aura::client::WINDOW_TYPE_NORMAL);
+ window1->Init(ui::LAYER_TEXTURED);
+ window1->SetParent(NULL);
+ window1->SetBounds(gfx::Rect(10, 20, 300, 400));
+ window1->Show();
+ wm::ActivateWindow(window1.get());
+
+ // window1 is active, so style should have active appearance.
+ Shadow* shadow1 = api.GetShadowForWindow(window1.get());
+ ASSERT_TRUE(shadow1 != NULL);
+ EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style());
+
+ // Create a window that is transient to window1, and that has the 'hide on
+ // deactivate' property set. Upon activation, window1 should still have an
+ // active shadow.
+ scoped_ptr<aura::Window> window2(new aura::Window(NULL));
+ window2->SetType(aura::client::WINDOW_TYPE_NORMAL);
+ window2->Init(ui::LAYER_TEXTURED);
+ window2->SetParent(NULL);
+ window2->SetBounds(gfx::Rect(11, 21, 301, 401));
+ window1->AddTransientChild(window2.get());
+ aura::client::SetHideOnDeactivate(window2.get(), true);
+ window2->Show();
+ wm::ActivateWindow(window2.get());
+
+ // window1 is now inactive, but its shadow should still appear active.
+ EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style());
+}
+
} // namespace internal
} // namespace ash