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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/message_center/views/notification_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/message_center/views/notification_view.cc
diff --git a/ui/message_center/views/notification_view.cc b/ui/message_center/views/notification_view.cc
index cee41f03326da583a2143968bf98a8107f1979d8..746f0822b8bdb8df86ec5df65c49a584c8456275 100644
--- a/ui/message_center/views/notification_view.cc
+++ b/ui/message_center/views/notification_view.cc
@@ -52,6 +52,9 @@ namespace {
// Dimensions.
const int kProgressBarBottomPadding = 0;
+constexpr int kCloseIconTopPadding = 5;
+constexpr int kCloseIconRightPadding = 5;
+
// static
std::unique_ptr<views::Border> MakeEmptyBorder(int top,
int left,
@@ -294,6 +297,16 @@ void NotificationView::Layout() {
settings_size.height());
}
+ // Close button.
+ if (close_button_) {
+ gfx::Rect content_bounds = GetContentsBounds();
+ gfx::Size close_size(close_button_->GetPreferredSize());
+ gfx::Rect close_rect(content_bounds.right() - close_size.width(),
+ content_bounds.y(), close_size.width(),
+ close_size.height());
+ close_button_->SetBoundsRect(close_rect);
+ }
+
bottom_view_->SetBounds(insets.left(), bottom_y,
content_width, bottom_height);
}
@@ -321,6 +334,7 @@ void NotificationView::UpdateWithNotification(
MessageView::UpdateWithNotification(notification);
CreateOrUpdateViews(notification);
+ CreateOrUpdateCloseButtonView(notification);
Layout();
SchedulePaint();
}
@@ -332,6 +346,13 @@ void NotificationView::ButtonPressed(views::Button* sender,
// TODO(dewittj): Remove this hack.
std::string id(notification_id());
+ if (close_button_ && sender == close_button_.get()) {
+ // Warning: This causes the NotificationView itself to be deleted, so don't
+ // do anything afterwards.
+ controller()->RemoveNotification(id, true /* by_user */);
+ return;
+ }
+
if (sender == settings_button_view_) {
controller()->ClickOnSettingsButton(id);
return;
@@ -344,11 +365,24 @@ void NotificationView::ButtonPressed(views::Button* sender,
return;
}
}
+}
+
+bool NotificationView::IsCloseButtonFocused() const {
+ if (!close_button_)
+ return false;
- // Let the superclass handle everything else.
- // Warning: This may cause the NotificationView itself to be deleted,
- // so don't do anything afterwards.
- MessageView::ButtonPressed(sender, event);
+ const views::FocusManager* focus_manager = GetFocusManager();
+ return focus_manager &&
+ focus_manager->GetFocusedView() == close_button_.get();
+}
+
+void NotificationView::RequestFocusOnCloseButton() {
+ if (close_button_)
+ close_button_->RequestFocus();
+}
+
+bool NotificationView::IsPinned() const {
+ return !close_button_;
}
void NotificationView::CreateOrUpdateTitleView(
@@ -630,6 +664,29 @@ void NotificationView::CreateOrUpdateActionButtonViews(
}
}
+void NotificationView::CreateOrUpdateCloseButtonView(
+ const Notification& notification) {
+ set_slide_out_enabled(!notification.pinned());
+
+ if (!notification.pinned() && !close_button_) {
+ PaddedButton* close = new PaddedButton(this);
+ close->SetPadding(-kCloseIconRightPadding, kCloseIconTopPadding);
+ close->SetNormalImage(IDR_NOTIFICATION_CLOSE);
+ close->SetHoveredImage(IDR_NOTIFICATION_CLOSE_HOVER);
+ close->SetPressedImage(IDR_NOTIFICATION_CLOSE_PRESSED);
+ close->set_animate_on_state_change(false);
+ close->SetAccessibleName(l10n_util::GetStringUTF16(
+ IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME));
+ close->SetTooltipText(l10n_util::GetStringUTF16(
+ IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP));
+ close->set_owned_by_client();
+ AddChildView(close);
+ close_button_.reset(close);
+ } else if (notification.pinned() && close_button_) {
+ close_button_.reset();
+ }
+}
+
int NotificationView::GetMessageLineLimit(int title_lines, int width) const {
// Image notifications require that the image must be kept flush against
// their icons, but we can allow more text if no image.
« 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