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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_controller.mm

Issue 7621061: Restoring a session should restore window minimization state (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Windows compile. Created 9 years, 4 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
6 6
7 #include <Carbon/Carbon.h> 7 #include <Carbon/Carbon.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 #include <numeric> 10 #include <numeric>
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 @interface NSWindow (NSPrivateApis) 149 @interface NSWindow (NSPrivateApis)
150 // Note: These functions are private, use -[NSObject respondsToSelector:] 150 // Note: These functions are private, use -[NSObject respondsToSelector:]
151 // before calling them. 151 // before calling them.
152 152
153 - (void)setBottomCornerRounded:(BOOL)rounded; 153 - (void)setBottomCornerRounded:(BOOL)rounded;
154 154
155 - (NSRect)_growBoxRect; 155 - (NSRect)_growBoxRect;
156 156
157 @end 157 @end
158 158
159 // Provide the forward-declarations of new 10.7 SDK symbols so they can be 159 // Forward-declare symbols that are part of the 10.6 SDK.
160 // called when building with the 10.5 SDK. 160 #if !defined(MAC_OS_X_VERSION_10_6) || \
161 #if !defined(MAC_OS_X_VERSION_10_7) || \ 161 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
162 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
163 162
164 enum { 163 enum {
165 NSWindowAnimationBehaviorDefault = 0, 164 NSTouchPhaseBegan = 1U << 0,
166 NSWindowAnimationBehaviorNone = 2, 165 NSTouchPhaseMoved = 1U << 1,
167 NSWindowAnimationBehaviorDocumentWindow = 3, 166 NSTouchPhaseStationary = 1U << 2,
168 NSWindowAnimationBehaviorUtilityWindow = 4, 167 NSTouchPhaseEnded = 1U << 3,
169 NSWindowAnimationBehaviorAlertPanel = 5 168 NSTouchPhaseCancelled = 1U << 4,
169 NSTouchPhaseTouching = NSTouchPhaseBegan | NSTouchPhaseMoved |
170 NSTouchPhaseStationary,
171 NSTouchPhaseAny = NSUIntegerMax
170 }; 172 };
171 typedef NSInteger NSWindowAnimationBehavior; 173 typedef NSUInteger NSTouchPhase;
172 174
173 enum { 175 @interface NSEvent (SnowLeopardDeclarations)
174 NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7, 176 - (NSSet*)touchesMatchingPhase:(NSTouchPhase)phase inView:(NSView*)view;
175 NSWindowCollectionBehaviorFullScreenAuxiliary = 1 << 8
176 };
177
178 enum {
179 NSFullScreenWindowMask = 1 << 14
180 };
181
182 @interface NSWindow (LionSDKDeclarations)
183 - (void)setRestorable:(BOOL)flag;
184 - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior;
185 @end 177 @end
186 178
187 #endif // MAC_OS_X_VERSION_10_7 179 @interface NSTouch : NSObject
180 - (NSPoint)normalizedPosition;
181 - (id<NSObject, NSCopying>)identity;
182 @end
183
184 #endif // MAC_OS_X_VERSION_10_6
188 185
189 @implementation BrowserWindowController 186 @implementation BrowserWindowController
190 187
191 + (BrowserWindowController*)browserWindowControllerForWindow:(NSWindow*)window { 188 + (BrowserWindowController*)browserWindowControllerForWindow:(NSWindow*)window {
192 while (window) { 189 while (window) {
193 id controller = [window windowController]; 190 id controller = [window windowController];
194 if ([controller isKindOfClass:[BrowserWindowController class]]) 191 if ([controller isKindOfClass:[BrowserWindowController class]])
195 return (BrowserWindowController*)controller; 192 return (BrowserWindowController*)controller;
196 window = [window parentWindow]; 193 window = [window parentWindow];
197 } 194 }
(...skipping 18 matching lines...) Expand all
216 // can override it in a unit test. 213 // can override it in a unit test.
217 NSString* nibpath = [base::mac::MainAppBundle() 214 NSString* nibpath = [base::mac::MainAppBundle()
218 pathForResource:@"BrowserWindow" 215 pathForResource:@"BrowserWindow"
219 ofType:@"nib"]; 216 ofType:@"nib"];
220 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { 217 if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
221 DCHECK(browser); 218 DCHECK(browser);
222 initializing_ = YES; 219 initializing_ = YES;
223 browser_.reset(browser); 220 browser_.reset(browser);
224 ownsBrowser_ = ownIt; 221 ownsBrowser_ = ownIt;
225 NSWindow* window = [self window]; 222 NSWindow* window = [self window];
226 windowShim_.reset(new BrowserWindowCocoa(browser, self, window)); 223 windowShim_.reset(new BrowserWindowCocoa(browser, self));
227 224
228 // Create the bar visibility lock set; 10 is arbitrary, but should hopefully 225 // Create the bar visibility lock set; 10 is arbitrary, but should hopefully
229 // be big enough to hold all locks that'll ever be needed. 226 // be big enough to hold all locks that'll ever be needed.
230 barVisibilityLocks_.reset([[NSMutableSet setWithCapacity:10] retain]); 227 barVisibilityLocks_.reset([[NSMutableSet setWithCapacity:10] retain]);
231 228
232 // Sets the window to not have rounded corners, which prevents 229 // Sets the window to not have rounded corners, which prevents
233 // the resize control from being inset slightly and looking ugly. 230 // the resize control from being inset slightly and looking ugly.
234 if ([window respondsToSelector:@selector(setBottomCornerRounded:)]) 231 if ([window respondsToSelector:@selector(setBottomCornerRounded:)])
235 [window setBottomCornerRounded:NO]; 232 [window setBottomCornerRounded:NO];
236 233
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 // We need to deactivate the controls (in the "WebView"). To do this, get the 604 // We need to deactivate the controls (in the "WebView"). To do this, get the
608 // selected TabContents's RenderWidgetHostView and tell it to deactivate. 605 // selected TabContents's RenderWidgetHostView and tell it to deactivate.
609 if (TabContents* contents = browser_->GetSelectedTabContents()) { 606 if (TabContents* contents = browser_->GetSelectedTabContents()) {
610 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView()) 607 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView())
611 rwhv->SetActive(false); 608 rwhv->SetActive(false);
612 } 609 }
613 } 610 }
614 611
615 // Called when we have been minimized. 612 // Called when we have been minimized.
616 - (void)windowDidMiniaturize:(NSNotification *)notification { 613 - (void)windowDidMiniaturize:(NSNotification *)notification {
614 [self saveWindowPositionIfNeeded];
615
617 // Let the selected RenderWidgetHostView know, so that it can tell plugins. 616 // Let the selected RenderWidgetHostView know, so that it can tell plugins.
618 if (TabContents* contents = browser_->GetSelectedTabContents()) { 617 if (TabContents* contents = browser_->GetSelectedTabContents()) {
619 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView()) 618 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView())
620 rwhv->SetWindowVisibility(false); 619 rwhv->SetWindowVisibility(false);
621 } 620 }
622 } 621 }
623 622
624 // Called when we have been unminimized. 623 // Called when we have been unminimized.
625 - (void)windowDidDeminiaturize:(NSNotification *)notification { 624 - (void)windowDidDeminiaturize:(NSNotification *)notification {
626 // Let the selected RenderWidgetHostView know, so that it can tell plugins. 625 // Let the selected RenderWidgetHostView know, so that it can tell plugins.
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 1755
1757 if (command && browser_->command_updater()->IsCommandEnabled(command)) { 1756 if (command && browser_->command_updater()->IsCommandEnabled(command)) {
1758 currentZoomStepDelta_ += (command == IDC_ZOOM_PLUS) ? 1 : -1; 1757 currentZoomStepDelta_ += (command == IDC_ZOOM_PLUS) ? 1 : -1;
1759 browser_->ExecuteCommandWithDisposition(command, 1758 browser_->ExecuteCommandWithDisposition(command,
1760 event_utils::WindowOpenDispositionFromNSEvent(event)); 1759 event_utils::WindowOpenDispositionFromNSEvent(event));
1761 } 1760 }
1762 } 1761 }
1763 1762
1764 // Delegate method called when window is resized. 1763 // Delegate method called when window is resized.
1765 - (void)windowDidResize:(NSNotification*)notification { 1764 - (void)windowDidResize:(NSNotification*)notification {
1765 [self saveWindowPositionIfNeeded];
1766
1766 // Resize (and possibly move) the status bubble. Note that we may get called 1767 // Resize (and possibly move) the status bubble. Note that we may get called
1767 // when the status bubble does not exist. 1768 // when the status bubble does not exist.
1768 if (statusBubble_) { 1769 if (statusBubble_) {
1769 statusBubble_->UpdateSizeAndPosition(); 1770 statusBubble_->UpdateSizeAndPosition();
1770 } 1771 }
1771 1772
1772 // Let the selected RenderWidgetHostView know, so that it can tell plugins. 1773 // Let the selected RenderWidgetHostView know, so that it can tell plugins.
1773 if (TabContents* contents = browser_->GetSelectedTabContents()) { 1774 if (TabContents* contents = browser_->GetSelectedTabContents()) {
1774 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView()) 1775 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView())
1775 rwhv->WindowFrameChanged(); 1776 rwhv->WindowFrameChanged();
(...skipping 20 matching lines...) Expand all
1796 google_util::AppendGoogleLocaleParam(GURL(chrome::kCrashReasonURL)); 1797 google_util::AppendGoogleLocaleParam(GURL(chrome::kCrashReasonURL));
1797 tab_contents->OpenURL(helpUrl, GURL(), CURRENT_TAB, PageTransition::LINK); 1798 tab_contents->OpenURL(helpUrl, GURL(), CURRENT_TAB, PageTransition::LINK);
1798 } 1799 }
1799 } 1800 }
1800 } 1801 }
1801 1802
1802 // Delegate method called when window did move. (See below for why we don't use 1803 // Delegate method called when window did move. (See below for why we don't use
1803 // |-windowWillMove:|, which is called less frequently than |-windowDidMove| 1804 // |-windowWillMove:|, which is called less frequently than |-windowDidMove|
1804 // instead.) 1805 // instead.)
1805 - (void)windowDidMove:(NSNotification*)notification { 1806 - (void)windowDidMove:(NSNotification*)notification {
1807 [self saveWindowPositionIfNeeded];
1808
1806 NSWindow* window = [self window]; 1809 NSWindow* window = [self window];
1807 NSRect windowFrame = [window frame]; 1810 NSRect windowFrame = [window frame];
1808 NSRect workarea = [[window screen] visibleFrame]; 1811 NSRect workarea = [[window screen] visibleFrame];
1809 1812
1810 // We reset the window growth state whenever the window is moved out of the 1813 // We reset the window growth state whenever the window is moved out of the
1811 // work area or away (up or down) from the bottom or top of the work area. 1814 // work area or away (up or down) from the bottom or top of the work area.
1812 // Unfortunately, Cocoa sends |-windowWillMove:| too frequently (including 1815 // Unfortunately, Cocoa sends |-windowWillMove:| too frequently (including
1813 // when clicking on the title bar to activate), and of course 1816 // when clicking on the title bar to activate), and of course
1814 // |-windowWillMove| is called too early for us to apply our heuristic. (The 1817 // |-windowWillMove| is called too early for us to apply our heuristic. (The
1815 // heuristic we use for detecting window movement is that if |windowTopGrowth_ 1818 // heuristic we use for detecting window movement is that if |windowTopGrowth_
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
2180 2183
2181 - (BOOL)supportsBookmarkBar { 2184 - (BOOL)supportsBookmarkBar {
2182 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; 2185 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR];
2183 } 2186 }
2184 2187
2185 - (BOOL)isTabbedWindow { 2188 - (BOOL)isTabbedWindow {
2186 return browser_->is_type_tabbed(); 2189 return browser_->is_type_tabbed();
2187 } 2190 }
2188 2191
2189 @end // @implementation BrowserWindowController(WindowType) 2192 @end // @implementation BrowserWindowController(WindowType)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698