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

Side by Side Diff: ui/arc/notification/arc_notification_content_view.cc

Issue 2960333003: Extract the view of control buttons on notification into a separated class (Closed)
Patch Set: addressed comments Created 3 years, 5 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/arc/notification/arc_notification_content_view.h" 5 #include "ui/arc/notification/arc_notification_content_view.h"
6 6
7 #include "ash/wm/window_util.h" 7 #include "ash/wm/window_util.h"
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "components/exo/notification_surface.h" 10 #include "components/exo/notification_surface.h"
11 #include "components/exo/surface.h" 11 #include "components/exo/surface.h"
12 #include "ui/accessibility/ax_action_data.h" 12 #include "ui/accessibility/ax_action_data.h"
13 #include "ui/accessibility/ax_node_data.h" 13 #include "ui/accessibility/ax_node_data.h"
14 #include "ui/arc/notification/arc_notification_surface.h" 14 #include "ui/arc/notification/arc_notification_surface.h"
15 #include "ui/arc/notification/arc_notification_view.h" 15 #include "ui/arc/notification/arc_notification_view.h"
16 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/compositor/layer_animation_observer.h" 17 #include "ui/compositor/layer_animation_observer.h"
19 #include "ui/events/event_handler.h" 18 #include "ui/events/event_handler.h"
20 #include "ui/gfx/animation/linear_animation.h"
21 #include "ui/gfx/animation/tween.h"
22 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
23 #include "ui/gfx/geometry/insets.h" 20 #include "ui/gfx/geometry/insets.h"
24 #include "ui/gfx/transform.h" 21 #include "ui/gfx/transform.h"
25 #include "ui/message_center/message_center_style.h" 22 #include "ui/message_center/message_center_style.h"
23 #include "ui/message_center/views/notification_control_buttons_view.h"
26 #include "ui/message_center/views/toast_contents_view.h" 24 #include "ui/message_center/views/toast_contents_view.h"
27 #include "ui/strings/grit/ui_strings.h" 25 #include "ui/strings/grit/ui_strings.h"
28 #include "ui/views/background.h"
29 #include "ui/views/focus/focus_manager.h" 26 #include "ui/views/focus/focus_manager.h"
30 #include "ui/views/layout/box_layout.h"
31 #include "ui/views/painter.h"
32 #include "ui/views/widget/root_view.h" 27 #include "ui/views/widget/root_view.h"
33 #include "ui/views/widget/widget.h" 28 #include "ui/views/widget/widget.h"
34 #include "ui/wm/core/window_util.h" 29 #include "ui/wm/core/window_util.h"
35 30
36 namespace arc { 31 namespace arc {
37 32
38 namespace { 33 namespace {
39 34
40 // This value should be the same as the duration of reveal animation of
41 // the settings view of an Android notification.
42 constexpr int kBackgroundColorChangeDuration = 360;
43
44 SkColor GetControlButtonBackgroundColor( 35 SkColor GetControlButtonBackgroundColor(
45 const mojom::ArcNotificationShownContents& shown_contents) { 36 const mojom::ArcNotificationShownContents& shown_contents) {
46 if (shown_contents == mojom::ArcNotificationShownContents::CONTENTS_SHOWN) 37 if (shown_contents == mojom::ArcNotificationShownContents::CONTENTS_SHOWN)
47 return message_center::kControlButtonBackgroundColor; 38 return message_center::kControlButtonBackgroundColor;
48 else 39 else
49 return SK_ColorTRANSPARENT; 40 return SK_ColorTRANSPARENT;
50 } 41 }
51 42
52 } // namespace 43 } // namespace
53 44
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 DISALLOW_COPY_AND_ASSIGN(SlideHelper); 175 DISALLOW_COPY_AND_ASSIGN(SlideHelper);
185 }; 176 };
186 177
187 class ArcNotificationContentView::ContentViewDelegate 178 class ArcNotificationContentView::ContentViewDelegate
188 : public ArcNotificationContentViewDelegate { 179 : public ArcNotificationContentViewDelegate {
189 public: 180 public:
190 explicit ContentViewDelegate(ArcNotificationContentView* owner) 181 explicit ContentViewDelegate(ArcNotificationContentView* owner)
191 : owner_(owner) {} 182 : owner_(owner) {}
192 183
193 bool IsCloseButtonFocused() const override { 184 bool IsCloseButtonFocused() const override {
194 if (!owner_->close_button_) 185 if (!owner_->control_buttons_view_)
195 return false; 186 return false;
196 return owner_->close_button_->HasFocus(); 187 return owner_->control_buttons_view_->IsCloseButtonFocused();
197 } 188 }
198 189
199 void RequestFocusOnCloseButton() override { 190 void RequestFocusOnCloseButton() override {
200 if (owner_->close_button_) 191 if (owner_->control_buttons_view_)
201 owner_->close_button_->RequestFocus(); 192 owner_->control_buttons_view_->RequestFocusOnCloseButton();
202 owner_->UpdateControlButtonsVisibility(); 193 owner_->UpdateControlButtonsVisibility();
203 } 194 }
204 195
205 void UpdateControlButtonsVisibility() override { 196 void UpdateControlButtonsVisibility() override {
206 owner_->UpdateControlButtonsVisibility(); 197 owner_->UpdateControlButtonsVisibility();
207 } 198 }
208 199
209 void OnSlideChanged() override { 200 void OnSlideChanged() override {
210 if (owner_->slide_helper_) 201 if (owner_->slide_helper_)
211 owner_->slide_helper_->Update(); 202 owner_->slide_helper_->Update();
212 } 203 }
213 204
214 private: 205 private:
215 ArcNotificationContentView* const owner_; 206 ArcNotificationContentView* const owner_;
216 207
217 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); 208 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate);
218 }; 209 };
219 210
220 ArcNotificationContentView::ControlButton::ControlButton(
221 ArcNotificationContentView* owner)
222 : message_center::PaddedButton(owner), owner_(owner) {
223 if (owner_->item_) {
224 SetBackground(views::CreateSolidBackground(
225 GetControlButtonBackgroundColor(owner_->item_->GetShownContents())));
226 } else {
227 SetBackground(views::CreateSolidBackground(
228 message_center::kControlButtonBackgroundColor));
229 }
230 }
231
232 void ArcNotificationContentView::ControlButton::OnFocus() {
233 message_center::PaddedButton::OnFocus();
234 owner_->UpdateControlButtonsVisibility();
235 }
236
237 void ArcNotificationContentView::ControlButton::OnBlur() {
238 message_center::PaddedButton::OnBlur();
239 owner_->UpdateControlButtonsVisibility();
240 }
241
242 // static, for ArcNotificationContentView::GetClassName(). 211 // static, for ArcNotificationContentView::GetClassName().
243 const char ArcNotificationContentView::kViewClassName[] = 212 const char ArcNotificationContentView::kViewClassName[] =
244 "ArcNotificationContentView"; 213 "ArcNotificationContentView";
245 214
246 ArcNotificationContentView::ArcNotificationContentView( 215 ArcNotificationContentView::ArcNotificationContentView(
247 ArcNotificationItem* item) 216 ArcNotificationItem* item)
248 : item_(item), 217 : item_(item),
249 notification_key_(item->GetNotificationKey()), 218 notification_key_(item->GetNotificationKey()),
250 event_forwarder_(new EventForwarder(this)) { 219 event_forwarder_(new EventForwarder(this)) {
251 SetFocusBehavior(FocusBehavior::ALWAYS); 220 SetFocusBehavior(FocusBehavior::ALWAYS);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 const char* ArcNotificationContentView::GetClassName() const { 253 const char* ArcNotificationContentView::GetClassName() const {
285 return kViewClassName; 254 return kViewClassName;
286 } 255 }
287 256
288 std::unique_ptr<ArcNotificationContentViewDelegate> 257 std::unique_ptr<ArcNotificationContentViewDelegate>
289 ArcNotificationContentView::CreateContentViewDelegate() { 258 ArcNotificationContentView::CreateContentViewDelegate() {
290 return base::MakeUnique<ArcNotificationContentView::ContentViewDelegate>( 259 return base::MakeUnique<ArcNotificationContentView::ContentViewDelegate>(
291 this); 260 this);
292 } 261 }
293 262
294 void ArcNotificationContentView::CreateCloseButton() {
295 DCHECK(control_buttons_view_);
296 DCHECK(item_);
297
298 close_button_ = base::MakeUnique<ControlButton>(this);
299 close_button_->SetImage(views::CustomButton::STATE_NORMAL,
300 message_center::GetCloseIcon());
301 close_button_->SetAccessibleName(l10n_util::GetStringUTF16(
302 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME));
303 close_button_->SetTooltipText(l10n_util::GetStringUTF16(
304 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP));
305 close_button_->set_owned_by_client();
306 control_buttons_view_->AddChildView(close_button_.get());
307 }
308
309 void ArcNotificationContentView::CreateSettingsButton() {
310 DCHECK(control_buttons_view_);
311 DCHECK(item_);
312
313 settings_button_ = new ControlButton(this);
314 settings_button_->SetImage(views::CustomButton::STATE_NORMAL,
315 message_center::GetSettingsIcon());
316 settings_button_->SetAccessibleName(l10n_util::GetStringUTF16(
317 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME));
318 settings_button_->SetTooltipText(l10n_util::GetStringUTF16(
319 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME));
320 control_buttons_view_->AddChildView(settings_button_);
321 }
322
323 void ArcNotificationContentView::MaybeCreateFloatingControlButtons() { 263 void ArcNotificationContentView::MaybeCreateFloatingControlButtons() {
324 // Floating close button is a transient child of |surface_| and also part 264 // Floating close button is a transient child of |surface_| and also part
325 // of the hosting widget's focus chain. It could only be created when both 265 // of the hosting widget's focus chain. It could only be created when both
326 // are present. Further, if we are being destroyed (|item_| is null), don't 266 // are present. Further, if we are being destroyed (|item_| is null), don't
327 // create the control buttons. 267 // create the control buttons.
328 if (!surface_ || !GetWidget() || !item_) 268 if (!surface_ || !GetWidget() || !item_)
329 return; 269 return;
330 270
271 DCHECK(!control_buttons_view_);
272 DCHECK(!floating_control_buttons_widget_);
273
274 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName());
275 auto* notification_view = static_cast<ArcNotificationView*>(parent());
276
331 // Creates the control_buttons_view_, which collects all control buttons into 277 // Creates the control_buttons_view_, which collects all control buttons into
332 // a horizontal box. 278 // a horizontal box.
333 control_buttons_view_ = new views::View(); 279 control_buttons_view_ =
334 control_buttons_view_->SetLayoutManager( 280 new message_center::NotificationControlButtonsView(notification_view);
335 new views::BoxLayout(views::BoxLayout::kHorizontal)); 281 control_buttons_view_->SetPaintToLayer(ui::LAYER_TEXTURED);
282 control_buttons_view_->layer()->SetFillsBoundsOpaquely(false);
336 283
337 if (item_->IsOpeningSettingsSupported()) 284 control_buttons_view_->SetBackgroundColor(
338 CreateSettingsButton(); 285 GetControlButtonBackgroundColor(item_->GetShownContents()));
339 if (!item_->GetPinned()) 286 control_buttons_view_->ShowSettingsButton(
340 CreateCloseButton(); 287 item_->IsOpeningSettingsSupported());
288 control_buttons_view_->ShowCloseButton(!item_->GetPinned());
341 289
342 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); 290 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
343 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 291 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
344 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 292 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
345 params.parent = surface_->GetWindow(); 293 params.parent = surface_->GetWindow();
346 294
347 floating_control_buttons_widget_.reset(new views::Widget); 295 floating_control_buttons_widget_.reset(new views::Widget);
348 floating_control_buttons_widget_->Init(params); 296 floating_control_buttons_widget_->Init(params);
349 floating_control_buttons_widget_->SetContentsView(control_buttons_view_); 297 floating_control_buttons_widget_->SetContentsView(control_buttons_view_);
350 298
351 // Put the close button into the focus chain. 299 // Put the close button into the focus chain.
352 floating_control_buttons_widget_->SetFocusTraversableParent( 300 floating_control_buttons_widget_->SetFocusTraversableParent(
353 GetWidget()->GetFocusTraversable()); 301 GetWidget()->GetFocusTraversable());
354 floating_control_buttons_widget_->SetFocusTraversableParentView(this); 302 floating_control_buttons_widget_->SetFocusTraversableParentView(this);
355 303
356 Layout(); 304 Layout();
357 } 305 }
358 306
359 void ArcNotificationContentView::SetSurface(ArcNotificationSurface* surface) { 307 void ArcNotificationContentView::SetSurface(ArcNotificationSurface* surface) {
360 if (surface_ == surface) 308 if (surface_ == surface)
361 return; 309 return;
362 310
363 // Reset |floating_control_buttons_widget_| when |surface_| is changed. 311 // Reset |floating_control_buttons_widget_| when |surface_| is changed.
364 floating_control_buttons_widget_.reset(); 312 floating_control_buttons_widget_.reset();
365 control_buttons_view_ = nullptr; 313 control_buttons_view_ = nullptr;
366 settings_button_ = nullptr;
367 close_button_.reset();
368 314
369 if (surface_ && surface_->GetWindow()) { 315 if (surface_ && surface_->GetWindow()) {
370 surface_->GetWindow()->RemoveObserver(this); 316 surface_->GetWindow()->RemoveObserver(this);
371 surface_->GetWindow()->RemovePreTargetHandler(event_forwarder_.get()); 317 surface_->GetWindow()->RemovePreTargetHandler(event_forwarder_.get());
372 318
373 if (GetWidget() && surface_->IsAttached()) 319 if (GetWidget() && surface_->IsAttached())
374 surface_->Detach(); 320 surface_->Detach();
375 } 321 }
376 322
377 surface_ = surface; 323 surface_ = surface;
(...skipping 21 matching lines...) Expand all
399 const float scale = static_cast<float>(message_center::kNotificationWidth) / 345 const float scale = static_cast<float>(message_center::kNotificationWidth) /
400 preferred_size.width(); 346 preferred_size.width();
401 preferred_size.SetSize(message_center::kNotificationWidth, 347 preferred_size.SetSize(message_center::kNotificationWidth,
402 preferred_size.height() * scale); 348 preferred_size.height() * scale);
403 } 349 }
404 350
405 SetPreferredSize(preferred_size); 351 SetPreferredSize(preferred_size);
406 } 352 }
407 353
408 void ArcNotificationContentView::UpdateControlButtonsVisibility() { 354 void ArcNotificationContentView::UpdateControlButtonsVisibility() {
409 if (!floating_control_buttons_widget_) 355 if (!control_buttons_view_)
410 return; 356 return;
411 357
358 DCHECK(floating_control_buttons_widget_);
359
412 const bool target_visiblity = 360 const bool target_visiblity =
413 IsMouseHovered() || (close_button_ && close_button_->HasFocus()) || 361 IsMouseHovered() || (control_buttons_view_->IsCloseButtonFocused()) ||
414 (settings_button_ && settings_button_->HasFocus()); 362 (control_buttons_view_->IsSettingsButtonFocused());
363
415 if (target_visiblity == floating_control_buttons_widget_->IsVisible()) 364 if (target_visiblity == floating_control_buttons_widget_->IsVisible())
416 return; 365 return;
417 366
418 if (target_visiblity) 367 if (target_visiblity)
419 floating_control_buttons_widget_->Show(); 368 floating_control_buttons_widget_->Show();
420 else 369 else
421 floating_control_buttons_widget_->Hide(); 370 floating_control_buttons_widget_->Hide();
422 } 371 }
423 372
424 void ArcNotificationContentView::UpdatePinnedState() { 373 void ArcNotificationContentView::UpdatePinnedState() {
425 if (!item_) 374 if (!item_)
426 return; 375 return;
427 376
428 // Surface is not attached yet. 377 // Surface is not attached yet.
429 if (!control_buttons_view_) 378 if (!control_buttons_view_)
430 return; 379 return;
431 380
432 if (item_->GetPinned() && close_button_) { 381 control_buttons_view_->ShowCloseButton(!item_->GetPinned());
433 control_buttons_view_->RemoveChildView(close_button_.get()); 382 Layout();
434 close_button_.reset();
435 Layout();
436 } else if (!item_->GetPinned() && !close_button_) {
437 CreateCloseButton();
438 Layout();
439 }
440 } 383 }
441 384
442 void ArcNotificationContentView::UpdateSnapshot() { 385 void ArcNotificationContentView::UpdateSnapshot() {
443 // Bail if we have a |surface_| because it controls the sizes and paints UI. 386 // Bail if we have a |surface_| because it controls the sizes and paints UI.
444 if (surface_) 387 if (surface_)
445 return; 388 return;
446 389
447 UpdatePreferredSize(); 390 UpdatePreferredSize();
448 SchedulePaint(); 391 SchedulePaint();
449 } 392 }
(...skipping 15 matching lines...) Expand all
465 // Creates slide helper after this view is added to its parent. 408 // Creates slide helper after this view is added to its parent.
466 slide_helper_.reset(new SlideHelper(this)); 409 slide_helper_.reset(new SlideHelper(this));
467 410
468 // Invokes Update() in case surface is attached during a slide. 411 // Invokes Update() in case surface is attached during a slide.
469 slide_helper_->Update(); 412 slide_helper_->Update();
470 413
471 // (Re-)create the floating buttons after |surface_| is attached to a widget. 414 // (Re-)create the floating buttons after |surface_| is attached to a widget.
472 MaybeCreateFloatingControlButtons(); 415 MaybeCreateFloatingControlButtons();
473 } 416 }
474 417
475 void ArcNotificationContentView::StartControlButtonsColorAnimation() {
476 if (control_button_color_animation_)
477 control_button_color_animation_->End();
478 control_button_color_animation_.reset(new gfx::LinearAnimation(this));
479 control_button_color_animation_->SetDuration(kBackgroundColorChangeDuration);
480 control_button_color_animation_->Start();
481 }
482
483 bool ArcNotificationContentView::ShouldUpdateControlButtonsColor() const {
484 // Don't update the control button color when we are about to be destroyed.
485 if (!item_)
486 return false;
487
488 if (settings_button_ &&
489 settings_button_->background()->get_color() !=
490 GetControlButtonBackgroundColor(item_->GetShownContents()))
491 return true;
492 if (close_button_ &&
493 close_button_->background()->get_color() !=
494 GetControlButtonBackgroundColor(item_->GetShownContents()))
495 return true;
496 return false;
497 }
498
499 void ArcNotificationContentView::UpdateAccessibleName() { 418 void ArcNotificationContentView::UpdateAccessibleName() {
500 // Don't update the accessible name when we are about to be destroyed. 419 // Don't update the accessible name when we are about to be destroyed.
501 if (!item_) 420 if (!item_)
502 return; 421 return;
503 422
504 accessible_name_ = item_->GetAccessibleName(); 423 accessible_name_ = item_->GetAccessibleName();
505 } 424 }
506 425
507 void ArcNotificationContentView::ViewHierarchyChanged( 426 void ArcNotificationContentView::ViewHierarchyChanged(
508 const views::View::ViewHierarchyChangedDetails& details) { 427 const views::View::ViewHierarchyChangedDetails& details) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 if (!surface_size.IsEmpty() && !contents_size.IsEmpty()) { 467 if (!surface_size.IsEmpty() && !contents_size.IsEmpty()) {
549 transform.Scale( 468 transform.Scale(
550 static_cast<float>(contents_size.width()) / surface_size.width(), 469 static_cast<float>(contents_size.width()) / surface_size.width(),
551 static_cast<float>(contents_size.height()) / surface_size.height()); 470 static_cast<float>(contents_size.height()) / surface_size.height());
552 } 471 }
553 472
554 // Apply the transform to the surface content so that close button can 473 // Apply the transform to the surface content so that close button can
555 // be positioned without the need to consider the transform. 474 // be positioned without the need to consider the transform.
556 surface_->GetContentWindow()->SetTransform(transform); 475 surface_->GetContentWindow()->SetTransform(transform);
557 476
558 if (!floating_control_buttons_widget_) 477 if (control_buttons_view_) {
559 return; 478 DCHECK(floating_control_buttons_widget_);
479 gfx::Rect control_buttons_bounds(contents_bounds);
480 int buttons_width = control_buttons_view_->GetPreferredSize().width();
481 int buttons_height = control_buttons_view_->GetPreferredSize().height();
560 482
561 gfx::Rect control_buttons_bounds(contents_bounds); 483 control_buttons_bounds.set_x(control_buttons_bounds.right() -
562 int buttons_width = 0; 484 buttons_width -
563 int buttons_height = 0; 485 message_center::kControlButtonPadding);
564 if (close_button_) { 486 control_buttons_bounds.set_y(control_buttons_bounds.y() +
565 buttons_width += close_button_->GetPreferredSize().width(); 487 message_center::kControlButtonPadding);
566 buttons_height = close_button_->GetPreferredSize().height(); 488 control_buttons_bounds.set_width(buttons_width);
489 control_buttons_bounds.set_height(buttons_height);
490 floating_control_buttons_widget_->SetBounds(control_buttons_bounds);
567 } 491 }
568 if (settings_button_) {
569 buttons_width += settings_button_->GetPreferredSize().width();
570 buttons_height = settings_button_->GetPreferredSize().height();
571 }
572 control_buttons_bounds.set_x(control_buttons_bounds.right() - buttons_width -
573 message_center::kControlButtonPadding);
574 control_buttons_bounds.set_y(control_buttons_bounds.y() +
575 message_center::kControlButtonPadding);
576 control_buttons_bounds.set_width(buttons_width);
577 control_buttons_bounds.set_height(buttons_height);
578 floating_control_buttons_widget_->SetBounds(control_buttons_bounds);
579 492
580 UpdateControlButtonsVisibility(); 493 UpdateControlButtonsVisibility();
581 494
582 ash::wm::SnapWindowToPixelBoundary(surface_->GetWindow()); 495 ash::wm::SnapWindowToPixelBoundary(surface_->GetWindow());
583 } 496 }
584 497
585 void ArcNotificationContentView::OnPaint(gfx::Canvas* canvas) { 498 void ArcNotificationContentView::OnPaint(gfx::Canvas* canvas) {
586 views::NativeViewHost::OnPaint(canvas); 499 views::NativeViewHost::OnPaint(canvas);
587 500
588 // Bail if there is a |surface_| or no item or no snapshot image. 501 // Bail if there is a |surface_| or no item or no snapshot image.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 void ArcNotificationContentView::GetAccessibleNodeData( 562 void ArcNotificationContentView::GetAccessibleNodeData(
650 ui::AXNodeData* node_data) { 563 ui::AXNodeData* node_data) {
651 node_data->role = ui::AX_ROLE_BUTTON; 564 node_data->role = ui::AX_ROLE_BUTTON;
652 node_data->AddStringAttribute( 565 node_data->AddStringAttribute(
653 ui::AX_ATTR_ROLE_DESCRIPTION, 566 ui::AX_ATTR_ROLE_DESCRIPTION,
654 l10n_util::GetStringUTF8( 567 l10n_util::GetStringUTF8(
655 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); 568 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME));
656 node_data->SetName(accessible_name_); 569 node_data->SetName(accessible_name_);
657 } 570 }
658 571
659 void ArcNotificationContentView::ButtonPressed(views::Button* sender,
660 const ui::Event& event) {
661 if (item_ && !item_->GetPinned() && sender == close_button_.get()) {
662 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName());
663 static_cast<ArcNotificationView*>(parent())->OnCloseButtonPressed();
664 }
665 if (item_ && settings_button_ && sender == settings_button_) {
666 item_->OpenSettings();
667 }
668 }
669
670 void ArcNotificationContentView::OnWindowBoundsChanged( 572 void ArcNotificationContentView::OnWindowBoundsChanged(
671 aura::Window* window, 573 aura::Window* window,
672 const gfx::Rect& old_bounds, 574 const gfx::Rect& old_bounds,
673 const gfx::Rect& new_bounds) { 575 const gfx::Rect& new_bounds) {
674 if (in_layout_) 576 if (in_layout_)
675 return; 577 return;
676 578
677 UpdatePreferredSize(); 579 UpdatePreferredSize();
678 Layout(); 580 Layout();
679 } 581 }
680 582
681 void ArcNotificationContentView::OnWindowDestroying(aura::Window* window) { 583 void ArcNotificationContentView::OnWindowDestroying(aura::Window* window) {
682 SetSurface(nullptr); 584 SetSurface(nullptr);
683 } 585 }
684 586
685 void ArcNotificationContentView::OnItemDestroying() { 587 void ArcNotificationContentView::OnItemDestroying() {
686 item_->RemoveObserver(this); 588 item_->RemoveObserver(this);
687 item_ = nullptr; 589 item_ = nullptr;
688 590
689 // Reset |surface_| with |item_| since no one is observing the |surface_| 591 // Reset |surface_| with |item_| since no one is observing the |surface_|
690 // after |item_| is gone and this view should be removed soon. 592 // after |item_| is gone and this view should be removed soon.
691 SetSurface(nullptr); 593 SetSurface(nullptr);
692 } 594 }
693 595
694 void ArcNotificationContentView::OnItemUpdated() { 596 void ArcNotificationContentView::OnItemUpdated() {
695 UpdateAccessibleName(); 597 UpdateAccessibleName();
696 UpdatePinnedState(); 598 UpdatePinnedState();
697 UpdateSnapshot(); 599 UpdateSnapshot();
698 if (ShouldUpdateControlButtonsColor()) 600 if (control_buttons_view_) {
699 StartControlButtonsColorAnimation(); 601 DCHECK(floating_control_buttons_widget_);
602 control_buttons_view_->SetBackgroundColor(
603 GetControlButtonBackgroundColor(item_->GetShownContents()));
604 }
700 } 605 }
701 606
702 void ArcNotificationContentView::OnNotificationSurfaceAdded( 607 void ArcNotificationContentView::OnNotificationSurfaceAdded(
703 ArcNotificationSurface* surface) { 608 ArcNotificationSurface* surface) {
704 if (surface->GetNotificationKey() != notification_key_) 609 if (surface->GetNotificationKey() != notification_key_)
705 return; 610 return;
706 611
707 SetSurface(surface); 612 SetSurface(surface);
708 } 613 }
709 614
710 void ArcNotificationContentView::OnNotificationSurfaceRemoved( 615 void ArcNotificationContentView::OnNotificationSurfaceRemoved(
711 ArcNotificationSurface* surface) { 616 ArcNotificationSurface* surface) {
712 if (surface->GetNotificationKey() != notification_key_) 617 if (surface->GetNotificationKey() != notification_key_)
713 return; 618 return;
714 619
715 SetSurface(nullptr); 620 SetSurface(nullptr);
716 } 621 }
717 622
718 void ArcNotificationContentView::AnimationEnded(
719 const gfx::Animation* animation) {
720 DCHECK_EQ(animation, control_button_color_animation_.get());
721 control_button_color_animation_.reset();
722 }
723
724 void ArcNotificationContentView::AnimationProgressed(
725 const gfx::Animation* animation) {
726 DCHECK_EQ(animation, control_button_color_animation_.get());
727
728 if (item_) {
729 const SkColor target =
730 GetControlButtonBackgroundColor(item_->GetShownContents());
731 const SkColor start =
732 target == message_center::kControlButtonBackgroundColor
733 ? SK_ColorTRANSPARENT
734 : message_center::kControlButtonBackgroundColor;
735 const SkColor current_color = gfx::Tween::ColorValueBetween(
736 animation->GetCurrentValue(), start, target);
737 if (settings_button_) {
738 settings_button_->SetBackground(
739 views::CreateSolidBackground(current_color));
740 settings_button_->SchedulePaint();
741 }
742 if (close_button_) {
743 close_button_->SetBackground(views::CreateSolidBackground(current_color));
744 close_button_->SchedulePaint();
745 }
746 }
747 }
748
749 } // namespace arc 623 } // namespace arc
OLDNEW
« no previous file with comments | « ui/arc/notification/arc_notification_content_view.h ('k') | ui/arc/notification/arc_notification_content_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698