summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-12 01:28:51 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-12 01:28:51 +0000
commit9b84c98d31b6282c5a399bb92ec720560f4e6496 (patch)
tree6a98a82dfad1a054e11b5721f6c9eb4dcede2fd5 /chrome
parentaf829b7a2b2141c5a7a9f38626c91655c27797ca (diff)
downloadchromium_src-9b84c98d31b6282c5a399bb92ec720560f4e6496.zip
chromium_src-9b84c98d31b6282c5a399bb92ec720560f4e6496.tar.gz
chromium_src-9b84c98d31b6282c5a399bb92ec720560f4e6496.tar.bz2
Clean up a few things about the first run bubble code:
* Constants at top didn't need "Static" since they were already in an anonymous namespace * Move function definitions out from declarations. This avoids auto-inlining these (sometimes large) functions and makes it easier to see what a class contains. * Now that I could see the class functions, make as many as possible private. * Make sure definition order and declaration order match. This shouldn't make any functional changes. BUG=none TEST=none Review URL: http://codereview.chromium.org/202065 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26069 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/views/first_run_bubble.cc522
-rw-r--r--chrome/browser/views/first_run_bubble.h23
2 files changed, 291 insertions, 254 deletions
diff --git a/chrome/browser/views/first_run_bubble.cc b/chrome/browser/views/first_run_bubble.cc
index 257a944..a29b9ff 100644
--- a/chrome/browser/views/first_run_bubble.cc
+++ b/chrome/browser/views/first_run_bubble.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -29,18 +29,18 @@ namespace {
// How much extra padding to put around our content over what the InfoBubble
// provides.
-static const int kBubblePadding = 4;
+const int kBubblePadding = 4;
// How much extra padding to put around our content over what the InfoBubble
// provides in alternative OEM bubble.
-static const int kOEMBubblePadding = 4;
+const int kOEMBubblePadding = 4;
// Padding between parts of strings on the same line (for instance,
// "New!" and "Search from the address bar!"
-static const int kStringSeparationPadding = 2;
+const int kStringSeparationPadding = 2;
// Margin around close button.
-static const int kMarginRightOfCloseButton = 7;
+const int kMarginRightOfCloseButton = 7;
std::wstring GetDefaultSearchEngineName(Profile* profile) {
if (!profile) {
@@ -71,132 +71,26 @@ class FirstRunBubbleViewBase : public views::View,
virtual void BubbleShown() = 0;
};
+// FirstRunBubbleView ---------------------------------------------------------
+
class FirstRunBubbleView : public FirstRunBubbleViewBase {
public:
- FirstRunBubbleView(FirstRunBubble* bubble_window, Profile* profile)
- : bubble_window_(bubble_window),
- label1_(NULL),
- label2_(NULL),
- label3_(NULL),
- keep_button_(NULL),
- change_button_(NULL) {
- gfx::Font& font =
- ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont);
-
- label1_ = new views::Label(l10n_util::GetString(IDS_FR_BUBBLE_TITLE));
- label1_->SetFont(font.DeriveFont(3, gfx::Font::BOLD));
- label1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- AddChildView(label1_);
-
- gfx::Size ps = GetPreferredSize();
-
- label2_ = new views::Label(l10n_util::GetString(IDS_FR_BUBBLE_SUBTEXT));
- label2_->SetMultiLine(true);
- label2_->SetFont(font);
- label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- label2_->SizeToFit(ps.width() - kBubblePadding * 2);
- AddChildView(label2_);
-
- std::wstring question_str
- = l10n_util::GetStringF(IDS_FR_BUBBLE_QUESTION,
- GetDefaultSearchEngineName(profile));
- label3_ = new views::Label(question_str);
- label3_->SetMultiLine(true);
- label3_->SetFont(font);
- label3_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- label3_->SizeToFit(ps.width() - kBubblePadding * 2);
- AddChildView(label3_);
-
- std::wstring keep_str =
- l10n_util::GetStringF(IDS_FR_BUBBLE_OK,
- GetDefaultSearchEngineName(profile));
- keep_button_ = new views::NativeButton(this, keep_str);
- keep_button_->SetIsDefault(true);
- AddChildView(keep_button_);
-
- std::wstring change_str = l10n_util::GetString(IDS_FR_BUBBLE_CHANGE);
- change_button_ = new views::NativeButton(this, change_str);
- AddChildView(change_button_);
- }
+ FirstRunBubbleView(FirstRunBubble* bubble_window, Profile* profile);
- void BubbleShown() {
- keep_button_->RequestFocus();
- }
+ private:
+ virtual ~FirstRunBubbleView() { }
- virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
- bubble_window_->Close();
- if (change_button_ == sender) {
- Browser* browser = BrowserList::GetLastActive();
- if (browser) {
- ShowOptionsWindow(OPTIONS_PAGE_GENERAL, OPTIONS_GROUP_DEFAULT_SEARCH,
- browser->profile());
- }
- }
- }
+ // FirstRunBubbleViewBase:
+ void BubbleShown();
- virtual void Layout() {
- gfx::Size canvas = GetPreferredSize();
-
- // The multiline business that follows is dirty hacks to get around
- // bug 1325257.
- label1_->SetMultiLine(false);
- gfx::Size pref_size = label1_->GetPreferredSize();
- label1_->SetMultiLine(true);
- label1_->SizeToFit(canvas.width() - kBubblePadding * 2);
- label1_->SetBounds(kBubblePadding, kBubblePadding,
- canvas.width() - kBubblePadding * 2,
- pref_size.height());
-
- int next_v_space = label1_->y() + pref_size.height() +
- kRelatedControlSmallVerticalSpacing;
-
- pref_size = label2_->GetPreferredSize();
- label2_->SetBounds(kBubblePadding, next_v_space,
- canvas.width() - kBubblePadding * 2,
- pref_size.height());
-
- next_v_space = label2_->y() + label2_->height() +
- kPanelSubVerticalSpacing;
-
- pref_size = label3_->GetPreferredSize();
- label3_->SetBounds(kBubblePadding, next_v_space,
- canvas.width() - kBubblePadding * 2,
- pref_size.height());
-
- pref_size = change_button_->GetPreferredSize();
- change_button_->SetBounds(
- canvas.width() - pref_size.width() - kBubblePadding,
- canvas.height() - pref_size.height() - kButtonVEdgeMargin,
- pref_size.width(), pref_size.height());
-
- pref_size = keep_button_->GetPreferredSize();
- keep_button_->SetBounds(change_button_->x() - pref_size.width() -
- kRelatedButtonHSpacing, change_button_->y(),
- pref_size.width(), pref_size.height());
- }
+ // Overridden from View:
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event);
+ virtual void Layout();
+ virtual gfx::Size GetPreferredSize();
- virtual gfx::Size GetPreferredSize() {
- return gfx::Size(views::Window::GetLocalizedContentsSize(
- IDS_FIRSTRUNBUBBLE_DIALOG_WIDTH_CHARS,
- IDS_FIRSTRUNBUBBLE_DIALOG_HEIGHT_LINES));
- }
-
- virtual void FocusWillChange(View* focused_before, View* focused_now) {
- if (focused_before && focused_before->GetClassName() ==
- views::NativeButton::kViewClassName) {
- views::NativeButton* before =
- static_cast<views::NativeButton*>(focused_before);
- before->SetIsDefault(false);
- }
- if (focused_now && focused_now->GetClassName() ==
- views::NativeButton::kViewClassName) {
- views::NativeButton* after =
- static_cast<views::NativeButton*>(focused_now);
- after->SetIsDefault(true);
- }
- }
+ // FocusChangeListener:
+ virtual void FocusWillChange(View* focused_before, View* focused_now);
- private:
FirstRunBubble* bubble_window_;
views::Label* label1_;
views::Label* label2_;
@@ -207,103 +101,149 @@ class FirstRunBubbleView : public FirstRunBubbleViewBase {
DISALLOW_COPY_AND_ASSIGN(FirstRunBubbleView);
};
-class FirstRunOEMBubbleView : public FirstRunBubbleViewBase {
- public:
- FirstRunOEMBubbleView(FirstRunBubble* bubble_window, Profile* profile)
- : bubble_window_(bubble_window),
- label1_(NULL),
- label2_(NULL),
- label3_(NULL),
- close_button_(NULL) {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- gfx::Font& font = rb.GetFont(ResourceBundle::MediumFont);
-
- label1_ = new views::Label(
- l10n_util::GetString(IDS_FR_OEM_BUBBLE_TITLE_1));
- label1_->SetFont(font.DeriveFont(3, gfx::Font::BOLD));
- label1_->SetColor(SK_ColorRED);
- label1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- AddChildView(label1_);
-
- label2_ = new views::Label(
- l10n_util::GetString(IDS_FR_OEM_BUBBLE_TITLE_2));
- label2_->SetFont(font.DeriveFont(3, gfx::Font::BOLD));
- label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- AddChildView(label2_);
-
- gfx::Size ps = GetPreferredSize();
-
- label3_ = new views::Label(
- l10n_util::GetString(IDS_FR_OEM_BUBBLE_SUBTEXT));
- label3_->SetMultiLine(true);
- label3_->SetFont(font);
- label3_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- label3_->SizeToFit(ps.width() - kOEMBubblePadding * 2);
- AddChildView(label3_);
-
- close_button_ = new views::ImageButton(this);
- close_button_->SetImage(views::CustomButton::BS_NORMAL,
- rb.GetBitmapNamed(IDR_CLOSE_BAR));
- close_button_->SetImage(views::CustomButton::BS_HOT,
- rb.GetBitmapNamed(IDR_CLOSE_BAR_H));
- close_button_->SetImage(views::CustomButton::BS_PUSHED,
- rb.GetBitmapNamed(IDR_CLOSE_BAR_P));
-
- AddChildView(close_button_);
- }
+FirstRunBubbleView::FirstRunBubbleView(FirstRunBubble* bubble_window,
+ Profile* profile)
+ : bubble_window_(bubble_window),
+ label1_(NULL),
+ label2_(NULL),
+ label3_(NULL),
+ keep_button_(NULL),
+ change_button_(NULL) {
+ gfx::Font& font =
+ ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont);
+
+ label1_ = new views::Label(l10n_util::GetString(IDS_FR_BUBBLE_TITLE));
+ label1_->SetFont(font.DeriveFont(3, gfx::Font::BOLD));
+ label1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ AddChildView(label1_);
+
+ gfx::Size ps = GetPreferredSize();
+
+ label2_ = new views::Label(l10n_util::GetString(IDS_FR_BUBBLE_SUBTEXT));
+ label2_->SetMultiLine(true);
+ label2_->SetFont(font);
+ label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ label2_->SizeToFit(ps.width() - kBubblePadding * 2);
+ AddChildView(label2_);
+
+ std::wstring question_str = l10n_util::GetStringF(IDS_FR_BUBBLE_QUESTION,
+ GetDefaultSearchEngineName(profile));
+ label3_ = new views::Label(question_str);
+ label3_->SetMultiLine(true);
+ label3_->SetFont(font);
+ label3_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ label3_->SizeToFit(ps.width() - kBubblePadding * 2);
+ AddChildView(label3_);
+
+ std::wstring keep_str = l10n_util::GetStringF(IDS_FR_BUBBLE_OK,
+ GetDefaultSearchEngineName(profile));
+ keep_button_ = new views::NativeButton(this, keep_str);
+ keep_button_->SetIsDefault(true);
+ AddChildView(keep_button_);
+
+ std::wstring change_str = l10n_util::GetString(IDS_FR_BUBBLE_CHANGE);
+ change_button_ = new views::NativeButton(this, change_str);
+ AddChildView(change_button_);
+}
- void BubbleShown() {
- this->RequestFocus();
- // No button in oem_bubble to request focus.
- }
+void FirstRunBubbleView::BubbleShown() {
+ keep_button_->RequestFocus();
+}
- virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
- bubble_window_->Close();
+void FirstRunBubbleView::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ bubble_window_->Close();
+ if (change_button_ == sender) {
+ Browser* browser = BrowserList::GetLastActive();
+ if (browser) {
+ ShowOptionsWindow(OPTIONS_PAGE_GENERAL, OPTIONS_GROUP_DEFAULT_SEARCH,
+ browser->profile());
+ }
}
+}
- virtual void Layout() {
- gfx::Size canvas = GetPreferredSize();
-
- // First, draw the close button on the far right.
- gfx::Size sz = close_button_->GetPreferredSize();
- close_button_->SetBounds(canvas.width() - sz.width() -
- kMarginRightOfCloseButton,
- kOEMBubblePadding,
- sz.width(),
- sz.height());
-
- gfx::Size pref_size = label1_->GetPreferredSize();
- label1_->SetBounds(kOEMBubblePadding, kOEMBubblePadding,
- pref_size.width() + kOEMBubblePadding * 2,
- pref_size.height());
-
- pref_size = label2_->GetPreferredSize();
- label2_->SetBounds(kOEMBubblePadding * 2 + label1_->
- GetPreferredSize().width(),
- kOEMBubblePadding,
- canvas.width() - kOEMBubblePadding * 2,
- pref_size.height());
-
- int next_v_space = label1_->y() + pref_size.height() +
- kRelatedControlSmallVerticalSpacing;
-
- pref_size = label3_->GetPreferredSize();
- label3_->SetBounds(kOEMBubblePadding, next_v_space,
- canvas.width() - kOEMBubblePadding * 2,
- pref_size.height());
- }
+void FirstRunBubbleView::Layout() {
+ gfx::Size canvas = GetPreferredSize();
+
+ // The multiline business that follows is dirty hacks to get around
+ // bug 1325257.
+ label1_->SetMultiLine(false);
+ gfx::Size pref_size = label1_->GetPreferredSize();
+ label1_->SetMultiLine(true);
+ label1_->SizeToFit(canvas.width() - kBubblePadding * 2);
+ label1_->SetBounds(kBubblePadding, kBubblePadding,
+ canvas.width() - kBubblePadding * 2,
+ pref_size.height());
+
+ int next_v_space = label1_->y() + pref_size.height() +
+ kRelatedControlSmallVerticalSpacing;
+
+ pref_size = label2_->GetPreferredSize();
+ label2_->SetBounds(kBubblePadding, next_v_space,
+ canvas.width() - kBubblePadding * 2,
+ pref_size.height());
+
+ next_v_space = label2_->y() + label2_->height() +
+ kPanelSubVerticalSpacing;
+
+ pref_size = label3_->GetPreferredSize();
+ label3_->SetBounds(kBubblePadding, next_v_space,
+ canvas.width() - kBubblePadding * 2,
+ pref_size.height());
+
+ pref_size = change_button_->GetPreferredSize();
+ change_button_->SetBounds(
+ canvas.width() - pref_size.width() - kBubblePadding,
+ canvas.height() - pref_size.height() - kButtonVEdgeMargin,
+ pref_size.width(), pref_size.height());
+
+ pref_size = keep_button_->GetPreferredSize();
+ keep_button_->SetBounds(change_button_->x() - pref_size.width() -
+ kRelatedButtonHSpacing, change_button_->y(),
+ pref_size.width(), pref_size.height());
+}
- virtual gfx::Size GetPreferredSize() {
- return gfx::Size(views::Window::GetLocalizedContentsSize(
- IDS_FIRSTRUNOEMBUBBLE_DIALOG_WIDTH_CHARS,
- IDS_FIRSTRUNOEMBUBBLE_DIALOG_HEIGHT_LINES));
- }
+gfx::Size FirstRunBubbleView::GetPreferredSize() {
+ return gfx::Size(views::Window::GetLocalizedContentsSize(
+ IDS_FIRSTRUNBUBBLE_DIALOG_WIDTH_CHARS,
+ IDS_FIRSTRUNBUBBLE_DIALOG_HEIGHT_LINES));
+}
- virtual void FocusWillChange(View* focused_before, View* focused_now) {
- // No buttons in oem_bubble to register focus changes.
+void FirstRunBubbleView::FocusWillChange(View* focused_before,
+ View* focused_now) {
+ if (focused_before &&
+ (focused_before->GetClassName() == views::NativeButton::kViewClassName)) {
+ views::NativeButton* before =
+ static_cast<views::NativeButton*>(focused_before);
+ before->SetIsDefault(false);
}
+ if (focused_now &&
+ (focused_now->GetClassName() == views::NativeButton::kViewClassName)) {
+ views::NativeButton* after = static_cast<views::NativeButton*>(focused_now);
+ after->SetIsDefault(true);
+ }
+}
+
+// FirstRunOEMBubbleView ------------------------------------------------------
+
+class FirstRunOEMBubbleView : public FirstRunBubbleViewBase {
+ public:
+ FirstRunOEMBubbleView(FirstRunBubble* bubble_window, Profile* profile);
private:
+ virtual ~FirstRunOEMBubbleView() { }
+
+ // FirstRunBubbleViewBase:
+ void BubbleShown();
+
+ // Overridden from View:
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event);
+ virtual void Layout();
+ virtual gfx::Size GetPreferredSize();
+
+ // FocusChangeListener:
+ virtual void FocusWillChange(View* focused_before, View* focused_now);
+
FirstRunBubble* bubble_window_;
views::Label* label1_;
views::Label* label2_;
@@ -313,41 +253,102 @@ class FirstRunOEMBubbleView : public FirstRunBubbleViewBase {
DISALLOW_COPY_AND_ASSIGN(FirstRunOEMBubbleView);
};
-// Keep the bubble around for kLingerTime milliseconds, to prevent accidental
-// closure.
-static const int kLingerTime = 1000;
+FirstRunOEMBubbleView::FirstRunOEMBubbleView(FirstRunBubble* bubble_window,
+ Profile* profile)
+ : bubble_window_(bubble_window),
+ label1_(NULL),
+ label2_(NULL),
+ label3_(NULL),
+ close_button_(NULL) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ gfx::Font& font = rb.GetFont(ResourceBundle::MediumFont);
+
+ label1_ = new views::Label(l10n_util::GetString(IDS_FR_OEM_BUBBLE_TITLE_1));
+ label1_->SetFont(font.DeriveFont(3, gfx::Font::BOLD));
+ label1_->SetColor(SK_ColorRED);
+ label1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ AddChildView(label1_);
+
+ label2_ = new views::Label(l10n_util::GetString(IDS_FR_OEM_BUBBLE_TITLE_2));
+ label2_->SetFont(font.DeriveFont(3, gfx::Font::BOLD));
+ label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ AddChildView(label2_);
+
+ gfx::Size ps = GetPreferredSize();
+
+ label3_ = new views::Label(l10n_util::GetString(IDS_FR_OEM_BUBBLE_SUBTEXT));
+ label3_->SetMultiLine(true);
+ label3_->SetFont(font);
+ label3_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ label3_->SizeToFit(ps.width() - kOEMBubblePadding * 2);
+ AddChildView(label3_);
+
+ close_button_ = new views::ImageButton(this);
+ close_button_->SetImage(views::CustomButton::BS_NORMAL,
+ rb.GetBitmapNamed(IDR_CLOSE_BAR));
+ close_button_->SetImage(views::CustomButton::BS_HOT,
+ rb.GetBitmapNamed(IDR_CLOSE_BAR_H));
+ close_button_->SetImage(views::CustomButton::BS_PUSHED,
+ rb.GetBitmapNamed(IDR_CLOSE_BAR_P));
+
+ AddChildView(close_button_);
+}
-void FirstRunBubble::OnActivate(UINT action, BOOL minimized, HWND window) {
- // We might get re-enabled right before we are closed (sequence is: we get
- // deactivated, we call close, before we are actually closed we get
- // reactivated). Don't do the disabling of the parent in such cases.
- if (action == WA_ACTIVE && !has_been_activated_) {
- has_been_activated_ = true;
+void FirstRunOEMBubbleView::BubbleShown() {
+ RequestFocus();
+ // No button in oem_bubble to request focus.
+}
- ::EnableWindow(GetParent(), false);
+void FirstRunOEMBubbleView::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ bubble_window_->Close();
+}
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- enable_window_method_factory_.NewRunnableMethod(
- &FirstRunBubble::EnableParent),
- kLingerTime);
- }
+void FirstRunOEMBubbleView::Layout() {
+ gfx::Size canvas = GetPreferredSize();
+
+ // First, draw the close button on the far right.
+ gfx::Size sz = close_button_->GetPreferredSize();
+ close_button_->SetBounds(
+ canvas.width() - sz.width() - kMarginRightOfCloseButton,
+ kOEMBubblePadding, sz.width(), sz.height());
+
+ gfx::Size pref_size = label1_->GetPreferredSize();
+ label1_->SetBounds(kOEMBubblePadding, kOEMBubblePadding,
+ pref_size.width() + kOEMBubblePadding * 2,
+ pref_size.height());
+
+ pref_size = label2_->GetPreferredSize();
+ label2_->SetBounds(
+ kOEMBubblePadding * 2 + label1_->GetPreferredSize().width(),
+ kOEMBubblePadding, canvas.width() - kOEMBubblePadding * 2,
+ pref_size.height());
+
+ int next_v_space =
+ label1_->y() + pref_size.height() + kRelatedControlSmallVerticalSpacing;
+
+ pref_size = label3_->GetPreferredSize();
+ label3_->SetBounds(kOEMBubblePadding, next_v_space,
+ canvas.width() - kOEMBubblePadding * 2,
+ pref_size.height());
+}
- // Keep window from automatically closing until kLingerTime has passed.
- if (::IsWindowEnabled(GetParent()))
- InfoBubble::OnActivate(action, minimized, window);
+gfx::Size FirstRunOEMBubbleView::GetPreferredSize() {
+ return gfx::Size(views::Window::GetLocalizedContentsSize(
+ IDS_FIRSTRUNOEMBUBBLE_DIALOG_WIDTH_CHARS,
+ IDS_FIRSTRUNOEMBUBBLE_DIALOG_HEIGHT_LINES));
}
-void FirstRunBubble::InfoBubbleClosing(InfoBubble* info_bubble,
- bool closed_by_escape) {
- // Make sure our parent window is re-enabled.
- if (!IsWindowEnabled(GetParent()))
- ::EnableWindow(GetParent(), true);
- enable_window_method_factory_.RevokeAll();
- GetFocusManager()->RemoveFocusChangeListener(view_);
+void FirstRunOEMBubbleView::FocusWillChange(View* focused_before,
+ View* focused_now) {
+ // No buttons in oem_bubble to register focus changes.
}
+// FirstRunBubble -------------------------------------------------------------
+
// static
-FirstRunBubble* FirstRunBubble::Show(Profile* profile, views::Window* parent,
+FirstRunBubble* FirstRunBubble::Show(Profile* profile,
+ views::Window* parent,
const gfx::Rect& position_relative_to,
bool use_OEM_bubble) {
FirstRunBubble* window = new FirstRunBubble();
@@ -365,9 +366,54 @@ FirstRunBubble* FirstRunBubble::Show(Profile* profile, views::Window* parent,
return window;
}
+FirstRunBubble::FirstRunBubble()
+ : has_been_activated_(false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(enable_window_method_factory_(this)),
+ view_(NULL) {
+}
+
+FirstRunBubble::~FirstRunBubble() {
+ // We should have called RevokeAll on the method factory already.
+ DCHECK(enable_window_method_factory_.empty());
+ enable_window_method_factory_.RevokeAll();
+}
+
void FirstRunBubble::EnableParent() {
::EnableWindow(GetParent(), true);
// Reactivate the FirstRunBubble so it responds to OnActivate messages.
SetWindowPos(GetParent(), 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOREDRAW | SWP_SHOWWINDOW);
}
+
+void FirstRunBubble::OnActivate(UINT action, BOOL minimized, HWND window) {
+ // Keep the bubble around for kLingerTime milliseconds, to prevent accidental
+ // closure.
+ const int kLingerTime = 1000;
+
+ // We might get re-enabled right before we are closed (sequence is: we get
+ // deactivated, we call close, before we are actually closed we get
+ // reactivated). Don't do the disabling of the parent in such cases.
+ if (action == WA_ACTIVE && !has_been_activated_) {
+ has_been_activated_ = true;
+
+ ::EnableWindow(GetParent(), false);
+
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ enable_window_method_factory_.NewRunnableMethod(
+ &FirstRunBubble::EnableParent),
+ kLingerTime);
+ }
+
+ // Keep window from automatically closing until kLingerTime has passed.
+ if (::IsWindowEnabled(GetParent()))
+ InfoBubble::OnActivate(action, minimized, window);
+}
+
+void FirstRunBubble::InfoBubbleClosing(InfoBubble* info_bubble,
+ bool closed_by_escape) {
+ // Make sure our parent window is re-enabled.
+ if (!IsWindowEnabled(GetParent()))
+ ::EnableWindow(GetParent(), true);
+ enable_window_method_factory_.RevokeAll();
+ GetFocusManager()->RemoveFocusChangeListener(view_);
+}
diff --git a/chrome/browser/views/first_run_bubble.h b/chrome/browser/views/first_run_bubble.h
index e3c7024..81f870d 100644
--- a/chrome/browser/views/first_run_bubble.h
+++ b/chrome/browser/views/first_run_bubble.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -19,20 +19,15 @@ class FirstRunBubble : public InfoBubble,
const gfx::Rect& position_relative_to,
bool use_OEM_bubble);
- FirstRunBubble()
- : has_been_activated_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(enable_window_method_factory_(this)),
- view_(NULL) {
- }
-
- virtual ~FirstRunBubble() {
- // We should have called RevokeAll on the method factory already.
- DCHECK(enable_window_method_factory_.empty());
- enable_window_method_factory_.RevokeAll();
- }
+ private:
+ FirstRunBubble();
+ virtual ~FirstRunBubble();
void set_view(FirstRunBubbleViewBase* view) { view_ = view; }
+ // Re-enable the parent window.
+ void EnableParent();
+
#if defined(OS_WIN)
// Overridden from InfoBubble:
virtual void OnActivate(UINT action, BOOL minimized, HWND window);
@@ -43,10 +38,6 @@ class FirstRunBubble : public InfoBubble,
bool closed_by_escape);
virtual bool CloseOnEscape() { return true; }
- private:
- // Re-enable the parent window.
- void EnableParent();
-
// Whether we have already been activated.
bool has_been_activated_;