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 "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
10 #include "app/text_elider.h" | |
11 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
12 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
13 #include "base/string_util.h" | 12 #include "base/string_util.h" |
14 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/themes/browser_theme_provider.h" | 14 #include "chrome/browser/themes/browser_theme_provider.h" |
16 #include "gfx/canvas_skia.h" | 15 #include "gfx/canvas_skia.h" |
17 #include "gfx/point.h" | 16 #include "gfx/point.h" |
18 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
19 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
20 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
21 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
22 #include "third_party/skia/include/core/SkPaint.h" | 21 #include "third_party/skia/include/core/SkPaint.h" |
23 #include "third_party/skia/include/core/SkPath.h" | 22 #include "third_party/skia/include/core/SkPath.h" |
24 #include "third_party/skia/include/core/SkRect.h" | 23 #include "third_party/skia/include/core/SkRect.h" |
25 #include "ui/base/animation/animation_delegate.h" | 24 #include "ui/base/animation/animation_delegate.h" |
26 #include "ui/base/animation/linear_animation.h" | 25 #include "ui/base/animation/linear_animation.h" |
| 26 #include "ui/base/text/text_elider.h" |
27 #include "views/controls/label.h" | 27 #include "views/controls/label.h" |
28 #include "views/controls/scrollbar/native_scroll_bar.h" | 28 #include "views/controls/scrollbar/native_scroll_bar.h" |
29 #include "views/screen.h" | 29 #include "views/screen.h" |
30 #include "views/widget/root_view.h" | 30 #include "views/widget/root_view.h" |
31 #include "views/widget/widget.h" | 31 #include "views/widget/widget.h" |
32 #include "views/window/window.h" | 32 #include "views/window/window.h" |
33 | 33 |
34 using views::Widget; | 34 using views::Widget; |
35 | 35 |
36 // The alpha and color of the bubble's shadow. | 36 // The alpha and color of the bubble's shadow. |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 if (view_->GetState() == StatusView::BUBBLE_HIDDEN) { | 641 if (view_->GetState() == StatusView::BUBBLE_HIDDEN) { |
642 is_expanded_ = false; | 642 is_expanded_ = false; |
643 SetBubbleWidth(GetStandardStatusBubbleWidth()); | 643 SetBubbleWidth(GetStandardStatusBubbleWidth()); |
644 } | 644 } |
645 | 645 |
646 // Set Elided Text corresponding to the GURL object. | 646 // Set Elided Text corresponding to the GURL object. |
647 gfx::Rect popup_bounds; | 647 gfx::Rect popup_bounds; |
648 popup_->GetBounds(&popup_bounds, true); | 648 popup_->GetBounds(&popup_bounds, true); |
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_ = gfx::ElideUrl(url, view_->Label::font(), | 651 url_text_ = ui::ElideUrl(url, view_->Label::font(), |
652 text_width, UTF16ToWideHack(languages)); | 652 text_width, UTF16ToWideHack(languages)); |
653 | 653 |
654 std::wstring original_url_text = | 654 std::wstring original_url_text = |
655 UTF16ToWideHack(net::FormatUrl(url, UTF16ToUTF8(languages))); | 655 UTF16ToWideHack(net::FormatUrl(url, UTF16ToUTF8(languages))); |
656 | 656 |
657 // An URL is always treated as a left-to-right string. On right-to-left UIs | 657 // 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 | 658 // we need to explicitly mark the URL as LTR to make sure it is displayed |
659 // correctly. | 659 // correctly. |
660 url_text_ = base::i18n::GetDisplayStringInLTRDirectionality(url_text_); | 660 url_text_ = base::i18n::GetDisplayStringInLTRDirectionality(url_text_); |
661 | 661 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 views::Window* window = frame->GetWindow(); | 796 views::Window* window = frame->GetWindow(); |
797 return !window || !window->IsMinimized(); | 797 return !window || !window->IsMinimized(); |
798 } | 798 } |
799 | 799 |
800 void StatusBubbleViews::ExpandBubble() { | 800 void StatusBubbleViews::ExpandBubble() { |
801 // Elide URL to maximum possible size, then check actual length (it may | 801 // Elide URL to maximum possible size, then check actual length (it may |
802 // still be too long to fit) before expanding bubble. | 802 // still be too long to fit) before expanding bubble. |
803 gfx::Rect popup_bounds; | 803 gfx::Rect popup_bounds; |
804 popup_->GetBounds(&popup_bounds, true); | 804 popup_->GetBounds(&popup_bounds, true); |
805 int max_status_bubble_width = GetMaxStatusBubbleWidth(); | 805 int max_status_bubble_width = GetMaxStatusBubbleWidth(); |
806 url_text_ = gfx::ElideUrl(url_, view_->Label::font(), | 806 url_text_ = ui::ElideUrl(url_, view_->Label::font(), |
807 max_status_bubble_width, UTF16ToWideHack(languages_)); | 807 max_status_bubble_width, UTF16ToWideHack(languages_)); |
808 int expanded_bubble_width =std::max(GetStandardStatusBubbleWidth(), | 808 int expanded_bubble_width =std::max(GetStandardStatusBubbleWidth(), |
809 std::min(view_->Label::font().GetStringWidth(url_text_) + | 809 std::min(view_->Label::font().GetStringWidth(url_text_) + |
810 (kShadowThickness * 2) + kTextPositionX + | 810 (kShadowThickness * 2) + kTextPositionX + |
811 kTextHorizPadding + 1, | 811 kTextHorizPadding + 1, |
812 max_status_bubble_width)); | 812 max_status_bubble_width)); |
813 is_expanded_ = true; | 813 is_expanded_ = true; |
814 expand_view_->StartExpansion(url_text_, popup_bounds.width(), | 814 expand_view_->StartExpansion(url_text_, popup_bounds.width(), |
815 expanded_bubble_width); | 815 expanded_bubble_width); |
816 } | 816 } |
(...skipping 11 matching lines...) Expand all Loading... |
828 void StatusBubbleViews::SetBubbleWidth(int width) { | 828 void StatusBubbleViews::SetBubbleWidth(int width) { |
829 size_.set_width(width); | 829 size_.set_width(width); |
830 SetBounds(original_position_.x(), original_position_.y(), | 830 SetBounds(original_position_.x(), original_position_.y(), |
831 size_.width(), size_.height()); | 831 size_.width(), size_.height()); |
832 } | 832 } |
833 | 833 |
834 void StatusBubbleViews::CancelExpandTimer() { | 834 void StatusBubbleViews::CancelExpandTimer() { |
835 if (!expand_timer_factory_.empty()) | 835 if (!expand_timer_factory_.empty()) |
836 expand_timer_factory_.RevokeAll(); | 836 expand_timer_factory_.RevokeAll(); |
837 } | 837 } |
OLD | NEW |