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

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

Issue 1151263002: Fix positioning of autofill popup on rtl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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/popup_controller_common.cc
diff --git a/chrome/browser/ui/autofill/popup_controller_common.cc b/chrome/browser/ui/autofill/popup_controller_common.cc
index 1de4c568eba92bc9660fe541c2e26a812b4c676c..87881ddc0dfe5d00246a30910be28e2c2f96f100 100644
--- a/chrome/browser/ui/autofill/popup_controller_common.cc
+++ b/chrome/browser/ui/autofill/popup_controller_common.cc
@@ -18,12 +18,15 @@ namespace autofill {
PopupControllerCommon::PopupControllerCommon(
const gfx::RectF& element_bounds,
+ base::i18n::TextDirection text_direction,
const gfx::NativeView container_view,
content::WebContents* web_contents)
: element_bounds_(element_bounds),
+ text_direction_(text_direction),
container_view_(container_view),
web_contents_(web_contents),
- key_press_event_target_(NULL) {}
+ key_press_event_target_(NULL) {
+}
PopupControllerCommon::~PopupControllerCommon() {}
void PopupControllerCommon::SetKeyPressCallback(
@@ -82,12 +85,20 @@ std::pair<int, int> PopupControllerCommon::CalculatePopupXAndWidth(
int popup_width = std::min(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.
- if (right_available >= popup_width || right_available >= left_available)
- return std::make_pair(right_growth_start, popup_width);
- else
- return std::make_pair(left_growth_end - popup_width, popup_width);
+ std::pair<int, int> grow_right(right_growth_start, popup_width);
+ std::pair<int, int> grow_left(left_growth_end - popup_width, popup_width);
+
+ // Prefer to grow towards the end (right for LTR, left for RTL). But if there
+ // is not enough space available in the desired direction and more space in
+ // the other direction, reverse it.
+ if (is_rtl()) {
+ return left_available >= popup_width || left_available >= right_available
+ ? grow_left
+ : grow_right;
+ }
+ return right_available >= popup_width || right_available >= left_available
+ ? grow_right
+ : grow_left;
}
std::pair<int,int> PopupControllerCommon::CalculatePopupYAndHeight(

Powered by Google App Engine
This is Rietveld 408576698