| 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/browser/browser.h" | 8 #include "chrome/browser/browser.h" |
| 9 #include "chrome/browser/browser_list.h" | 9 #include "chrome/browser/browser_list.h" |
| 10 #include "chrome/browser/browser_window.h" | 10 #include "chrome/browser/browser_window.h" |
| 11 #include "chrome/browser/options_window.h" | 11 #include "chrome/browser/options_window.h" |
| 12 #include "chrome/browser/profile.h" | 12 #include "chrome/browser/profile.h" |
| 13 #include "chrome/browser/search_engines/template_url_model.h" | 13 #include "chrome/browser/search_engines/template_url_model.h" |
| 14 #include "chrome/browser/views/standard_layout.h" | 14 #include "chrome/browser/views/standard_layout.h" |
| 15 #include "chrome/common/l10n_util.h" | 15 #include "chrome/common/l10n_util.h" |
| 16 #include "chrome/common/resource_bundle.h" | 16 #include "chrome/common/resource_bundle.h" |
| 17 #include "chrome/views/event.h" | 17 #include "chrome/views/event.h" |
| 18 #include "chrome/views/controls/button/native_button.h" | 18 #include "chrome/views/controls/button/native_button.h" |
| 19 #include "chrome/views/controls/label.h" | 19 #include "chrome/views/controls/label.h" |
| 20 #include "chrome/views/focus/focus_manager.h" |
| 20 #include "chrome/views/window/window.h" | 21 #include "chrome/views/window/window.h" |
| 21 #include "grit/chromium_strings.h" | 22 #include "grit/chromium_strings.h" |
| 22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 23 #include "grit/locale_settings.h" | 24 #include "grit/locale_settings.h" |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // How much extra padding to put around our content over what | 28 // How much extra padding to put around our content over what the InfoBubble |
| 28 // infobubble provides. | 29 // provides. |
| 29 static const int kBubblePadding = 4; | 30 static const int kBubblePadding = 4; |
| 30 | 31 |
| 31 std::wstring GetDefaultSearchEngineName(Profile* profile) { | 32 std::wstring GetDefaultSearchEngineName(Profile* profile) { |
| 32 if (!profile) { | 33 if (!profile) { |
| 33 NOTREACHED(); | 34 NOTREACHED(); |
| 34 return std::wstring(); | 35 return std::wstring(); |
| 35 } | 36 } |
| 36 const TemplateURL* const default_provider = | 37 const TemplateURL* const default_provider = |
| 37 profile->GetTemplateURLModel()->GetDefaultSearchProvider(); | 38 profile->GetTemplateURLModel()->GetDefaultSearchProvider(); |
| 38 if (!default_provider) { | 39 if (!default_provider) { |
| 39 // 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. |
| 40 // returning an empty string is a stopgap measure for the crash | 41 // returning an empty string is a stopgap measure for the crash |
| 41 // http://code.google.com/p/chromium/issues/detail?id=2573 | 42 // http://code.google.com/p/chromium/issues/detail?id=2573 |
| 42 return std::wstring(); | 43 return std::wstring(); |
| 43 } | 44 } |
| 44 return default_provider->short_name(); | 45 return default_provider->short_name(); |
| 45 } | 46 } |
| 46 | 47 |
| 47 } // namespace | 48 } // namespace |
| 48 | 49 |
| 49 // 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 |
| 50 // dialog-ish view, but is not a true dialog. | 51 // dialog-ish view, but is not a true dialog. |
| 51 class FirstRunBubbleView : public views::View, | 52 class FirstRunBubbleView : public views::View, |
| 52 public views::NativeButton::Listener { | 53 public views::NativeButton::Listener, |
| 54 public views::FocusChangeListener { |
| 53 public: | 55 public: |
| 54 FirstRunBubbleView(FirstRunBubble* bubble_window, Profile* profile) | 56 FirstRunBubbleView(FirstRunBubble* bubble_window, Profile* profile) |
| 55 : bubble_window_(bubble_window), | 57 : bubble_window_(bubble_window), |
| 56 label1_(NULL), | 58 label1_(NULL), |
| 57 label2_(NULL), | 59 label2_(NULL), |
| 58 label3_(NULL), | 60 label3_(NULL), |
| 59 keep_button_(NULL), | 61 keep_button_(NULL), |
| 60 change_button_(NULL) { | 62 change_button_(NULL) { |
| 61 ChromeFont& font = | 63 ChromeFont& font = |
| 62 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont); | 64 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 keep_button_->RequestFocus(); | 159 keep_button_->RequestFocus(); |
| 158 } | 160 } |
| 159 | 161 |
| 160 // Overridden from views::View. | 162 // Overridden from views::View. |
| 161 virtual gfx::Size GetPreferredSize() { | 163 virtual gfx::Size GetPreferredSize() { |
| 162 return gfx::Size(views::Window::GetLocalizedContentsSize( | 164 return gfx::Size(views::Window::GetLocalizedContentsSize( |
| 163 IDS_FIRSTRUNBUBBLE_DIALOG_WIDTH_CHARS, | 165 IDS_FIRSTRUNBUBBLE_DIALOG_WIDTH_CHARS, |
| 164 IDS_FIRSTRUNBUBBLE_DIALOG_HEIGHT_LINES)); | 166 IDS_FIRSTRUNBUBBLE_DIALOG_HEIGHT_LINES)); |
| 165 } | 167 } |
| 166 | 168 |
| 169 virtual void FocusWillChange(View* focused_before, View* focused_now) { |
| 170 if (focused_before && focused_before->GetClassName() == |
| 171 views::NativeButton::kViewClassName) { |
| 172 views::NativeButton* before = |
| 173 static_cast<views::NativeButton*>(focused_before); |
| 174 before->SetDefaultButton(false); |
| 175 } |
| 176 if (focused_now && focused_now->GetClassName() == |
| 177 views::NativeButton::kViewClassName) { |
| 178 views::NativeButton* after = |
| 179 static_cast<views::NativeButton*>(focused_now); |
| 180 after->SetDefaultButton(true); |
| 181 } |
| 182 } |
| 183 |
| 167 private: | 184 private: |
| 168 FirstRunBubble* bubble_window_; | 185 FirstRunBubble* bubble_window_; |
| 169 views::Label* label1_; | 186 views::Label* label1_; |
| 170 views::Label* label2_; | 187 views::Label* label2_; |
| 171 views::Label* label3_; | 188 views::Label* label3_; |
| 172 views::NativeButton* change_button_; | 189 views::NativeButton* change_button_; |
| 173 views::NativeButton* keep_button_; | 190 views::NativeButton* keep_button_; |
| 174 DISALLOW_EVIL_CONSTRUCTORS(FirstRunBubbleView); | 191 |
| 192 DISALLOW_COPY_AND_ASSIGN(FirstRunBubbleView); |
| 175 }; | 193 }; |
| 176 | 194 |
| 177 // Keep the bubble around for kLingerTime milliseconds, to prevent accidental | 195 // Keep the bubble around for kLingerTime milliseconds, to prevent accidental |
| 178 // closure. | 196 // closure. |
| 179 static const int kLingerTime = 1000; | 197 static const int kLingerTime = 1000; |
| 180 | 198 |
| 181 void FirstRunBubble::OnActivate(UINT action, BOOL minimized, HWND window) { | 199 void FirstRunBubble::OnActivate(UINT action, BOOL minimized, HWND window) { |
| 182 // We might get re-enabled right before we are closed (sequence is: we get | 200 // We might get re-enabled right before we are closed (sequence is: we get |
| 183 // deactivated, we call close, before we are actually closed we get | 201 // deactivated, we call close, before we are actually closed we get |
| 184 // reactivated). Don't do the disabling of the parent in such cases. | 202 // reactivated). Don't do the disabling of the parent in such cases. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 196 } | 214 } |
| 197 InfoBubble::OnActivate(action, minimized, window); | 215 InfoBubble::OnActivate(action, minimized, window); |
| 198 } | 216 } |
| 199 | 217 |
| 200 void FirstRunBubble::InfoBubbleClosing(InfoBubble* info_bubble, | 218 void FirstRunBubble::InfoBubbleClosing(InfoBubble* info_bubble, |
| 201 bool closed_by_escape) { | 219 bool closed_by_escape) { |
| 202 // Make sure our parent window is re-enabled. | 220 // Make sure our parent window is re-enabled. |
| 203 if (!IsWindowEnabled(GetParent())) | 221 if (!IsWindowEnabled(GetParent())) |
| 204 ::EnableWindow(GetParent(), true); | 222 ::EnableWindow(GetParent(), true); |
| 205 enable_window_method_factory_.RevokeAll(); | 223 enable_window_method_factory_.RevokeAll(); |
| 224 views::FocusManager* focus_manager = |
| 225 views::FocusManager::GetFocusManager(GetNativeView()); |
| 226 focus_manager->RemoveFocusChangeListener(view_); |
| 206 } | 227 } |
| 207 | 228 |
| 229 // static |
| 208 FirstRunBubble* FirstRunBubble::Show(Profile* profile, HWND parent_hwnd, | 230 FirstRunBubble* FirstRunBubble::Show(Profile* profile, HWND parent_hwnd, |
| 209 const gfx::Rect& position_relative_to) { | 231 const gfx::Rect& position_relative_to) { |
| 210 FirstRunBubble* window = new FirstRunBubble(); | 232 FirstRunBubble* window = new FirstRunBubble(); |
| 211 views::View* view = new FirstRunBubbleView(window, profile); | 233 FirstRunBubbleView* view = new FirstRunBubbleView(window, profile); |
| 212 window->SetDelegate(window); | 234 window->SetDelegate(window); |
| 235 window->set_view(view); |
| 213 window->Init(parent_hwnd, position_relative_to, view); | 236 window->Init(parent_hwnd, position_relative_to, view); |
| 214 window->ShowWindow(SW_SHOW); | 237 window->ShowWindow(SW_SHOW); |
| 238 views::FocusManager* focus_manager = |
| 239 views::FocusManager::GetFocusManager(window->GetNativeView()); |
| 240 focus_manager->AddFocusChangeListener(view); |
| 215 return window; | 241 return window; |
| 216 } | 242 } |
| 217 | 243 |
| 218 void FirstRunBubble::EnableParent() { | 244 void FirstRunBubble::EnableParent() { |
| 219 ::EnableWindow(GetParent(), true); | 245 ::EnableWindow(GetParent(), true); |
| 220 } | 246 } |
| OLD | NEW |