Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm

Issue 1380083005: Mac: Use [NSArray firstObject] for [NSScreen screens] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h" 5 #include "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
9 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
10 #include "base/mac/sdk_forward_declarations.h" 10 #include "base/mac/sdk_forward_declarations.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 - (BOOL)_isTitleHidden; 50 - (BOOL)_isTitleHidden;
51 @end 51 @end
52 52
53 namespace { 53 namespace {
54 54
55 const int kActivateThrottlePeriodSeconds = 2; 55 const int kActivateThrottlePeriodSeconds = 2;
56 56
57 NSRect GfxToCocoaBounds(gfx::Rect bounds) { 57 NSRect GfxToCocoaBounds(gfx::Rect bounds) {
58 typedef AppWindow::BoundsSpecification BoundsSpecification; 58 typedef AppWindow::BoundsSpecification BoundsSpecification;
59 59
60 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; 60 NSRect main_screen_rect = [[[NSScreen screens] firstObject] frame];
61 61
62 // If coordinates are unspecified, center window on primary screen. 62 // If coordinates are unspecified, center window on primary screen.
63 if (bounds.x() == BoundsSpecification::kUnspecifiedPosition) 63 if (bounds.x() == BoundsSpecification::kUnspecifiedPosition)
64 bounds.set_x(floor((NSWidth(main_screen_rect) - bounds.width()) / 2)); 64 bounds.set_x(floor((NSWidth(main_screen_rect) - bounds.width()) / 2));
65 if (bounds.y() == BoundsSpecification::kUnspecifiedPosition) 65 if (bounds.y() == BoundsSpecification::kUnspecifiedPosition)
66 bounds.set_y(floor((NSHeight(main_screen_rect) - bounds.height()) / 2)); 66 bounds.set_y(floor((NSHeight(main_screen_rect) - bounds.height()) / 2));
67 67
68 // Convert to Mac coordinates. 68 // Convert to Mac coordinates.
69 NSRect cocoa_bounds = NSRectFromCGRect(bounds.ToCGRect()); 69 NSRect cocoa_bounds = NSRectFromCGRect(bounds.ToCGRect());
70 cocoa_bounds.origin.y = NSHeight(main_screen_rect) - NSMaxY(cocoa_bounds); 70 cocoa_bounds.origin.y = NSHeight(main_screen_rect) - NSMaxY(cocoa_bounds);
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 bool NativeAppWindowCocoa::IsFullscreenOrPending() const { 445 bool NativeAppWindowCocoa::IsFullscreenOrPending() const {
446 return is_fullscreen_; 446 return is_fullscreen_;
447 } 447 }
448 448
449 gfx::NativeWindow NativeAppWindowCocoa::GetNativeWindow() const { 449 gfx::NativeWindow NativeAppWindowCocoa::GetNativeWindow() const {
450 return window(); 450 return window();
451 } 451 }
452 452
453 gfx::Rect NativeAppWindowCocoa::GetRestoredBounds() const { 453 gfx::Rect NativeAppWindowCocoa::GetRestoredBounds() const {
454 // Flip coordinates based on the primary screen. 454 // Flip coordinates based on the primary screen.
455 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; 455 NSScreen* screen = [[NSScreen screens] firstObject];
456 NSRect frame = restored_bounds_; 456 NSRect frame = restored_bounds_;
457 gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame)); 457 gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
458 bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame)); 458 bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
459 return bounds; 459 return bounds;
460 } 460 }
461 461
462 ui::WindowShowState NativeAppWindowCocoa::GetRestoredState() const { 462 ui::WindowShowState NativeAppWindowCocoa::GetRestoredState() const {
463 if (IsMaximized()) 463 if (IsMaximized())
464 return ui::SHOW_STATE_MAXIMIZED; 464 return ui::SHOW_STATE_MAXIMIZED;
465 if (IsFullscreen()) 465 if (IsFullscreen())
466 return ui::SHOW_STATE_FULLSCREEN; 466 return ui::SHOW_STATE_FULLSCREEN;
467 return ui::SHOW_STATE_NORMAL; 467 return ui::SHOW_STATE_NORMAL;
468 } 468 }
469 469
470 gfx::Rect NativeAppWindowCocoa::GetBounds() const { 470 gfx::Rect NativeAppWindowCocoa::GetBounds() const {
471 // Flip coordinates based on the primary screen. 471 // Flip coordinates based on the primary screen.
472 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; 472 NSScreen* screen = [[NSScreen screens] firstObject];
473 NSRect frame = [window() frame]; 473 NSRect frame = [window() frame];
474 gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame)); 474 gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
475 bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame)); 475 bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
476 return bounds; 476 return bounds;
477 } 477 }
478 478
479 void NativeAppWindowCocoa::Show() { 479 void NativeAppWindowCocoa::Show() {
480 if (is_hidden_with_app_) { 480 if (is_hidden_with_app_) {
481 apps::ExtensionAppShimHandler::UnhideWithoutActivationForWindow( 481 apps::ExtensionAppShimHandler::UnhideWithoutActivationForWindow(
482 app_window_); 482 app_window_);
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 SkColor NativeAppWindowCocoa::InactiveFrameColor() const { 680 SkColor NativeAppWindowCocoa::InactiveFrameColor() const {
681 return inactive_frame_color_; 681 return inactive_frame_color_;
682 } 682 }
683 683
684 gfx::Insets NativeAppWindowCocoa::GetFrameInsets() const { 684 gfx::Insets NativeAppWindowCocoa::GetFrameInsets() const {
685 if (!has_frame_) 685 if (!has_frame_)
686 return gfx::Insets(); 686 return gfx::Insets();
687 687
688 // Flip the coordinates based on the main screen. 688 // Flip the coordinates based on the main screen.
689 NSInteger screen_height = 689 NSInteger screen_height =
690 NSHeight([[[NSScreen screens] objectAtIndex:0] frame]); 690 NSHeight([[[NSScreen screens] firstObject] frame]);
691 691
692 NSRect frame_nsrect = [window() frame]; 692 NSRect frame_nsrect = [window() frame];
693 gfx::Rect frame_rect(NSRectToCGRect(frame_nsrect)); 693 gfx::Rect frame_rect(NSRectToCGRect(frame_nsrect));
694 frame_rect.set_y(screen_height - NSMaxY(frame_nsrect)); 694 frame_rect.set_y(screen_height - NSMaxY(frame_nsrect));
695 695
696 NSRect content_nsrect = [window() contentRectForFrameRect:frame_nsrect]; 696 NSRect content_nsrect = [window() contentRectForFrameRect:frame_nsrect];
697 gfx::Rect content_rect(NSRectToCGRect(content_nsrect)); 697 gfx::Rect content_rect(NSRectToCGRect(content_nsrect));
698 content_rect.set_y(screen_height - NSMaxY(content_nsrect)); 698 content_rect.set_y(screen_height - NSMaxY(content_nsrect));
699 699
700 return frame_rect.InsetsFrom(content_rect); 700 return frame_rect.InsetsFrom(content_rect);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 } 882 }
883 883
884 void NativeAppWindowCocoa::UpdateRestoredBounds() { 884 void NativeAppWindowCocoa::UpdateRestoredBounds() {
885 if (IsRestored(*this)) 885 if (IsRestored(*this))
886 restored_bounds_ = [window() frame]; 886 restored_bounds_ = [window() frame];
887 } 887 }
888 888
889 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { 889 void NativeAppWindowCocoa::HideWithoutMarkingHidden() {
890 [window() orderOut:window_controller_]; 890 [window() orderOut:window_controller_];
891 } 891 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/app_list_service_mac.mm ('k') | chrome/browser/ui/cocoa/autofill/autofill_popup_base_view_cocoa.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698