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

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

Issue 7621061: Restoring a session should restore window minimization state (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing Mark's comments. 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_private.h" 5 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #import "base/memory/scoped_nsobject.h" 10 #import "base/memory/scoped_nsobject.h"
(...skipping 17 matching lines...) Expand all
28 #import "chrome/browser/ui/cocoa/tabs/side_tab_strip_controller.h" 28 #import "chrome/browser/ui/cocoa/tabs/side_tab_strip_controller.h"
29 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" 29 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
30 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" 30 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
31 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 31 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
32 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 32 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
33 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 33 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
34 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
35 #include "content/browser/renderer_host/render_widget_host_view.h" 35 #include "content/browser/renderer_host/render_widget_host_view.h"
36 #include "content/browser/tab_contents/tab_contents.h" 36 #include "content/browser/tab_contents/tab_contents.h"
37 #include "content/browser/tab_contents/tab_contents_view.h" 37 #include "content/browser/tab_contents/tab_contents_view.h"
38 #include "ui/base/ui_base_types.h"
38 39
39 // Forward-declare symbols that are part of the 10.6 SDK. 40 // Forward-declare symbols that are part of the 10.6 SDK.
40 #if !defined(MAC_OS_X_VERSION_10_6) || \ 41 #if !defined(MAC_OS_X_VERSION_10_6) || \
41 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 42 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
42 43
43 enum { 44 enum {
44 NSApplicationPresentationDefault = 0, 45 NSApplicationPresentationDefault = 0,
45 NSApplicationPresentationAutoHideDock = (1 << 0), 46 NSApplicationPresentationAutoHideDock = (1 << 0),
46 NSApplicationPresentationHideDock = (1 << 1), 47 NSApplicationPresentationHideDock = (1 << 1),
47 NSApplicationPresentationAutoHideMenuBar = (1 << 2), 48 NSApplicationPresentationAutoHideMenuBar = (1 << 2),
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 [button setBordered:NO]; 105 [button setBordered:NO];
105 [[button cell] setHighlightsBy:NSContentsCellMask]; 106 [[button cell] setHighlightsBy:NSContentsCellMask];
106 [[button cell] setShowsStateBy:NSContentsCellMask]; 107 [[button cell] setShowsStateBy:NSContentsCellMask];
107 [button setImage:[NSImage imageNamed:NSImageNameIChatTheaterTemplate]]; 108 [button setImage:[NSImage imageNamed:NSImageNameIChatTheaterTemplate]];
108 [button setTarget:self]; 109 [button setTarget:self];
109 [button setAction:@selector(togglePresentationModeForLionOrLater:)]; 110 [button setAction:@selector(togglePresentationModeForLionOrLater:)];
110 [[[[self window] contentView] superview] addSubview:button]; 111 [[[[self window] contentView] superview] addSubview:button];
111 } 112 }
112 113
113 - (void)saveWindowPositionIfNeeded { 114 - (void)saveWindowPositionIfNeeded {
114 if (browser_ != BrowserList::GetLastActive()) 115 if (!browser_->ShouldSaveWindowPlacement())
115 return; 116 return;
116 117
117 if (!browser_->profile()->GetPrefs() ||
118 !browser_->ShouldSaveWindowPlacement()) {
119 return;
120 }
121
122 [self saveWindowPositionToPrefs:browser_->profile()->GetPrefs()];
123 }
124
125 - (void)saveWindowPositionToPrefs:(PrefService*)prefs {
126 // If we're in fullscreen mode, save the position of the regular window 118 // If we're in fullscreen mode, save the position of the regular window
127 // instead. 119 // instead.
128 NSWindow* window = [self isFullscreen] ? savedRegularWindow_ : [self window]; 120 NSWindow* window = [self isFullscreen] ? savedRegularWindow_ : [self window];
129 121
130 // Window positions are stored relative to the origin of the primary monitor. 122 // Window positions are stored relative to the origin of the primary monitor.
131 NSRect monitorFrame = [[[NSScreen screens] objectAtIndex:0] frame]; 123 NSRect monitorFrame = [[[NSScreen screens] objectAtIndex:0] frame];
132 NSScreen* windowScreen = [window screen]; 124 NSScreen* windowScreen = [window screen];
133 125
134 // |windowScreen| can be nil (for example, if the monitor arrangement was 126 // |windowScreen| can be nil (for example, if the monitor arrangement was
135 // changed while in fullscreen mode). If we see a nil screen, return without 127 // changed while in fullscreen mode). If we see a nil screen, return without
136 // saving. 128 // saving.
137 // TODO(rohitrao): We should just not save anything for fullscreen windows. 129 // TODO(rohitrao): We should just not save anything for fullscreen windows.
138 // http://crbug.com/36479. 130 // http://crbug.com/36479.
139 if (!windowScreen) 131 if (!windowScreen)
140 return; 132 return;
141 133
142 // Start with the window's frame, which is in virtual coordinates. 134 // Start with the window's frame, which is in virtual coordinates.
143 // Do some y twiddling to flip the coordinate system. 135 // Do some y twiddling to flip the coordinate system.
144 gfx::Rect bounds(NSRectToCGRect([window frame])); 136 gfx::Rect bounds(NSRectToCGRect([window frame]));
145 bounds.set_y(monitorFrame.size.height - bounds.y() - bounds.height()); 137 bounds.set_y(monitorFrame.size.height - bounds.y() - bounds.height());
146 138
147 // We also need to save the current work area, in flipped coordinates. 139 // Browser::SaveWindowPlacement saves information for session restore.
140 ui::WindowShowState show_state = [window isMiniaturized] ?
141 ui::SHOW_STATE_MINIMIZED : ui::SHOW_STATE_NORMAL;
142 browser_->SaveWindowPlacement(bounds, show_state);
143
144 // Only save main window information to preferences.
145 PrefService* prefs = browser_->profile()->GetPrefs();
146 if (!prefs || browser_ != BrowserList::GetLastActive())
147 return;
148
149 // Save the current work area, in flipped coordinates.
148 gfx::Rect workArea(NSRectToCGRect([windowScreen visibleFrame])); 150 gfx::Rect workArea(NSRectToCGRect([windowScreen visibleFrame]));
149 workArea.set_y(monitorFrame.size.height - workArea.y() - workArea.height()); 151 workArea.set_y(monitorFrame.size.height - workArea.y() - workArea.height());
150 152
151 // Browser::SaveWindowPlacement is used for session restore.
152 if (browser_->ShouldSaveWindowPlacement())
153 browser_->SaveWindowPlacement(bounds, /*maximized=*/ false);
154
155 DictionaryPrefUpdate update(prefs, browser_->GetWindowPlacementKey().c_str()); 153 DictionaryPrefUpdate update(prefs, browser_->GetWindowPlacementKey().c_str());
156 DictionaryValue* windowPreferences = update.Get(); 154 DictionaryValue* windowPreferences = update.Get();
157 windowPreferences->SetInteger("left", bounds.x()); 155 windowPreferences->SetInteger("left", bounds.x());
158 windowPreferences->SetInteger("top", bounds.y()); 156 windowPreferences->SetInteger("top", bounds.y());
159 windowPreferences->SetInteger("right", bounds.right()); 157 windowPreferences->SetInteger("right", bounds.right());
160 windowPreferences->SetInteger("bottom", bounds.bottom()); 158 windowPreferences->SetInteger("bottom", bounds.bottom());
161 windowPreferences->SetBoolean("maximized", false); 159 windowPreferences->SetBoolean("maximized", false);
162 windowPreferences->SetBoolean("always_on_top", false); 160 windowPreferences->SetBoolean("always_on_top", false);
163 windowPreferences->SetInteger("work_area_left", workArea.x()); 161 windowPreferences->SetInteger("work_area_left", workArea.x());
164 windowPreferences->SetInteger("work_area_top", workArea.y()); 162 windowPreferences->SetInteger("work_area_top", workArea.y());
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 - (void)disableBarVisibilityUpdates { 871 - (void)disableBarVisibilityUpdates {
874 // Early escape if there's nothing to do. 872 // Early escape if there's nothing to do.
875 if (!barVisibilityUpdatesEnabled_) 873 if (!barVisibilityUpdatesEnabled_)
876 return; 874 return;
877 875
878 barVisibilityUpdatesEnabled_ = NO; 876 barVisibilityUpdatesEnabled_ = NO;
879 [presentationModeController_ cancelAnimationAndTimers]; 877 [presentationModeController_ cancelAnimationAndTimers];
880 } 878 }
881 879
882 @end // @implementation BrowserWindowController(Private) 880 @end // @implementation BrowserWindowController(Private)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698