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