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

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

Issue 2547433002: Transfer responsibility for providing a close button for a notification to each implementation of M… (Closed)
Patch Set: WrapUnique -> MakeUnique Created 4 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
« no previous file with comments | « ui/message_center/views/notification_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "ui/views/painter.h" 45 #include "ui/views/painter.h"
46 #include "ui/views/view_targeter.h" 46 #include "ui/views/view_targeter.h"
47 #include "ui/views/widget/widget.h" 47 #include "ui/views/widget/widget.h"
48 #include "url/gurl.h" 48 #include "url/gurl.h"
49 49
50 namespace { 50 namespace {
51 51
52 // Dimensions. 52 // Dimensions.
53 const int kProgressBarBottomPadding = 0; 53 const int kProgressBarBottomPadding = 0;
54 54
55 constexpr int kCloseIconTopPadding = 5;
56 constexpr int kCloseIconRightPadding = 5;
57
55 // static 58 // static
56 std::unique_ptr<views::Border> MakeEmptyBorder(int top, 59 std::unique_ptr<views::Border> MakeEmptyBorder(int top,
57 int left, 60 int left,
58 int bottom, 61 int bottom,
59 int right) { 62 int right) {
60 return views::CreateEmptyBorder(top, left, bottom, right); 63 return views::CreateEmptyBorder(top, left, bottom, right);
61 } 64 }
62 65
63 // static 66 // static
64 std::unique_ptr<views::Border> MakeTextBorder(int padding, 67 std::unique_ptr<views::Border> MakeTextBorder(int padding,
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 int bottom_height = bottom_view_->GetHeightForWidth(content_width); 290 int bottom_height = bottom_view_->GetHeightForWidth(content_width);
288 291
289 if (settings_button_view_) { 292 if (settings_button_view_) {
290 gfx::Size settings_size(settings_button_view_->GetPreferredSize()); 293 gfx::Size settings_size(settings_button_view_->GetPreferredSize());
291 settings_button_view_->SetBounds(content_width - settings_size.width(), 294 settings_button_view_->SetBounds(content_width - settings_size.width(),
292 bottom_y - settings_size.height(), 295 bottom_y - settings_size.height(),
293 settings_size.width(), 296 settings_size.width(),
294 settings_size.height()); 297 settings_size.height());
295 } 298 }
296 299
300 // Close button.
301 if (close_button_) {
302 gfx::Rect content_bounds = GetContentsBounds();
303 gfx::Size close_size(close_button_->GetPreferredSize());
304 gfx::Rect close_rect(content_bounds.right() - close_size.width(),
305 content_bounds.y(), close_size.width(),
306 close_size.height());
307 close_button_->SetBoundsRect(close_rect);
308 }
309
297 bottom_view_->SetBounds(insets.left(), bottom_y, 310 bottom_view_->SetBounds(insets.left(), bottom_y,
298 content_width, bottom_height); 311 content_width, bottom_height);
299 } 312 }
300 313
301 void NotificationView::OnFocus() { 314 void NotificationView::OnFocus() {
302 MessageView::OnFocus(); 315 MessageView::OnFocus();
303 ScrollRectToVisible(GetLocalBounds()); 316 ScrollRectToVisible(GetLocalBounds());
304 } 317 }
305 318
306 void NotificationView::ScrollRectToVisible(const gfx::Rect& rect) { 319 void NotificationView::ScrollRectToVisible(const gfx::Rect& rect) {
307 // Notification want to show the whole notification when a part of it (like 320 // Notification want to show the whole notification when a part of it (like
308 // a button) gets focused. 321 // a button) gets focused.
309 views::View::ScrollRectToVisible(GetLocalBounds()); 322 views::View::ScrollRectToVisible(GetLocalBounds());
310 } 323 }
311 324
312 gfx::NativeCursor NotificationView::GetCursor(const ui::MouseEvent& event) { 325 gfx::NativeCursor NotificationView::GetCursor(const ui::MouseEvent& event) {
313 if (!clickable_ || !controller()->HasClickedListener(notification_id())) 326 if (!clickable_ || !controller()->HasClickedListener(notification_id()))
314 return views::View::GetCursor(event); 327 return views::View::GetCursor(event);
315 328
316 return views::GetNativeHandCursor(); 329 return views::GetNativeHandCursor();
317 } 330 }
318 331
319 void NotificationView::UpdateWithNotification( 332 void NotificationView::UpdateWithNotification(
320 const Notification& notification) { 333 const Notification& notification) {
321 MessageView::UpdateWithNotification(notification); 334 MessageView::UpdateWithNotification(notification);
322 335
323 CreateOrUpdateViews(notification); 336 CreateOrUpdateViews(notification);
337 CreateOrUpdateCloseButtonView(notification);
324 Layout(); 338 Layout();
325 SchedulePaint(); 339 SchedulePaint();
326 } 340 }
327 341
328 void NotificationView::ButtonPressed(views::Button* sender, 342 void NotificationView::ButtonPressed(views::Button* sender,
329 const ui::Event& event) { 343 const ui::Event& event) {
330 // Certain operations can cause |this| to be destructed, so copy the members 344 // Certain operations can cause |this| to be destructed, so copy the members
331 // we send to other parts of the code. 345 // we send to other parts of the code.
332 // TODO(dewittj): Remove this hack. 346 // TODO(dewittj): Remove this hack.
333 std::string id(notification_id()); 347 std::string id(notification_id());
334 348
349 if (close_button_ && sender == close_button_.get()) {
350 // Warning: This causes the NotificationView itself to be deleted, so don't
351 // do anything afterwards.
352 controller()->RemoveNotification(id, true /* by_user */);
353 return;
354 }
355
335 if (sender == settings_button_view_) { 356 if (sender == settings_button_view_) {
336 controller()->ClickOnSettingsButton(id); 357 controller()->ClickOnSettingsButton(id);
337 return; 358 return;
338 } 359 }
339 360
340 // See if the button pressed was an action button. 361 // See if the button pressed was an action button.
341 for (size_t i = 0; i < action_buttons_.size(); ++i) { 362 for (size_t i = 0; i < action_buttons_.size(); ++i) {
342 if (sender == action_buttons_[i]) { 363 if (sender == action_buttons_[i]) {
343 controller()->ClickOnNotificationButton(id, i); 364 controller()->ClickOnNotificationButton(id, i);
344 return; 365 return;
345 } 366 }
346 } 367 }
368 }
347 369
348 // Let the superclass handle everything else. 370 bool NotificationView::IsCloseButtonFocused() const {
349 // Warning: This may cause the NotificationView itself to be deleted, 371 if (!close_button_)
350 // so don't do anything afterwards. 372 return false;
351 MessageView::ButtonPressed(sender, event); 373
374 const views::FocusManager* focus_manager = GetFocusManager();
375 return focus_manager &&
376 focus_manager->GetFocusedView() == close_button_.get();
377 }
378
379 void NotificationView::RequestFocusOnCloseButton() {
380 if (close_button_)
381 close_button_->RequestFocus();
382 }
383
384 bool NotificationView::IsPinned() const {
385 return !close_button_;
352 } 386 }
353 387
354 void NotificationView::CreateOrUpdateTitleView( 388 void NotificationView::CreateOrUpdateTitleView(
355 const Notification& notification) { 389 const Notification& notification) {
356 if (notification.title().empty()) { 390 if (notification.title().empty()) {
357 // Deletion will also remove |title_view_| from its parent. 391 // Deletion will also remove |title_view_| from its parent.
358 delete title_view_; 392 delete title_view_;
359 title_view_ = nullptr; 393 title_view_ = nullptr;
360 return; 394 return;
361 } 395 }
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 if (new_buttons) { 657 if (new_buttons) {
624 Layout(); 658 Layout();
625 views::Widget* widget = GetWidget(); 659 views::Widget* widget = GetWidget();
626 if (widget != NULL) { 660 if (widget != NULL) {
627 widget->SetSize(widget->GetContentsView()->GetPreferredSize()); 661 widget->SetSize(widget->GetContentsView()->GetPreferredSize());
628 GetWidget()->SynthesizeMouseMoveEvent(); 662 GetWidget()->SynthesizeMouseMoveEvent();
629 } 663 }
630 } 664 }
631 } 665 }
632 666
667 void NotificationView::CreateOrUpdateCloseButtonView(
668 const Notification& notification) {
669 set_slide_out_enabled(!notification.pinned());
670
671 if (!notification.pinned() && !close_button_) {
672 PaddedButton* close = new PaddedButton(this);
673 close->SetPadding(-kCloseIconRightPadding, kCloseIconTopPadding);
674 close->SetNormalImage(IDR_NOTIFICATION_CLOSE);
675 close->SetHoveredImage(IDR_NOTIFICATION_CLOSE_HOVER);
676 close->SetPressedImage(IDR_NOTIFICATION_CLOSE_PRESSED);
677 close->set_animate_on_state_change(false);
678 close->SetAccessibleName(l10n_util::GetStringUTF16(
679 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME));
680 close->SetTooltipText(l10n_util::GetStringUTF16(
681 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP));
682 close->set_owned_by_client();
683 AddChildView(close);
684 close_button_.reset(close);
685 } else if (notification.pinned() && close_button_) {
686 close_button_.reset();
687 }
688 }
689
633 int NotificationView::GetMessageLineLimit(int title_lines, int width) const { 690 int NotificationView::GetMessageLineLimit(int title_lines, int width) const {
634 // Image notifications require that the image must be kept flush against 691 // Image notifications require that the image must be kept flush against
635 // their icons, but we can allow more text if no image. 692 // their icons, but we can allow more text if no image.
636 int effective_title_lines = std::max(0, title_lines - 1); 693 int effective_title_lines = std::max(0, title_lines - 1);
637 int line_reduction_from_title = (image_view_ ? 1 : 2) * effective_title_lines; 694 int line_reduction_from_title = (image_view_ ? 1 : 2) * effective_title_lines;
638 if (!image_view_) { 695 if (!image_view_) {
639 // Title lines are counted as twice as big as message lines for the purpose 696 // Title lines are counted as twice as big as message lines for the purpose
640 // of this calculation. 697 // of this calculation.
641 // The effect from the title reduction here should be: 698 // The effect from the title reduction here should be:
642 // * 0 title lines: 5 max lines message. 699 // * 0 title lines: 5 max lines message.
(...skipping 22 matching lines...) Expand all
665 722
666 return message_line_limit; 723 return message_line_limit;
667 } 724 }
668 725
669 int NotificationView::GetMessageHeight(int width, int limit) const { 726 int NotificationView::GetMessageHeight(int width, int limit) const {
670 return message_view_ ? 727 return message_view_ ?
671 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; 728 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0;
672 } 729 }
673 730
674 } // namespace message_center 731 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/notification_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698