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/common/system/tray/tray_background_view.h" |
6 | 6 |
7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
8 #include "ash/common/shelf/shelf_constants.h" | 8 #include "ash/common/shelf/shelf_constants.h" |
9 #include "ash/common/shelf/wm_shelf.h" | 9 #include "ash/common/shelf/wm_shelf.h" |
10 #include "ash/common/shelf/wm_shelf_util.h" | 10 #include "ash/common/shelf/wm_shelf_util.h" |
11 #include "ash/common/shell_window_ids.h" | 11 #include "ash/common/shell_window_ids.h" |
12 #include "ash/common/system/tray/tray_constants.h" | 12 #include "ash/common/system/tray/tray_constants.h" |
13 #include "ash/screen_util.h" | 13 #include "ash/common/system/tray/tray_event_filter.h" |
14 #include "ash/shell.h" | 14 #include "ash/common/wm_lookup.h" |
15 #include "ash/system/status_area_widget.h" | 15 #include "ash/common/wm_shell.h" |
16 #include "ash/system/status_area_widget_delegate.h" | 16 #include "ash/common/wm_window.h" |
17 #include "ash/system/tray/system_tray.h" | 17 #include "ash/system/tray/system_tray.h" |
18 #include "ash/system/tray/tray_event_filter.h" | |
19 #include "ash/wm/window_animations.h" | |
20 #include "base/command_line.h" | |
21 #include "grit/ash_resources.h" | 18 #include "grit/ash_resources.h" |
22 #include "ui/accessibility/ax_view_state.h" | 19 #include "ui/accessibility/ax_view_state.h" |
23 #include "ui/aura/window.h" | |
24 #include "ui/aura/window_event_dispatcher.h" | |
25 #include "ui/base/nine_image_painter_factory.h" | 20 #include "ui/base/nine_image_painter_factory.h" |
26 #include "ui/base/ui_base_switches_util.h" | 21 #include "ui/base/ui_base_switches_util.h" |
27 #include "ui/compositor/layer.h" | 22 #include "ui/compositor/layer.h" |
28 #include "ui/compositor/layer_animation_element.h" | 23 #include "ui/compositor/layer_animation_element.h" |
29 #include "ui/compositor/scoped_layer_animation_settings.h" | 24 #include "ui/compositor/scoped_layer_animation_settings.h" |
30 #include "ui/events/event_constants.h" | 25 #include "ui/events/event_constants.h" |
31 #include "ui/gfx/animation/tween.h" | 26 #include "ui/gfx/animation/tween.h" |
32 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
33 #include "ui/gfx/geometry/rect.h" | 28 #include "ui/gfx/geometry/rect.h" |
34 #include "ui/gfx/image/image_skia.h" | 29 #include "ui/gfx/image/image_skia.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 const static int kImageVertical = 1; | 90 const static int kImageVertical = 1; |
96 const static int kNumOrientations = 2; | 91 const static int kNumOrientations = 2; |
97 | 92 |
98 explicit TrayBackground(TrayBackgroundView* tray_background_view) : | 93 explicit TrayBackground(TrayBackgroundView* tray_background_view) : |
99 tray_background_view_(tray_background_view) { | 94 tray_background_view_(tray_background_view) { |
100 } | 95 } |
101 | 96 |
102 ~TrayBackground() override {} | 97 ~TrayBackground() override {} |
103 | 98 |
104 private: | 99 private: |
105 WmShelf* GetShelf() const { | 100 WmShelf* GetShelf() const { return tray_background_view_->shelf(); } |
106 return tray_background_view_->GetShelf(); | |
107 } | |
108 | 101 |
109 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const { | 102 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const { |
110 SkColor background_color = SK_ColorTRANSPARENT; | 103 SkColor background_color = SK_ColorTRANSPARENT; |
111 if (GetShelf()->GetBackgroundType() == | 104 if (GetShelf()->GetBackgroundType() == |
112 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) { | 105 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) { |
113 background_color = SkColorSetA(kShelfBaseColor, | 106 background_color = SkColorSetA(kShelfBaseColor, |
114 GetShelfConstant(SHELF_BACKGROUND_ALPHA)); | 107 GetShelfConstant(SHELF_BACKGROUND_ALPHA)); |
115 } | 108 } |
116 | 109 |
117 // TODO(bruthig|tdanderson): The background should be changed using a | 110 // TODO(bruthig|tdanderson): The background should be changed using a |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 219 |
227 views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0); | 220 views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0); |
228 layout->SetDefaultFlex(1); | 221 layout->SetDefaultFlex(1); |
229 views::View::SetLayoutManager(layout); | 222 views::View::SetLayoutManager(layout); |
230 PreferredSizeChanged(); | 223 PreferredSizeChanged(); |
231 } | 224 } |
232 | 225 |
233 //////////////////////////////////////////////////////////////////////////////// | 226 //////////////////////////////////////////////////////////////////////////////// |
234 // TrayBackgroundView | 227 // TrayBackgroundView |
235 | 228 |
236 TrayBackgroundView::TrayBackgroundView(StatusAreaWidget* status_area_widget) | 229 TrayBackgroundView::TrayBackgroundView(WmShelf* wm_shelf) |
237 : status_area_widget_(status_area_widget), | 230 : wm_shelf_(wm_shelf), |
238 tray_container_(NULL), | 231 tray_container_(NULL), |
239 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), | 232 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), |
240 background_(NULL), | 233 background_(NULL), |
241 draw_background_as_active_(false), | 234 draw_background_as_active_(false), |
242 widget_observer_(new TrayWidgetObserver(this)) { | 235 widget_observer_(new TrayWidgetObserver(this)) { |
243 DCHECK(status_area_widget->wm_shelf()); | 236 DCHECK(wm_shelf_); |
244 set_notify_enter_exit_on_child(true); | 237 set_notify_enter_exit_on_child(true); |
245 | 238 |
246 tray_container_ = new TrayContainer(shelf_alignment_); | 239 tray_container_ = new TrayContainer(shelf_alignment_); |
247 SetContents(tray_container_); | 240 SetContents(tray_container_); |
248 tray_event_filter_.reset(new TrayEventFilter); | 241 tray_event_filter_.reset(new TrayEventFilter); |
249 | 242 |
250 SetPaintToLayer(true); | 243 SetPaintToLayer(true); |
251 layer()->SetFillsBoundsOpaquely(false); | 244 layer()->SetFillsBoundsOpaquely(false); |
252 // Start the tray items not visible, because visibility changes are animated. | 245 // Start the tray items not visible, because visibility changes are animated. |
253 views::View::SetVisible(false); | 246 views::View::SetVisible(false); |
254 } | 247 } |
255 | 248 |
256 TrayBackgroundView::~TrayBackgroundView() { | 249 TrayBackgroundView::~TrayBackgroundView() { |
257 if (GetWidget()) | 250 if (GetWidget()) |
258 GetWidget()->RemoveObserver(widget_observer_.get()); | 251 GetWidget()->RemoveObserver(widget_observer_.get()); |
259 StopObservingImplicitAnimations(); | 252 StopObservingImplicitAnimations(); |
260 } | 253 } |
261 | 254 |
262 void TrayBackgroundView::Initialize() { | 255 void TrayBackgroundView::Initialize() { |
263 GetWidget()->AddObserver(widget_observer_.get()); | 256 GetWidget()->AddObserver(widget_observer_.get()); |
264 } | 257 } |
265 | 258 |
266 // static | 259 // static |
267 void TrayBackgroundView::InitializeBubbleAnimations( | 260 void TrayBackgroundView::InitializeBubbleAnimations( |
268 views::Widget* bubble_widget) { | 261 views::Widget* bubble_widget) { |
269 aura::Window* window = bubble_widget->GetNativeWindow(); | 262 WmWindow* window = WmLookup::Get()->GetWindowForWidget(bubble_widget); |
270 ::wm::SetWindowVisibilityAnimationType( | 263 window->SetVisibilityAnimationType( |
271 window, ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 264 ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
272 ::wm::SetWindowVisibilityAnimationTransition(window, ::wm::ANIMATE_HIDE); | 265 window->SetVisibilityAnimationTransition(::wm::ANIMATE_HIDE); |
273 ::wm::SetWindowVisibilityAnimationDuration( | 266 window->SetVisibilityAnimationDuration( |
274 window, base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMs)); | 267 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMs)); |
275 } | 268 } |
276 | 269 |
277 void TrayBackgroundView::SetVisible(bool visible) { | 270 void TrayBackgroundView::SetVisible(bool visible) { |
278 if (visible == layer()->GetTargetVisibility()) | 271 if (visible == layer()->GetTargetVisibility()) |
279 return; | 272 return; |
280 | 273 |
281 if (visible) { | 274 if (visible) { |
282 // The alignment of the shelf can change while the TrayBackgroundView is | 275 // The alignment of the shelf can change while the TrayBackgroundView is |
283 // hidden. Reset the offscreen transform so that the animation to becoming | 276 // hidden. Reset the offscreen transform so that the animation to becoming |
284 // visible reflects the current layout. | 277 // visible reflects the current layout. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 | 369 |
377 void TrayBackgroundView::SetContents(views::View* contents) { | 370 void TrayBackgroundView::SetContents(views::View* contents) { |
378 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 371 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
379 AddChildView(contents); | 372 AddChildView(contents); |
380 } | 373 } |
381 void TrayBackgroundView::SetContentsBackground() { | 374 void TrayBackgroundView::SetContentsBackground() { |
382 background_ = new TrayBackground(this); | 375 background_ = new TrayBackground(this); |
383 tray_container_->set_background(background_); | 376 tray_container_->set_background(background_); |
384 } | 377 } |
385 | 378 |
386 WmShelf* TrayBackgroundView::GetShelf() { | |
387 return status_area_widget_->wm_shelf(); | |
388 } | |
389 | |
390 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { | 379 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { |
391 shelf_alignment_ = alignment; | 380 shelf_alignment_ = alignment; |
392 tray_container_->SetAlignment(alignment); | 381 tray_container_->SetAlignment(alignment); |
393 } | 382 } |
394 | 383 |
395 void TrayBackgroundView::OnImplicitAnimationsCompleted() { | 384 void TrayBackgroundView::OnImplicitAnimationsCompleted() { |
396 // If there is another animation in the queue, the reverse animation was | 385 // If there is another animation in the queue, the reverse animation was |
397 // triggered before the completion of animating to invisible. Do not turn off | 386 // triggered before the completion of animating to invisible. Do not turn off |
398 // the visibility so that the next animation may render. The value of | 387 // the visibility so that the next animation may render. The value of |
399 // layer()->GetTargetVisibility() can be incorrect if the hide animation was | 388 // layer()->GetTargetVisibility() can be incorrect if the hide animation was |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 int vertical_alignment = 0; | 445 int vertical_alignment = 0; |
457 int horizontal_alignment = kBubblePaddingVerticalBottom; | 446 int horizontal_alignment = kBubblePaddingVerticalBottom; |
458 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) | 447 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) |
459 rect.Inset(vertical_alignment, 0, 0, horizontal_alignment); | 448 rect.Inset(vertical_alignment, 0, 0, horizontal_alignment); |
460 else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) | 449 else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) |
461 rect.Inset(0, 0, vertical_alignment, horizontal_alignment); | 450 rect.Inset(0, 0, vertical_alignment, horizontal_alignment); |
462 } else { | 451 } else { |
463 DCHECK(false) << "Unhandled anchor type."; | 452 DCHECK(false) << "Unhandled anchor type."; |
464 } | 453 } |
465 } else { | 454 } else { |
466 aura::Window* target_root = anchor_widget ? | 455 WmWindow* target_root = anchor_widget |
467 anchor_widget->GetNativeView()->GetRootWindow() : | 456 ? WmLookup::Get() |
468 Shell::GetPrimaryRootWindow(); | 457 ->GetWindowForWidget(anchor_widget) |
469 rect = target_root->bounds(); | 458 ->GetRootWindow() |
| 459 : WmShell::Get()->GetPrimaryRootWindow(); |
| 460 rect = target_root->GetBounds(); |
470 if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) { | 461 if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) { |
471 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { | 462 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { |
472 rect = gfx::Rect( | 463 rect = gfx::Rect( |
473 base::i18n::IsRTL() ? | 464 base::i18n::IsRTL() ? |
474 kPaddingFromRightEdgeOfScreenBottomAlignment : | 465 kPaddingFromRightEdgeOfScreenBottomAlignment : |
475 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, | 466 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, |
476 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, | 467 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, |
477 0, 0); | 468 0, 0); |
478 rect = ScreenUtil::ConvertRectToScreen(target_root, rect); | 469 rect = target_root->ConvertRectToScreen(rect); |
479 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) { | 470 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) { |
480 rect = gfx::Rect( | 471 rect = gfx::Rect( |
481 kPaddingFromRightEdgeOfScreenBottomAlignment, | 472 kPaddingFromRightEdgeOfScreenBottomAlignment, |
482 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, | 473 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, |
483 1, 1); | 474 1, 1); |
484 rect = ScreenUtil::ConvertRectToScreen(target_root, rect); | 475 rect = target_root->ConvertRectToScreen(rect); |
485 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) { | 476 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) { |
486 rect = gfx::Rect( | 477 rect = gfx::Rect( |
487 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, | 478 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, |
488 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, | 479 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, |
489 1, 1); | 480 1, 1); |
490 rect = ScreenUtil::ConvertRectToScreen(target_root, rect); | 481 rect = target_root->ConvertRectToScreen(rect); |
491 } else { | 482 } else { |
492 // TODO(bruthig) May need to handle other ANCHOR_ALIGNMENT_ values. | 483 // TODO(bruthig) May need to handle other ANCHOR_ALIGNMENT_ values. |
493 // ie. ANCHOR_ALIGNMENT_TOP | 484 // ie. ANCHOR_ALIGNMENT_TOP |
494 DCHECK(false) << "Unhandled anchor alignment."; | 485 DCHECK(false) << "Unhandled anchor alignment."; |
495 } | 486 } |
496 } else { | 487 } else { |
497 rect = gfx::Rect( | 488 rect = gfx::Rect( |
498 base::i18n::IsRTL() ? | 489 base::i18n::IsRTL() ? |
499 kPaddingFromRightEdgeOfScreenBottomAlignment : | 490 kPaddingFromRightEdgeOfScreenBottomAlignment : |
500 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, | 491 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, |
(...skipping 20 matching lines...) Expand all Loading... |
521 return; | 512 return; |
522 SchedulePaint(); | 513 SchedulePaint(); |
523 } | 514 } |
524 | 515 |
525 void TrayBackgroundView::UpdateBubbleViewArrow( | 516 void TrayBackgroundView::UpdateBubbleViewArrow( |
526 views::TrayBubbleView* bubble_view) { | 517 views::TrayBubbleView* bubble_view) { |
527 // Nothing to do here. | 518 // Nothing to do here. |
528 } | 519 } |
529 | 520 |
530 } // namespace ash | 521 } // namespace ash |
OLD | NEW |