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

Side by Side Diff: views/bubble/bubble_view.cc

Issue 8319008: aura: brightness and volume bubble. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: 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 bool enable_accelerator)
23 animation_delegate_(NULL), 18 : ClientView(owner, contents_view) {
24 registered_accelerator_(false), 19 if (enable_accelerator)
25 should_fade_(false) { 20 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0));
26 ResetLayoutManager();
27 InitAnimation();
28 } 21 }
29 22
30 void BubbleView::InitAnimation() { 23 BubbleView::~BubbleView() {}
24
25 void BubbleView::StartFade() {
31 fade_animation_.reset(new ui::SlideAnimation(this)); 26 fade_animation_.reset(new ui::SlideAnimation(this));
32 fade_animation_->SetSlideDuration(kHideFadeDurationMS); 27 fade_animation_->SetSlideDuration(kHideFadeDurationMS);
33 fade_animation_->Reset(1.0); 28 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(); 29 fade_animation_->Hide();
52 } 30 }
53 31
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) { 32 bool BubbleView::AcceleratorPressed(const Accelerator& accelerator) {
81 if (registered_accelerator_) { 33 if (accelerator.key_code() != ui::VKEY_ESCAPE)
82 GetWidget()->GetFocusManager()->UnregisterAccelerator( 34 return false;
83 views::Accelerator(ui::VKEY_ESCAPE, false, false, false), this); 35 if (fade_animation_.get())
84 registered_accelerator_ = false; 36 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(); 37 GetWidget()->Close();
92 return true; 38 return true;
93 } 39 }
94 40
95 void BubbleView::AnimationEnded(const ui::Animation* animation) { 41 void BubbleView::AnimationEnded(const ui::Animation* animation) {
96 if (animation_delegate_) 42 DCHECK_EQ(animation, fade_animation_.get());
97 animation_delegate_->AnimationEnded(animation); 43 fade_animation_->Reset();
98
99 fade_animation_->Reset(0.0);
100 // Close the widget.
101 registered_accelerator_ = false;
102 GetWidget()->Close(); 44 GetWidget()->Close();
103 } 45 }
104 46
105 void BubbleView::AnimationProgressed(const ui::Animation* animation) { 47 void BubbleView::AnimationProgressed(const ui::Animation* animation) {
106 if (fade_animation_->is_animating()) { 48 DCHECK_EQ(animation, fade_animation_.get());
107 if (animation_delegate_) 49 DCHECK(fade_animation_->is_animating());
108 animation_delegate_->AnimationProgressed(animation); 50 GetWidget()->SetOpacity(fade_animation_->GetCurrentValue() * 255);
109 51 SchedulePaint();
110 GetWidget()->SetOpacity(animation->GetCurrentValue() * 255);
111 SchedulePaint();
112 }
113 } 52 }
114 53
115 } // namespace views 54 } // namespace views
OLDNEW
« chrome/browser/chromeos/system_key_event_listener.cc ('K') | « views/bubble/bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698