Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: chrome/browser/ui/views/status_bubble_views.cc

Issue 24883002: Uses and returns the fractional width in text eliding (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More fixes per feedback Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 SkIntToScalar(kShadowThickness), 427 SkIntToScalar(kShadowThickness),
428 SkIntToScalar(width - kShadowThickness), 428 SkIntToScalar(width - kShadowThickness),
429 SkIntToScalar(height - kShadowThickness)); 429 SkIntToScalar(height - kShadowThickness));
430 SkPath path; 430 SkPath path;
431 path.addRoundRect(rect, rad, SkPath::kCW_Direction); 431 path.addRoundRect(rect, rad, SkPath::kCW_Direction);
432 canvas->DrawPath(path, paint); 432 canvas->DrawPath(path, paint);
433 433
434 // Draw highlight text and then the text body. In order to make sure the text 434 // Draw highlight text and then the text body. In order to make sure the text
435 // is aligned to the right on RTL UIs, we mirror the text bounds if the 435 // is aligned to the right on RTL UIs, we mirror the text bounds if the
436 // locale is RTL. 436 // locale is RTL.
437 int text_width = std::min( 437 int text_width = std::min<int>(
438 views::Label::font().GetStringWidth(text_), 438 views::Label::font().GetStringWidth(text_),
439 width - (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding); 439 width - (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding);
440 int text_height = height - (kShadowThickness * 2); 440 int text_height = height - (kShadowThickness * 2);
441 gfx::Rect body_bounds(kShadowThickness + kTextPositionX, 441 gfx::Rect body_bounds(kShadowThickness + kTextPositionX,
442 kShadowThickness, 442 kShadowThickness,
443 std::max(0, text_width), 443 std::max(0, text_width),
444 std::max(0, text_height)); 444 std::max(0, text_height));
445 body_bounds.set_x(GetMirroredXForRect(body_bounds)); 445 body_bounds.set_x(GetMirroredXForRect(body_bounds));
446 SkColor text_color = 446 SkColor text_color =
447 theme_service_->GetColor(ThemeProperties::COLOR_TAB_TEXT); 447 theme_service_->GetColor(ThemeProperties::COLOR_TAB_TEXT);
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 } 817 }
818 818
819 void StatusBubbleViews::ExpandBubble() { 819 void StatusBubbleViews::ExpandBubble() {
820 // Elide URL to maximum possible size, then check actual length (it may 820 // Elide URL to maximum possible size, then check actual length (it may
821 // still be too long to fit) before expanding bubble. 821 // still be too long to fit) before expanding bubble.
822 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); 822 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen();
823 int max_status_bubble_width = GetMaxStatusBubbleWidth(); 823 int max_status_bubble_width = GetMaxStatusBubbleWidth();
824 url_text_ = gfx::ElideUrl(url_, view_->Label::font(), 824 url_text_ = gfx::ElideUrl(url_, view_->Label::font(),
825 max_status_bubble_width, languages_); 825 max_status_bubble_width, languages_);
826 int expanded_bubble_width =std::max(GetStandardStatusBubbleWidth(), 826 int expanded_bubble_width =std::max(GetStandardStatusBubbleWidth(),
827 std::min(view_->Label::font().GetStringWidth(url_text_) + 827 std::min<int>(view_->Label::font().GetStringWidth(url_text_) +
828 (kShadowThickness * 2) + kTextPositionX + 828 (kShadowThickness * 2) + kTextPositionX +
829 kTextHorizPadding + 1, 829 kTextHorizPadding + 1,
830 max_status_bubble_width)); 830 max_status_bubble_width));
831 is_expanded_ = true; 831 is_expanded_ = true;
832 expand_view_->StartExpansion(url_text_, popup_bounds.width(), 832 expand_view_->StartExpansion(url_text_, popup_bounds.width(),
833 expanded_bubble_width); 833 expanded_bubble_width);
834 } 834 }
835 835
836 int StatusBubbleViews::GetStandardStatusBubbleWidth() { 836 int StatusBubbleViews::GetStandardStatusBubbleWidth() {
837 return base_view_->bounds().width() / 3; 837 return base_view_->bounds().width() / 3;
838 } 838 }
839 839
840 int StatusBubbleViews::GetMaxStatusBubbleWidth() { 840 int StatusBubbleViews::GetMaxStatusBubbleWidth() {
841 const ui::NativeTheme* theme = base_view_->GetNativeTheme(); 841 const ui::NativeTheme* theme = base_view_->GetNativeTheme();
842 return static_cast<int>(std::max(0, base_view_->bounds().width() - 842 return static_cast<int>(std::max(0, base_view_->bounds().width() -
843 (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1 - 843 (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1 -
844 views::NativeScrollBar::GetVerticalScrollBarWidth(theme))); 844 views::NativeScrollBar::GetVerticalScrollBarWidth(theme)));
845 } 845 }
846 846
847 void StatusBubbleViews::SetBubbleWidth(int width) { 847 void StatusBubbleViews::SetBubbleWidth(int width) {
848 size_.set_width(width); 848 size_.set_width(width);
849 SetBounds(original_position_.x(), original_position_.y(), 849 SetBounds(original_position_.x(), original_position_.y(),
850 size_.width(), size_.height()); 850 size_.width(), size_.height());
851 } 851 }
852 852
853 void StatusBubbleViews::CancelExpandTimer() { 853 void StatusBubbleViews::CancelExpandTimer() {
854 if (expand_timer_factory_.HasWeakPtrs()) 854 if (expand_timer_factory_.HasWeakPtrs())
855 expand_timer_factory_.InvalidateWeakPtrs(); 855 expand_timer_factory_.InvalidateWeakPtrs();
856 } 856 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698