OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/setting_level_bubble.h" | 5 #include "chrome/browser/chromeos/setting_level_bubble.h" |
6 | 6 |
7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
8 | 8 |
9 #include "base/timer.h" | 9 #include "base/timer.h" |
10 #include "chrome/browser/chromeos/login/background_view.h" | 10 #include "chrome/browser/chromeos/login/background_view.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 | 68 |
69 if (window) | 69 if (window) |
70 return views::Widget::GetWidgetForNativeWindow(window); | 70 return views::Widget::GetWidgetForNativeWindow(window); |
71 else | 71 else |
72 return WebUILoginDisplay::GetLoginWindow(); | 72 return WebUILoginDisplay::GetLoginWindow(); |
73 } | 73 } |
74 | 74 |
75 SettingLevelBubble::SettingLevelBubble(SkBitmap* increase_icon, | 75 SettingLevelBubble::SettingLevelBubble(SkBitmap* increase_icon, |
76 SkBitmap* decrease_icon, | 76 SkBitmap* decrease_icon, |
77 SkBitmap* zero_icon) | 77 SkBitmap* disabled_icon) |
78 : previous_percent_(-1), | 78 : previous_percent_(-1), |
79 current_percent_(-1), | 79 current_percent_(-1), |
80 increase_icon_(increase_icon), | 80 increase_icon_(increase_icon), |
81 decrease_icon_(decrease_icon), | 81 decrease_icon_(decrease_icon), |
82 zero_icon_(zero_icon), | 82 disabled_icon_(disabled_icon), |
83 bubble_(NULL), | 83 bubble_(NULL), |
84 view_(NULL), | 84 view_(NULL), |
85 animation_(this) { | 85 animation_(this) { |
86 animation_.SetSlideDuration(kAnimationDurationMs); | 86 animation_.SetSlideDuration(kAnimationDurationMs); |
87 animation_.SetTweenType(ui::Tween::LINEAR); | 87 animation_.SetTweenType(ui::Tween::LINEAR); |
88 } | 88 } |
89 | 89 |
90 SettingLevelBubble::~SettingLevelBubble() {} | 90 SettingLevelBubble::~SettingLevelBubble() {} |
91 | 91 |
92 void SettingLevelBubble::ShowBubble(int percent) { | 92 void SettingLevelBubble::ShowBubble(int percent, bool enabled) { |
93 percent = LimitPercent(percent); | 93 percent = LimitPercent(percent); |
94 if (previous_percent_ == -1) | 94 if (previous_percent_ == -1) |
95 previous_percent_ = percent; | 95 previous_percent_ = percent; |
96 current_percent_ = percent; | 96 current_percent_ = percent; |
97 | 97 |
98 SkBitmap* icon = increase_icon_; | 98 SkBitmap* icon = increase_icon_; |
99 if (current_percent_ == 0) | 99 if (!enabled || current_percent_ == 0) |
100 icon = zero_icon_; | 100 icon = disabled_icon_; |
101 else if (current_percent_ < previous_percent_) | 101 else if (current_percent_ < previous_percent_) |
102 icon = decrease_icon_; | 102 icon = decrease_icon_; |
103 | 103 |
104 if (!bubble_) { | 104 if (!bubble_) { |
105 views::Widget* parent_widget = GetToplevelWidget(); | 105 views::Widget* parent_widget = GetToplevelWidget(); |
106 if (parent_widget == NULL) { | 106 if (parent_widget == NULL) { |
107 LOG(WARNING) << "Unable to locate parent widget to display a bubble"; | 107 LOG(WARNING) << "Unable to locate parent widget to display a bubble"; |
108 return; | 108 return; |
109 } | 109 } |
110 DCHECK(view_ == NULL); | 110 DCHECK(view_ == NULL); |
111 view_ = new SettingLevelBubbleView; | 111 view_ = new SettingLevelBubbleView; |
112 view_->Init(icon, previous_percent_); | 112 view_->Init(icon, previous_percent_, enabled); |
113 | 113 |
114 // Calculate the position in screen coordinates that the bubble should | 114 // Calculate the position in screen coordinates that the bubble should |
115 // "point" at (since we use BubbleBorder::FLOAT, this position actually | 115 // "point" at (since we use BubbleBorder::FLOAT, this position actually |
116 // specifies the center of the bubble). | 116 // specifies the center of the bubble). |
117 const gfx::Rect monitor_area = | 117 const gfx::Rect monitor_area = |
118 gfx::Screen::GetMonitorAreaNearestWindow( | 118 gfx::Screen::GetMonitorAreaNearestWindow( |
119 GTK_WIDGET(parent_widget->GetNativeWindow())); | 119 GTK_WIDGET(parent_widget->GetNativeWindow())); |
120 const gfx::Size view_size = view_->GetPreferredSize(); | 120 const gfx::Size view_size = view_->GetPreferredSize(); |
121 const gfx::Rect position_relative_to( | 121 const gfx::Rect position_relative_to( |
122 monitor_area.x() + kBubbleXRatio * monitor_area.width(), | 122 monitor_area.x() + kBubbleXRatio * monitor_area.width(), |
123 monitor_area.bottom() - view_size.height() / 2 - kBubbleBottomGap, | 123 monitor_area.bottom() - view_size.height() / 2 - kBubbleBottomGap, |
124 0, 0); | 124 0, 0); |
125 | 125 |
126 // ShowFocusless doesn't set ESC accelerator. | 126 // ShowFocusless doesn't set ESC accelerator. |
127 bubble_ = Bubble::ShowFocusless(parent_widget, | 127 bubble_ = Bubble::ShowFocusless(parent_widget, |
128 position_relative_to, | 128 position_relative_to, |
129 BubbleBorder::FLOAT, | 129 BubbleBorder::FLOAT, |
130 view_, // contents | 130 view_, // contents |
131 this, // delegate | 131 this, // delegate |
132 true); // show while screen is locked | 132 true); // show while screen is locked |
133 } else { | 133 } else { |
134 DCHECK(view_); | 134 DCHECK(view_); |
135 timeout_timer_.Stop(); | 135 timeout_timer_.Stop(); |
136 view_->SetIcon(icon); | 136 view_->SetIcon(icon); |
137 } | 137 } |
| 138 |
| 139 view_->SetEnabled(enabled); |
| 140 |
138 if (animation_.is_animating()) | 141 if (animation_.is_animating()) |
139 animation_.End(); | 142 animation_.End(); |
140 animation_.Reset(); | 143 animation_.Reset(); |
141 animation_.Show(); | 144 animation_.Show(); |
| 145 |
142 timeout_timer_.Start(base::TimeDelta::FromSeconds(kBubbleShowTimeoutSec), | 146 timeout_timer_.Start(base::TimeDelta::FromSeconds(kBubbleShowTimeoutSec), |
143 this, &SettingLevelBubble::OnTimeout); | 147 this, &SettingLevelBubble::OnTimeout); |
144 } | 148 } |
145 | 149 |
146 void SettingLevelBubble::HideBubble() { | 150 void SettingLevelBubble::HideBubble() { |
147 if (bubble_) | 151 if (bubble_) |
148 bubble_->Close(); | 152 bubble_->Close(); |
149 } | 153 } |
150 | 154 |
151 void SettingLevelBubble::UpdateWithoutShowingBubble(int percent) { | 155 void SettingLevelBubble::UpdateWithoutShowingBubble(int percent, bool enabled) { |
| 156 if (view_) |
| 157 view_->SetEnabled(enabled); |
| 158 |
152 percent = LimitPercent(percent); | 159 percent = LimitPercent(percent); |
153 | 160 |
154 previous_percent_ = | 161 previous_percent_ = |
155 animation_.is_animating() ? | 162 animation_.is_animating() ? |
156 animation_.GetCurrentValue() : | 163 animation_.GetCurrentValue() : |
157 current_percent_; | 164 current_percent_; |
158 if (previous_percent_ < 0) | 165 if (previous_percent_ < 0) |
159 previous_percent_ = percent; | 166 previous_percent_ = percent; |
160 current_percent_ = percent; | 167 current_percent_ = percent; |
161 | 168 |
(...skipping 22 matching lines...) Expand all Loading... |
184 bool SettingLevelBubble::FadeInOnShow() { | 191 bool SettingLevelBubble::FadeInOnShow() { |
185 return false; | 192 return false; |
186 } | 193 } |
187 | 194 |
188 void SettingLevelBubble::AnimationEnded(const ui::Animation* animation) { | 195 void SettingLevelBubble::AnimationEnded(const ui::Animation* animation) { |
189 previous_percent_ = current_percent_; | 196 previous_percent_ = current_percent_; |
190 } | 197 } |
191 | 198 |
192 void SettingLevelBubble::AnimationProgressed(const ui::Animation* animation) { | 199 void SettingLevelBubble::AnimationProgressed(const ui::Animation* animation) { |
193 if (view_) { | 200 if (view_) { |
194 view_->Update( | 201 view_->SetLevel( |
195 ui::Tween::ValueBetween(animation->GetCurrentValue(), | 202 ui::Tween::ValueBetween(animation->GetCurrentValue(), |
196 previous_percent_, | 203 previous_percent_, |
197 current_percent_)); | 204 current_percent_)); |
198 } | 205 } |
199 } | 206 } |
200 | 207 |
201 } // namespace chromeos | 208 } // namespace chromeos |
OLD | NEW |