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

Side by Side Diff: chrome/browser/infobars/infobar.cc

Issue 23531053: ui/base/animation -> ui/gfx/animation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge 2 trunk Created 7 years, 3 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
« no previous file with comments | « chrome/browser/infobars/infobar.h ('k') | chrome/browser/infobars/infobar_container.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/infobars/infobar.h" 5 #include "chrome/browser/infobars/infobar.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/infobars/infobar_container.h" 11 #include "chrome/browser/infobars/infobar_container.h"
12 #include "chrome/browser/infobars/infobar_service.h" 12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "ui/base/animation/slide_animation.h" 13 #include "ui/gfx/animation/slide_animation.h"
14 14
15 SkColor GetInfoBarTopColor(InfoBarDelegate::Type infobar_type) { 15 SkColor GetInfoBarTopColor(InfoBarDelegate::Type infobar_type) {
16 static const SkColor kWarningBackgroundColorTop = 16 static const SkColor kWarningBackgroundColorTop =
17 SkColorSetRGB(255, 242, 183); // Yellow 17 SkColorSetRGB(255, 242, 183); // Yellow
18 static const SkColor kPageActionBackgroundColorTop = 18 static const SkColor kPageActionBackgroundColorTop =
19 SkColorSetRGB(237, 237, 237); // Gray 19 SkColorSetRGB(237, 237, 237); // Gray
20 return (infobar_type == InfoBarDelegate::WARNING_TYPE) ? 20 return (infobar_type == InfoBarDelegate::WARNING_TYPE) ?
21 kWarningBackgroundColorTop : kPageActionBackgroundColorTop; 21 kWarningBackgroundColorTop : kPageActionBackgroundColorTop;
22 } 22 }
23 23
(...skipping 11 matching lines...) Expand all
35 delegate_(delegate), 35 delegate_(delegate),
36 container_(NULL), 36 container_(NULL),
37 animation_(this), 37 animation_(this),
38 arrow_height_(0), 38 arrow_height_(0),
39 arrow_target_height_(kDefaultArrowTargetHeight), 39 arrow_target_height_(kDefaultArrowTargetHeight),
40 arrow_half_width_(0), 40 arrow_half_width_(0),
41 bar_height_(0), 41 bar_height_(0),
42 bar_target_height_(kDefaultBarTargetHeight) { 42 bar_target_height_(kDefaultBarTargetHeight) {
43 DCHECK(owner_ != NULL); 43 DCHECK(owner_ != NULL);
44 DCHECK(delegate_ != NULL); 44 DCHECK(delegate_ != NULL);
45 animation_.SetTweenType(ui::Tween::LINEAR); 45 animation_.SetTweenType(gfx::Tween::LINEAR);
46 } 46 }
47 47
48 InfoBar::~InfoBar() { 48 InfoBar::~InfoBar() {
49 } 49 }
50 50
51 void InfoBar::Show(bool animate) { 51 void InfoBar::Show(bool animate) {
52 PlatformSpecificShow(animate); 52 PlatformSpecificShow(animate);
53 if (animate) { 53 if (animate) {
54 animation_.Show(); 54 animation_.Show();
55 } else { 55 } else {
(...skipping 25 matching lines...) Expand all
81 RecalculateHeights(false); 81 RecalculateHeights(false);
82 } 82 }
83 } 83 }
84 84
85 void InfoBar::CloseSoon() { 85 void InfoBar::CloseSoon() {
86 owner_ = NULL; 86 owner_ = NULL;
87 PlatformSpecificOnCloseSoon(); 87 PlatformSpecificOnCloseSoon();
88 MaybeDelete(); 88 MaybeDelete();
89 } 89 }
90 90
91 void InfoBar::AnimationProgressed(const ui::Animation* animation) { 91 void InfoBar::AnimationProgressed(const gfx::Animation* animation) {
92 RecalculateHeights(false); 92 RecalculateHeights(false);
93 } 93 }
94 94
95 void InfoBar::RemoveSelf() { 95 void InfoBar::RemoveSelf() {
96 // |owner_| should never be NULL here. If it is, then someone violated what 96 // |owner_| should never be NULL here. If it is, then someone violated what
97 // they were supposed to do -- e.g. a ConfirmInfoBarDelegate subclass returned 97 // they were supposed to do -- e.g. a ConfirmInfoBarDelegate subclass returned
98 // true from Accept() or Cancel() even though the infobar was already closing. 98 // true from Accept() or Cancel() even though the infobar was already closing.
99 // In the worst case, if we also switched tabs during that process, then 99 // In the worst case, if we also switched tabs during that process, then
100 // |this| has already been destroyed. But if that's the case, then we're 100 // |this| has already been destroyed. But if that's the case, then we're
101 // going to deref a garbage |this| pointer here whether we check |owner_| or 101 // going to deref a garbage |this| pointer here whether we check |owner_| or
102 // not, and in other cases (where we're still closing and |this| is valid), 102 // not, and in other cases (where we're still closing and |this| is valid),
103 // checking |owner_| here will avoid a NULL deref. 103 // checking |owner_| here will avoid a NULL deref.
104 if (owner_) 104 if (owner_)
105 owner_->RemoveInfoBar(delegate_); 105 owner_->RemoveInfoBar(delegate_);
106 } 106 }
107 107
108 void InfoBar::SetBarTargetHeight(int height) { 108 void InfoBar::SetBarTargetHeight(int height) {
109 if (bar_target_height_ != height) { 109 if (bar_target_height_ != height) {
110 bar_target_height_ = height; 110 bar_target_height_ = height;
111 RecalculateHeights(false); 111 RecalculateHeights(false);
112 } 112 }
113 } 113 }
114 114
115 int InfoBar::OffsetY(const gfx::Size& prefsize) const { 115 int InfoBar::OffsetY(const gfx::Size& prefsize) const {
116 return arrow_height_ + 116 return arrow_height_ +
117 std::max((bar_target_height_ - prefsize.height()) / 2, 0) - 117 std::max((bar_target_height_ - prefsize.height()) / 2, 0) -
118 (bar_target_height_ - bar_height_); 118 (bar_target_height_ - bar_height_);
119 } 119 }
120 120
121 void InfoBar::AnimationEnded(const ui::Animation* animation) { 121 void InfoBar::AnimationEnded(const gfx::Animation* animation) {
122 // When the animation ends, we must ensure the container is notified even if 122 // When the animation ends, we must ensure the container is notified even if
123 // the heights haven't changed, lest it never get an "animation finished" 123 // the heights haven't changed, lest it never get an "animation finished"
124 // notification. (If the browser doesn't get this notification, it will not 124 // notification. (If the browser doesn't get this notification, it will not
125 // bother to re-layout the content area for the new infobar size.) 125 // bother to re-layout the content area for the new infobar size.)
126 RecalculateHeights(true); 126 RecalculateHeights(true);
127 MaybeDelete(); 127 MaybeDelete();
128 } 128 }
129 129
130 void InfoBar::RecalculateHeights(bool force_notify) { 130 void InfoBar::RecalculateHeights(bool force_notify) {
131 int old_arrow_height = arrow_height_; 131 int old_arrow_height = arrow_height_;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 } 171 }
172 172
173 void InfoBar::MaybeDelete() { 173 void InfoBar::MaybeDelete() {
174 if (!owner_ && delegate_ && (animation_.GetCurrentValue() == 0.0)) { 174 if (!owner_ && delegate_ && (animation_.GetCurrentValue() == 0.0)) {
175 if (container_) 175 if (container_)
176 container_->RemoveInfoBar(this); 176 container_->RemoveInfoBar(this);
177 delete delegate_; 177 delete delegate_;
178 delegate_ = NULL; 178 delegate_ = NULL;
179 } 179 }
180 } 180 }
OLDNEW
« no previous file with comments | « chrome/browser/infobars/infobar.h ('k') | chrome/browser/infobars/infobar_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698