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

Side by Side Diff: chrome/browser/cocoa/page_info_window_controller.mm

Issue 207027: [Mac] Polish the search engine manager (Closed)
Patch Set: '' Created 11 years, 3 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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/cocoa/page_info_window_controller.h" 5 #import "chrome/browser/cocoa/page_info_window_controller.h"
6 6
7 #include "base/mac_util.h" 7 #include "base/mac_util.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #import "chrome/browser/cocoa/nswindow_local_state.h"
10 #include "chrome/browser/cocoa/page_info_window_mac.h" 11 #include "chrome/browser/cocoa/page_info_window_mac.h"
11 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
12 #include "chrome/common/pref_service.h" 13 #include "chrome/common/pref_service.h"
13 14
14 @interface PageInfoWindowController (Private) 15 @interface PageInfoWindowController (Private)
15 // Saves the window preference to the local state. 16 // Saves the window preference to the local state.
16 - (void)saveWindowPositionToLocalState; 17 - (void)saveWindowPositionToLocalState;
17 @end 18 @end
18 19
19 @implementation PageInfoWindowController 20 @implementation PageInfoWindowController
(...skipping 18 matching lines...) Expand all
38 [bundle pathForResource:@"pageinfo_bad" ofType:@"png"]]; 39 [bundle pathForResource:@"pageinfo_bad" ofType:@"png"]];
39 badImg_.reset(img); 40 badImg_.reset(img);
40 } 41 }
41 return self; 42 return self;
42 } 43 }
43 44
44 - (void)awakeFromNib { 45 - (void)awakeFromNib {
45 if (g_browser_process && g_browser_process->local_state()) { 46 if (g_browser_process && g_browser_process->local_state()) {
46 // Get the positioning information. 47 // Get the positioning information.
47 PrefService* prefs = g_browser_process->local_state(); 48 PrefService* prefs = g_browser_process->local_state();
48 DictionaryValue* windowPrefs = 49 [[self window] restoreWindowPositionFromPrefs:prefs
49 prefs->GetMutableDictionary(prefs::kPageInfoWindowPlacement); 50 withPath:prefs::kPageInfoWindowPlacement];
50 int x = 0, y = 0;
51 windowPrefs->GetInteger(L"x", &x);
52 windowPrefs->GetInteger(L"y", &y);
53 // Turn the origin (lower-left) into an upper-left window point.
54 NSPoint upperLeft = NSMakePoint(x, y + [[self window] frame].size.height);
55 NSPoint cascadePoint = [[self window] cascadeTopLeftFromPoint:upperLeft];
56 // Cascade again to get the offset when opening new windows.
57 [[self window] cascadeTopLeftFromPoint:cascadePoint];
58 [self saveWindowPositionToLocalState]; // Force a save of the pref.
59 } 51 }
60 52
61 // By default, assume we have no history information. 53 // By default, assume we have no history information.
62 [self setShowHistoryBox:NO]; 54 [self setShowHistoryBox:NO];
63 } 55 }
64 56
65 - (void)dealloc { 57 - (void)dealloc {
66 [identityImg_ release]; 58 [identityImg_ release];
67 [connectionImg_ release]; 59 [connectionImg_ release];
68 [historyImg_ release]; 60 [historyImg_ release];
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 101
110 // If the page info window gets closed, we have nothing left to manage and we 102 // If the page info window gets closed, we have nothing left to manage and we
111 // can clean ourselves up. 103 // can clean ourselves up.
112 - (void)windowWillClose:(NSNotification*)notif { 104 - (void)windowWillClose:(NSNotification*)notif {
113 [self autorelease]; 105 [self autorelease];
114 } 106 }
115 107
116 // The last page info window that was moved will determine the location of the 108 // The last page info window that was moved will determine the location of the
117 // next new one. 109 // next new one.
118 - (void)windowDidMove:(NSNotification*)notif { 110 - (void)windowDidMove:(NSNotification*)notif {
119 [self saveWindowPositionToLocalState]; 111 if (g_browser_process && g_browser_process->local_state())
120 } 112 [[self window] saveWindowPositionToPrefs:g_browser_process->local_state()
121 113 withPath:prefs::kPageInfoWindowPlacement];
122 // Saves the window preference to the local state.
123 - (void)saveWindowPositionToLocalState {
124 if (!g_browser_process || !g_browser_process->local_state())
125 return;
126 [self saveWindowPositionToPrefs:g_browser_process->local_state()];
127 }
128
129 // Saves the window's origin into the given PrefService. Caller is responsible
130 // for making sure |prefs| is not NULL.
131 - (void)saveWindowPositionToPrefs:(PrefService*)prefs {
132 // Save the origin of the window.
133 DictionaryValue* windowPrefs = prefs->GetMutableDictionary(
134 prefs::kPageInfoWindowPlacement);
135 NSRect frame = [[self window] frame];
136 windowPrefs->SetInteger(L"x", frame.origin.x);
137 windowPrefs->SetInteger(L"y", frame.origin.y);
138 } 114 }
139 115
140 @end 116 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698