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

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

Issue 1877543002: Revise the shelf alignment locking mechanism. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update and cleanup tests. Created 4 years, 8 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
« no previous file with comments | « ash/system/tray/tray_image_item.cc ('k') | ash/system/tray/tray_utils.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 "ash/shelf/shelf_types.h" 7 #include "ash/shelf/shelf_types.h"
8 #include "ash/shelf/shelf_util.h"
8 #include "ash/system/tray/system_tray.h" 9 #include "ash/system/tray/system_tray.h"
9 #include "ash/system/tray/system_tray_item.h" 10 #include "ash/system/tray/system_tray_item.h"
10 #include "ui/compositor/layer.h" 11 #include "ui/compositor/layer.h"
11 #include "ui/gfx/animation/slide_animation.h" 12 #include "ui/gfx/animation/slide_animation.h"
12 #include "ui/views/controls/image_view.h" 13 #include "ui/views/controls/image_view.h"
13 #include "ui/views/controls/label.h" 14 #include "ui/views/controls/label.h"
14 #include "ui/views/layout/box_layout.h" 15 #include "ui/views/layout/box_layout.h"
15 #include "ui/views/widget/widget.h" 16 #include "ui/views/widget/widget.h"
16 17
17 namespace { 18 namespace {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 gfx::Size TrayItemView::DesiredSize() const { 79 gfx::Size TrayItemView::DesiredSize() const {
79 return views::View::GetPreferredSize(); 80 return views::View::GetPreferredSize();
80 } 81 }
81 82
82 int TrayItemView::GetAnimationDurationMS() { 83 int TrayItemView::GetAnimationDurationMS() {
83 return kTrayItemAnimationDurationMS; 84 return kTrayItemAnimationDurationMS;
84 } 85 }
85 86
86 gfx::Size TrayItemView::GetPreferredSize() const { 87 gfx::Size TrayItemView::GetPreferredSize() const {
87 gfx::Size size = DesiredSize(); 88 gfx::Size size = DesiredSize();
88 if (owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) 89 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment()))
89 size.set_height(kTrayIconHeight); 90 size.set_height(kTrayIconHeight);
90 else 91 else
91 size.set_width(kTrayIconWidth); 92 size.set_width(kTrayIconWidth);
92 if (!animation_.get() || !animation_->is_animating()) 93 if (!animation_.get() || !animation_->is_animating())
93 return size; 94 return size;
94 if (owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { 95 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) {
95 size.set_width(std::max(1, 96 size.set_width(std::max(1,
96 static_cast<int>(size.width() * animation_->GetCurrentValue()))); 97 static_cast<int>(size.width() * animation_->GetCurrentValue())));
97 } else { 98 } else {
98 size.set_height(std::max(1, 99 size.set_height(std::max(1,
99 static_cast<int>(size.height() * animation_->GetCurrentValue()))); 100 static_cast<int>(size.height() * animation_->GetCurrentValue())));
100 } 101 }
101 return size; 102 return size;
102 } 103 }
103 104
104 int TrayItemView::GetHeightForWidth(int width) const { 105 int TrayItemView::GetHeightForWidth(int width) const {
105 return GetPreferredSize().height(); 106 return GetPreferredSize().height();
106 } 107 }
107 108
108 void TrayItemView::ChildPreferredSizeChanged(views::View* child) { 109 void TrayItemView::ChildPreferredSizeChanged(views::View* child) {
109 PreferredSizeChanged(); 110 PreferredSizeChanged();
110 } 111 }
111 112
112 void TrayItemView::AnimationProgressed(const gfx::Animation* animation) { 113 void TrayItemView::AnimationProgressed(const gfx::Animation* animation) {
113 gfx::Transform transform; 114 gfx::Transform transform;
114 if (owner()->system_tray()->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { 115 if (IsHorizontalAlignment(owner()->system_tray()->shelf_alignment())) {
115 transform.Translate(0, animation->CurrentValueBetween( 116 transform.Translate(0, animation->CurrentValueBetween(
116 static_cast<double>(height()) / 2, 0.)); 117 static_cast<double>(height()) / 2, 0.));
117 } else { 118 } else {
118 transform.Translate(animation->CurrentValueBetween( 119 transform.Translate(animation->CurrentValueBetween(
119 static_cast<double>(width() / 2), 0.), 0); 120 static_cast<double>(width() / 2), 0.), 0);
120 } 121 }
121 transform.Scale(animation->GetCurrentValue(), 122 transform.Scale(animation->GetCurrentValue(),
122 animation->GetCurrentValue()); 123 animation->GetCurrentValue());
123 layer()->SetTransform(transform); 124 layer()->SetTransform(transform);
124 PreferredSizeChanged(); 125 PreferredSizeChanged();
125 } 126 }
126 127
127 void TrayItemView::AnimationEnded(const gfx::Animation* animation) { 128 void TrayItemView::AnimationEnded(const gfx::Animation* animation) {
128 if (animation->GetCurrentValue() < 0.1) 129 if (animation->GetCurrentValue() < 0.1)
129 views::View::SetVisible(false); 130 views::View::SetVisible(false);
130 } 131 }
131 132
132 void TrayItemView::AnimationCanceled(const gfx::Animation* animation) { 133 void TrayItemView::AnimationCanceled(const gfx::Animation* animation) {
133 AnimationEnded(animation); 134 AnimationEnded(animation);
134 } 135 }
135 136
136 } // namespace ash 137 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/tray_image_item.cc ('k') | ash/system/tray/tray_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698