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

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

Issue 385123005: Change ui::wm::Shadow to use cc::NinePatchLayer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
« ui/resources/ui_resources.grd ('K') | « ui/wm/core/shadow.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/wm/core/shadow.cc
diff --git a/ui/wm/core/shadow.cc b/ui/wm/core/shadow.cc
index 1eb0ac6b4e3523c4890354f1efa88f77fc89bc21..c1fcafc8359b5981530fec488cf96f2dd0c9baa0 100644
--- a/ui/wm/core/shadow.cc
+++ b/ui/wm/core/shadow.cc
@@ -5,9 +5,10 @@
#include "ui/wm/core/shadow.h"
#include "grit/ui_resources.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/compositor/layer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
-#include "ui/wm/core/image_grid.h"
namespace {
@@ -17,9 +18,9 @@ const float kInactiveShadowOpacity = 0.2f;
const float kSmallShadowOpacity = 1.0f;
// Interior inset for different styles.
-const int kActiveInteriorInset = 0;
-const int kInactiveInteriorInset = 0;
-const int kSmallInteriorInset = 5;
+const int kActiveInteriorInset = 64;
+const int kInactiveInteriorInset = 64;
+const int kSmallInteriorInset = 4;
// Duration for opacity animation in milliseconds.
const int kShadowAnimationDurationMs = 100;
@@ -60,19 +61,18 @@ Shadow::~Shadow() {
void Shadow::Init(Style style) {
style_ = style;
- image_grid_.reset(new ImageGrid);
+
+ layer_.reset(new ui::Layer());
+ layer()->SetShowNinePatch();
UpdateImagesForStyle();
- image_grid_->layer()->set_name("Shadow");
- image_grid_->layer()->SetOpacity(GetOpacityForStyle(style_));
+ layer()->set_name("Shadow");
+ layer()->SetVisible(true);
+ layer()->SetOpacity(GetOpacityForStyle(style_));
}
void Shadow::SetContentBounds(const gfx::Rect& content_bounds) {
content_bounds_ = content_bounds;
- UpdateImageGridBounds();
-}
-
-ui::Layer* Shadow::layer() const {
- return image_grid_->layer();
+ UpdateImageBounds();
}
void Shadow::SetStyle(Style style) {
@@ -89,7 +89,7 @@ void Shadow::SetStyle(Style style) {
// animations.
if (style == STYLE_SMALL || old_style == STYLE_SMALL) {
UpdateImagesForStyle();
- image_grid_->layer()->SetOpacity(GetOpacityForStyle(style));
+ layer()->SetOpacity(GetOpacityForStyle(style));
return;
}
@@ -99,7 +99,7 @@ void Shadow::SetStyle(Style style) {
if (style == STYLE_ACTIVE) {
UpdateImagesForStyle();
// Opacity was baked into inactive image, start opacity low to match.
- image_grid_->layer()->SetOpacity(kInactiveShadowOpacity);
+ layer()->SetOpacity(kInactiveShadowOpacity);
}
{
@@ -110,10 +110,10 @@ void Shadow::SetStyle(Style style) {
base::TimeDelta::FromMilliseconds(kShadowAnimationDurationMs));
switch (style_) {
case STYLE_ACTIVE:
- image_grid_->layer()->SetOpacity(kActiveShadowOpacity);
+ layer()->SetOpacity(kActiveShadowOpacity);
break;
case STYLE_INACTIVE:
- image_grid_->layer()->SetOpacity(kInactiveShadowOpacity);
+ layer()->SetOpacity(kInactiveShadowOpacity);
break;
default:
NOTREACHED() << "Unhandled style " << style_;
@@ -128,48 +128,22 @@ void Shadow::OnImplicitAnimationsCompleted() {
if (style_ == STYLE_INACTIVE) {
UpdateImagesForStyle();
// Opacity is baked into inactive image, so set fully opaque.
- image_grid_->layer()->SetOpacity(1.0f);
+ layer()->SetOpacity(1.0f);
}
}
void Shadow::UpdateImagesForStyle() {
ResourceBundle& res = ResourceBundle::GetSharedInstance();
+ gfx::Image image;
switch (style_) {
case STYLE_ACTIVE:
- image_grid_->SetImages(
- &res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE_TOP_LEFT),
- &res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE_TOP),
- &res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE_TOP_RIGHT),
- &res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE_LEFT),
- NULL,
- &res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE_RIGHT),
- &res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE_BOTTOM_LEFT),
- &res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE_BOTTOM),
- &res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE_BOTTOM_RIGHT));
+ image = res.GetImageNamed(IDR_AURA_SHADOW_ACTIVE);
break;
case STYLE_INACTIVE:
- image_grid_->SetImages(
- &res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_TOP_LEFT),
- &res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_TOP),
- &res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_TOP_RIGHT),
- &res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_LEFT),
- NULL,
- &res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_RIGHT),
- &res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_BOTTOM_LEFT),
- &res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_BOTTOM),
- &res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE_BOTTOM_RIGHT));
+ image = res.GetImageNamed(IDR_AURA_SHADOW_INACTIVE);
break;
case STYLE_SMALL:
- image_grid_->SetImages(
- &res.GetImageNamed(IDR_WINDOW_BUBBLE_SHADOW_SMALL_TOP_LEFT),
- &res.GetImageNamed(IDR_WINDOW_BUBBLE_SHADOW_SMALL_TOP),
- &res.GetImageNamed(IDR_WINDOW_BUBBLE_SHADOW_SMALL_TOP_RIGHT),
- &res.GetImageNamed(IDR_WINDOW_BUBBLE_SHADOW_SMALL_LEFT),
- NULL,
- &res.GetImageNamed(IDR_WINDOW_BUBBLE_SHADOW_SMALL_RIGHT),
- &res.GetImageNamed(IDR_WINDOW_BUBBLE_SHADOW_SMALL_BOTTOM_LEFT),
- &res.GetImageNamed(IDR_WINDOW_BUBBLE_SHADOW_SMALL_BOTTOM),
- &res.GetImageNamed(IDR_WINDOW_BUBBLE_SHADOW_SMALL_BOTTOM_RIGHT));
+ image = res.GetImageNamed(IDR_WINDOW_BUBBLE_SHADOW_SMALL);
break;
default:
NOTREACHED() << "Unhandled style " << style_;
@@ -179,15 +153,26 @@ void Shadow::UpdateImagesForStyle() {
// Update interior inset for style.
interior_inset_ = GetInteriorInsetForStyle(style_);
+ // Update nine-patch layer image with aperture and border.
+ gfx::Rect aperture(interior_inset_,
+ interior_inset_,
+ image.Width() - interior_inset_ * 2,
+ image.Height() - interior_inset_ * 2);
+ gfx::Rect border(interior_inset_,
+ interior_inset_,
+ interior_inset_ * 2,
+ interior_inset_ * 2);
+ layer()->UpdateNinePatchBitmap(image.AsBitmap(), aperture, border);
+
// Image sizes may have changed.
- UpdateImageGridBounds();
+ UpdateImageBounds();
}
-void Shadow::UpdateImageGridBounds() {
+void Shadow::UpdateImageBounds() {
// Update bounds based on content bounds and image sizes.
- gfx::Rect image_grid_bounds = content_bounds_;
- image_grid_bounds.Inset(interior_inset_, interior_inset_);
- image_grid_->SetContentBounds(image_grid_bounds);
+ gfx::Rect image_bounds = content_bounds_;
+ image_bounds.Inset(-interior_inset_, -interior_inset_);
+ layer()->SetBounds(image_bounds);
}
} // namespace wm
« ui/resources/ui_resources.grd ('K') | « ui/wm/core/shadow.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698