| 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 #import "ui/gfx/mac/coordinate_conversion.h" | 5 #import "ui/gfx/mac/coordinate_conversion.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "ui/gfx/geometry/rect.h" | 9 #include "ui/gfx/geometry/rect.h" |
| 10 #include "ui/gfx/geometry/point.h" |
| 10 | 11 |
| 11 namespace gfx { | 12 namespace gfx { |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 // The height of the primary display, which OSX defines as the monitor with the | 16 // The height of the primary display, which OSX defines as the monitor with the |
| 16 // menubar. This is always at index 0. | 17 // menubar. This is always at index 0. |
| 17 CGFloat PrimaryDisplayHeight() { | 18 CGFloat PrimaryDisplayHeight() { |
| 18 return NSMaxY([[[NSScreen screens] objectAtIndex:0] frame]); | 19 return NSMaxY([[[NSScreen screens] objectAtIndex:0] frame]); |
| 19 } | 20 } |
| 20 | 21 |
| 21 } // namespace | 22 } // namespace |
| 22 | 23 |
| 23 NSRect ScreenRectToNSRect(const gfx::Rect& rect) { | 24 NSRect ScreenRectToNSRect(const gfx::Rect& rect) { |
| 24 return NSMakeRect(rect.x(), | 25 return NSMakeRect(rect.x(), |
| 25 PrimaryDisplayHeight() - rect.y() - rect.height(), | 26 PrimaryDisplayHeight() - rect.y() - rect.height(), |
| 26 rect.width(), | 27 rect.width(), |
| 27 rect.height()); | 28 rect.height()); |
| 28 } | 29 } |
| 29 | 30 |
| 30 gfx::Rect ScreenRectFromNSRect(const NSRect& rect) { | 31 gfx::Rect ScreenRectFromNSRect(const NSRect& rect) { |
| 31 return gfx::Rect(rect.origin.x, | 32 return gfx::Rect(rect.origin.x, |
| 32 PrimaryDisplayHeight() - rect.origin.y - rect.size.height, | 33 PrimaryDisplayHeight() - rect.origin.y - rect.size.height, |
| 33 rect.size.width, | 34 rect.size.width, |
| 34 rect.size.height); | 35 rect.size.height); |
| 35 } | 36 } |
| 36 | 37 |
| 38 NSPoint ScreenPointToNSPoint(const gfx::Point& point) { |
| 39 return NSMakePoint(point.x(), PrimaryDisplayHeight() - point.y()); |
| 40 } |
| 41 |
| 42 gfx::Point ScreenPointFromNSPoint(const NSPoint& point) { |
| 43 return gfx::Point(point.x, PrimaryDisplayHeight() - point.y); |
| 44 } |
| 45 |
| 37 } // namespace gfx | 46 } // namespace gfx |
| OLD | NEW |