Chromium Code Reviews| Index: ui/message_center/views/message_view.cc |
| diff --git a/ui/message_center/views/message_view.cc b/ui/message_center/views/message_view.cc |
| index 7b400052dbdc0c6ab3d9c67d803ea29472836a59..cad695855ddc80f7177d1de5dea02ca416b8eeaa 100644 |
| --- a/ui/message_center/views/message_view.cc |
| +++ b/ui/message_center/views/message_view.cc |
| @@ -27,6 +27,9 @@ |
| namespace { |
| +const int kCloseIconTopPadding = 5; |
|
dewittj
2016/05/13 20:28:35
nit: I think that constexpr is slightly preferred
xiyuan
2016/05/13 22:31:00
Done.
|
| +const int kCloseIconRightPadding = 5; |
| + |
| const int kShadowOffset = 1; |
| const int kShadowBlur = 4; |
| @@ -35,16 +38,11 @@ const int kShadowBlur = 4; |
| namespace message_center { |
| MessageView::MessageView(MessageCenterController* controller, |
| - const std::string& notification_id, |
| - const NotifierId& notifier_id, |
| - const gfx::ImageSkia& small_image, |
| - const base::string16& display_source) |
| + const Notification& notification) |
| : controller_(controller), |
| - notification_id_(notification_id), |
| - notifier_id_(notifier_id), |
| - background_view_(NULL), |
| - scroller_(NULL), |
| - display_source_(display_source) { |
| + notification_id_(notification.id()), |
| + notifier_id_(notification.notifier_id()), |
| + display_source_(notification.display_source()) { |
| SetFocusBehavior(FocusBehavior::ALWAYS); |
| // Create the opaque background that's above the view's shadow. |
| @@ -54,7 +52,7 @@ MessageView::MessageView(MessageCenterController* controller, |
| AddChildView(background_view_); |
| views::ImageView* small_image_view = new views::ImageView(); |
| - small_image_view->SetImage(small_image); |
| + small_image_view->SetImage(notification.small_image().AsImageSkia()); |
| small_image_view->SetImageSize(gfx::Size(kSmallImageSize, kSmallImageSize)); |
| // The small image view should be added to view hierarchy by the derived |
| // class. This ensures that it is on top of other views. |
| @@ -71,6 +69,7 @@ MessageView::~MessageView() { |
| void MessageView::UpdateWithNotification(const Notification& notification) { |
| small_image_view_->SetImage(notification.small_image().AsImageSkia()); |
| display_source_ = notification.display_source(); |
| + CreateOrUpdateCloseButtonView(notification); |
| } |
| // static |
| @@ -88,16 +87,21 @@ void MessageView::CreateShadowBorder() { |
| } |
| bool MessageView::IsCloseButtonFocused() { |
| - // May be overridden by the owner of the close button. |
| - return false; |
| + if (!close_button_) |
| + return false; |
| + |
| + views::FocusManager* focus_manager = GetFocusManager(); |
| + return focus_manager && |
| + focus_manager->GetFocusedView() == close_button_.get(); |
| } |
| void MessageView::RequestFocusOnCloseButton() { |
| - // May be overridden by the owner of the close button. |
| + if (close_button_) |
| + close_button_->RequestFocus(); |
| } |
| bool MessageView::IsPinned() { |
| - return false; |
| + return !close_button_; |
| } |
| void MessageView::GetAccessibleState(ui::AXViewState* state) { |
| @@ -141,6 +145,7 @@ bool MessageView::OnKeyReleased(const ui::KeyEvent& event) { |
| void MessageView::OnPaint(gfx::Canvas* canvas) { |
| DCHECK_EQ(this, small_image_view_->parent()); |
| + DCHECK_EQ(this, close_button_->parent()); |
| SlideOutView::OnPaint(canvas); |
| views::Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); |
| } |
| @@ -163,6 +168,16 @@ void MessageView::Layout() { |
| // Background. |
| background_view_->SetBoundsRect(content_bounds); |
| + // 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); |
| + } |
| + |
| gfx::Size small_image_size(small_image_view_->GetPreferredSize()); |
| gfx::Rect small_image_rect(small_image_size); |
| small_image_rect.set_origin(gfx::Point( |
| @@ -209,6 +224,9 @@ void MessageView::OnGestureEvent(ui::GestureEvent* event) { |
| void MessageView::ButtonPressed(views::Button* sender, |
| const ui::Event& event) { |
| + if (close_button_ && sender == close_button_.get()) { |
| + controller()->RemoveNotification(notification_id(), true); // By user. |
| + } |
| } |
| void MessageView::OnSlideOut() { |
| @@ -224,4 +242,25 @@ void MessageView::SetDrawBackgroundAsActive(bool active) { |
| SchedulePaint(); |
| } |
| +void MessageView::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->set_owned_by_client(); |
| + AddChildView(close); |
| + close_button_.reset(close); |
| + } else if (notification.pinned() && close_button_) { |
| + close_button_.reset(); |
| + } |
| +} |
| + |
| } // namespace message_center |