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/window_animations.h" | 19 #include "ash/wm/window_animations.h" |
20 #include "grit/ash_resources.h" | 20 #include "grit/ash_resources.h" |
21 #include "ui/accessibility/ax_view_state.h" | 21 #include "ui/accessibility/ax_view_state.h" |
22 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
23 #include "ui/aura/window_event_dispatcher.h" | 23 #include "ui/aura/window_event_dispatcher.h" |
24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
25 #include "ui/compositor/layer.h" | |
26 #include "ui/compositor/scoped_layer_animation_settings.h" | |
25 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
26 #include "ui/gfx/image/image_skia.h" | 28 #include "ui/gfx/image/image_skia.h" |
27 #include "ui/gfx/image/image_skia_operations.h" | 29 #include "ui/gfx/image/image_skia_operations.h" |
28 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
29 #include "ui/gfx/screen.h" | 31 #include "ui/gfx/screen.h" |
30 #include "ui/gfx/skia_util.h" | 32 #include "ui/gfx/skia_util.h" |
33 #include "ui/gfx/transform.h" | |
31 #include "ui/views/background.h" | 34 #include "ui/views/background.h" |
32 #include "ui/views/layout/box_layout.h" | 35 #include "ui/views/layout/box_layout.h" |
33 | 36 |
34 namespace { | 37 namespace { |
35 | 38 |
36 const int kTrayBackgroundAlpha = 100; | 39 const int kTrayBackgroundAlpha = 100; |
37 const int kTrayBackgroundHoverAlpha = 150; | 40 const int kTrayBackgroundHoverAlpha = 150; |
38 const SkColor kTrayBackgroundPressedColor = SkColorSetRGB(66, 129, 244); | 41 const SkColor kTrayBackgroundPressedColor = SkColorSetRGB(66, 129, 244); |
39 | 42 |
40 const int kAnimationDurationForPopupMS = 200; | 43 const int kAnimationDurationForPopupMS = 200; |
44 const int kAnimationDurationForVisibility = 200; | |
41 | 45 |
42 } // namespace | 46 } // namespace |
43 | 47 |
44 using views::TrayBubbleView; | 48 using views::TrayBubbleView; |
45 | 49 |
46 namespace ash { | 50 namespace ash { |
47 | 51 |
48 // static | 52 // static |
49 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView"; | 53 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView"; |
50 | 54 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 | 304 |
301 // Initially we want to paint the background, but without the hover effect. | 305 // Initially we want to paint the background, but without the hover effect. |
302 hide_background_animator_.SetPaintsBackground( | 306 hide_background_animator_.SetPaintsBackground( |
303 true, BACKGROUND_CHANGE_IMMEDIATE); | 307 true, BACKGROUND_CHANGE_IMMEDIATE); |
304 hover_background_animator_.SetPaintsBackground( | 308 hover_background_animator_.SetPaintsBackground( |
305 false, BACKGROUND_CHANGE_IMMEDIATE); | 309 false, BACKGROUND_CHANGE_IMMEDIATE); |
306 | 310 |
307 tray_container_ = new TrayContainer(shelf_alignment_); | 311 tray_container_ = new TrayContainer(shelf_alignment_); |
308 SetContents(tray_container_); | 312 SetContents(tray_container_); |
309 tray_event_filter_.reset(new TrayEventFilter); | 313 tray_event_filter_.reset(new TrayEventFilter); |
314 | |
315 SetPaintToLayer(true); | |
316 SetFillsBoundsOpaquely(false); | |
310 } | 317 } |
311 | 318 |
312 TrayBackgroundView::~TrayBackgroundView() { | 319 TrayBackgroundView::~TrayBackgroundView() { |
313 if (GetWidget()) | 320 if (GetWidget()) |
314 GetWidget()->RemoveObserver(widget_observer_.get()); | 321 GetWidget()->RemoveObserver(widget_observer_.get()); |
315 } | 322 } |
316 | 323 |
317 void TrayBackgroundView::Initialize() { | 324 void TrayBackgroundView::Initialize() { |
318 GetWidget()->AddObserver(widget_observer_.get()); | 325 GetWidget()->AddObserver(widget_observer_.get()); |
319 SetTrayBorder(); | 326 SetTrayBorder(); |
320 } | 327 } |
321 | 328 |
329 void TrayBackgroundView::SetVisible(bool set_visible) { | |
flackr
2014/04/30 16:06:40
s/set_visible/visible to match the variable name i
jonross
2014/04/30 21:25:38
Done.
| |
330 if (set_visible == visible()) | |
331 return; | |
332 | |
333 if (set_visible) | |
334 views::View::SetVisible(set_visible); | |
flackr
2014/04/30 16:06:40
I believe you should be able to SetVisible(false)
jonross
2014/04/30 21:25:38
In order to user layer()->SetVisibility(false) I w
| |
335 | |
336 layer()->GetAnimator()->StopAnimating(); | |
337 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); | |
338 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | |
339 kAnimationDurationForVisibility)); | |
340 animation.SetPreemptionStrategy( | |
341 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
342 animation.AddObserver(this); | |
343 | |
344 if (set_visible) { | |
345 layer()->SetOpacity(1.0f); | |
346 gfx::Transform transform; | |
347 transform.Translate(0.0f, 0.0f); | |
348 transform.Scale(1.0f, 1.0f); | |
349 layer()->SetTransform(transform); | |
350 } else { | |
351 layer()->SetOpacity(0.0f); | |
352 gfx::Transform transform; | |
353 if (shelf_alignment_ == SHELF_ALIGNMENT_BOTTOM || | |
354 shelf_alignment_ == SHELF_ALIGNMENT_TOP) { | |
flackr
2014/04/30 16:06:40
nit: bad indent, should line up with above line.
jonross
2014/04/30 21:25:38
Done.
| |
355 transform.Translate(width(), height() / 2.0f); | |
356 } else { | |
357 transform.Translate(width() / 2.0f, height()); | |
358 } | |
359 transform.Scale(0.01f, 0.01f); | |
flackr
2014/04/30 16:06:40
Use constants for non 0 or 1 values.
jonross
2014/04/30 21:25:38
Done.
| |
360 layer()->SetTransform(transform); | |
361 } | |
362 } | |
363 | |
322 const char* TrayBackgroundView::GetClassName() const { | 364 const char* TrayBackgroundView::GetClassName() const { |
323 return kViewClassName; | 365 return kViewClassName; |
324 } | 366 } |
325 | 367 |
326 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { | 368 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { |
327 hovered_ = true; | 369 hovered_ = true; |
328 } | 370 } |
329 | 371 |
330 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { | 372 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { |
331 hovered_ = false; | 373 hovered_ = false; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
380 void TrayBackgroundView::SetContentsBackground() { | 422 void TrayBackgroundView::SetContentsBackground() { |
381 background_ = new TrayBackground(this); | 423 background_ = new TrayBackground(this); |
382 tray_container_->set_background(background_); | 424 tray_container_->set_background(background_); |
383 } | 425 } |
384 | 426 |
385 ShelfLayoutManager* TrayBackgroundView::GetShelfLayoutManager() { | 427 ShelfLayoutManager* TrayBackgroundView::GetShelfLayoutManager() { |
386 return ShelfLayoutManager::ForShelf(GetWidget()->GetNativeView()); | 428 return ShelfLayoutManager::ForShelf(GetWidget()->GetNativeView()); |
387 } | 429 } |
388 | 430 |
389 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { | 431 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { |
432 if (!visible() && shelf_alignment_ != alignment) { | |
433 // A translation transform was applied when becoming hidden. Swap the | |
434 // transform to be the offscreen position for the new alignment. | |
flackr
2014/04/30 16:06:40
It'd probably make more sense to set the correct t
jonross
2014/04/30 21:25:38
Done.
| |
435 gfx::Transform transform; | |
436 if (alignment == SHELF_ALIGNMENT_BOTTOM || alignment == SHELF_ALIGNMENT_TOP) | |
437 transform.Translate(width(), height() / 2.0f); | |
438 else | |
439 transform.Translate(width() /2.0f, height()); | |
440 transform.Scale(0.01f, 0.01f); | |
441 layer()->SetTransform(transform); | |
442 } | |
443 | |
390 shelf_alignment_ = alignment; | 444 shelf_alignment_ = alignment; |
391 SetTrayBorder(); | 445 SetTrayBorder(); |
392 tray_container_->SetAlignment(alignment); | 446 tray_container_->SetAlignment(alignment); |
393 } | 447 } |
394 | 448 |
395 void TrayBackgroundView::SetTrayBorder() { | 449 void TrayBackgroundView::SetTrayBorder() { |
396 views::View* parent = status_area_widget_->status_area_widget_delegate(); | 450 views::View* parent = status_area_widget_->status_area_widget_delegate(); |
397 // Tray views are laid out right-to-left or bottom-to-top | 451 // Tray views are laid out right-to-left or bottom-to-top |
398 bool on_edge = (this == parent->child_at(0)); | 452 bool on_edge = (this == parent->child_at(0)); |
399 int left_edge, top_edge, right_edge, bottom_edge; | 453 int left_edge, top_edge, right_edge, bottom_edge; |
(...skipping 13 matching lines...) Expand all Loading... | |
413 top_edge = 0; | 467 top_edge = 0; |
414 left_edge = ShelfLayoutManager::kShelfItemInset; | 468 left_edge = ShelfLayoutManager::kShelfItemInset; |
415 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; | 469 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; |
416 right_edge = kShelfSize - | 470 right_edge = kShelfSize - |
417 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight; | 471 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight; |
418 } | 472 } |
419 SetBorder(views::Border::CreateEmptyBorder( | 473 SetBorder(views::Border::CreateEmptyBorder( |
420 top_edge, left_edge, bottom_edge, right_edge)); | 474 top_edge, left_edge, bottom_edge, right_edge)); |
421 } | 475 } |
422 | 476 |
477 void TrayBackgroundView::OnImplicitAnimationsCompleted() { | |
478 if (layer()->opacity() == 0.0f) | |
479 views::View::SetVisible(false); | |
480 } | |
481 | |
423 void TrayBackgroundView::InitializeBubbleAnimations( | 482 void TrayBackgroundView::InitializeBubbleAnimations( |
424 views::Widget* bubble_widget) { | 483 views::Widget* bubble_widget) { |
425 wm::SetWindowVisibilityAnimationType( | 484 wm::SetWindowVisibilityAnimationType( |
426 bubble_widget->GetNativeWindow(), | 485 bubble_widget->GetNativeWindow(), |
427 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 486 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
428 wm::SetWindowVisibilityAnimationTransition( | 487 wm::SetWindowVisibilityAnimationTransition( |
429 bubble_widget->GetNativeWindow(), | 488 bubble_widget->GetNativeWindow(), |
430 wm::ANIMATE_HIDE); | 489 wm::ANIMATE_HIDE); |
431 wm::SetWindowVisibilityAnimationDuration( | 490 wm::SetWindowVisibilityAnimationDuration( |
432 bubble_widget->GetNativeWindow(), | 491 bubble_widget->GetNativeWindow(), |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 background_->set_alpha(kTrayBackgroundAlpha); | 578 background_->set_alpha(kTrayBackgroundAlpha); |
520 SchedulePaint(); | 579 SchedulePaint(); |
521 } | 580 } |
522 | 581 |
523 void TrayBackgroundView::UpdateBubbleViewArrow( | 582 void TrayBackgroundView::UpdateBubbleViewArrow( |
524 views::TrayBubbleView* bubble_view) { | 583 views::TrayBubbleView* bubble_view) { |
525 // Nothing to do here. | 584 // Nothing to do here. |
526 } | 585 } |
527 | 586 |
528 } // namespace ash | 587 } // namespace ash |
OLD | NEW |