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

Unified Diff: ui/gfx/image/image_skia_operations.cc

Issue 2550593002: Update WM shadows for MD. (Closed)
Patch Set: fix corners Created 4 years 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
Index: ui/gfx/image/image_skia_operations.cc
diff --git a/ui/gfx/image/image_skia_operations.cc b/ui/gfx/image/image_skia_operations.cc
index 383623515779eeec0d85494df9ad7216c27f2f4c..a7bee40ce7e0daa7421804348be6786b03d71e2d 100644
--- a/ui/gfx/image/image_skia_operations.cc
+++ b/ui/gfx/image/image_skia_operations.cc
@@ -370,11 +370,8 @@ class ResizeSource : public ImageSkiaSource {
// |source| that represent requested scale factors.
class DropShadowSource : public ImageSkiaSource {
public:
- DropShadowSource(const ImageSkia& source,
- const ShadowValues& shadows_in_dip)
- : source_(source),
- shaodws_in_dip_(shadows_in_dip) {
- }
+ DropShadowSource(const ImageSkia& source, const ShadowValues& shadows_in_dip)
+ : source_(source), shadows_in_dip_(shadows_in_dip) {}
~DropShadowSource() override {}
// gfx::ImageSkiaSource overrides:
@@ -382,8 +379,8 @@ class DropShadowSource : public ImageSkiaSource {
const ImageSkiaRep& image_rep = source_.GetRepresentation(scale);
ShadowValues shadows_in_pixel;
- for (size_t i = 0; i < shaodws_in_dip_.size(); ++i)
- shadows_in_pixel.push_back(shaodws_in_dip_[i].Scale(scale));
+ for (size_t i = 0; i < shadows_in_dip_.size(); ++i)
+ shadows_in_pixel.push_back(shadows_in_dip_[i].Scale(scale));
const SkBitmap shadow_bitmap = SkBitmapOperations::CreateDropShadow(
image_rep.sk_bitmap(),
@@ -393,12 +390,56 @@ class DropShadowSource : public ImageSkiaSource {
private:
const ImageSkia source_;
- const ShadowValues shaodws_in_dip_;
+ const ShadowValues shadows_in_dip_;
DISALLOW_COPY_AND_ASSIGN(DropShadowSource);
};
-// An image source that is 1dp wide, suitable for tiling horizontally.
+class ShadowNineboxSource : public CanvasImageSource {
+ public:
+ ShadowNineboxSource(const std::vector<ShadowValue>& shadows,
+ float corner_radius)
+ : CanvasImageSource(CalculateSize(shadows, corner_radius), false),
+ shadows_(shadows),
+ corner_radius_(corner_radius) {}
James Cook 2016/12/05 23:38:35 nit: DCHECK something about shadows.size() or .emp
Evan Stade 2016/12/06 00:53:21 Done.
+ ~ShadowNineboxSource() override {}
+
+ // CanvasImageSource overrides:
+ void Draw(Canvas* canvas) override {
+ SkPaint paint;
+ paint.setLooper(CreateShadowDrawLooperCorrectBlur(shadows_));
+ Insets insets = -ShadowValue::GetMargin(shadows_);
+ gfx::Rect bounds(size());
+ bounds.Inset(insets);
+ gfx::RectF rrect_bounds(bounds);
James Cook 2016/12/05 23:38:35 nit: Either rounded_rect_bounds or comment that rr
Evan Stade 2016/12/06 00:53:21 removed variable
+ SkRRect r_rect = SkRRect::MakeRectXY(gfx::RectFToSkRect(rrect_bounds),
+ corner_radius_, corner_radius_);
+
+ // Clip out the center so it's not painted with the shadow.
+ canvas->sk_canvas()->clipRRect(r_rect, SkRegion::kDifference_Op, true);
+ // Clipping alone is not enough --- due to anti aliasing there will still be
+ // some of the fill color in the rounded corners. We must make the fill
+ // color transparent.
+ paint.setColor(SK_ColorTRANSPARENT);
+ canvas->sk_canvas()->drawRRect(r_rect, paint);
+ }
+
+ private:
+ static Size CalculateSize(const std::vector<ShadowValue>& shadows,
+ float corner_radius) {
+ Insets insets = ShadowValue::GetBlurRegion(shadows);
+ return Size(insets.width() + 2 * corner_radius,
+ insets.height() + 2 * corner_radius);
+ }
+
+ const std::vector<ShadowValue> shadows_;
+
+ float corner_radius_;
+
+ DISALLOW_COPY_AND_ASSIGN(ShadowNineboxSource);
+};
+
+// An image source that is 1px wide, suitable for tiling horizontally.
class HorizontalShadowSource : public CanvasImageSource {
public:
HorizontalShadowSource(const std::vector<ShadowValue>& shadows,
@@ -592,11 +633,17 @@ ImageSkia ImageSkiaOperations::CreateImageWithDropShadow(
}
// static
+ImageSkia ImageSkiaOperations::CreateShadowNinebox(const ShadowValues& shadows,
+ float corner_radius) {
+ auto source = new ShadowNineboxSource(shadows, corner_radius);
+ return ImageSkia(source, source->size());
+}
+
+// static
ImageSkia ImageSkiaOperations::CreateHorizontalShadow(
const std::vector<ShadowValue>& shadows,
bool fades_down) {
- HorizontalShadowSource* source =
- new HorizontalShadowSource(shadows, fades_down);
+ auto source = new HorizontalShadowSource(shadows, fades_down);
return ImageSkia(source, source->size());
}

Powered by Google App Engine
This is Rietveld 408576698