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
3 // found in the LICENSE file.
5 #import "ui/gfx/mac/coordinate_conversion.h"
7 #import <Cocoa/Cocoa.h>
9 #include "ui/gfx/geometry/point.h"
10 #include "ui/gfx/geometry/rect.h"
16 // The height of the primary display, which OSX defines as the monitor with the
17 // menubar. This is always at index 0.
18 CGFloat PrimaryDisplayHeight() {
19 return NSMaxY([[[NSScreen screens] objectAtIndex:0] frame]);
24 NSRect ScreenRectToNSRect(const Rect& rect) {
25 return NSMakeRect(rect.x(),
26 PrimaryDisplayHeight() - rect.y() - rect.height(),
31 Rect ScreenRectFromNSRect(const NSRect& rect) {
32 return Rect(rect.origin.x,
33 PrimaryDisplayHeight() - rect.origin.y - rect.size.height,
34 rect.size.width, rect.size.height);
37 NSPoint ScreenPointToNSPoint(const Point& point) {
38 return NSMakePoint(point.x(), PrimaryDisplayHeight() - point.y());
41 Point ScreenPointFromNSPoint(const NSPoint& point) {
42 return Point(point.x, PrimaryDisplayHeight() - point.y);