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_item_view.h" | 5 #include "ash/system/tray/tray_item_view.h" |
6 | 6 |
7 #include "ash/shelf/shelf_types.h" | 7 #include "ash/shelf/shelf_types.h" |
8 #include "ash/system/tray/system_tray.h" | 8 #include "ash/system/tray/system_tray.h" |
9 #include "ash/system/tray/system_tray_item.h" | 9 #include "ash/system/tray/system_tray_item.h" |
10 #include "ui/compositor/layer.h" | 10 #include "ui/compositor/layer.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 gfx::Size TrayItemView::DesiredSize() const { | 78 gfx::Size TrayItemView::DesiredSize() const { |
79 return views::View::GetPreferredSize(); | 79 return views::View::GetPreferredSize(); |
80 } | 80 } |
81 | 81 |
82 int TrayItemView::GetAnimationDurationMS() { | 82 int TrayItemView::GetAnimationDurationMS() { |
83 return kTrayItemAnimationDurationMS; | 83 return kTrayItemAnimationDurationMS; |
84 } | 84 } |
85 | 85 |
86 gfx::Size TrayItemView::GetPreferredSize() const { | 86 gfx::Size TrayItemView::GetPreferredSize() const { |
87 gfx::Size size = DesiredSize(); | 87 gfx::Size size = DesiredSize(); |
88 if (owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM || | 88 if (owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) |
89 owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_TOP) | |
90 size.set_height(kTrayIconHeight); | 89 size.set_height(kTrayIconHeight); |
91 else | 90 else |
92 size.set_width(kTrayIconWidth); | 91 size.set_width(kTrayIconWidth); |
93 if (!animation_.get() || !animation_->is_animating()) | 92 if (!animation_.get() || !animation_->is_animating()) |
94 return size; | 93 return size; |
95 if (owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM || | 94 if (owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { |
96 owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_TOP) { | |
97 size.set_width(std::max(1, | 95 size.set_width(std::max(1, |
98 static_cast<int>(size.width() * animation_->GetCurrentValue()))); | 96 static_cast<int>(size.width() * animation_->GetCurrentValue()))); |
99 } else { | 97 } else { |
100 size.set_height(std::max(1, | 98 size.set_height(std::max(1, |
101 static_cast<int>(size.height() * animation_->GetCurrentValue()))); | 99 static_cast<int>(size.height() * animation_->GetCurrentValue()))); |
102 } | 100 } |
103 return size; | 101 return size; |
104 } | 102 } |
105 | 103 |
106 int TrayItemView::GetHeightForWidth(int width) const { | 104 int TrayItemView::GetHeightForWidth(int width) const { |
107 return GetPreferredSize().height(); | 105 return GetPreferredSize().height(); |
108 } | 106 } |
109 | 107 |
110 void TrayItemView::ChildPreferredSizeChanged(views::View* child) { | 108 void TrayItemView::ChildPreferredSizeChanged(views::View* child) { |
111 PreferredSizeChanged(); | 109 PreferredSizeChanged(); |
112 } | 110 } |
113 | 111 |
114 void TrayItemView::AnimationProgressed(const gfx::Animation* animation) { | 112 void TrayItemView::AnimationProgressed(const gfx::Animation* animation) { |
115 gfx::Transform transform; | 113 gfx::Transform transform; |
116 if (owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM || | 114 if (owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { |
117 owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_TOP) { | |
118 transform.Translate(0, animation->CurrentValueBetween( | 115 transform.Translate(0, animation->CurrentValueBetween( |
119 static_cast<double>(height()) / 2, 0.)); | 116 static_cast<double>(height()) / 2, 0.)); |
120 } else { | 117 } else { |
121 transform.Translate(animation->CurrentValueBetween( | 118 transform.Translate(animation->CurrentValueBetween( |
122 static_cast<double>(width() / 2), 0.), 0); | 119 static_cast<double>(width() / 2), 0.), 0); |
123 } | 120 } |
124 transform.Scale(animation->GetCurrentValue(), | 121 transform.Scale(animation->GetCurrentValue(), |
125 animation->GetCurrentValue()); | 122 animation->GetCurrentValue()); |
126 layer()->SetTransform(transform); | 123 layer()->SetTransform(transform); |
127 PreferredSizeChanged(); | 124 PreferredSizeChanged(); |
128 } | 125 } |
129 | 126 |
130 void TrayItemView::AnimationEnded(const gfx::Animation* animation) { | 127 void TrayItemView::AnimationEnded(const gfx::Animation* animation) { |
131 if (animation->GetCurrentValue() < 0.1) | 128 if (animation->GetCurrentValue() < 0.1) |
132 views::View::SetVisible(false); | 129 views::View::SetVisible(false); |
133 } | 130 } |
134 | 131 |
135 void TrayItemView::AnimationCanceled(const gfx::Animation* animation) { | 132 void TrayItemView::AnimationCanceled(const gfx::Animation* animation) { |
136 AnimationEnded(animation); | 133 AnimationEnded(animation); |
137 } | 134 } |
138 | 135 |
139 } // namespace ash | 136 } // namespace ash |
OLD | NEW |