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

Side by Side Diff: ui/message_center/views/toast_contents_view.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 | « ui/message_center/views/toast_contents_view.h ('k') | ui/ui.gyp » ('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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "ui/message_center/views/toast_contents_view.h" 5 #include "ui/message_center/views/toast_contents_view.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "base/timer/timer.h" 12 #include "base/timer/timer.h"
13 #include "ui/base/accessibility/accessible_view_state.h" 13 #include "ui/base/accessibility/accessible_view_state.h"
14 #include "ui/base/animation/animation_delegate.h" 14 #include "ui/gfx/animation/animation_delegate.h"
15 #include "ui/base/animation/slide_animation.h" 15 #include "ui/gfx/animation/slide_animation.h"
16 #include "ui/gfx/display.h" 16 #include "ui/gfx/display.h"
17 #include "ui/gfx/screen.h" 17 #include "ui/gfx/screen.h"
18 #include "ui/message_center/message_center.h" 18 #include "ui/message_center/message_center.h"
19 #include "ui/message_center/message_center_style.h" 19 #include "ui/message_center/message_center_style.h"
20 #include "ui/message_center/notification.h" 20 #include "ui/message_center/notification.h"
21 #include "ui/message_center/views/message_popup_collection.h" 21 #include "ui/message_center/views/message_popup_collection.h"
22 #include "ui/message_center/views/message_view.h" 22 #include "ui/message_center/views/message_view.h"
23 #include "ui/views/view.h" 23 #include "ui/views/view.h"
24 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
25 #include "ui/views/widget/widget_delegate.h" 25 #include "ui/views/widget/widget_delegate.h"
(...skipping 26 matching lines...) Expand all
52 is_closing_(false), 52 is_closing_(false),
53 closing_animation_(NULL) { 53 closing_animation_(NULL) {
54 DCHECK(collection_); 54 DCHECK(collection_);
55 55
56 set_notify_enter_exit_on_child(true); 56 set_notify_enter_exit_on_child(true);
57 // Sets the transparent background. Then, when the message view is slid out, 57 // Sets the transparent background. Then, when the message view is slid out,
58 // the whole toast seems to slide although the actual bound of the widget 58 // the whole toast seems to slide although the actual bound of the widget
59 // remains. This is hacky but easier to keep the consistency. 59 // remains. This is hacky but easier to keep the consistency.
60 set_background(views::Background::CreateSolidBackground(0, 0, 0, 0)); 60 set_background(views::Background::CreateSolidBackground(0, 0, 0, 0));
61 61
62 fade_animation_.reset(new ui::SlideAnimation(this)); 62 fade_animation_.reset(new gfx::SlideAnimation(this));
63 fade_animation_->SetSlideDuration(kFadeInOutDuration); 63 fade_animation_->SetSlideDuration(kFadeInOutDuration);
64 } 64 }
65 65
66 // This is destroyed when the toast window closes. 66 // This is destroyed when the toast window closes.
67 ToastContentsView::~ToastContentsView() { 67 ToastContentsView::~ToastContentsView() {
68 } 68 }
69 69
70 views::Widget* ToastContentsView::CreateWidget(gfx::NativeView parent) { 70 views::Widget* ToastContentsView::CreateWidget(gfx::NativeView parent) {
71 views::Widget::InitParams params( 71 views::Widget::InitParams params(
72 views::Widget::InitParams::TYPE_POPUP); 72 views::Widget::InitParams::TYPE_POPUP);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // on screen, the rest should refer to the bounds_. 160 // on screen, the rest should refer to the bounds_.
161 animated_bounds_start_ = GetWidget()->GetWindowBoundsInScreen(); 161 animated_bounds_start_ = GetWidget()->GetWindowBoundsInScreen();
162 animated_bounds_end_ = new_bounds; 162 animated_bounds_end_ = new_bounds;
163 163
164 if (collection_) 164 if (collection_)
165 collection_->IncrementDeferCounter(); 165 collection_->IncrementDeferCounter();
166 166
167 if (bounds_animation_.get()) 167 if (bounds_animation_.get())
168 bounds_animation_->Stop(); 168 bounds_animation_->Stop();
169 169
170 bounds_animation_.reset(new ui::SlideAnimation(this)); 170 bounds_animation_.reset(new gfx::SlideAnimation(this));
171 bounds_animation_->Show(); 171 bounds_animation_->Show();
172 } 172 }
173 173
174 void ToastContentsView::StartFadeIn() { 174 void ToastContentsView::StartFadeIn() {
175 // The decrement is done in OnBoundsAnimationEndedOrCancelled callback. 175 // The decrement is done in OnBoundsAnimationEndedOrCancelled callback.
176 if (collection_) 176 if (collection_)
177 collection_->IncrementDeferCounter(); 177 collection_->IncrementDeferCounter();
178 fade_animation_->Stop(); 178 fade_animation_->Stop();
179 179
180 GetWidget()->SetOpacity(0); 180 GetWidget()->SetOpacity(0);
181 GetWidget()->Show(); 181 GetWidget()->Show();
182 fade_animation_->Reset(0); 182 fade_animation_->Reset(0);
183 fade_animation_->Show(); 183 fade_animation_->Show();
184 } 184 }
185 185
186 void ToastContentsView::StartFadeOut() { 186 void ToastContentsView::StartFadeOut() {
187 // The decrement is done in OnBoundsAnimationEndedOrCancelled callback. 187 // The decrement is done in OnBoundsAnimationEndedOrCancelled callback.
188 if (collection_) 188 if (collection_)
189 collection_->IncrementDeferCounter(); 189 collection_->IncrementDeferCounter();
190 fade_animation_->Stop(); 190 fade_animation_->Stop();
191 191
192 closing_animation_ = (is_closing_ ? fade_animation_.get() : NULL); 192 closing_animation_ = (is_closing_ ? fade_animation_.get() : NULL);
193 fade_animation_->Reset(1); 193 fade_animation_->Reset(1);
194 fade_animation_->Hide(); 194 fade_animation_->Hide();
195 } 195 }
196 196
197 void ToastContentsView::OnBoundsAnimationEndedOrCancelled( 197 void ToastContentsView::OnBoundsAnimationEndedOrCancelled(
198 const ui::Animation* animation) { 198 const gfx::Animation* animation) {
199 if (is_closing_ && closing_animation_ == animation && GetWidget()) { 199 if (is_closing_ && closing_animation_ == animation && GetWidget()) {
200 views::Widget* widget = GetWidget(); 200 views::Widget* widget = GetWidget();
201 #if defined(USE_AURA) 201 #if defined(USE_AURA)
202 // TODO(dewittj): This is a workaround to prevent a nasty bug where 202 // TODO(dewittj): This is a workaround to prevent a nasty bug where
203 // closing a transparent widget doesn't actually remove the window, 203 // closing a transparent widget doesn't actually remove the window,
204 // causing entire areas of the screen to become unresponsive to clicks. 204 // causing entire areas of the screen to become unresponsive to clicks.
205 // See crbug.com/243469 205 // See crbug.com/243469
206 widget->Hide(); 206 widget->Hide();
207 # if defined(OS_WIN) 207 # if defined(OS_WIN)
208 widget->SetOpacity(0xFF); 208 widget->SetOpacity(0xFF);
209 # endif 209 # endif
210 #endif 210 #endif
211 widget->Close(); 211 widget->Close();
212 } 212 }
213 213
214 // This cannot be called before GetWidget()->Close(). Decrementing defer count 214 // This cannot be called before GetWidget()->Close(). Decrementing defer count
215 // will invoke update, which may invoke another close animation with 215 // will invoke update, which may invoke another close animation with
216 // incrementing defer counter. Close() after such process will cause a 216 // incrementing defer counter. Close() after such process will cause a
217 // mismatch between increment/decrement. See crbug.com/238477 217 // mismatch between increment/decrement. See crbug.com/238477
218 if (collection_) 218 if (collection_)
219 collection_->DecrementDeferCounter(); 219 collection_->DecrementDeferCounter();
220 } 220 }
221 221
222 // ui::AnimationDelegate 222 // gfx::AnimationDelegate
223 void ToastContentsView::AnimationProgressed(const ui::Animation* animation) { 223 void ToastContentsView::AnimationProgressed(const gfx::Animation* animation) {
224 if (animation == bounds_animation_.get()) { 224 if (animation == bounds_animation_.get()) {
225 gfx::Rect current(animation->CurrentValueBetween( 225 gfx::Rect current(animation->CurrentValueBetween(
226 animated_bounds_start_, animated_bounds_end_)); 226 animated_bounds_start_, animated_bounds_end_));
227 GetWidget()->SetBounds(current); 227 GetWidget()->SetBounds(current);
228 } else if (animation == fade_animation_.get()) { 228 } else if (animation == fade_animation_.get()) {
229 unsigned char opacity = 229 unsigned char opacity =
230 static_cast<unsigned char>(fade_animation_->GetCurrentValue() * 255); 230 static_cast<unsigned char>(fade_animation_->GetCurrentValue() * 255);
231 GetWidget()->SetOpacity(opacity); 231 GetWidget()->SetOpacity(opacity);
232 } 232 }
233 } 233 }
234 234
235 void ToastContentsView::AnimationEnded(const ui::Animation* animation) { 235 void ToastContentsView::AnimationEnded(const gfx::Animation* animation) {
236 OnBoundsAnimationEndedOrCancelled(animation); 236 OnBoundsAnimationEndedOrCancelled(animation);
237 } 237 }
238 238
239 void ToastContentsView::AnimationCanceled( 239 void ToastContentsView::AnimationCanceled(
240 const ui::Animation* animation) { 240 const gfx::Animation* animation) {
241 OnBoundsAnimationEndedOrCancelled(animation); 241 OnBoundsAnimationEndedOrCancelled(animation);
242 } 242 }
243 243
244 // views::WidgetDelegate 244 // views::WidgetDelegate
245 views::View* ToastContentsView::GetContentsView() { 245 views::View* ToastContentsView::GetContentsView() {
246 return this; 246 return this;
247 } 247 }
248 248
249 void ToastContentsView::WindowClosing() { 249 void ToastContentsView::WindowClosing() {
250 if (!is_closing_ && collection_) 250 if (!is_closing_ && collection_)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 } 314 }
315 315
316 gfx::Rect ToastContentsView::GetClosedToastBounds(gfx::Rect bounds) { 316 gfx::Rect ToastContentsView::GetClosedToastBounds(gfx::Rect bounds) {
317 return gfx::Rect(bounds.x() + bounds.width() - kClosedToastWidth, 317 return gfx::Rect(bounds.x() + bounds.width() - kClosedToastWidth,
318 bounds.y(), 318 bounds.y(),
319 kClosedToastWidth, 319 kClosedToastWidth,
320 bounds.height()); 320 bounds.height());
321 } 321 }
322 322
323 } // namespace message_center 323 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/toast_contents_view.h ('k') | ui/ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698