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

Unified Diff: ui/wm/core/shadow_controller.cc

Issue 2596743002: Replace WM shadow types (on/off) and styles (small/inactive/active) (Closed)
Patch Set: one more mechanical change Created 3 years, 11 months 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 | « ui/wm/core/shadow.cc ('k') | ui/wm/core/shadow_controller_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/wm/core/shadow_controller.cc
diff --git a/ui/wm/core/shadow_controller.cc b/ui/wm/core/shadow_controller.cc
index ce30bbdabc8f504929fca934eefd2919ef413d95..ac93dc78700114aa566c88819f038f4aef4aaccf 100644
--- a/ui/wm/core/shadow_controller.cc
+++ b/ui/wm/core/shadow_controller.cc
@@ -32,41 +32,37 @@ namespace wm {
namespace {
-ShadowType GetShadowTypeFromWindow(aura::Window* window) {
+constexpr ShadowElevation kActiveNormalShadowElevation = ShadowElevation::LARGE;
+constexpr ShadowElevation kInactiveNormalShadowElevation =
+ ShadowElevation::MEDIUM;
+
+ShadowElevation GetDefaultShadowElevationForWindow(aura::Window* window) {
switch (window->type()) {
case ui::wm::WINDOW_TYPE_NORMAL:
case ui::wm::WINDOW_TYPE_PANEL:
+ return kInactiveNormalShadowElevation;
+
case ui::wm::WINDOW_TYPE_MENU:
case ui::wm::WINDOW_TYPE_TOOLTIP:
- return SHADOW_TYPE_RECTANGULAR;
+ return ShadowElevation::SMALL;
+
default:
break;
}
- return SHADOW_TYPE_NONE;
+ return ShadowElevation::NONE;
}
-Shadow::Style GetShadowStyleForWindow(aura::Window* window) {
- switch (window->type()) {
- case ui::wm::WINDOW_TYPE_MENU:
- case ui::wm::WINDOW_TYPE_TOOLTIP:
- return Shadow::STYLE_SMALL;
+ShadowElevation GetShadowElevationForActiveState(aura::Window* window) {
+ if (IsActiveWindow(window))
+ return kActiveNormalShadowElevation;
- // System tray bubbles render like active windows. TODO(estade): this
- // mechanism will need to be revisited for applying WM shadows to other
- // types of bubbles which don't want to render such large shadows.
- case ui::wm::WINDOW_TYPE_POPUP:
- return Shadow::STYLE_ACTIVE;
-
- default:
- return IsActiveWindow(window) ? Shadow::STYLE_ACTIVE
- : Shadow::STYLE_INACTIVE;
- }
+ return GetShadowElevation(window);
}
// 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(
+ShadowElevation GetShadowElevationForWindowLosingActive(
aura::Window* losing_active,
aura::Window* gaining_active) {
if (gaining_active && aura::client::GetHideOnDeactivate(gaining_active)) {
@@ -75,9 +71,9 @@ Shadow::Style GetShadowStyleForWindowLosingActive(
GetTransientChildren(losing_active).end(),
gaining_active);
if (it != GetTransientChildren(losing_active).end())
- return Shadow::STYLE_ACTIVE;
+ return kActiveNormalShadowElevation;
}
- return Shadow::STYLE_INACTIVE;
+ return kInactiveNormalShadowElevation;
}
} // namespace
@@ -123,7 +119,7 @@ class ShadowController::Impl :
// Checks if |window| is visible and contains a property requesting a shadow.
bool ShouldShowShadowForWindow(aura::Window* window) const;
- // Updates the shadow styles for windows when activation changes.
+ // Updates the shadow for windows when activation changes.
void HandleWindowActivationChange(aura::Window* gaining_active,
aura::Window* losing_active);
@@ -155,15 +151,16 @@ ShadowController::Impl* ShadowController::Impl::GetInstance() {
void ShadowController::Impl::OnWindowInitialized(aura::Window* window) {
observer_manager_.Add(window);
- SetShadowType(window, GetShadowTypeFromWindow(window));
+ SetShadowElevation(window, GetDefaultShadowElevationForWindow(window));
HandlePossibleShadowVisibilityChange(window);
}
void ShadowController::Impl::OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) {
- if (key == kShadowTypeKey) {
- if (window->GetProperty(kShadowTypeKey) == static_cast<ShadowType>(old))
+ if (key == kShadowElevationKey) {
+ if (window->GetProperty(kShadowElevationKey) ==
+ static_cast<ShadowElevation>(old))
return;
} else if (key == aura::client::kShowStateKey) {
if (window->GetProperty(aura::client::kShowStateKey) ==
@@ -196,14 +193,14 @@ void ShadowController::Impl::OnWindowActivated(ActivationReason reason,
if (gained_active) {
Shadow* shadow = GetShadowForWindow(gained_active);
if (shadow)
- shadow->SetStyle(GetShadowStyleForWindow(gained_active));
+ shadow->SetElevation(GetShadowElevationForActiveState(gained_active));
}
if (lost_active) {
Shadow* shadow = GetShadowForWindow(lost_active);
if (shadow &&
- GetShadowStyleForWindow(lost_active) == Shadow::STYLE_INACTIVE) {
- shadow->SetStyle(GetShadowStyleForWindowLosingActive(lost_active,
- gained_active));
+ GetShadowElevation(lost_active) == kInactiveNormalShadowElevation) {
+ shadow->SetElevation(
+ GetShadowElevationForWindowLosingActive(lost_active, gained_active));
}
}
}
@@ -214,19 +211,10 @@ bool ShadowController::Impl::ShouldShowShadowForWindow(
window->GetProperty(aura::client::kShowStateKey);
if (show_state == ui::SHOW_STATE_FULLSCREEN ||
show_state == ui::SHOW_STATE_MAXIMIZED) {
- return SHADOW_TYPE_NONE;
+ return false;
}
- const ShadowType type = GetShadowType(window);
- switch (type) {
- case SHADOW_TYPE_NONE:
- return false;
- case SHADOW_TYPE_RECTANGULAR:
- return true;
- default:
- NOTREACHED() << "Unknown shadow type " << type;
- return false;
- }
+ return static_cast<int>(GetShadowElevation(window)) > 0;
}
void ShadowController::Impl::HandlePossibleShadowVisibilityChange(
@@ -234,7 +222,7 @@ void ShadowController::Impl::HandlePossibleShadowVisibilityChange(
const bool should_show = ShouldShowShadowForWindow(window);
Shadow* shadow = GetShadowForWindow(window);
if (shadow) {
- shadow->SetStyle(GetShadowStyleForWindow(window));
+ shadow->SetElevation(GetShadowElevationForActiveState(window));
shadow->layer()->SetVisible(should_show);
} else if (should_show && !shadow) {
CreateShadowForWindow(window);
@@ -244,7 +232,7 @@ void ShadowController::Impl::HandlePossibleShadowVisibilityChange(
void ShadowController::Impl::CreateShadowForWindow(aura::Window* window) {
Shadow* shadow = new Shadow();
window->SetProperty(kShadowLayerKey, shadow);
- shadow->Init(GetShadowStyleForWindow(window));
+ shadow->Init(GetShadowElevationForActiveState(window));
shadow->SetContentBounds(gfx::Rect(window->bounds().size()));
shadow->layer()->SetVisible(ShouldShowShadowForWindow(window));
window->layer()->Add(shadow->layer());
« no previous file with comments | « ui/wm/core/shadow.cc ('k') | ui/wm/core/shadow_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698