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

Side by Side Diff: ash/system/tray/tray_background_view.cc

Issue 515573002: Use active state on touch start for tray icons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update test histogram Created 6 years, 3 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 (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 "ash/system/tray/tray_background_view.h" 5 #include "ash/system/tray/tray_background_view.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/root_window_controller.h" 8 #include "ash/root_window_controller.h"
9 #include "ash/screen_util.h" 9 #include "ash/screen_util.h"
10 #include "ash/shelf/shelf_layout_manager.h" 10 #include "ash/shelf/shelf_layout_manager.h"
11 #include "ash/shelf/shelf_widget.h" 11 #include "ash/shelf/shelf_widget.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/shell_window_ids.h" 13 #include "ash/shell_window_ids.h"
14 #include "ash/system/status_area_widget.h" 14 #include "ash/system/status_area_widget.h"
15 #include "ash/system/status_area_widget_delegate.h" 15 #include "ash/system/status_area_widget_delegate.h"
16 #include "ash/system/tray/system_tray.h" 16 #include "ash/system/tray/system_tray.h"
17 #include "ash/system/tray/tray_constants.h" 17 #include "ash/system/tray/tray_constants.h"
18 #include "ash/system/tray/tray_event_filter.h" 18 #include "ash/system/tray/tray_event_filter.h"
19 #include "ash/wm/window_animations.h" 19 #include "ash/wm/window_animations.h"
20 #include "base/command_line.h"
20 #include "grit/ash_resources.h" 21 #include "grit/ash_resources.h"
21 #include "ui/accessibility/ax_view_state.h" 22 #include "ui/accessibility/ax_view_state.h"
22 #include "ui/aura/window.h" 23 #include "ui/aura/window.h"
23 #include "ui/aura/window_event_dispatcher.h" 24 #include "ui/aura/window_event_dispatcher.h"
24 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/compositor/layer.h" 26 #include "ui/compositor/layer.h"
26 #include "ui/compositor/layer_animation_element.h" 27 #include "ui/compositor/layer_animation_element.h"
27 #include "ui/compositor/scoped_layer_animation_settings.h" 28 #include "ui/compositor/scoped_layer_animation_settings.h"
29 #include "ui/events/event_constants.h"
28 #include "ui/gfx/animation/tween.h" 30 #include "ui/gfx/animation/tween.h"
29 #include "ui/gfx/canvas.h" 31 #include "ui/gfx/canvas.h"
30 #include "ui/gfx/image/image_skia.h" 32 #include "ui/gfx/image/image_skia.h"
31 #include "ui/gfx/image/image_skia_operations.h" 33 #include "ui/gfx/image/image_skia_operations.h"
32 #include "ui/gfx/rect.h" 34 #include "ui/gfx/rect.h"
33 #include "ui/gfx/screen.h" 35 #include "ui/gfx/screen.h"
34 #include "ui/gfx/skia_util.h" 36 #include "ui/gfx/skia_util.h"
35 #include "ui/gfx/transform.h" 37 #include "ui/gfx/transform.h"
36 #include "ui/views/background.h" 38 #include "ui/views/background.h"
37 #include "ui/views/layout/box_layout.h" 39 #include "ui/views/layout/box_layout.h"
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 tray_container_(NULL), 303 tray_container_(NULL),
302 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), 304 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM),
303 background_(NULL), 305 background_(NULL),
304 hide_background_animator_(this, 0, kTrayBackgroundAlpha), 306 hide_background_animator_(this, 0, kTrayBackgroundAlpha),
305 hover_background_animator_( 307 hover_background_animator_(
306 this, 308 this,
307 0, 309 0,
308 kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha), 310 kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha),
309 hovered_(false), 311 hovered_(false),
310 draw_background_as_active_(false), 312 draw_background_as_active_(false),
313 touch_feedback_enabled_(false),
311 widget_observer_(new TrayWidgetObserver(this)) { 314 widget_observer_(new TrayWidgetObserver(this)) {
312 set_notify_enter_exit_on_child(true); 315 set_notify_enter_exit_on_child(true);
313 316
314 // Initially we want to paint the background, but without the hover effect. 317 // Initially we want to paint the background, but without the hover effect.
315 hide_background_animator_.SetPaintsBackground( 318 hide_background_animator_.SetPaintsBackground(
316 true, BACKGROUND_CHANGE_IMMEDIATE); 319 true, BACKGROUND_CHANGE_IMMEDIATE);
317 hover_background_animator_.SetPaintsBackground( 320 hover_background_animator_.SetPaintsBackground(
318 false, BACKGROUND_CHANGE_IMMEDIATE); 321 false, BACKGROUND_CHANGE_IMMEDIATE);
319 322
320 tray_container_ = new TrayContainer(shelf_alignment_); 323 tray_container_ = new TrayContainer(shelf_alignment_);
321 SetContents(tray_container_); 324 SetContents(tray_container_);
322 tray_event_filter_.reset(new TrayEventFilter); 325 tray_event_filter_.reset(new TrayEventFilter);
323 326
324 SetPaintToLayer(true); 327 SetPaintToLayer(true);
325 SetFillsBoundsOpaquely(false); 328 SetFillsBoundsOpaquely(false);
326 // Start the tray items not visible, because visibility changes are animated. 329 // Start the tray items not visible, because visibility changes are animated.
327 views::View::SetVisible(false); 330 views::View::SetVisible(false);
331
332 if (CommandLine::ForCurrentProcess()->
333 HasSwitch(switches::kAshEnableTouchViewTouchFeedback)) {
334 touch_feedback_enabled_ = true;
335 }
328 } 336 }
329 337
330 TrayBackgroundView::~TrayBackgroundView() { 338 TrayBackgroundView::~TrayBackgroundView() {
331 if (GetWidget()) 339 if (GetWidget())
332 GetWidget()->RemoveObserver(widget_observer_.get()); 340 GetWidget()->RemoveObserver(widget_observer_.get());
333 } 341 }
334 342
335 void TrayBackgroundView::Initialize() { 343 void TrayBackgroundView::Initialize() {
336 GetWidget()->AddObserver(widget_observer_.get()); 344 GetWidget()->AddObserver(widget_observer_.get());
337 SetTrayBorder(); 345 SetTrayBorder();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 return false; 427 return false;
420 } 428 }
421 429
422 gfx::Rect TrayBackgroundView::GetFocusBounds() { 430 gfx::Rect TrayBackgroundView::GetFocusBounds() {
423 // The tray itself expands to the right and bottom edge of the screen to make 431 // The tray itself expands to the right and bottom edge of the screen to make
424 // sure clicking on the edges brings up the popup. However, the focus border 432 // sure clicking on the edges brings up the popup. However, the focus border
425 // should be only around the container. 433 // should be only around the container.
426 return GetContentsBounds(); 434 return GetContentsBounds();
427 } 435 }
428 436
437 void TrayBackgroundView::OnGestureEvent(ui::GestureEvent* event) {
438 if (touch_feedback_enabled_) {
439 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
440 SetDrawBackgroundAsActive(true);
441 } else if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN ||
442 event->type() == ui::ET_GESTURE_TAP_CANCEL) {
443 SetDrawBackgroundAsActive(false);
444 }
445 }
446 ActionableView::OnGestureEvent(event);
447 }
448
429 void TrayBackgroundView::UpdateBackground(int alpha) { 449 void TrayBackgroundView::UpdateBackground(int alpha) {
430 // The animator should never fire when the alternate shelf layout is used. 450 // The animator should never fire when the alternate shelf layout is used.
431 if (!background_ || draw_background_as_active_) 451 if (!background_ || draw_background_as_active_)
432 return; 452 return;
433 background_->set_alpha(hide_background_animator_.alpha() + 453 background_->set_alpha(hide_background_animator_.alpha() +
434 hover_background_animator_.alpha()); 454 hover_background_animator_.alpha());
435 SchedulePaint(); 455 SchedulePaint();
436 } 456 }
437 457
438 void TrayBackgroundView::SetContents(views::View* contents) { 458 void TrayBackgroundView::SetContents(views::View* contents) {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 case SHELF_ALIGNMENT_RIGHT: 641 case SHELF_ALIGNMENT_RIGHT:
622 return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT; 642 return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT;
623 case SHELF_ALIGNMENT_TOP: 643 case SHELF_ALIGNMENT_TOP:
624 return TrayBubbleView::ANCHOR_ALIGNMENT_TOP; 644 return TrayBubbleView::ANCHOR_ALIGNMENT_TOP;
625 } 645 }
626 NOTREACHED(); 646 NOTREACHED();
627 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; 647 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM;
628 } 648 }
629 649
630 void TrayBackgroundView::SetDrawBackgroundAsActive(bool visible) { 650 void TrayBackgroundView::SetDrawBackgroundAsActive(bool visible) {
651 if (draw_background_as_active_ == visible)
652 return;
631 draw_background_as_active_ = visible; 653 draw_background_as_active_ = visible;
632 if (!background_) 654 if (!background_)
633 return; 655 return;
634 656
635 // Do not change gradually, changing color between grey and blue is weird. 657 // Do not change gradually, changing color between grey and blue is weird.
636 if (draw_background_as_active_) 658 if (draw_background_as_active_)
637 background_->set_color(kTrayBackgroundPressedColor); 659 background_->set_color(kTrayBackgroundPressedColor);
638 else if (hovered_) 660 else if (hovered_)
639 background_->set_alpha(kTrayBackgroundHoverAlpha); 661 background_->set_alpha(kTrayBackgroundHoverAlpha);
640 else 662 else
641 background_->set_alpha(kTrayBackgroundAlpha); 663 background_->set_alpha(kTrayBackgroundAlpha);
642 SchedulePaint(); 664 SchedulePaint();
643 } 665 }
644 666
645 void TrayBackgroundView::UpdateBubbleViewArrow( 667 void TrayBackgroundView::UpdateBubbleViewArrow(
646 views::TrayBubbleView* bubble_view) { 668 views::TrayBubbleView* bubble_view) {
647 // Nothing to do here. 669 // Nothing to do here.
648 } 670 }
649 671
650 } // namespace ash 672 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/tray_background_view.h ('k') | ash/system/web_notification/web_notification_tray_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698