Chromium Code Reviews| 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" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "ui/views/background.h" | 31 #include "ui/views/background.h" |
| 32 #include "ui/views/layout/box_layout.h" | 32 #include "ui/views/layout/box_layout.h" |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 const int kTrayBackgroundAlpha = 100; | 36 const int kTrayBackgroundAlpha = 100; |
| 37 const int kTrayBackgroundHoverAlpha = 150; | 37 const int kTrayBackgroundHoverAlpha = 150; |
| 38 const SkColor kTrayBackgroundPressedColor = SkColorSetRGB(66, 129, 244); | 38 const SkColor kTrayBackgroundPressedColor = SkColorSetRGB(66, 129, 244); |
| 39 | 39 |
| 40 const int kAnimationDurationForPopupMS = 200; | 40 const int kAnimationDurationForPopupMS = 200; |
| 41 const int kAnimationDurationForVisibility = 200; | |
| 41 | 42 |
| 43 // Animations can be disabled for tests. | |
| 44 bool animations_enabled = true; | |
|
flackr
2014/04/29 14:18:22
nit: newline before end of namespace.
jonross
2014/04/30 14:09:31
Done.
| |
| 42 } // namespace | 45 } // namespace |
| 43 | 46 |
| 44 using views::TrayBubbleView; | 47 using views::TrayBubbleView; |
| 45 | 48 |
| 46 namespace ash { | 49 namespace ash { |
| 47 | 50 |
| 48 // static | 51 // static |
| 49 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView"; | 52 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView"; |
| 50 | 53 |
| 51 // Used to track when the anchor widget changes position on screen so that the | 54 // Used to track when the anchor widget changes position on screen so that the |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 | 303 |
| 301 // Initially we want to paint the background, but without the hover effect. | 304 // Initially we want to paint the background, but without the hover effect. |
| 302 hide_background_animator_.SetPaintsBackground( | 305 hide_background_animator_.SetPaintsBackground( |
| 303 true, BACKGROUND_CHANGE_IMMEDIATE); | 306 true, BACKGROUND_CHANGE_IMMEDIATE); |
| 304 hover_background_animator_.SetPaintsBackground( | 307 hover_background_animator_.SetPaintsBackground( |
| 305 false, BACKGROUND_CHANGE_IMMEDIATE); | 308 false, BACKGROUND_CHANGE_IMMEDIATE); |
| 306 | 309 |
| 307 tray_container_ = new TrayContainer(shelf_alignment_); | 310 tray_container_ = new TrayContainer(shelf_alignment_); |
| 308 SetContents(tray_container_); | 311 SetContents(tray_container_); |
| 309 tray_event_filter_.reset(new TrayEventFilter); | 312 tray_event_filter_.reset(new TrayEventFilter); |
| 313 | |
| 314 SetPaintToLayer(true); | |
| 315 SetFillsBoundsOpaquely(false); | |
| 310 } | 316 } |
| 311 | 317 |
| 312 TrayBackgroundView::~TrayBackgroundView() { | 318 TrayBackgroundView::~TrayBackgroundView() { |
| 313 if (GetWidget()) | 319 if (GetWidget()) |
| 314 GetWidget()->RemoveObserver(widget_observer_.get()); | 320 GetWidget()->RemoveObserver(widget_observer_.get()); |
| 315 } | 321 } |
| 316 | 322 |
| 317 void TrayBackgroundView::Initialize() { | 323 void TrayBackgroundView::Initialize() { |
| 318 GetWidget()->AddObserver(widget_observer_.get()); | 324 GetWidget()->AddObserver(widget_observer_.get()); |
| 319 SetTrayBorder(); | 325 SetTrayBorder(); |
| 320 } | 326 } |
| 321 | 327 |
| 328 void TrayBackgroundView::SetVisible(bool set_visible) { | |
| 329 if (!GetWidget() || !animations_enabled) { | |
| 330 views::View::SetVisible(set_visible); | |
| 331 return; | |
| 332 } | |
| 333 | |
| 334 if (!animation_) { | |
| 335 animation_.reset(new gfx::SlideAnimation(this)); | |
| 336 animation_->SetSlideDuration(kAnimationDurationForVisibility); | |
| 337 animation_->SetTweenType(gfx::Tween::LINEAR); | |
| 338 animation_->Reset(visible() ? 1.0 : 0.0); | |
| 339 } | |
| 340 | |
| 341 if (!set_visible) { | |
| 342 animation_->Hide(); | |
| 343 AnimationProgressed(animation_.get()); | |
|
flackr
2014/04/29 14:18:22
Isn't AnimationProgressed supposed to be called au
| |
| 344 } else { | |
| 345 animation_->Show(); | |
| 346 AnimationProgressed(animation_.get()); | |
| 347 views::View::SetVisible(true); | |
| 348 } | |
| 349 } | |
| 350 | |
| 351 gfx::Size TrayBackgroundView::GetPreferredSize() { | |
| 352 gfx::Size size = views::View::GetPreferredSize(); | |
| 353 if (!animation_.get() || !animation_->is_animating()) | |
| 354 return size; | |
| 355 if (shelf_alignment_ == SHELF_ALIGNMENT_BOTTOM || | |
| 356 shelf_alignment_ == SHELF_ALIGNMENT_TOP) { | |
| 357 size.set_width(std::max(1, | |
| 358 static_cast<int>(size.width() * animation_->GetCurrentValue()))); | |
| 359 } else { | |
| 360 size.set_height(std::max(1, | |
| 361 static_cast<int>(size.height() * animation_->GetCurrentValue()))); | |
| 362 } | |
| 363 return size; | |
| 364 } | |
| 365 | |
| 366 int TrayBackgroundView::GetHeightForWidth(int width) { | |
| 367 return GetPreferredSize().height(); | |
| 368 } | |
| 369 | |
| 322 const char* TrayBackgroundView::GetClassName() const { | 370 const char* TrayBackgroundView::GetClassName() const { |
| 323 return kViewClassName; | 371 return kViewClassName; |
| 324 } | 372 } |
| 325 | 373 |
| 326 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { | 374 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { |
| 327 hovered_ = true; | 375 hovered_ = true; |
| 328 } | 376 } |
| 329 | 377 |
| 330 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { | 378 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { |
| 331 hovered_ = false; | 379 hovered_ = false; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 top_edge = 0; | 461 top_edge = 0; |
| 414 left_edge = ShelfLayoutManager::kShelfItemInset; | 462 left_edge = ShelfLayoutManager::kShelfItemInset; |
| 415 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; | 463 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; |
| 416 right_edge = kShelfSize - | 464 right_edge = kShelfSize - |
| 417 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight; | 465 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight; |
| 418 } | 466 } |
| 419 SetBorder(views::Border::CreateEmptyBorder( | 467 SetBorder(views::Border::CreateEmptyBorder( |
| 420 top_edge, left_edge, bottom_edge, right_edge)); | 468 top_edge, left_edge, bottom_edge, right_edge)); |
| 421 } | 469 } |
| 422 | 470 |
| 471 void TrayBackgroundView::DisableAnimationsForTest() { | |
| 472 animations_enabled = false; | |
|
flackr
2014/04/29 14:18:22
I realize this pattern is copied from elsewhere, b
| |
| 473 } | |
| 474 | |
| 475 void TrayBackgroundView::AnimationProgressed(const gfx::Animation* animation) { | |
| 476 gfx::Transform transform; | |
| 477 if (shelf_alignment_ == SHELF_ALIGNMENT_BOTTOM || | |
| 478 shelf_alignment_ == SHELF_ALIGNMENT_TOP) { | |
| 479 transform.Translate(0, animation->CurrentValueBetween( | |
| 480 static_cast<double>(height()) / 2, 0.)); | |
|
flackr
2014/04/29 14:18:22
nit: The static_cast is unnecessary for this sort
| |
| 481 } else { | |
| 482 transform.Translate(animation->CurrentValueBetween( | |
| 483 static_cast<double>(width() / 2), 0.), 0); | |
|
flackr
2014/04/29 14:18:22
ditto.
| |
| 484 } | |
| 485 transform.Scale(animation->GetCurrentValue(), | |
| 486 animation->GetCurrentValue()); | |
| 487 layer()->SetTransform(transform); | |
|
flackr
2014/04/29 14:18:22
The animation is done as a layer transform? Would
| |
| 488 PreferredSizeChanged(); | |
| 489 } | |
| 490 | |
| 491 void TrayBackgroundView::AnimationEnded(const gfx::Animation* animation) { | |
| 492 if (animation->GetCurrentValue() < 0.1) | |
| 493 views::View::SetVisible(false); | |
| 494 } | |
| 495 | |
| 496 void TrayBackgroundView::AnimationCanceled(const gfx::Animation* animation) { | |
| 497 AnimationEnded(animation); | |
|
flackr
2014/04/29 14:18:22
Isn't this not guaranteed to give the correct resu
| |
| 498 } | |
| 499 | |
| 423 void TrayBackgroundView::InitializeBubbleAnimations( | 500 void TrayBackgroundView::InitializeBubbleAnimations( |
| 424 views::Widget* bubble_widget) { | 501 views::Widget* bubble_widget) { |
| 425 wm::SetWindowVisibilityAnimationType( | 502 wm::SetWindowVisibilityAnimationType( |
| 426 bubble_widget->GetNativeWindow(), | 503 bubble_widget->GetNativeWindow(), |
| 427 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 504 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
| 428 wm::SetWindowVisibilityAnimationTransition( | 505 wm::SetWindowVisibilityAnimationTransition( |
| 429 bubble_widget->GetNativeWindow(), | 506 bubble_widget->GetNativeWindow(), |
| 430 wm::ANIMATE_HIDE); | 507 wm::ANIMATE_HIDE); |
| 431 wm::SetWindowVisibilityAnimationDuration( | 508 wm::SetWindowVisibilityAnimationDuration( |
| 432 bubble_widget->GetNativeWindow(), | 509 bubble_widget->GetNativeWindow(), |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 background_->set_alpha(kTrayBackgroundAlpha); | 596 background_->set_alpha(kTrayBackgroundAlpha); |
| 520 SchedulePaint(); | 597 SchedulePaint(); |
| 521 } | 598 } |
| 522 | 599 |
| 523 void TrayBackgroundView::UpdateBubbleViewArrow( | 600 void TrayBackgroundView::UpdateBubbleViewArrow( |
| 524 views::TrayBubbleView* bubble_view) { | 601 views::TrayBubbleView* bubble_view) { |
| 525 // Nothing to do here. | 602 // Nothing to do here. |
| 526 } | 603 } |
| 527 | 604 |
| 528 } // namespace ash | 605 } // namespace ash |
| OLD | NEW |