Chromium Code Reviews| Index: chrome/browser/chromeos/setting_level_bubble.cc |
| diff --git a/chrome/browser/chromeos/setting_level_bubble.cc b/chrome/browser/chromeos/setting_level_bubble.cc |
| index bb8df2362e4adcf2320bb95217fb29f28b764efb..c89d62d1239dc1829c85b4f6be42d18b4c0c8c64 100644 |
| --- a/chrome/browser/chromeos/setting_level_bubble.cc |
| +++ b/chrome/browser/chromeos/setting_level_bubble.cc |
| @@ -14,8 +14,10 @@ |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_list.h" |
| #include "chrome/browser/ui/browser_window.h" |
| -#include "chrome/browser/ui/views/bubble/bubble.h" |
| #include "ui/gfx/screen.h" |
| +#include "views/bubble/bubble_delegate.h" |
| +#include "views/bubble/bubble_view.h" |
| +#include "views/layout/fill_layout.h" |
| #include "views/widget/root_view.h" |
| using base::TimeDelta; |
| @@ -59,6 +61,7 @@ namespace chromeos { |
| static views::Widget* GetToplevelWidget() { |
| #if defined(USE_AURA) |
| // TODO(saintlou): Need to fix in PureViews. |
| + // Is this the same as using parent->GetRootView()? |
|
Daniel Erat
2011/10/19 17:28:09
yeah, i think that the root view is what we want h
alicet1
2011/10/20 15:03:08
saintlou uploaded a fix to this code. let me know
|
| return WebUILoginDisplay::GetLoginWindow(); |
| #else |
| GtkWindow* window = NULL; |
| @@ -85,6 +88,24 @@ static views::Widget* GetToplevelWidget() { |
| #endif |
| } |
| +// static |
| +views::Widget* SettingLevelBubble::ConstructSettingLevelBubble( |
| + SkBitmap* increase_icon, |
| + SkBitmap* decrease_icon, |
| + SkBitmap* zero_icon, |
| + double percent, |
| + bool enabled) { |
| + views::Widget* parent = GetToplevelWidget(); |
| + SettingLevelBubble* delegate = |
| + new SettingLevelBubble(increase_icon, decrease_icon, zero_icon); |
| + delegate->UpdateSettingLevelInternal(percent, enabled); |
| + // Construct and initialize settings. |
| + views::Widget* widget = views::BubbleDelegateView::CreateBubble( |
| + delegate, parent); |
| + widget->client_view()->AsBubbleView()->set_close_on_esc(false); |
| + return widget; |
| +} |
| + |
| SettingLevelBubble::SettingLevelBubble(SkBitmap* increase_icon, |
| SkBitmap* decrease_icon, |
| SkBitmap* disabled_icon) |
| @@ -93,72 +114,60 @@ SettingLevelBubble::SettingLevelBubble(SkBitmap* increase_icon, |
| increase_icon_(increase_icon), |
| decrease_icon_(decrease_icon), |
| disabled_icon_(disabled_icon), |
| - bubble_(NULL), |
| + current_icon_(NULL), |
| view_(NULL), |
| is_animating_(false) { |
| } |
| -SettingLevelBubble::~SettingLevelBubble() {} |
| +SettingLevelBubble::~SettingLevelBubble() { |
| + WindowClosing(); |
| +} |
| + |
| +void SettingLevelBubble::StartHideTimer() { |
| + hide_timer_.Stop(); |
| + hide_timer_.Start(FROM_HERE, |
| + base::TimeDelta::FromMilliseconds(kBubbleShowTimeoutMs), |
| + this, &SettingLevelBubble::OnHideTimeout); |
| +} |
| + |
| +void SettingLevelBubble::Init() { |
| + SetLayoutManager(new views::FillLayout()); |
| + view_ = new SettingLevelBubbleView(); |
| + |
| + view_->Init(current_icon_, current_percent_, enabled_); |
| + CalculateAnchorPoint(); |
| + AddChildView(view_); |
| +} |
| + |
| +gfx::Point SettingLevelBubble::GetAnchorPoint() const { |
| + return anchor_point_; |
| +} |
| -void SettingLevelBubble::ShowBubble(double percent, bool enabled) { |
| +void SettingLevelBubble::UpdateSettingLevelInternal(double percent, |
| + bool enabled) { |
| + enabled_ = enabled; |
| const double old_target_percent = target_percent_; |
| UpdateTargetPercent(percent); |
| - |
| - SkBitmap* icon = increase_icon_; |
| + current_icon_ = increase_icon_; |
| if (!enabled || target_percent_ == 0) |
| - icon = disabled_icon_; |
| + current_icon_ = disabled_icon_; |
| else if (old_target_percent >= 0 && target_percent_ < old_target_percent) |
| - icon = decrease_icon_; |
| - |
| - if (!bubble_) { |
| - views::Widget* parent_widget = GetToplevelWidget(); |
| - if (parent_widget == NULL) { |
| - LOG(WARNING) << "Unable to locate parent widget to display a bubble"; |
| - return; |
| - } |
| - DCHECK(view_ == NULL); |
| - view_ = new SettingLevelBubbleView; |
| - view_->Init(icon, current_percent_, enabled); |
| - |
| - // Calculate the position in screen coordinates that the bubble should |
| - // "point" at (since we use BubbleBorder::FLOAT, this position actually |
| - // specifies the center of the bubble). |
| - const gfx::Rect monitor_area = |
| - gfx::Screen::GetMonitorAreaNearestWindow( |
| - parent_widget->GetNativeView()); |
| - const gfx::Size view_size = view_->GetPreferredSize(); |
| - const gfx::Rect position_relative_to( |
| - monitor_area.x() + kBubbleXRatio * monitor_area.width(), |
| - monitor_area.bottom() - view_size.height() / 2 - kBubbleBottomGap, |
| - 0, 0); |
| - |
| - bubble_ = Bubble::ShowFocusless(parent_widget, |
| - position_relative_to, |
| - views::BubbleBorder::FLOAT, |
| - view_, // contents |
| - this, // delegate |
| - true); // show while screen is locked |
| - // TODO(derat): We probably shouldn't be using Bubble. It'd be nice to call |
| - // bubble_->set_fade_away_on_close(true) here, but then, if ShowBubble() |
| - // gets called while the bubble is fading away, we end up just adjusting the |
| - // value on the disappearing bubble; ideally we'd have a way to cancel the |
| - // fade and show the bubble at full opacity for another |
| - // kBubbleShowTimeoutMs. |
| - } else { |
| - DCHECK(view_); |
| - hide_timer_.Stop(); |
| - view_->SetIcon(icon); |
| - view_->SetEnabled(enabled); |
| - } |
| + current_icon_ = decrease_icon_; |
| +} |
| - hide_timer_.Start(FROM_HERE, |
| - base::TimeDelta::FromMilliseconds(kBubbleShowTimeoutMs), |
| - this, &SettingLevelBubble::OnHideTimeout); |
| +views::BubbleBorder::ArrowLocation |
| +SettingLevelBubble::GetArrowLocation() const { |
| + return views::BubbleBorder::FLOAT; |
| } |
| -void SettingLevelBubble::HideBubble() { |
| - if (bubble_) |
| - bubble_->Close(); |
| +void SettingLevelBubble::WindowClosing() { |
| + hide_timer_.Stop(); |
| + StopAnimation(); |
| + view_ = NULL; |
| + current_percent_ = target_percent_; |
| + target_time_ = TimeTicks(); |
| + last_animation_update_time_ = TimeTicks(); |
| + last_target_update_time_ = TimeTicks(); |
| } |
| void SettingLevelBubble::UpdateWithoutShowingBubble(double percent, |
| @@ -168,8 +177,21 @@ void SettingLevelBubble::UpdateWithoutShowingBubble(double percent, |
| view_->SetEnabled(enabled); |
| } |
| +void SettingLevelBubble::CalculateAnchorPoint() { |
| + // Calculate the position in screen coordinates that the bubble should |
| + // "point" at (since we use BubbleBorder::FLOAT, this position actually |
| + // specifies the center of the bubble). |
| + const gfx::Rect monitor_area = |
| + gfx::Screen::GetMonitorAreaNearestWindow( |
| + GetWidget()->GetTopLevelWidget()->GetNativeView()); |
| + gfx::Size view_size = GetPreferredSize(); |
| + anchor_point_ = gfx::Point( |
| + monitor_area.x() + kBubbleXRatio * monitor_area.width(), |
| + monitor_area.bottom() - view_size.height() / 2 - kBubbleBottomGap); |
| +} |
| + |
| void SettingLevelBubble::OnHideTimeout() { |
| - HideBubble(); |
| + GetWidget()->Close(); |
| } |
| void SettingLevelBubble::OnAnimationTimeout() { |
| @@ -195,26 +217,6 @@ void SettingLevelBubble::OnAnimationTimeout() { |
| view_->SetLevel(current_percent_); |
| } |
| -void SettingLevelBubble::BubbleClosing(Bubble* bubble, bool) { |
| - DCHECK(bubble == bubble_); |
| - hide_timer_.Stop(); |
| - StopAnimation(); |
| - bubble_ = NULL; |
| - view_ = NULL; |
| - current_percent_ = target_percent_; |
| - target_time_ = TimeTicks(); |
| - last_animation_update_time_ = TimeTicks(); |
| - last_target_update_time_ = TimeTicks(); |
| -} |
| - |
| -bool SettingLevelBubble::CloseOnEscape() { |
| - return true; |
| -} |
| - |
| -bool SettingLevelBubble::FadeInOnShow() { |
| - return false; |
| -} |
| - |
| void SettingLevelBubble::UpdateTargetPercent(double percent) { |
| target_percent_ = LimitPercent(percent); |
| const TimeTicks now = TimeTicks::Now(); |