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

Unified Diff: views/bubble/bubble_view.cc

Issue 8227003: Views Bubble API adjustments and cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add close_on_esc setting and fade-in functionality. 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
« no previous file with comments | « views/bubble/bubble_view.h ('k') | views/bubble/bubble_view_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/bubble/bubble_view.cc
diff --git a/views/bubble/bubble_view.cc b/views/bubble/bubble_view.cc
index 0dcd522c524f47fb9f7a5ce418b926bc9b0410f1..8ae5efe5e887eef0c7112b5e42ce9606e1644064 100644
--- a/views/bubble/bubble_view.cc
+++ b/views/bubble/bubble_view.cc
@@ -6,110 +6,56 @@
#include "ui/base/animation/slide_animation.h"
#include "views/bubble/bubble_border.h"
-#include "views/controls/label.h"
-#include "views/layout/box_layout.h"
-#include "views/layout/layout_constants.h"
-#include "views/views_delegate.h"
-#include "views/window/client_view.h"
#include "views/widget/widget.h"
-// How long the fade should last for.
+// The duration of the fade animation in milliseconds.
static const int kHideFadeDurationMS = 1000;
namespace views {
BubbleView::BubbleView(Widget* owner, View* contents_view)
: ClientView(owner, contents_view),
- animation_delegate_(NULL),
- registered_accelerator_(false),
- should_fade_(false) {
- ResetLayoutManager();
- InitAnimation();
+ close_on_esc_(true) {
+ AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0));
}
-void BubbleView::InitAnimation() {
- fade_animation_.reset(new ui::SlideAnimation(this));
- fade_animation_->SetSlideDuration(kHideFadeDurationMS);
- fade_animation_->Reset(1.0);
-}
-
-BubbleView* BubbleView::AsBubbleView() { return this; }
-const BubbleView* BubbleView::AsBubbleView() const { return this; }
-
BubbleView::~BubbleView() {}
-void BubbleView::Show() {
- if (!registered_accelerator_)
- registered_accelerator_ = true;
- GetWidget()->Show();
- GetWidget()->Activate();
- SchedulePaint();
-}
-
-void BubbleView::StartFade() {
- should_fade_ = true;
- fade_animation_->Hide();
-}
-
-void BubbleView::ResetLayoutManager() {
- SetLayoutManager(new views::BoxLayout(
- views::BoxLayout::kHorizontal, 0, 0, 1));
-}
-
-void BubbleView::set_animation_delegate(ui::AnimationDelegate* delegate) {
- animation_delegate_ = delegate;
-}
-
-void BubbleView::ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child) {
- if (is_add && parent == this)
- child->SetBoundsRect(bounds());
-}
-
-void BubbleView::Layout() {
- gfx::Rect lb = GetContentsBounds();
- contents_view()->SetBoundsRect(lb);
- contents_view()->Layout();
-}
-
-gfx::Size BubbleView::GetPreferredSize() {
- return bounds().size();
+void BubbleView::StartFade(bool fade_in) {
+ fade_animation_.reset(new ui::SlideAnimation(this));
+ fade_animation_->SetSlideDuration(kHideFadeDurationMS);
+ fade_animation_->Reset(fade_in ? 0.0 : 1.0);
+ if (fade_in) {
+ GetWidget()->SetOpacity(0);
+ GetWidget()->Show();
+ fade_animation_->Show();
+ } else {
+ fade_animation_->Hide();
+ }
}
bool BubbleView::AcceleratorPressed(const Accelerator& accelerator) {
- if (registered_accelerator_) {
- GetWidget()->GetFocusManager()->UnregisterAccelerator(
- views::Accelerator(ui::VKEY_ESCAPE, false, false, false), this);
- registered_accelerator_ = false;
- }
- // Turn off animation, if any.
- if (should_fade_ && fade_animation_->is_animating()) {
- fade_animation_->Reset(1.0);
- fade_animation_->Show();
- }
+ if (!close_on_esc_ || accelerator.key_code() != ui::VKEY_ESCAPE)
+ return false;
+ if (fade_animation_.get())
+ fade_animation_->Reset();
GetWidget()->Close();
return true;
}
void BubbleView::AnimationEnded(const ui::Animation* animation) {
- if (animation_delegate_)
- animation_delegate_->AnimationEnded(animation);
-
- fade_animation_->Reset(0.0);
- // Close the widget.
- registered_accelerator_ = false;
- GetWidget()->Close();
+ DCHECK_EQ(animation, fade_animation_.get());
+ bool closed = fade_animation_->GetCurrentValue() == 0;
+ fade_animation_->Reset();
+ if (closed)
+ GetWidget()->Close();
}
void BubbleView::AnimationProgressed(const ui::Animation* animation) {
- if (fade_animation_->is_animating()) {
- if (animation_delegate_)
- animation_delegate_->AnimationProgressed(animation);
-
- GetWidget()->SetOpacity(animation->GetCurrentValue() * 255);
- SchedulePaint();
- }
+ DCHECK_EQ(animation, fade_animation_.get());
+ DCHECK(fade_animation_->is_animating());
+ GetWidget()->SetOpacity(fade_animation_->GetCurrentValue() * 255);
+ SchedulePaint();
}
} // namespace views
« no previous file with comments | « views/bubble/bubble_view.h ('k') | views/bubble/bubble_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698