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

Unified Diff: chrome/browser/ui/autofill/autofill_popup_controller_impl.cc

Issue 24883002: Uses and returns the fractional width in text eliding (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix round-down problems 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/autofill_popup_controller_impl.cc
diff --git a/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc b/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc
index 44402305bf6d0e65ff615151dac0e0497b5a4db6..c12b2b4c4fc29ef09abd56eb18a6e1d9ee277dd5 100644
--- a/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc
@@ -122,30 +122,30 @@ void AutofillPopupControllerImpl::Show(
// Android displays the long text with ellipsis using the view attributes.
UpdatePopupBounds();
- int popup_width = popup_bounds().width();
+ float popup_width = popup_bounds().width();
// Elide the name and subtext strings so that the popup fits in the available
// space.
for (size_t i = 0; i < names_.size(); ++i) {
- int name_width = GetNameFontForRow(i).GetStringWidth(names_[i]);
- int subtext_width = subtext_font().GetStringWidth(subtexts_[i]);
- int total_text_length = name_width + subtext_width;
+ float name_width = GetNameFontForRow(i).GetStringWidth(names_[i]);
+ float subtext_width = subtext_font().GetStringWidth(subtexts_[i]);
+ float total_text_length = name_width + subtext_width;
// The line can have no strings if it represents a UI element, such as
// a separator line.
if (total_text_length == 0)
continue;
- int available_width = popup_width - RowWidthWithoutText(i);
+ float available_width = popup_width - RowWidthWithoutText(i);
// Each field recieves space in proportion to its length.
- int name_size = available_width * name_width / total_text_length;
+ float name_size = available_width * name_width / total_text_length;
names_[i] = gfx::ElideText(names_[i],
GetNameFontForRow(i),
name_size,
gfx::ELIDE_AT_END);
- int subtext_size = available_width * subtext_width / total_text_length;
+ float subtext_size = available_width * subtext_width / total_text_length;
subtexts_[i] = gfx::ElideText(subtexts_[i],
subtext_font(),
subtext_size,
@@ -335,25 +335,25 @@ bool AutofillPopupControllerImpl::IsWarning(size_t index) const {
return identifiers_[index] == WebAutofillClient::MenuItemIDWarningMessage;
}
-gfx::Rect AutofillPopupControllerImpl::GetRowBounds(size_t index) {
+gfx::RectF AutofillPopupControllerImpl::GetRowBounds(size_t index) {
int top = 0;
for (size_t i = 0; i < index; ++i) {
top += GetRowHeightFromId(identifiers()[i]);
}
- return gfx::Rect(
+ return gfx::RectF(
0,
top,
popup_bounds_.width(),
GetRowHeightFromId(identifiers()[index]));
}
-void AutofillPopupControllerImpl::SetPopupBounds(const gfx::Rect& bounds) {
+void AutofillPopupControllerImpl::SetPopupBounds(const gfx::RectF& bounds) {
popup_bounds_ = bounds;
UpdateBoundsAndRedrawPopup();
}
-const gfx::Rect& AutofillPopupControllerImpl::popup_bounds() const {
+const gfx::RectF& AutofillPopupControllerImpl::popup_bounds() const {
return popup_bounds_;
}
@@ -565,17 +565,17 @@ void AutofillPopupControllerImpl::InvalidateRow(size_t row) {
}
#if !defined(OS_ANDROID)
-int AutofillPopupControllerImpl::GetDesiredPopupWidth() const {
+float AutofillPopupControllerImpl::GetDesiredPopupWidth() const {
if (!name_font_.platform_font() || !subtext_font_.platform_font()) {
// We can't calculate the size of the popup if the fonts
// aren't present.
return 0;
}
- int popup_width = RoundedElementBounds().width();
+ float popup_width = RoundedElementBounds().width();
DCHECK_EQ(names().size(), subtexts().size());
for (size_t i = 0; i < names().size(); ++i) {
- int row_size = name_font_.GetStringWidth(names()[i]) +
+ float row_size = name_font_.GetStringWidth(names()[i]) +
subtext_font_.GetStringWidth(subtexts()[i]) +
RowWidthWithoutText(i);
@@ -612,7 +612,7 @@ int AutofillPopupControllerImpl::RowWidthWithoutText(int row) const {
}
void AutofillPopupControllerImpl::UpdatePopupBounds() {
- int popup_required_width = GetDesiredPopupWidth();
+ float popup_required_width = GetDesiredPopupWidth();
int popup_height = GetDesiredPopupHeight();
// This is the top left point of the popup if the popup is above the element
// and grows to the left (since that is the highest and furthest left the
@@ -633,15 +633,15 @@ void AutofillPopupControllerImpl::UpdatePopupBounds() {
gfx::Display bottom_right_display = GetDisplayNearestPoint(
bottom_right_corner_of_popup);
- std::pair<int, int> popup_x_and_width = CalculatePopupXAndWidth(
+ std::pair<float, float> popup_x_and_width = CalculatePopupXAndWidth(
top_left_display, bottom_right_display, popup_required_width);
std::pair<int, int> popup_y_and_height = CalculatePopupYAndHeight(
top_left_display, bottom_right_display, popup_height);
- popup_bounds_ = gfx::Rect(popup_x_and_width.first,
- popup_y_and_height.first,
- popup_x_and_width.second,
- popup_y_and_height.second);
+ popup_bounds_ = gfx::RectF(popup_x_and_width.first,
+ popup_y_and_height.first,
+ popup_x_and_width.second,
+ popup_y_and_height.second);
}
#endif // !defined(OS_ANDROID)
@@ -653,7 +653,7 @@ void AutofillPopupControllerImpl::ClearState() {
// Don't clear view_, because otherwise the popup will have to get regenerated
// and this will cause flickering.
- popup_bounds_ = gfx::Rect();
+ popup_bounds_ = gfx::RectF();
names_.clear();
subtexts_.clear();
@@ -674,10 +674,10 @@ gfx::Display AutofillPopupControllerImpl::GetDisplayNearestPoint(
point);
}
-std::pair<int, int> AutofillPopupControllerImpl::CalculatePopupXAndWidth(
+std::pair<float, float> AutofillPopupControllerImpl::CalculatePopupXAndWidth(
const gfx::Display& left_display,
const gfx::Display& right_display,
- int popup_required_width) const {
+ float popup_required_width) const {
int leftmost_display_x = left_display.bounds().x();
int rightmost_display_x =
right_display.GetSizeInPixel().width() + right_display.bounds().x();
@@ -694,8 +694,8 @@ std::pair<int, int> AutofillPopupControllerImpl::CalculatePopupXAndWidth(
int right_available = rightmost_display_x - right_growth_start;
int left_available = left_growth_end - leftmost_display_x;
- int popup_width = std::min(popup_required_width,
- std::max(right_available, left_available));
+ float popup_width = std::min<float>(
+ popup_required_width, std::max(right_available, left_available));
// If there is enough space for the popup on the right, show it there,
// otherwise choose the larger size.

Powered by Google App Engine
This is Rietveld 408576698