| OLD | NEW |
| 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/message_view.h" | 5 #include "ui/message_center/views/message_view.h" |
| 6 | 6 |
| 7 #include "ui/accessibility/ax_view_state.h" | 7 #include "ui/accessibility/ax_view_state.h" |
| 8 #include "ui/base/l10n/l10n_util.h" | 8 #include "ui/base/l10n/l10n_util.h" |
| 9 #include "ui/base/models/simple_menu_model.h" | 9 #include "ui/base/models/simple_menu_model.h" |
| 10 #include "ui/base/ui_base_switches_util.h" | 10 #include "ui/base/ui_base_switches_util.h" |
| 11 #include "ui/compositor/scoped_layer_animation_settings.h" | 11 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 13 #include "ui/gfx/shadow_value.h" | 13 #include "ui/gfx/shadow_value.h" |
| 14 #include "ui/message_center/message_center.h" | 14 #include "ui/message_center/message_center.h" |
| 15 #include "ui/message_center/message_center_style.h" | 15 #include "ui/message_center/message_center_style.h" |
| 16 #include "ui/message_center/views/padded_button.h" | 16 #include "ui/message_center/views/padded_button.h" |
| 17 #include "ui/resources/grit/ui_resources.h" | 17 #include "ui/resources/grit/ui_resources.h" |
| 18 #include "ui/strings/grit/ui_strings.h" | 18 #include "ui/strings/grit/ui_strings.h" |
| 19 #include "ui/views/background.h" | 19 #include "ui/views/background.h" |
| 20 #include "ui/views/controls/button/image_button.h" | 20 #include "ui/views/controls/button/image_button.h" |
| 21 #include "ui/views/controls/image_view.h" | 21 #include "ui/views/controls/image_view.h" |
| 22 #include "ui/views/controls/scroll_view.h" | 22 #include "ui/views/controls/scroll_view.h" |
| 23 #include "ui/views/focus/focus_manager.h" | 23 #include "ui/views/focus/focus_manager.h" |
| 24 #include "ui/views/painter.h" | 24 #include "ui/views/painter.h" |
| 25 #include "ui/views/shadow_border.h" | 25 #include "ui/views/shadow_border.h" |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 const int kCloseIconTopPadding = 5; | |
| 30 const int kCloseIconRightPadding = 5; | |
| 31 | |
| 32 const int kShadowOffset = 1; | 29 const int kShadowOffset = 1; |
| 33 const int kShadowBlur = 4; | 30 const int kShadowBlur = 4; |
| 34 | 31 |
| 35 } // namespace | 32 } // namespace |
| 36 | 33 |
| 37 namespace message_center { | 34 namespace message_center { |
| 38 | 35 |
| 39 MessageView::MessageView(MessageViewController* controller, | 36 MessageView::MessageView(MessageViewController* controller, |
| 40 const std::string& notification_id, | 37 const std::string& notification_id, |
| 41 const NotifierId& notifier_id, | 38 const NotifierId& notifier_id, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 56 AddChildView(background_view_); | 53 AddChildView(background_view_); |
| 57 | 54 |
| 58 views::ImageView* small_image_view = new views::ImageView(); | 55 views::ImageView* small_image_view = new views::ImageView(); |
| 59 small_image_view->SetImage(small_image); | 56 small_image_view->SetImage(small_image); |
| 60 small_image_view->SetImageSize(gfx::Size(kSmallImageSize, kSmallImageSize)); | 57 small_image_view->SetImageSize(gfx::Size(kSmallImageSize, kSmallImageSize)); |
| 61 // The small image view should be added to view hierarchy by the derived | 58 // The small image view should be added to view hierarchy by the derived |
| 62 // class. This ensures that it is on top of other views. | 59 // class. This ensures that it is on top of other views. |
| 63 small_image_view->set_owned_by_client(); | 60 small_image_view->set_owned_by_client(); |
| 64 small_image_view_.reset(small_image_view); | 61 small_image_view_.reset(small_image_view); |
| 65 | 62 |
| 66 PaddedButton *close = new PaddedButton(this); | |
| 67 close->SetPadding(-kCloseIconRightPadding, kCloseIconTopPadding); | |
| 68 close->SetNormalImage(IDR_NOTIFICATION_CLOSE); | |
| 69 close->SetHoveredImage(IDR_NOTIFICATION_CLOSE_HOVER); | |
| 70 close->SetPressedImage(IDR_NOTIFICATION_CLOSE_PRESSED); | |
| 71 close->set_animate_on_state_change(false); | |
| 72 close->SetAccessibleName(l10n_util::GetStringUTF16( | |
| 73 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); | |
| 74 // The close button should be added to view hierarchy by the derived class. | |
| 75 // This ensures that it is on top of other views. | |
| 76 close->set_owned_by_client(); | |
| 77 close_button_.reset(close); | |
| 78 | |
| 79 focus_painter_ = views::Painter::CreateSolidFocusPainter( | 63 focus_painter_ = views::Painter::CreateSolidFocusPainter( |
| 80 kFocusBorderColor, gfx::Insets(0, 1, 3, 2)); | 64 kFocusBorderColor, gfx::Insets(0, 1, 3, 2)); |
| 81 } | 65 } |
| 82 | 66 |
| 83 MessageView::~MessageView() { | 67 MessageView::~MessageView() { |
| 84 } | 68 } |
| 85 | 69 |
| 86 void MessageView::UpdateWithNotification(const Notification& notification) { | 70 void MessageView::UpdateWithNotification(const Notification& notification) { |
| 87 small_image_view_->SetImage(notification.small_image().AsImageSkia()); | 71 small_image_view_->SetImage(notification.small_image().AsImageSkia()); |
| 88 display_source_ = notification.display_source(); | 72 display_source_ = notification.display_source(); |
| 89 } | 73 } |
| 90 | 74 |
| 91 // static | 75 // static |
| 92 gfx::Insets MessageView::GetShadowInsets() { | 76 gfx::Insets MessageView::GetShadowInsets() { |
| 93 return gfx::Insets(kShadowBlur / 2 - kShadowOffset, | 77 return gfx::Insets(kShadowBlur / 2 - kShadowOffset, |
| 94 kShadowBlur / 2, | 78 kShadowBlur / 2, |
| 95 kShadowBlur / 2 + kShadowOffset, | 79 kShadowBlur / 2 + kShadowOffset, |
| 96 kShadowBlur / 2); | 80 kShadowBlur / 2); |
| 97 } | 81 } |
| 98 | 82 |
| 99 void MessageView::CreateShadowBorder() { | 83 void MessageView::CreateShadowBorder() { |
| 100 SetBorder(scoped_ptr<views::Border>(new views::ShadowBorder( | 84 SetBorder(scoped_ptr<views::Border>(new views::ShadowBorder( |
| 101 gfx::ShadowValue(gfx::Vector2d(0, kShadowOffset), kShadowBlur, | 85 gfx::ShadowValue(gfx::Vector2d(0, kShadowOffset), kShadowBlur, |
| 102 message_center::kShadowColor)))); | 86 message_center::kShadowColor)))); |
| 103 } | 87 } |
| 104 | 88 |
| 105 bool MessageView::IsCloseButtonFocused() { | 89 bool MessageView::IsCloseButtonFocused() { |
| 106 views::FocusManager* focus_manager = GetFocusManager(); | 90 // May be overridden by the owner of the close button. |
| 107 return focus_manager && focus_manager->GetFocusedView() == close_button(); | 91 return false; |
| 108 } | 92 } |
| 109 | 93 |
| 110 void MessageView::RequestFocusOnCloseButton() { | 94 void MessageView::RequestFocusOnCloseButton() { |
| 111 close_button_->RequestFocus(); | 95 // May be overridden by the owner of the close button. |
| 96 } |
| 97 |
| 98 bool MessageView::IsPinned() { |
| 99 return false; |
| 112 } | 100 } |
| 113 | 101 |
| 114 void MessageView::GetAccessibleState(ui::AXViewState* state) { | 102 void MessageView::GetAccessibleState(ui::AXViewState* state) { |
| 115 state->role = ui::AX_ROLE_BUTTON; | 103 state->role = ui::AX_ROLE_BUTTON; |
| 116 state->name = accessible_name_; | 104 state->name = accessible_name_; |
| 117 } | 105 } |
| 118 | 106 |
| 119 bool MessageView::OnMousePressed(const ui::MouseEvent& event) { | 107 bool MessageView::OnMousePressed(const ui::MouseEvent& event) { |
| 120 if (!event.IsOnlyLeftMouseButton()) | 108 if (!event.IsOnlyLeftMouseButton()) |
| 121 return false; | 109 return false; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 144 // Space key handling is triggerred at key-release timing. See | 132 // Space key handling is triggerred at key-release timing. See |
| 145 // ui/views/controls/buttons/custom_button.cc for why. | 133 // ui/views/controls/buttons/custom_button.cc for why. |
| 146 if (event.flags() != ui::EF_NONE || event.flags() != ui::VKEY_SPACE) | 134 if (event.flags() != ui::EF_NONE || event.flags() != ui::VKEY_SPACE) |
| 147 return false; | 135 return false; |
| 148 | 136 |
| 149 controller_->ClickOnNotification(notification_id_); | 137 controller_->ClickOnNotification(notification_id_); |
| 150 return true; | 138 return true; |
| 151 } | 139 } |
| 152 | 140 |
| 153 void MessageView::OnPaint(gfx::Canvas* canvas) { | 141 void MessageView::OnPaint(gfx::Canvas* canvas) { |
| 154 DCHECK_EQ(this, close_button_->parent()); | |
| 155 DCHECK_EQ(this, small_image_view_->parent()); | 142 DCHECK_EQ(this, small_image_view_->parent()); |
| 156 SlideOutView::OnPaint(canvas); | 143 SlideOutView::OnPaint(canvas); |
| 157 views::Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); | 144 views::Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); |
| 158 } | 145 } |
| 159 | 146 |
| 160 void MessageView::OnFocus() { | 147 void MessageView::OnFocus() { |
| 161 SlideOutView::OnFocus(); | 148 SlideOutView::OnFocus(); |
| 162 // We paint a focus indicator. | 149 // We paint a focus indicator. |
| 163 SchedulePaint(); | 150 SchedulePaint(); |
| 164 } | 151 } |
| 165 | 152 |
| 166 void MessageView::OnBlur() { | 153 void MessageView::OnBlur() { |
| 167 SlideOutView::OnBlur(); | 154 SlideOutView::OnBlur(); |
| 168 // We paint a focus indicator. | 155 // We paint a focus indicator. |
| 169 SchedulePaint(); | 156 SchedulePaint(); |
| 170 } | 157 } |
| 171 | 158 |
| 172 void MessageView::Layout() { | 159 void MessageView::Layout() { |
| 173 gfx::Rect content_bounds = GetContentsBounds(); | 160 gfx::Rect content_bounds = GetContentsBounds(); |
| 174 | 161 |
| 175 // Background. | 162 // Background. |
| 176 background_view_->SetBoundsRect(content_bounds); | 163 background_view_->SetBoundsRect(content_bounds); |
| 177 | 164 |
| 178 // Close button. | |
| 179 gfx::Size close_size(close_button_->GetPreferredSize()); | |
| 180 gfx::Rect close_rect(content_bounds.right() - close_size.width(), | |
| 181 content_bounds.y(), | |
| 182 close_size.width(), | |
| 183 close_size.height()); | |
| 184 close_button_->SetBoundsRect(close_rect); | |
| 185 | |
| 186 gfx::Size small_image_size(small_image_view_->GetPreferredSize()); | 165 gfx::Size small_image_size(small_image_view_->GetPreferredSize()); |
| 187 gfx::Rect small_image_rect(small_image_size); | 166 gfx::Rect small_image_rect(small_image_size); |
| 188 small_image_rect.set_origin(gfx::Point( | 167 small_image_rect.set_origin(gfx::Point( |
| 189 content_bounds.right() - small_image_size.width() - kSmallImagePadding, | 168 content_bounds.right() - small_image_size.width() - kSmallImagePadding, |
| 190 content_bounds.bottom() - small_image_size.height() - | 169 content_bounds.bottom() - small_image_size.height() - |
| 191 kSmallImagePadding)); | 170 kSmallImagePadding)); |
| 192 small_image_view_->SetBoundsRect(small_image_rect); | 171 small_image_view_->SetBoundsRect(small_image_rect); |
| 193 } | 172 } |
| 194 | 173 |
| 195 void MessageView::OnGestureEvent(ui::GestureEvent* event) { | 174 void MessageView::OnGestureEvent(ui::GestureEvent* event) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 222 if (!event->IsScrollGestureEvent() && !event->IsFlingScrollEvent()) | 201 if (!event->IsScrollGestureEvent() && !event->IsFlingScrollEvent()) |
| 223 return; | 202 return; |
| 224 | 203 |
| 225 if (scroller_) | 204 if (scroller_) |
| 226 scroller_->OnGestureEvent(event); | 205 scroller_->OnGestureEvent(event); |
| 227 event->SetHandled(); | 206 event->SetHandled(); |
| 228 } | 207 } |
| 229 | 208 |
| 230 void MessageView::ButtonPressed(views::Button* sender, | 209 void MessageView::ButtonPressed(views::Button* sender, |
| 231 const ui::Event& event) { | 210 const ui::Event& event) { |
| 232 if (sender == close_button()) { | |
| 233 controller_->RemoveNotification(notification_id_, true); // By user. | |
| 234 } | |
| 235 } | 211 } |
| 236 | 212 |
| 237 void MessageView::OnSlideOut() { | 213 void MessageView::OnSlideOut() { |
| 238 controller_->RemoveNotification(notification_id_, true); // By user. | 214 controller_->RemoveNotification(notification_id_, true); // By user. |
| 239 } | 215 } |
| 240 | 216 |
| 241 void MessageView::SetDrawBackgroundAsActive(bool active) { | 217 void MessageView::SetDrawBackgroundAsActive(bool active) { |
| 242 if (!switches::IsTouchFeedbackEnabled()) | 218 if (!switches::IsTouchFeedbackEnabled()) |
| 243 return; | 219 return; |
| 244 background_view_->background()-> | 220 background_view_->background()-> |
| 245 SetNativeControlColor(active ? kHoveredButtonBackgroundColor : | 221 SetNativeControlColor(active ? kHoveredButtonBackgroundColor : |
| 246 kNotificationBackgroundColor); | 222 kNotificationBackgroundColor); |
| 247 SchedulePaint(); | 223 SchedulePaint(); |
| 248 } | 224 } |
| 249 | 225 |
| 250 } // namespace message_center | 226 } // namespace message_center |
| OLD | NEW |