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

Unified Diff: ui/message_center/views/notification_view.cc

Issue 1645843003: Implement Non-Closable Notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary property. Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/message_center/views/notification_view.h ('k') | ui/message_center/views/notification_view_unittest.cc » ('j') | 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 fe91d1b09469a099755b1165664ef94720302697..254fcbf13501358a449bd3e870c278c0f1db818b 100644
--- a/ui/message_center/views/notification_view.cc
+++ b/ui/message_center/views/notification_view.cc
@@ -59,6 +59,9 @@ namespace {
// Dimensions.
const int kProgressBarBottomPadding = 0;
+const int kCloseIconTopPadding = 5;
+const int kCloseIconRightPadding = 5;
+
// static
scoped_ptr<views::Border> MakeEmptyBorder(int top,
int left,
@@ -228,7 +231,8 @@ views::View* NotificationView::TargetForRect(views::View* root,
action_buttons_.end());
if (settings_button_view_)
buttons.push_back(settings_button_view_);
- buttons.push_back(close_button());
+ if (close_button_)
+ buttons.push_back(close_button_.get());
for (size_t i = 0; i < buttons.size(); ++i) {
gfx::Point point_in_child = point;
@@ -241,6 +245,7 @@ views::View* NotificationView::TargetForRect(views::View* root,
}
void NotificationView::CreateOrUpdateViews(const Notification& notification) {
+ CreateOrUpdateCloseButtonView(notification);
CreateOrUpdateTitleView(notification);
CreateOrUpdateMessageView(notification);
CreateOrUpdateProgressBarView(notification);
@@ -308,7 +313,6 @@ NotificationView::NotificationView(MessageCenterController* controller,
// image to overlap the content as needed to provide large enough click and
// touch areas (<http://crbug.com/168822> and <http://crbug.com/168856>).
AddChildView(small_image());
- AddChildView(close_button());
SetAccessibleName(notification);
SetEventTargeter(
@@ -378,6 +382,16 @@ void NotificationView::Layout() {
int top_height = top_view_->GetHeightForWidth(content_width);
top_view_->SetBounds(insets.left(), insets.top(), content_width, top_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);
+ }
+
// Icon.
icon_view_->SetBounds(insets.left(), insets.top(), kIconSize, kIconSize);
@@ -445,6 +459,10 @@ void NotificationView::ButtonPressed(views::Button* sender,
}
}
+ if (close_button_ && sender == close_button_.get()) {
+ controller_->RemoveNotification(notification_id(), true); // By user.
+ }
+
// Let the superclass handle everything else.
// Warning: This may cause the NotificationView itself to be deleted,
// so don't do anything afterwards.
@@ -772,6 +790,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));
+ // The close button should be added to view hierarchy by the derived class.
+ // This ensures that it is on top of other views.
+ close->set_owned_by_client();
+ close_button_.reset(close);
+ AddChildView(close_button_.get());
+ } 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.
@@ -813,4 +854,22 @@ int NotificationView::GetMessageHeight(int width, int limit) const {
message_view_->GetSizeForWidthAndLines(width, limit).height() : 0;
}
+bool NotificationView::IsCloseButtonFocused() {
+ if (!close_button_)
+ return false;
+
+ 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() {
+ return !close_button_;
+}
+
} // namespace message_center
« no previous file with comments | « ui/message_center/views/notification_view.h ('k') | ui/message_center/views/notification_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698