OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/status_bubble_views.h" | 5 #include "chrome/browser/views/status_bubble_views.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/animation_delegate.h" | |
10 #include "app/linear_animation.h" | |
11 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
12 #include "app/text_elider.h" | 10 #include "app/text_elider.h" |
13 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
14 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
15 #include "base/string_util.h" | 13 #include "base/string_util.h" |
16 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
17 #include "chrome/browser/themes/browser_theme_provider.h" | 15 #include "chrome/browser/themes/browser_theme_provider.h" |
18 #include "gfx/canvas_skia.h" | 16 #include "gfx/canvas_skia.h" |
19 #include "gfx/point.h" | 17 #include "gfx/point.h" |
20 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
21 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
22 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
23 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
24 #include "third_party/skia/include/core/SkPaint.h" | 22 #include "third_party/skia/include/core/SkPaint.h" |
25 #include "third_party/skia/include/core/SkPath.h" | 23 #include "third_party/skia/include/core/SkPath.h" |
26 #include "third_party/skia/include/core/SkRect.h" | 24 #include "third_party/skia/include/core/SkRect.h" |
| 25 #include "ui/base/animation/animation_delegate.h" |
| 26 #include "ui/base/animation/linear_animation.h" |
27 #include "views/controls/label.h" | 27 #include "views/controls/label.h" |
28 #include "views/controls/scrollbar/native_scroll_bar.h" | 28 #include "views/controls/scrollbar/native_scroll_bar.h" |
29 #include "views/screen.h" | 29 #include "views/screen.h" |
30 #include "views/widget/root_view.h" | 30 #include "views/widget/root_view.h" |
31 #include "views/widget/widget.h" | 31 #include "views/widget/widget.h" |
32 #include "views/window/window.h" | 32 #include "views/window/window.h" |
33 | 33 |
34 using views::Widget; | 34 using views::Widget; |
35 | 35 |
36 // The alpha and color of the bubble's shadow. | 36 // The alpha and color of the bubble's shadow. |
(...skipping 25 matching lines...) Expand all Loading... |
62 static const int kFramerate = 25; | 62 static const int kFramerate = 25; |
63 | 63 |
64 // How long each expansion step should take. | 64 // How long each expansion step should take. |
65 static const int kMinExpansionStepDurationMS = 20; | 65 static const int kMinExpansionStepDurationMS = 20; |
66 static const int kMaxExpansionStepDurationMS = 150; | 66 static const int kMaxExpansionStepDurationMS = 150; |
67 | 67 |
68 // View ----------------------------------------------------------------------- | 68 // View ----------------------------------------------------------------------- |
69 // StatusView manages the display of the bubble, applying text changes and | 69 // StatusView manages the display of the bubble, applying text changes and |
70 // fading in or out the bubble as required. | 70 // fading in or out the bubble as required. |
71 class StatusBubbleViews::StatusView : public views::Label, | 71 class StatusBubbleViews::StatusView : public views::Label, |
72 public LinearAnimation, | 72 public ui::LinearAnimation, |
73 public AnimationDelegate { | 73 public ui::AnimationDelegate { |
74 public: | 74 public: |
75 StatusView(StatusBubble* status_bubble, views::Widget* popup, | 75 StatusView(StatusBubble* status_bubble, views::Widget* popup, |
76 ThemeProvider* theme_provider) | 76 ThemeProvider* theme_provider) |
77 : ALLOW_THIS_IN_INITIALIZER_LIST(LinearAnimation(kFramerate, this)), | 77 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::LinearAnimation(kFramerate, this)), |
78 stage_(BUBBLE_HIDDEN), | 78 stage_(BUBBLE_HIDDEN), |
79 style_(STYLE_STANDARD), | 79 style_(STYLE_STANDARD), |
80 ALLOW_THIS_IN_INITIALIZER_LIST(timer_factory_(this)), | 80 ALLOW_THIS_IN_INITIALIZER_LIST(timer_factory_(this)), |
81 status_bubble_(status_bubble), | 81 status_bubble_(status_bubble), |
82 popup_(popup), | 82 popup_(popup), |
83 opacity_start_(0), | 83 opacity_start_(0), |
84 opacity_end_(0), | 84 opacity_end_(0), |
85 theme_provider_(theme_provider) { | 85 theme_provider_(theme_provider) { |
86 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 86 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
87 gfx::Font font(rb.GetFont(ResourceBundle::BaseFont)); | 87 gfx::Font font(rb.GetFont(ResourceBundle::BaseFont)); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } else if (stage_ == BUBBLE_SHOWING_TIMER) { | 297 } else if (stage_ == BUBBLE_SHOWING_TIMER) { |
298 // We hadn't yet begun showing anything when we received a new request | 298 // We hadn't yet begun showing anything when we received a new request |
299 // for something to show, so we start from scratch. | 299 // for something to show, so we start from scratch. |
300 ResetTimer(); | 300 ResetTimer(); |
301 } | 301 } |
302 } | 302 } |
303 | 303 |
304 // Animation functions. | 304 // Animation functions. |
305 double StatusBubbleViews::StatusView::GetCurrentOpacity() { | 305 double StatusBubbleViews::StatusView::GetCurrentOpacity() { |
306 return opacity_start_ + (opacity_end_ - opacity_start_) * | 306 return opacity_start_ + (opacity_end_ - opacity_start_) * |
307 LinearAnimation::GetCurrentValue(); | 307 ui::LinearAnimation::GetCurrentValue(); |
308 } | 308 } |
309 | 309 |
310 void StatusBubbleViews::StatusView::SetOpacity(double opacity) { | 310 void StatusBubbleViews::StatusView::SetOpacity(double opacity) { |
311 popup_->SetOpacity(static_cast<unsigned char>(opacity * 255)); | 311 popup_->SetOpacity(static_cast<unsigned char>(opacity * 255)); |
312 SchedulePaint(); | 312 SchedulePaint(); |
313 } | 313 } |
314 | 314 |
315 void StatusBubbleViews::StatusView::AnimateToState(double state) { | 315 void StatusBubbleViews::StatusView::AnimateToState(double state) { |
316 SetOpacity(GetCurrentOpacity()); | 316 SetOpacity(GetCurrentOpacity()); |
317 } | 317 } |
318 | 318 |
319 void StatusBubbleViews::StatusView::AnimationEnded( | 319 void StatusBubbleViews::StatusView::AnimationEnded( |
320 const Animation* animation) { | 320 const ui::Animation* animation) { |
321 SetOpacity(opacity_end_); | 321 SetOpacity(opacity_end_); |
322 | 322 |
323 if (stage_ == BUBBLE_HIDING_FADE) { | 323 if (stage_ == BUBBLE_HIDING_FADE) { |
324 stage_ = BUBBLE_HIDDEN; | 324 stage_ = BUBBLE_HIDDEN; |
325 popup_->Hide(); | 325 popup_->Hide(); |
326 } else if (stage_ == BUBBLE_SHOWING_FADE) { | 326 } else if (stage_ == BUBBLE_SHOWING_FADE) { |
327 stage_ = BUBBLE_SHOWN; | 327 stage_ = BUBBLE_SHOWN; |
328 } | 328 } |
329 } | 329 } |
330 | 330 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 body_bounds.x(), | 453 body_bounds.x(), |
454 body_bounds.y(), | 454 body_bounds.y(), |
455 body_bounds.width(), | 455 body_bounds.width(), |
456 body_bounds.height()); | 456 body_bounds.height()); |
457 } | 457 } |
458 | 458 |
459 // StatusViewExpander --------------------------------------------------------- | 459 // StatusViewExpander --------------------------------------------------------- |
460 // Manages the expansion and contraction of the status bubble as it accommodates | 460 // Manages the expansion and contraction of the status bubble as it accommodates |
461 // URLs too long to fit in the standard bubble. Changes are passed through the | 461 // URLs too long to fit in the standard bubble. Changes are passed through the |
462 // StatusView to paint. | 462 // StatusView to paint. |
463 class StatusBubbleViews::StatusViewExpander : public LinearAnimation, | 463 class StatusBubbleViews::StatusViewExpander : public ui::LinearAnimation, |
464 public AnimationDelegate { | 464 public ui::AnimationDelegate { |
465 public: | 465 public: |
466 StatusViewExpander(StatusBubbleViews* status_bubble, | 466 StatusViewExpander(StatusBubbleViews* status_bubble, |
467 StatusView* status_view) | 467 StatusView* status_view) |
468 : ALLOW_THIS_IN_INITIALIZER_LIST(LinearAnimation(kFramerate, this)), | 468 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::LinearAnimation(kFramerate, this)), |
469 status_bubble_(status_bubble), | 469 status_bubble_(status_bubble), |
470 status_view_(status_view), | 470 status_view_(status_view), |
471 expansion_start_(0), | 471 expansion_start_(0), |
472 expansion_end_(0) { | 472 expansion_end_(0) { |
473 } | 473 } |
474 | 474 |
475 // Manage the expansion of the bubble. | 475 // Manage the expansion of the bubble. |
476 void StartExpansion(string16 expanded_text, int current_width, | 476 void StartExpansion(string16 expanded_text, int current_width, |
477 int expansion_end); | 477 int expansion_end); |
478 | 478 |
479 // Set width of fully expanded bubble. | 479 // Set width of fully expanded bubble. |
480 void SetExpandedWidth(int expanded_width); | 480 void SetExpandedWidth(int expanded_width); |
481 | 481 |
482 private: | 482 private: |
483 // Animation functions. | 483 // Animation functions. |
484 int GetCurrentBubbleWidth(); | 484 int GetCurrentBubbleWidth(); |
485 void SetBubbleWidth(int width); | 485 void SetBubbleWidth(int width); |
486 void AnimateToState(double state); | 486 void AnimateToState(double state); |
487 void AnimationEnded(const Animation* animation); | 487 void AnimationEnded(const ui::Animation* animation); |
488 | 488 |
489 // Manager that owns us. | 489 // Manager that owns us. |
490 StatusBubbleViews* status_bubble_; | 490 StatusBubbleViews* status_bubble_; |
491 | 491 |
492 // Change the bounds and text of this view. | 492 // Change the bounds and text of this view. |
493 StatusView* status_view_; | 493 StatusView* status_view_; |
494 | 494 |
495 // Text elided (if needed) to fit maximum status bar width. | 495 // Text elided (if needed) to fit maximum status bar width. |
496 string16 expanded_text_; | 496 string16 expanded_text_; |
497 | 497 |
498 // Widths at expansion start and end. | 498 // Widths at expansion start and end. |
499 int expansion_start_; | 499 int expansion_start_; |
500 int expansion_end_; | 500 int expansion_end_; |
501 }; | 501 }; |
502 | 502 |
503 void StatusBubbleViews::StatusViewExpander::AnimateToState(double state) { | 503 void StatusBubbleViews::StatusViewExpander::AnimateToState(double state) { |
504 SetBubbleWidth(GetCurrentBubbleWidth()); | 504 SetBubbleWidth(GetCurrentBubbleWidth()); |
505 } | 505 } |
506 | 506 |
507 void StatusBubbleViews::StatusViewExpander::AnimationEnded( | 507 void StatusBubbleViews::StatusViewExpander::AnimationEnded( |
508 const Animation* animation) { | 508 const ui::Animation* animation) { |
509 SetBubbleWidth(expansion_end_); | 509 SetBubbleWidth(expansion_end_); |
510 status_view_->SetText(expanded_text_, false); | 510 status_view_->SetText(expanded_text_, false); |
511 } | 511 } |
512 | 512 |
513 void StatusBubbleViews::StatusViewExpander::StartExpansion( | 513 void StatusBubbleViews::StatusViewExpander::StartExpansion( |
514 string16 expanded_text, int expansion_start, | 514 string16 expanded_text, int expansion_start, |
515 int expansion_end) { | 515 int expansion_end) { |
516 expanded_text_ = expanded_text; | 516 expanded_text_ = expanded_text; |
517 expansion_start_ = expansion_start; | 517 expansion_start_ = expansion_start; |
518 expansion_end_ = expansion_end; | 518 expansion_end_ = expansion_end; |
519 int min_duration = std::max(kMinExpansionStepDurationMS, | 519 int min_duration = std::max(kMinExpansionStepDurationMS, |
520 static_cast<int>(kMaxExpansionStepDurationMS * | 520 static_cast<int>(kMaxExpansionStepDurationMS * |
521 (expansion_end - expansion_start) / 100.0)); | 521 (expansion_end - expansion_start) / 100.0)); |
522 SetDuration(std::min(kMaxExpansionStepDurationMS, min_duration)); | 522 SetDuration(std::min(kMaxExpansionStepDurationMS, min_duration)); |
523 Start(); | 523 Start(); |
524 } | 524 } |
525 | 525 |
526 int StatusBubbleViews::StatusViewExpander::GetCurrentBubbleWidth() { | 526 int StatusBubbleViews::StatusViewExpander::GetCurrentBubbleWidth() { |
527 return static_cast<int>(expansion_start_ + | 527 return static_cast<int>(expansion_start_ + |
528 (expansion_end_ - expansion_start_) * LinearAnimation::GetCurrentValue()); | 528 (expansion_end_ - expansion_start_) * |
| 529 ui::LinearAnimation::GetCurrentValue()); |
529 } | 530 } |
530 | 531 |
531 void StatusBubbleViews::StatusViewExpander::SetBubbleWidth(int width) { | 532 void StatusBubbleViews::StatusViewExpander::SetBubbleWidth(int width) { |
532 status_bubble_->SetBubbleWidth(width); | 533 status_bubble_->SetBubbleWidth(width); |
533 status_view_->SchedulePaint(); | 534 status_view_->SchedulePaint(); |
534 } | 535 } |
535 | 536 |
536 // StatusBubble --------------------------------------------------------------- | 537 // StatusBubble --------------------------------------------------------------- |
537 | 538 |
538 const int StatusBubbleViews::kShadowThickness = 1; | 539 const int StatusBubbleViews::kShadowThickness = 1; |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 void StatusBubbleViews::SetBubbleWidth(int width) { | 828 void StatusBubbleViews::SetBubbleWidth(int width) { |
828 size_.set_width(width); | 829 size_.set_width(width); |
829 SetBounds(original_position_.x(), original_position_.y(), | 830 SetBounds(original_position_.x(), original_position_.y(), |
830 size_.width(), size_.height()); | 831 size_.width(), size_.height()); |
831 } | 832 } |
832 | 833 |
833 void StatusBubbleViews::CancelExpandTimer() { | 834 void StatusBubbleViews::CancelExpandTimer() { |
834 if (!expand_timer_factory_.empty()) | 835 if (!expand_timer_factory_.empty()) |
835 expand_timer_factory_.RevokeAll(); | 836 expand_timer_factory_.RevokeAll(); |
836 } | 837 } |
OLD | NEW |