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" |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 if (!status_text_.empty()) { | 663 if (!status_text_.empty()) { |
664 view_->SetText(status_text, true); | 664 view_->SetText(status_text, true); |
665 view_->Show(); | 665 view_->Show(); |
666 } else if (!url_text_.empty()) { | 666 } else if (!url_text_.empty()) { |
667 view_->SetText(url_text_, true); | 667 view_->SetText(url_text_, true); |
668 } else { | 668 } else { |
669 view_->SetText(base::string16(), true); | 669 view_->SetText(base::string16(), true); |
670 } | 670 } |
671 } | 671 } |
672 | 672 |
673 void StatusBubbleViews::SetURL(const GURL& url, const std::string& languages) { | 673 void StatusBubbleViews::SetURL(const GURL& url) { |
674 url_ = url; | 674 url_ = url; |
675 languages_ = languages; | |
676 if (size_.IsEmpty()) | 675 if (size_.IsEmpty()) |
677 return; // We have no bounds, don't attempt to show the popup. | 676 return; // We have no bounds, don't attempt to show the popup. |
678 | 677 |
679 Init(); | 678 Init(); |
680 | 679 |
681 // If we want to clear a displayed URL but there is a status still to | 680 // If we want to clear a displayed URL but there is a status still to |
682 // display, display that status instead. | 681 // display, display that status instead. |
683 if (url.is_empty() && !status_text_.empty()) { | 682 if (url.is_empty() && !status_text_.empty()) { |
684 url_text_ = base::string16(); | 683 url_text_ = base::string16(); |
685 if (IsFrameVisible()) | 684 if (IsFrameVisible()) |
686 view_->SetText(status_text_, true); | 685 view_->SetText(status_text_, true); |
687 return; | 686 return; |
688 } | 687 } |
689 | 688 |
690 // Reset expansion state only when bubble is completely hidden. | 689 // Reset expansion state only when bubble is completely hidden. |
691 if (view_->state() == StatusView::BUBBLE_HIDDEN) { | 690 if (view_->state() == StatusView::BUBBLE_HIDDEN) { |
692 is_expanded_ = false; | 691 is_expanded_ = false; |
693 SetBubbleWidth(GetStandardStatusBubbleWidth()); | 692 SetBubbleWidth(GetStandardStatusBubbleWidth()); |
694 } | 693 } |
695 | 694 |
696 // Set Elided Text corresponding to the GURL object. | 695 // Set Elided Text corresponding to the GURL object. |
697 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); | 696 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); |
698 int text_width = static_cast<int>(popup_bounds.width() - | 697 int text_width = static_cast<int>(popup_bounds.width() - |
699 (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1); | 698 (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1); |
700 url_text_ = | 699 url_text_ = |
701 url_formatter::ElideUrl(url, gfx::FontList(), text_width, languages); | 700 url_formatter::ElideUrl(url, gfx::FontList(), text_width); |
702 | 701 |
703 // An URL is always treated as a left-to-right string. On right-to-left UIs | 702 // An URL is always treated as a left-to-right string. On right-to-left UIs |
704 // we need to explicitly mark the URL as LTR to make sure it is displayed | 703 // we need to explicitly mark the URL as LTR to make sure it is displayed |
705 // correctly. | 704 // correctly. |
706 url_text_ = base::i18n::GetDisplayStringInLTRDirectionality(url_text_); | 705 url_text_ = base::i18n::GetDisplayStringInLTRDirectionality(url_text_); |
707 | 706 |
708 if (IsFrameVisible()) { | 707 if (IsFrameVisible()) { |
709 view_->SetText(url_text_, true); | 708 view_->SetText(url_text_, true); |
710 | 709 |
711 CancelExpandTimer(); | 710 CancelExpandTimer(); |
712 | 711 |
713 // If bubble is already in expanded state, shift to adjust to new text | 712 // If bubble is already in expanded state, shift to adjust to new text |
714 // size (shrinking or expanding). Otherwise delay. | 713 // size (shrinking or expanding). Otherwise delay. |
715 if (is_expanded_ && !url.is_empty()) { | 714 if (is_expanded_ && !url.is_empty()) { |
716 ExpandBubble(); | 715 ExpandBubble(); |
717 } else if (url_formatter::FormatUrl(url, languages).length() > | 716 } else if (url_formatter::FormatUrl(url).length() > |
718 url_text_.length()) { | 717 url_text_.length()) { |
719 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 718 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
720 FROM_HERE, base::Bind(&StatusBubbleViews::ExpandBubble, | 719 FROM_HERE, base::Bind(&StatusBubbleViews::ExpandBubble, |
721 expand_timer_factory_.GetWeakPtr()), | 720 expand_timer_factory_.GetWeakPtr()), |
722 base::TimeDelta::FromMilliseconds(kExpandHoverDelayMS)); | 721 base::TimeDelta::FromMilliseconds(kExpandHoverDelayMS)); |
723 } | 722 } |
724 } | 723 } |
725 } | 724 } |
726 | 725 |
727 void StatusBubbleViews::Hide() { | 726 void StatusBubbleViews::Hide() { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 views::Widget* window = frame->GetTopLevelWidget(); | 854 views::Widget* window = frame->GetTopLevelWidget(); |
856 return window && window->IsMaximized(); | 855 return window && window->IsMaximized(); |
857 } | 856 } |
858 | 857 |
859 void StatusBubbleViews::ExpandBubble() { | 858 void StatusBubbleViews::ExpandBubble() { |
860 // Elide URL to maximum possible size, then check actual length (it may | 859 // Elide URL to maximum possible size, then check actual length (it may |
861 // still be too long to fit) before expanding bubble. | 860 // still be too long to fit) before expanding bubble. |
862 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); | 861 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); |
863 int max_status_bubble_width = GetMaxStatusBubbleWidth(); | 862 int max_status_bubble_width = GetMaxStatusBubbleWidth(); |
864 const gfx::FontList font_list; | 863 const gfx::FontList font_list; |
865 url_text_ = url_formatter::ElideUrl(url_, font_list, max_status_bubble_width, | 864 url_text_ = url_formatter::ElideUrl(url_, font_list, max_status_bubble_width); |
866 languages_); | |
867 int expanded_bubble_width = | 865 int expanded_bubble_width = |
868 std::max(GetStandardStatusBubbleWidth(), | 866 std::max(GetStandardStatusBubbleWidth(), |
869 std::min(gfx::GetStringWidth(url_text_, font_list) + | 867 std::min(gfx::GetStringWidth(url_text_, font_list) + |
870 (kShadowThickness * 2) + kTextPositionX + | 868 (kShadowThickness * 2) + kTextPositionX + |
871 kTextHorizPadding + 1, | 869 kTextHorizPadding + 1, |
872 max_status_bubble_width)); | 870 max_status_bubble_width)); |
873 is_expanded_ = true; | 871 is_expanded_ = true; |
874 expand_view_->StartExpansion(url_text_, popup_bounds.width(), | 872 expand_view_->StartExpansion(url_text_, popup_bounds.width(), |
875 expanded_bubble_width); | 873 expanded_bubble_width); |
876 } | 874 } |
(...skipping 12 matching lines...) Expand all Loading... |
889 void StatusBubbleViews::SetBubbleWidth(int width) { | 887 void StatusBubbleViews::SetBubbleWidth(int width) { |
890 size_.set_width(width); | 888 size_.set_width(width); |
891 SetBounds(original_position_.x(), original_position_.y(), | 889 SetBounds(original_position_.x(), original_position_.y(), |
892 size_.width(), size_.height()); | 890 size_.width(), size_.height()); |
893 } | 891 } |
894 | 892 |
895 void StatusBubbleViews::CancelExpandTimer() { | 893 void StatusBubbleViews::CancelExpandTimer() { |
896 if (expand_timer_factory_.HasWeakPtrs()) | 894 if (expand_timer_factory_.HasWeakPtrs()) |
897 expand_timer_factory_.InvalidateWeakPtrs(); | 895 expand_timer_factory_.InvalidateWeakPtrs(); |
898 } | 896 } |
OLD | NEW |