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

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

Issue 1979553003: Consolidate to use MessageView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 child_at(i)->SetVisible(visible); 143 child_at(i)->SetVisible(visible);
144 } 144 }
145 145
146 } // namespace 146 } // namespace
147 147
148 namespace message_center { 148 namespace message_center {
149 149
150 // NotificationView //////////////////////////////////////////////////////////// 150 // NotificationView ////////////////////////////////////////////////////////////
151 151
152 // static 152 // static
153 NotificationView* NotificationView::Create(MessageCenterController* controller, 153 MessageView* NotificationView::Create(MessageCenterController* controller,
154 const Notification& notification, 154 const Notification& notification,
155 bool top_level) { 155 bool top_level) {
156 switch (notification.type()) { 156 switch (notification.type()) {
157 case NOTIFICATION_TYPE_BASE_FORMAT: 157 case NOTIFICATION_TYPE_BASE_FORMAT:
158 case NOTIFICATION_TYPE_IMAGE: 158 case NOTIFICATION_TYPE_IMAGE:
159 case NOTIFICATION_TYPE_MULTIPLE: 159 case NOTIFICATION_TYPE_MULTIPLE:
160 case NOTIFICATION_TYPE_SIMPLE: 160 case NOTIFICATION_TYPE_SIMPLE:
161 case NOTIFICATION_TYPE_PROGRESS: 161 case NOTIFICATION_TYPE_PROGRESS:
162 break; 162 break;
163 default: 163 default:
164 // If the caller asks for an unrecognized kind of view (entirely possible 164 // If the caller asks for an unrecognized kind of view (entirely possible
165 // if an application is running on an older version of this code that 165 // if an application is running on an older version of this code that
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { 242 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) {
243 accessible_lines.push_back(items[i].title + base::ASCIIToUTF16(" ") + 243 accessible_lines.push_back(items[i].title + base::ASCIIToUTF16(" ") +
244 items[i].message); 244 items[i].message);
245 } 245 }
246 set_accessible_name( 246 set_accessible_name(
247 base::JoinString(accessible_lines, base::ASCIIToUTF16("\n"))); 247 base::JoinString(accessible_lines, base::ASCIIToUTF16("\n")));
248 } 248 }
249 249
250 NotificationView::NotificationView(MessageCenterController* controller, 250 NotificationView::NotificationView(MessageCenterController* controller,
251 const Notification& notification) 251 const Notification& notification)
252 : MessageView(this, 252 : MessageView(controller,
253 notification.id(), 253 notification.id(),
254 notification.notifier_id(), 254 notification.notifier_id(),
255 notification.small_image().AsImageSkia(), 255 notification.small_image().AsImageSkia(),
256 notification.display_source()), 256 notification.display_source()),
257 controller_(controller),
258 clickable_(notification.clickable()), 257 clickable_(notification.clickable()),
259 top_view_(NULL), 258 top_view_(NULL),
260 title_view_(NULL), 259 title_view_(NULL),
261 message_view_(NULL), 260 message_view_(NULL),
262 context_message_view_(NULL), 261 context_message_view_(NULL),
263 settings_button_view_(NULL), 262 settings_button_view_(NULL),
264 icon_view_(NULL), 263 icon_view_(NULL),
265 bottom_view_(NULL), 264 bottom_view_(NULL),
266 image_container_(NULL), 265 image_container_(NULL),
267 image_view_(NULL), 266 image_view_(NULL),
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 ScrollRectToVisible(GetLocalBounds()); 395 ScrollRectToVisible(GetLocalBounds());
397 } 396 }
398 397
399 void NotificationView::ScrollRectToVisible(const gfx::Rect& rect) { 398 void NotificationView::ScrollRectToVisible(const gfx::Rect& rect) {
400 // Notification want to show the whole notification when a part of it (like 399 // Notification want to show the whole notification when a part of it (like
401 // a button) gets focused. 400 // a button) gets focused.
402 views::View::ScrollRectToVisible(GetLocalBounds()); 401 views::View::ScrollRectToVisible(GetLocalBounds());
403 } 402 }
404 403
405 gfx::NativeCursor NotificationView::GetCursor(const ui::MouseEvent& event) { 404 gfx::NativeCursor NotificationView::GetCursor(const ui::MouseEvent& event) {
406 if (!clickable_ || !controller_->HasClickedListener(notification_id())) 405 if (!clickable_ || !controller()->HasClickedListener(notification_id()))
407 return views::View::GetCursor(event); 406 return views::View::GetCursor(event);
408 407
409 return views::GetNativeHandCursor(); 408 return views::GetNativeHandCursor();
410 } 409 }
411 410
412 void NotificationView::UpdateWithNotification( 411 void NotificationView::UpdateWithNotification(
413 const Notification& notification) { 412 const Notification& notification) {
414 MessageView::UpdateWithNotification(notification); 413 MessageView::UpdateWithNotification(notification);
415 414
416 CreateOrUpdateViews(notification); 415 CreateOrUpdateViews(notification);
417 SetAccessibleName(notification); 416 SetAccessibleName(notification);
418 Layout(); 417 Layout();
419 SchedulePaint(); 418 SchedulePaint();
420 } 419 }
421 420
422 void NotificationView::ButtonPressed(views::Button* sender, 421 void NotificationView::ButtonPressed(views::Button* sender,
423 const ui::Event& event) { 422 const ui::Event& event) {
424 // Certain operations can cause |this| to be destructed, so copy the members 423 // Certain operations can cause |this| to be destructed, so copy the members
425 // we send to other parts of the code. 424 // we send to other parts of the code.
426 // TODO(dewittj): Remove this hack. 425 // TODO(dewittj): Remove this hack.
427 std::string id(notification_id()); 426 std::string id(notification_id());
428 427
429 if (sender == settings_button_view_) { 428 if (sender == settings_button_view_) {
430 controller_->ClickOnSettingsButton(id); 429 controller()->ClickOnSettingsButton(id);
431 return; 430 return;
432 } 431 }
433 432
434 // See if the button pressed was an action button. 433 // See if the button pressed was an action button.
435 for (size_t i = 0; i < action_buttons_.size(); ++i) { 434 for (size_t i = 0; i < action_buttons_.size(); ++i) {
436 if (sender == action_buttons_[i]) { 435 if (sender == action_buttons_[i]) {
437 controller_->ClickOnNotificationButton(id, i); 436 controller()->ClickOnNotificationButton(id, i);
438 return; 437 return;
439 } 438 }
440 } 439 }
441 440
442 if (close_button_ && sender == close_button_.get()) { 441 if (close_button_ && sender == close_button_.get()) {
443 controller_->RemoveNotification(notification_id(), true); // By user. 442 controller()->RemoveNotification(notification_id(), true); // By user.
444 } 443 }
445 444
446 // Let the superclass handle everything else. 445 // Let the superclass handle everything else.
447 // Warning: This may cause the NotificationView itself to be deleted, 446 // Warning: This may cause the NotificationView itself to be deleted,
448 // so don't do anything afterwards. 447 // so don't do anything afterwards.
449 MessageView::ButtonPressed(sender, event); 448 MessageView::ButtonPressed(sender, event);
450 } 449 }
451 450
452 void NotificationView::ClickOnNotification(const std::string& notification_id) {
453 controller_->ClickOnNotification(notification_id);
454 }
455
456 void NotificationView::RemoveNotification(const std::string& notification_id,
457 bool by_user) {
458 controller_->RemoveNotification(notification_id, by_user);
459 }
460
461 void NotificationView::CreateOrUpdateTitleView( 451 void NotificationView::CreateOrUpdateTitleView(
462 const Notification& notification) { 452 const Notification& notification) {
463 if (notification.title().empty()) { 453 if (notification.title().empty()) {
464 if (title_view_) { 454 if (title_view_) {
465 // Deletion will also remove |title_view_| from its parent. 455 // Deletion will also remove |title_view_| from its parent.
466 delete title_view_; 456 delete title_view_;
467 title_view_ = NULL; 457 title_view_ = NULL;
468 } 458 }
469 return; 459 return;
470 } 460 }
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 void NotificationView::RequestFocusOnCloseButton() { 830 void NotificationView::RequestFocusOnCloseButton() {
841 if (close_button_) 831 if (close_button_)
842 close_button_->RequestFocus(); 832 close_button_->RequestFocus();
843 } 833 }
844 834
845 bool NotificationView::IsPinned() { 835 bool NotificationView::IsPinned() {
846 return !close_button_; 836 return !close_button_;
847 } 837 }
848 838
849 } // namespace message_center 839 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698