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

Side by Side Diff: ui/message_center/views/notification_view.cc

Issue 102473005: Refresh for the Chrome notifications image template. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mac unit test Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/message_center/message_center_style.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/message_center/views/notification_view.h" 5 #include "ui/message_center/views/notification_view.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "grit/ui_resources.h" 10 #include "grit/ui_resources.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 }; 202 };
203 203
204 ProportionalImageView::ProportionalImageView(const gfx::ImageSkia& image) 204 ProportionalImageView::ProportionalImageView(const gfx::ImageSkia& image)
205 : image_(image) { 205 : image_(image) {
206 } 206 }
207 207
208 ProportionalImageView::~ProportionalImageView() { 208 ProportionalImageView::~ProportionalImageView() {
209 } 209 }
210 210
211 gfx::Size ProportionalImageView::GetPreferredSize() { 211 gfx::Size ProportionalImageView::GetPreferredSize() {
212 gfx::Size size = GetImageSizeForWidth(image_.width()); 212 gfx::Insets insets = GetInsets();
213 return gfx::Size(size.width() + GetInsets().width(), 213 gfx::Rect rect = gfx::Rect(GetImageSizeForWidth(image_.width()));
214 size.height() + GetInsets().height()); 214 rect.Inset(-insets);
215 return rect.size();
215 } 216 }
216 217
217 int ProportionalImageView::GetHeightForWidth(int width) { 218 int ProportionalImageView::GetHeightForWidth(int width) {
218 return GetImageSizeForWidth(width).height(); 219 // The border will count against the width available for the image
220 // and towards the height taken by the image.
221 gfx::Insets insets = GetInsets();
222 int inset_width = width - insets.width();
223 return GetImageSizeForWidth(inset_width).height() + insets.height();
219 } 224 }
220 225
221 void ProportionalImageView::OnPaint(gfx::Canvas* canvas) { 226 void ProportionalImageView::OnPaint(gfx::Canvas* canvas) {
222 views::View::OnPaint(canvas); 227 views::View::OnPaint(canvas);
223 228
224 gfx::Size draw_size(GetImageSizeForWidth(width())); 229 gfx::Size draw_size(GetImageSizeForWidth(width() - GetInsets().width()));
225 if (!draw_size.IsEmpty()) { 230 if (!draw_size.IsEmpty()) {
226 gfx::Rect draw_bounds = GetContentsBounds(); 231 gfx::Rect draw_bounds = GetContentsBounds();
227 draw_bounds.ClampToCenteredSize(draw_size); 232 draw_bounds.ClampToCenteredSize(draw_size);
228 233
229 gfx::Size image_size(image_.size()); 234 gfx::Size image_size(image_.size());
230 if (image_size == draw_size) { 235 if (image_size == draw_size) {
231 canvas->DrawImageInt(image_, draw_bounds.x(), draw_bounds.y()); 236 canvas->DrawImageInt(image_, draw_bounds.x(), draw_bounds.y());
232 } else { 237 } else {
233 // Resize case 238 // Resize case
234 SkPaint paint; 239 SkPaint paint;
235 paint.setFilterBitmap(true); 240 paint.setFilterBitmap(true);
236 canvas->DrawImageInt(image_, 0, 0, 241 canvas->DrawImageInt(image_, 0, 0,
237 image_size.width(), image_size.height(), 242 image_size.width(), image_size.height(),
238 draw_bounds.x(), draw_bounds.y(), 243 draw_bounds.x(), draw_bounds.y(),
239 draw_size.width(), draw_size.height(), 244 draw_size.width(), draw_size.height(),
240 true, paint); 245 true, paint);
241 } 246 }
242 } 247 }
243 } 248 }
244 249
245 gfx::Size ProportionalImageView::GetImageSizeForWidth(int width) { 250 gfx::Size ProportionalImageView::GetImageSizeForWidth(int width) {
246 gfx::Size size = visible() ? image_.size() : gfx::Size(); 251 gfx::Size size = visible() ? image_.size() : gfx::Size();
247 return message_center::GetImageSizeForWidth(width, size); 252 return message_center::GetImageSizeForWidth(width, size);
248 } 253 }
249 254
255 // The NotificationImage is the view representing the area covered by the
256 // notification's image, including background and border. Its size can be
257 // specified in advance and images will be scaled to fit including a border if
258 // necessary.
259
260 // static
261 views::View* MakeNotificationImage(const gfx::Image& image, gfx::Size size) {
262 views::View* container = new views::View();
263 container->SetLayoutManager(new views::FillLayout());
264 container->set_background(views::Background::CreateSolidBackground(
265 message_center::kImageBackgroundColor));
266
267 views::View* proportional_image_view =
268 new ProportionalImageView(image.AsImageSkia());
269
270 gfx::Size ideal_size(
271 message_center::kNotificationPreferredImageWidth,
272 message_center::kNotificationPreferredImageHeight);
273 gfx::Size scaled_size = message_center::GetImageSizeForWidth(
274 message_center::kNotificationPreferredImageWidth, image.Size());
275
276 // This calculation determines that the new image would have the correct
277 // height for width.
278 if (ideal_size != scaled_size) {
279 proportional_image_view->set_border(views::Border::CreateSolidBorder(
280 message_center::kNotificationImageBorderSize, SK_ColorTRANSPARENT));
281 }
282
283 container->AddChildView(proportional_image_view);
284 return container;
285 }
286
250 // NotificationProgressBar ///////////////////////////////////////////////////// 287 // NotificationProgressBar /////////////////////////////////////////////////////
251 288
252 class NotificationProgressBar : public views::ProgressBar { 289 class NotificationProgressBar : public views::ProgressBar {
253 public: 290 public:
254 NotificationProgressBar(); 291 NotificationProgressBar();
255 virtual ~NotificationProgressBar(); 292 virtual ~NotificationProgressBar();
256 293
257 private: 294 private:
258 // Overriden from View 295 // Overriden from View
259 virtual gfx::Size GetPreferredSize() OVERRIDE; 296 virtual gfx::Size GetPreferredSize() OVERRIDE;
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 632
596 // Create the bottom_view_, which collects into a vertical box all content 633 // Create the bottom_view_, which collects into a vertical box all content
597 // below the notification icon except for the expand button. 634 // below the notification icon except for the expand button.
598 bottom_view_ = new views::View(); 635 bottom_view_ = new views::View();
599 bottom_view_->SetLayoutManager( 636 bottom_view_->SetLayoutManager(
600 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 637 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
601 638
602 // Create the image view if appropriate. 639 // Create the image view if appropriate.
603 image_view_ = NULL; 640 image_view_ = NULL;
604 if (!notification.image().IsEmpty()) { 641 if (!notification.image().IsEmpty()) {
605 image_view_ = new ProportionalImageView(notification.image().AsImageSkia()); 642 gfx::Size image_size(
643 kNotificationPreferredImageWidth, kNotificationPreferredImageHeight);
644 image_view_ = MakeNotificationImage(notification.image(), image_size);
606 image_view_->SetVisible(is_expanded_); 645 image_view_->SetVisible(is_expanded_);
607 bottom_view_->AddChildView(image_view_); 646 bottom_view_->AddChildView(image_view_);
608 } 647 }
609 648
610 // Create action buttons if appropriate. 649 // Create action buttons if appropriate.
611 std::vector<ButtonInfo> buttons = notification.buttons(); 650 std::vector<ButtonInfo> buttons = notification.buttons();
612 for (size_t i = 0; i < buttons.size(); ++i) { 651 for (size_t i = 0; i < buttons.size(); ++i) {
613 views::View* separator = new views::ImageView(); 652 views::View* separator = new views::ImageView();
614 separator->set_border(MakeSeparatorBorder(1, 0, kButtonSeparatorColor)); 653 separator->set_border(MakeSeparatorBorder(1, 0, kButtonSeparatorColor));
615 bottom_view_->AddChildView(separator); 654 bottom_view_->AddChildView(separator);
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 return message_view_ ? 890 return message_view_ ?
852 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; 891 message_view_->GetLinesForWidthAndLimit(width, limit) : 0;
853 } 892 }
854 893
855 int NotificationView::GetMessageHeight(int width, int limit) { 894 int NotificationView::GetMessageHeight(int width, int limit) {
856 return message_view_ ? 895 return message_view_ ?
857 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; 896 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0;
858 } 897 }
859 898
860 } // namespace message_center 899 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/message_center_style.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698