OLD | NEW |
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" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/themes/theme_properties.h" | 14 #include "chrome/browser/themes/theme_properties.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
17 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
18 #include "third_party/skia/include/core/SkPaint.h" | 18 #include "third_party/skia/include/core/SkPaint.h" |
19 #include "third_party/skia/include/core/SkPath.h" | 19 #include "third_party/skia/include/core/SkPath.h" |
20 #include "third_party/skia/include/core/SkRect.h" | 20 #include "third_party/skia/include/core/SkRect.h" |
21 #include "ui/base/animation/animation_delegate.h" | |
22 #include "ui/base/animation/linear_animation.h" | |
23 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
24 #include "ui/base/theme_provider.h" | 22 #include "ui/base/theme_provider.h" |
| 23 #include "ui/gfx/animation/animation_delegate.h" |
| 24 #include "ui/gfx/animation/linear_animation.h" |
25 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
26 #include "ui/gfx/point.h" | 26 #include "ui/gfx/point.h" |
27 #include "ui/gfx/screen.h" | 27 #include "ui/gfx/screen.h" |
28 #include "ui/gfx/skia_util.h" | 28 #include "ui/gfx/skia_util.h" |
29 #include "ui/gfx/text_elider.h" | 29 #include "ui/gfx/text_elider.h" |
30 #include "ui/native_theme/native_theme.h" | 30 #include "ui/native_theme/native_theme.h" |
31 #include "ui/views/controls/label.h" | 31 #include "ui/views/controls/label.h" |
32 #include "ui/views/controls/scrollbar/native_scroll_bar.h" | 32 #include "ui/views/controls/scrollbar/native_scroll_bar.h" |
33 #include "ui/views/widget/root_view.h" | 33 #include "ui/views/widget/root_view.h" |
34 #include "ui/views/widget/widget.h" | 34 #include "ui/views/widget/widget.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 static const int kFramerate = 25; | 67 static const int kFramerate = 25; |
68 | 68 |
69 // How long each expansion step should take. | 69 // How long each expansion step should take. |
70 static const int kMinExpansionStepDurationMS = 20; | 70 static const int kMinExpansionStepDurationMS = 20; |
71 static const int kMaxExpansionStepDurationMS = 150; | 71 static const int kMaxExpansionStepDurationMS = 150; |
72 | 72 |
73 // View ----------------------------------------------------------------------- | 73 // View ----------------------------------------------------------------------- |
74 // StatusView manages the display of the bubble, applying text changes and | 74 // StatusView manages the display of the bubble, applying text changes and |
75 // fading in or out the bubble as required. | 75 // fading in or out the bubble as required. |
76 class StatusBubbleViews::StatusView : public views::Label, | 76 class StatusBubbleViews::StatusView : public views::Label, |
77 public ui::LinearAnimation, | 77 public gfx::LinearAnimation, |
78 public ui::AnimationDelegate { | 78 public gfx::AnimationDelegate { |
79 public: | 79 public: |
80 StatusView(StatusBubble* status_bubble, | 80 StatusView(StatusBubble* status_bubble, |
81 views::Widget* popup, | 81 views::Widget* popup, |
82 ui::ThemeProvider* theme_provider) | 82 ui::ThemeProvider* theme_provider) |
83 : ui::LinearAnimation(kFramerate, this), | 83 : gfx::LinearAnimation(kFramerate, this), |
84 stage_(BUBBLE_HIDDEN), | 84 stage_(BUBBLE_HIDDEN), |
85 style_(STYLE_STANDARD), | 85 style_(STYLE_STANDARD), |
86 timer_factory_(this), | 86 timer_factory_(this), |
87 status_bubble_(status_bubble), | 87 status_bubble_(status_bubble), |
88 popup_(popup), | 88 popup_(popup), |
89 opacity_start_(0), | 89 opacity_start_(0), |
90 opacity_end_(0), | 90 opacity_end_(0), |
91 theme_service_(theme_provider) { | 91 theme_service_(theme_provider) { |
92 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 92 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
93 SetFont(rb.GetFont(ui::ResourceBundle::BaseFont)); | 93 SetFont(rb.GetFont(ui::ResourceBundle::BaseFont)); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } else if (stage_ == BUBBLE_SHOWING_TIMER) { | 307 } else if (stage_ == BUBBLE_SHOWING_TIMER) { |
308 // We hadn't yet begun showing anything when we received a new request | 308 // We hadn't yet begun showing anything when we received a new request |
309 // for something to show, so we start from scratch. | 309 // for something to show, so we start from scratch. |
310 ResetTimer(); | 310 ResetTimer(); |
311 } | 311 } |
312 } | 312 } |
313 | 313 |
314 // Animation functions. | 314 // Animation functions. |
315 double StatusBubbleViews::StatusView::GetCurrentOpacity() { | 315 double StatusBubbleViews::StatusView::GetCurrentOpacity() { |
316 return opacity_start_ + (opacity_end_ - opacity_start_) * | 316 return opacity_start_ + (opacity_end_ - opacity_start_) * |
317 ui::LinearAnimation::GetCurrentValue(); | 317 gfx::LinearAnimation::GetCurrentValue(); |
318 } | 318 } |
319 | 319 |
320 void StatusBubbleViews::StatusView::SetOpacity(double opacity) { | 320 void StatusBubbleViews::StatusView::SetOpacity(double opacity) { |
321 popup_->SetOpacity(static_cast<unsigned char>(opacity * 255)); | 321 popup_->SetOpacity(static_cast<unsigned char>(opacity * 255)); |
322 } | 322 } |
323 | 323 |
324 void StatusBubbleViews::StatusView::AnimateToState(double state) { | 324 void StatusBubbleViews::StatusView::AnimateToState(double state) { |
325 SetOpacity(GetCurrentOpacity()); | 325 SetOpacity(GetCurrentOpacity()); |
326 } | 326 } |
327 | 327 |
328 void StatusBubbleViews::StatusView::AnimationEnded( | 328 void StatusBubbleViews::StatusView::AnimationEnded( |
329 const ui::Animation* animation) { | 329 const gfx::Animation* animation) { |
330 SetOpacity(opacity_end_); | 330 SetOpacity(opacity_end_); |
331 | 331 |
332 if (stage_ == BUBBLE_HIDING_FADE) { | 332 if (stage_ == BUBBLE_HIDING_FADE) { |
333 stage_ = BUBBLE_HIDDEN; | 333 stage_ = BUBBLE_HIDDEN; |
334 popup_->Hide(); | 334 popup_->Hide(); |
335 } else if (stage_ == BUBBLE_SHOWING_FADE) { | 335 } else if (stage_ == BUBBLE_SHOWING_FADE) { |
336 stage_ = BUBBLE_SHOWN; | 336 stage_ = BUBBLE_SHOWN; |
337 } | 337 } |
338 } | 338 } |
339 | 339 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 body_bounds.x(), | 458 body_bounds.x(), |
459 body_bounds.y(), | 459 body_bounds.y(), |
460 body_bounds.width(), | 460 body_bounds.width(), |
461 body_bounds.height()); | 461 body_bounds.height()); |
462 } | 462 } |
463 | 463 |
464 // StatusViewExpander --------------------------------------------------------- | 464 // StatusViewExpander --------------------------------------------------------- |
465 // Manages the expansion and contraction of the status bubble as it accommodates | 465 // Manages the expansion and contraction of the status bubble as it accommodates |
466 // URLs too long to fit in the standard bubble. Changes are passed through the | 466 // URLs too long to fit in the standard bubble. Changes are passed through the |
467 // StatusView to paint. | 467 // StatusView to paint. |
468 class StatusBubbleViews::StatusViewExpander : public ui::LinearAnimation, | 468 class StatusBubbleViews::StatusViewExpander : public gfx::LinearAnimation, |
469 public ui::AnimationDelegate { | 469 public gfx::AnimationDelegate { |
470 public: | 470 public: |
471 StatusViewExpander(StatusBubbleViews* status_bubble, | 471 StatusViewExpander(StatusBubbleViews* status_bubble, |
472 StatusView* status_view) | 472 StatusView* status_view) |
473 : ui::LinearAnimation(kFramerate, this), | 473 : gfx::LinearAnimation(kFramerate, this), |
474 status_bubble_(status_bubble), | 474 status_bubble_(status_bubble), |
475 status_view_(status_view), | 475 status_view_(status_view), |
476 expansion_start_(0), | 476 expansion_start_(0), |
477 expansion_end_(0) { | 477 expansion_end_(0) { |
478 } | 478 } |
479 | 479 |
480 // Manage the expansion of the bubble. | 480 // Manage the expansion of the bubble. |
481 void StartExpansion(const string16& expanded_text, | 481 void StartExpansion(const string16& expanded_text, |
482 int current_width, | 482 int current_width, |
483 int expansion_end); | 483 int expansion_end); |
484 | 484 |
485 // Set width of fully expanded bubble. | 485 // Set width of fully expanded bubble. |
486 void SetExpandedWidth(int expanded_width); | 486 void SetExpandedWidth(int expanded_width); |
487 | 487 |
488 private: | 488 private: |
489 // Animation functions. | 489 // Animation functions. |
490 int GetCurrentBubbleWidth(); | 490 int GetCurrentBubbleWidth(); |
491 void SetBubbleWidth(int width); | 491 void SetBubbleWidth(int width); |
492 virtual void AnimateToState(double state) OVERRIDE; | 492 virtual void AnimateToState(double state) OVERRIDE; |
493 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; | 493 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; |
494 | 494 |
495 // Manager that owns us. | 495 // Manager that owns us. |
496 StatusBubbleViews* status_bubble_; | 496 StatusBubbleViews* status_bubble_; |
497 | 497 |
498 // Change the bounds and text of this view. | 498 // Change the bounds and text of this view. |
499 StatusView* status_view_; | 499 StatusView* status_view_; |
500 | 500 |
501 // Text elided (if needed) to fit maximum status bar width. | 501 // Text elided (if needed) to fit maximum status bar width. |
502 string16 expanded_text_; | 502 string16 expanded_text_; |
503 | 503 |
504 // Widths at expansion start and end. | 504 // Widths at expansion start and end. |
505 int expansion_start_; | 505 int expansion_start_; |
506 int expansion_end_; | 506 int expansion_end_; |
507 }; | 507 }; |
508 | 508 |
509 void StatusBubbleViews::StatusViewExpander::AnimateToState(double state) { | 509 void StatusBubbleViews::StatusViewExpander::AnimateToState(double state) { |
510 SetBubbleWidth(GetCurrentBubbleWidth()); | 510 SetBubbleWidth(GetCurrentBubbleWidth()); |
511 } | 511 } |
512 | 512 |
513 void StatusBubbleViews::StatusViewExpander::AnimationEnded( | 513 void StatusBubbleViews::StatusViewExpander::AnimationEnded( |
514 const ui::Animation* animation) { | 514 const gfx::Animation* animation) { |
515 SetBubbleWidth(expansion_end_); | 515 SetBubbleWidth(expansion_end_); |
516 status_view_->SetText(expanded_text_, false); | 516 status_view_->SetText(expanded_text_, false); |
517 } | 517 } |
518 | 518 |
519 void StatusBubbleViews::StatusViewExpander::StartExpansion( | 519 void StatusBubbleViews::StatusViewExpander::StartExpansion( |
520 const string16& expanded_text, | 520 const string16& expanded_text, |
521 int expansion_start, | 521 int expansion_start, |
522 int expansion_end) { | 522 int expansion_end) { |
523 expanded_text_ = expanded_text; | 523 expanded_text_ = expanded_text; |
524 expansion_start_ = expansion_start; | 524 expansion_start_ = expansion_start; |
525 expansion_end_ = expansion_end; | 525 expansion_end_ = expansion_end; |
526 int min_duration = std::max(kMinExpansionStepDurationMS, | 526 int min_duration = std::max(kMinExpansionStepDurationMS, |
527 static_cast<int>(kMaxExpansionStepDurationMS * | 527 static_cast<int>(kMaxExpansionStepDurationMS * |
528 (expansion_end - expansion_start) / 100.0)); | 528 (expansion_end - expansion_start) / 100.0)); |
529 SetDuration(std::min(kMaxExpansionStepDurationMS, min_duration)); | 529 SetDuration(std::min(kMaxExpansionStepDurationMS, min_duration)); |
530 Start(); | 530 Start(); |
531 } | 531 } |
532 | 532 |
533 int StatusBubbleViews::StatusViewExpander::GetCurrentBubbleWidth() { | 533 int StatusBubbleViews::StatusViewExpander::GetCurrentBubbleWidth() { |
534 return static_cast<int>(expansion_start_ + | 534 return static_cast<int>(expansion_start_ + |
535 (expansion_end_ - expansion_start_) * | 535 (expansion_end_ - expansion_start_) * |
536 ui::LinearAnimation::GetCurrentValue()); | 536 gfx::LinearAnimation::GetCurrentValue()); |
537 } | 537 } |
538 | 538 |
539 void StatusBubbleViews::StatusViewExpander::SetBubbleWidth(int width) { | 539 void StatusBubbleViews::StatusViewExpander::SetBubbleWidth(int width) { |
540 status_bubble_->SetBubbleWidth(width); | 540 status_bubble_->SetBubbleWidth(width); |
541 status_view_->SchedulePaint(); | 541 status_view_->SchedulePaint(); |
542 } | 542 } |
543 | 543 |
544 // StatusBubble --------------------------------------------------------------- | 544 // StatusBubble --------------------------------------------------------------- |
545 | 545 |
546 const int StatusBubbleViews::kShadowThickness = 1; | 546 const int StatusBubbleViews::kShadowThickness = 1; |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 void StatusBubbleViews::SetBubbleWidth(int width) { | 847 void StatusBubbleViews::SetBubbleWidth(int width) { |
848 size_.set_width(width); | 848 size_.set_width(width); |
849 SetBounds(original_position_.x(), original_position_.y(), | 849 SetBounds(original_position_.x(), original_position_.y(), |
850 size_.width(), size_.height()); | 850 size_.width(), size_.height()); |
851 } | 851 } |
852 | 852 |
853 void StatusBubbleViews::CancelExpandTimer() { | 853 void StatusBubbleViews::CancelExpandTimer() { |
854 if (expand_timer_factory_.HasWeakPtrs()) | 854 if (expand_timer_factory_.HasWeakPtrs()) |
855 expand_timer_factory_.InvalidateWeakPtrs(); | 855 expand_timer_factory_.InvalidateWeakPtrs(); |
856 } | 856 } |
OLD | NEW |