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

Unified Diff: third_party/WebKit/Source/platform/graphics/PlaceholderImage.cpp

Issue 2915353002: Stylize PlaceholderImages with icons. (Closed)
Patch Set: Addressed comments Created 3 years, 6 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
Index: third_party/WebKit/Source/platform/graphics/PlaceholderImage.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/PlaceholderImage.cpp b/third_party/WebKit/Source/platform/graphics/PlaceholderImage.cpp
index 9023571e795998239fd43c78bc01b0cd951ac3c3..e215eb305d3e97bf9d0f0abab8a2b914f6487294 100644
--- a/third_party/WebKit/Source/platform/graphics/PlaceholderImage.cpp
+++ b/third_party/WebKit/Source/platform/graphics/PlaceholderImage.cpp
@@ -5,22 +5,24 @@
#include "platform/graphics/PlaceholderImage.h"
#include "platform/geometry/FloatRect.h"
-#include "platform/graphics/Color.h"
+#include "platform/geometry/IntPoint.h"
+#include "platform/geometry/IntRect.h"
+#include "platform/graphics/BitmapImage.h"
+#include "platform/graphics/GraphicsContext.h"
#include "platform/graphics/ImageObserver.h"
+#include "platform/graphics/paint/PaintCanvas.h"
+#include "platform/graphics/paint/PaintFlags.h"
#include "platform/graphics/paint/PaintRecord.h"
#include "platform/graphics/paint/PaintRecorder.h"
+#include "platform/wtf/StdLibExtras.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/include/core/SkSize.h"
namespace blink {
-namespace {
-
-// Gray with 40% opacity.
-const RGBA32 kFillColor = 0x66808080;
-
-} // namespace
+PlaceholderImage::PlaceholderImage(ImageObserver* observer, const IntSize& size)
+ : Image(observer), size_(size) {}
PlaceholderImage::~PlaceholderImage() {}
@@ -30,6 +32,7 @@ sk_sp<SkImage> PlaceholderImage::ImageForCurrentFrame() {
const FloatRect dest_rect(0.0f, 0.0f, static_cast<float>(size_.Width()),
static_cast<float>(size_.Height()));
+
PaintRecorder paint_recorder;
Draw(paint_recorder.beginRecording(dest_rect), PaintFlags(), dest_rect,
dest_rect, kDoNotRespectImageOrientation, kClampImageToSourceRect);
@@ -46,18 +49,68 @@ void PlaceholderImage::Draw(PaintCanvas* canvas,
const PaintFlags& base_flags,
const FloatRect& dest_rect,
const FloatRect& src_rect,
- RespectImageOrientationEnum,
- ImageClampingMode) {
+ RespectImageOrientationEnum respect_orientation,
+ ImageClampingMode image_clamping_mode) {
if (!src_rect.Intersects(FloatRect(0.0f, 0.0f,
static_cast<float>(size_.Width()),
static_cast<float>(size_.Height())))) {
return;
}
+ // Placeholder image visual specifications:
+ // https://docs.google.com/document/d/1BHeA1azbgCdZgCnr16VN2g7A9MHPQ_dwKn5szh8evMQ/edit
+
PaintFlags flags(base_flags);
flags.setStyle(PaintFlags::kFill_Style);
- flags.setColor(kFillColor);
+ flags.setColor(SkColorSetARGB(0x80, 0xD9, 0xD9, 0xD9));
canvas->drawRect(dest_rect, flags);
+
+ constexpr int kIconWidth = 24;
+ constexpr int kIconHeight = 24;
+ constexpr int kIconPaddingX = 8;
+ constexpr int kIconPaddingY = 5;
+
+ if (dest_rect.Width() < kIconWidth + 2 * kIconPaddingX ||
+ dest_rect.Height() < kIconHeight + 2 * kIconPaddingY) {
+ return;
+ }
+
+ DEFINE_STATIC_REF(Image, icon_image,
+ (Image::LoadPlatformResource("placeholderIcon")));
+ DCHECK(!icon_image->IsNull());
+
+ FloatRect icon_dest_rect(
+ dest_rect.X() + (dest_rect.Width() - kIconWidth) / 2.0f,
+ dest_rect.Y() + (dest_rect.Height() - kIconHeight) / 2.0f, kIconWidth,
+ kIconHeight);
+
+ // Note that the |icon_image| is not scaled according to dest_rect / src_rect,
+ // and is always drawn at the same size. This is so that placeholder icons are
+ // visible (e.g. when replacing a large image that's scaled down to a small
+ // area) and so that all placeholder images on the same page look consistent.
+ canvas->drawImageRect(icon_image->PaintImageForCurrentFrame(),
+ IntRect(IntPoint::Zero(), icon_image->Size()),
+ icon_dest_rect, &base_flags,
+ PaintCanvas::kFast_SrcRectConstraint);
+}
+
+void PlaceholderImage::DrawPattern(GraphicsContext& context,
+ const FloatRect& src_rect,
+ const FloatSize& scale,
+ const FloatPoint& phase,
+ SkBlendMode mode,
+ const FloatRect& dest_rect,
+ const FloatSize& repeat_spacing) {
+ DCHECK(context.Canvas());
+
+ PaintFlags flags = context.FillFlags();
+ flags.setBlendMode(mode);
+
+ // Ignore the pattern specifications and just draw a single placeholder image
+ // over the whole |dest_rect|. This is done in order to prevent repeated icons
+ // from cluttering tiled background images.
+ Draw(context.Canvas(), flags, dest_rect, src_rect,
+ kDoNotRespectImageOrientation, kClampImageToSourceRect);
}
void PlaceholderImage::DestroyDecodedData() {
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/PlaceholderImage.h ('k') | third_party/WebKit/public/blink_image_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698