| 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 "grit/ui_resources.h" | 7 #include "grit/ui_resources.h" |
| 8 #include "grit/ui_strings.h" | 8 #include "grit/ui_strings.h" |
| 9 #include "ui/base/accessibility/accessible_view_state.h" | 9 #include "ui/base/accessibility/accessible_view_state.h" |
| 10 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
| 11 #include "ui/base/models/simple_menu_model.h" | 11 #include "ui/base/models/simple_menu_model.h" |
| 12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 13 #include "ui/compositor/scoped_layer_animation_settings.h" | 13 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 14 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
| 15 #include "ui/message_center/message_center.h" | 15 #include "ui/message_center/message_center.h" |
| 16 #include "ui/message_center/message_center_style.h" | 16 #include "ui/message_center/message_center_style.h" |
| 17 #include "ui/message_center/message_center_util.h" | 17 #include "ui/message_center/message_center_util.h" |
| 18 #include "ui/message_center/views/padded_button.h" | 18 #include "ui/message_center/views/padded_button.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/scroll_view.h" | 22 #include "ui/views/controls/scroll_view.h" |
| 22 #include "ui/views/focus/focus_manager.h" | 23 #include "ui/views/focus/focus_manager.h" |
| 23 #include "ui/views/painter.h" | 24 #include "ui/views/painter.h" |
| 24 #include "ui/views/shadow_border.h" | 25 #include "ui/views/shadow_border.h" |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 const int kCloseIconTopPadding = 5; | 29 const int kCloseIconTopPadding = 5; |
| 29 const int kCloseIconRightPadding = 5; | 30 const int kCloseIconRightPadding = 5; |
| 30 | 31 |
| 31 const int kShadowOffset = 1; | 32 const int kShadowOffset = 1; |
| 32 const int kShadowBlur = 4; | 33 const int kShadowBlur = 4; |
| 33 | 34 |
| 34 } // namespace | 35 } // namespace |
| 35 | 36 |
| 36 namespace message_center { | 37 namespace message_center { |
| 37 | 38 |
| 38 MessageView::MessageView(MessageViewController* controller, | 39 MessageView::MessageView(MessageViewController* controller, |
| 39 const std::string& notification_id, | 40 const std::string& notification_id, |
| 40 const NotifierId& notifier_id, | 41 const NotifierId& notifier_id, |
| 42 const gfx::ImageSkia& small_image, |
| 41 const base::string16& display_source) | 43 const base::string16& display_source) |
| 42 : controller_(controller), | 44 : controller_(controller), |
| 43 notification_id_(notification_id), | 45 notification_id_(notification_id), |
| 44 notifier_id_(notifier_id), | 46 notifier_id_(notifier_id), |
| 45 background_view_(NULL), | 47 background_view_(NULL), |
| 46 scroller_(NULL), | 48 scroller_(NULL), |
| 47 display_source_(display_source) { | 49 display_source_(display_source) { |
| 48 SetFocusable(true); | 50 SetFocusable(true); |
| 49 | 51 |
| 50 // Create the opaque background that's above the view's shadow. | 52 // Create the opaque background that's above the view's shadow. |
| 51 background_view_ = new views::View(); | 53 background_view_ = new views::View(); |
| 52 background_view_->set_background( | 54 background_view_->set_background( |
| 53 views::Background::CreateSolidBackground(kNotificationBackgroundColor)); | 55 views::Background::CreateSolidBackground(kNotificationBackgroundColor)); |
| 54 AddChildView(background_view_); | 56 AddChildView(background_view_); |
| 55 | 57 |
| 58 views::ImageView* small_image_view = new views::ImageView(); |
| 59 small_image_view->SetImage(small_image); |
| 60 small_image_view->SetImageSize(gfx::Size(kSmallImageSize, kSmallImageSize)); |
| 61 // 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. |
| 63 small_image_view->set_owned_by_client(); |
| 64 small_image_view_.reset(small_image_view); |
| 65 |
| 56 PaddedButton *close = new PaddedButton(this); | 66 PaddedButton *close = new PaddedButton(this); |
| 57 close->SetPadding(-kCloseIconRightPadding, kCloseIconTopPadding); | 67 close->SetPadding(-kCloseIconRightPadding, kCloseIconTopPadding); |
| 58 close->SetNormalImage(IDR_NOTIFICATION_CLOSE); | 68 close->SetNormalImage(IDR_NOTIFICATION_CLOSE); |
| 59 close->SetHoveredImage(IDR_NOTIFICATION_CLOSE_HOVER); | 69 close->SetHoveredImage(IDR_NOTIFICATION_CLOSE_HOVER); |
| 60 close->SetPressedImage(IDR_NOTIFICATION_CLOSE_PRESSED); | 70 close->SetPressedImage(IDR_NOTIFICATION_CLOSE_PRESSED); |
| 61 close->set_animate_on_state_change(false); | 71 close->set_animate_on_state_change(false); |
| 62 close->SetAccessibleName(l10n_util::GetStringUTF16( | 72 close->SetAccessibleName(l10n_util::GetStringUTF16( |
| 63 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); | 73 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); |
| 64 // The close button should be added to view hierarchy by the derived class. | 74 // The close button should be added to view hierarchy by the derived class. |
| 65 // This ensures that it is on top of other views. | 75 // This ensures that it is on top of other views. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // Space key handling is triggerred at key-release timing. See | 142 // Space key handling is triggerred at key-release timing. See |
| 133 // ui/views/controls/buttons/custom_button.cc for why. | 143 // ui/views/controls/buttons/custom_button.cc for why. |
| 134 if (event.flags() != ui::EF_NONE || event.flags() != ui::VKEY_SPACE) | 144 if (event.flags() != ui::EF_NONE || event.flags() != ui::VKEY_SPACE) |
| 135 return false; | 145 return false; |
| 136 | 146 |
| 137 controller_->ClickOnNotification(notification_id_); | 147 controller_->ClickOnNotification(notification_id_); |
| 138 return true; | 148 return true; |
| 139 } | 149 } |
| 140 | 150 |
| 141 void MessageView::OnPaint(gfx::Canvas* canvas) { | 151 void MessageView::OnPaint(gfx::Canvas* canvas) { |
| 152 DCHECK_EQ(this, close_button_->parent()); |
| 153 DCHECK_EQ(this, small_image_view_->parent()); |
| 142 SlideOutView::OnPaint(canvas); | 154 SlideOutView::OnPaint(canvas); |
| 143 views::Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); | 155 views::Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); |
| 144 } | 156 } |
| 145 | 157 |
| 146 void MessageView::OnFocus() { | 158 void MessageView::OnFocus() { |
| 147 SlideOutView::OnFocus(); | 159 SlideOutView::OnFocus(); |
| 148 // We paint a focus indicator. | 160 // We paint a focus indicator. |
| 149 SchedulePaint(); | 161 SchedulePaint(); |
| 150 } | 162 } |
| 151 | 163 |
| 152 void MessageView::OnBlur() { | 164 void MessageView::OnBlur() { |
| 153 SlideOutView::OnBlur(); | 165 SlideOutView::OnBlur(); |
| 154 // We paint a focus indicator. | 166 // We paint a focus indicator. |
| 155 SchedulePaint(); | 167 SchedulePaint(); |
| 156 } | 168 } |
| 157 | 169 |
| 158 void MessageView::Layout() { | 170 void MessageView::Layout() { |
| 159 gfx::Rect content_bounds = GetContentsBounds(); | 171 gfx::Rect content_bounds = GetContentsBounds(); |
| 160 | 172 |
| 161 // Background. | 173 // Background. |
| 162 background_view_->SetBoundsRect(content_bounds); | 174 background_view_->SetBoundsRect(content_bounds); |
| 163 | 175 |
| 164 // Close button. | 176 // Close button. |
| 165 gfx::Size close_size(close_button_->GetPreferredSize()); | 177 gfx::Size close_size(close_button_->GetPreferredSize()); |
| 166 close_button_->SetBounds( | 178 gfx::Rect close_rect(content_bounds.right() - close_size.width(), |
| 167 content_bounds.right() - close_size.width(), content_bounds.y(), | 179 content_bounds.y(), |
| 168 close_size.width(), close_size.height()); | 180 close_size.width(), |
| 181 close_size.height()); |
| 182 close_button_->SetBoundsRect(close_rect); |
| 183 |
| 184 gfx::Size small_image_size(small_image_view_->GetPreferredSize()); |
| 185 gfx::Rect small_image_rect(small_image_size); |
| 186 small_image_rect.set_origin(gfx::Point( |
| 187 content_bounds.right() - small_image_size.width() - kSmallImagePadding, |
| 188 content_bounds.bottom() - small_image_size.height() - |
| 189 kSmallImagePadding)); |
| 190 small_image_view_->SetBoundsRect(small_image_rect); |
| 169 } | 191 } |
| 170 | 192 |
| 171 void MessageView::OnGestureEvent(ui::GestureEvent* event) { | 193 void MessageView::OnGestureEvent(ui::GestureEvent* event) { |
| 172 if (event->type() == ui::ET_GESTURE_TAP) { | 194 if (event->type() == ui::ET_GESTURE_TAP) { |
| 173 controller_->ClickOnNotification(notification_id_); | 195 controller_->ClickOnNotification(notification_id_); |
| 174 event->SetHandled(); | 196 event->SetHandled(); |
| 175 return; | 197 return; |
| 176 } | 198 } |
| 177 | 199 |
| 178 SlideOutView::OnGestureEvent(event); | 200 SlideOutView::OnGestureEvent(event); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 193 if (sender == close_button()) { | 215 if (sender == close_button()) { |
| 194 controller_->RemoveNotification(notification_id_, true); // By user. | 216 controller_->RemoveNotification(notification_id_, true); // By user. |
| 195 } | 217 } |
| 196 } | 218 } |
| 197 | 219 |
| 198 void MessageView::OnSlideOut() { | 220 void MessageView::OnSlideOut() { |
| 199 controller_->RemoveNotification(notification_id_, true); // By user. | 221 controller_->RemoveNotification(notification_id_, true); // By user. |
| 200 } | 222 } |
| 201 | 223 |
| 202 } // namespace message_center | 224 } // namespace message_center |
| OLD | NEW |