| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 if (!status_text_.empty()) { | 614 if (!status_text_.empty()) { |
| 615 view_->SetText(status_text, true); | 615 view_->SetText(status_text, true); |
| 616 view_->Show(); | 616 view_->Show(); |
| 617 } else if (!url_text_.empty()) { | 617 } else if (!url_text_.empty()) { |
| 618 view_->SetText(url_text_, true); | 618 view_->SetText(url_text_, true); |
| 619 } else { | 619 } else { |
| 620 view_->SetText(string16(), true); | 620 view_->SetText(string16(), true); |
| 621 } | 621 } |
| 622 } | 622 } |
| 623 | 623 |
| 624 void StatusBubbleViews::SetURL(const GURL& url, const string16& languages) { | 624 void StatusBubbleViews::SetURL(const GURL& url, const std::string& languages) { |
| 625 url_ = url; |
| 625 languages_ = languages; | 626 languages_ = languages; |
| 626 url_ = url; | |
| 627 if (size_.IsEmpty()) | 627 if (size_.IsEmpty()) |
| 628 return; // We have no bounds, don't attempt to show the popup. | 628 return; // We have no bounds, don't attempt to show the popup. |
| 629 | 629 |
| 630 Init(); | 630 Init(); |
| 631 | 631 |
| 632 // If we want to clear a displayed URL but there is a status still to | 632 // If we want to clear a displayed URL but there is a status still to |
| 633 // display, display that status instead. | 633 // display, display that status instead. |
| 634 if (url.is_empty() && !status_text_.empty()) { | 634 if (url.is_empty() && !status_text_.empty()) { |
| 635 url_text_ = string16(); | 635 url_text_ = string16(); |
| 636 if (IsFrameVisible()) | 636 if (IsFrameVisible()) |
| 637 view_->SetText(status_text_, true); | 637 view_->SetText(status_text_, true); |
| 638 return; | 638 return; |
| 639 } | 639 } |
| 640 | 640 |
| 641 // Reset expansion state only when bubble is completely hidden. | 641 // Reset expansion state only when bubble is completely hidden. |
| 642 if (view_->GetState() == StatusView::BUBBLE_HIDDEN) { | 642 if (view_->GetState() == StatusView::BUBBLE_HIDDEN) { |
| 643 is_expanded_ = false; | 643 is_expanded_ = false; |
| 644 SetBubbleWidth(GetStandardStatusBubbleWidth()); | 644 SetBubbleWidth(GetStandardStatusBubbleWidth()); |
| 645 } | 645 } |
| 646 | 646 |
| 647 // Set Elided Text corresponding to the GURL object. | 647 // Set Elided Text corresponding to the GURL object. |
| 648 gfx::Rect popup_bounds = popup_->GetWindowScreenBounds(); | 648 gfx::Rect popup_bounds = popup_->GetWindowScreenBounds(); |
| 649 int text_width = static_cast<int>(popup_bounds.width() - | 649 int text_width = static_cast<int>(popup_bounds.width() - |
| 650 (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1); | 650 (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1); |
| 651 url_text_ = ui::ElideUrl(url, view_->Label::font(), | 651 url_text_ = ui::ElideUrl(url, view_->Label::font(), text_width, languages); |
| 652 text_width, UTF16ToUTF8(languages)); | |
| 653 | 652 |
| 654 std::wstring original_url_text = | 653 std::wstring original_url_text = |
| 655 UTF16ToWideHack(net::FormatUrl(url, UTF16ToUTF8(languages))); | 654 UTF16ToWideHack(net::FormatUrl(url, languages)); |
| 656 | 655 |
| 657 // An URL is always treated as a left-to-right string. On right-to-left UIs | 656 // An URL is always treated as a left-to-right string. On right-to-left UIs |
| 658 // we need to explicitly mark the URL as LTR to make sure it is displayed | 657 // we need to explicitly mark the URL as LTR to make sure it is displayed |
| 659 // correctly. | 658 // correctly. |
| 660 url_text_ = base::i18n::GetDisplayStringInLTRDirectionality(url_text_); | 659 url_text_ = base::i18n::GetDisplayStringInLTRDirectionality(url_text_); |
| 661 | 660 |
| 662 if (IsFrameVisible()) { | 661 if (IsFrameVisible()) { |
| 663 view_->SetText(url_text_, true); | 662 view_->SetText(url_text_, true); |
| 664 | 663 |
| 665 CancelExpandTimer(); | 664 CancelExpandTimer(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 views::Widget* window = frame->GetTopLevelWidget(); | 795 views::Widget* window = frame->GetTopLevelWidget(); |
| 797 return !window || !window->IsMinimized(); | 796 return !window || !window->IsMinimized(); |
| 798 } | 797 } |
| 799 | 798 |
| 800 void StatusBubbleViews::ExpandBubble() { | 799 void StatusBubbleViews::ExpandBubble() { |
| 801 // Elide URL to maximum possible size, then check actual length (it may | 800 // Elide URL to maximum possible size, then check actual length (it may |
| 802 // still be too long to fit) before expanding bubble. | 801 // still be too long to fit) before expanding bubble. |
| 803 gfx::Rect popup_bounds = popup_->GetWindowScreenBounds(); | 802 gfx::Rect popup_bounds = popup_->GetWindowScreenBounds(); |
| 804 int max_status_bubble_width = GetMaxStatusBubbleWidth(); | 803 int max_status_bubble_width = GetMaxStatusBubbleWidth(); |
| 805 url_text_ = ui::ElideUrl(url_, view_->Label::font(), | 804 url_text_ = ui::ElideUrl(url_, view_->Label::font(), |
| 806 max_status_bubble_width, UTF16ToUTF8(languages_)); | 805 max_status_bubble_width, languages_); |
| 807 int expanded_bubble_width =std::max(GetStandardStatusBubbleWidth(), | 806 int expanded_bubble_width =std::max(GetStandardStatusBubbleWidth(), |
| 808 std::min(view_->Label::font().GetStringWidth(url_text_) + | 807 std::min(view_->Label::font().GetStringWidth(url_text_) + |
| 809 (kShadowThickness * 2) + kTextPositionX + | 808 (kShadowThickness * 2) + kTextPositionX + |
| 810 kTextHorizPadding + 1, | 809 kTextHorizPadding + 1, |
| 811 max_status_bubble_width)); | 810 max_status_bubble_width)); |
| 812 is_expanded_ = true; | 811 is_expanded_ = true; |
| 813 expand_view_->StartExpansion(url_text_, popup_bounds.width(), | 812 expand_view_->StartExpansion(url_text_, popup_bounds.width(), |
| 814 expanded_bubble_width); | 813 expanded_bubble_width); |
| 815 } | 814 } |
| 816 | 815 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 827 void StatusBubbleViews::SetBubbleWidth(int width) { | 826 void StatusBubbleViews::SetBubbleWidth(int width) { |
| 828 size_.set_width(width); | 827 size_.set_width(width); |
| 829 SetBounds(original_position_.x(), original_position_.y(), | 828 SetBounds(original_position_.x(), original_position_.y(), |
| 830 size_.width(), size_.height()); | 829 size_.width(), size_.height()); |
| 831 } | 830 } |
| 832 | 831 |
| 833 void StatusBubbleViews::CancelExpandTimer() { | 832 void StatusBubbleViews::CancelExpandTimer() { |
| 834 if (!expand_timer_factory_.empty()) | 833 if (!expand_timer_factory_.empty()) |
| 835 expand_timer_factory_.RevokeAll(); | 834 expand_timer_factory_.RevokeAll(); |
| 836 } | 835 } |
| OLD | NEW |