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 "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/maximize_mode/maximize_mode_controller.h" | |
19 #include "ash/wm/window_animations.h" | 20 #include "ash/wm/window_animations.h" |
21 #include "base/command_line.h" | |
20 #include "grit/ash_resources.h" | 22 #include "grit/ash_resources.h" |
21 #include "ui/accessibility/ax_view_state.h" | 23 #include "ui/accessibility/ax_view_state.h" |
22 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
23 #include "ui/aura/window_event_dispatcher.h" | 25 #include "ui/aura/window_event_dispatcher.h" |
24 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
25 #include "ui/compositor/layer.h" | 27 #include "ui/compositor/layer.h" |
26 #include "ui/compositor/layer_animation_element.h" | 28 #include "ui/compositor/layer_animation_element.h" |
27 #include "ui/compositor/scoped_layer_animation_settings.h" | 29 #include "ui/compositor/scoped_layer_animation_settings.h" |
30 #include "ui/events/event_constants.h" | |
28 #include "ui/gfx/animation/tween.h" | 31 #include "ui/gfx/animation/tween.h" |
29 #include "ui/gfx/canvas.h" | 32 #include "ui/gfx/canvas.h" |
30 #include "ui/gfx/image/image_skia.h" | 33 #include "ui/gfx/image/image_skia.h" |
31 #include "ui/gfx/image/image_skia_operations.h" | 34 #include "ui/gfx/image/image_skia_operations.h" |
32 #include "ui/gfx/rect.h" | 35 #include "ui/gfx/rect.h" |
33 #include "ui/gfx/screen.h" | 36 #include "ui/gfx/screen.h" |
34 #include "ui/gfx/skia_util.h" | 37 #include "ui/gfx/skia_util.h" |
35 #include "ui/gfx/transform.h" | 38 #include "ui/gfx/transform.h" |
36 #include "ui/views/background.h" | 39 #include "ui/views/background.h" |
37 #include "ui/views/layout/box_layout.h" | 40 #include "ui/views/layout/box_layout.h" |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 tray_container_(NULL), | 304 tray_container_(NULL), |
302 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), | 305 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), |
303 background_(NULL), | 306 background_(NULL), |
304 hide_background_animator_(this, 0, kTrayBackgroundAlpha), | 307 hide_background_animator_(this, 0, kTrayBackgroundAlpha), |
305 hover_background_animator_( | 308 hover_background_animator_( |
306 this, | 309 this, |
307 0, | 310 0, |
308 kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha), | 311 kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha), |
309 hovered_(false), | 312 hovered_(false), |
310 draw_background_as_active_(false), | 313 draw_background_as_active_(false), |
314 touch_feedback_enabled_(false), | |
311 widget_observer_(new TrayWidgetObserver(this)) { | 315 widget_observer_(new TrayWidgetObserver(this)) { |
312 set_notify_enter_exit_on_child(true); | 316 set_notify_enter_exit_on_child(true); |
313 | 317 |
314 // Initially we want to paint the background, but without the hover effect. | 318 // Initially we want to paint the background, but without the hover effect. |
315 hide_background_animator_.SetPaintsBackground( | 319 hide_background_animator_.SetPaintsBackground( |
316 true, BACKGROUND_CHANGE_IMMEDIATE); | 320 true, BACKGROUND_CHANGE_IMMEDIATE); |
317 hover_background_animator_.SetPaintsBackground( | 321 hover_background_animator_.SetPaintsBackground( |
318 false, BACKGROUND_CHANGE_IMMEDIATE); | 322 false, BACKGROUND_CHANGE_IMMEDIATE); |
319 | 323 |
320 tray_container_ = new TrayContainer(shelf_alignment_); | 324 tray_container_ = new TrayContainer(shelf_alignment_); |
321 SetContents(tray_container_); | 325 SetContents(tray_container_); |
322 tray_event_filter_.reset(new TrayEventFilter); | 326 tray_event_filter_.reset(new TrayEventFilter); |
323 | 327 |
324 SetPaintToLayer(true); | 328 SetPaintToLayer(true); |
325 SetFillsBoundsOpaquely(false); | 329 SetFillsBoundsOpaquely(false); |
326 // Start the tray items not visible, because visibility changes are animated. | 330 // Start the tray items not visible, because visibility changes are animated. |
327 views::View::SetVisible(false); | 331 views::View::SetVisible(false); |
332 | |
333 Shell* shell = Shell::GetInstance(); | |
334 shell->AddShellObserver(this); | |
335 if (shell->maximize_mode_controller()->IsMaximizeModeWindowManagerEnabled() && | |
336 CommandLine::ForCurrentProcess()-> | |
337 HasSwitch(switches::kAshEnableTouchViewTouchFeedback)) { | |
338 touch_feedback_enabled_ = true; | |
339 } | |
328 } | 340 } |
329 | 341 |
330 TrayBackgroundView::~TrayBackgroundView() { | 342 TrayBackgroundView::~TrayBackgroundView() { |
331 if (GetWidget()) | 343 if (GetWidget()) |
332 GetWidget()->RemoveObserver(widget_observer_.get()); | 344 GetWidget()->RemoveObserver(widget_observer_.get()); |
345 Shell::GetInstance()->RemoveShellObserver(this); | |
333 } | 346 } |
334 | 347 |
335 void TrayBackgroundView::Initialize() { | 348 void TrayBackgroundView::Initialize() { |
336 GetWidget()->AddObserver(widget_observer_.get()); | 349 GetWidget()->AddObserver(widget_observer_.get()); |
337 SetTrayBorder(); | 350 SetTrayBorder(); |
338 } | 351 } |
339 | 352 |
340 void TrayBackgroundView::SetVisible(bool visible) { | 353 void TrayBackgroundView::SetVisible(bool visible) { |
341 if (visible == layer()->GetTargetVisibility()) | 354 if (visible == layer()->GetTargetVisibility()) |
342 return; | 355 return; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 return false; | 432 return false; |
420 } | 433 } |
421 | 434 |
422 gfx::Rect TrayBackgroundView::GetFocusBounds() { | 435 gfx::Rect TrayBackgroundView::GetFocusBounds() { |
423 // The tray itself expands to the right and bottom edge of the screen to make | 436 // 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 | 437 // sure clicking on the edges brings up the popup. However, the focus border |
425 // should be only around the container. | 438 // should be only around the container. |
426 return GetContentsBounds(); | 439 return GetContentsBounds(); |
427 } | 440 } |
428 | 441 |
442 void TrayBackgroundView::OnGestureEvent(ui::GestureEvent* event) { | |
443 if (touch_feedback_enabled_) { | |
444 switch (event->type()) { | |
flackr
2014/08/29 15:34:10
For so few cases an if / else if is probably clean
jonross
2014/08/29 17:20:21
Done.
| |
445 case ui::ET_GESTURE_TAP_DOWN: { | |
446 SetDrawBackgroundAsActive(true); | |
447 break; | |
448 } | |
449 case ui::ET_GESTURE_SCROLL_BEGIN: | |
450 case ui::ET_GESTURE_TAP_CANCEL: { | |
flackr
2014/08/29 15:34:10
Do you need ET_GESTURE_TAP as well to restore the
jonross
2014/08/29 17:20:21
Currently when you touch these icons they are only
| |
451 SetDrawBackgroundAsActive(false); | |
452 break; | |
453 } | |
454 default: { | |
455 // No action | |
456 } | |
457 } | |
458 } | |
459 ActionableView::OnGestureEvent(event); | |
460 } | |
461 | |
429 void TrayBackgroundView::UpdateBackground(int alpha) { | 462 void TrayBackgroundView::UpdateBackground(int alpha) { |
430 // The animator should never fire when the alternate shelf layout is used. | 463 // The animator should never fire when the alternate shelf layout is used. |
431 if (!background_ || draw_background_as_active_) | 464 if (!background_ || draw_background_as_active_) |
432 return; | 465 return; |
433 background_->set_alpha(hide_background_animator_.alpha() + | 466 background_->set_alpha(hide_background_animator_.alpha() + |
434 hover_background_animator_.alpha()); | 467 hover_background_animator_.alpha()); |
435 SchedulePaint(); | 468 SchedulePaint(); |
436 } | 469 } |
437 | 470 |
471 void TrayBackgroundView::OnMaximizeModeStarted() { | |
472 touch_feedback_enabled_ = CommandLine::ForCurrentProcess()-> | |
473 HasSwitch(switches::kAshEnableTouchViewTouchFeedback); | |
474 } | |
475 | |
476 void TrayBackgroundView::OnMaximizeModeEnded() { | |
477 touch_feedback_enabled_ = false; | |
478 } | |
479 | |
438 void TrayBackgroundView::SetContents(views::View* contents) { | 480 void TrayBackgroundView::SetContents(views::View* contents) { |
439 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 481 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
440 AddChildView(contents); | 482 AddChildView(contents); |
441 } | 483 } |
442 | 484 |
443 void TrayBackgroundView::SetPaintsBackground( | 485 void TrayBackgroundView::SetPaintsBackground( |
444 bool value, BackgroundAnimatorChangeType change_type) { | 486 bool value, BackgroundAnimatorChangeType change_type) { |
445 hide_background_animator_.SetPaintsBackground(value, change_type); | 487 hide_background_animator_.SetPaintsBackground(value, change_type); |
446 } | 488 } |
447 | 489 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
621 case SHELF_ALIGNMENT_RIGHT: | 663 case SHELF_ALIGNMENT_RIGHT: |
622 return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT; | 664 return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT; |
623 case SHELF_ALIGNMENT_TOP: | 665 case SHELF_ALIGNMENT_TOP: |
624 return TrayBubbleView::ANCHOR_ALIGNMENT_TOP; | 666 return TrayBubbleView::ANCHOR_ALIGNMENT_TOP; |
625 } | 667 } |
626 NOTREACHED(); | 668 NOTREACHED(); |
627 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; | 669 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; |
628 } | 670 } |
629 | 671 |
630 void TrayBackgroundView::SetDrawBackgroundAsActive(bool visible) { | 672 void TrayBackgroundView::SetDrawBackgroundAsActive(bool visible) { |
673 if (draw_background_as_active_ == visible) | |
674 return; | |
631 draw_background_as_active_ = visible; | 675 draw_background_as_active_ = visible; |
632 if (!background_) | 676 if (!background_) |
633 return; | 677 return; |
634 | 678 |
635 // Do not change gradually, changing color between grey and blue is weird. | 679 // Do not change gradually, changing color between grey and blue is weird. |
636 if (draw_background_as_active_) | 680 if (draw_background_as_active_) |
637 background_->set_color(kTrayBackgroundPressedColor); | 681 background_->set_color(kTrayBackgroundPressedColor); |
638 else if (hovered_) | 682 else if (hovered_) |
639 background_->set_alpha(kTrayBackgroundHoverAlpha); | 683 background_->set_alpha(kTrayBackgroundHoverAlpha); |
640 else | 684 else |
641 background_->set_alpha(kTrayBackgroundAlpha); | 685 background_->set_alpha(kTrayBackgroundAlpha); |
642 SchedulePaint(); | 686 SchedulePaint(); |
643 } | 687 } |
644 | 688 |
645 void TrayBackgroundView::UpdateBubbleViewArrow( | 689 void TrayBackgroundView::UpdateBubbleViewArrow( |
646 views::TrayBubbleView* bubble_view) { | 690 views::TrayBubbleView* bubble_view) { |
647 // Nothing to do here. | 691 // Nothing to do here. |
648 } | 692 } |
649 | 693 |
650 } // namespace ash | 694 } // namespace ash |
OLD | NEW |