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

Side by Side Diff: chrome/browser/ui/views/status_bubble_views.cc

Issue 2009333002: Converts Widget::SetOpacity from char to float (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/views/status_bubble_views.h" 5 #include "chrome/browser/ui/views/status_bubble_views.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // How long each expansion step should take. 79 // How long each expansion step should take.
80 static const int kMinExpansionStepDurationMS = 20; 80 static const int kMinExpansionStepDurationMS = 20;
81 static const int kMaxExpansionStepDurationMS = 150; 81 static const int kMaxExpansionStepDurationMS = 150;
82 82
83 83
84 // StatusBubbleViews::StatusViewAnimation -------------------------------------- 84 // StatusBubbleViews::StatusViewAnimation --------------------------------------
85 class StatusBubbleViews::StatusViewAnimation : public gfx::LinearAnimation, 85 class StatusBubbleViews::StatusViewAnimation : public gfx::LinearAnimation,
86 public gfx::AnimationDelegate { 86 public gfx::AnimationDelegate {
87 public: 87 public:
88 StatusViewAnimation(StatusView* status_view, 88 StatusViewAnimation(StatusView* status_view,
89 double opacity_start, 89 float opacity_start,
90 double opacity_end); 90 float opacity_end);
91 ~StatusViewAnimation() override; 91 ~StatusViewAnimation() override;
92 92
93 double GetCurrentOpacity(); 93 float GetCurrentOpacity();
94 94
95 private: 95 private:
96 // gfx::LinearAnimation: 96 // gfx::LinearAnimation:
97 void AnimateToState(double state) override; 97 void AnimateToState(double state) override;
98 98
99 // gfx::AnimationDelegate: 99 // gfx::AnimationDelegate:
100 void AnimationEnded(const Animation* animation) override; 100 void AnimationEnded(const Animation* animation) override;
101 101
102 StatusView* status_view_; 102 StatusView* status_view_;
103 103
104 // Start and end opacities for the current transition - note that as a 104 // Start and end opacities for the current transition - note that as a
105 // fade-in can easily turn into a fade out, opacity_start_ is sometimes 105 // fade-in can easily turn into a fade out, opacity_start_ is sometimes
106 // a value between 0 and 1. 106 // a value between 0 and 1.
107 double opacity_start_; 107 float opacity_start_;
108 double opacity_end_; 108 float opacity_end_;
109 109
110 DISALLOW_COPY_AND_ASSIGN(StatusViewAnimation); 110 DISALLOW_COPY_AND_ASSIGN(StatusViewAnimation);
111 }; 111 };
112 112
113 113
114 // StatusBubbleViews::StatusView ----------------------------------------------- 114 // StatusBubbleViews::StatusView -----------------------------------------------
115 // 115 //
116 // StatusView manages the display of the bubble, applying text changes and 116 // StatusView manages the display of the bubble, applying text changes and
117 // fading in or out the bubble as required. 117 // fading in or out the bubble as required.
118 class StatusBubbleViews::StatusView : public views::View { 118 class StatusBubbleViews::StatusView : public views::View {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 void Show(); 151 void Show();
152 152
153 // Hide the bubble instantly. 153 // Hide the bubble instantly.
154 void Hide(); 154 void Hide();
155 155
156 // Resets any timers we have. Typically called when the user moves a 156 // Resets any timers we have. Typically called when the user moves a
157 // mouse. 157 // mouse.
158 void ResetTimer(); 158 void ResetTimer();
159 159
160 // This call backs the StatusView in order to fade the bubble in and out. 160 // This call backs the StatusView in order to fade the bubble in and out.
161 void SetOpacity(double opacity); 161 void SetOpacity(float opacity);
162 162
163 // Depending on the state of the bubble this will either hide the popup or 163 // Depending on the state of the bubble this will either hide the popup or
164 // not. 164 // not.
165 void OnAnimationEnded(); 165 void OnAnimationEnded();
166 166
167 private: 167 private:
168 class InitialTimer; 168 class InitialTimer;
169 169
170 // Manage the timers that control the delay before a fade begins or ends. 170 // Manage the timers that control the delay before a fade begins or ends.
171 void StartTimer(base::TimeDelta time); 171 void StartTimer(base::TimeDelta time);
172 void OnTimer(); 172 void OnTimer();
173 void CancelTimer(); 173 void CancelTimer();
174 void RestartTimer(base::TimeDelta delay); 174 void RestartTimer(base::TimeDelta delay);
175 175
176 // Manage the fades and starting and stopping the animations correctly. 176 // Manage the fades and starting and stopping the animations correctly.
177 void StartFade(double start, double end, int duration); 177 void StartFade(float start, float end, int duration);
178 void StartHiding(); 178 void StartHiding();
179 void StartShowing(); 179 void StartShowing();
180 180
181 // views::View: 181 // views::View:
182 const char* GetClassName() const override; 182 const char* GetClassName() const override;
183 void OnPaint(gfx::Canvas* canvas) override; 183 void OnPaint(gfx::Canvas* canvas) override;
184 184
185 BubbleState state_; 185 BubbleState state_;
186 BubbleStyle style_; 186 BubbleStyle style_;
187 187
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 255
256 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 256 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
257 FROM_HERE, base::Bind(&StatusBubbleViews::StatusView::OnTimer, 257 FROM_HERE, base::Bind(&StatusBubbleViews::StatusView::OnTimer,
258 timer_factory_.GetWeakPtr()), 258 timer_factory_.GetWeakPtr()),
259 time); 259 time);
260 } 260 }
261 261
262 void StatusBubbleViews::StatusView::OnTimer() { 262 void StatusBubbleViews::StatusView::OnTimer() {
263 if (state_ == BUBBLE_HIDING_TIMER) { 263 if (state_ == BUBBLE_HIDING_TIMER) {
264 state_ = BUBBLE_HIDING_FADE; 264 state_ = BUBBLE_HIDING_FADE;
265 StartFade(1.0, 0.0, kHideFadeDurationMS); 265 StartFade(1.0f, 0.0f, kHideFadeDurationMS);
266 } else if (state_ == BUBBLE_SHOWING_TIMER) { 266 } else if (state_ == BUBBLE_SHOWING_TIMER) {
267 state_ = BUBBLE_SHOWING_FADE; 267 state_ = BUBBLE_SHOWING_FADE;
268 StartFade(0.0, 1.0, kShowFadeDurationMS); 268 StartFade(0.0f, 1.0f, kShowFadeDurationMS);
269 } 269 }
270 } 270 }
271 271
272 void StatusBubbleViews::StatusView::CancelTimer() { 272 void StatusBubbleViews::StatusView::CancelTimer() {
273 if (timer_factory_.HasWeakPtrs()) 273 if (timer_factory_.HasWeakPtrs())
274 timer_factory_.InvalidateWeakPtrs(); 274 timer_factory_.InvalidateWeakPtrs();
275 } 275 }
276 276
277 void StatusBubbleViews::StatusView::RestartTimer(base::TimeDelta delay) { 277 void StatusBubbleViews::StatusView::RestartTimer(base::TimeDelta delay) {
278 CancelTimer(); 278 CancelTimer();
279 StartTimer(delay); 279 StartTimer(delay);
280 } 280 }
281 281
282 void StatusBubbleViews::StatusView::ResetTimer() { 282 void StatusBubbleViews::StatusView::ResetTimer() {
283 if (state_ == BUBBLE_SHOWING_TIMER) { 283 if (state_ == BUBBLE_SHOWING_TIMER) {
284 // We hadn't yet begun showing anything when we received a new request 284 // We hadn't yet begun showing anything when we received a new request
285 // for something to show, so we start from scratch. 285 // for something to show, so we start from scratch.
286 RestartTimer(base::TimeDelta::FromMilliseconds(kShowDelay)); 286 RestartTimer(base::TimeDelta::FromMilliseconds(kShowDelay));
287 } 287 }
288 } 288 }
289 289
290 void StatusBubbleViews::StatusView::StartFade(double start, 290 void StatusBubbleViews::StatusView::StartFade(float start,
291 double end, 291 float end,
292 int duration) { 292 int duration) {
293 animation_.reset(new StatusViewAnimation(this, start, end)); 293 animation_.reset(new StatusViewAnimation(this, start, end));
294 294
295 // This will also reset the currently-occurring animation. 295 // This will also reset the currently-occurring animation.
296 animation_->SetDuration(duration); 296 animation_->SetDuration(duration);
297 animation_->Start(); 297 animation_->Start();
298 } 298 }
299 299
300 void StatusBubbleViews::StatusView::StartHiding() { 300 void StatusBubbleViews::StatusView::StartHiding() {
301 if (state_ == BUBBLE_SHOWN) { 301 if (state_ == BUBBLE_SHOWN) {
302 state_ = BUBBLE_HIDING_TIMER; 302 state_ = BUBBLE_HIDING_TIMER;
303 StartTimer(base::TimeDelta::FromMilliseconds(kHideDelay)); 303 StartTimer(base::TimeDelta::FromMilliseconds(kHideDelay));
304 } else if (state_ == BUBBLE_SHOWING_TIMER) { 304 } else if (state_ == BUBBLE_SHOWING_TIMER) {
305 state_ = BUBBLE_HIDDEN; 305 state_ = BUBBLE_HIDDEN;
306 popup_->Hide(); 306 popup_->Hide();
307 CancelTimer(); 307 CancelTimer();
308 } else if (state_ == BUBBLE_SHOWING_FADE) { 308 } else if (state_ == BUBBLE_SHOWING_FADE) {
309 state_ = BUBBLE_HIDING_FADE; 309 state_ = BUBBLE_HIDING_FADE;
310 // Figure out where we are in the current fade. 310 // Figure out where we are in the current fade.
311 double current_opacity = animation_->GetCurrentOpacity(); 311 float current_opacity = animation_->GetCurrentOpacity();
312 312
313 // Start a fade in the opposite direction. 313 // Start a fade in the opposite direction.
314 StartFade(current_opacity, 0.0, 314 StartFade(current_opacity, 0.0f,
315 static_cast<int>(kHideFadeDurationMS * current_opacity)); 315 static_cast<int>(kHideFadeDurationMS * current_opacity));
316 } 316 }
317 } 317 }
318 318
319 void StatusBubbleViews::StatusView::StartShowing() { 319 void StatusBubbleViews::StatusView::StartShowing() {
320 if (state_ == BUBBLE_HIDDEN) { 320 if (state_ == BUBBLE_HIDDEN) {
321 popup_->ShowInactive(); 321 popup_->ShowInactive();
322 state_ = BUBBLE_SHOWING_TIMER; 322 state_ = BUBBLE_SHOWING_TIMER;
323 StartTimer(base::TimeDelta::FromMilliseconds(kShowDelay)); 323 StartTimer(base::TimeDelta::FromMilliseconds(kShowDelay));
324 } else if (state_ == BUBBLE_HIDING_TIMER) { 324 } else if (state_ == BUBBLE_HIDING_TIMER) {
325 state_ = BUBBLE_SHOWN; 325 state_ = BUBBLE_SHOWN;
326 CancelTimer(); 326 CancelTimer();
327 } else if (state_ == BUBBLE_HIDING_FADE) { 327 } else if (state_ == BUBBLE_HIDING_FADE) {
328 // We're partway through a fade. 328 // We're partway through a fade.
329 state_ = BUBBLE_SHOWING_FADE; 329 state_ = BUBBLE_SHOWING_FADE;
330 330
331 // Figure out where we are in the current fade. 331 // Figure out where we are in the current fade.
332 double current_opacity = animation_->GetCurrentOpacity(); 332 float current_opacity = animation_->GetCurrentOpacity();
333 333
334 // Start a fade in the opposite direction. 334 // Start a fade in the opposite direction.
335 StartFade(current_opacity, 1.0, 335 StartFade(current_opacity, 1.0f,
336 static_cast<int>(kShowFadeDurationMS * current_opacity)); 336 static_cast<int>(kShowFadeDurationMS * current_opacity));
337 } else if (state_ == BUBBLE_SHOWING_TIMER) { 337 } else if (state_ == BUBBLE_SHOWING_TIMER) {
338 // We hadn't yet begun showing anything when we received a new request 338 // We hadn't yet begun showing anything when we received a new request
339 // for something to show, so we start from scratch. 339 // for something to show, so we start from scratch.
340 ResetTimer(); 340 ResetTimer();
341 } 341 }
342 } 342 }
343 343
344 void StatusBubbleViews::StatusView::SetOpacity(double opacity) { 344 void StatusBubbleViews::StatusView::SetOpacity(float opacity) {
345 popup_->SetOpacity(static_cast<unsigned char>(opacity * 255)); 345 popup_->SetOpacity(opacity);
346 } 346 }
347 347
348 void StatusBubbleViews::StatusView::SetStyle(BubbleStyle style) { 348 void StatusBubbleViews::StatusView::SetStyle(BubbleStyle style) {
349 if (style_ != style) { 349 if (style_ != style) {
350 style_ = style; 350 style_ = style;
351 SchedulePaint(); 351 SchedulePaint();
352 } 352 }
353 } 353 }
354 354
355 void StatusBubbleViews::StatusView::OnAnimationEnded() { 355 void StatusBubbleViews::StatusView::OnAnimationEnded() {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 canvas->DrawStringRect(text_, font_list, 446 canvas->DrawStringRect(text_, font_list,
447 SkColorSetA(text_color, SkColorGetA(text_color) / 2), 447 SkColorSetA(text_color, SkColorGetA(text_color) / 2),
448 text_bounds); 448 text_bounds);
449 } 449 }
450 450
451 451
452 // StatusBubbleViews::StatusViewAnimation -------------------------------------- 452 // StatusBubbleViews::StatusViewAnimation --------------------------------------
453 453
454 StatusBubbleViews::StatusViewAnimation::StatusViewAnimation( 454 StatusBubbleViews::StatusViewAnimation::StatusViewAnimation(
455 StatusView* status_view, 455 StatusView* status_view,
456 double opacity_start, 456 float opacity_start,
457 double opacity_end) 457 float opacity_end)
458 : gfx::LinearAnimation(kFramerate, this), 458 : gfx::LinearAnimation(kFramerate, this),
459 status_view_(status_view), 459 status_view_(status_view),
460 opacity_start_(opacity_start), 460 opacity_start_(opacity_start),
461 opacity_end_(opacity_end) { 461 opacity_end_(opacity_end) {}
462 }
463 462
464 StatusBubbleViews::StatusViewAnimation::~StatusViewAnimation() { 463 StatusBubbleViews::StatusViewAnimation::~StatusViewAnimation() {
465 // Remove ourself as a delegate so that we don't get notified when 464 // Remove ourself as a delegate so that we don't get notified when
466 // animations end as a result of destruction. 465 // animations end as a result of destruction.
467 set_delegate(NULL); 466 set_delegate(NULL);
468 } 467 }
469 468
470 double StatusBubbleViews::StatusViewAnimation::GetCurrentOpacity() { 469 float StatusBubbleViews::StatusViewAnimation::GetCurrentOpacity() {
471 return opacity_start_ + (opacity_end_ - opacity_start_) * 470 return static_cast<float>(opacity_start_ +
472 gfx::LinearAnimation::GetCurrentValue(); 471 (opacity_end_ - opacity_start_) *
472 gfx::LinearAnimation::GetCurrentValue());
473 } 473 }
474 474
475 void StatusBubbleViews::StatusViewAnimation::AnimateToState(double state) { 475 void StatusBubbleViews::StatusViewAnimation::AnimateToState(double state) {
476 status_view_->SetOpacity(GetCurrentOpacity()); 476 status_view_->SetOpacity(GetCurrentOpacity());
477 } 477 }
478 478
479 void StatusBubbleViews::StatusViewAnimation::AnimationEnded( 479 void StatusBubbleViews::StatusViewAnimation::AnimationEnded(
480 const gfx::Animation* animation) { 480 const gfx::Animation* animation) {
481 status_view_->SetOpacity(opacity_end_); 481 status_view_->SetOpacity(opacity_end_);
482 status_view_->OnAnimationEnded(); 482 status_view_->OnAnimationEnded();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 params.parent = frame->GetNativeView(); 607 params.parent = frame->GetNativeView();
608 params.context = frame->GetNativeWindow(); 608 params.context = frame->GetNativeWindow();
609 #if defined(MOJO_SHELL_CLIENT) 609 #if defined(MOJO_SHELL_CLIENT)
610 params.mus_properties 610 params.mus_properties
611 [mus::mojom::WindowManager::kWindowIgnoredByShelf_Property] = 611 [mus::mojom::WindowManager::kWindowIgnoredByShelf_Property] =
612 mojo::ConvertTo<std::vector<uint8_t>>(true); 612 mojo::ConvertTo<std::vector<uint8_t>>(true);
613 #endif 613 #endif
614 popup_->Init(params); 614 popup_->Init(params);
615 // We do our own animation and don't want any from the system. 615 // We do our own animation and don't want any from the system.
616 popup_->SetVisibilityChangedAnimationsEnabled(false); 616 popup_->SetVisibilityChangedAnimationsEnabled(false);
617 popup_->SetOpacity(0x00); 617 popup_->SetOpacity(0.f);
618 popup_->SetContentsView(view_); 618 popup_->SetContentsView(view_);
619 #if defined(USE_ASH) 619 #if defined(USE_ASH)
620 ash::wm::GetWindowState(popup_->GetNativeWindow())-> 620 ash::wm::GetWindowState(popup_->GetNativeWindow())->
621 set_ignored_by_shelf(true); 621 set_ignored_by_shelf(true);
622 #endif 622 #endif
623 RepositionPopup(); 623 RepositionPopup();
624 } 624 }
625 } 625 }
626 626
627 void StatusBubbleViews::Reposition() { 627 void StatusBubbleViews::Reposition() {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 void StatusBubbleViews::SetBubbleWidth(int width) { 900 void StatusBubbleViews::SetBubbleWidth(int width) {
901 size_.set_width(width); 901 size_.set_width(width);
902 SetBounds(original_position_.x(), original_position_.y(), 902 SetBounds(original_position_.x(), original_position_.y(),
903 size_.width(), size_.height()); 903 size_.width(), size_.height());
904 } 904 }
905 905
906 void StatusBubbleViews::CancelExpandTimer() { 906 void StatusBubbleViews::CancelExpandTimer() {
907 if (expand_timer_factory_.HasWeakPtrs()) 907 if (expand_timer_factory_.HasWeakPtrs())
908 expand_timer_factory_.InvalidateWeakPtrs(); 908 expand_timer_factory_.InvalidateWeakPtrs();
909 } 909 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/screen_capture_notification_ui_views.cc ('k') | ui/views/mus/native_widget_mus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698