Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_view_common.h" | 5 #include "chrome/browser/ui/autofill/popup_view_common.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ui/gfx/display.h" | 10 #include "ui/display/display.h" |
| 11 #include "ui/display/screen.h" | |
| 11 #include "ui/gfx/geometry/point.h" | 12 #include "ui/gfx/geometry/point.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/gfx/geometry/vector2d.h" | 14 #include "ui/gfx/geometry/vector2d.h" |
| 14 #include "ui/gfx/screen.h" | |
| 15 | 15 |
| 16 namespace autofill { | 16 namespace autofill { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 std::pair<int, int> CalculatePopupXAndWidth(const gfx::Display& left_display, | 20 std::pair<int, int> CalculatePopupXAndWidth( |
| 21 const gfx::Display& right_display, | 21 const display::Display& left_display, |
| 22 int popup_required_width, | 22 const display::Display& right_display, |
| 23 const gfx::Rect element_bounds, | 23 int popup_required_width, |
| 24 bool is_rtl) { | 24 const gfx::Rect element_bounds, |
|
Lei Zhang
2016/04/28 20:13:10
Oh, I noticed these aren't being passed in by refe
oshima
2016/04/28 20:19:04
Done.
| |
| 25 bool is_rtl) { | |
| 25 int leftmost_display_x = left_display.bounds().x(); | 26 int leftmost_display_x = left_display.bounds().x(); |
| 26 int rightmost_display_x = | 27 int rightmost_display_x = |
| 27 right_display.GetSizeInPixel().width() + right_display.bounds().x(); | 28 right_display.GetSizeInPixel().width() + right_display.bounds().x(); |
| 28 | 29 |
| 29 // Calculate the start coordinates for the popup if it is growing right or | 30 // Calculate the start coordinates for the popup if it is growing right or |
| 30 // the end position if it is growing to the left, capped to screen space. | 31 // the end position if it is growing to the left, capped to screen space. |
| 31 int right_growth_start = std::max( | 32 int right_growth_start = std::max( |
| 32 leftmost_display_x, std::min(rightmost_display_x, element_bounds.x())); | 33 leftmost_display_x, std::min(rightmost_display_x, element_bounds.x())); |
| 33 int left_growth_end = | 34 int left_growth_end = |
| 34 std::max(leftmost_display_x, | 35 std::max(leftmost_display_x, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 51 ? grow_left | 52 ? grow_left |
| 52 : grow_right; | 53 : grow_right; |
| 53 } | 54 } |
| 54 return right_available >= popup_width || right_available >= left_available | 55 return right_available >= popup_width || right_available >= left_available |
| 55 ? grow_right | 56 ? grow_right |
| 56 : grow_left; | 57 : grow_left; |
| 57 } | 58 } |
| 58 | 59 |
| 59 // Calculates the height of the popup and the y position of it. These values | 60 // Calculates the height of the popup and the y position of it. These values |
| 60 // will stay on the screen. | 61 // will stay on the screen. |
| 61 std::pair<int, int> CalculatePopupYAndHeight(const gfx::Display& top_display, | 62 std::pair<int, int> CalculatePopupYAndHeight( |
| 62 const gfx::Display& bottom_display, | 63 const display::Display& top_display, |
| 63 int popup_required_height, | 64 const display::Display& bottom_display, |
| 64 const gfx::Rect element_bounds) { | 65 int popup_required_height, |
| 66 const gfx::Rect element_bounds) { | |
|
oshima
2016/04/28 20:19:04
and here too
| |
| 65 int topmost_display_y = top_display.bounds().y(); | 67 int topmost_display_y = top_display.bounds().y(); |
| 66 int bottommost_display_y = | 68 int bottommost_display_y = |
| 67 bottom_display.GetSizeInPixel().height() + bottom_display.bounds().y(); | 69 bottom_display.GetSizeInPixel().height() + bottom_display.bounds().y(); |
| 68 | 70 |
| 69 // Calculate the start coordinates for the popup if it is growing down or | 71 // Calculate the start coordinates for the popup if it is growing down or |
| 70 // the end position if it is growing up, capped to screen space. | 72 // the end position if it is growing up, capped to screen space. |
| 71 int top_growth_end = std::max( | 73 int top_growth_end = std::max( |
| 72 topmost_display_y, std::min(bottommost_display_y, element_bounds.y())); | 74 topmost_display_y, std::min(bottommost_display_y, element_bounds.y())); |
| 73 int bottom_growth_start = | 75 int bottom_growth_start = |
| 74 std::max(topmost_display_y, | 76 std::max(topmost_display_y, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 103 element_bounds.origin() + | 105 element_bounds.origin() + |
| 104 gfx::Vector2d(element_bounds.width() - desired_width, -desired_height); | 106 gfx::Vector2d(element_bounds.width() - desired_width, -desired_height); |
| 105 | 107 |
| 106 // This is the bottom right point of the popup if the popup is below the | 108 // This is the bottom right point of the popup if the popup is below the |
| 107 // element and grows to the right (since the is the lowest and furthest right | 109 // element and grows to the right (since the is the lowest and furthest right |
| 108 // the popup could go). | 110 // the popup could go). |
| 109 gfx::Point bottom_right_corner_of_popup = | 111 gfx::Point bottom_right_corner_of_popup = |
| 110 element_bounds.origin() + | 112 element_bounds.origin() + |
| 111 gfx::Vector2d(desired_width, element_bounds.height() + desired_height); | 113 gfx::Vector2d(desired_width, element_bounds.height() + desired_height); |
| 112 | 114 |
| 113 gfx::Display top_left_display = | 115 display::Display top_left_display = |
| 114 GetDisplayNearestPoint(top_left_corner_of_popup, container_view); | 116 GetDisplayNearestPoint(top_left_corner_of_popup, container_view); |
| 115 gfx::Display bottom_right_display = | 117 display::Display bottom_right_display = |
| 116 GetDisplayNearestPoint(bottom_right_corner_of_popup, container_view); | 118 GetDisplayNearestPoint(bottom_right_corner_of_popup, container_view); |
| 117 | 119 |
| 118 std::pair<int, int> popup_x_and_width = | 120 std::pair<int, int> popup_x_and_width = |
| 119 CalculatePopupXAndWidth(top_left_display, bottom_right_display, | 121 CalculatePopupXAndWidth(top_left_display, bottom_right_display, |
| 120 desired_width, element_bounds, is_rtl); | 122 desired_width, element_bounds, is_rtl); |
| 121 std::pair<int, int> popup_y_and_height = CalculatePopupYAndHeight( | 123 std::pair<int, int> popup_y_and_height = CalculatePopupYAndHeight( |
| 122 top_left_display, bottom_right_display, desired_height, element_bounds); | 124 top_left_display, bottom_right_display, desired_height, element_bounds); |
| 123 | 125 |
| 124 return gfx::Rect(popup_x_and_width.first, popup_y_and_height.first, | 126 return gfx::Rect(popup_x_and_width.first, popup_y_and_height.first, |
| 125 popup_x_and_width.second, popup_y_and_height.second); | 127 popup_x_and_width.second, popup_y_and_height.second); |
| 126 } | 128 } |
| 127 | 129 |
| 128 gfx::Display PopupViewCommon::GetDisplayNearestPoint( | 130 display::Display PopupViewCommon::GetDisplayNearestPoint( |
| 129 const gfx::Point& point, | 131 const gfx::Point& point, |
| 130 gfx::NativeView container_view) { | 132 gfx::NativeView container_view) { |
| 131 return gfx::Screen::GetScreen()->GetDisplayNearestPoint(point); | 133 return display::Screen::GetScreen()->GetDisplayNearestPoint(point); |
| 132 } | 134 } |
| 133 | 135 |
| 134 } // namespace autofill | 136 } // namespace autofill |
| OLD | NEW |