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

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

Issue 145033006: views: Make View::set_border() take a scoped_ptr<>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Further renaming Created 6 years, 11 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 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 namespace { 47 namespace {
48 48
49 // Dimensions. 49 // Dimensions.
50 const int kProgressBarWidth = message_center::kNotificationWidth - 50 const int kProgressBarWidth = message_center::kNotificationWidth -
51 message_center::kTextLeftPadding - message_center::kTextRightPadding; 51 message_center::kTextLeftPadding - message_center::kTextRightPadding;
52 const int kProgressBarBottomPadding = 0; 52 const int kProgressBarBottomPadding = 0;
53 const int kExpandIconBottomPadding = 8; 53 const int kExpandIconBottomPadding = 8;
54 const int kExpandIconRightPadding = 11; 54 const int kExpandIconRightPadding = 11;
55 55
56 // static 56 // static
57 views::Border* MakeEmptyBorder(int top, int left, int bottom, int right) { 57 scoped_ptr<views::Border> MakeEmptyBorder(int top,
58 int left,
59 int bottom,
60 int right) {
58 return views::Border::CreateEmptyBorder(top, left, bottom, right); 61 return views::Border::CreateEmptyBorder(top, left, bottom, right);
59 } 62 }
60 63
61 // static 64 // static
62 views::Border* MakeTextBorder(int padding, int top, int bottom) { 65 scoped_ptr<views::Border> MakeTextBorder(int padding,
66 int top,
67 int bottom) {
63 // Split the padding between the top and the bottom, then add the extra space. 68 // Split the padding between the top and the bottom, then add the extra space.
64 return MakeEmptyBorder(padding / 2 + top, 69 return MakeEmptyBorder(padding / 2 + top,
65 message_center::kTextLeftPadding, 70 message_center::kTextLeftPadding,
66 (padding + 1) / 2 + bottom, 71 (padding + 1) / 2 + bottom,
67 message_center::kTextRightPadding); 72 message_center::kTextRightPadding);
68 } 73 }
69 74
70 // static 75 // static
71 views::Border* MakeProgressBarBorder(int top, int bottom) { 76 scoped_ptr<views::Border> MakeProgressBarBorder(int top, int bottom) {
72 return MakeEmptyBorder(top, 77 return MakeEmptyBorder(top,
73 message_center::kTextLeftPadding, 78 message_center::kTextLeftPadding,
74 bottom, 79 bottom,
75 message_center::kTextRightPadding); 80 message_center::kTextRightPadding);
76 } 81 }
77 82
78 // static 83 // static
79 views::Border* MakeSeparatorBorder(int top, int left, SkColor color) { 84 scoped_ptr<views::Border> MakeSeparatorBorder(int top,
85 int left,
86 SkColor color) {
80 return views::Border::CreateSolidSidedBorder(top, left, 0, 0, color); 87 return views::Border::CreateSolidSidedBorder(top, left, 0, 0, color);
81 } 88 }
82 89
83 // static 90 // static
84 // Return true if and only if the image is null or has alpha. 91 // Return true if and only if the image is null or has alpha.
85 bool HasAlpha(gfx::ImageSkia& image, views::Widget* widget) { 92 bool HasAlpha(gfx::ImageSkia& image, views::Widget* widget) {
86 // Determine which bitmap to use. 93 // Determine which bitmap to use.
87 ui::ScaleFactor factor = ui::SCALE_FACTOR_100P; 94 ui::ScaleFactor factor = ui::SCALE_FACTOR_100P;
88 if (widget) { 95 if (widget) {
89 factor = ui::GetScaleFactorForNativeView(widget->GetNativeView()); 96 factor = ui::GetScaleFactorForNativeView(widget->GetNativeView());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 gfx::Size scaled_size = 182 gfx::Size scaled_size =
176 message_center::GetImageSizeForContainerSize(ideal_size, image.Size()); 183 message_center::GetImageSizeForContainerSize(ideal_size, image.Size());
177 184
178 views::View* proportional_image_view = 185 views::View* proportional_image_view =
179 new message_center::ProportionalImageView(image.AsImageSkia(), 186 new message_center::ProportionalImageView(image.AsImageSkia(),
180 ideal_size); 187 ideal_size);
181 188
182 // This calculation determines that the new image would have the correct 189 // This calculation determines that the new image would have the correct
183 // height for width. 190 // height for width.
184 if (ideal_size != scaled_size) { 191 if (ideal_size != scaled_size) {
185 proportional_image_view->set_border(views::Border::CreateSolidBorder( 192 proportional_image_view->SetBorder(views::Border::CreateSolidBorder(
186 message_center::kNotificationImageBorderSize, SK_ColorTRANSPARENT)); 193 message_center::kNotificationImageBorderSize, SK_ColorTRANSPARENT));
187 } 194 }
188 195
189 container->AddChildView(proportional_image_view); 196 container->AddChildView(proportional_image_view);
190 return container; 197 return container;
191 } 198 }
192 199
193 // NotificationProgressBar ///////////////////////////////////////////////////// 200 // NotificationProgressBar /////////////////////////////////////////////////////
194 201
195 class NotificationProgressBar : public views::ProgressBar { 202 class NotificationProgressBar : public views::ProgressBar {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 controller_(controller), 311 controller_(controller),
305 clickable_(notification.clickable()), 312 clickable_(notification.clickable()),
306 is_expanded_(expanded) { 313 is_expanded_(expanded) {
307 std::vector<base::string16> accessible_lines; 314 std::vector<base::string16> accessible_lines;
308 // Create the top_view_, which collects into a vertical box all content 315 // Create the top_view_, which collects into a vertical box all content
309 // at the top of the notification (to the right of the icon) except for the 316 // at the top of the notification (to the right of the icon) except for the
310 // close button. 317 // close button.
311 top_view_ = new views::View(); 318 top_view_ = new views::View();
312 top_view_->SetLayoutManager( 319 top_view_->SetLayoutManager(
313 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 320 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
314 top_view_->set_border(MakeEmptyBorder( 321 top_view_->SetBorder(MakeEmptyBorder(
315 kTextTopPadding - 8, 0, kTextBottomPadding - 5, 0)); 322 kTextTopPadding - 8, 0, kTextBottomPadding - 5, 0));
316 323
317 const gfx::FontList default_label_font_list = views::Label().font_list(); 324 const gfx::FontList default_label_font_list = views::Label().font_list();
318 325
319 // Create the title view if appropriate. 326 // Create the title view if appropriate.
320 title_view_ = NULL; 327 title_view_ = NULL;
321 if (!notification.title().empty()) { 328 if (!notification.title().empty()) {
322 const gfx::FontList& font_list = 329 const gfx::FontList& font_list =
323 default_label_font_list.DeriveFontListWithSizeDelta(2); 330 default_label_font_list.DeriveFontListWithSizeDelta(2);
324 int padding = kTitleLineHeight - font_list.GetHeight(); 331 int padding = kTitleLineHeight - font_list.GetHeight();
325 title_view_ = new BoundedLabel( 332 title_view_ = new BoundedLabel(
326 gfx::TruncateString(notification.title(), kTitleCharacterLimit), 333 gfx::TruncateString(notification.title(), kTitleCharacterLimit),
327 font_list); 334 font_list);
328 title_view_->SetLineHeight(kTitleLineHeight); 335 title_view_->SetLineHeight(kTitleLineHeight);
329 title_view_->SetLineLimit(IsExperimentalNotificationUIEnabled() ? 336 title_view_->SetLineLimit(IsExperimentalNotificationUIEnabled() ?
330 message_center::kExperimentalTitleLineLimit : 337 message_center::kExperimentalTitleLineLimit :
331 message_center::kTitleLineLimit); 338 message_center::kTitleLineLimit);
332 title_view_->SetColors(message_center::kRegularTextColor, 339 title_view_->SetColors(message_center::kRegularTextColor,
333 kRegularTextBackgroundColor); 340 kRegularTextBackgroundColor);
334 title_view_->set_border(MakeTextBorder(padding, 3, 0)); 341 title_view_->SetBorder(MakeTextBorder(padding, 3, 0));
335 top_view_->AddChildView(title_view_); 342 top_view_->AddChildView(title_view_);
336 accessible_lines.push_back(notification.title()); 343 accessible_lines.push_back(notification.title());
337 } 344 }
338 345
339 // Create the message view if appropriate. 346 // Create the message view if appropriate.
340 message_view_ = NULL; 347 message_view_ = NULL;
341 if (!notification.message().empty()) { 348 if (!notification.message().empty()) {
342 int padding = kMessageLineHeight - default_label_font_list.GetHeight(); 349 int padding = kMessageLineHeight - default_label_font_list.GetHeight();
343 message_view_ = new BoundedLabel( 350 message_view_ = new BoundedLabel(
344 gfx::TruncateString(notification.message(), kMessageCharacterLimit)); 351 gfx::TruncateString(notification.message(), kMessageCharacterLimit));
345 message_view_->SetLineHeight(kMessageLineHeight); 352 message_view_->SetLineHeight(kMessageLineHeight);
346 message_view_->SetVisible(!is_expanded_ || !notification.items().size()); 353 message_view_->SetVisible(!is_expanded_ || !notification.items().size());
347 message_view_->SetColors(message_center::kRegularTextColor, 354 message_view_->SetColors(message_center::kRegularTextColor,
348 kDimTextBackgroundColor); 355 kDimTextBackgroundColor);
349 message_view_->set_border(MakeTextBorder(padding, 4, 0)); 356 message_view_->SetBorder(MakeTextBorder(padding, 4, 0));
350 top_view_->AddChildView(message_view_); 357 top_view_->AddChildView(message_view_);
351 accessible_lines.push_back(notification.message()); 358 accessible_lines.push_back(notification.message());
352 } 359 }
353 360
354 // Create the context message view if appropriate. 361 // Create the context message view if appropriate.
355 context_message_view_ = NULL; 362 context_message_view_ = NULL;
356 if (!notification.context_message().empty()) { 363 if (!notification.context_message().empty()) {
357 int padding = kMessageLineHeight - default_label_font_list.GetHeight(); 364 int padding = kMessageLineHeight - default_label_font_list.GetHeight();
358 context_message_view_ = 365 context_message_view_ =
359 new BoundedLabel(gfx::TruncateString(notification.context_message(), 366 new BoundedLabel(gfx::TruncateString(notification.context_message(),
360 kContextMessageCharacterLimit), 367 kContextMessageCharacterLimit),
361 default_label_font_list); 368 default_label_font_list);
362 context_message_view_->SetLineLimit( 369 context_message_view_->SetLineLimit(
363 message_center::kContextMessageLineLimit); 370 message_center::kContextMessageLineLimit);
364 context_message_view_->SetLineHeight(kMessageLineHeight); 371 context_message_view_->SetLineHeight(kMessageLineHeight);
365 context_message_view_->SetColors(message_center::kDimTextColor, 372 context_message_view_->SetColors(message_center::kDimTextColor,
366 kContextTextBackgroundColor); 373 kContextTextBackgroundColor);
367 context_message_view_->set_border(MakeTextBorder(padding, 4, 0)); 374 context_message_view_->SetBorder(MakeTextBorder(padding, 4, 0));
368 top_view_->AddChildView(context_message_view_); 375 top_view_->AddChildView(context_message_view_);
369 accessible_lines.push_back(notification.context_message()); 376 accessible_lines.push_back(notification.context_message());
370 } 377 }
371 378
372 // Create the progress bar view. 379 // Create the progress bar view.
373 progress_bar_view_ = NULL; 380 progress_bar_view_ = NULL;
374 if (notification.type() == NOTIFICATION_TYPE_PROGRESS) { 381 if (notification.type() == NOTIFICATION_TYPE_PROGRESS) {
375 progress_bar_view_ = new NotificationProgressBar(); 382 progress_bar_view_ = new NotificationProgressBar();
376 progress_bar_view_->set_border(MakeProgressBarBorder( 383 progress_bar_view_->SetBorder(MakeProgressBarBorder(
377 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); 384 message_center::kProgressBarTopPadding, kProgressBarBottomPadding));
378 progress_bar_view_->SetValue(notification.progress() / 100.0); 385 progress_bar_view_->SetValue(notification.progress() / 100.0);
379 top_view_->AddChildView(progress_bar_view_); 386 top_view_->AddChildView(progress_bar_view_);
380 } 387 }
381 388
382 // Create the list item views (up to a maximum). 389 // Create the list item views (up to a maximum).
383 int padding = kMessageLineHeight - default_label_font_list.GetHeight(); 390 int padding = kMessageLineHeight - default_label_font_list.GetHeight();
384 std::vector<NotificationItem> items = notification.items(); 391 std::vector<NotificationItem> items = notification.items();
385 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { 392 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) {
386 ItemView* item_view = new ItemView(items[i]); 393 ItemView* item_view = new ItemView(items[i]);
387 item_view->SetVisible(is_expanded_); 394 item_view->SetVisible(is_expanded_);
388 item_view->set_border(MakeTextBorder(padding, i ? 0 : 4, 0)); 395 item_view->SetBorder(MakeTextBorder(padding, i ? 0 : 4, 0));
389 item_views_.push_back(item_view); 396 item_views_.push_back(item_view);
390 top_view_->AddChildView(item_view); 397 top_view_->AddChildView(item_view);
391 accessible_lines.push_back( 398 accessible_lines.push_back(
392 items[i].title + base::ASCIIToUTF16(" ") + items[i].message); 399 items[i].title + base::ASCIIToUTF16(" ") + items[i].message);
393 } 400 }
394 401
395 // Create the notification icon view. 402 // Create the notification icon view.
396 gfx::ImageSkia icon = notification.icon().AsImageSkia(); 403 gfx::ImageSkia icon = notification.icon().AsImageSkia();
397 if (notification.type() == NOTIFICATION_TYPE_SIMPLE && 404 if (notification.type() == NOTIFICATION_TYPE_SIMPLE &&
398 (icon.width() != kIconSize || 405 (icon.width() != kIconSize ||
(...skipping 26 matching lines...) Expand all
425 kNotificationPreferredImageWidth, kNotificationPreferredImageHeight); 432 kNotificationPreferredImageWidth, kNotificationPreferredImageHeight);
426 image_view_ = MakeNotificationImage(notification.image(), image_size); 433 image_view_ = MakeNotificationImage(notification.image(), image_size);
427 image_view_->SetVisible(is_expanded_); 434 image_view_->SetVisible(is_expanded_);
428 bottom_view_->AddChildView(image_view_); 435 bottom_view_->AddChildView(image_view_);
429 } 436 }
430 437
431 // Create action buttons if appropriate. 438 // Create action buttons if appropriate.
432 std::vector<ButtonInfo> buttons = notification.buttons(); 439 std::vector<ButtonInfo> buttons = notification.buttons();
433 for (size_t i = 0; i < buttons.size(); ++i) { 440 for (size_t i = 0; i < buttons.size(); ++i) {
434 views::View* separator = new views::ImageView(); 441 views::View* separator = new views::ImageView();
435 separator->set_border(MakeSeparatorBorder(1, 0, kButtonSeparatorColor)); 442 separator->SetBorder(MakeSeparatorBorder(1, 0, kButtonSeparatorColor));
436 bottom_view_->AddChildView(separator); 443 bottom_view_->AddChildView(separator);
437 NotificationButton* button = new NotificationButton(this); 444 NotificationButton* button = new NotificationButton(this);
438 ButtonInfo button_info = buttons[i]; 445 ButtonInfo button_info = buttons[i];
439 button->SetTitle(button_info.title); 446 button->SetTitle(button_info.title);
440 button->SetIcon(button_info.icon.AsImageSkia()); 447 button->SetIcon(button_info.icon.AsImageSkia());
441 action_buttons_.push_back(button); 448 action_buttons_.push_back(button);
442 bottom_view_->AddChildView(button); 449 bottom_view_->AddChildView(button);
443 } 450 }
444 451
445 // Create expand button 452 // Create expand button
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 return message_view_ ? 668 return message_view_ ?
662 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; 669 message_view_->GetLinesForWidthAndLimit(width, limit) : 0;
663 } 670 }
664 671
665 int NotificationView::GetMessageHeight(int width, int limit) { 672 int NotificationView::GetMessageHeight(int width, int limit) {
666 return message_view_ ? 673 return message_view_ ?
667 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; 674 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0;
668 } 675 }
669 676
670 } // namespace message_center 677 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698