OLD | NEW |
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 #include "chrome/browser/ui/views/chrome_views_delegate.h" | 5 #include "chrome/browser/ui/views/chrome_views_delegate.h" |
6 | 6 |
7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" |
11 #include "chrome/browser/ui/views/accessibility_event_router_views.h" | 13 #include "chrome/browser/ui/views/accessibility_event_router_views.h" |
12 #include "chrome/browser/ui/window_sizer.h" | 14 #include "chrome/browser/ui/window_sizer.h" |
| 15 #include "chrome/common/pref_names.h" |
13 #include "gfx/rect.h" | 16 #include "gfx/rect.h" |
14 #include "ui/base/clipboard/clipboard.h" | 17 #include "ui/base/clipboard/clipboard.h" |
15 | 18 |
16 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
17 #include "chrome/browser/app_icon_win.h" | 20 #include "chrome/browser/app_icon_win.h" |
18 #endif | 21 #endif |
19 | 22 |
| 23 namespace { |
| 24 |
| 25 // Some window data should be stored in local state, instead of by profile; use |
| 26 // the window_name to differentiate between storage types. This function may |
| 27 // return NULL if the necessary PrefService has not yet been initialized. |
| 28 // TODO(mirandac): This function will also serve to separate windows by profile |
| 29 // in a multiprofile environment. |
| 30 PrefService* GetPrefsForWindow(const std::wstring& window_name) { |
| 31 if (LowerCaseEqualsASCII(window_name, prefs::kTaskManagerWindowPlacement)) { |
| 32 return g_browser_process->local_state(); |
| 33 } else { |
| 34 if (!g_browser_process->profile_manager()) { |
| 35 return NULL; |
| 36 } |
| 37 return g_browser_process->profile_manager()->GetDefaultProfile()-> |
| 38 GetPrefs(); |
| 39 } |
| 40 } |
| 41 |
| 42 } // namespace |
| 43 |
20 /////////////////////////////////////////////////////////////////////////////// | 44 /////////////////////////////////////////////////////////////////////////////// |
21 // ChromeViewsDelegate, views::ViewsDelegate implementation: | 45 // ChromeViewsDelegate, views::ViewsDelegate implementation: |
22 | 46 |
23 ui::Clipboard* ChromeViewsDelegate::GetClipboard() const { | 47 ui::Clipboard* ChromeViewsDelegate::GetClipboard() const { |
24 return g_browser_process->clipboard(); | 48 return g_browser_process->clipboard(); |
25 } | 49 } |
26 | 50 |
27 void ChromeViewsDelegate::SaveWindowPlacement(const std::wstring& window_name, | 51 void ChromeViewsDelegate::SaveWindowPlacement(const std::wstring& window_name, |
28 const gfx::Rect& bounds, | 52 const gfx::Rect& bounds, |
29 bool maximized) { | 53 bool maximized) { |
30 if (!g_browser_process->local_state()) | 54 PrefService* prefs = GetPrefsForWindow(window_name); |
| 55 if (!prefs) |
31 return; | 56 return; |
32 | 57 |
33 DictionaryValue* window_preferences = | 58 DictionaryValue* window_preferences = |
34 g_browser_process->local_state()->GetMutableDictionary( | 59 prefs->GetMutableDictionary(WideToUTF8(window_name).c_str()); |
35 WideToUTF8(window_name).c_str()); | |
36 window_preferences->SetInteger("left", bounds.x()); | 60 window_preferences->SetInteger("left", bounds.x()); |
37 window_preferences->SetInteger("top", bounds.y()); | 61 window_preferences->SetInteger("top", bounds.y()); |
38 window_preferences->SetInteger("right", bounds.right()); | 62 window_preferences->SetInteger("right", bounds.right()); |
39 window_preferences->SetInteger("bottom", bounds.bottom()); | 63 window_preferences->SetInteger("bottom", bounds.bottom()); |
40 window_preferences->SetBoolean("maximized", maximized); | 64 window_preferences->SetBoolean("maximized", maximized); |
41 | 65 |
42 scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_info_provider( | 66 scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_info_provider( |
43 WindowSizer::CreateDefaultMonitorInfoProvider()); | 67 WindowSizer::CreateDefaultMonitorInfoProvider()); |
44 gfx::Rect work_area( | 68 gfx::Rect work_area( |
45 monitor_info_provider->GetMonitorWorkAreaMatching(bounds)); | 69 monitor_info_provider->GetMonitorWorkAreaMatching(bounds)); |
46 window_preferences->SetInteger("work_area_left", work_area.x()); | 70 window_preferences->SetInteger("work_area_left", work_area.x()); |
47 window_preferences->SetInteger("work_area_top", work_area.y()); | 71 window_preferences->SetInteger("work_area_top", work_area.y()); |
48 window_preferences->SetInteger("work_area_right", work_area.right()); | 72 window_preferences->SetInteger("work_area_right", work_area.right()); |
49 window_preferences->SetInteger("work_area_bottom", work_area.bottom()); | 73 window_preferences->SetInteger("work_area_bottom", work_area.bottom()); |
50 } | 74 } |
51 | 75 |
52 bool ChromeViewsDelegate::GetSavedWindowBounds(const std::wstring& window_name, | 76 bool ChromeViewsDelegate::GetSavedWindowBounds(const std::wstring& window_name, |
53 gfx::Rect* bounds) const { | 77 gfx::Rect* bounds) const { |
54 if (!g_browser_process->local_state()) | 78 PrefService* prefs = GetPrefsForWindow(window_name); |
| 79 if (!prefs) |
55 return false; | 80 return false; |
56 | 81 |
57 const DictionaryValue* dictionary = | 82 const DictionaryValue* dictionary = |
58 g_browser_process->local_state()->GetDictionary( | 83 prefs->GetDictionary(WideToUTF8(window_name).c_str()); |
59 WideToUTF8(window_name).c_str()); | |
60 int left, top, right, bottom; | 84 int left, top, right, bottom; |
61 if (!dictionary || !dictionary->GetInteger("left", &left) || | 85 if (!dictionary || !dictionary->GetInteger("left", &left) || |
62 !dictionary->GetInteger("top", &top) || | 86 !dictionary->GetInteger("top", &top) || |
63 !dictionary->GetInteger("right", &right) || | 87 !dictionary->GetInteger("right", &right) || |
64 !dictionary->GetInteger("bottom", &bottom)) | 88 !dictionary->GetInteger("bottom", &bottom)) |
65 return false; | 89 return false; |
66 | 90 |
67 bounds->SetRect(left, top, right - left, bottom - top); | 91 bounds->SetRect(left, top, right - left, bottom - top); |
68 return true; | 92 return true; |
69 } | 93 } |
70 | 94 |
71 bool ChromeViewsDelegate::GetSavedMaximizedState( | 95 bool ChromeViewsDelegate::GetSavedMaximizedState( |
72 const std::wstring& window_name, | 96 const std::wstring& window_name, |
73 bool* maximized) const { | 97 bool* maximized) const { |
74 if (!g_browser_process->local_state()) | 98 PrefService* prefs = GetPrefsForWindow(window_name); |
| 99 if (!prefs) |
75 return false; | 100 return false; |
76 | 101 |
77 const DictionaryValue* dictionary = | 102 const DictionaryValue* dictionary = |
78 g_browser_process->local_state()->GetDictionary( | 103 prefs->GetDictionary(WideToUTF8(window_name).c_str()); |
79 WideToUTF8(window_name).c_str()); | 104 |
80 return dictionary && dictionary->GetBoolean("maximized", maximized) && | 105 return dictionary && dictionary->GetBoolean("maximized", maximized) && |
81 maximized; | 106 maximized; |
82 } | 107 } |
83 | 108 |
84 void ChromeViewsDelegate::NotifyAccessibilityEvent( | 109 void ChromeViewsDelegate::NotifyAccessibilityEvent( |
85 views::View* view, AccessibilityTypes::Event event_type) { | 110 views::View* view, AccessibilityTypes::Event event_type) { |
86 AccessibilityEventRouterViews::GetInstance()->HandleAccessibilityEvent( | 111 AccessibilityEventRouterViews::GetInstance()->HandleAccessibilityEvent( |
87 view, event_type); | 112 view, event_type); |
88 } | 113 } |
89 | 114 |
90 #if defined(OS_WIN) | 115 #if defined(OS_WIN) |
91 HICON ChromeViewsDelegate::GetDefaultWindowIcon() const { | 116 HICON ChromeViewsDelegate::GetDefaultWindowIcon() const { |
92 return GetAppIcon(); | 117 return GetAppIcon(); |
93 } | 118 } |
94 #endif | 119 #endif |
95 | 120 |
96 void ChromeViewsDelegate::AddRef() { | 121 void ChromeViewsDelegate::AddRef() { |
97 g_browser_process->AddRefModule(); | 122 g_browser_process->AddRefModule(); |
98 } | 123 } |
99 | 124 |
100 void ChromeViewsDelegate::ReleaseRef() { | 125 void ChromeViewsDelegate::ReleaseRef() { |
101 g_browser_process->ReleaseModule(); | 126 g_browser_process->ReleaseModule(); |
102 } | 127 } |
OLD | NEW |