Chromium Code Reviews| 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 7e28e376c01d1f46981d08adedc6f8fedd9f4110..b27f971c3c992160fa2c5d2d17765ec32670b592 100644 |
| --- a/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc |
| +++ b/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc |
| @@ -67,6 +67,10 @@ const DataResource kDataResources[] = { |
| { "visaCC", IDR_AUTOFILL_CC_VISA }, |
| }; |
| +int round(float x) { |
| + return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5); |
| +} |
| + |
| } // end namespace |
| // static |
| @@ -74,7 +78,7 @@ AutofillPopupControllerImpl* AutofillPopupControllerImpl::GetOrCreate( |
| AutofillPopupControllerImpl* previous, |
| AutofillPopupDelegate* delegate, |
| gfx::NativeView container_view, |
| - const gfx::Rect& element_bounds) { |
| + const gfx::RectF& element_bounds) { |
| DCHECK(!previous || previous->delegate_ == delegate); |
| if (previous && |
| @@ -93,7 +97,7 @@ AutofillPopupControllerImpl* AutofillPopupControllerImpl::GetOrCreate( |
| AutofillPopupControllerImpl::AutofillPopupControllerImpl( |
| AutofillPopupDelegate* delegate, |
| gfx::NativeView container_view, |
| - const gfx::Rect& element_bounds) |
| + const gfx::RectF& element_bounds) |
| : view_(NULL), |
| delegate_(delegate), |
| container_view_(container_view), |
| @@ -287,7 +291,7 @@ gfx::NativeView AutofillPopupControllerImpl::container_view() const { |
| return container_view_; |
| } |
| -const gfx::Rect& AutofillPopupControllerImpl::element_bounds() const { |
| +const gfx::RectF& AutofillPopupControllerImpl::element_bounds() const { |
| return element_bounds_; |
| } |
| @@ -505,7 +509,7 @@ int AutofillPopupControllerImpl::GetDesiredPopupWidth() const { |
| return 0; |
| } |
| - int popup_width = element_bounds().width(); |
| + int popup_width = round(element_bounds().width()); |
| DCHECK_EQ(names().size(), subtexts().size()); |
| for (size_t i = 0; i < names().size(); ++i) { |
| int row_size = name_font_.GetStringWidth(names()[i]) + |
| @@ -551,16 +555,16 @@ void AutofillPopupControllerImpl::UpdatePopupBounds() { |
| // 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 |
| // popup go could). |
| - gfx::Point top_left_corner_of_popup = element_bounds().origin() + |
| - gfx::Vector2d(element_bounds().width() - popup_required_width, |
| + gfx::Point top_left_corner_of_popup = round(element_bounds().origin()) + |
|
Ilya Sherman
2013/02/04 23:23:28
Rounding a gfx::Point doesn't compile.
|
| + gfx::Vector2d(round(element_bounds().width()) - popup_required_width, |
| -popup_height); |
| // This is the bottom right point of the popup if the popup is below the |
| // element and grows to the right (since the is the lowest and furthest right |
| // the popup could go). |
| - gfx::Point bottom_right_corner_of_popup = element_bounds().origin() + |
| + gfx::Point bottom_right_corner_of_popup = round(element_bounds().origin()) + |
|
Ilya Sherman
2013/02/04 23:23:28
Ditto.
|
| gfx::Vector2d(popup_required_width, |
| - element_bounds().height() + popup_height); |
| + round(element_bounds().height()) + popup_height); |
| gfx::Display top_left_display = GetDisplayNearestPoint( |
| top_left_corner_of_popup); |
| @@ -598,10 +602,10 @@ std::pair<int, int> AutofillPopupControllerImpl::CalculatePopupXAndWidth( |
| // the end position if it is growing to the left, capped to screen space. |
| int right_growth_start = std::max(leftmost_display_x, |
| std::min(rightmost_display_x, |
| - element_bounds().x())); |
| + round(element_bounds().x()))); |
| int left_growth_end = std::max(leftmost_display_x, |
| std::min(rightmost_display_x, |
| - element_bounds().right())); |
| + round(element_bounds().right()))); |
| int right_available = rightmost_display_x - right_growth_start; |
| int left_available = left_growth_end - leftmost_display_x; |
| @@ -631,10 +635,9 @@ std::pair<int,int> AutofillPopupControllerImpl::CalculatePopupYAndHeight( |
| // the end position if it is growing up, capped to screen space. |
| int top_growth_end = std::max(topmost_display_y, |
| std::min(bottommost_display_y, |
| - element_bounds().y())); |
| + round(element_bounds().y()))); |
| int bottom_growth_start = std::max(topmost_display_y, |
|
Ilya Sherman
2013/02/04 23:23:28
nit: Since you're now wrapping one of the argument
|
| - std::min(bottommost_display_y, |
| - element_bounds().bottom())); |
| + std::min(bottommost_display_y, round(element_bounds().bottom()))); |
| int top_available = bottom_growth_start - topmost_display_y; |
| int bottom_available = bottommost_display_y - top_growth_end; |