Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: ash/system/tray/tray_item_view.cc

Issue 10386142: ash: Some code-cleanup around tray-resizing code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/system/tray/tray_item_view.h ('k') | ash/system/user/tray_user.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/base/animation/slide_animation.h" 7 #include "ui/base/animation/slide_animation.h"
8 #include "ui/compositor/layer.h" 8 #include "ui/compositor/layer.h"
9 #include "ui/views/controls/image_view.h" 9 #include "ui/views/controls/image_view.h"
10 #include "ui/views/controls/label.h" 10 #include "ui/views/controls/label.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 if (!set_visible) { 55 if (!set_visible) {
56 animation_->Hide(); 56 animation_->Hide();
57 AnimationProgressed(animation_.get()); 57 AnimationProgressed(animation_.get());
58 } else { 58 } else {
59 animation_->Show(); 59 animation_->Show();
60 AnimationProgressed(animation_.get()); 60 AnimationProgressed(animation_.get());
61 views::View::SetVisible(true); 61 views::View::SetVisible(true);
62 } 62 }
63 } 63 }
64 64
65 void TrayItemView::ApplyChange() {
66 // Forcing the widget to the new size is sufficient. The positioning is
67 // taken care of by the layout manager (ShelfLayoutManager).
68 GetWidget()->SetSize(GetWidget()->GetContentsView()->GetPreferredSize());
69 }
70
71 gfx::Size TrayItemView::DesiredSize() { 65 gfx::Size TrayItemView::DesiredSize() {
72 return views::View::GetPreferredSize(); 66 return views::View::GetPreferredSize();
73 } 67 }
74 68
75 int TrayItemView::GetAnimationDurationMS() { 69 int TrayItemView::GetAnimationDurationMS() {
76 return kTrayItemAnimationDurationMS; 70 return kTrayItemAnimationDurationMS;
77 } 71 }
78 72
79 void TrayItemView::PreferredSizeChanged() {
80 views::View::PreferredSizeChanged();
81 ApplyChange();
82 }
83
84 gfx::Size TrayItemView::GetPreferredSize() { 73 gfx::Size TrayItemView::GetPreferredSize() {
85 gfx::Size size = DesiredSize(); 74 gfx::Size size = DesiredSize();
86 size.set_height(kTrayIconHeight); 75 size.set_height(kTrayIconHeight);
87 if (!animation_.get() || !animation_->is_animating()) 76 if (!animation_.get() || !animation_->is_animating())
88 return size; 77 return size;
89 size.set_width(std::max(1, 78 size.set_width(std::max(1,
90 static_cast<int>(size.width() * animation_->GetCurrentValue()))); 79 static_cast<int>(size.width() * animation_->GetCurrentValue())));
91 return size; 80 return size;
92 } 81 }
93 82
83 void TrayItemView::ChildPreferredSizeChanged(views::View* child) {
84 PreferredSizeChanged();
85 }
86
94 void TrayItemView::AnimationProgressed(const ui::Animation* animation) { 87 void TrayItemView::AnimationProgressed(const ui::Animation* animation) {
95 ui::Transform transform; 88 ui::Transform transform;
96 transform.SetScale(animation->GetCurrentValue(), 89 transform.SetScale(animation->GetCurrentValue(),
97 animation->GetCurrentValue()); 90 animation->GetCurrentValue());
98 transform.ConcatTranslate(0, animation->CurrentValueBetween( 91 transform.ConcatTranslate(0, animation->CurrentValueBetween(
99 static_cast<double>(height()) / 2, 0.)); 92 static_cast<double>(height()) / 2, 0.));
100 layer()->SetTransform(transform); 93 layer()->SetTransform(transform);
101 ApplyChange(); 94 PreferredSizeChanged();
102 } 95 }
103 96
104 void TrayItemView::AnimationEnded(const ui::Animation* animation) { 97 void TrayItemView::AnimationEnded(const ui::Animation* animation) {
105 if (animation->GetCurrentValue() < 0.1) 98 if (animation->GetCurrentValue() < 0.1)
106 views::View::SetVisible(false); 99 views::View::SetVisible(false);
107 } 100 }
108 101
109 void TrayItemView::AnimationCanceled(const ui::Animation* animation) { 102 void TrayItemView::AnimationCanceled(const ui::Animation* animation) {
110 AnimationEnded(animation); 103 AnimationEnded(animation);
111 } 104 }
112 105
113 } // namespace internal 106 } // namespace internal
114 } // namespace ash 107 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/tray_item_view.h ('k') | ash/system/user/tray_user.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698