mac: Also use [NSScreen mainScreen] in other places

This commit is contained in:
Cheng Zhao 2015-05-04 12:06:03 +08:00
parent f5cf3556b1
commit 7142cae041

View file

@ -11,14 +11,14 @@
#include "atom/common/options_switches.h" #include "atom/common/options_switches.h"
#include "base/mac/mac_util.h" #include "base/mac/mac_util.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "brightray/browser/inspectable_web_contents.h"
#include "brightray/browser/inspectable_web_contents_view.h"
#include "content/public/browser/browser_accessibility_state.h" #include "content/public/browser/browser_accessibility_state.h"
#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
#include "vendor/brightray/browser/inspectable_web_contents.h"
#include "vendor/brightray/browser/inspectable_web_contents_view.h"
static const CGFloat kAtomWindowCornerRadius = 4.0; static const CGFloat kAtomWindowCornerRadius = 4.0;
@ -303,7 +303,7 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
options.Get(switches::kWidth, &width); options.Get(switches::kWidth, &width);
options.Get(switches::kHeight, &height); options.Get(switches::kHeight, &height);
NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; NSRect main_screen_rect = [[NSScreen mainScreen] frame];
NSRect cocoa_bounds = NSMakeRect( NSRect cocoa_bounds = NSMakeRect(
round((NSWidth(main_screen_rect) - width) / 2) , round((NSWidth(main_screen_rect) - width) / 2) ,
round((NSHeight(main_screen_rect) - height) / 2), round((NSHeight(main_screen_rect) - height) / 2),
@ -463,7 +463,7 @@ void NativeWindowMac::SetBounds(const gfx::Rect& bounds) {
bounds.width(), bounds.width(),
bounds.height()); bounds.height());
// Flip coordinates based on the primary screen. // Flip coordinates based on the primary screen.
NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; NSScreen* screen = [NSScreen mainScreen];
cocoa_bounds.origin.y = cocoa_bounds.origin.y =
NSHeight([screen frame]) - bounds.height() - bounds.y(); NSHeight([screen frame]) - bounds.height() - bounds.y();
@ -472,13 +472,10 @@ void NativeWindowMac::SetBounds(const gfx::Rect& bounds) {
gfx::Rect NativeWindowMac::GetBounds() { gfx::Rect NativeWindowMac::GetBounds() {
NSRect frame = [window_ frame]; NSRect frame = [window_ frame];
NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
NSScreen* screen = [NSScreen mainScreen];
gfx::Point pos(frame.origin.x, bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
NSHeight([screen frame]) - frame.origin.y - frame.size.height); return bounds;
gfx::Size size(frame.size.width, frame.size.height);
return gfx::Rect(pos, size);
} }
void NativeWindowMac::SetSize(const gfx::Size& size) { void NativeWindowMac::SetSize(const gfx::Size& size) {