Commit 0bfff1df authored by alicet@chromium.org's avatar alicet@chromium.org

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
parent dc44a0b4
// 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
...@@ -14,8 +14,9 @@ ...@@ -14,8 +14,9 @@
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/bubble/bubble.h"
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
#include "views/bubble/bubble_delegate.h"
#include "views/layout/fill_layout.h"
#include "views/widget/root_view.h" #include "views/widget/root_view.h"
using base::TimeDelta; using base::TimeDelta;
...@@ -84,80 +85,101 @@ static views::Widget* GetToplevelWidget() { ...@@ -84,80 +85,101 @@ static views::Widget* GetToplevelWidget() {
return WebUILoginDisplay::GetLoginWindow(); return WebUILoginDisplay::GetLoginWindow();
} }
SettingLevelBubble::SettingLevelBubble(SkBitmap* increase_icon, // SettingLevelBubbleDelegateView ----------------------------------------------
SkBitmap* decrease_icon, class SettingLevelBubbleDelegateView : public views::BubbleDelegateView {
SkBitmap* disabled_icon) public:
: current_percent_(-1.0), // BubbleDelegate overrides:
target_percent_(-1.0), virtual gfx::Point GetAnchorPoint() OVERRIDE;
increase_icon_(increase_icon),
decrease_icon_(decrease_icon),
disabled_icon_(disabled_icon),
bubble_(NULL),
view_(NULL),
is_animating_(false) {
}
SettingLevelBubble::~SettingLevelBubble() {} // Create the bubble delegate view.
explicit SettingLevelBubbleDelegateView(views::Widget* parent);
virtual ~SettingLevelBubbleDelegateView();
void SettingLevelBubble::ShowBubble(double percent, bool enabled) { SettingLevelBubbleView* view() { return view_; }
const double old_target_percent = target_percent_;
UpdateTargetPercent(percent);
SkBitmap* icon = increase_icon_; protected:
if (!enabled || target_percent_ == 0) // BubbleDelegate overrides:
icon = disabled_icon_; virtual void Init() OVERRIDE;
else if (old_target_percent >= 0 && target_percent_ < old_target_percent)
icon = decrease_icon_;
if (!bubble_) { private:
views::Widget* parent_widget = GetToplevelWidget(); views::Widget* parent_;
if (parent_widget == NULL) {
LOG(WARNING) << "Unable to locate parent widget to display a bubble"; SettingLevelBubbleView* view_;
return;
} DISALLOW_COPY_AND_ASSIGN(SettingLevelBubbleDelegateView);
DCHECK(view_ == NULL); };
view_ = new SettingLevelBubbleView;
view_->Init(icon, current_percent_, enabled);
gfx::Point SettingLevelBubbleDelegateView::GetAnchorPoint() {
gfx::Size view_size = GetPreferredSize();
// Calculate the position in screen coordinates that the bubble should // Calculate the position in screen coordinates that the bubble should
// "point" at (since we use BubbleBorder::FLOAT, this position actually // "point" at (since we use BubbleBorder::FLOAT, this position actually
// specifies the center of the bubble). // specifies the center of the bubble).
const gfx::Rect monitor_area = gfx::Rect monitor_area =
gfx::Screen::GetMonitorAreaNearestWindow( gfx::Screen::GetMonitorAreaNearestWindow(
parent_widget->GetNativeView()); parent_->GetNativeView());
const gfx::Size view_size = view_->GetPreferredSize(); return (gfx::Point(
const gfx::Rect position_relative_to(
monitor_area.x() + kBubbleXRatio * monitor_area.width(), monitor_area.x() + kBubbleXRatio * monitor_area.width(),
monitor_area.bottom() - view_size.height() / 2 - kBubbleBottomGap, monitor_area.bottom() - view_size.height() / 2 - kBubbleBottomGap));
0, 0); }
bubble_ = Bubble::ShowFocusless(parent_widget, SettingLevelBubbleDelegateView::SettingLevelBubbleDelegateView(
position_relative_to, views::Widget* parent)
: BubbleDelegateView(gfx::Point(),
views::BubbleBorder::FLOAT, views::BubbleBorder::FLOAT,
view_, // contents SK_ColorWHITE),
this, // delegate parent_(parent),
true); // show while screen is locked view_(NULL) {
// TODO(derat): We probably shouldn't be using Bubble. It'd be nice to call set_close_on_esc(false);
// 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 SettingLevelBubbleDelegateView::~SettingLevelBubbleDelegateView() {
// fade and show the bubble at full opacity for another view_ = NULL;
// kBubbleShowTimeoutMs. }
} else {
DCHECK(view_); void SettingLevelBubbleDelegateView::Init() {
SetLayoutManager(new views::FillLayout());
view_ = new SettingLevelBubbleView();
AddChildView(view_);
}
// SettingLevelBubble ----------------------------------------------------------
void SettingLevelBubble::ShowBubble(double percent, bool enabled) {
hide_timer_.Stop(); hide_timer_.Stop();
view_->SetIcon(icon);
// Set up target percent and icon.
const double old_target_percent = target_percent_;
UpdateTargetPercent(percent);
SkBitmap* current_icon = increase_icon_;
if (!enabled || target_percent_ == 0)
current_icon = disabled_icon_;
else if (old_target_percent >= 0 && target_percent_ < old_target_percent)
current_icon = decrease_icon_;
if (!view_) {
view_ = CreateView();
view_->Init(current_icon, percent, enabled);
} else {
// 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_->SetEnabled(enabled);
} }
view_->GetWidget()->Show();
// When the timer runs out, start the fade sequence.
hide_timer_.Start(FROM_HERE, hide_timer_.Start(FROM_HERE,
base::TimeDelta::FromMilliseconds(kBubbleShowTimeoutMs), base::TimeDelta::FromMilliseconds(kBubbleShowTimeoutMs),
this, &SettingLevelBubble::OnHideTimeout); this, &SettingLevelBubble::OnHideTimeout);
} }
void SettingLevelBubble::HideBubble() { void SettingLevelBubble::HideBubble() {
if (bubble_) hide_timer_.Stop();
bubble_->Close(); if (view_) {
view_->GetWidget()->Close();
view_ = NULL;
}
} }
void SettingLevelBubble::UpdateWithoutShowingBubble(double percent, void SettingLevelBubble::UpdateWithoutShowingBubble(double percent,
...@@ -167,8 +189,55 @@ void SettingLevelBubble::UpdateWithoutShowingBubble(double percent, ...@@ -167,8 +189,55 @@ void SettingLevelBubble::UpdateWithoutShowingBubble(double percent,
view_->SetEnabled(enabled); 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() { void SettingLevelBubble::OnHideTimeout() {
HideBubble(); // Start fading away.
if (view_) {
SettingLevelBubbleDelegateView* delegate =
static_cast<SettingLevelBubbleDelegateView*>
(view_->GetWidget()->widget_delegate());
delegate->StartFade(false);
}
} }
void SettingLevelBubble::OnAnimationTimeout() { void SettingLevelBubble::OnAnimationTimeout() {
...@@ -194,26 +263,6 @@ void SettingLevelBubble::OnAnimationTimeout() { ...@@ -194,26 +263,6 @@ void SettingLevelBubble::OnAnimationTimeout() {
view_->SetLevel(current_percent_); 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) { void SettingLevelBubble::UpdateTargetPercent(double percent) {
target_percent_ = LimitPercent(percent); target_percent_ = LimitPercent(percent);
const TimeTicks now = TimeTicks::Now(); const TimeTicks now = TimeTicks::Now();
......
...@@ -7,9 +7,11 @@ ...@@ -7,9 +7,11 @@
#pragma once #pragma once
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "base/time.h" #include "base/time.h"
#include "base/timer.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; class SkBitmap;
...@@ -17,12 +19,15 @@ namespace chromeos { ...@@ -17,12 +19,15 @@ namespace chromeos {
class SettingLevelBubbleView; 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. // volume or brightness.
class SettingLevelBubble : public BubbleDelegate { class SettingLevelBubble : public views::Widget::Observer {
public: 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); void ShowBubble(double percent, bool enabled);
// Hides the Bubble, closing the view.
void HideBubble(); void HideBubble();
// Updates the bubble's current level without showing the bubble onscreen. // Updates the bubble's current level without showing the bubble onscreen.
...@@ -46,15 +51,23 @@ class SettingLevelBubble : public BubbleDelegate { ...@@ -46,15 +51,23 @@ class SettingLevelBubble : public BubbleDelegate {
SettingLevelBubble(SkBitmap* increase_icon, SettingLevelBubble(SkBitmap* increase_icon,
SkBitmap* decrease_icon, SkBitmap* decrease_icon,
SkBitmap* zero_icon); SkBitmap* zero_icon);
virtual ~SettingLevelBubble(); virtual ~SettingLevelBubble();
private: private:
// Overridden from BubbleDelegate. FRIEND_TEST_ALL_PREFIXES(SettingLevelBubbleTest, CreateAndUpdate);
virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE; FRIEND_TEST_ALL_PREFIXES(SettingLevelBubbleTest, ShowBubble);
virtual bool CloseOnEscape() OVERRIDE; FRIEND_TEST_ALL_PREFIXES(BrightnessBubbleTest, UpdateWithoutShowing);
virtual bool FadeInOnShow() OVERRIDE; 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(); void OnHideTimeout();
// Callback for |animation_timer_|. Updates the level displayed by the view, // Callback for |animation_timer_|. Updates the level displayed by the view,
...@@ -90,9 +103,6 @@ class SettingLevelBubble : public BubbleDelegate { ...@@ -90,9 +103,6 @@ class SettingLevelBubble : public BubbleDelegate {
SkBitmap* decrease_icon_; SkBitmap* decrease_icon_;
SkBitmap* disabled_icon_; SkBitmap* disabled_icon_;
// Currently shown bubble or NULL.
Bubble* bubble_;
// Contents view owned by Bubble. // Contents view owned by Bubble.
SettingLevelBubbleView* view_; SettingLevelBubbleView* view_;
......
// 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
...@@ -28,14 +28,14 @@ const int kProgressBarHeight = 17; ...@@ -28,14 +28,14 @@ const int kProgressBarHeight = 17;
namespace chromeos { namespace chromeos {
SettingLevelBubbleView::SettingLevelBubbleView() SettingLevelBubbleView::SettingLevelBubbleView()
: progress_bar_(NULL), : progress_bar_(new views::ProgressBar()),
icon_(NULL) { icon_(NULL) {
} }
void SettingLevelBubbleView::Init(SkBitmap* icon, double level, bool enabled) { void SettingLevelBubbleView::Init(SkBitmap* icon, double level, bool enabled) {
DCHECK(!icon_);
DCHECK(icon); DCHECK(icon);
icon_ = icon; icon_ = icon;
progress_bar_ = new views::ProgressBar();
AddChildView(progress_bar_); AddChildView(progress_bar_);
progress_bar_->SetDisplayRange(0.0, 100.0); progress_bar_->SetDisplayRange(0.0, 100.0);
progress_bar_->EnableCanvasFlippingForRTLUI(true); progress_bar_->EnableCanvasFlippingForRTLUI(true);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_VIEW_H_ #define CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_VIEW_H_
#pragma once #pragma once
#include "base/gtest_prod_util.h"
#include "views/view.h" #include "views/view.h"
namespace views { namespace views {
...@@ -20,6 +21,7 @@ namespace chromeos { ...@@ -20,6 +21,7 @@ namespace chromeos {
// level-based setting like volume or brightness. // level-based setting like volume or brightness.
class SettingLevelBubbleView : public views::View { class SettingLevelBubbleView : public views::View {
public: public:
// Layout() is called before Init(), make sure |progress_bar_| is ready.
SettingLevelBubbleView(); SettingLevelBubbleView();
// Initialize the view, setting the progress bar to the specified level in the // Initialize the view, setting the progress bar to the specified level in the
...@@ -42,6 +44,8 @@ class SettingLevelBubbleView : public views::View { ...@@ -42,6 +44,8 @@ class SettingLevelBubbleView : public views::View {
virtual gfx::Size GetPreferredSize() OVERRIDE; virtual gfx::Size GetPreferredSize() OVERRIDE;
private: private:
FRIEND_TEST_ALL_PREFIXES(SettingLevelBubbleTest, CreateAndUpdate);
views::ProgressBar* progress_bar_; views::ProgressBar* progress_bar_;
SkBitmap* icon_; // not owned SkBitmap* icon_; // not owned
......
// 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
...@@ -2314,6 +2314,7 @@ ...@@ -2314,6 +2314,7 @@
'browser/browsing_data_helper_browsertest.h', 'browser/browsing_data_helper_browsertest.h',
'browser/browsing_data_indexed_db_helper_browsertest.cc', 'browser/browsing_data_indexed_db_helper_browsertest.cc',
'browser/browsing_data_local_storage_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.cc',
'browser/chromeos/cros/cros_in_process_browser_test.h', 'browser/chromeos/cros/cros_in_process_browser_test.h',
'browser/chromeos/cros/cros_mock.cc', 'browser/chromeos/cros/cros_mock.cc',
...@@ -2359,7 +2360,9 @@ ...@@ -2359,7 +2360,9 @@
'browser/chromeos/status/input_method_menu_button_browsertest.cc', 'browser/chromeos/status/input_method_menu_button_browsertest.cc',
'browser/chromeos/status/power_menu_button_browsertest.cc', 'browser/chromeos/status/power_menu_button_browsertest.cc',
'browser/chromeos/status/status_area_view_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/tab_closeable_state_watcher_browsertest.cc',
'browser/chromeos/volume_bubble_browsertest.cc',
'browser/content_settings/content_settings_browsertest.cc', 'browser/content_settings/content_settings_browsertest.cc',
'browser/crash_recovery_browsertest.cc', 'browser/crash_recovery_browsertest.cc',
'browser/custom_handlers/protocol_handler_registry_browsertest.cc', 'browser/custom_handlers/protocol_handler_registry_browsertest.cc',
......
...@@ -29,7 +29,8 @@ BubbleDelegateView::BubbleDelegateView( ...@@ -29,7 +29,8 @@ BubbleDelegateView::BubbleDelegateView(
close_on_esc_(true), close_on_esc_(true),
anchor_point_(anchor_point), anchor_point_(anchor_point),
arrow_location_(arrow_location), arrow_location_(arrow_location),
color_(color) { color_(color),
original_opacity_(255) {
AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0));
} }
...@@ -88,14 +89,21 @@ void BubbleDelegateView::StartFade(bool fade_in) { ...@@ -88,14 +89,21 @@ void BubbleDelegateView::StartFade(bool fade_in) {
fade_animation_->SetSlideDuration(kHideFadeDurationMS); fade_animation_->SetSlideDuration(kHideFadeDurationMS);
fade_animation_->Reset(fade_in ? 0.0 : 1.0); fade_animation_->Reset(fade_in ? 0.0 : 1.0);
if (fade_in) { if (fade_in) {
GetWidget()->SetOpacity(0); original_opacity_ = 0;
GetWidget()->SetOpacity(original_opacity_);
GetWidget()->Show(); GetWidget()->Show();
fade_animation_->Show(); fade_animation_->Show();
} else { } else {
original_opacity_ = 255;
fade_animation_->Hide(); fade_animation_->Hide();
} }
} }
void BubbleDelegateView::ResetFade() {
fade_animation_.reset();
GetWidget()->SetOpacity(original_opacity_);
}
bool BubbleDelegateView::AcceleratorPressed(const Accelerator& accelerator) { bool BubbleDelegateView::AcceleratorPressed(const Accelerator& accelerator) {
if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE)
return false; return false;
......
...@@ -58,6 +58,10 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView, ...@@ -58,6 +58,10 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView,
// Fade in calls Widget::Show; fade out calls Widget::Close upon completion. // Fade in calls Widget::Show; fade out calls Widget::Close upon completion.
void StartFade(bool fade_in); 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: protected:
// View overrides: // View overrides:
virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE; virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE;
...@@ -90,6 +94,9 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView, ...@@ -90,6 +94,9 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView,
// The background color of the bubble. // The background color of the bubble.
SkColor color_; SkColor color_;
// Original opacity of the bubble.
int original_opacity_;
}; };
} // namespace views } // namespace views
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment