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

Unified Diff: chrome/browser/chromeos/setting_level_bubble.cc

Issue 8319008: aura: brightness and volume bubble. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: updates Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
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 c546f88455987beeed36cab168edef82d1719c95..3c04fa19bd3d2d87580f3a4af2aa5642165c20f5 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"
msw 2011/10/20 19:36:13 Merge and remove bubble_view.h soon.
alicet1 2011/10/20 22:36:30 Done.
+#include "views/layout/fill_layout.h"
#include "views/widget/root_view.h"
using base::TimeDelta;
@@ -84,6 +86,24 @@ static views::Widget* GetToplevelWidget() {
return WebUILoginDisplay::GetLoginWindow();
}
+// static
+views::Widget* SettingLevelBubble::CreateSettingLevelBubble(
+ 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->UpdateSetting(percent, enabled);
+ // Construct and initialize settings.
+ views::Widget* widget = views::BubbleDelegateView::CreateBubble(
+ delegate, parent);
+ widget->client_view()->AsBubbleView()->set_close_on_esc(false);
msw 2011/10/20 19:36:13 Merge for BubbleDelegateView::set_close_on_esc
alicet1 2011/10/20 22:36:30 Done.
+ return widget;
+}
+
SettingLevelBubble::SettingLevelBubble(SkBitmap* increase_icon,
SkBitmap* decrease_icon,
SkBitmap* disabled_icon)
@@ -92,72 +112,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();
msw 2011/10/20 19:36:13 This shouldn't be necessary.
alicet1 2011/10/20 22:36:30 Done.
+}
+
+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();
msw 2011/10/20 19:36:13 I wonder if you can calculate the anchor point ear
alicet1 2011/10/20 22:36:30 yeah, I need the view first.
+ AddChildView(view_);
+}
+
+gfx::Point SettingLevelBubble::GetAnchorPoint() const {
+ return anchor_point_;
+}
-void SettingLevelBubble::ShowBubble(double percent, bool enabled) {
+void SettingLevelBubble::UpdateSetting(double percent,
+ bool enabled) {
msw 2011/10/20 19:36:13 This fits on one line.
alicet1 2011/10/20 22:36:30 Done.
+ 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,
@@ -167,8 +175,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() {
@@ -194,26 +215,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();

Powered by Google App Engine
This is Rietveld 408576698