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/secure_display/elide_url.h" | 17 #include "components/url_formatter/elide_url.h" |
18 #include "net/base/net_util.h" | 18 #include "components/url_formatter/url_formatter.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/SkRRect.h" | 20 #include "third_party/skia/include/core/SkRRect.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 secure_display::ElideUrl(url, gfx::FontList(), text_width, languages); | 698 url_formatter::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 (net::FormatUrl(url, languages).length() > url_text_.length()) { | 714 } else if (url_formatter::FormatUrl(url, languages).length() > |
| 715 url_text_.length()) { |
715 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 716 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
716 FROM_HERE, base::Bind(&StatusBubbleViews::ExpandBubble, | 717 FROM_HERE, base::Bind(&StatusBubbleViews::ExpandBubble, |
717 expand_timer_factory_.GetWeakPtr()), | 718 expand_timer_factory_.GetWeakPtr()), |
718 base::TimeDelta::FromMilliseconds(kExpandHoverDelayMS)); | 719 base::TimeDelta::FromMilliseconds(kExpandHoverDelayMS)); |
719 } | 720 } |
720 } | 721 } |
721 } | 722 } |
722 | 723 |
723 void StatusBubbleViews::Hide() { | 724 void StatusBubbleViews::Hide() { |
724 status_text_ = base::string16(); | 725 status_text_ = base::string16(); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 views::Widget* window = frame->GetTopLevelWidget(); | 852 views::Widget* window = frame->GetTopLevelWidget(); |
852 return window && window->IsMaximized(); | 853 return window && window->IsMaximized(); |
853 } | 854 } |
854 | 855 |
855 void StatusBubbleViews::ExpandBubble() { | 856 void StatusBubbleViews::ExpandBubble() { |
856 // Elide URL to maximum possible size, then check actual length (it may | 857 // Elide URL to maximum possible size, then check actual length (it may |
857 // still be too long to fit) before expanding bubble. | 858 // still be too long to fit) before expanding bubble. |
858 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); | 859 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); |
859 int max_status_bubble_width = GetMaxStatusBubbleWidth(); | 860 int max_status_bubble_width = GetMaxStatusBubbleWidth(); |
860 const gfx::FontList font_list; | 861 const gfx::FontList font_list; |
861 url_text_ = secure_display::ElideUrl(url_, font_list, max_status_bubble_width, | 862 url_text_ = url_formatter::ElideUrl(url_, font_list, max_status_bubble_width, |
862 languages_); | 863 languages_); |
863 int expanded_bubble_width = | 864 int expanded_bubble_width = |
864 std::max(GetStandardStatusBubbleWidth(), | 865 std::max(GetStandardStatusBubbleWidth(), |
865 std::min(gfx::GetStringWidth(url_text_, font_list) + | 866 std::min(gfx::GetStringWidth(url_text_, font_list) + |
866 (kShadowThickness * 2) + kTextPositionX + | 867 (kShadowThickness * 2) + kTextPositionX + |
867 kTextHorizPadding + 1, | 868 kTextHorizPadding + 1, |
868 max_status_bubble_width)); | 869 max_status_bubble_width)); |
869 is_expanded_ = true; | 870 is_expanded_ = true; |
870 expand_view_->StartExpansion(url_text_, popup_bounds.width(), | 871 expand_view_->StartExpansion(url_text_, popup_bounds.width(), |
871 expanded_bubble_width); | 872 expanded_bubble_width); |
(...skipping 13 matching lines...) Expand all Loading... |
885 void StatusBubbleViews::SetBubbleWidth(int width) { | 886 void StatusBubbleViews::SetBubbleWidth(int width) { |
886 size_.set_width(width); | 887 size_.set_width(width); |
887 SetBounds(original_position_.x(), original_position_.y(), | 888 SetBounds(original_position_.x(), original_position_.y(), |
888 size_.width(), size_.height()); | 889 size_.width(), size_.height()); |
889 } | 890 } |
890 | 891 |
891 void StatusBubbleViews::CancelExpandTimer() { | 892 void StatusBubbleViews::CancelExpandTimer() { |
892 if (expand_timer_factory_.HasWeakPtrs()) | 893 if (expand_timer_factory_.HasWeakPtrs()) |
893 expand_timer_factory_.InvalidateWeakPtrs(); | 894 expand_timer_factory_.InvalidateWeakPtrs(); |
894 } | 895 } |
OLD | NEW |