OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/first_run_bubble.h" | 5 #include "chrome/browser/views/first_run_bubble.h" |
6 | 6 |
7 #include "base/win_util.h" | 7 #include "base/win_util.h" |
8 #include "chrome/app/locales/locale_settings.h" | 8 #include "chrome/app/locales/locale_settings.h" |
9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 #include "chromium_strings.h" | 23 #include "chromium_strings.h" |
24 #include "generated_resources.h" | 24 #include "generated_resources.h" |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 // How much extra padding to put around our content over what | 28 // How much extra padding to put around our content over what |
29 // infobubble provides. | 29 // infobubble provides. |
30 static const int kBubblePadding = 4; | 30 static const int kBubblePadding = 4; |
31 | 31 |
32 std::wstring GetDefaultSearchEngineName() { | 32 std::wstring GetDefaultSearchEngineName(Profile* profile) { |
33 Browser* browser = BrowserList::GetLastActive(); | 33 if (!profile) { |
34 DCHECK(browser); | 34 NOTREACHED(); |
| 35 return std::wstring(); |
| 36 } |
35 const TemplateURL* const default_provider = | 37 const TemplateURL* const default_provider = |
36 browser->profile()->GetTemplateURLModel()->GetDefaultSearchProvider(); | 38 profile->GetTemplateURLModel()->GetDefaultSearchProvider(); |
37 if (!default_provider) { | 39 if (!default_provider) { |
38 // TODO(cpu): bug 1187517. It is possible to have no default provider. | 40 // TODO(cpu): bug 1187517. It is possible to have no default provider. |
39 // returning an empty string is a stopgap measure for the crash | 41 // returning an empty string is a stopgap measure for the crash |
40 // http://code.google.com/p/chromium/issues/detail?id=2573 | 42 // http://code.google.com/p/chromium/issues/detail?id=2573 |
41 return std::wstring(); | 43 return std::wstring(); |
42 } | 44 } |
43 return default_provider->short_name(); | 45 return default_provider->short_name(); |
44 } | 46 } |
45 | 47 |
46 } // namespace | 48 } // namespace |
47 | 49 |
48 // Implements the client view inside the first run bubble. It is kind of a | 50 // Implements the client view inside the first run bubble. It is kind of a |
49 // dialog-ish view, but is not a true dialog. | 51 // dialog-ish view, but is not a true dialog. |
50 class FirstRunBubbleView : public views::View, | 52 class FirstRunBubbleView : public views::View, |
51 public views::NativeButton::Listener { | 53 public views::NativeButton::Listener { |
52 public: | 54 public: |
53 explicit FirstRunBubbleView(FirstRunBubble* bubble_window) | 55 FirstRunBubbleView(FirstRunBubble* bubble_window, Profile* profile) |
54 : bubble_window_(bubble_window), | 56 : bubble_window_(bubble_window), |
55 label1_(NULL), | 57 label1_(NULL), |
56 label2_(NULL), | 58 label2_(NULL), |
57 label3_(NULL), | 59 label3_(NULL), |
58 keep_button_(NULL), | 60 keep_button_(NULL), |
59 change_button_(NULL) { | 61 change_button_(NULL) { |
60 ChromeFont& font = | 62 ChromeFont& font = |
61 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont); | 63 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont); |
62 | 64 |
63 label1_ = new views::Label(l10n_util::GetString(IDS_FR_BUBBLE_TITLE)); | 65 label1_ = new views::Label(l10n_util::GetString(IDS_FR_BUBBLE_TITLE)); |
64 label1_->SetFont(font.DeriveFont(3, ChromeFont::BOLD)); | 66 label1_->SetFont(font.DeriveFont(3, ChromeFont::BOLD)); |
65 label1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 67 label1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
66 AddChildView(label1_); | 68 AddChildView(label1_); |
67 | 69 |
68 gfx::Size ps = GetPreferredSize(); | 70 gfx::Size ps = GetPreferredSize(); |
69 | 71 |
70 label2_ = new views::Label(l10n_util::GetString(IDS_FR_BUBBLE_SUBTEXT)); | 72 label2_ = new views::Label(l10n_util::GetString(IDS_FR_BUBBLE_SUBTEXT)); |
71 label2_->SetMultiLine(true); | 73 label2_->SetMultiLine(true); |
72 label2_->SetFont(font); | 74 label2_->SetFont(font); |
73 label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 75 label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
74 label2_->SizeToFit(ps.width() - kBubblePadding * 2); | 76 label2_->SizeToFit(ps.width() - kBubblePadding * 2); |
75 AddChildView(label2_); | 77 AddChildView(label2_); |
76 | 78 |
77 std::wstring question_str | 79 std::wstring question_str |
78 = l10n_util::GetStringF(IDS_FR_BUBBLE_QUESTION, | 80 = l10n_util::GetStringF(IDS_FR_BUBBLE_QUESTION, |
79 GetDefaultSearchEngineName()); | 81 GetDefaultSearchEngineName(profile)); |
80 label3_ = new views::Label(question_str); | 82 label3_ = new views::Label(question_str); |
81 label3_->SetMultiLine(true); | 83 label3_->SetMultiLine(true); |
82 label3_->SetFont(font); | 84 label3_->SetFont(font); |
83 label3_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 85 label3_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
84 label3_->SizeToFit(ps.width() - kBubblePadding * 2); | 86 label3_->SizeToFit(ps.width() - kBubblePadding * 2); |
85 AddChildView(label3_); | 87 AddChildView(label3_); |
86 | 88 |
87 std::wstring keep_str = l10n_util::GetStringF(IDS_FR_BUBBLE_OK, | 89 std::wstring keep_str = |
88 GetDefaultSearchEngineName()); | 90 l10n_util::GetStringF(IDS_FR_BUBBLE_OK, |
| 91 GetDefaultSearchEngineName(profile)); |
89 keep_button_ = new views::NativeButton(keep_str, true); | 92 keep_button_ = new views::NativeButton(keep_str, true); |
90 keep_button_->SetListener(this); | 93 keep_button_->SetListener(this); |
91 AddChildView(keep_button_); | 94 AddChildView(keep_button_); |
92 | 95 |
93 std::wstring change_str = l10n_util::GetString(IDS_FR_BUBBLE_CHANGE); | 96 std::wstring change_str = l10n_util::GetString(IDS_FR_BUBBLE_CHANGE); |
94 change_button_ = new views::NativeButton(change_str); | 97 change_button_ = new views::NativeButton(change_str); |
95 change_button_->SetListener(this); | 98 change_button_->SetListener(this); |
96 AddChildView(change_button_); | 99 AddChildView(change_button_); |
97 } | 100 } |
98 | 101 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 199 } |
197 | 200 |
198 void FirstRunBubble::InfoBubbleClosing(InfoBubble* info_bubble, | 201 void FirstRunBubble::InfoBubbleClosing(InfoBubble* info_bubble, |
199 bool closed_by_escape) { | 202 bool closed_by_escape) { |
200 // Make sure our parent window is re-enabled. | 203 // Make sure our parent window is re-enabled. |
201 if (!IsWindowEnabled(GetParent())) | 204 if (!IsWindowEnabled(GetParent())) |
202 ::EnableWindow(GetParent(), true); | 205 ::EnableWindow(GetParent(), true); |
203 enable_window_method_factory_.RevokeAll(); | 206 enable_window_method_factory_.RevokeAll(); |
204 } | 207 } |
205 | 208 |
206 FirstRunBubble* FirstRunBubble::Show(HWND parent_hwnd, | 209 FirstRunBubble* FirstRunBubble::Show(Profile* profile, HWND parent_hwnd, |
207 const gfx::Rect& position_relative_to) { | 210 const gfx::Rect& position_relative_to) { |
208 FirstRunBubble* window = new FirstRunBubble(); | 211 FirstRunBubble* window = new FirstRunBubble(); |
209 views::View* view = new FirstRunBubbleView(window); | 212 views::View* view = new FirstRunBubbleView(window, profile); |
210 window->SetDelegate(window); | 213 window->SetDelegate(window); |
211 window->Init(parent_hwnd, position_relative_to, view); | 214 window->Init(parent_hwnd, position_relative_to, view); |
212 window->ShowWindow(SW_SHOW); | 215 window->ShowWindow(SW_SHOW); |
213 return window; | 216 return window; |
214 } | 217 } |
215 | 218 |
216 void FirstRunBubble::EnableParent() { | 219 void FirstRunBubble::EnableParent() { |
217 ::EnableWindow(GetParent(), true); | 220 ::EnableWindow(GetParent(), true); |
218 } | 221 } |
219 | 222 |
OLD | NEW |