| 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 "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/accessibility/ax_node_data.h" | 8 #include "ui/accessibility/ax_node_data.h" |
| 9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
| 10 #include "ui/base/models/simple_menu_model.h" | 10 #include "ui/base/models/simple_menu_model.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/image/image_skia_operations.h" | 13 #include "ui/gfx/image/image_skia_operations.h" |
| 14 #include "ui/gfx/shadow_util.h" | 14 #include "ui/gfx/shadow_util.h" |
| 15 #include "ui/gfx/shadow_value.h" | 15 #include "ui/gfx/shadow_value.h" |
| 16 #include "ui/message_center/message_center.h" | 16 #include "ui/message_center/message_center.h" |
| 17 #include "ui/message_center/message_center_style.h" | 17 #include "ui/message_center/message_center_style.h" |
| 18 #include "ui/message_center/views/message_center_controller.h" | 18 #include "ui/message_center/views/message_center_controller.h" |
| 19 #include "ui/resources/grit/ui_resources.h" | 19 #include "ui/resources/grit/ui_resources.h" |
| 20 #include "ui/strings/grit/ui_strings.h" | 20 #include "ui/strings/grit/ui_strings.h" |
| 21 #include "ui/views/background.h" | 21 #include "ui/views/background.h" |
| 22 #include "ui/views/border.h" | 22 #include "ui/views/border.h" |
| 23 #include "ui/views/controls/button/image_button.h" | 23 #include "ui/views/controls/button/image_button.h" |
| 24 #include "ui/views/controls/image_view.h" | 24 #include "ui/views/controls/image_view.h" |
| 25 #include "ui/views/controls/scroll_view.h" | 25 #include "ui/views/controls/scroll_view.h" |
| 26 #include "ui/views/focus/focus_manager.h" | 26 #include "ui/views/focus/focus_manager.h" |
| 27 #include "ui/views/painter.h" | 27 #include "ui/views/painter.h" |
| 28 #include "ui/views/widget/widget.h" |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 #if defined(OS_CHROMEOS) | 32 #if defined(OS_CHROMEOS) |
| 32 const int kShadowCornerRadius = 2; | 33 const int kShadowCornerRadius = 2; |
| 33 #else | 34 #else |
| 34 const int kShadowCornerRadius = 0; | 35 const int kShadowCornerRadius = 0; |
| 35 #endif | 36 #endif |
| 36 const int kShadowElevation = 2; | 37 const int kShadowElevation = 2; |
| 37 | 38 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 57 } | 58 } |
| 58 | 59 |
| 59 } // namespace | 60 } // namespace |
| 60 | 61 |
| 61 namespace message_center { | 62 namespace message_center { |
| 62 | 63 |
| 63 MessageView::MessageView(MessageCenterController* controller, | 64 MessageView::MessageView(MessageCenterController* controller, |
| 64 const Notification& notification) | 65 const Notification& notification) |
| 65 : controller_(controller), | 66 : controller_(controller), |
| 66 notification_id_(notification.id()), | 67 notification_id_(notification.id()), |
| 67 notifier_id_(notification.notifier_id()) { | 68 notifier_id_(notification.notifier_id()), |
| 69 slide_out_controller_(this, this) { |
| 68 SetFocusBehavior(FocusBehavior::ALWAYS); | 70 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 69 | 71 |
| 70 // Create the opaque background that's above the view's shadow. | 72 // Create the opaque background that's above the view's shadow. |
| 71 background_view_ = new views::View(); | 73 background_view_ = new views::View(); |
| 72 background_view_->set_background( | 74 background_view_->set_background( |
| 73 views::Background::CreateSolidBackground(kNotificationBackgroundColor)); | 75 views::Background::CreateSolidBackground(kNotificationBackgroundColor)); |
| 74 AddChildView(background_view_); | 76 AddChildView(background_view_); |
| 75 | 77 |
| 76 focus_painter_ = views::Painter::CreateSolidFocusPainter( | 78 focus_painter_ = views::Painter::CreateSolidFocusPainter( |
| 77 kFocusBorderColor, gfx::Insets(0, 1, 3, 2)); | 79 kFocusBorderColor, gfx::Insets(0, 1, 3, 2)); |
| 78 | 80 |
| 79 UpdateWithNotification(notification); | 81 UpdateWithNotification(notification); |
| 80 } | 82 } |
| 81 | 83 |
| 82 MessageView::~MessageView() { | 84 MessageView::~MessageView() { |
| 83 } | 85 } |
| 84 | 86 |
| 85 void MessageView::UpdateWithNotification(const Notification& notification) { | 87 void MessageView::UpdateWithNotification(const Notification& notification) { |
| 86 display_source_ = notification.display_source(); | 88 display_source_ = notification.display_source(); |
| 87 accessible_name_ = CreateAccessibleName(notification); | 89 accessible_name_ = CreateAccessibleName(notification); |
| 88 set_slide_out_enabled(!notification.pinned()); | 90 slide_out_controller_.set_enabled(!notification.pinned()); |
| 89 } | 91 } |
| 90 | 92 |
| 91 // static | 93 // static |
| 92 gfx::Insets MessageView::GetShadowInsets() { | 94 gfx::Insets MessageView::GetShadowInsets() { |
| 93 return -gfx::ShadowValue::GetMargin( | 95 return -gfx::ShadowValue::GetMargin( |
| 94 gfx::ShadowDetails::Get(kShadowElevation, kShadowCornerRadius).values); | 96 gfx::ShadowDetails::Get(kShadowElevation, kShadowCornerRadius).values); |
| 95 } | 97 } |
| 96 | 98 |
| 97 void MessageView::CreateShadowBorder() { | 99 void MessageView::SetIsNested() { |
| 100 is_nested_ = true; |
| 101 SetPaintToLayer(); |
| 102 layer()->SetFillsBoundsOpaquely(false); |
| 103 |
| 98 const auto& shadow = | 104 const auto& shadow = |
| 99 gfx::ShadowDetails::Get(kShadowElevation, kShadowCornerRadius); | 105 gfx::ShadowDetails::Get(kShadowElevation, kShadowCornerRadius); |
| 100 gfx::Insets ninebox_insets = gfx::ShadowValue::GetBlurRegion(shadow.values) + | 106 gfx::Insets ninebox_insets = gfx::ShadowValue::GetBlurRegion(shadow.values) + |
| 101 gfx::Insets(kShadowCornerRadius); | 107 gfx::Insets(kShadowCornerRadius); |
| 102 SetBorder(views::CreateBorderPainter( | 108 SetBorder(views::CreateBorderPainter( |
| 103 std::unique_ptr<views::Painter>(views::Painter::CreateImagePainter( | 109 std::unique_ptr<views::Painter>(views::Painter::CreateImagePainter( |
| 104 shadow.ninebox_image, ninebox_insets)), | 110 shadow.ninebox_image, ninebox_insets)), |
| 105 -gfx::ShadowValue::GetMargin(shadow.values))); | 111 -gfx::ShadowValue::GetMargin(shadow.values))); |
| 106 } | 112 } |
| 107 | 113 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 138 // Space key handling is triggerred at key-release timing. See | 144 // Space key handling is triggerred at key-release timing. See |
| 139 // ui/views/controls/buttons/custom_button.cc for why. | 145 // ui/views/controls/buttons/custom_button.cc for why. |
| 140 if (event.flags() != ui::EF_NONE || event.key_code() != ui::VKEY_SPACE) | 146 if (event.flags() != ui::EF_NONE || event.key_code() != ui::VKEY_SPACE) |
| 141 return false; | 147 return false; |
| 142 | 148 |
| 143 controller_->ClickOnNotification(notification_id_); | 149 controller_->ClickOnNotification(notification_id_); |
| 144 return true; | 150 return true; |
| 145 } | 151 } |
| 146 | 152 |
| 147 void MessageView::OnPaint(gfx::Canvas* canvas) { | 153 void MessageView::OnPaint(gfx::Canvas* canvas) { |
| 148 SlideOutView::OnPaint(canvas); | |
| 149 views::Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); | 154 views::Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); |
| 150 } | 155 } |
| 151 | 156 |
| 152 void MessageView::OnFocus() { | 157 void MessageView::OnFocus() { |
| 153 SlideOutView::OnFocus(); | |
| 154 // We paint a focus indicator. | 158 // We paint a focus indicator. |
| 155 SchedulePaint(); | 159 SchedulePaint(); |
| 156 } | 160 } |
| 157 | 161 |
| 158 void MessageView::OnBlur() { | 162 void MessageView::OnBlur() { |
| 159 SlideOutView::OnBlur(); | |
| 160 // We paint a focus indicator. | 163 // We paint a focus indicator. |
| 161 SchedulePaint(); | 164 SchedulePaint(); |
| 162 } | 165 } |
| 163 | 166 |
| 164 void MessageView::Layout() { | 167 void MessageView::Layout() { |
| 165 gfx::Rect content_bounds = GetContentsBounds(); | 168 gfx::Rect content_bounds = GetContentsBounds(); |
| 166 | 169 |
| 167 // Background. | 170 // Background. |
| 168 background_view_->SetBoundsRect(content_bounds); | 171 background_view_->SetBoundsRect(content_bounds); |
| 169 #if defined(OS_CHROMEOS) | 172 #if defined(OS_CHROMEOS) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 192 SetDrawBackgroundAsActive(false); | 195 SetDrawBackgroundAsActive(false); |
| 193 controller_->ClickOnNotification(notification_id_); | 196 controller_->ClickOnNotification(notification_id_); |
| 194 event->SetHandled(); | 197 event->SetHandled(); |
| 195 return; | 198 return; |
| 196 } | 199 } |
| 197 default: { | 200 default: { |
| 198 // Do nothing | 201 // Do nothing |
| 199 } | 202 } |
| 200 } | 203 } |
| 201 | 204 |
| 202 SlideOutView::OnGestureEvent(event); | |
| 203 // Do not return here by checking handled(). SlideOutView calls SetHandled() | |
| 204 // even though the scroll gesture doesn't make no (or little) effects on the | |
| 205 // slide-out behavior. See http://crbug.com/172991 | |
| 206 | |
| 207 if (!event->IsScrollGestureEvent() && !event->IsFlingScrollEvent()) | 205 if (!event->IsScrollGestureEvent() && !event->IsFlingScrollEvent()) |
| 208 return; | 206 return; |
| 209 | 207 |
| 210 if (scroller_) | 208 if (scroller_) |
| 211 scroller_->OnGestureEvent(event); | 209 scroller_->OnGestureEvent(event); |
| 212 event->SetHandled(); | 210 event->SetHandled(); |
| 213 } | 211 } |
| 214 | 212 |
| 213 ui::Layer* MessageView::GetSlideOutLayer() { |
| 214 return is_nested_ ? layer() : GetWidget()->GetLayer(); |
| 215 } |
| 216 |
| 217 void MessageView::OnSlideOut() { |
| 218 controller_->RemoveNotification(notification_id_, true); // By user. |
| 219 } |
| 220 |
| 215 void MessageView::OnCloseButtonPressed() { | 221 void MessageView::OnCloseButtonPressed() { |
| 216 controller_->RemoveNotification(notification_id_, true); // By user. | 222 controller_->RemoveNotification(notification_id_, true); // By user. |
| 217 } | 223 } |
| 218 | 224 |
| 219 void MessageView::OnSlideOut() { | |
| 220 controller_->RemoveNotification(notification_id_, true); // By user. | |
| 221 } | |
| 222 | |
| 223 void MessageView::SetDrawBackgroundAsActive(bool active) { | 225 void MessageView::SetDrawBackgroundAsActive(bool active) { |
| 224 background_view_->background()-> | 226 background_view_->background()-> |
| 225 SetNativeControlColor(active ? kHoveredButtonBackgroundColor : | 227 SetNativeControlColor(active ? kHoveredButtonBackgroundColor : |
| 226 kNotificationBackgroundColor); | 228 kNotificationBackgroundColor); |
| 227 SchedulePaint(); | 229 SchedulePaint(); |
| 228 } | 230 } |
| 229 | 231 |
| 230 } // namespace message_center | 232 } // namespace message_center |
| OLD | NEW |