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" | |
14 #include "ui/gfx/shadow_util.h" | |
13 #include "ui/gfx/shadow_value.h" | 15 #include "ui/gfx/shadow_value.h" |
14 #include "ui/message_center/message_center.h" | 16 #include "ui/message_center/message_center.h" |
15 #include "ui/message_center/message_center_style.h" | 17 #include "ui/message_center/message_center_style.h" |
16 #include "ui/message_center/views/message_center_controller.h" | 18 #include "ui/message_center/views/message_center_controller.h" |
17 #include "ui/resources/grit/ui_resources.h" | 19 #include "ui/resources/grit/ui_resources.h" |
18 #include "ui/strings/grit/ui_strings.h" | 20 #include "ui/strings/grit/ui_strings.h" |
19 #include "ui/views/background.h" | 21 #include "ui/views/background.h" |
22 #include "ui/views/border.h" | |
20 #include "ui/views/controls/button/image_button.h" | 23 #include "ui/views/controls/button/image_button.h" |
21 #include "ui/views/controls/image_view.h" | 24 #include "ui/views/controls/image_view.h" |
22 #include "ui/views/controls/scroll_view.h" | 25 #include "ui/views/controls/scroll_view.h" |
23 #include "ui/views/focus/focus_manager.h" | 26 #include "ui/views/focus/focus_manager.h" |
24 #include "ui/views/painter.h" | 27 #include "ui/views/painter.h" |
25 #include "ui/views/shadow_border.h" | |
26 | 28 |
27 namespace { | 29 namespace { |
28 | 30 |
29 constexpr int kShadowOffset = 1; | 31 #if defined(OS_CHROMEOS) |
30 constexpr int kShadowBlur = 4; | 32 const int kShadowCornerRadius = 2; |
33 #else | |
34 const int kShadowCornerRadius = 0; | |
35 #endif | |
36 const int kShadowElevation = 2; | |
31 | 37 |
32 // Creates a text for spoken feedback from the data contained in the | 38 // Creates a text for spoken feedback from the data contained in the |
33 // notification. | 39 // notification. |
34 base::string16 CreateAccessibleName( | 40 base::string16 CreateAccessibleName( |
35 const message_center::Notification& notification) { | 41 const message_center::Notification& notification) { |
36 if (!notification.accessible_name().empty()) | 42 if (!notification.accessible_name().empty()) |
37 return notification.accessible_name(); | 43 return notification.accessible_name(); |
38 | 44 |
39 // Fall back to a text constructed from the notification. | 45 // Fall back to a text constructed from the notification. |
40 std::vector<base::string16> accessible_lines = { | 46 std::vector<base::string16> accessible_lines = { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 } | 92 } |
87 | 93 |
88 void MessageView::UpdateWithNotification(const Notification& notification) { | 94 void MessageView::UpdateWithNotification(const Notification& notification) { |
89 small_image_view_->SetImage(notification.small_image().AsImageSkia()); | 95 small_image_view_->SetImage(notification.small_image().AsImageSkia()); |
90 display_source_ = notification.display_source(); | 96 display_source_ = notification.display_source(); |
91 accessible_name_ = CreateAccessibleName(notification); | 97 accessible_name_ = CreateAccessibleName(notification); |
92 } | 98 } |
93 | 99 |
94 // static | 100 // static |
95 gfx::Insets MessageView::GetShadowInsets() { | 101 gfx::Insets MessageView::GetShadowInsets() { |
96 return gfx::Insets(kShadowBlur / 2 - kShadowOffset, | 102 return -gfx::ShadowValue::GetMargin( |
97 kShadowBlur / 2, | 103 gfx::ShadowDetails::Get(kShadowElevation, kShadowCornerRadius).values); |
98 kShadowBlur / 2 + kShadowOffset, | |
99 kShadowBlur / 2); | |
100 } | 104 } |
101 | 105 |
102 void MessageView::CreateShadowBorder() { | 106 void MessageView::CreateShadowBorder() { |
103 SetBorder(std::unique_ptr<views::Border>(new views::ShadowBorder( | 107 const auto& shadow = |
104 gfx::ShadowValue(gfx::Vector2d(0, kShadowOffset), kShadowBlur, | 108 gfx::ShadowDetails::Get(kShadowElevation, kShadowCornerRadius); |
105 message_center::kShadowColor)))); | 109 gfx::Insets ninebox_insets = gfx::ShadowValue::GetBlurRegion(shadow.values) + |
110 gfx::Insets(kShadowCornerRadius); | |
111 SetBorder(views::CreateBorderPainter( | |
112 std::unique_ptr<views::Painter>(views::Painter::CreateImagePainter( | |
Evan Stade
2017/01/05 00:11:41
see crbug.com/678371
| |
113 shadow.ninebox_image, ninebox_insets)), | |
114 -gfx::ShadowValue::GetMargin(shadow.values))); | |
106 } | 115 } |
107 | 116 |
108 void MessageView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 117 void MessageView::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
109 node_data->role = ui::AX_ROLE_BUTTON; | 118 node_data->role = ui::AX_ROLE_BUTTON; |
110 node_data->SetName(accessible_name_); | 119 node_data->SetName(accessible_name_); |
111 } | 120 } |
112 | 121 |
113 bool MessageView::OnMousePressed(const ui::MouseEvent& event) { | 122 bool MessageView::OnMousePressed(const ui::MouseEvent& event) { |
114 if (!event.IsOnlyLeftMouseButton()) | 123 if (!event.IsOnlyLeftMouseButton()) |
115 return false; | 124 return false; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 SlideOutView::OnBlur(); | 169 SlideOutView::OnBlur(); |
161 // We paint a focus indicator. | 170 // We paint a focus indicator. |
162 SchedulePaint(); | 171 SchedulePaint(); |
163 } | 172 } |
164 | 173 |
165 void MessageView::Layout() { | 174 void MessageView::Layout() { |
166 gfx::Rect content_bounds = GetContentsBounds(); | 175 gfx::Rect content_bounds = GetContentsBounds(); |
167 | 176 |
168 // Background. | 177 // Background. |
169 background_view_->SetBoundsRect(content_bounds); | 178 background_view_->SetBoundsRect(content_bounds); |
179 #if defined(OS_CHROMEOS) | |
180 // ChromeOS rounds the corners of the message view. TODO(estade): should we do | |
181 // this for all platforms? | |
182 gfx::Path path; | |
183 constexpr SkScalar kCornerRadius = SkIntToScalar(2); | |
184 path.addRoundRect(gfx::RectToSkRect(background_view_->GetLocalBounds()), | |
185 kCornerRadius, kCornerRadius); | |
186 background_view_->set_clip_path(path); | |
187 #endif | |
170 | 188 |
171 gfx::Size small_image_size(small_image_view_->GetPreferredSize()); | 189 gfx::Size small_image_size(small_image_view_->GetPreferredSize()); |
172 gfx::Rect small_image_rect(small_image_size); | 190 gfx::Rect small_image_rect(small_image_size); |
173 small_image_rect.set_origin(gfx::Point( | 191 small_image_rect.set_origin(gfx::Point( |
174 content_bounds.right() - small_image_size.width() - kSmallImagePadding, | 192 content_bounds.right() - small_image_size.width() - kSmallImagePadding, |
175 content_bounds.bottom() - small_image_size.height() - | 193 content_bounds.bottom() - small_image_size.height() - |
176 kSmallImagePadding)); | 194 kSmallImagePadding)); |
177 small_image_view_->SetBoundsRect(small_image_rect); | 195 small_image_view_->SetBoundsRect(small_image_rect); |
178 } | 196 } |
179 | 197 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 } | 235 } |
218 | 236 |
219 void MessageView::SetDrawBackgroundAsActive(bool active) { | 237 void MessageView::SetDrawBackgroundAsActive(bool active) { |
220 background_view_->background()-> | 238 background_view_->background()-> |
221 SetNativeControlColor(active ? kHoveredButtonBackgroundColor : | 239 SetNativeControlColor(active ? kHoveredButtonBackgroundColor : |
222 kNotificationBackgroundColor); | 240 kNotificationBackgroundColor); |
223 SchedulePaint(); | 241 SchedulePaint(); |
224 } | 242 } |
225 | 243 |
226 } // namespace message_center | 244 } // namespace message_center |
OLD | NEW |