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

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

Issue 23494065: Fix restoring a window after maximizing it. (Mac) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comment Created 7 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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
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 // setFrame: without animate: does not trigger a windowDidEndLiveResize: so
586 // call it here.
587 WindowDidFinishResize();
569 } 588 }
570 589
571 void NativeAppWindowCocoa::UpdateWindowIcon() { 590 void NativeAppWindowCocoa::UpdateWindowIcon() {
572 // TODO(junmin): implement. 591 // TODO(junmin): implement.
573 } 592 }
574 593
575 void NativeAppWindowCocoa::UpdateWindowTitle() { 594 void NativeAppWindowCocoa::UpdateWindowTitle() {
576 string16 title = shell_window_->GetTitle(); 595 string16 title = shell_window_->GetTitle();
577 [window() setTitle:base::SysUTF16ToNSString(title)]; 596 [window() setTitle:base::SysUTF16ToNSString(title)];
578 } 597 }
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 // lose key window status. 851 // lose key window status.
833 if ([NSApp isActive] && ([NSApp keyWindow] == window())) 852 if ([NSApp isActive] && ([NSApp keyWindow] == window()))
834 return; 853 return;
835 854
836 content::RenderWidgetHostView* rwhv = 855 content::RenderWidgetHostView* rwhv =
837 web_contents()->GetRenderWidgetHostView(); 856 web_contents()->GetRenderWidgetHostView();
838 if (rwhv) 857 if (rwhv)
839 rwhv->SetActive(false); 858 rwhv->SetActive(false);
840 } 859 }
841 860
842 void NativeAppWindowCocoa::WindowDidResize() { 861 void NativeAppWindowCocoa::WindowDidFinishResize() {
843 // Update |is_maximized_| if needed: 862 // Update |is_maximized_| if needed:
844 // - Exit maximized state if resized. 863 // - Exit maximized state if resized.
845 // - Consider us maximized if resize places us back to maximized location. 864 // - Consider us maximized if resize places us back to maximized location.
846 // This happens when returning from fullscreen. 865 // This happens when returning from fullscreen.
847 NSRect frame = [window() frame]; 866 NSRect frame = [window() frame];
848 NSRect screen = [[window() screen] visibleFrame]; 867 NSRect screen = [[window() screen] visibleFrame];
849 if (!NSEqualSizes(frame.size, screen.size)) 868 if (!NSEqualSizes(frame.size, screen.size))
850 is_maximized_ = false; 869 is_maximized_ = false;
851 else if (NSEqualPoints(frame.origin, screen.origin)) 870 else if (NSEqualPoints(frame.origin, screen.origin))
852 is_maximized_ = true; 871 is_maximized_ = true;
853 872
873 // Update |is_fullscreen_| if needed.
874 is_fullscreen_ = ([window() styleMask] & NSFullScreenWindowMask) != 0;
875
854 UpdateRestoredBounds(); 876 UpdateRestoredBounds();
877 }
878
879 void NativeAppWindowCocoa::WindowDidResize() {
855 shell_window_->OnNativeWindowChanged(); 880 shell_window_->OnNativeWindowChanged();
856 } 881 }
857 882
858 void NativeAppWindowCocoa::WindowDidMove() { 883 void NativeAppWindowCocoa::WindowDidMove() {
859 UpdateRestoredBounds(); 884 UpdateRestoredBounds();
860 shell_window_->OnNativeWindowChanged(); 885 shell_window_->OnNativeWindowChanged();
861 } 886 }
862 887
863 void NativeAppWindowCocoa::WindowDidMiniaturize() { 888 void NativeAppWindowCocoa::WindowDidMiniaturize() {
864 shell_window_->OnNativeWindowChanged(); 889 shell_window_->OnNativeWindowChanged();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 ShellNSWindow* NativeAppWindowCocoa::window() const { 953 ShellNSWindow* NativeAppWindowCocoa::window() const {
929 NSWindow* window = [window_controller_ window]; 954 NSWindow* window = [window_controller_ window];
930 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); 955 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]);
931 return static_cast<ShellNSWindow*>(window); 956 return static_cast<ShellNSWindow*>(window);
932 } 957 }
933 958
934 void NativeAppWindowCocoa::UpdateRestoredBounds() { 959 void NativeAppWindowCocoa::UpdateRestoredBounds() {
935 if (IsRestored(*this)) 960 if (IsRestored(*this))
936 restored_bounds_ = [window() frame]; 961 restored_bounds_ = [window() frame];
937 } 962 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698