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

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

Issue 6735032: Get rid of PrefService::GetMutableDictionary/GetMutableList (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another windows compile error Created 9 years, 8 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) 2010 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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "chrome/browser/ui/cocoa/window_size_autosaver.h" 7 #import "chrome/browser/ui/cocoa/window_size_autosaver.h"
8 8
9 #include "chrome/browser/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/prefs/scoped_user_pref_update.h"
10 11
11 // If the window width stored in the prefs is smaller than this, the size is 12 // If the window width stored in the prefs is smaller than this, the size is
12 // not restored but instead cleared from the profile -- to protect users from 13 // not restored but instead cleared from the profile -- to protect users from
13 // accidentally making their windows very small and then not finding them again. 14 // accidentally making their windows very small and then not finding them again.
14 const int kMinWindowWidth = 101; 15 const int kMinWindowWidth = 101;
15 16
16 // Minimum restored window height, see |kMinWindowWidth|. 17 // Minimum restored window height, see |kMinWindowWidth|.
17 const int kMinWindowHeight = 17; 18 const int kMinWindowHeight = 17;
18 19
19 @interface WindowSizeAutosaver (Private) 20 @interface WindowSizeAutosaver (Private)
(...skipping 25 matching lines...) Expand all
45 } 46 }
46 return self; 47 return self;
47 } 48 }
48 49
49 - (void)dealloc { 50 - (void)dealloc {
50 [[NSNotificationCenter defaultCenter] removeObserver:self]; 51 [[NSNotificationCenter defaultCenter] removeObserver:self];
51 [super dealloc]; 52 [super dealloc];
52 } 53 }
53 54
54 - (void)save:(NSNotification*)notification { 55 - (void)save:(NSNotification*)notification {
55 DictionaryValue* windowPrefs = prefService_->GetMutableDictionary(path_); 56 DictionaryPrefUpdate update(prefService_, path_);
57 DictionaryValue* windowPrefs = update.Get();
56 NSRect frame = [window_ frame]; 58 NSRect frame = [window_ frame];
57 if ([window_ styleMask] & NSResizableWindowMask) { 59 if ([window_ styleMask] & NSResizableWindowMask) {
58 // Save the origin of the window. 60 // Save the origin of the window.
59 windowPrefs->SetInteger("left", NSMinX(frame)); 61 windowPrefs->SetInteger("left", NSMinX(frame));
60 windowPrefs->SetInteger("right", NSMaxX(frame)); 62 windowPrefs->SetInteger("right", NSMaxX(frame));
61 // windows's and linux's profiles have top < bottom due to having their 63 // windows's and linux's profiles have top < bottom due to having their
62 // screen origin in the upper left, while cocoa's is in the lower left. To 64 // screen origin in the upper left, while cocoa's is in the lower left. To
63 // keep the top < bottom invariant, store top in bottom and vice versa. 65 // keep the top < bottom invariant, store top in bottom and vice versa.
64 windowPrefs->SetInteger("top", NSMinY(frame)); 66 windowPrefs->SetInteger("top", NSMinY(frame));
65 windowPrefs->SetInteger("bottom", NSMaxY(frame)); 67 windowPrefs->SetInteger("bottom", NSMaxY(frame));
66 } else { 68 } else {
67 // Save the origin of the window. 69 // Save the origin of the window.
68 windowPrefs->SetInteger("x", frame.origin.x); 70 windowPrefs->SetInteger("x", frame.origin.x);
69 windowPrefs->SetInteger("y", frame.origin.y); 71 windowPrefs->SetInteger("y", frame.origin.y);
70 } 72 }
71 } 73 }
72 74
73 - (void)restore { 75 - (void)restore {
74 // Get the positioning information. 76 // Get the positioning information.
75 DictionaryValue* windowPrefs = prefService_->GetMutableDictionary(path_); 77 const DictionaryValue* windowPrefs = prefService_->GetDictionary(path_);
76 if ([window_ styleMask] & NSResizableWindowMask) { 78 if ([window_ styleMask] & NSResizableWindowMask) {
77 int x1, x2, y1, y2; 79 int x1, x2, y1, y2;
78 if (!windowPrefs->GetInteger("left", &x1) || 80 if (!windowPrefs->GetInteger("left", &x1) ||
79 !windowPrefs->GetInteger("right", &x2) || 81 !windowPrefs->GetInteger("right", &x2) ||
80 !windowPrefs->GetInteger("top", &y1) || 82 !windowPrefs->GetInteger("top", &y1) ||
81 !windowPrefs->GetInteger("bottom", &y2)) { 83 !windowPrefs->GetInteger("bottom", &y2)) {
82 return; 84 return;
83 } 85 }
84 if (x2 - x1 < kMinWindowWidth || y2 - y1 < kMinWindowHeight) { 86 if (x2 - x1 < kMinWindowWidth || y2 - y1 < kMinWindowHeight) {
85 // Windows should never be very small. 87 // Windows should never be very small.
86 windowPrefs->Remove("left", NULL); 88 DictionaryPrefUpdate update(prefService_, path_);
87 windowPrefs->Remove("right", NULL); 89 DictionaryValue* mutableWindowPrefs = update.Get();
88 windowPrefs->Remove("top", NULL); 90 mutableWindowPrefs->Remove("left", NULL);
89 windowPrefs->Remove("bottom", NULL); 91 mutableWindowPrefs->Remove("right", NULL);
92 mutableWindowPrefs->Remove("top", NULL);
93 mutableWindowPrefs->Remove("bottom", NULL);
90 } else { 94 } else {
91 [window_ setFrame:NSMakeRect(x1, y1, x2 - x1, y2 - y1) display:YES]; 95 [window_ setFrame:NSMakeRect(x1, y1, x2 - x1, y2 - y1) display:YES];
92 96
93 // Make sure the window is on-screen. 97 // Make sure the window is on-screen.
94 [window_ cascadeTopLeftFromPoint:NSZeroPoint]; 98 [window_ cascadeTopLeftFromPoint:NSZeroPoint];
95 } 99 }
96 } else { 100 } else {
97 int x, y; 101 int x, y;
98 if (!windowPrefs->GetInteger("x", &x) || 102 if (!windowPrefs->GetInteger("x", &x) ||
99 !windowPrefs->GetInteger("y", &y)) 103 !windowPrefs->GetInteger("y", &y))
100 return; // Nothing stored. 104 return; // Nothing stored.
101 // Turn the origin (lower-left) into an upper-left window point. 105 // Turn the origin (lower-left) into an upper-left window point.
102 NSPoint upperLeft = NSMakePoint(x, y + NSHeight([window_ frame])); 106 NSPoint upperLeft = NSMakePoint(x, y + NSHeight([window_ frame]));
103 [window_ cascadeTopLeftFromPoint:upperLeft]; 107 [window_ cascadeTopLeftFromPoint:upperLeft];
104 } 108 }
105 } 109 }
106 110
107 @end 111 @end
108 112
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698