| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 views::RootView* root = | 48 views::RootView* root = |
| 49 views::Widget::FindRootView( | 49 views::Widget::FindRootView( |
| 50 GTK_WINDOW(browser->window()->GetNativeHandle())); | 50 GTK_WINDOW(browser->window()->GetNativeHandle())); |
| 51 DCHECK(root); | 51 DCHECK(root); |
| 52 if (!root) | 52 if (!root) |
| 53 return NULL; | 53 return NULL; |
| 54 | 54 |
| 55 return root->GetWidget(); | 55 return root->GetWidget(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 SettingLevelBubble::SettingLevelBubble(SkBitmap* icon) | 58 SettingLevelBubble::SettingLevelBubble(SkBitmap* increase_icon, |
| 59 SkBitmap* decrease_icon, |
| 60 SkBitmap* zero_icon) |
| 59 : previous_percent_(-1), | 61 : previous_percent_(-1), |
| 60 current_percent_(-1), | 62 current_percent_(-1), |
| 61 icon_(icon), | 63 increase_icon_(increase_icon), |
| 64 decrease_icon_(decrease_icon), |
| 65 zero_icon_(zero_icon), |
| 62 bubble_(NULL), | 66 bubble_(NULL), |
| 63 view_(NULL), | 67 view_(NULL), |
| 64 animation_(this) { | 68 animation_(this) { |
| 65 animation_.SetSlideDuration(kAnimationDurationMs); | 69 animation_.SetSlideDuration(kAnimationDurationMs); |
| 66 animation_.SetTweenType(Tween::LINEAR); | 70 animation_.SetTweenType(Tween::LINEAR); |
| 67 } | 71 } |
| 68 | 72 |
| 69 void SettingLevelBubble::ShowBubble(int percent) { | 73 void SettingLevelBubble::ShowBubble(int percent) { |
| 70 if (percent < 0) | 74 if (percent < 0) |
| 71 percent = 0; | 75 percent = 0; |
| 72 if (percent > 100) | 76 if (percent > 100) |
| 73 percent = 100; | 77 percent = 100; |
| 74 if (previous_percent_ == -1) | 78 if (previous_percent_ == -1) |
| 75 previous_percent_ = percent; | 79 previous_percent_ = percent; |
| 76 current_percent_ = percent; | 80 current_percent_ = percent; |
| 81 |
| 82 SkBitmap* icon = increase_icon_; |
| 83 if (current_percent_ == 0) |
| 84 icon = zero_icon_; |
| 85 else if (current_percent_ < previous_percent_) |
| 86 icon = decrease_icon_; |
| 87 |
| 77 if (!bubble_) { | 88 if (!bubble_) { |
| 78 views::Widget* widget = GetToplevelWidget(); | 89 views::Widget* widget = GetToplevelWidget(); |
| 79 if (widget == NULL) | 90 if (widget == NULL) |
| 80 return; | 91 return; |
| 81 DCHECK(view_ == NULL); | 92 DCHECK(view_ == NULL); |
| 82 view_ = new SettingLevelBubbleView; | 93 view_ = new SettingLevelBubbleView; |
| 83 view_->Init(icon_, previous_percent_); | 94 view_->Init(icon, previous_percent_); |
| 84 // Calculate position of the bubble. | 95 // Calculate position of the bubble. |
| 85 gfx::Rect bounds; | 96 gfx::Rect bounds; |
| 86 widget->GetBounds(&bounds, false); | 97 widget->GetBounds(&bounds, false); |
| 87 const gfx::Size view_size = view_->GetPreferredSize(); | 98 const gfx::Size view_size = view_->GetPreferredSize(); |
| 88 // Note that (x, y) is the point of the center of the bubble. | 99 // Note that (x, y) is the point of the center of the bubble. |
| 89 const int x = view_size.width() / 2 + | 100 const int x = view_size.width() / 2 + |
| 90 kBubbleXRatio * (bounds.width() - view_size.width()); | 101 kBubbleXRatio * (bounds.width() - view_size.width()); |
| 91 const int y = bounds.height() - view_size.height() / 2 - kBubbleBottomGap; | 102 const int y = bounds.height() - view_size.height() / 2 - kBubbleBottomGap; |
| 92 bubble_ = InfoBubble::ShowFocusless(widget, gfx::Rect(x, y, 0, 20), | 103 bubble_ = InfoBubble::ShowFocusless(widget, gfx::Rect(x, y, 0, 20), |
| 93 BubbleBorder::FLOAT, view_, this); | 104 BubbleBorder::FLOAT, view_, this); |
| 94 } else { | 105 } else { |
| 95 DCHECK(view_); | 106 DCHECK(view_); |
| 96 timeout_timer_.Stop(); | 107 timeout_timer_.Stop(); |
| 108 view_->SetIcon(icon); |
| 97 } | 109 } |
| 98 if (animation_.is_animating()) | 110 if (animation_.is_animating()) |
| 99 animation_.End(); | 111 animation_.End(); |
| 100 animation_.Reset(); | 112 animation_.Reset(); |
| 101 animation_.Show(); | 113 animation_.Show(); |
| 102 timeout_timer_.Start(base::TimeDelta::FromSeconds(kBubbleShowTimeoutSec), | 114 timeout_timer_.Start(base::TimeDelta::FromSeconds(kBubbleShowTimeoutSec), |
| 103 this, &SettingLevelBubble::OnTimeout); | 115 this, &SettingLevelBubble::OnTimeout); |
| 104 } | 116 } |
| 105 | 117 |
| 106 void SettingLevelBubble::OnTimeout() { | 118 void SettingLevelBubble::OnTimeout() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 123 void SettingLevelBubble::AnimationProgressed(const Animation* animation) { | 135 void SettingLevelBubble::AnimationProgressed(const Animation* animation) { |
| 124 if (view_) { | 136 if (view_) { |
| 125 view_->Update( | 137 view_->Update( |
| 126 Tween::ValueBetween(animation->GetCurrentValue(), | 138 Tween::ValueBetween(animation->GetCurrentValue(), |
| 127 previous_percent_, | 139 previous_percent_, |
| 128 current_percent_)); | 140 current_percent_)); |
| 129 } | 141 } |
| 130 } | 142 } |
| 131 | 143 |
| 132 } // namespace chromeos | 144 } // namespace chromeos |
| OLD | NEW |