Index: ash/wm/frame_painter.cc |
diff --git a/ash/wm/frame_painter.cc b/ash/wm/frame_painter.cc |
index d9e72ab6dc1e66c8be539a528d124a3e03589131..7d5c83236fb010cd9bf45d27b96ccb6bd897d81e 100644 |
--- a/ash/wm/frame_painter.cc |
+++ b/ash/wm/frame_painter.cc |
@@ -12,6 +12,7 @@ |
#include "third_party/skia/include/core/SkPath.h" |
#include "third_party/skia/include/core/SkShader.h" |
#include "ui/aura/window.h" |
+#include "ui/base/animation/slide_animation.h" |
#include "ui/base/hit_test.h" |
#include "ui/base/resource/resource_bundle.h" |
#include "ui/base/theme_provider.h" |
@@ -59,10 +60,13 @@ const SkColor kHeaderContentSeparatorColor = SkColorSetRGB(128, 128, 128); |
const int kCloseButtonOffsetX = 0; |
// Space between close button and top edge of window. |
const int kCloseButtonOffsetY = 0; |
+// Duration of crossfade animation for activating and deactivating frame. |
+const int kActivationCrossfadeDurationMS = 100; |
James Cook
2012/03/19 19:25:58
I think the shadow animation uses 200 ms. Could y
pkotwicz
2012/03/20 00:59:46
Done.
|
// Tiles an image into an area, rounding the top corners. |
void TileRoundRect(gfx::Canvas* canvas, |
int x, int y, int w, int h, |
+ SkPaint paint, |
James Cook
2012/03/19 19:25:58
Are these cheap to copy? If not, pass a pointer?
|
const SkBitmap& bitmap, |
int corner_radius) { |
SkRect rect; |
@@ -76,12 +80,10 @@ void TileRoundRect(gfx::Canvas* canvas, |
SkPath path; |
path.addRoundRect(rect, radii, SkPath::kCW_Direction); |
- SkPaint paint; |
SkShader* shader = SkShader::CreateBitmapShader(bitmap, |
SkShader::kRepeat_TileMode, |
SkShader::kRepeat_TileMode); |
paint.setShader(shader); |
- paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
// CreateBitmapShader returns a Shader with a reference count of one, we |
// need to unref after paint takes ownership of the shader. |
shader->unref(); |
@@ -104,7 +106,10 @@ FramePainter::FramePainter() |
top_edge_(NULL), |
top_right_corner_(NULL), |
header_left_edge_(NULL), |
- header_right_edge_(NULL) { |
+ header_right_edge_(NULL), |
+ previous_theme_frame_(NULL), |
+ crossfade_theme_frame_(NULL), |
+ crossfade_animation_(NULL) { |
} |
FramePainter::~FramePainter() { |
@@ -225,13 +230,41 @@ void FramePainter::PaintHeader(views::NonClientFrameView* view, |
const SkBitmap* theme_frame, |
const SkBitmap* theme_frame_overlay) { |
- // Draw the header background, clipping the corners to be rounded. |
+ if (previous_theme_frame_ && previous_theme_frame_ != theme_frame) { |
+ crossfade_animation_.reset(new ui::SlideAnimation(this)); |
+ crossfade_theme_frame_ = previous_theme_frame_; |
+ crossfade_animation_->Reset(); |
James Cook
2012/03/19 19:25:58
Does the animation have to be reset if it was just
pkotwicz
2012/03/20 00:59:46
Done.
|
+ crossfade_animation_->SetSlideDuration(kActivationCrossfadeDurationMS); |
+ crossfade_animation_->Show(); |
+ } |
+ |
+ header_frame_bounds_ = gfx::Rect(0, 0, view->width(), theme_frame->height()); |
const int kCornerRadius = 2; |
+ |
+ SkPaint paint; |
+ if (crossfade_animation_.get() && crossfade_animation_->is_animating()) { |
+ uint8 theme_alpha = crossfade_animation_->GetCurrentValue() * 255; |
+ |
+ // Draw the old header background, clipping the corners to be rounded. |
+ paint.setAlpha(255 - theme_alpha); |
+ paint.setXfermodeMode(SkXfermode::kPlus_Mode); |
+ TileRoundRect(canvas, |
+ 0, 0, view->width(), theme_frame->height(), |
+ paint, |
+ *crossfade_theme_frame_, |
+ kCornerRadius); |
+ |
+ paint.setAlpha(theme_alpha); |
+ } |
+ |
+ // Draw the header background, clipping the corners to be rounded. |
TileRoundRect(canvas, |
- 0, 0, view->width(), theme_frame->height(), |
+ 0, 0, view->width(), theme_frame->height(), paint, |
*theme_frame, |
kCornerRadius); |
+ previous_theme_frame_ = theme_frame; |
+ |
// Draw the theme frame overlay, if available. |
if (theme_frame_overlay) |
canvas->DrawBitmapInt(*theme_frame_overlay, 0, 0); |
@@ -358,6 +391,13 @@ void FramePainter::LayoutHeader(views::NonClientFrameView* view, |
} |
/////////////////////////////////////////////////////////////////////////////// |
+// ui::AnimationDelegate overrides: |
+ |
+void FramePainter::AnimationProgressed(const ui::Animation* animation) { |
+ frame_->SchedulePaintInRect(gfx::Rect(header_frame_bounds_)); |
+} |
+ |
+/////////////////////////////////////////////////////////////////////////////// |
// FramePainter, private: |
void FramePainter::SetButtonImages(views::ImageButton* button, |