summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-29 21:16:26 +0000
committerderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-29 21:16:26 +0000
commit59f43788f52b293531a92b368ada577e8a1668d0 (patch)
tree64ae234a4f572a1da1c4bc2be067cc636af7be99 /ash
parent81c121289b5fefcb1fc97be4efc54c187c893450 (diff)
downloadchromium_src-59f43788f52b293531a92b368ada577e8a1668d0.zip
chromium_src-59f43788f52b293531a92b368ada577e8a1668d0.tar.gz
chromium_src-59f43788f52b293531a92b368ada577e8a1668d0.tar.bz2
aura: Add support for smaller, lighter shadows.
These are displayed behind tooltips and menus. BUG=115402 TEST=added a tiny test to check that we use the new shadow style; also manually checked that tooltips and menus get the small shadow but other windows get the larger active/inactive shadows TBR=ben@chromium.org Review URL: http://codereview.chromium.org/9508004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124255 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/wm/shadow.cc51
-rw-r--r--ash/wm/shadow.h7
-rw-r--r--ash/wm/shadow_controller.cc16
-rw-r--r--ash/wm/shadow_controller_unittest.cc28
-rw-r--r--ash/wm/shadow_types.h5
5 files changed, 93 insertions, 14 deletions
diff --git a/ash/wm/shadow.cc b/ash/wm/shadow.cc
index 8f33765..c6fbd44a 100644
--- a/ash/wm/shadow.cc
+++ b/ash/wm/shadow.cc
@@ -11,15 +11,28 @@
namespace {
-// Shadow opacity for active window.
+// Shadow opacity for different styles.
const float kActiveShadowOpacity = 1.0f;
-
-// Shadow opacity for inactive window.
const float kInactiveShadowOpacity = 0.2f;
+const float kSmallShadowOpacity = 1.0f;
// Duration for opacity animation in milliseconds.
const int64 kAnimationDurationMs = 200;
+float GetOpacityForStyle(ash::internal::Shadow::Style style) {
+ switch (style) {
+ case ash::internal::Shadow::STYLE_ACTIVE:
+ return kActiveShadowOpacity;
+ case ash::internal::Shadow::STYLE_INACTIVE:
+ return kInactiveShadowOpacity;
+ case ash::internal::Shadow::STYLE_SMALL:
+ return kSmallShadowOpacity;
+ default:
+ NOTREACHED() << "Unhandled style " << style;
+ }
+ return 1.0f;
+}
+
} // namespace
namespace ash {
@@ -31,12 +44,12 @@ Shadow::Shadow() {
Shadow::~Shadow() {
}
-void Shadow::Init() {
- style_ = STYLE_ACTIVE;
+void Shadow::Init(Style style) {
+ style_ = style;
image_grid_.reset(new ImageGrid);
UpdateImagesForStyle();
image_grid_->layer()->set_name("Shadow");
- image_grid_->layer()->SetOpacity(kActiveShadowOpacity);
+ image_grid_->layer()->SetOpacity(GetOpacityForStyle(style_));
}
void Shadow::SetContentBounds(const gfx::Rect& content_bounds) {
@@ -51,11 +64,21 @@ ui::Layer* Shadow::layer() const {
void Shadow::SetStyle(Style style) {
if (style_ == style)
return;
+
+ Style old_style = style_;
style_ = style;
// Stop waiting for any as yet unfinished implicit animations.
StopObservingImplicitAnimations();
+ // If we're switching to or from the small style, don't bother with
+ // animations.
+ if (style == STYLE_SMALL || old_style == STYLE_SMALL) {
+ UpdateImagesForStyle();
+ image_grid_->layer()->SetOpacity(GetOpacityForStyle(style));
+ return;
+ }
+
// If we're becoming active, switch images now. Because the inactive image
// has a very low opacity the switch isn't noticeable and this approach
// allows us to use only a single set of shadow images at a time.
@@ -79,7 +102,7 @@ void Shadow::SetStyle(Style style) {
image_grid_->layer()->SetOpacity(kInactiveShadowOpacity);
break;
default:
- NOTREACHED();
+ NOTREACHED() << "Unhandled style " << style_;
break;
}
}
@@ -122,8 +145,20 @@ void Shadow::UpdateImagesForStyle() {
&res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_BOTTOM),
&res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_BOTTOM_RIGHT));
break;
+ case STYLE_SMALL:
+ image_grid_->SetImages(
+ &res.GetImageNamed(IDR_AURA_SHADOW_SMALL_TOP_LEFT),
+ &res.GetImageNamed(IDR_AURA_SHADOW_SMALL_TOP),
+ &res.GetImageNamed(IDR_AURA_SHADOW_SMALL_TOP_RIGHT),
+ &res.GetImageNamed(IDR_AURA_SHADOW_SMALL_LEFT),
+ NULL,
+ &res.GetImageNamed(IDR_AURA_SHADOW_SMALL_RIGHT),
+ &res.GetImageNamed(IDR_AURA_SHADOW_SMALL_BOTTOM_LEFT),
+ &res.GetImageNamed(IDR_AURA_SHADOW_SMALL_BOTTOM),
+ &res.GetImageNamed(IDR_AURA_SHADOW_SMALL_BOTTOM_RIGHT));
+ break;
default:
- NOTREACHED();
+ NOTREACHED() << "Unhandled style " << style_;
break;
}
diff --git a/ash/wm/shadow.h b/ash/wm/shadow.h
index 039b381..8f5ab07 100644
--- a/ash/wm/shadow.h
+++ b/ash/wm/shadow.h
@@ -28,14 +28,19 @@ class ASH_EXPORT Shadow : public ui::ImplicitAnimationObserver {
// Active windows have more opaque shadows, shifted down to make the window
// appear "higher".
STYLE_ACTIVE,
+
// Inactive windows have less opaque shadows.
STYLE_INACTIVE,
+
+ // Small windows like tooltips and context menus have lighter, smaller
+ // shadows.
+ STYLE_SMALL,
};
Shadow();
virtual ~Shadow();
- void Init();
+ void Init(Style style);
// Returns |image_grid_|'s ui::Layer. This is exposed so it can be added to
// the same layer as the content and stacked below it. SetContentBounds()
diff --git a/ash/wm/shadow_controller.cc b/ash/wm/shadow_controller.cc
index 7e7d5f5..caae9ae 100644
--- a/ash/wm/shadow_controller.cc
+++ b/ash/wm/shadow_controller.cc
@@ -42,6 +42,17 @@ ShadowType GetShadowTypeFromWindow(aura::Window* window) {
return SHADOW_TYPE_NONE;
}
+bool ShouldUseSmallShadowForWindow(aura::Window* window) {
+ switch (window->type()) {
+ case aura::client::WINDOW_TYPE_MENU:
+ case aura::client::WINDOW_TYPE_TOOLTIP:
+ return true;
+ default:
+ break;
+ }
+ return false;
+}
+
} // namespace
ShadowController::ShadowController() {
@@ -116,7 +127,7 @@ Shadow* ShadowController::GetShadowForWindow(aura::Window* window) {
void ShadowController::HandleWindowActivationChange(aura::Window* window,
bool active) {
Shadow* shadow = GetShadowForWindow(window);
- if (shadow)
+ if (shadow && !ShouldUseSmallShadowForWindow(window))
shadow->SetStyle(active ? Shadow::STYLE_ACTIVE : Shadow::STYLE_INACTIVE);
}
@@ -134,7 +145,8 @@ void ShadowController::CreateShadowForWindow(aura::Window* window) {
linked_ptr<Shadow> shadow(new Shadow());
window_shadows_.insert(make_pair(window, shadow));
- shadow->Init();
+ shadow->Init(ShouldUseSmallShadowForWindow(window) ?
+ Shadow::STYLE_SMALL : Shadow::STYLE_ACTIVE);
shadow->SetContentBounds(gfx::Rect(window->bounds().size()));
shadow->layer()->SetVisible(ShouldShowShadowForWindow(window));
window->layer()->Add(shadow->layer());
diff --git a/ash/wm/shadow_controller_unittest.cc b/ash/wm/shadow_controller_unittest.cc
index 60c2119..eb6f9af 100644
--- a/ash/wm/shadow_controller_unittest.cc
+++ b/ash/wm/shadow_controller_unittest.cc
@@ -122,5 +122,33 @@ TEST_F(ShadowControllerTest, ShadowStyle) {
EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow2->style());
}
+// Tests that we use smaller shadows for tooltips and menus.
+TEST_F(ShadowControllerTest, SmallShadowsForTooltipsAndMenus) {
+ ShadowController::TestApi api(
+ ash::Shell::GetInstance()->shadow_controller());
+
+ scoped_ptr<aura::Window> tooltip_window(new aura::Window(NULL));
+ tooltip_window->SetType(aura::client::WINDOW_TYPE_TOOLTIP);
+ tooltip_window->Init(ui::Layer::LAYER_TEXTURED);
+ tooltip_window->SetParent(NULL);
+ tooltip_window->SetBounds(gfx::Rect(10, 20, 300, 400));
+ tooltip_window->Show();
+
+ Shadow* tooltip_shadow = api.GetShadowForWindow(tooltip_window.get());
+ ASSERT_TRUE(tooltip_shadow != NULL);
+ EXPECT_EQ(Shadow::STYLE_SMALL, tooltip_shadow->style());
+
+ scoped_ptr<aura::Window> menu_window(new aura::Window(NULL));
+ menu_window->SetType(aura::client::WINDOW_TYPE_MENU);
+ menu_window->Init(ui::Layer::LAYER_TEXTURED);
+ menu_window->SetParent(NULL);
+ menu_window->SetBounds(gfx::Rect(10, 20, 300, 400));
+ menu_window->Show();
+
+ Shadow* menu_shadow = api.GetShadowForWindow(tooltip_window.get());
+ ASSERT_TRUE(menu_shadow != NULL);
+ EXPECT_EQ(Shadow::STYLE_SMALL, menu_shadow->style());
+}
+
} // namespace internal
} // namespace ash
diff --git a/ash/wm/shadow_types.h b/ash/wm/shadow_types.h
index bf30037..ebb2079 100644
--- a/ash/wm/shadow_types.h
+++ b/ash/wm/shadow_types.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -23,8 +23,7 @@ enum ShadowType {
SHADOW_TYPE_RECTANGULAR,
};
-ASH_EXPORT void SetShadowType(aura::Window* window,
- ShadowType shadow_type);
+ASH_EXPORT void SetShadowType(aura::Window* window, ShadowType shadow_type);
ASH_EXPORT ShadowType GetShadowType(aura::Window* window);
} // namespace internal