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 "ash/display/display_util.h" | 5 #include "ash/display/display_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/display/display_info.h" | 9 #include "ash/display/display_info.h" |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 break; | 157 break; |
158 } | 158 } |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 gfx::Rect GetNativeEdgeBounds(AshWindowTreeHost* ash_host, | 162 gfx::Rect GetNativeEdgeBounds(AshWindowTreeHost* ash_host, |
163 const gfx::Rect& bounds_in_screen) { | 163 const gfx::Rect& bounds_in_screen) { |
164 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); | 164 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); |
165 gfx::Rect native_bounds = host->GetBounds(); | 165 gfx::Rect native_bounds = host->GetBounds(); |
166 native_bounds.Inset(ash_host->GetHostInsets()); | 166 native_bounds.Inset(ash_host->GetHostInsets()); |
167 | 167 gfx::Point start_in_native = bounds_in_screen.origin(); |
168 bool vertical = bounds_in_screen.width() < bounds_in_screen.height(); | 168 gfx::Point end_in_native = bounds_in_screen.bottom_right(); |
169 gfx::Point start_in_native; | |
170 gfx::Point end_in_native; | |
171 | |
172 if (vertical) { | |
173 start_in_native = bounds_in_screen.origin(); | |
174 end_in_native = start_in_native; | |
175 end_in_native.set_y(bounds_in_screen.bottom()); | |
176 } else { | |
177 start_in_native = bounds_in_screen.origin(); | |
178 end_in_native = start_in_native; | |
179 end_in_native.set_x(bounds_in_screen.right()); | |
180 } | |
181 | 169 |
182 ConvertPointFromScreenToNative(host, &start_in_native); | 170 ConvertPointFromScreenToNative(host, &start_in_native); |
183 ConvertPointFromScreenToNative(host, &end_in_native); | 171 ConvertPointFromScreenToNative(host, &end_in_native); |
184 if (vertical) { | 172 |
| 173 if (std::abs(start_in_native.x() - end_in_native.x()) < |
| 174 std::abs(start_in_native.y() - end_in_native.y())) { |
185 // vertical in native | 175 // vertical in native |
186 int x = std::abs(native_bounds.x() - start_in_native.x()) < | 176 int x = std::abs(native_bounds.x() - start_in_native.x()) < |
187 std::abs(native_bounds.right() - start_in_native.x()) | 177 std::abs(native_bounds.right() - start_in_native.x()) |
188 ? native_bounds.x() | 178 ? native_bounds.x() |
189 : native_bounds.right() - 1; | 179 : native_bounds.right() - 1; |
190 return gfx::Rect(x, std::min(start_in_native.y(), end_in_native.y()), 1, | 180 return gfx::Rect(x, std::min(start_in_native.y(), end_in_native.y()), 1, |
191 end_in_native.y() - start_in_native.y()); | 181 std::abs(end_in_native.y() - start_in_native.y())); |
192 } else { | 182 } else { |
193 // horizontal in native | 183 // horizontal in native |
194 int y = std::abs(native_bounds.y() - start_in_native.y()) < | 184 int y = std::abs(native_bounds.y() - start_in_native.y()) < |
195 std::abs(native_bounds.bottom() - start_in_native.y()) | 185 std::abs(native_bounds.bottom() - start_in_native.y()) |
196 ? native_bounds.y() | 186 ? native_bounds.y() |
197 : native_bounds.bottom() - 1; | 187 : native_bounds.bottom() - 1; |
198 return gfx::Rect(std::min(start_in_native.x(), end_in_native.x()), y, | 188 return gfx::Rect(std::min(start_in_native.x(), end_in_native.x()), y, |
199 end_in_native.x() - start_in_native.x(), 1); | 189 std::abs(end_in_native.x() - start_in_native.x()), 1); |
200 } | 190 } |
201 } | 191 } |
202 | 192 |
203 // Moves the cursor to the point inside the root that is closest to | 193 // Moves the cursor to the point inside the root that is closest to |
204 // the point_in_screen, which is outside of the root window. | 194 // the point_in_screen, which is outside of the root window. |
205 void MoveCursorTo(AshWindowTreeHost* ash_host, | 195 void MoveCursorTo(AshWindowTreeHost* ash_host, |
206 const gfx::Point& point_in_screen, | 196 const gfx::Point& point_in_screen, |
207 bool update_last_location_now) { | 197 bool update_last_location_now) { |
208 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); | 198 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); |
209 gfx::Point point_in_native = point_in_screen; | 199 gfx::Point point_in_native = point_in_screen; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 int FindDisplayIndexContainingPoint(const std::vector<gfx::Display>& displays, | 236 int FindDisplayIndexContainingPoint(const std::vector<gfx::Display>& displays, |
247 const gfx::Point& point_in_screen) { | 237 const gfx::Point& point_in_screen) { |
248 auto iter = std::find_if(displays.begin(), displays.end(), | 238 auto iter = std::find_if(displays.begin(), displays.end(), |
249 [point_in_screen](const gfx::Display& display) { | 239 [point_in_screen](const gfx::Display& display) { |
250 return display.bounds().Contains(point_in_screen); | 240 return display.bounds().Contains(point_in_screen); |
251 }); | 241 }); |
252 return iter == displays.end() ? -1 : (iter - displays.begin()); | 242 return iter == displays.end() ? -1 : (iter - displays.begin()); |
253 } | 243 } |
254 | 244 |
255 } // namespace ash | 245 } // namespace ash |
OLD | NEW |