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" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 bottom_available >= top_available) { | 115 bottom_available >= top_available) { |
116 // The popup can appear below the field. | 116 // The popup can appear below the field. |
117 return std::make_pair(bottom_growth_start, popup_required_height); | 117 return std::make_pair(bottom_growth_start, popup_required_height); |
118 } else { | 118 } else { |
119 // The popup must appear above the field. | 119 // The popup must appear above the field. |
120 return std::make_pair(top_growth_end - popup_required_height, | 120 return std::make_pair(top_growth_end - popup_required_height, |
121 popup_required_height); | 121 popup_required_height); |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 gfx::Rect PopupControllerCommon::GetPopupBounds( | 125 gfx::Rect PopupControllerCommon::GetPopupBounds(int desired_width, |
126 int popup_required_height, | 126 int desired_height) const { |
127 int popup_required_width) const { | |
128 // This is the top left point of the popup if the popup is above the element | 127 // This is the top left point of the popup if the popup is above the element |
129 // and grows to the left (since that is the highest and furthest left the | 128 // and grows to the left (since that is the highest and furthest left the |
130 // popup go could). | 129 // popup go could). |
131 gfx::Point top_left_corner_of_popup = RoundedElementBounds().origin() + | 130 gfx::Point top_left_corner_of_popup = RoundedElementBounds().origin() + |
132 gfx::Vector2d(RoundedElementBounds().width() - popup_required_width, | 131 gfx::Vector2d(RoundedElementBounds().width() - desired_width, |
133 -popup_required_height); | 132 -desired_height); |
134 | 133 |
135 // This is the bottom right point of the popup if the popup is below the | 134 // This is the bottom right point of the popup if the popup is below the |
136 // element and grows to the right (since the is the lowest and furthest right | 135 // element and grows to the right (since the is the lowest and furthest right |
137 // the popup could go). | 136 // the popup could go). |
138 gfx::Point bottom_right_corner_of_popup = RoundedElementBounds().origin() + | 137 gfx::Point bottom_right_corner_of_popup = RoundedElementBounds().origin() + |
139 gfx::Vector2d(popup_required_width, | 138 gfx::Vector2d(desired_width, |
140 RoundedElementBounds().height() + popup_required_height); | 139 RoundedElementBounds().height() + desired_height); |
141 | 140 |
142 gfx::Display top_left_display = GetDisplayNearestPoint( | 141 gfx::Display top_left_display = GetDisplayNearestPoint( |
143 top_left_corner_of_popup); | 142 top_left_corner_of_popup); |
144 gfx::Display bottom_right_display = GetDisplayNearestPoint( | 143 gfx::Display bottom_right_display = GetDisplayNearestPoint( |
145 bottom_right_corner_of_popup); | 144 bottom_right_corner_of_popup); |
146 | 145 |
147 std::pair<int, int> popup_x_and_width = | 146 std::pair<int, int> popup_x_and_width = |
148 CalculatePopupXAndWidth(top_left_display, | 147 CalculatePopupXAndWidth(top_left_display, |
149 bottom_right_display, | 148 bottom_right_display, |
150 popup_required_width); | 149 desired_width); |
151 std::pair<int, int> popup_y_and_height = | 150 std::pair<int, int> popup_y_and_height = |
152 CalculatePopupYAndHeight(top_left_display, | 151 CalculatePopupYAndHeight(top_left_display, |
153 bottom_right_display, | 152 bottom_right_display, |
154 popup_required_height); | 153 desired_height); |
155 | 154 |
156 return gfx::Rect(popup_x_and_width.first, | 155 return gfx::Rect(popup_x_and_width.first, |
157 popup_y_and_height.first, | 156 popup_y_and_height.first, |
158 popup_x_and_width.second, | 157 popup_x_and_width.second, |
159 popup_y_and_height.second); | 158 popup_y_and_height.second); |
160 } | 159 } |
161 | 160 |
162 } // namespace autofill | 161 } // namespace autofill |
OLD | NEW |