| 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..1c75ff3172bf29b4e51dfda0540840d16b82a42b 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,17 @@ 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 +460,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 +791,29 @@ void NotificationView::CreateOrUpdateActionButtonViews(
|
| }
|
| }
|
|
|
| +void NotificationView::CreateOrUpdateCloseButtonView(
|
| + const Notification& notification) {
|
| + set_closable(notification.closable());
|
| +
|
| + if (notification.closable() && !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.closable() && 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 +855,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::IsClosable() {
|
| + return close_button_;
|
| +}
|
| +
|
| } // namespace message_center
|
|
|