OLD | NEW |
---|---|
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 "apps/app_shim/extension_app_shim_handler_mac.h" | 7 #include "apps/app_shim/extension_app_shim_handler_mac.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 | 49 |
50 // Replicate specific 10.7 SDK declarations for building with prior SDKs. | 50 // Replicate specific 10.7 SDK declarations for building with prior SDKs. |
51 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 51 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
52 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 52 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
53 | 53 |
54 @interface NSWindow (LionSDKDeclarations) | 54 @interface NSWindow (LionSDKDeclarations) |
55 - (void)toggleFullScreen:(id)sender; | 55 - (void)toggleFullScreen:(id)sender; |
56 @end | 56 @end |
57 | 57 |
58 enum { | 58 enum { |
59 NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7 | 59 NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7, |
60 NSFullScreenWindowMask = 1 << 14 | |
60 }; | 61 }; |
61 | 62 |
62 #endif // MAC_OS_X_VERSION_10_7 | 63 #endif // MAC_OS_X_VERSION_10_7 |
63 | 64 |
64 @implementation NativeAppWindowController | 65 @implementation NativeAppWindowController |
65 | 66 |
66 @synthesize appWindow = appWindow_; | 67 @synthesize appWindow = appWindow_; |
67 | 68 |
68 - (void)windowWillClose:(NSNotification*)notification { | 69 - (void)windowWillClose:(NSNotification*)notification { |
69 if (appWindow_) | 70 if (appWindow_) |
70 appWindow_->WindowWillClose(); | 71 appWindow_->WindowWillClose(); |
71 } | 72 } |
72 | 73 |
73 - (void)windowDidBecomeKey:(NSNotification*)notification { | 74 - (void)windowDidBecomeKey:(NSNotification*)notification { |
74 if (appWindow_) | 75 if (appWindow_) |
75 appWindow_->WindowDidBecomeKey(); | 76 appWindow_->WindowDidBecomeKey(); |
76 } | 77 } |
77 | 78 |
78 - (void)windowDidResignKey:(NSNotification*)notification { | 79 - (void)windowDidResignKey:(NSNotification*)notification { |
79 if (appWindow_) | 80 if (appWindow_) |
80 appWindow_->WindowDidResignKey(); | 81 appWindow_->WindowDidResignKey(); |
81 } | 82 } |
82 | 83 |
83 - (void)windowDidResize:(NSNotification*)notification { | 84 - (void)windowDidResize:(NSNotification*)notification { |
84 if (appWindow_) | 85 if (appWindow_) |
85 appWindow_->WindowDidResize(); | 86 appWindow_->WindowDidResize(); |
86 } | 87 } |
87 | 88 |
89 - (void)windowDidEndLiveResize:(NSNotification*)notification { | |
90 if (appWindow_) | |
91 appWindow_->WindowDidFinishResize(); | |
92 } | |
93 | |
94 - (void)windowDidEnterFullScreen:(NSNotification*)notification { | |
95 if (appWindow_) | |
96 appWindow_->WindowDidFinishResize(); | |
97 } | |
98 | |
99 - (void)windowDidExitFullScreen:(NSNotification*)notification { | |
100 if (appWindow_) | |
101 appWindow_->WindowDidFinishResize(); | |
102 } | |
103 | |
88 - (void)windowDidMove:(NSNotification*)notification { | 104 - (void)windowDidMove:(NSNotification*)notification { |
89 if (appWindow_) | 105 if (appWindow_) |
90 appWindow_->WindowDidMove(); | 106 appWindow_->WindowDidMove(); |
91 } | 107 } |
92 | 108 |
93 - (void)windowDidMiniaturize:(NSNotification*)notification { | 109 - (void)windowDidMiniaturize:(NSNotification*)notification { |
94 if (appWindow_) | 110 if (appWindow_) |
95 appWindow_->WindowDidMiniaturize(); | 111 appWindow_->WindowDidMiniaturize(); |
96 } | 112 } |
97 | 113 |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 checked_bounds.set_height(max_size.height); | 575 checked_bounds.set_height(max_size.height); |
560 | 576 |
561 NSRect cocoa_bounds = NSMakeRect(checked_bounds.x(), 0, | 577 NSRect cocoa_bounds = NSMakeRect(checked_bounds.x(), 0, |
562 checked_bounds.width(), | 578 checked_bounds.width(), |
563 checked_bounds.height()); | 579 checked_bounds.height()); |
564 // Flip coordinates based on the primary screen. | 580 // Flip coordinates based on the primary screen. |
565 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 581 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
566 cocoa_bounds.origin.y = NSHeight([screen frame]) - checked_bounds.bottom(); | 582 cocoa_bounds.origin.y = NSHeight([screen frame]) - checked_bounds.bottom(); |
567 | 583 |
568 [window() setFrame:cocoa_bounds display:YES]; | 584 [window() setFrame:cocoa_bounds display:YES]; |
585 WindowDidFinishResize(); | |
scheib
2013/09/30 14:11:01
Place explanation summary from patch discussion in
jackhou1
2013/10/01 02:41:15
Done.
| |
569 } | 586 } |
570 | 587 |
571 void NativeAppWindowCocoa::UpdateWindowIcon() { | 588 void NativeAppWindowCocoa::UpdateWindowIcon() { |
572 // TODO(junmin): implement. | 589 // TODO(junmin): implement. |
573 } | 590 } |
574 | 591 |
575 void NativeAppWindowCocoa::UpdateWindowTitle() { | 592 void NativeAppWindowCocoa::UpdateWindowTitle() { |
576 string16 title = shell_window_->GetTitle(); | 593 string16 title = shell_window_->GetTitle(); |
577 [window() setTitle:base::SysUTF16ToNSString(title)]; | 594 [window() setTitle:base::SysUTF16ToNSString(title)]; |
578 } | 595 } |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
832 // lose key window status. | 849 // lose key window status. |
833 if ([NSApp isActive] && ([NSApp keyWindow] == window())) | 850 if ([NSApp isActive] && ([NSApp keyWindow] == window())) |
834 return; | 851 return; |
835 | 852 |
836 content::RenderWidgetHostView* rwhv = | 853 content::RenderWidgetHostView* rwhv = |
837 web_contents()->GetRenderWidgetHostView(); | 854 web_contents()->GetRenderWidgetHostView(); |
838 if (rwhv) | 855 if (rwhv) |
839 rwhv->SetActive(false); | 856 rwhv->SetActive(false); |
840 } | 857 } |
841 | 858 |
842 void NativeAppWindowCocoa::WindowDidResize() { | 859 void NativeAppWindowCocoa::WindowDidFinishResize() { |
843 // Update |is_maximized_| if needed: | 860 // Update |is_maximized_| if needed: |
844 // - Exit maximized state if resized. | 861 // - Exit maximized state if resized. |
845 // - Consider us maximized if resize places us back to maximized location. | 862 // - Consider us maximized if resize places us back to maximized location. |
846 // This happens when returning from fullscreen. | 863 // This happens when returning from fullscreen. |
847 NSRect frame = [window() frame]; | 864 NSRect frame = [window() frame]; |
848 NSRect screen = [[window() screen] visibleFrame]; | 865 NSRect screen = [[window() screen] visibleFrame]; |
849 if (!NSEqualSizes(frame.size, screen.size)) | 866 if (!NSEqualSizes(frame.size, screen.size)) |
850 is_maximized_ = false; | 867 is_maximized_ = false; |
851 else if (NSEqualPoints(frame.origin, screen.origin)) | 868 else if (NSEqualPoints(frame.origin, screen.origin)) |
852 is_maximized_ = true; | 869 is_maximized_ = true; |
853 | 870 |
871 // Update |is_fullscreen_| if needed. | |
872 is_fullscreen_ = ([window() styleMask] & NSFullScreenWindowMask) != 0; | |
873 | |
854 UpdateRestoredBounds(); | 874 UpdateRestoredBounds(); |
875 } | |
876 | |
877 void NativeAppWindowCocoa::WindowDidResize() { | |
855 shell_window_->OnNativeWindowChanged(); | 878 shell_window_->OnNativeWindowChanged(); |
856 } | 879 } |
857 | 880 |
858 void NativeAppWindowCocoa::WindowDidMove() { | 881 void NativeAppWindowCocoa::WindowDidMove() { |
859 UpdateRestoredBounds(); | 882 UpdateRestoredBounds(); |
860 shell_window_->OnNativeWindowChanged(); | 883 shell_window_->OnNativeWindowChanged(); |
861 } | 884 } |
862 | 885 |
863 void NativeAppWindowCocoa::WindowDidMiniaturize() { | 886 void NativeAppWindowCocoa::WindowDidMiniaturize() { |
864 shell_window_->OnNativeWindowChanged(); | 887 shell_window_->OnNativeWindowChanged(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
928 ShellNSWindow* NativeAppWindowCocoa::window() const { | 951 ShellNSWindow* NativeAppWindowCocoa::window() const { |
929 NSWindow* window = [window_controller_ window]; | 952 NSWindow* window = [window_controller_ window]; |
930 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); | 953 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); |
931 return static_cast<ShellNSWindow*>(window); | 954 return static_cast<ShellNSWindow*>(window); |
932 } | 955 } |
933 | 956 |
934 void NativeAppWindowCocoa::UpdateRestoredBounds() { | 957 void NativeAppWindowCocoa::UpdateRestoredBounds() { |
935 if (IsRestored(*this)) | 958 if (IsRestored(*this)) |
936 restored_bounds_ = [window() frame]; | 959 restored_bounds_ = [window() frame]; |
937 } | 960 } |
OLD | NEW |