| 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/location.h" | 11 #include "base/location.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 16 #include "chrome/browser/themes/theme_properties.h" | 16 #include "chrome/browser/themes/theme_properties.h" |
| 17 #include "components/url_formatter/elide_url.h" | 17 #include "components/secure_display/elide_url.h" |
| 18 #include "components/url_formatter/url_formatter.h" | 18 #include "net/base/net_util.h" |
| 19 #include "third_party/skia/include/core/SkPaint.h" | 19 #include "third_party/skia/include/core/SkPaint.h" |
| 20 #include "third_party/skia/include/core/SkRect.h" | 20 #include "third_party/skia/include/core/SkRect.h" |
| 21 #include "ui/base/theme_provider.h" | 21 #include "ui/base/theme_provider.h" |
| 22 #include "ui/gfx/animation/animation_delegate.h" | 22 #include "ui/gfx/animation/animation_delegate.h" |
| 23 #include "ui/gfx/animation/linear_animation.h" | 23 #include "ui/gfx/animation/linear_animation.h" |
| 24 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
| 25 #include "ui/gfx/font_list.h" | 25 #include "ui/gfx/font_list.h" |
| 26 #include "ui/gfx/geometry/point.h" | 26 #include "ui/gfx/geometry/point.h" |
| 27 #include "ui/gfx/geometry/rect.h" | 27 #include "ui/gfx/geometry/rect.h" |
| 28 #include "ui/gfx/screen.h" | 28 #include "ui/gfx/screen.h" |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 if (view_->state() == StatusView::BUBBLE_HIDDEN) { | 688 if (view_->state() == StatusView::BUBBLE_HIDDEN) { |
| 689 is_expanded_ = false; | 689 is_expanded_ = false; |
| 690 SetBubbleWidth(GetStandardStatusBubbleWidth()); | 690 SetBubbleWidth(GetStandardStatusBubbleWidth()); |
| 691 } | 691 } |
| 692 | 692 |
| 693 // Set Elided Text corresponding to the GURL object. | 693 // Set Elided Text corresponding to the GURL object. |
| 694 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); | 694 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); |
| 695 int text_width = static_cast<int>(popup_bounds.width() - | 695 int text_width = static_cast<int>(popup_bounds.width() - |
| 696 (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1); | 696 (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1); |
| 697 url_text_ = | 697 url_text_ = |
| 698 url_formatter::ElideUrl(url, gfx::FontList(), text_width, languages); | 698 secure_display::ElideUrl(url, gfx::FontList(), text_width, languages); |
| 699 | 699 |
| 700 // An URL is always treated as a left-to-right string. On right-to-left UIs | 700 // An URL is always treated as a left-to-right string. On right-to-left UIs |
| 701 // we need to explicitly mark the URL as LTR to make sure it is displayed | 701 // we need to explicitly mark the URL as LTR to make sure it is displayed |
| 702 // correctly. | 702 // correctly. |
| 703 url_text_ = base::i18n::GetDisplayStringInLTRDirectionality(url_text_); | 703 url_text_ = base::i18n::GetDisplayStringInLTRDirectionality(url_text_); |
| 704 | 704 |
| 705 if (IsFrameVisible()) { | 705 if (IsFrameVisible()) { |
| 706 view_->SetText(url_text_, true); | 706 view_->SetText(url_text_, true); |
| 707 | 707 |
| 708 CancelExpandTimer(); | 708 CancelExpandTimer(); |
| 709 | 709 |
| 710 // If bubble is already in expanded state, shift to adjust to new text | 710 // If bubble is already in expanded state, shift to adjust to new text |
| 711 // size (shrinking or expanding). Otherwise delay. | 711 // size (shrinking or expanding). Otherwise delay. |
| 712 if (is_expanded_ && !url.is_empty()) { | 712 if (is_expanded_ && !url.is_empty()) { |
| 713 ExpandBubble(); | 713 ExpandBubble(); |
| 714 } else if (url_formatter::FormatUrl(url, languages).length() > | 714 } else if (net::FormatUrl(url, languages).length() > url_text_.length()) { |
| 715 url_text_.length()) { | |
| 716 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 715 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 717 FROM_HERE, base::Bind(&StatusBubbleViews::ExpandBubble, | 716 FROM_HERE, base::Bind(&StatusBubbleViews::ExpandBubble, |
| 718 expand_timer_factory_.GetWeakPtr()), | 717 expand_timer_factory_.GetWeakPtr()), |
| 719 base::TimeDelta::FromMilliseconds(kExpandHoverDelayMS)); | 718 base::TimeDelta::FromMilliseconds(kExpandHoverDelayMS)); |
| 720 } | 719 } |
| 721 } | 720 } |
| 722 } | 721 } |
| 723 | 722 |
| 724 void StatusBubbleViews::Hide() { | 723 void StatusBubbleViews::Hide() { |
| 725 status_text_ = base::string16(); | 724 status_text_ = base::string16(); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 views::Widget* window = frame->GetTopLevelWidget(); | 851 views::Widget* window = frame->GetTopLevelWidget(); |
| 853 return window && window->IsMaximized(); | 852 return window && window->IsMaximized(); |
| 854 } | 853 } |
| 855 | 854 |
| 856 void StatusBubbleViews::ExpandBubble() { | 855 void StatusBubbleViews::ExpandBubble() { |
| 857 // Elide URL to maximum possible size, then check actual length (it may | 856 // Elide URL to maximum possible size, then check actual length (it may |
| 858 // still be too long to fit) before expanding bubble. | 857 // still be too long to fit) before expanding bubble. |
| 859 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); | 858 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); |
| 860 int max_status_bubble_width = GetMaxStatusBubbleWidth(); | 859 int max_status_bubble_width = GetMaxStatusBubbleWidth(); |
| 861 const gfx::FontList font_list; | 860 const gfx::FontList font_list; |
| 862 url_text_ = url_formatter::ElideUrl(url_, font_list, max_status_bubble_width, | 861 url_text_ = secure_display::ElideUrl(url_, font_list, max_status_bubble_width, |
| 863 languages_); | 862 languages_); |
| 864 int expanded_bubble_width = | 863 int expanded_bubble_width = |
| 865 std::max(GetStandardStatusBubbleWidth(), | 864 std::max(GetStandardStatusBubbleWidth(), |
| 866 std::min(gfx::GetStringWidth(url_text_, font_list) + | 865 std::min(gfx::GetStringWidth(url_text_, font_list) + |
| 867 (kShadowThickness * 2) + kTextPositionX + | 866 (kShadowThickness * 2) + kTextPositionX + |
| 868 kTextHorizPadding + 1, | 867 kTextHorizPadding + 1, |
| 869 max_status_bubble_width)); | 868 max_status_bubble_width)); |
| 870 is_expanded_ = true; | 869 is_expanded_ = true; |
| 871 expand_view_->StartExpansion(url_text_, popup_bounds.width(), | 870 expand_view_->StartExpansion(url_text_, popup_bounds.width(), |
| 872 expanded_bubble_width); | 871 expanded_bubble_width); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 886 void StatusBubbleViews::SetBubbleWidth(int width) { | 885 void StatusBubbleViews::SetBubbleWidth(int width) { |
| 887 size_.set_width(width); | 886 size_.set_width(width); |
| 888 SetBounds(original_position_.x(), original_position_.y(), | 887 SetBounds(original_position_.x(), original_position_.y(), |
| 889 size_.width(), size_.height()); | 888 size_.width(), size_.height()); |
| 890 } | 889 } |
| 891 | 890 |
| 892 void StatusBubbleViews::CancelExpandTimer() { | 891 void StatusBubbleViews::CancelExpandTimer() { |
| 893 if (expand_timer_factory_.HasWeakPtrs()) | 892 if (expand_timer_factory_.HasWeakPtrs()) |
| 894 expand_timer_factory_.InvalidateWeakPtrs(); | 893 expand_timer_factory_.InvalidateWeakPtrs(); |
| 895 } | 894 } |
| OLD | NEW |