| 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/location.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/thread_task_runner_handle.h" |
| 14 #include "chrome/browser/themes/theme_properties.h" | 16 #include "chrome/browser/themes/theme_properties.h" |
| 15 #include "chrome/browser/ui/elide_url.h" | 17 #include "chrome/browser/ui/elide_url.h" |
| 16 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 17 #include "third_party/skia/include/core/SkPaint.h" | 19 #include "third_party/skia/include/core/SkPaint.h" |
| 18 #include "third_party/skia/include/core/SkRect.h" | 20 #include "third_party/skia/include/core/SkRect.h" |
| 19 #include "ui/base/theme_provider.h" | 21 #include "ui/base/theme_provider.h" |
| 20 #include "ui/gfx/animation/animation_delegate.h" | 22 #include "ui/gfx/animation/animation_delegate.h" |
| 21 #include "ui/gfx/animation/linear_animation.h" | 23 #include "ui/gfx/animation/linear_animation.h" |
| 22 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
| 23 #include "ui/gfx/font_list.h" | 25 #include "ui/gfx/font_list.h" |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 SetOpacity(0.0); | 237 SetOpacity(0.0); |
| 236 text_.clear(); | 238 text_.clear(); |
| 237 popup_->Hide(); | 239 popup_->Hide(); |
| 238 state_ = BUBBLE_HIDDEN; | 240 state_ = BUBBLE_HIDDEN; |
| 239 } | 241 } |
| 240 | 242 |
| 241 void StatusBubbleViews::StatusView::StartTimer(base::TimeDelta time) { | 243 void StatusBubbleViews::StatusView::StartTimer(base::TimeDelta time) { |
| 242 if (timer_factory_.HasWeakPtrs()) | 244 if (timer_factory_.HasWeakPtrs()) |
| 243 timer_factory_.InvalidateWeakPtrs(); | 245 timer_factory_.InvalidateWeakPtrs(); |
| 244 | 246 |
| 245 base::MessageLoop::current()->PostDelayedTask( | 247 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 246 FROM_HERE, | 248 FROM_HERE, base::Bind(&StatusBubbleViews::StatusView::OnTimer, |
| 247 base::Bind(&StatusBubbleViews::StatusView::OnTimer, | 249 timer_factory_.GetWeakPtr()), |
| 248 timer_factory_.GetWeakPtr()), | |
| 249 time); | 250 time); |
| 250 } | 251 } |
| 251 | 252 |
| 252 void StatusBubbleViews::StatusView::OnTimer() { | 253 void StatusBubbleViews::StatusView::OnTimer() { |
| 253 if (state_ == BUBBLE_HIDING_TIMER) { | 254 if (state_ == BUBBLE_HIDING_TIMER) { |
| 254 state_ = BUBBLE_HIDING_FADE; | 255 state_ = BUBBLE_HIDING_FADE; |
| 255 StartFade(1.0, 0.0, kHideFadeDurationMS); | 256 StartFade(1.0, 0.0, kHideFadeDurationMS); |
| 256 } else if (state_ == BUBBLE_SHOWING_TIMER) { | 257 } else if (state_ == BUBBLE_SHOWING_TIMER) { |
| 257 state_ = BUBBLE_SHOWING_FADE; | 258 state_ = BUBBLE_SHOWING_FADE; |
| 258 StartFade(0.0, 1.0, kShowFadeDurationMS); | 259 StartFade(0.0, 1.0, kShowFadeDurationMS); |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 if (IsFrameVisible()) { | 693 if (IsFrameVisible()) { |
| 693 view_->SetText(url_text_, true); | 694 view_->SetText(url_text_, true); |
| 694 | 695 |
| 695 CancelExpandTimer(); | 696 CancelExpandTimer(); |
| 696 | 697 |
| 697 // If bubble is already in expanded state, shift to adjust to new text | 698 // If bubble is already in expanded state, shift to adjust to new text |
| 698 // size (shrinking or expanding). Otherwise delay. | 699 // size (shrinking or expanding). Otherwise delay. |
| 699 if (is_expanded_ && !url.is_empty()) { | 700 if (is_expanded_ && !url.is_empty()) { |
| 700 ExpandBubble(); | 701 ExpandBubble(); |
| 701 } else if (net::FormatUrl(url, languages).length() > url_text_.length()) { | 702 } else if (net::FormatUrl(url, languages).length() > url_text_.length()) { |
| 702 base::MessageLoop::current()->PostDelayedTask( | 703 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 703 FROM_HERE, | 704 FROM_HERE, base::Bind(&StatusBubbleViews::ExpandBubble, |
| 704 base::Bind(&StatusBubbleViews::ExpandBubble, | 705 expand_timer_factory_.GetWeakPtr()), |
| 705 expand_timer_factory_.GetWeakPtr()), | |
| 706 base::TimeDelta::FromMilliseconds(kExpandHoverDelayMS)); | 706 base::TimeDelta::FromMilliseconds(kExpandHoverDelayMS)); |
| 707 } | 707 } |
| 708 } | 708 } |
| 709 } | 709 } |
| 710 | 710 |
| 711 void StatusBubbleViews::Hide() { | 711 void StatusBubbleViews::Hide() { |
| 712 status_text_ = base::string16(); | 712 status_text_ = base::string16(); |
| 713 url_text_ = base::string16(); | 713 url_text_ = base::string16(); |
| 714 if (view_) | 714 if (view_) |
| 715 view_->Hide(); | 715 view_->Hide(); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 void StatusBubbleViews::SetBubbleWidth(int width) { | 872 void StatusBubbleViews::SetBubbleWidth(int width) { |
| 873 size_.set_width(width); | 873 size_.set_width(width); |
| 874 SetBounds(original_position_.x(), original_position_.y(), | 874 SetBounds(original_position_.x(), original_position_.y(), |
| 875 size_.width(), size_.height()); | 875 size_.width(), size_.height()); |
| 876 } | 876 } |
| 877 | 877 |
| 878 void StatusBubbleViews::CancelExpandTimer() { | 878 void StatusBubbleViews::CancelExpandTimer() { |
| 879 if (expand_timer_factory_.HasWeakPtrs()) | 879 if (expand_timer_factory_.HasWeakPtrs()) |
| 880 expand_timer_factory_.InvalidateWeakPtrs(); | 880 expand_timer_factory_.InvalidateWeakPtrs(); |
| 881 } | 881 } |
| OLD | NEW |