OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/common/system/tray/throbber_view.h" | 5 #include "ash/common/system/tray/throbber_view.h" |
6 | 6 |
7 #include "ash/common/system/tray/tray_constants.h" | 7 #include "ash/common/system/tray/tray_constants.h" |
8 #include "grit/ash_resources.h" | 8 #include "grit/ash_resources.h" |
9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
10 #include "ui/compositor/layer.h" | 10 #include "ui/compositor/layer.h" |
11 #include "ui/compositor/scoped_layer_animation_settings.h" | 11 #include "ui/compositor/scoped_layer_animation_settings.h" |
12 | 12 |
13 namespace ash { | 13 namespace ash { |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Duration for showing/hiding animation in milliseconds. | 16 // Duration for showing/hiding animation in milliseconds. |
17 const int kThrobberAnimationDurationMs = 200; | 17 const int kThrobberAnimationDurationMs = 200; |
18 | 18 |
19 } // namespace | 19 } // namespace |
20 | 20 |
21 SystemTrayThrobber::SystemTrayThrobber() : views::SmoothedThrobber() { | 21 SystemTrayThrobber::SystemTrayThrobber() : views::SmoothedThrobber() {} |
22 } | |
23 | 22 |
24 SystemTrayThrobber::~SystemTrayThrobber() { | 23 SystemTrayThrobber::~SystemTrayThrobber() {} |
25 } | |
26 | 24 |
27 void SystemTrayThrobber::SetTooltipText(const base::string16& tooltip_text) { | 25 void SystemTrayThrobber::SetTooltipText(const base::string16& tooltip_text) { |
28 tooltip_text_ = tooltip_text; | 26 tooltip_text_ = tooltip_text; |
29 } | 27 } |
30 | 28 |
31 bool SystemTrayThrobber::GetTooltipText(const gfx::Point& p, | 29 bool SystemTrayThrobber::GetTooltipText(const gfx::Point& p, |
32 base::string16* tooltip) const { | 30 base::string16* tooltip) const { |
33 if (tooltip_text_.empty()) | 31 if (tooltip_text_.empty()) |
34 return false; | 32 return false; |
35 | 33 |
36 *tooltip = tooltip_text_; | 34 *tooltip = tooltip_text_; |
37 return true; | 35 return true; |
38 } | 36 } |
39 | 37 |
40 ThrobberView::ThrobberView() { | 38 ThrobberView::ThrobberView() { |
41 throbber_ = new SystemTrayThrobber(); | 39 throbber_ = new SystemTrayThrobber(); |
42 throbber_->set_stop_delay_ms(kThrobberAnimationDurationMs); | 40 throbber_->set_stop_delay_ms(kThrobberAnimationDurationMs); |
43 AddChildView(throbber_); | 41 AddChildView(throbber_); |
44 | 42 |
45 SetPaintToLayer(true); | 43 SetPaintToLayer(true); |
46 layer()->SetFillsBoundsOpaquely(false); | 44 layer()->SetFillsBoundsOpaquely(false); |
47 layer()->SetOpacity(0.0); | 45 layer()->SetOpacity(0.0); |
48 } | 46 } |
49 | 47 |
50 ThrobberView::~ThrobberView() { | 48 ThrobberView::~ThrobberView() {} |
51 } | |
52 | 49 |
53 gfx::Size ThrobberView::GetPreferredSize() const { | 50 gfx::Size ThrobberView::GetPreferredSize() const { |
54 return gfx::Size(ash::kTrayPopupItemHeight, ash::kTrayPopupItemHeight); | 51 return gfx::Size(ash::kTrayPopupItemHeight, ash::kTrayPopupItemHeight); |
55 } | 52 } |
56 | 53 |
57 void ThrobberView::Layout() { | 54 void ThrobberView::Layout() { |
58 View* child = child_at(0); | 55 View* child = child_at(0); |
59 gfx::Size ps = child->GetPreferredSize(); | 56 gfx::Size ps = child->GetPreferredSize(); |
60 child->SetBounds((width() - ps.width()) / 2, | 57 child->SetBounds((width() - ps.width()) / 2, (height() - ps.height()) / 2, |
61 (height() - ps.height()) / 2, | |
62 ps.width(), ps.height()); | 58 ps.width(), ps.height()); |
63 SizeToPreferredSize(); | 59 SizeToPreferredSize(); |
64 } | 60 } |
65 | 61 |
66 bool ThrobberView::GetTooltipText(const gfx::Point& p, | 62 bool ThrobberView::GetTooltipText(const gfx::Point& p, |
67 base::string16* tooltip) const { | 63 base::string16* tooltip) const { |
68 if (tooltip_text_.empty()) | 64 if (tooltip_text_.empty()) |
69 return false; | 65 return false; |
70 | 66 |
71 *tooltip = tooltip_text_; | 67 *tooltip = tooltip_text_; |
(...skipping 20 matching lines...) Expand all Loading... |
92 layer()->GetAnimator()->StopAnimating(); | 88 layer()->GetAnimator()->StopAnimating(); |
93 | 89 |
94 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); | 90 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); |
95 animation.SetTransitionDuration( | 91 animation.SetTransitionDuration( |
96 base::TimeDelta::FromMilliseconds(kThrobberAnimationDurationMs)); | 92 base::TimeDelta::FromMilliseconds(kThrobberAnimationDurationMs)); |
97 | 93 |
98 layer()->SetOpacity(start_throbber ? 1.0 : 0.0); | 94 layer()->SetOpacity(start_throbber ? 1.0 : 0.0); |
99 } | 95 } |
100 | 96 |
101 } // namespace ash | 97 } // namespace ash |
OLD | NEW |