| 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/views/first_run_bubble.h" | 5 #include "chrome/browser/views/first_run_bubble.h" |
| 6 | 6 |
| 7 #include "app/gfx/font_util.h" | 7 #include "app/gfx/font_util.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "app/win_util.h" | 10 #include "app/win_util.h" |
| 11 #include "base/utf_string_conversions.h" |
| 11 #include "base/win_util.h" | 12 #include "base/win_util.h" |
| 12 #include "chrome/browser/browser.h" | 13 #include "chrome/browser/browser.h" |
| 13 #include "chrome/browser/browser_list.h" | 14 #include "chrome/browser/browser_list.h" |
| 14 #include "chrome/browser/browser_window.h" | 15 #include "chrome/browser/browser_window.h" |
| 15 #include "chrome/browser/first_run.h" | 16 #include "chrome/browser/first_run.h" |
| 16 #include "chrome/browser/options_window.h" | 17 #include "chrome/browser/options_window.h" |
| 17 #include "chrome/browser/profile.h" | 18 #include "chrome/browser/search_engines/util.h" |
| 18 #include "chrome/browser/search_engines/template_url_model.h" | |
| 19 #include "chrome/browser/metrics/user_metrics.h" | 19 #include "chrome/browser/metrics/user_metrics.h" |
| 20 #include "grit/chromium_strings.h" | 20 #include "grit/chromium_strings.h" |
| 21 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 22 #include "grit/locale_settings.h" | 22 #include "grit/locale_settings.h" |
| 23 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
| 24 #include "views/event.h" | 24 #include "views/event.h" |
| 25 #include "views/controls/button/native_button.h" | 25 #include "views/controls/button/native_button.h" |
| 26 #include "views/controls/button/image_button.h" | 26 #include "views/controls/button/image_button.h" |
| 27 #include "views/controls/label.h" | 27 #include "views/controls/label.h" |
| 28 #include "views/focus/focus_manager.h" | 28 #include "views/focus/focus_manager.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 39 // provides in alternative OEM bubble. | 39 // provides in alternative OEM bubble. |
| 40 const int kOEMBubblePadding = 4; | 40 const int kOEMBubblePadding = 4; |
| 41 | 41 |
| 42 // Padding between parts of strings on the same line (for instance, | 42 // Padding between parts of strings on the same line (for instance, |
| 43 // "New!" and "Search from the address bar!" | 43 // "New!" and "Search from the address bar!" |
| 44 const int kStringSeparationPadding = 2; | 44 const int kStringSeparationPadding = 2; |
| 45 | 45 |
| 46 // Margin around close button. | 46 // Margin around close button. |
| 47 const int kMarginRightOfCloseButton = 7; | 47 const int kMarginRightOfCloseButton = 7; |
| 48 | 48 |
| 49 std::wstring GetDefaultSearchEngineName(Profile* profile) { | |
| 50 if (!profile) { | |
| 51 NOTREACHED(); | |
| 52 return std::wstring(); | |
| 53 } | |
| 54 const TemplateURL* const default_provider = | |
| 55 profile->GetTemplateURLModel()->GetDefaultSearchProvider(); | |
| 56 if (!default_provider) { | |
| 57 // TODO(cpu): bug 1187517. It is possible to have no default provider. | |
| 58 // returning an empty string is a stopgap measure for the crash | |
| 59 // http://code.google.com/p/chromium/issues/detail?id=2573 | |
| 60 return std::wstring(); | |
| 61 } | |
| 62 return default_provider->short_name(); | |
| 63 } | |
| 64 | |
| 65 } // namespace | 49 } // namespace |
| 66 | 50 |
| 67 // Base class for implementations of the client view which appears inside the | 51 // Base class for implementations of the client view which appears inside the |
| 68 // first run bubble. It is a dialog-ish view, but is not a true dialog. | 52 // first run bubble. It is a dialog-ish view, but is not a true dialog. |
| 69 class FirstRunBubbleViewBase : public views::View, | 53 class FirstRunBubbleViewBase : public views::View, |
| 70 public views::ButtonListener, | 54 public views::ButtonListener, |
| 71 public views::FocusChangeListener { | 55 public views::FocusChangeListener { |
| 72 public: | 56 public: |
| 73 // Called by FirstRunBubble::Show to request focus for the proper button | 57 // Called by FirstRunBubble::Show to request focus for the proper button |
| 74 // in the FirstRunBubbleView when it is shown. | 58 // in the FirstRunBubbleView when it is shown. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 gfx::Size ps = GetPreferredSize(); | 110 gfx::Size ps = GetPreferredSize(); |
| 127 | 111 |
| 128 label2_ = new views::Label(l10n_util::GetString(IDS_FR_BUBBLE_SUBTEXT)); | 112 label2_ = new views::Label(l10n_util::GetString(IDS_FR_BUBBLE_SUBTEXT)); |
| 129 label2_->SetMultiLine(true); | 113 label2_->SetMultiLine(true); |
| 130 label2_->SetFont(font); | 114 label2_->SetFont(font); |
| 131 label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 115 label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 132 label2_->SizeToFit(ps.width() - kBubblePadding * 2); | 116 label2_->SizeToFit(ps.width() - kBubblePadding * 2); |
| 133 AddChildView(label2_); | 117 AddChildView(label2_); |
| 134 | 118 |
| 135 std::wstring question_str = l10n_util::GetStringF(IDS_FR_BUBBLE_QUESTION, | 119 std::wstring question_str = l10n_util::GetStringF(IDS_FR_BUBBLE_QUESTION, |
| 136 GetDefaultSearchEngineName(profile)); | 120 UTF16ToWideHack(GetDefaultSearchEngineName(profile))); |
| 137 label3_ = new views::Label(question_str); | 121 label3_ = new views::Label(question_str); |
| 138 label3_->SetMultiLine(true); | 122 label3_->SetMultiLine(true); |
| 139 label3_->SetFont(font); | 123 label3_->SetFont(font); |
| 140 label3_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 124 label3_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 141 label3_->SizeToFit(ps.width() - kBubblePadding * 2); | 125 label3_->SizeToFit(ps.width() - kBubblePadding * 2); |
| 142 AddChildView(label3_); | 126 AddChildView(label3_); |
| 143 | 127 |
| 144 std::wstring keep_str = l10n_util::GetStringF(IDS_FR_BUBBLE_OK, | 128 std::wstring keep_str = l10n_util::GetStringF(IDS_FR_BUBBLE_OK, |
| 145 GetDefaultSearchEngineName(profile)); | 129 UTF16ToWideHack(GetDefaultSearchEngineName(profile))); |
| 146 keep_button_ = new views::NativeButton(this, keep_str); | 130 keep_button_ = new views::NativeButton(this, keep_str); |
| 147 keep_button_->SetIsDefault(true); | 131 keep_button_->SetIsDefault(true); |
| 148 AddChildView(keep_button_); | 132 AddChildView(keep_button_); |
| 149 | 133 |
| 150 std::wstring change_str = l10n_util::GetString(IDS_FR_BUBBLE_CHANGE); | 134 std::wstring change_str = l10n_util::GetString(IDS_FR_BUBBLE_CHANGE); |
| 151 change_button_ = new views::NativeButton(this, change_str); | 135 change_button_ = new views::NativeButton(this, change_str); |
| 152 AddChildView(change_button_); | 136 AddChildView(change_button_); |
| 153 } | 137 } |
| 154 | 138 |
| 155 void FirstRunBubbleView::BubbleShown() { | 139 void FirstRunBubbleView::BubbleShown() { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 FirstRunBubble* bubble_window, | 398 FirstRunBubble* bubble_window, |
| 415 Profile* profile) | 399 Profile* profile) |
| 416 : bubble_window_(bubble_window), | 400 : bubble_window_(bubble_window), |
| 417 profile_(profile), | 401 profile_(profile), |
| 418 label1_(NULL), | 402 label1_(NULL), |
| 419 label2_(NULL) { | 403 label2_(NULL) { |
| 420 const gfx::Font& font = | 404 const gfx::Font& font = |
| 421 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont); | 405 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont); |
| 422 | 406 |
| 423 label1_ = new views::Label(l10n_util::GetStringF(IDS_FR_SE_BUBBLE_TITLE, | 407 label1_ = new views::Label(l10n_util::GetStringF(IDS_FR_SE_BUBBLE_TITLE, |
| 424 GetDefaultSearchEngineName(profile_))); | 408 UTF16ToWideHack(GetDefaultSearchEngineName(profile_)))); |
| 425 label1_->SetFont(font.DeriveFont(3, gfx::Font::BOLD)); | 409 label1_->SetFont(font.DeriveFont(3, gfx::Font::BOLD)); |
| 426 label1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 410 label1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 427 AddChildView(label1_); | 411 AddChildView(label1_); |
| 428 | 412 |
| 429 gfx::Size ps = GetPreferredSize(); | 413 gfx::Size ps = GetPreferredSize(); |
| 430 | 414 |
| 431 label2_ = new views::Label(l10n_util::GetString(IDS_FR_BUBBLE_SUBTEXT)); | 415 label2_ = new views::Label(l10n_util::GetString(IDS_FR_BUBBLE_SUBTEXT)); |
| 432 label2_->SetMultiLine(true); | 416 label2_->SetMultiLine(true); |
| 433 label2_->SetFont(font); | 417 label2_->SetFont(font); |
| 434 label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 418 label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 } | 532 } |
| 549 | 533 |
| 550 void FirstRunBubble::InfoBubbleClosing(InfoBubble* info_bubble, | 534 void FirstRunBubble::InfoBubbleClosing(InfoBubble* info_bubble, |
| 551 bool closed_by_escape) { | 535 bool closed_by_escape) { |
| 552 // Make sure our parent window is re-enabled. | 536 // Make sure our parent window is re-enabled. |
| 553 if (!IsWindowEnabled(GetParent())) | 537 if (!IsWindowEnabled(GetParent())) |
| 554 ::EnableWindow(GetParent(), true); | 538 ::EnableWindow(GetParent(), true); |
| 555 enable_window_method_factory_.RevokeAll(); | 539 enable_window_method_factory_.RevokeAll(); |
| 556 GetFocusManager()->RemoveFocusChangeListener(view_); | 540 GetFocusManager()->RemoveFocusChangeListener(view_); |
| 557 } | 541 } |
| OLD | NEW |