| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/autofill/popup_controller_common.h" | 5 #include "chrome/browser/ui/autofill/popup_controller_common.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| 11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 12 #include "ui/gfx/display.h" | 12 #include "ui/gfx/display.h" |
| 13 #include "ui/gfx/geometry/rect_conversions.h" | 13 #include "ui/gfx/geometry/rect_conversions.h" |
| 14 #include "ui/gfx/geometry/vector2d.h" | 14 #include "ui/gfx/geometry/vector2d.h" |
| 15 #include "ui/gfx/screen.h" | 15 #include "ui/gfx/screen.h" |
| 16 | 16 |
| 17 namespace autofill { | 17 namespace autofill { |
| 18 | 18 |
| 19 PopupControllerCommon::PopupControllerCommon( | 19 PopupControllerCommon::PopupControllerCommon( |
| 20 const gfx::RectF& element_bounds, | 20 const gfx::RectF& element_bounds, |
| 21 base::i18n::TextDirection text_direction, |
| 21 const gfx::NativeView container_view, | 22 const gfx::NativeView container_view, |
| 22 content::WebContents* web_contents) | 23 content::WebContents* web_contents) |
| 23 : element_bounds_(element_bounds), | 24 : element_bounds_(element_bounds), |
| 25 text_direction_(text_direction), |
| 24 container_view_(container_view), | 26 container_view_(container_view), |
| 25 web_contents_(web_contents), | 27 web_contents_(web_contents), |
| 26 key_press_event_target_(NULL) {} | 28 key_press_event_target_(NULL) { |
| 29 } |
| 27 PopupControllerCommon::~PopupControllerCommon() {} | 30 PopupControllerCommon::~PopupControllerCommon() {} |
| 28 | 31 |
| 29 void PopupControllerCommon::SetKeyPressCallback( | 32 void PopupControllerCommon::SetKeyPressCallback( |
| 30 content::RenderWidgetHost::KeyPressEventCallback callback) { | 33 content::RenderWidgetHost::KeyPressEventCallback callback) { |
| 31 DCHECK(key_press_event_callback_.is_null()); | 34 DCHECK(key_press_event_callback_.is_null()); |
| 32 key_press_event_callback_ = callback; | 35 key_press_event_callback_ = callback; |
| 33 } | 36 } |
| 34 | 37 |
| 35 void PopupControllerCommon::RegisterKeyPressCallback() { | 38 void PopupControllerCommon::RegisterKeyPressCallback() { |
| 36 if (web_contents_ && !key_press_event_target_) { | 39 if (web_contents_ && !key_press_event_target_) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 int left_growth_end = std::max(leftmost_display_x, | 78 int left_growth_end = std::max(leftmost_display_x, |
| 76 std::min(rightmost_display_x, | 79 std::min(rightmost_display_x, |
| 77 RoundedElementBounds().right())); | 80 RoundedElementBounds().right())); |
| 78 | 81 |
| 79 int right_available = rightmost_display_x - right_growth_start; | 82 int right_available = rightmost_display_x - right_growth_start; |
| 80 int left_available = left_growth_end - leftmost_display_x; | 83 int left_available = left_growth_end - leftmost_display_x; |
| 81 | 84 |
| 82 int popup_width = std::min(popup_required_width, | 85 int popup_width = std::min(popup_required_width, |
| 83 std::max(right_available, left_available)); | 86 std::max(right_available, left_available)); |
| 84 | 87 |
| 85 // If there is enough space for the popup on the right, show it there, | 88 std::pair<int, int> grow_right(right_growth_start, popup_width); |
| 86 // otherwise choose the larger size. | 89 std::pair<int, int> grow_left(left_growth_end - popup_width, popup_width); |
| 87 if (right_available >= popup_width || right_available >= left_available) | 90 |
| 88 return std::make_pair(right_growth_start, popup_width); | 91 // Prefer to grow towards the end (right for LTR, left for RTL). But if there |
| 89 else | 92 // is not enough space available in the desired direction and more space in |
| 90 return std::make_pair(left_growth_end - popup_width, popup_width); | 93 // the other direction, reverse it. |
| 94 if (is_rtl()) { |
| 95 return left_available >= popup_width || left_available >= right_available |
| 96 ? grow_left |
| 97 : grow_right; |
| 98 } |
| 99 return right_available >= popup_width || right_available >= left_available |
| 100 ? grow_right |
| 101 : grow_left; |
| 91 } | 102 } |
| 92 | 103 |
| 93 std::pair<int,int> PopupControllerCommon::CalculatePopupYAndHeight( | 104 std::pair<int,int> PopupControllerCommon::CalculatePopupYAndHeight( |
| 94 const gfx::Display& top_display, | 105 const gfx::Display& top_display, |
| 95 const gfx::Display& bottom_display, | 106 const gfx::Display& bottom_display, |
| 96 int popup_required_height) const { | 107 int popup_required_height) const { |
| 97 int topmost_display_y = top_display.bounds().y(); | 108 int topmost_display_y = top_display.bounds().y(); |
| 98 int bottommost_display_y = | 109 int bottommost_display_y = |
| 99 bottom_display.GetSizeInPixel().height() + bottom_display.bounds().y(); | 110 bottom_display.GetSizeInPixel().height() + bottom_display.bounds().y(); |
| 100 | 111 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 bottom_right_display, | 163 bottom_right_display, |
| 153 desired_height); | 164 desired_height); |
| 154 | 165 |
| 155 return gfx::Rect(popup_x_and_width.first, | 166 return gfx::Rect(popup_x_and_width.first, |
| 156 popup_y_and_height.first, | 167 popup_y_and_height.first, |
| 157 popup_x_and_width.second, | 168 popup_x_and_width.second, |
| 158 popup_y_and_height.second); | 169 popup_y_and_height.second); |
| 159 } | 170 } |
| 160 | 171 |
| 161 } // namespace autofill | 172 } // namespace autofill |
| OLD | NEW |