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

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: 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
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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 }; 201 };
202 202
203 ProportionalImageView::ProportionalImageView(const gfx::ImageSkia& image) 203 ProportionalImageView::ProportionalImageView(const gfx::ImageSkia& image)
204 : image_(image) { 204 : image_(image) {
205 } 205 }
206 206
207 ProportionalImageView::~ProportionalImageView() { 207 ProportionalImageView::~ProportionalImageView() {
208 } 208 }
209 209
210 gfx::Size ProportionalImageView::GetPreferredSize() { 210 gfx::Size ProportionalImageView::GetPreferredSize() {
211 gfx::Size size = GetImageSizeForWidth(image_.width()); 211 gfx::Insets insets = GetInsets();
212 return gfx::Size(size.width() + GetInsets().width(), 212 gfx::Rect rect = gfx::Rect(GetImageSizeForWidth(image_.width()));
213 size.height() + GetInsets().height()); 213 rect.Inset(-insets);
214 return rect.size();
214 } 215 }
215 216
216 int ProportionalImageView::GetHeightForWidth(int width) { 217 int ProportionalImageView::GetHeightForWidth(int width) {
217 return GetImageSizeForWidth(width).height(); 218 // The border will count against the width available for the image
219 // and towards the height taken by the image.
220 gfx::Insets insets = GetInsets();
221 int inset_width = width - insets.width();
222 return GetImageSizeForWidth(inset_width).height() + insets.height();
218 } 223 }
219 224
220 void ProportionalImageView::OnPaint(gfx::Canvas* canvas) { 225 void ProportionalImageView::OnPaint(gfx::Canvas* canvas) {
221 views::View::OnPaint(canvas); 226 views::View::OnPaint(canvas);
222 227
223 gfx::Size draw_size(GetImageSizeForWidth(width())); 228 gfx::Size draw_size(GetImageSizeForWidth(width() - GetInsets().width()));
224 if (!draw_size.IsEmpty()) { 229 if (!draw_size.IsEmpty()) {
225 gfx::Rect draw_bounds = GetContentsBounds(); 230 gfx::Rect draw_bounds = GetContentsBounds();
226 draw_bounds.ClampToCenteredSize(draw_size); 231 draw_bounds.ClampToCenteredSize(draw_size);
227 232
228 gfx::Size image_size(image_.size()); 233 gfx::Size image_size(image_.size());
229 if (image_size == draw_size) { 234 if (image_size == draw_size) {
230 canvas->DrawImageInt(image_, draw_bounds.x(), draw_bounds.y()); 235 canvas->DrawImageInt(image_, draw_bounds.x(), draw_bounds.y());
231 } else { 236 } else {
232 // Resize case 237 // Resize case
233 SkPaint paint; 238 SkPaint paint;
234 paint.setFilterBitmap(true); 239 paint.setFilterBitmap(true);
235 canvas->DrawImageInt(image_, 0, 0, 240 canvas->DrawImageInt(image_, 0, 0,
236 image_size.width(), image_size.height(), 241 image_size.width(), image_size.height(),
237 draw_bounds.x(), draw_bounds.y(), 242 draw_bounds.x(), draw_bounds.y(),
238 draw_size.width(), draw_size.height(), 243 draw_size.width(), draw_size.height(),
239 true, paint); 244 true, paint);
240 } 245 }
241 } 246 }
242 } 247 }
243 248
244 gfx::Size ProportionalImageView::GetImageSizeForWidth(int width) { 249 gfx::Size ProportionalImageView::GetImageSizeForWidth(int width) {
245 gfx::Size size = visible() ? image_.size() : gfx::Size(); 250 gfx::Size size = visible() ? image_.size() : gfx::Size();
246 return message_center::GetImageSizeForWidth(width, size); 251 return message_center::GetImageSizeForWidth(width, size);
247 } 252 }
248 253
254 // NotificationImage ///////////////////////////////////////////////////////
255
256 // The NotificationImage is the view representing the area covered by the
257 // notification's image, including background and border. Its size can be
258 // specified in advance and images will be scaled to fit including a border if
259 // necessary.
260 class NotificationImage : public views::View {
Dmitry Titov 2013/12/06 19:29:11 Is it possible to avoid creating new class? Can we
dewittj 2013/12/10 02:47:04 Done.
261 public:
262 NotificationImage(const gfx::Image& image, gfx::Size size);
263 virtual ~NotificationImage();
264
265 private:
266 virtual gfx::Size GetPreferredSize() OVERRIDE;
267
268 gfx::Image image_;
269 gfx::Size size_;
270 };
Dmitry Titov 2013/12/06 19:29:11 DISALLOW_COPY_AND_ASSIGN...
dewittj 2013/12/10 02:47:04 Done.
271
272 NotificationImage::NotificationImage(const gfx::Image& image, gfx::Size size)
273 : image_(image), size_(size) {
274 SetLayoutManager(new views::FillLayout());
275 set_background(views::Background::CreateSolidBackground(
276 message_center::kImageBackgroundColor));
277 gfx::Size image_size = image_.Size();
278 float image_aspect = 0;
279 if (image_size.height() > 0)
280 image_aspect = static_cast<float>(image_size.width()) / image_size.height();
281
282 views::View* proportional_image_view =
283 new ProportionalImageView(image.AsImageSkia());
284
285 // This calculation determines that the new image would have the correct
286 // height for width.
287 if (static_cast<int>(image_aspect * size_.height()) != size_.width()) {
288 proportional_image_view->set_border(views::Border::CreateSolidBorder(
289 message_center::kNotificationImageBorderSize, SK_ColorTRANSPARENT));
290 }
291
292 AddChildView(proportional_image_view);
293 }
294
295 NotificationImage::~NotificationImage() {}
296
297 gfx::Size NotificationImage::GetPreferredSize() { return size_; }
298
249 // NotificationProgressBar ///////////////////////////////////////////////////// 299 // NotificationProgressBar /////////////////////////////////////////////////////
250 300
251 class NotificationProgressBar : public views::ProgressBar { 301 class NotificationProgressBar : public views::ProgressBar {
252 public: 302 public:
253 NotificationProgressBar(); 303 NotificationProgressBar();
254 virtual ~NotificationProgressBar(); 304 virtual ~NotificationProgressBar();
255 305
256 private: 306 private:
257 // Overriden from View 307 // Overriden from View
258 virtual gfx::Size GetPreferredSize() OVERRIDE; 308 virtual gfx::Size GetPreferredSize() OVERRIDE;
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 626
577 // Create the bottom_view_, which collects into a vertical box all content 627 // Create the bottom_view_, which collects into a vertical box all content
578 // below the notification icon except for the expand button. 628 // below the notification icon except for the expand button.
579 bottom_view_ = new views::View(); 629 bottom_view_ = new views::View();
580 bottom_view_->SetLayoutManager( 630 bottom_view_->SetLayoutManager(
581 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 631 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
582 632
583 // Create the image view if appropriate. 633 // Create the image view if appropriate.
584 image_view_ = NULL; 634 image_view_ = NULL;
585 if (!notification.image().IsEmpty()) { 635 if (!notification.image().IsEmpty()) {
586 image_view_ = new ProportionalImageView(notification.image().AsImageSkia()); 636 gfx::Size image_size(
637 kNotificationPreferredImageSize,
638 kNotificationPreferredImageSize * kNotificationPreferredImageRatio);
639 image_view_ = new NotificationImage(notification.image(), image_size);
587 image_view_->SetVisible(is_expanded_); 640 image_view_->SetVisible(is_expanded_);
588 bottom_view_->AddChildView(image_view_); 641 bottom_view_->AddChildView(image_view_);
589 } 642 }
590 643
591 // Create action buttons if appropriate. 644 // Create action buttons if appropriate.
592 std::vector<ButtonInfo> buttons = notification.buttons(); 645 std::vector<ButtonInfo> buttons = notification.buttons();
593 for (size_t i = 0; i < buttons.size(); ++i) { 646 for (size_t i = 0; i < buttons.size(); ++i) {
594 views::View* separator = new views::ImageView(); 647 views::View* separator = new views::ImageView();
595 separator->set_border(MakeSeparatorBorder(1, 0, kButtonSeparatorColor)); 648 separator->set_border(MakeSeparatorBorder(1, 0, kButtonSeparatorColor));
596 bottom_view_->AddChildView(separator); 649 bottom_view_->AddChildView(separator);
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 return message_view_ ? 885 return message_view_ ?
833 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; 886 message_view_->GetLinesForWidthAndLimit(width, limit) : 0;
834 } 887 }
835 888
836 int NotificationView::GetMessageHeight(int width, int limit) { 889 int NotificationView::GetMessageHeight(int width, int limit) {
837 return message_view_ ? 890 return message_view_ ?
838 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; 891 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0;
839 } 892 }
840 893
841 } // namespace message_center 894 } // namespace message_center
OLDNEW
« ui/message_center/message_center_style.h ('K') | « 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