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

Side by Side 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: Merge 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "views/bubble/bubble_view.h" 5 #include "views/bubble/bubble_view.h"
6 6
7 #include "ui/base/animation/slide_animation.h" 7 #include "ui/base/animation/slide_animation.h"
8 #include "views/bubble/bubble_border.h" 8 #include "views/bubble/bubble_border.h"
9 #include "views/controls/label.h"
10 #include "views/layout/box_layout.h"
11 #include "views/layout/layout_constants.h"
12 #include "views/views_delegate.h"
13 #include "views/window/client_view.h"
14 #include "views/widget/widget.h" 9 #include "views/widget/widget.h"
15 10
16 // How long the fade should last for. 11 // The duration of the fade animation in milliseconds.
17 static const int kHideFadeDurationMS = 1000; 12 static const int kHideFadeDurationMS = 1000;
18 13
19 namespace views { 14 namespace views {
20 15
21 BubbleView::BubbleView(Widget* owner, View* contents_view) 16 BubbleView::BubbleView(Widget* owner, View* contents_view)
22 : ClientView(owner, contents_view), 17 : ClientView(owner, contents_view) {
23 animation_delegate_(NULL), 18 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0));
24 registered_accelerator_(false),
25 should_fade_(false) {
26 ResetLayoutManager();
27 InitAnimation();
28 } 19 }
29 20
30 void BubbleView::InitAnimation() { 21 BubbleView::~BubbleView() {}
22
23 void BubbleView::StartFade() {
31 fade_animation_.reset(new ui::SlideAnimation(this)); 24 fade_animation_.reset(new ui::SlideAnimation(this));
32 fade_animation_->SetSlideDuration(kHideFadeDurationMS); 25 fade_animation_->SetSlideDuration(kHideFadeDurationMS);
33 fade_animation_->Reset(1.0); 26 fade_animation_->Reset(1.0);
34 }
35
36 BubbleView* BubbleView::AsBubbleView() { return this; }
37 const BubbleView* BubbleView::AsBubbleView() const { return this; }
38
39 BubbleView::~BubbleView() {}
40
41 void BubbleView::Show() {
42 if (!registered_accelerator_)
43 registered_accelerator_ = true;
44 GetWidget()->Show();
45 GetWidget()->Activate();
46 SchedulePaint();
47 }
48
49 void BubbleView::StartFade() {
50 should_fade_ = true;
51 fade_animation_->Hide(); 27 fade_animation_->Hide();
52 } 28 }
53 29
54 void BubbleView::ResetLayoutManager() {
55 SetLayoutManager(new views::BoxLayout(
56 views::BoxLayout::kHorizontal, 0, 0, 1));
57 }
58
59 void BubbleView::set_animation_delegate(ui::AnimationDelegate* delegate) {
60 animation_delegate_ = delegate;
61 }
62
63 void BubbleView::ViewHierarchyChanged(bool is_add,
64 views::View* parent,
65 views::View* child) {
66 if (is_add && parent == this)
67 child->SetBoundsRect(bounds());
68 }
69
70 void BubbleView::Layout() {
71 gfx::Rect lb = GetContentsBounds();
72 contents_view()->SetBoundsRect(lb);
73 contents_view()->Layout();
74 }
75
76 gfx::Size BubbleView::GetPreferredSize() {
77 return bounds().size();
78 }
79
80 bool BubbleView::AcceleratorPressed(const Accelerator& accelerator) { 30 bool BubbleView::AcceleratorPressed(const Accelerator& accelerator) {
81 if (registered_accelerator_) { 31 if (accelerator.key_code() != ui::VKEY_ESCAPE)
82 GetWidget()->GetFocusManager()->UnregisterAccelerator( 32 return false;
83 views::Accelerator(ui::VKEY_ESCAPE, false, false, false), this); 33 if (fade_animation_.get())
84 registered_accelerator_ = false; 34 fade_animation_->Reset();
85 }
86 // Turn off animation, if any.
87 if (should_fade_ && fade_animation_->is_animating()) {
88 fade_animation_->Reset(1.0);
89 fade_animation_->Show();
90 }
91 GetWidget()->Close(); 35 GetWidget()->Close();
92 return true; 36 return true;
93 } 37 }
94 38
95 void BubbleView::AnimationEnded(const ui::Animation* animation) { 39 void BubbleView::AnimationEnded(const ui::Animation* animation) {
96 if (animation_delegate_) 40 DCHECK_EQ(animation, fade_animation_.get());
97 animation_delegate_->AnimationEnded(animation); 41 fade_animation_->Reset();
98
99 fade_animation_->Reset(0.0);
100 // Close the widget.
101 registered_accelerator_ = false;
102 GetWidget()->Close(); 42 GetWidget()->Close();
103 } 43 }
104 44
105 void BubbleView::AnimationProgressed(const ui::Animation* animation) { 45 void BubbleView::AnimationProgressed(const ui::Animation* animation) {
106 if (fade_animation_->is_animating()) { 46 DCHECK_EQ(animation, fade_animation_.get());
107 if (animation_delegate_) 47 DCHECK(fade_animation_->is_animating());
108 animation_delegate_->AnimationProgressed(animation); 48 GetWidget()->SetOpacity(fade_animation_->GetCurrentValue() * 255);
109 49 SchedulePaint();
110 GetWidget()->SetOpacity(animation->GetCurrentValue() * 255);
111 SchedulePaint();
112 }
113 } 50 }
114 51
115 } // namespace views 52 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698