| 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/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/themes/theme_properties.h" | 14 #include "chrome/browser/themes/theme_properties.h" |
| 15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
| 16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 17 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
| 18 #include "third_party/skia/include/core/SkPaint.h" | 18 #include "third_party/skia/include/core/SkPaint.h" |
| 19 #include "third_party/skia/include/core/SkPath.h" | 19 #include "third_party/skia/include/core/SkPath.h" |
| 20 #include "third_party/skia/include/core/SkRect.h" | 20 #include "third_party/skia/include/core/SkRect.h" |
| 21 #include "ui/base/animation/animation_delegate.h" | 21 #include "ui/base/animation/animation_delegate.h" |
| 22 #include "ui/base/animation/linear_animation.h" | 22 #include "ui/base/animation/linear_animation.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 24 #include "ui/base/text/text_elider.h" | |
| 25 #include "ui/base/theme_provider.h" | 24 #include "ui/base/theme_provider.h" |
| 26 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
| 27 #include "ui/gfx/point.h" | 26 #include "ui/gfx/point.h" |
| 28 #include "ui/gfx/screen.h" | 27 #include "ui/gfx/screen.h" |
| 29 #include "ui/gfx/skia_util.h" | 28 #include "ui/gfx/skia_util.h" |
| 29 #include "ui/gfx/text_elider.h" |
| 30 #include "ui/native_theme/native_theme.h" | 30 #include "ui/native_theme/native_theme.h" |
| 31 #include "ui/views/controls/label.h" | 31 #include "ui/views/controls/label.h" |
| 32 #include "ui/views/controls/scrollbar/native_scroll_bar.h" | 32 #include "ui/views/controls/scrollbar/native_scroll_bar.h" |
| 33 #include "ui/views/widget/root_view.h" | 33 #include "ui/views/widget/root_view.h" |
| 34 #include "ui/views/widget/widget.h" | 34 #include "ui/views/widget/widget.h" |
| 35 #include "url/gurl.h" | 35 #include "url/gurl.h" |
| 36 | 36 |
| 37 #if defined(USE_ASH) | 37 #if defined(USE_ASH) |
| 38 #include "ash/wm/property_util.h" | 38 #include "ash/wm/property_util.h" |
| 39 #endif | 39 #endif |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 // Reset expansion state only when bubble is completely hidden. | 656 // Reset expansion state only when bubble is completely hidden. |
| 657 if (view_->GetState() == StatusView::BUBBLE_HIDDEN) { | 657 if (view_->GetState() == StatusView::BUBBLE_HIDDEN) { |
| 658 is_expanded_ = false; | 658 is_expanded_ = false; |
| 659 SetBubbleWidth(GetStandardStatusBubbleWidth()); | 659 SetBubbleWidth(GetStandardStatusBubbleWidth()); |
| 660 } | 660 } |
| 661 | 661 |
| 662 // Set Elided Text corresponding to the GURL object. | 662 // Set Elided Text corresponding to the GURL object. |
| 663 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); | 663 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); |
| 664 int text_width = static_cast<int>(popup_bounds.width() - | 664 int text_width = static_cast<int>(popup_bounds.width() - |
| 665 (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1); | 665 (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1); |
| 666 url_text_ = ui::ElideUrl(url, view_->Label::font(), text_width, languages); | 666 url_text_ = gfx::ElideUrl(url, view_->Label::font(), text_width, languages); |
| 667 | 667 |
| 668 // An URL is always treated as a left-to-right string. On right-to-left UIs | 668 // An URL is always treated as a left-to-right string. On right-to-left UIs |
| 669 // we need to explicitly mark the URL as LTR to make sure it is displayed | 669 // we need to explicitly mark the URL as LTR to make sure it is displayed |
| 670 // correctly. | 670 // correctly. |
| 671 url_text_ = base::i18n::GetDisplayStringInLTRDirectionality(url_text_); | 671 url_text_ = base::i18n::GetDisplayStringInLTRDirectionality(url_text_); |
| 672 | 672 |
| 673 if (IsFrameVisible()) { | 673 if (IsFrameVisible()) { |
| 674 view_->SetText(url_text_, true); | 674 view_->SetText(url_text_, true); |
| 675 | 675 |
| 676 CancelExpandTimer(); | 676 CancelExpandTimer(); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 | 813 |
| 814 views::Widget* window = frame->GetTopLevelWidget(); | 814 views::Widget* window = frame->GetTopLevelWidget(); |
| 815 return !window || !window->IsMinimized(); | 815 return !window || !window->IsMinimized(); |
| 816 } | 816 } |
| 817 | 817 |
| 818 void StatusBubbleViews::ExpandBubble() { | 818 void StatusBubbleViews::ExpandBubble() { |
| 819 // Elide URL to maximum possible size, then check actual length (it may | 819 // Elide URL to maximum possible size, then check actual length (it may |
| 820 // still be too long to fit) before expanding bubble. | 820 // still be too long to fit) before expanding bubble. |
| 821 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); | 821 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); |
| 822 int max_status_bubble_width = GetMaxStatusBubbleWidth(); | 822 int max_status_bubble_width = GetMaxStatusBubbleWidth(); |
| 823 url_text_ = ui::ElideUrl(url_, view_->Label::font(), | 823 url_text_ = gfx::ElideUrl(url_, view_->Label::font(), |
| 824 max_status_bubble_width, languages_); | 824 max_status_bubble_width, languages_); |
| 825 int expanded_bubble_width =std::max(GetStandardStatusBubbleWidth(), | 825 int expanded_bubble_width =std::max(GetStandardStatusBubbleWidth(), |
| 826 std::min(view_->Label::font().GetStringWidth(url_text_) + | 826 std::min(view_->Label::font().GetStringWidth(url_text_) + |
| 827 (kShadowThickness * 2) + kTextPositionX + | 827 (kShadowThickness * 2) + kTextPositionX + |
| 828 kTextHorizPadding + 1, | 828 kTextHorizPadding + 1, |
| 829 max_status_bubble_width)); | 829 max_status_bubble_width)); |
| 830 is_expanded_ = true; | 830 is_expanded_ = true; |
| 831 expand_view_->StartExpansion(url_text_, popup_bounds.width(), | 831 expand_view_->StartExpansion(url_text_, popup_bounds.width(), |
| 832 expanded_bubble_width); | 832 expanded_bubble_width); |
| 833 } | 833 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 846 void StatusBubbleViews::SetBubbleWidth(int width) { | 846 void StatusBubbleViews::SetBubbleWidth(int width) { |
| 847 size_.set_width(width); | 847 size_.set_width(width); |
| 848 SetBounds(original_position_.x(), original_position_.y(), | 848 SetBounds(original_position_.x(), original_position_.y(), |
| 849 size_.width(), size_.height()); | 849 size_.width(), size_.height()); |
| 850 } | 850 } |
| 851 | 851 |
| 852 void StatusBubbleViews::CancelExpandTimer() { | 852 void StatusBubbleViews::CancelExpandTimer() { |
| 853 if (expand_timer_factory_.HasWeakPtrs()) | 853 if (expand_timer_factory_.HasWeakPtrs()) |
| 854 expand_timer_factory_.InvalidateWeakPtrs(); | 854 expand_timer_factory_.InvalidateWeakPtrs(); |
| 855 } | 855 } |
| OLD | NEW |