diff options
author | alicet@chromium.org <alicet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-28 23:21:52 +0000 |
---|---|---|
committer | alicet@chromium.org <alicet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-28 23:21:52 +0000 |
commit | 0bfff1df077e9ab9ad9be9bb877a360ea4f2f925 (patch) | |
tree | 629499954ccb6b349f90bcee9fcdf4081de0cade | |
parent | dc44a0b461217eab1e90a2ec6baa744cb67a9d27 (diff) | |
download | chromium_src-0bfff1df077e9ab9ad9be9bb877a360ea4f2f925.zip chromium_src-0bfff1df077e9ab9ad9be9bb877a360ea4f2f925.tar.gz chromium_src-0bfff1df077e9ab9ad9be9bb877a360ea4f2f925.tar.bz2 |
aura: brightness and volume bubble.
BUG=98322
TEST=None
Review URL: http://codereview.chromium.org/8319008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107821 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/brightness_bubble_browsertest.cc | 33 | ||||
-rw-r--r-- | chrome/browser/chromeos/setting_level_bubble.cc | 205 | ||||
-rw-r--r-- | chrome/browser/chromeos/setting_level_bubble.h | 34 | ||||
-rw-r--r-- | chrome/browser/chromeos/setting_level_bubble_browsertest.cc | 89 | ||||
-rw-r--r-- | chrome/browser/chromeos/setting_level_bubble_view.cc | 4 | ||||
-rw-r--r-- | chrome/browser/chromeos/setting_level_bubble_view.h | 4 | ||||
-rw-r--r-- | chrome/browser/chromeos/volume_bubble_browsertest.cc | 30 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 3 | ||||
-rw-r--r-- | views/bubble/bubble_delegate.cc | 12 | ||||
-rw-r--r-- | views/bubble/bubble_delegate.h | 7 |
10 files changed, 327 insertions, 94 deletions
diff --git a/chrome/browser/chromeos/brightness_bubble_browsertest.cc b/chrome/browser/chromeos/brightness_bubble_browsertest.cc new file mode 100644 index 0000000..21e3e36 --- /dev/null +++ b/chrome/browser/chromeos/brightness_bubble_browsertest.cc @@ -0,0 +1,33 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/message_loop.h" +#include "chrome/browser/chromeos/brightness_bubble.h" +#include "chrome/browser/chromeos/setting_level_bubble_view.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "views/view.h" + +typedef InProcessBrowserTest BrightnessBubbleTest; + +namespace chromeos { + +IN_PROC_BROWSER_TEST_F(BrightnessBubbleTest, UpdateWithoutShowing) { + BrightnessBubble* bubble = BrightnessBubble::GetInstance(); + bubble->UpdateWithoutShowingBubble(20, false); + EXPECT_EQ(NULL, bubble->view_); + EXPECT_EQ(20, bubble->current_percent_); + bubble->UpdateWithoutShowingBubble(30, false); + EXPECT_EQ(NULL, bubble->view_); + EXPECT_EQ(20, bubble->current_percent_); + EXPECT_EQ(30, bubble->target_percent_); + bubble->UpdateWithoutShowingBubble(40, false); + EXPECT_EQ(NULL, bubble->view_); + EXPECT_EQ(40, bubble->target_percent_); + bubble->ShowBubble(50, true); + EXPECT_TRUE(bubble->view_->GetWidget()->IsVisible()); + EXPECT_EQ(50, bubble->target_percent_); + MessageLoop::current()->RunAllPending(); +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/setting_level_bubble.cc b/chrome/browser/chromeos/setting_level_bubble.cc index c546f88..0db0b7c 100644 --- a/chrome/browser/chromeos/setting_level_bubble.cc +++ b/chrome/browser/chromeos/setting_level_bubble.cc @@ -14,8 +14,9 @@ #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/layout/fill_layout.h" #include "views/widget/root_view.h" using base::TimeDelta; @@ -84,80 +85,101 @@ static views::Widget* GetToplevelWidget() { return WebUILoginDisplay::GetLoginWindow(); } -SettingLevelBubble::SettingLevelBubble(SkBitmap* increase_icon, - SkBitmap* decrease_icon, - SkBitmap* disabled_icon) - : current_percent_(-1.0), - target_percent_(-1.0), - increase_icon_(increase_icon), - decrease_icon_(decrease_icon), - disabled_icon_(disabled_icon), - bubble_(NULL), - view_(NULL), - is_animating_(false) { +// SettingLevelBubbleDelegateView ---------------------------------------------- +class SettingLevelBubbleDelegateView : public views::BubbleDelegateView { + public: + // BubbleDelegate overrides: + virtual gfx::Point GetAnchorPoint() OVERRIDE; + + // Create the bubble delegate view. + explicit SettingLevelBubbleDelegateView(views::Widget* parent); + virtual ~SettingLevelBubbleDelegateView(); + + SettingLevelBubbleView* view() { return view_; } + + protected: + // BubbleDelegate overrides: + virtual void Init() OVERRIDE; + + private: + views::Widget* parent_; + + SettingLevelBubbleView* view_; + + DISALLOW_COPY_AND_ASSIGN(SettingLevelBubbleDelegateView); +}; + +gfx::Point SettingLevelBubbleDelegateView::GetAnchorPoint() { + gfx::Size view_size = GetPreferredSize(); + // 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). + gfx::Rect monitor_area = + gfx::Screen::GetMonitorAreaNearestWindow( + parent_->GetNativeView()); + return (gfx::Point( + monitor_area.x() + kBubbleXRatio * monitor_area.width(), + monitor_area.bottom() - view_size.height() / 2 - kBubbleBottomGap)); } -SettingLevelBubble::~SettingLevelBubble() {} +SettingLevelBubbleDelegateView::SettingLevelBubbleDelegateView( + views::Widget* parent) + : BubbleDelegateView(gfx::Point(), + views::BubbleBorder::FLOAT, + SK_ColorWHITE), + parent_(parent), + view_(NULL) { + set_close_on_esc(false); +} + +SettingLevelBubbleDelegateView::~SettingLevelBubbleDelegateView() { + view_ = NULL; +} +void SettingLevelBubbleDelegateView::Init() { + SetLayoutManager(new views::FillLayout()); + view_ = new SettingLevelBubbleView(); + AddChildView(view_); +} + +// SettingLevelBubble ---------------------------------------------------------- void SettingLevelBubble::ShowBubble(double percent, bool enabled) { + hide_timer_.Stop(); + + // Set up target percent and icon. const double old_target_percent = target_percent_; UpdateTargetPercent(percent); - - SkBitmap* icon = increase_icon_; + SkBitmap* 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_; + current_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. + if (!view_) { + view_ = CreateView(); + view_->Init(current_icon, percent, enabled); } else { - DCHECK(view_); - hide_timer_.Stop(); - view_->SetIcon(icon); + // Reset fade sequence, if the bubble is already fading. + SettingLevelBubbleDelegateView* delegate = + static_cast<SettingLevelBubbleDelegateView*> + (view_->GetWidget()->widget_delegate()); + delegate->ResetFade(); + view_->SetIcon(current_icon); view_->SetEnabled(enabled); } - + view_->GetWidget()->Show(); + // When the timer runs out, start the fade sequence. hide_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kBubbleShowTimeoutMs), this, &SettingLevelBubble::OnHideTimeout); } void SettingLevelBubble::HideBubble() { - if (bubble_) - bubble_->Close(); + hide_timer_.Stop(); + if (view_) { + view_->GetWidget()->Close(); + view_ = NULL; + } } void SettingLevelBubble::UpdateWithoutShowingBubble(double percent, @@ -167,8 +189,55 @@ void SettingLevelBubble::UpdateWithoutShowingBubble(double percent, view_->SetEnabled(enabled); } +SettingLevelBubble::SettingLevelBubble(SkBitmap* increase_icon, + SkBitmap* decrease_icon, + SkBitmap* disabled_icon) + : current_percent_(-1.0), + target_percent_(-1.0), + increase_icon_(increase_icon), + decrease_icon_(decrease_icon), + disabled_icon_(disabled_icon), + view_(NULL), + is_animating_(false) { +} + +SettingLevelBubble::~SettingLevelBubble() { + view_ = NULL; +} + +void SettingLevelBubble::OnWidgetClosing(views::Widget* widget) { + if (view_ && view_->GetWidget() == widget) { + view_->GetWidget()->RemoveObserver(this); + view_ = NULL; + } + // Update states. + current_percent_ = target_percent_; + target_time_ = TimeTicks(); + last_animation_update_time_ = TimeTicks(); + last_target_update_time_ = TimeTicks(); + hide_timer_.Stop(); + StopAnimation(); +} + +SettingLevelBubbleView* SettingLevelBubble::CreateView() { + views::Widget* parent = GetToplevelWidget(); + SettingLevelBubbleDelegateView* delegate = + new SettingLevelBubbleDelegateView(parent); + views::Widget* widget = + views::BubbleDelegateView::CreateBubble(delegate, parent); + widget->AddObserver(this); + // Hold on to the content view. + return delegate->view(); +} + void SettingLevelBubble::OnHideTimeout() { - HideBubble(); + // Start fading away. + if (view_) { + SettingLevelBubbleDelegateView* delegate = + static_cast<SettingLevelBubbleDelegateView*> + (view_->GetWidget()->widget_delegate()); + delegate->StartFade(false); + } } void SettingLevelBubble::OnAnimationTimeout() { @@ -194,26 +263,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(); diff --git a/chrome/browser/chromeos/setting_level_bubble.h b/chrome/browser/chromeos/setting_level_bubble.h index 6496dde..d775161 100644 --- a/chrome/browser/chromeos/setting_level_bubble.h +++ b/chrome/browser/chromeos/setting_level_bubble.h @@ -7,9 +7,11 @@ #pragma once #include "base/basictypes.h" +#include "base/gtest_prod_util.h" #include "base/time.h" #include "base/timer.h" -#include "chrome/browser/ui/views/bubble/bubble.h" +#include "views/bubble/bubble_delegate.h" +#include "views/widget/widget.h" class SkBitmap; @@ -17,12 +19,15 @@ namespace chromeos { class SettingLevelBubbleView; -// Singleton class controlling a bubble displaying a level-based setting like +// Controls a bubble displaying a level-based setting like // volume or brightness. -class SettingLevelBubble : public BubbleDelegate { +class SettingLevelBubble : public views::Widget::Observer { public: - // Shows the bubble. |percent| should be in the range [0.0, 100.0]. + // Shows the bubble with the target |percent| and |enabled| setting. + // |percent| should be in the range [0.0, 100.0]. void ShowBubble(double percent, bool enabled); + + // Hides the Bubble, closing the view. void HideBubble(); // Updates the bubble's current level without showing the bubble onscreen. @@ -46,15 +51,23 @@ class SettingLevelBubble : public BubbleDelegate { SettingLevelBubble(SkBitmap* increase_icon, SkBitmap* decrease_icon, SkBitmap* zero_icon); + virtual ~SettingLevelBubble(); private: - // Overridden from BubbleDelegate. - virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE; - virtual bool CloseOnEscape() OVERRIDE; - virtual bool FadeInOnShow() OVERRIDE; + FRIEND_TEST_ALL_PREFIXES(SettingLevelBubbleTest, CreateAndUpdate); + FRIEND_TEST_ALL_PREFIXES(SettingLevelBubbleTest, ShowBubble); + FRIEND_TEST_ALL_PREFIXES(BrightnessBubbleTest, UpdateWithoutShowing); + FRIEND_TEST_ALL_PREFIXES(VolumeBubbleTest, GetInstanceAndShow); + + // views::Widget::Observer overrides: + void OnWidgetClosing(views::Widget* widget) OVERRIDE; - // Callback for |hide_timer_|. Closes the bubble. + // Creates the bubble content view. + // Caller should call Init() on the returned SettingLevelBubbleView. + SettingLevelBubbleView* CreateView(); + + // Callback for |hide_timer_|. Starts fading out. void OnHideTimeout(); // Callback for |animation_timer_|. Updates the level displayed by the view, @@ -90,9 +103,6 @@ class SettingLevelBubble : public BubbleDelegate { SkBitmap* decrease_icon_; SkBitmap* disabled_icon_; - // Currently shown bubble or NULL. - Bubble* bubble_; - // Contents view owned by Bubble. SettingLevelBubbleView* view_; diff --git a/chrome/browser/chromeos/setting_level_bubble_browsertest.cc b/chrome/browser/chromeos/setting_level_bubble_browsertest.cc new file mode 100644 index 0000000..eac3906 --- /dev/null +++ b/chrome/browser/chromeos/setting_level_bubble_browsertest.cc @@ -0,0 +1,89 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/message_loop.h" +#include "chrome/browser/chromeos/setting_level_bubble.h" +#include "chrome/browser/chromeos/setting_level_bubble_view.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "views/controls/progress_bar.h" +#include "views/view.h" + + +class SettingLevelBubbleTest : public InProcessBrowserTest { + public: + SettingLevelBubbleTest() { + up_icon_.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); + down_icon_.setConfig(SkBitmap::kARGB_8888_Config, 5, 5); + mute_icon_.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); + } + + virtual ~SettingLevelBubbleTest() {} + + protected: + SkBitmap up_icon_; + SkBitmap down_icon_; + SkBitmap mute_icon_; + + private: + DISALLOW_COPY_AND_ASSIGN(SettingLevelBubbleTest); +}; + +namespace chromeos { + +IN_PROC_BROWSER_TEST_F(SettingLevelBubbleTest, CreateAndUpdate) { + SettingLevelBubble bubble(&up_icon_, + &down_icon_, + &mute_icon_); + EXPECT_EQ(NULL, bubble.view_); + EXPECT_EQ(&up_icon_, bubble.increase_icon_); + EXPECT_EQ(&down_icon_, bubble.decrease_icon_); + EXPECT_EQ(&mute_icon_, bubble.disabled_icon_); + + // Update setting: + // Old target is 50, new target is 70, set enable = false. + bubble.ShowBubble(70, false); + EXPECT_TRUE(bubble.view_->GetWidget()->IsVisible()); + EXPECT_EQ(&mute_icon_, bubble.view_->icon_); + EXPECT_FALSE(bubble.view_->progress_bar_->IsEnabled()); + + // Old target is 70, new target is 30, set enable = true. + bubble.ShowBubble(30, true); + EXPECT_EQ(&down_icon_, bubble.view_->icon_); + EXPECT_TRUE(bubble.view_->progress_bar_->IsEnabled()); + + // Old target is 30, new target is 40, set enable = true. + bubble.ShowBubble(30, true); + EXPECT_EQ(&up_icon_, bubble.view_->icon_); + EXPECT_TRUE(bubble.view_->progress_bar_->IsEnabled()); + + // Old target is 30, new target is 0, set enable = true. + bubble.ShowBubble(0, true); + EXPECT_EQ(&mute_icon_, bubble.view_->icon_); + EXPECT_TRUE(bubble.view_->progress_bar_->IsEnabled()); + bubble.HideBubble(); + MessageLoop::current()->RunAllPending(); +} + +IN_PROC_BROWSER_TEST_F(SettingLevelBubbleTest, ShowBubble) { + // Create setting at 30 percent, enabled. + SettingLevelBubble bubble(&up_icon_, + &down_icon_, + &mute_icon_); + bubble.UpdateWithoutShowingBubble(30, false); + EXPECT_EQ(NULL, bubble.view_); + EXPECT_EQ(30, bubble.current_percent_); + + // Show bubble at 40 percent, enabled. + bubble.ShowBubble(40, true); + EXPECT_TRUE(bubble.view_ != NULL); + EXPECT_TRUE(bubble.view_->GetWidget()->IsVisible()); + + // Update to 0 percent and close. + bubble.UpdateWithoutShowingBubble(0, true); + bubble.OnWidgetClosing(bubble.view_->GetWidget()); + EXPECT_EQ(0, bubble.current_percent_); +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/setting_level_bubble_view.cc b/chrome/browser/chromeos/setting_level_bubble_view.cc index 5f4ae7c..145471c 100644 --- a/chrome/browser/chromeos/setting_level_bubble_view.cc +++ b/chrome/browser/chromeos/setting_level_bubble_view.cc @@ -28,14 +28,14 @@ const int kProgressBarHeight = 17; namespace chromeos { SettingLevelBubbleView::SettingLevelBubbleView() - : progress_bar_(NULL), + : progress_bar_(new views::ProgressBar()), icon_(NULL) { } void SettingLevelBubbleView::Init(SkBitmap* icon, double level, bool enabled) { + DCHECK(!icon_); DCHECK(icon); icon_ = icon; - progress_bar_ = new views::ProgressBar(); AddChildView(progress_bar_); progress_bar_->SetDisplayRange(0.0, 100.0); progress_bar_->EnableCanvasFlippingForRTLUI(true); diff --git a/chrome/browser/chromeos/setting_level_bubble_view.h b/chrome/browser/chromeos/setting_level_bubble_view.h index f118cac..4904abe 100644 --- a/chrome/browser/chromeos/setting_level_bubble_view.h +++ b/chrome/browser/chromeos/setting_level_bubble_view.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_VIEW_H_ #pragma once +#include "base/gtest_prod_util.h" #include "views/view.h" namespace views { @@ -20,6 +21,7 @@ namespace chromeos { // level-based setting like volume or brightness. class SettingLevelBubbleView : public views::View { public: + // Layout() is called before Init(), make sure |progress_bar_| is ready. SettingLevelBubbleView(); // Initialize the view, setting the progress bar to the specified level in the @@ -42,6 +44,8 @@ class SettingLevelBubbleView : public views::View { virtual gfx::Size GetPreferredSize() OVERRIDE; private: + FRIEND_TEST_ALL_PREFIXES(SettingLevelBubbleTest, CreateAndUpdate); + views::ProgressBar* progress_bar_; SkBitmap* icon_; // not owned diff --git a/chrome/browser/chromeos/volume_bubble_browsertest.cc b/chrome/browser/chromeos/volume_bubble_browsertest.cc new file mode 100644 index 0000000..cbe6178 --- /dev/null +++ b/chrome/browser/chromeos/volume_bubble_browsertest.cc @@ -0,0 +1,30 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/volume_bubble.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "chrome/browser/chromeos/setting_level_bubble_view.h" +#include "views/view.h" + +typedef InProcessBrowserTest VolumeBubbleTest; + +namespace chromeos { + +IN_PROC_BROWSER_TEST_F(VolumeBubbleTest, GetInstanceAndShow) { + VolumeBubble* bubble1 = VolumeBubble::GetInstance(); + VolumeBubble* bubble2 = VolumeBubble::GetInstance(); + ASSERT_EQ(bubble1, bubble2); + + bubble1->ShowBubble(20, true); + EXPECT_TRUE(bubble1->view_ != NULL); + EXPECT_TRUE(bubble1->view_->IsVisible()); + views::View* saved_view = bubble1->view_; + bubble1->HideBubble(); + EXPECT_EQ(NULL, bubble1->view_); + bubble1->ShowBubble(20, true); + EXPECT_TRUE(bubble1->view_ != NULL); + EXPECT_NE(saved_view, bubble1->view_); +} + +} // namespace chromeos diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 1b7354c..e41b34d 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2314,6 +2314,7 @@ 'browser/browsing_data_helper_browsertest.h', 'browser/browsing_data_indexed_db_helper_browsertest.cc', 'browser/browsing_data_local_storage_helper_browsertest.cc', + 'browser/chromeos/brightness_bubble_browsertest.cc', 'browser/chromeos/cros/cros_in_process_browser_test.cc', 'browser/chromeos/cros/cros_in_process_browser_test.h', 'browser/chromeos/cros/cros_mock.cc', @@ -2359,7 +2360,9 @@ 'browser/chromeos/status/input_method_menu_button_browsertest.cc', 'browser/chromeos/status/power_menu_button_browsertest.cc', 'browser/chromeos/status/status_area_view_browsertest.cc', + 'browser/chromeos/setting_level_bubble_browsertest.cc', 'browser/chromeos/tab_closeable_state_watcher_browsertest.cc', + 'browser/chromeos/volume_bubble_browsertest.cc', 'browser/content_settings/content_settings_browsertest.cc', 'browser/crash_recovery_browsertest.cc', 'browser/custom_handlers/protocol_handler_registry_browsertest.cc', diff --git a/views/bubble/bubble_delegate.cc b/views/bubble/bubble_delegate.cc index b46e353..1fb7ebf 100644 --- a/views/bubble/bubble_delegate.cc +++ b/views/bubble/bubble_delegate.cc @@ -29,7 +29,8 @@ BubbleDelegateView::BubbleDelegateView( close_on_esc_(true), anchor_point_(anchor_point), arrow_location_(arrow_location), - color_(color) { + color_(color), + original_opacity_(255) { AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); } @@ -88,14 +89,21 @@ void BubbleDelegateView::StartFade(bool fade_in) { fade_animation_->SetSlideDuration(kHideFadeDurationMS); fade_animation_->Reset(fade_in ? 0.0 : 1.0); if (fade_in) { - GetWidget()->SetOpacity(0); + original_opacity_ = 0; + GetWidget()->SetOpacity(original_opacity_); GetWidget()->Show(); fade_animation_->Show(); } else { + original_opacity_ = 255; fade_animation_->Hide(); } } +void BubbleDelegateView::ResetFade() { + fade_animation_.reset(); + GetWidget()->SetOpacity(original_opacity_); +} + bool BubbleDelegateView::AcceleratorPressed(const Accelerator& accelerator) { if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) return false; diff --git a/views/bubble/bubble_delegate.h b/views/bubble/bubble_delegate.h index 8bd0322..929f619 100644 --- a/views/bubble/bubble_delegate.h +++ b/views/bubble/bubble_delegate.h @@ -58,6 +58,10 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView, // Fade in calls Widget::Show; fade out calls Widget::Close upon completion. void StartFade(bool fade_in); + // Reset fade and opacity of bubble. Restore the opacity of the + // bubble to the setting before StartFade() was called. + void ResetFade(); + protected: // View overrides: virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE; @@ -90,6 +94,9 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView, // The background color of the bubble. SkColor color_; + + // Original opacity of the bubble. + int original_opacity_; }; } // namespace views |