OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/window_sizer.h" | 5 #include "chrome/browser/ui/window_sizer.h" |
6 | 6 |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/browser/profiles/profile_manager.h" |
9 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_list.h" | 11 #include "chrome/browser/ui/browser_list.h" |
11 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
13 | 14 |
14 /////////////////////////////////////////////////////////////////////////////// | 15 /////////////////////////////////////////////////////////////////////////////// |
15 // An implementation of WindowSizer::StateProvider that gets the last active | 16 // An implementation of WindowSizer::StateProvider that gets the last active |
16 // and persistent state from the browser window and the user's profile. | 17 // and persistent state from the browser window and the user's profile. |
17 class DefaultStateProvider : public WindowSizer::StateProvider { | 18 class DefaultStateProvider : public WindowSizer::StateProvider { |
18 public: | 19 public: |
19 explicit DefaultStateProvider(const std::string& app_name, Browser* browser) | 20 explicit DefaultStateProvider(const std::string& app_name, Browser* browser) |
20 : app_name_(app_name), | 21 : app_name_(app_name), |
21 browser_(browser) { | 22 browser_(browser) { |
22 } | 23 } |
23 | 24 |
24 // Overridden from WindowSizer::StateProvider: | 25 // Overridden from WindowSizer::StateProvider: |
25 virtual bool GetPersistentState(gfx::Rect* bounds, | 26 virtual bool GetPersistentState(gfx::Rect* bounds, |
26 bool* maximized, | 27 bool* maximized, |
27 gfx::Rect* work_area) const { | 28 gfx::Rect* work_area) const { |
28 DCHECK(bounds && maximized); | 29 DCHECK(bounds && maximized); |
29 | 30 |
30 std::string key(prefs::kBrowserWindowPlacement); | 31 std::string key(prefs::kBrowserWindowPlacement); |
31 if (!app_name_.empty()) { | 32 if (!app_name_.empty()) { |
32 key.append("_"); | 33 key.append("_"); |
33 key.append(app_name_); | 34 key.append(app_name_); |
34 } | 35 } |
35 | 36 |
36 if (!g_browser_process->local_state()) | 37 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 38 if (!profile_manager) |
37 return false; | 39 return false; |
38 | 40 |
39 const DictionaryValue* wp_pref = | 41 const DictionaryValue* wp_pref = |
40 g_browser_process->local_state()->GetDictionary(key.c_str()); | 42 profile_manager->GetDefaultProfile()->GetPrefs()->GetDictionary( |
| 43 key.c_str()); |
41 int top = 0, left = 0, bottom = 0, right = 0; | 44 int top = 0, left = 0, bottom = 0, right = 0; |
42 bool has_prefs = | 45 bool has_prefs = |
43 wp_pref && | 46 wp_pref && |
44 wp_pref->GetInteger("top", &top) && | 47 wp_pref->GetInteger("top", &top) && |
45 wp_pref->GetInteger("left", &left) && | 48 wp_pref->GetInteger("left", &left) && |
46 wp_pref->GetInteger("bottom", &bottom) && | 49 wp_pref->GetInteger("bottom", &bottom) && |
47 wp_pref->GetInteger("right", &right) && | 50 wp_pref->GetInteger("right", &right) && |
48 wp_pref->GetBoolean("maximized", maximized); | 51 wp_pref->GetBoolean("maximized", maximized); |
49 bounds->SetRect(left, top, std::max(0, right - left), | 52 bounds->SetRect(left, top, std::max(0, right - left), |
50 std::max(0, bottom - top)); | 53 std::max(0, bottom - top)); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 // On non-Mac platforms, we are less aggressive about repositioning. Simply | 330 // On non-Mac platforms, we are less aggressive about repositioning. Simply |
328 // ensure that at least kMinVisibleWidth * kMinVisibleHeight is visible. | 331 // ensure that at least kMinVisibleWidth * kMinVisibleHeight is visible. |
329 const int min_y = work_area.y() + kMinVisibleHeight - bounds->height(); | 332 const int min_y = work_area.y() + kMinVisibleHeight - bounds->height(); |
330 const int min_x = work_area.x() + kMinVisibleWidth - bounds->width(); | 333 const int min_x = work_area.x() + kMinVisibleWidth - bounds->width(); |
331 const int max_y = work_area.bottom() - kMinVisibleHeight; | 334 const int max_y = work_area.bottom() - kMinVisibleHeight; |
332 const int max_x = work_area.right() - kMinVisibleWidth; | 335 const int max_x = work_area.right() - kMinVisibleWidth; |
333 bounds->set_y(std::max(min_y, std::min(max_y, bounds->y()))); | 336 bounds->set_y(std::max(min_y, std::min(max_y, bounds->y()))); |
334 bounds->set_x(std::max(min_x, std::min(max_x, bounds->x()))); | 337 bounds->set_x(std::max(min_x, std::min(max_x, bounds->x()))); |
335 #endif // defined(OS_MACOSX) | 338 #endif // defined(OS_MACOSX) |
336 } | 339 } |
OLD | NEW |