| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/system/tray/throbber_view.h" | |
| 6 | |
| 7 #include "ash/common/system/tray/tray_constants.h" | |
| 8 #include "grit/ash_resources.h" | |
| 9 #include "ui/base/resource/resource_bundle.h" | |
| 10 #include "ui/compositor/layer.h" | |
| 11 #include "ui/compositor/scoped_layer_animation_settings.h" | |
| 12 | |
| 13 namespace ash { | |
| 14 namespace { | |
| 15 | |
| 16 // Duration for showing/hiding animation in milliseconds. | |
| 17 const int kThrobberAnimationDurationMs = 200; | |
| 18 | |
| 19 } // namespace | |
| 20 | |
| 21 SystemTrayThrobber::SystemTrayThrobber() : views::SmoothedThrobber() { | |
| 22 } | |
| 23 | |
| 24 SystemTrayThrobber::~SystemTrayThrobber() { | |
| 25 } | |
| 26 | |
| 27 void SystemTrayThrobber::SetTooltipText(const base::string16& tooltip_text) { | |
| 28 tooltip_text_ = tooltip_text; | |
| 29 } | |
| 30 | |
| 31 bool SystemTrayThrobber::GetTooltipText(const gfx::Point& p, | |
| 32 base::string16* tooltip) const { | |
| 33 if (tooltip_text_.empty()) | |
| 34 return false; | |
| 35 | |
| 36 *tooltip = tooltip_text_; | |
| 37 return true; | |
| 38 } | |
| 39 | |
| 40 ThrobberView::ThrobberView() { | |
| 41 throbber_ = new SystemTrayThrobber(); | |
| 42 throbber_->set_stop_delay_ms(kThrobberAnimationDurationMs); | |
| 43 AddChildView(throbber_); | |
| 44 | |
| 45 SetPaintToLayer(true); | |
| 46 layer()->SetFillsBoundsOpaquely(false); | |
| 47 layer()->SetOpacity(0.0); | |
| 48 } | |
| 49 | |
| 50 ThrobberView::~ThrobberView() { | |
| 51 } | |
| 52 | |
| 53 gfx::Size ThrobberView::GetPreferredSize() const { | |
| 54 return gfx::Size(ash::kTrayPopupItemHeight, ash::kTrayPopupItemHeight); | |
| 55 } | |
| 56 | |
| 57 void ThrobberView::Layout() { | |
| 58 View* child = child_at(0); | |
| 59 gfx::Size ps = child->GetPreferredSize(); | |
| 60 child->SetBounds((width() - ps.width()) / 2, | |
| 61 (height() - ps.height()) / 2, | |
| 62 ps.width(), ps.height()); | |
| 63 SizeToPreferredSize(); | |
| 64 } | |
| 65 | |
| 66 bool ThrobberView::GetTooltipText(const gfx::Point& p, | |
| 67 base::string16* tooltip) const { | |
| 68 if (tooltip_text_.empty()) | |
| 69 return false; | |
| 70 | |
| 71 *tooltip = tooltip_text_; | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 void ThrobberView::Start() { | |
| 76 ScheduleAnimation(true); | |
| 77 throbber_->Start(); | |
| 78 } | |
| 79 | |
| 80 void ThrobberView::Stop() { | |
| 81 ScheduleAnimation(false); | |
| 82 throbber_->Stop(); | |
| 83 } | |
| 84 | |
| 85 void ThrobberView::SetTooltipText(const base::string16& tooltip_text) { | |
| 86 tooltip_text_ = tooltip_text; | |
| 87 throbber_->SetTooltipText(tooltip_text); | |
| 88 } | |
| 89 | |
| 90 void ThrobberView::ScheduleAnimation(bool start_throbber) { | |
| 91 // Stop any previous animation. | |
| 92 layer()->GetAnimator()->StopAnimating(); | |
| 93 | |
| 94 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); | |
| 95 animation.SetTransitionDuration( | |
| 96 base::TimeDelta::FromMilliseconds(kThrobberAnimationDurationMs)); | |
| 97 | |
| 98 layer()->SetOpacity(start_throbber ? 1.0 : 0.0); | |
| 99 } | |
| 100 | |
| 101 } // namespace ash | |
| OLD | NEW |