Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / ui / gfx / mac / coordinate_conversion.mm
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.
4
5 #import "ui/gfx/mac/coordinate_conversion.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #include "ui/gfx/geometry/rect.h"
10
11 namespace gfx {
12
13 namespace {
14
15 // The height of the primary display, which OSX defines as the monitor with the
16 // menubar. This is always at index 0.
17 CGFloat PrimaryDisplayHeight() {
18   return NSMaxY([[[NSScreen screens] objectAtIndex:0] frame]);
19 }
20
21 }  // namespace
22
23 NSRect ScreenRectToNSRect(const gfx::Rect& rect) {
24   return NSMakeRect(rect.x(),
25                     PrimaryDisplayHeight() - rect.y() - rect.height(),
26                     rect.width(),
27                     rect.height());
28 }
29
30 gfx::Rect ScreenRectFromNSRect(const NSRect& rect) {
31   return gfx::Rect(rect.origin.x,
32                    PrimaryDisplayHeight() - rect.origin.y - rect.size.height,
33                    rect.size.width,
34                    rect.size.height);
35 }
36
37 }  // namespace gfx