diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 20:03:41 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 20:03:41 +0000 |
commit | b82c42c45ee1b113377a2800b36d6e5e05b8b8e1 (patch) | |
tree | 6034126ffc720a18cabc0bdb211de7ca10233670 /ui/gfx/screen_mac.mm | |
parent | ce8d264d556f06a4b46b58b95bc82a884bb315d0 (diff) | |
download | chromium_src-b82c42c45ee1b113377a2800b36d6e5e05b8b8e1.zip chromium_src-b82c42c45ee1b113377a2800b36d6e5e05b8b8e1.tar.gz chromium_src-b82c42c45ee1b113377a2800b36d6e5e05b8b8e1.tar.bz2 |
* Separated implementation class from gfx::Screen
* Moved Monitor class to gfx/.
* Converted all use of gfx::Screen to match new API
BUG=115347,111990
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9960042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133961 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/screen_mac.mm')
-rw-r--r-- | ui/gfx/screen_mac.mm | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/ui/gfx/screen_mac.mm b/ui/gfx/screen_mac.mm index a3b7306d..64dbf86 100644 --- a/ui/gfx/screen_mac.mm +++ b/ui/gfx/screen_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,6 +7,9 @@ #import <ApplicationServices/ApplicationServices.h> #import <Cocoa/Cocoa.h> +#include "base/logging.h" +#include "ui/gfx/monitor.h" + namespace { gfx::Rect ConvertCoordinateSystem(NSRect ns_rect) { @@ -38,6 +41,25 @@ NSScreen* GetMatchingScreen(const gfx::Rect& match_rect) { return max_screen; } +gfx::Monitor GetMonitorForScreen(NSScreen* screen, bool is_primary) { + NSRect frame = [screen frame]; + // TODO(oshima): Implement ID and Observer. + gfx::Monitor monitor(0, gfx::Rect(NSRectToCGRect(frame))); + + NSRect visible_frame = [screen visibleFrame]; + + // Convert work area's coordinate systems. + if (is_primary) { + gfx::Rect work_area = gfx::Rect(NSRectToCGRect(visible_frame)); + work_area.set_y(frame.size.height - visible_frame.origin.y - + visible_frame.size.height); + monitor.set_work_area(work_area); + } else { + monitor.set_work_area(ConvertCoordinateSystem(visible_frame)); + } + return monitor; +} + } // namespace namespace gfx { @@ -52,39 +74,24 @@ gfx::Point Screen::GetCursorScreenPoint() { } // static -gfx::Rect Screen::GetPrimaryMonitorWorkArea() { +gfx::Monitor Screen::GetPrimaryMonitor() { // Primary monitor is defined as the monitor with the menubar, // which is always at index 0. NSScreen* primary = [[NSScreen screens] objectAtIndex:0]; - NSRect frame = [primary frame]; - NSRect visible_frame = [primary visibleFrame]; + gfx::Monitor monitor = GetMonitorForScreen(primary, true /* primary */); - // Convert coordinate systems. - gfx::Rect rect = gfx::Rect(NSRectToCGRect(visible_frame)); - rect.set_y(frame.size.height - visible_frame.origin.y - - visible_frame.size.height); - return rect; -} - -// static -gfx::Rect Screen::GetPrimaryMonitorBounds() { - // Primary monitor is defined as the monitor with the menubar, - // which is always at index 0. - NSScreen* primary = [[NSScreen screens] objectAtIndex:0]; - return gfx::Rect(NSRectToCGRect([primary frame])); + CGDirectDisplayID main_display = CGMainDisplayID(); + CHECK_EQ(static_cast<const int>(CGDisplayPixelsWide(main_display)), + monitor.size().width()); + CHECK_EQ(static_cast<const int>(CGDisplayPixelsHigh(main_display)), + monitor.size().height()); + return monitor; } // static -gfx::Rect Screen::GetMonitorWorkAreaMatching(const gfx::Rect& match_rect) { +gfx::Monitor Screen::GetMonitorMatching(const gfx::Rect& match_rect) { NSScreen* match_screen = GetMatchingScreen(match_rect); - return ConvertCoordinateSystem([match_screen visibleFrame]); -} - -// static -gfx::Size Screen::GetPrimaryMonitorSize() { - CGDirectDisplayID main_display = CGMainDisplayID(); - return gfx::Size(CGDisplayPixelsWide(main_display), - CGDisplayPixelsHigh(main_display)); + return GetMonitorForScreen(match_screen, false /* may not be primary */); } // static |