| 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.h" | 9 #include "app/linear_animation.h" |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
| 12 #include "app/text_elider.h" | 12 #include "app/text_elider.h" |
| 13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "chrome/browser/browser_theme_provider.h" | 16 #include "chrome/browser/browser_theme_provider.h" |
| 17 #include "gfx/canvas.h" | 17 #include "gfx/canvas.h" |
| 18 #include "gfx/point.h" | 18 #include "gfx/point.h" |
| 19 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 static const int kFramerate = 25; | 61 static const int kFramerate = 25; |
| 62 | 62 |
| 63 // How long each expansion step should take. | 63 // How long each expansion step should take. |
| 64 static const int kMinExpansionStepDurationMS = 20; | 64 static const int kMinExpansionStepDurationMS = 20; |
| 65 static const int kMaxExpansionStepDurationMS = 150; | 65 static const int kMaxExpansionStepDurationMS = 150; |
| 66 | 66 |
| 67 // View ----------------------------------------------------------------------- | 67 // View ----------------------------------------------------------------------- |
| 68 // StatusView manages the display of the bubble, applying text changes and | 68 // StatusView manages the display of the bubble, applying text changes and |
| 69 // fading in or out the bubble as required. | 69 // fading in or out the bubble as required. |
| 70 class StatusBubbleViews::StatusView : public views::Label, | 70 class StatusBubbleViews::StatusView : public views::Label, |
| 71 public Animation, | 71 public LinearAnimation, |
| 72 public AnimationDelegate { | 72 public AnimationDelegate { |
| 73 public: | 73 public: |
| 74 StatusView(StatusBubble* status_bubble, views::Widget* popup, | 74 StatusView(StatusBubble* status_bubble, views::Widget* popup, |
| 75 ThemeProvider* theme_provider) | 75 ThemeProvider* theme_provider) |
| 76 : ALLOW_THIS_IN_INITIALIZER_LIST(Animation(kFramerate, this)), | 76 : ALLOW_THIS_IN_INITIALIZER_LIST(LinearAnimation(kFramerate, this)), |
| 77 stage_(BUBBLE_HIDDEN), | 77 stage_(BUBBLE_HIDDEN), |
| 78 style_(STYLE_STANDARD), | 78 style_(STYLE_STANDARD), |
| 79 ALLOW_THIS_IN_INITIALIZER_LIST(timer_factory_(this)), | 79 ALLOW_THIS_IN_INITIALIZER_LIST(timer_factory_(this)), |
| 80 status_bubble_(status_bubble), | 80 status_bubble_(status_bubble), |
| 81 popup_(popup), | 81 popup_(popup), |
| 82 opacity_start_(0), | 82 opacity_start_(0), |
| 83 opacity_end_(0), | 83 opacity_end_(0), |
| 84 theme_provider_(theme_provider) { | 84 theme_provider_(theme_provider) { |
| 85 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 85 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 86 gfx::Font font(rb.GetFont(ResourceBundle::BaseFont)); | 86 gfx::Font font(rb.GetFont(ResourceBundle::BaseFont)); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 } else if (stage_ == BUBBLE_SHOWING_TIMER) { | 303 } else if (stage_ == BUBBLE_SHOWING_TIMER) { |
| 304 // We hadn't yet begun showing anything when we received a new request | 304 // We hadn't yet begun showing anything when we received a new request |
| 305 // for something to show, so we start from scratch. | 305 // for something to show, so we start from scratch. |
| 306 ResetTimer(); | 306 ResetTimer(); |
| 307 } | 307 } |
| 308 } | 308 } |
| 309 | 309 |
| 310 // Animation functions. | 310 // Animation functions. |
| 311 double StatusBubbleViews::StatusView::GetCurrentOpacity() { | 311 double StatusBubbleViews::StatusView::GetCurrentOpacity() { |
| 312 return opacity_start_ + (opacity_end_ - opacity_start_) * | 312 return opacity_start_ + (opacity_end_ - opacity_start_) * |
| 313 Animation::GetCurrentValue(); | 313 LinearAnimation::GetCurrentValue(); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void StatusBubbleViews::StatusView::SetOpacity(double opacity) { | 316 void StatusBubbleViews::StatusView::SetOpacity(double opacity) { |
| 317 popup_->SetOpacity(static_cast<unsigned char>(opacity * 255)); | 317 popup_->SetOpacity(static_cast<unsigned char>(opacity * 255)); |
| 318 SchedulePaint(); | 318 SchedulePaint(); |
| 319 } | 319 } |
| 320 | 320 |
| 321 void StatusBubbleViews::StatusView::AnimateToState(double state) { | 321 void StatusBubbleViews::StatusView::AnimateToState(double state) { |
| 322 SetOpacity(GetCurrentOpacity()); | 322 SetOpacity(GetCurrentOpacity()); |
| 323 } | 323 } |
| (...skipping 134 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 Animation, | 468 class StatusBubbleViews::StatusViewExpander : public LinearAnimation, |
| 469 public AnimationDelegate { | 469 public AnimationDelegate { |
| 470 public: | 470 public: |
| 471 StatusViewExpander(StatusBubble* status_bubble, | 471 StatusViewExpander(StatusBubble* status_bubble, |
| 472 StatusView* status_view) | 472 StatusView* status_view) |
| 473 : ALLOW_THIS_IN_INITIALIZER_LIST(Animation(kFramerate, this)), | 473 : ALLOW_THIS_IN_INITIALIZER_LIST(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(std::wstring expanded_text, int current_width, | 481 void StartExpansion(std::wstring expanded_text, int current_width, |
| 482 int expansion_end); | 482 int expansion_end); |
| 483 | 483 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 expansion_end_ = expansion_end; | 523 expansion_end_ = expansion_end; |
| 524 int min_duration = std::max(kMinExpansionStepDurationMS, | 524 int min_duration = std::max(kMinExpansionStepDurationMS, |
| 525 static_cast<int>(kMaxExpansionStepDurationMS * | 525 static_cast<int>(kMaxExpansionStepDurationMS * |
| 526 (expansion_end - expansion_start) / 100.0)); | 526 (expansion_end - expansion_start) / 100.0)); |
| 527 SetDuration(std::min(kMaxExpansionStepDurationMS, min_duration)); | 527 SetDuration(std::min(kMaxExpansionStepDurationMS, min_duration)); |
| 528 Start(); | 528 Start(); |
| 529 } | 529 } |
| 530 | 530 |
| 531 int StatusBubbleViews::StatusViewExpander::GetCurrentBubbleWidth() { | 531 int StatusBubbleViews::StatusViewExpander::GetCurrentBubbleWidth() { |
| 532 return static_cast<int>(expansion_start_ + | 532 return static_cast<int>(expansion_start_ + |
| 533 (expansion_end_ - expansion_start_) * Animation::GetCurrentValue()); | 533 (expansion_end_ - expansion_start_) * LinearAnimation::GetCurrentValue()); |
| 534 } | 534 } |
| 535 | 535 |
| 536 void StatusBubbleViews::StatusViewExpander::SetBubbleWidth(int width) { | 536 void StatusBubbleViews::StatusViewExpander::SetBubbleWidth(int width) { |
| 537 status_bubble_->SetBubbleWidth(width); | 537 status_bubble_->SetBubbleWidth(width); |
| 538 status_view_->SchedulePaint(); | 538 status_view_->SchedulePaint(); |
| 539 } | 539 } |
| 540 | 540 |
| 541 // StatusBubble --------------------------------------------------------------- | 541 // StatusBubble --------------------------------------------------------------- |
| 542 | 542 |
| 543 const int StatusBubbleViews::kShadowThickness = 1; | 543 const int StatusBubbleViews::kShadowThickness = 1; |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 | 842 |
| 843 void StatusBubbleViews::SetBubbleWidth(int width) { | 843 void StatusBubbleViews::SetBubbleWidth(int width) { |
| 844 size_.set_width(width); | 844 size_.set_width(width); |
| 845 SetBounds(position_.x(), position_.y(), size_.width(), size_.height()); | 845 SetBounds(position_.x(), position_.y(), size_.width(), size_.height()); |
| 846 } | 846 } |
| 847 | 847 |
| 848 void StatusBubbleViews::CancelExpandTimer() { | 848 void StatusBubbleViews::CancelExpandTimer() { |
| 849 if (!expand_timer_factory_.empty()) | 849 if (!expand_timer_factory_.empty()) |
| 850 expand_timer_factory_.RevokeAll(); | 850 expand_timer_factory_.RevokeAll(); |
| 851 } | 851 } |
| OLD | NEW |