Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: ui/message_center/views/message_view.cc

Issue 2850153003: Revert of CrOS: Fix appearance of notification toasts when sliding out via gesture (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/message_center/views/message_view.h ('k') | ui/message_center/views/message_view_factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
29 28
30 namespace { 29 namespace {
31 30
32 #if defined(OS_CHROMEOS) 31 #if defined(OS_CHROMEOS)
33 const int kShadowCornerRadius = 2; 32 const int kShadowCornerRadius = 2;
34 #else 33 #else
35 const int kShadowCornerRadius = 0; 34 const int kShadowCornerRadius = 0;
36 #endif 35 #endif
37 const int kShadowElevation = 2; 36 const int kShadowElevation = 2;
38 37
(...skipping 19 matching lines...) Expand all
58 } 57 }
59 58
60 } // namespace 59 } // namespace
61 60
62 namespace message_center { 61 namespace message_center {
63 62
64 MessageView::MessageView(MessageCenterController* controller, 63 MessageView::MessageView(MessageCenterController* controller,
65 const Notification& notification) 64 const Notification& notification)
66 : controller_(controller), 65 : controller_(controller),
67 notification_id_(notification.id()), 66 notification_id_(notification.id()),
68 notifier_id_(notification.notifier_id()), 67 notifier_id_(notification.notifier_id()) {
69 slide_out_controller_(this, this) {
70 SetFocusBehavior(FocusBehavior::ALWAYS); 68 SetFocusBehavior(FocusBehavior::ALWAYS);
71 69
72 // Create the opaque background that's above the view's shadow. 70 // Create the opaque background that's above the view's shadow.
73 background_view_ = new views::View(); 71 background_view_ = new views::View();
74 background_view_->set_background( 72 background_view_->set_background(
75 views::Background::CreateSolidBackground(kNotificationBackgroundColor)); 73 views::Background::CreateSolidBackground(kNotificationBackgroundColor));
76 AddChildView(background_view_); 74 AddChildView(background_view_);
77 75
78 focus_painter_ = views::Painter::CreateSolidFocusPainter( 76 focus_painter_ = views::Painter::CreateSolidFocusPainter(
79 kFocusBorderColor, gfx::Insets(0, 1, 3, 2)); 77 kFocusBorderColor, gfx::Insets(0, 1, 3, 2));
80 78
81 UpdateWithNotification(notification); 79 UpdateWithNotification(notification);
82 } 80 }
83 81
84 MessageView::~MessageView() { 82 MessageView::~MessageView() {
85 } 83 }
86 84
87 void MessageView::UpdateWithNotification(const Notification& notification) { 85 void MessageView::UpdateWithNotification(const Notification& notification) {
88 display_source_ = notification.display_source(); 86 display_source_ = notification.display_source();
89 accessible_name_ = CreateAccessibleName(notification); 87 accessible_name_ = CreateAccessibleName(notification);
90 slide_out_controller_.set_enabled(!notification.pinned()); 88 set_slide_out_enabled(!notification.pinned());
91 } 89 }
92 90
93 // static 91 // static
94 gfx::Insets MessageView::GetShadowInsets() { 92 gfx::Insets MessageView::GetShadowInsets() {
95 return -gfx::ShadowValue::GetMargin( 93 return -gfx::ShadowValue::GetMargin(
96 gfx::ShadowDetails::Get(kShadowElevation, kShadowCornerRadius).values); 94 gfx::ShadowDetails::Get(kShadowElevation, kShadowCornerRadius).values);
97 } 95 }
98 96
99 void MessageView::SetIsNested() { 97 void MessageView::CreateShadowBorder() {
100 is_nested_ = true;
101 SetPaintToLayer();
102 layer()->SetFillsBoundsOpaquely(false);
103
104 const auto& shadow = 98 const auto& shadow =
105 gfx::ShadowDetails::Get(kShadowElevation, kShadowCornerRadius); 99 gfx::ShadowDetails::Get(kShadowElevation, kShadowCornerRadius);
106 gfx::Insets ninebox_insets = gfx::ShadowValue::GetBlurRegion(shadow.values) + 100 gfx::Insets ninebox_insets = gfx::ShadowValue::GetBlurRegion(shadow.values) +
107 gfx::Insets(kShadowCornerRadius); 101 gfx::Insets(kShadowCornerRadius);
108 SetBorder(views::CreateBorderPainter( 102 SetBorder(views::CreateBorderPainter(
109 std::unique_ptr<views::Painter>(views::Painter::CreateImagePainter( 103 std::unique_ptr<views::Painter>(views::Painter::CreateImagePainter(
110 shadow.ninebox_image, ninebox_insets)), 104 shadow.ninebox_image, ninebox_insets)),
111 -gfx::ShadowValue::GetMargin(shadow.values))); 105 -gfx::ShadowValue::GetMargin(shadow.values)));
112 } 106 }
113 107
(...skipping 30 matching lines...) Expand all
144 // Space key handling is triggerred at key-release timing. See 138 // Space key handling is triggerred at key-release timing. See
145 // ui/views/controls/buttons/custom_button.cc for why. 139 // ui/views/controls/buttons/custom_button.cc for why.
146 if (event.flags() != ui::EF_NONE || event.key_code() != ui::VKEY_SPACE) 140 if (event.flags() != ui::EF_NONE || event.key_code() != ui::VKEY_SPACE)
147 return false; 141 return false;
148 142
149 controller_->ClickOnNotification(notification_id_); 143 controller_->ClickOnNotification(notification_id_);
150 return true; 144 return true;
151 } 145 }
152 146
153 void MessageView::OnPaint(gfx::Canvas* canvas) { 147 void MessageView::OnPaint(gfx::Canvas* canvas) {
148 SlideOutView::OnPaint(canvas);
154 views::Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); 149 views::Painter::PaintFocusPainter(this, canvas, focus_painter_.get());
155 } 150 }
156 151
157 void MessageView::OnFocus() { 152 void MessageView::OnFocus() {
153 SlideOutView::OnFocus();
158 // We paint a focus indicator. 154 // We paint a focus indicator.
159 SchedulePaint(); 155 SchedulePaint();
160 } 156 }
161 157
162 void MessageView::OnBlur() { 158 void MessageView::OnBlur() {
159 SlideOutView::OnBlur();
163 // We paint a focus indicator. 160 // We paint a focus indicator.
164 SchedulePaint(); 161 SchedulePaint();
165 } 162 }
166 163
167 void MessageView::Layout() { 164 void MessageView::Layout() {
168 gfx::Rect content_bounds = GetContentsBounds(); 165 gfx::Rect content_bounds = GetContentsBounds();
169 166
170 // Background. 167 // Background.
171 background_view_->SetBoundsRect(content_bounds); 168 background_view_->SetBoundsRect(content_bounds);
172 #if defined(OS_CHROMEOS) 169 #if defined(OS_CHROMEOS)
(...skipping 22 matching lines...) Expand all
195 SetDrawBackgroundAsActive(false); 192 SetDrawBackgroundAsActive(false);
196 controller_->ClickOnNotification(notification_id_); 193 controller_->ClickOnNotification(notification_id_);
197 event->SetHandled(); 194 event->SetHandled();
198 return; 195 return;
199 } 196 }
200 default: { 197 default: {
201 // Do nothing 198 // Do nothing
202 } 199 }
203 } 200 }
204 201
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
205 if (!event->IsScrollGestureEvent() && !event->IsFlingScrollEvent()) 207 if (!event->IsScrollGestureEvent() && !event->IsFlingScrollEvent())
206 return; 208 return;
207 209
208 if (scroller_) 210 if (scroller_)
209 scroller_->OnGestureEvent(event); 211 scroller_->OnGestureEvent(event);
210 event->SetHandled(); 212 event->SetHandled();
211 } 213 }
212 214
213 ui::Layer* MessageView::GetSlideOutLayer() { 215 void MessageView::OnCloseButtonPressed() {
214 return is_nested_ ? layer() : GetWidget()->GetLayer(); 216 controller_->RemoveNotification(notification_id_, true); // By user.
215 } 217 }
216 218
217 void MessageView::OnSlideOut() { 219 void MessageView::OnSlideOut() {
218 controller_->RemoveNotification(notification_id_, true); // By user. 220 controller_->RemoveNotification(notification_id_, true); // By user.
219 } 221 }
220 222
221 void MessageView::OnCloseButtonPressed() {
222 controller_->RemoveNotification(notification_id_, true); // By user.
223 }
224
225 void MessageView::SetDrawBackgroundAsActive(bool active) { 223 void MessageView::SetDrawBackgroundAsActive(bool active) {
226 background_view_->background()-> 224 background_view_->background()->
227 SetNativeControlColor(active ? kHoveredButtonBackgroundColor : 225 SetNativeControlColor(active ? kHoveredButtonBackgroundColor :
228 kNotificationBackgroundColor); 226 kNotificationBackgroundColor);
229 SchedulePaint(); 227 SchedulePaint();
230 } 228 }
231 229
232 } // namespace message_center 230 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/message_view.h ('k') | ui/message_center/views/message_view_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698