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

Unified Diff: ui/message_center/views/notification_view.cc

Issue 12879009: Made WebKit notifications display 80x80 icons if they have them. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/message_center/views/notification_view.cc
diff --git a/ui/message_center/views/notification_view.cc b/ui/message_center/views/notification_view.cc
index f4a0572414d4d1e489d8cd67def9d2b967e62122..00e32047e46676e3d976516819fa91495bb19cf2 100644
--- a/ui/message_center/views/notification_view.cc
+++ b/ui/message_center/views/notification_view.cc
@@ -8,6 +8,7 @@
#include "base/utf_string_conversions.h"
#include "grit/ui_resources.h"
#include "ui/base/accessibility/accessible_view_state.h"
+#include "ui/base/layout.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/canvas.h"
@@ -26,14 +27,14 @@
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
+#include "ui/views/widget/widget.h"
namespace {
// Dimensions.
-const int kIconColumnWidth = message_center::kNotificationIconSize;
+const int kIconSize = message_center::kNotificationIconSize;
const int kLegacyIconSize = 40;
-const int kTextLeftPadding = kIconColumnWidth +
- message_center::kIconToTextPadding;
+const int kTextLeftPadding = kIconSize + message_center::kIconToTextPadding;
const int kTextBottomPadding = 12;
const int kTextRightPadding = 23;
const int kItemTitleToMessagePadding = 3;
@@ -87,6 +88,36 @@ views::Border* MakeSeparatorBorder(int top, int left, SkColor color) {
return views::Border::CreateSolidSidedBorder(top, left, 0, 0, color);
}
+// static
+// Return true if and only if the image is null or has alpha.
+bool HasAlpha(gfx::ImageSkia& image, views::Widget* widget) {
+ // Determine which bitmap to use.
+ ui::ScaleFactor factor = ui::SCALE_FACTOR_100P;
+ if (widget) {
+ factor = ui::GetScaleFactorForNativeView(widget->GetNativeView());
+ if (factor == ui::SCALE_FACTOR_NONE)
+ factor = ui::SCALE_FACTOR_100P;
+ }
+
+ // Extract that bitmap's alpha and look for a non-opaque pixel there.
+ SkBitmap bitmap = image.GetRepresentation(factor).sk_bitmap();
+ if (!bitmap.isNull()) {
+ SkBitmap alpha;
+ alpha.setConfig(SkBitmap::kA1_Config, bitmap.width(), bitmap.height(), 0);
+ bitmap.extractAlpha(&alpha);
+ for (int y = 0; y < bitmap.height(); ++y) {
+ for (int x = 0; x < bitmap.width(); ++x) {
+ if (alpha.getColor(x, y) != SK_ColorBLACK) {
+ return true;
+ }
+ }
+ }
+ }
+
+ // If no opaque pixel was found, return false unless the bitmap is empty.
+ return bitmap.isNull();
+}
+
// ItemView ////////////////////////////////////////////////////////////////////
// ItemViews are responsible for drawing each list notification item's title and
@@ -385,16 +416,20 @@ NotificationView::NotificationView(const Notification& notification,
}
// Create the notification icon view.
- if (notification.type() == NOTIFICATION_TYPE_SIMPLE) {
+ gfx::ImageSkia icon = notification.icon().AsImageSkia();
+ if (notification.type() == NOTIFICATION_TYPE_SIMPLE &&
+ (icon.width() != kIconSize ||
+ icon.height() != kIconSize ||
+ HasAlpha(icon, GetWidget()))) {
views::ImageView* icon_view = new views::ImageView();
- icon_view->SetImage(notification.icon().AsImageSkia());
+ icon_view->SetImage(icon);
icon_view->SetImageSize(gfx::Size(kLegacyIconSize, kLegacyIconSize));
icon_view->SetHorizontalAlignment(views::ImageView::CENTER);
icon_view->SetVerticalAlignment(views::ImageView::CENTER);
icon_view->set_background(MakeBackground(kLegacyIconBackgroundColor));
icon_view_ = icon_view;
} else {
- icon_view_ = new ProportionalImageView(notification.icon().AsImageSkia());
+ icon_view_ = new ProportionalImageView(icon);
}
// Create the bottom_view_, which collects into a vertical box all content
@@ -451,8 +486,7 @@ int NotificationView::GetHeightForWidth(int width) {
gfx::Insets insets = GetInsets();
int top_height = top_view_->GetHeightForWidth(width - insets.width());
int bottom_height = bottom_view_->GetHeightForWidth(width - insets.width());
- int icon_size = message_center::kNotificationIconSize;
- return std::max(top_height, icon_size) + bottom_height + insets.height();
+ return std::max(top_height, kIconSize) + bottom_height + insets.height();
}
void NotificationView::Layout() {
@@ -473,11 +507,10 @@ void NotificationView::Layout() {
top_view_->SetBounds(insets.left(), insets.top(), content_width, top_height);
// Icon.
- int icon_size = message_center::kNotificationIconSize;
- icon_view_->SetBounds(insets.left(), insets.top(), icon_size, icon_size);
+ icon_view_->SetBounds(insets.left(), insets.top(), kIconSize, kIconSize);
// Bottom views.
- int bottom_y = insets.top() + std::max(top_height, icon_size);
+ int bottom_y = insets.top() + std::max(top_height, kIconSize);
int bottom_height = bottom_view_->GetHeightForWidth(content_width);
bottom_view_->SetBounds(insets.left(), bottom_y,
content_width, bottom_height);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698