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

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

Issue 12742005: Added text line limits to collapsed and expanded notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 9 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/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "grit/ui_resources.h" 9 #include "grit/ui_resources.h"
10 #include "ui/base/accessibility/accessible_view_state.h" 10 #include "ui/base/accessibility/accessible_view_state.h"
11 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/base/text/text_elider.h" 12 #include "ui/base/text/text_elider.h"
13 #include "ui/gfx/canvas.h" 13 #include "ui/gfx/canvas.h"
14 #include "ui/gfx/size.h" 14 #include "ui/gfx/size.h"
15 #include "ui/message_center/message_center_constants.h" 15 #include "ui/message_center/message_center_constants.h"
16 #include "ui/message_center/message_center_switches.h" 16 #include "ui/message_center/message_center_switches.h"
17 #include "ui/message_center/message_center_util.h" 17 #include "ui/message_center/message_center_util.h"
18 #include "ui/message_center/notification.h" 18 #include "ui/message_center/notification.h"
19 #include "ui/message_center/notification_change_observer.h" 19 #include "ui/message_center/notification_change_observer.h"
20 #include "ui/message_center/notification_types.h" 20 #include "ui/message_center/notification_types.h"
21 #include "ui/message_center/views/bounded_label.h"
21 #include "ui/message_center/views/message_simple_view.h" 22 #include "ui/message_center/views/message_simple_view.h"
22 #include "ui/native_theme/native_theme.h" 23 #include "ui/native_theme/native_theme.h"
23 #include "ui/views/controls/button/image_button.h" 24 #include "ui/views/controls/button/image_button.h"
24 #include "ui/views/controls/image_view.h" 25 #include "ui/views/controls/image_view.h"
25 #include "ui/views/controls/label.h" 26 #include "ui/views/controls/label.h"
26 #include "ui/views/layout/box_layout.h" 27 #include "ui/views/layout/box_layout.h"
27 #include "ui/views/layout/fill_layout.h" 28 #include "ui/views/layout/fill_layout.h"
28 29
29 namespace { 30 namespace {
30 31
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 } 333 }
333 334
334 // Currently all roads lead to the generic NotificationView. 335 // Currently all roads lead to the generic NotificationView.
335 return new NotificationView(notification, observer, expanded); 336 return new NotificationView(notification, observer, expanded);
336 } 337 }
337 338
338 NotificationView::NotificationView(const Notification& notification, 339 NotificationView::NotificationView(const Notification& notification,
339 NotificationChangeObserver* observer, 340 NotificationChangeObserver* observer,
340 bool expanded) 341 bool expanded)
341 : MessageView(notification, observer, expanded) { 342 : MessageView(notification, observer, expanded) {
343 // As we build the view, we'll see if any part of it is expandable.
344 bool expandable = false;
345
342 // Create the opaque background that's above the view's shadow. 346 // Create the opaque background that's above the view's shadow.
343 background_view_ = new views::View(); 347 background_view_ = new views::View();
344 background_view_->set_background( 348 background_view_->set_background(
345 views::Background::CreateSolidBackground(kBackgroundColor)); 349 views::Background::CreateSolidBackground(kBackgroundColor));
346 350
347 // Create the top_view_, which collects into a vertical box all content 351 // Create the top_view_, which collects into a vertical box all content
348 // at the top of the notification (to the right of the icon) except for the 352 // at the top of the notification (to the right of the icon) except for the
349 // close button. 353 // close button.
350 top_view_ = new ContainerView(); 354 top_view_ = new ContainerView();
351 355
352 // Create the title view if appropriate. 356 // Create the title view if appropriate.
353 title_view_ = NULL; 357 title_view_ = NULL;
354 if (!notification.title().empty()) { 358 if (!notification.title().empty()) {
355 title_view_ = new views::Label(notification.title()); 359 gfx::Font font = views::Label().font().DeriveFont(4);
360 title_view_ = new BoundedLabel(notification.title(), font, 1);
356 title_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 361 title_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
357 if (is_expanded())
358 title_view_->SetMultiLine(true);
359 else
360 title_view_->SetElideBehavior(views::Label::ELIDE_AT_END);
361 title_view_->SetFont(title_view_->font().DeriveFont(4));
362 title_view_->SetEnabledColor(kTitleColor); 362 title_view_->SetEnabledColor(kTitleColor);
363 title_view_->SetBackgroundColor(kTitleBackgroundColor); 363 title_view_->SetBackgroundColor(kTitleBackgroundColor);
364 title_view_->set_border(MakeBorder(kTextTopPadding, 3)); 364 title_view_->set_border(MakeBorder(kTextTopPadding, 3));
365 top_view_->AddChildView(title_view_); 365 top_view_->AddChildView(title_view_);
366 } 366 }
367 367
368 // Create the message view if appropriate. 368 // Create the message view if appropriate.
369 message_view_ = NULL; 369 message_view_ = NULL;
370 if (!notification.message().empty()) { 370 if (!notification.message().empty()) {
371 message_view_ = new views::Label(notification.message()); 371 size_t lines = (is_expanded() && notification.image().IsEmpty()) ? 7 : 2;
372 message_view_ = new BoundedLabel(notification.message(), lines);
372 message_view_->SetVisible(!is_expanded() || !notification.items().size()); 373 message_view_->SetVisible(!is_expanded() || !notification.items().size());
373 message_view_->set_collapse_when_hidden(true); 374 message_view_->set_collapse_when_hidden(true);
374 message_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 375 message_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
375 if (is_expanded())
376 message_view_->SetMultiLine(true);
377 else
378 message_view_->SetElideBehavior(views::Label::ELIDE_AT_END);
379 message_view_->SetEnabledColor(kMessageColor); 376 message_view_->SetEnabledColor(kMessageColor);
380 message_view_->SetBackgroundColor(kMessageBackgroundColor); 377 message_view_->SetBackgroundColor(kMessageBackgroundColor);
381 message_view_->set_border(MakeBorder(0, 3)); 378 message_view_->set_border(MakeBorder(0, 3));
382 top_view_->AddChildView(message_view_); 379 top_view_->AddChildView(message_view_);
380 expandable = (message_view_->GetPreferredLines() > lines);
383 } 381 }
384 382
385 // Create the list item views (up to a maximum). 383 // Create the list item views (up to a maximum).
386 std::vector<NotificationItem> items = notification.items(); 384 std::vector<NotificationItem> items = notification.items();
387 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { 385 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) {
388 ItemView* item_view = new ItemView(items[i]); 386 ItemView* item_view = new ItemView(items[i]);
389 item_view->SetVisible(is_expanded()); 387 item_view->SetVisible(is_expanded());
390 item_view->set_border(MakeBorder(0, 4)); 388 item_view->set_border(MakeBorder(0, 4));
391 item_views_.push_back(item_view); 389 item_views_.push_back(item_view);
392 top_view_->AddChildView(item_view); 390 top_view_->AddChildView(item_view);
391 expandable = true;
393 } 392 }
394 393
395 // Create the notification icon view. 394 // Create the notification icon view.
396 icon_view_ = new ProportionalImageView(notification.icon().AsImageSkia()); 395 icon_view_ = new ProportionalImageView(notification.icon().AsImageSkia());
397 396
398 // Create the bottom_view_, which collects into a vertical box all content 397 // Create the bottom_view_, which collects into a vertical box all content
399 // below the notification icon except for the expand button. 398 // below the notification icon except for the expand button.
400 bottom_view_ = new ContainerView(); 399 bottom_view_ = new ContainerView();
401 bottom_view_->set_background( 400 bottom_view_->set_background(
402 views::Background::CreateSolidBackground(kBackgroundColor)); 401 views::Background::CreateSolidBackground(kBackgroundColor));
403 402
404 // Create the image view if appropriate. 403 // Create the image view if appropriate.
405 image_view_ = NULL; 404 image_view_ = NULL;
406 if (!notification.image().IsEmpty()) { 405 if (!notification.image().IsEmpty()) {
407 image_view_ = new ProportionalImageView(notification.image().AsImageSkia()); 406 image_view_ = new ProportionalImageView(notification.image().AsImageSkia());
408 image_view_->SetVisible(is_expanded()); 407 image_view_->SetVisible(is_expanded());
409 bottom_view_->AddChildView(image_view_); 408 bottom_view_->AddChildView(image_view_);
409 expandable = true;
410 } 410 }
411 411
412 // Create action buttons if appropriate. 412 // Create action buttons if appropriate.
413 std::vector<ButtonInfo> buttons = notification.buttons(); 413 std::vector<ButtonInfo> buttons = notification.buttons();
414 for (size_t i = 0; i < buttons.size(); ++i) { 414 for (size_t i = 0; i < buttons.size(); ++i) {
415 views::View* separator = new views::ImageView(); 415 views::View* separator = new views::ImageView();
416 separator->set_border(MakeBorder(1, 0, 0, 0, kButtonSeparatorColor)); 416 separator->set_border(MakeBorder(1, 0, 0, 0, kButtonSeparatorColor));
417 bottom_view_->AddChildView(separator); 417 bottom_view_->AddChildView(separator);
418 NotificationButton* button = new NotificationButton(this); 418 NotificationButton* button = new NotificationButton(this);
419 ButtonInfo button_info = buttons[i]; 419 ButtonInfo button_info = buttons[i];
420 button->SetTitle(button_info.title); 420 button->SetTitle(button_info.title);
421 button->SetIcon(button_info.icon.AsImageSkia()); 421 button->SetIcon(button_info.icon.AsImageSkia());
422 action_buttons_.push_back(button); 422 action_buttons_.push_back(button);
423 bottom_view_->AddChildView(button); 423 bottom_view_->AddChildView(button);
424 } 424 }
425 425
426 // Hide the expand button if appropriate. 426 // Hide the expand button if appropriate.
427 bool expandable = item_views_.size() || image_view_;
428 expand_button()->SetVisible(expandable && !is_expanded()); 427 expand_button()->SetVisible(expandable && !is_expanded());
429 428
430 // Put together the different content and control views. Layering those allows 429 // Put together the different content and control views. Layering those allows
431 // for proper layout logic and it also allows the close and expand buttons to 430 // for proper layout logic and it also allows the close and expand buttons to
432 // overlap the content as needed to provide large enough click and touch areas 431 // overlap the content as needed to provide large enough click and touch areas
433 // (<http://crbug.com/168822> and <http://crbug.com/168856>). 432 // (<http://crbug.com/168822> and <http://crbug.com/168856>).
434 AddChildView(background_view_); 433 AddChildView(background_view_);
435 AddChildView(top_view_); 434 AddChildView(top_view_);
436 AddChildView(icon_view_); 435 AddChildView(icon_view_);
437 AddChildView(bottom_view_); 436 AddChildView(bottom_view_);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 observer()->OnButtonClicked(notification_id(), i); 493 observer()->OnButtonClicked(notification_id(), i);
495 return; 494 return;
496 } 495 }
497 } 496 }
498 497
499 // Let the superclass handled anything other than action buttons. 498 // Let the superclass handled anything other than action buttons.
500 MessageView::ButtonPressed(sender, event); 499 MessageView::ButtonPressed(sender, event);
501 500
502 // Show and hide subviews appropriately on expansion. 501 // Show and hide subviews appropriately on expansion.
503 if (sender == expand_button()) { 502 if (sender == expand_button()) {
504 if (message_view_) 503 if (message_view_ && !item_views_.size() && !image_view_)
505 message_view_->SetVisible(!item_views_.size()); 504 message_view_->SetMaxLines(7);
505 else if (message_view_ && item_views_.size())
506 message_view_->SetVisible(false);
506 for (size_t i = 0; i < item_views_.size(); ++i) 507 for (size_t i = 0; i < item_views_.size(); ++i)
507 item_views_[i]->SetVisible(true); 508 item_views_[i]->SetVisible(true);
508 if (image_view_) 509 if (image_view_)
509 image_view_->SetVisible(true); 510 image_view_->SetVisible(true);
510 expand_button()->SetVisible(false); 511 expand_button()->SetVisible(false);
511 PreferredSizeChanged(); 512 PreferredSizeChanged();
512 SchedulePaint(); 513 SchedulePaint();
513 } 514 }
514 } 515 }
515 516
516 } // namespace message_center 517 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698