Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3491)

Unified Diff: chrome/browser/ui/views/first_run_bubble.cc

Issue 8265005: first run bubble using the views/bubble api. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: update Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/first_run_bubble.cc
diff --git a/chrome/browser/ui/views/first_run_bubble.cc b/chrome/browser/ui/views/first_run_bubble.cc
index 349257a66e8f143a00a279ded5b6de2ad5e62db1..70d9944ffe4bee65165494a46fcf2dfdf0d31549 100644
--- a/chrome/browser/ui/views/first_run_bubble.cc
+++ b/chrome/browser/ui/views/first_run_bubble.cc
@@ -20,80 +20,44 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "views/controls/button/image_button.h"
-#include "views/controls/button/text_button.h"
#include "views/controls/label.h"
#include "views/events/event.h"
#include "views/focus/focus_manager.h"
+#include "views/layout/fill_layout.h"
+#include "views/layout/grid_layout.h"
#include "views/layout/layout_constants.h"
+#if defined(OS_WIN) && !defined(USE_AURA)
#include "views/widget/native_widget_win.h"
+#endif
#include "views/widget/widget.h"
-namespace {
-
-// How much extra padding to put around our content over what the Bubble
-// provides.
-const int kBubblePadding = 4;
-
-// How much extra padding to put around our content over what the Bubble
-// provides in alternative OEM bubble.
-const int kOEMBubblePadding = 4;
-
-// Padding between parts of strings on the same line (for instance,
-// "New!" and "Search from the address bar!"
-const int kStringSeparationPadding = 2;
-
-// Margin around close button.
-const int kMarginRightOfCloseButton = 7;
-
-// The bubble's HWND is actually owned by the border widget, and it's the border
-// widget that's owned by the frame window the bubble is anchored to. This
-// function makes the two leaps necessary to go from the bubble contents HWND
-// to the frame HWND.
-HWND GetLogicalBubbleOwner(HWND bubble_hwnd) {
- HWND border_widget_hwnd = GetWindow(bubble_hwnd, GW_OWNER);
- return GetWindow(border_widget_hwnd, GW_OWNER);
-}
-
-} // namespace
+// FirstRunBubbleView --------------------------------------------------
-// Base class for implementations of the client view which appears inside the
-// first run bubble. It is a dialog-ish view, but is not a true dialog.
-class FirstRunBubbleViewBase : public views::View,
- public views::ButtonListener,
- public views::FocusChangeListener {
- public:
- // Called by FirstRunBubble::Show to request focus for the proper button
- // in the FirstRunBubbleView when it is shown.
- virtual void BubbleShown() = 0;
-};
-
-// FirstRunBubbleView ---------------------------------------------------------
-
-class FirstRunBubbleView : public FirstRunBubbleViewBase {
+class FirstRunBubbleView : public views::View,
msw 2011/11/03 20:25:38 It's very awesome that we've consolidated the firs
alicet1 2011/11/04 22:37:36 giving it a try.
+ public views::ButtonListener,
+ public views::FocusChangeListener {
public:
FirstRunBubbleView(FirstRunBubble* bubble_window, Profile* profile);
- private:
- virtual ~FirstRunBubbleView() {}
+ // Initialize labels used in the first run bubble.
+ void InitContents();
- // FirstRunBubbleViewBase:
- virtual void BubbleShown();
+ private:
+ virtual ~FirstRunBubbleView();
- // Overridden from View:
- virtual void ButtonPressed(views::Button* sender, const views::Event& event);
- virtual void Layout();
- virtual gfx::Size GetPreferredSize();
+ // Overrides from ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
- // FocusChangeListener:
- virtual void FocusWillChange(View* focused_before, View* focused_now);
+ // Implements views::FocusChangeListener
+ void FocusWillChange(View* focused_before, View* focused_now);
FirstRunBubble* bubble_window_;
+ Profile* profile_;
views::Label* label1_;
views::Label* label2_;
views::Label* label3_;
msw 2011/11/03 20:25:38 label3_ is no longer used, please remove it.
alicet1 2011/11/04 22:37:36 Done.
- views::NativeTextButton* change_button_;
- views::NativeTextButton* keep_button_;
- Profile* profile_;
+ views::ImageButton* close_button_;
DISALLOW_COPY_AND_ASSIGN(FirstRunBubbleView);
};
@@ -101,206 +65,28 @@ class FirstRunBubbleView : public FirstRunBubbleViewBase {
FirstRunBubbleView::FirstRunBubbleView(FirstRunBubble* bubble_window,
Profile* profile)
: bubble_window_(bubble_window),
+ profile_(profile),
label1_(NULL),
label2_(NULL),
label3_(NULL),
- keep_button_(NULL),
- change_button_(NULL),
- profile_(profile) {
- const gfx::Font& font =
- ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont);
-
- label1_ = new views::Label(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_TITLE));
msw 2011/11/03 20:25:38 Can you remove any string resources that are now u
alicet1 2011/11/04 22:37:36 I'll file a bug to clean when cleaning the gtk cas
- label1_->SetFont(font.DeriveFont(3, gfx::Font::BOLD));
- label1_->SetBackgroundColor(Bubble::kBackgroundColor);
- label1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- AddChildView(label1_);
-
- gfx::Size ps = GetPreferredSize();
-
- label2_ = new views::Label(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_SUBTEXT));
- label2_->SetMultiLine(true);
- label2_->SetFont(font);
- label2_->SetBackgroundColor(Bubble::kBackgroundColor);
- label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- label2_->SizeToFit(ps.width() - kBubblePadding * 2);
- AddChildView(label2_);
-
- string16 question_str = l10n_util::GetStringFUTF16(
- IDS_FR_BUBBLE_QUESTION,
- GetDefaultSearchEngineName(profile));
- label3_ = new views::Label(question_str);
- label3_->SetMultiLine(true);
- label3_->SetFont(font);
- label3_->SetBackgroundColor(Bubble::kBackgroundColor);
- label3_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- label3_->SizeToFit(ps.width() - kBubblePadding * 2);
- AddChildView(label3_);
-
- std::wstring keep_str = UTF16ToWide(l10n_util::GetStringFUTF16(
- IDS_FR_BUBBLE_OK,
- GetDefaultSearchEngineName(profile)));
- keep_button_ = new views::NativeTextButton(this, keep_str);
- keep_button_->SetIsDefault(true);
- AddChildView(keep_button_);
-
- std::wstring change_str =
- UTF16ToWide(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_CHANGE));
- change_button_ = new views::NativeTextButton(this, change_str);
- AddChildView(change_button_);
-}
+ close_button_(NULL) {}
-void FirstRunBubbleView::BubbleShown() {
- keep_button_->RequestFocus();
-}
-
-void FirstRunBubbleView::ButtonPressed(views::Button* sender,
- const views::Event& event) {
- UserMetrics::RecordAction(UserMetricsAction("FirstRunBubbleView_Clicked"));
- bubble_window_->set_fade_away_on_close(true);
- bubble_window_->Close();
- if (change_button_ == sender) {
- UserMetrics::RecordAction(
- UserMetricsAction("FirstRunBubbleView_ChangeButton"));
-
- Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
- if (browser) {
- browser->OpenSearchEngineOptionsDialog();
- }
- }
-}
-
-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() +
- views::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() +
- views::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() - views::kButtonVEdgeMargin,
- pref_size.width(), pref_size.height());
-
- pref_size = keep_button_->GetPreferredSize();
- keep_button_->SetBounds(change_button_->x() - pref_size.width() -
- views::kRelatedButtonHSpacing, change_button_->y(),
- pref_size.width(), pref_size.height());
-}
-
-gfx::Size FirstRunBubbleView::GetPreferredSize() {
- return gfx::Size(views::Widget::GetLocalizedContentsSize(
- IDS_FIRSTRUNBUBBLE_DIALOG_WIDTH_CHARS,
- IDS_FIRSTRUNBUBBLE_DIALOG_HEIGHT_LINES));
-}
-
-void FirstRunBubbleView::FocusWillChange(View* focused_before,
- View* focused_now) {
- if (focused_before &&
- (focused_before->GetClassName() ==
- views::NativeTextButton::kViewClassName)) {
- views::NativeTextButton* before =
- static_cast<views::NativeTextButton*>(focused_before);
- before->SetIsDefault(false);
- }
- if (focused_now &&
- (focused_now->GetClassName() ==
- views::NativeTextButton::kViewClassName)) {
- views::NativeTextButton* after =
- static_cast<views::NativeTextButton*>(focused_now);
- after->SetIsDefault(true);
- }
-}
-
-// FirstRunOEMBubbleView ------------------------------------------------------
-
-class FirstRunOEMBubbleView : public FirstRunBubbleViewBase {
- public:
- FirstRunOEMBubbleView(FirstRunBubble* bubble_window, Profile* profile);
-
- private:
- virtual ~FirstRunOEMBubbleView() { }
-
- // FirstRunBubbleViewBase:
- virtual 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_;
- views::Label* label3_;
- views::ImageButton* close_button_;
- Profile* profile_;
-
- DISALLOW_COPY_AND_ASSIGN(FirstRunOEMBubbleView);
-};
-
-FirstRunOEMBubbleView::FirstRunOEMBubbleView(FirstRunBubble* bubble_window,
- Profile* profile)
- : bubble_window_(bubble_window),
- label1_(NULL),
- label2_(NULL),
- label3_(NULL),
- close_button_(NULL),
- profile_(profile) {
+void FirstRunBubbleView::InitContents() {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- const gfx::Font& font = rb.GetFont(ResourceBundle::MediumFont);
+ const gfx::Font& original_font = rb.GetFont(ResourceBundle::MediumFont);
+ const gfx::Font& derived_font = original_font.DeriveFont(2, gfx::Font::BOLD);
- label1_ = new views::Label(
- l10n_util::GetStringUTF16(IDS_FR_OEM_BUBBLE_TITLE_1));
- label1_->SetFont(font.DeriveFont(3, gfx::Font::BOLD));
- label1_->SetBackgroundColor(Bubble::kBackgroundColor);
- label1_->SetEnabledColor(SK_ColorRED);
+ label1_ = new views::Label(l10n_util::GetStringFUTF16(
+ IDS_FR_SE_BUBBLE_TITLE,
+ GetDefaultSearchEngineName(profile_)));
+ label1_->SetFont(derived_font);
label1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- AddChildView(label1_);
label2_ = new views::Label(
- l10n_util::GetStringUTF16(IDS_FR_OEM_BUBBLE_TITLE_2));
- label2_->SetFont(font.DeriveFont(3, gfx::Font::BOLD));
- label2_->SetBackgroundColor(Bubble::kBackgroundColor);
+ l10n_util::GetStringUTF16(IDS_FR_BUBBLE_SUBTEXT));
msw 2011/11/03 20:25:38 This should fit on the line above.
alicet1 2011/11/04 22:37:36 Done.
+ label2_->SetMultiLine(true);
+ label2_->SetFont(original_font);
label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- AddChildView(label2_);
-
- gfx::Size ps = GetPreferredSize();
-
- label3_ = new views::Label(
- l10n_util::GetStringUTF16(IDS_FR_OEM_BUBBLE_SUBTEXT));
- label3_->SetMultiLine(true);
- label3_->SetFont(font);
- label3_->SetBackgroundColor(Bubble::kBackgroundColor);
- 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,
@@ -309,180 +95,54 @@ FirstRunOEMBubbleView::FirstRunOEMBubbleView(FirstRunBubble* bubble_window,
rb.GetBitmapNamed(IDR_CLOSE_BAR_H));
close_button_->SetImage(views::CustomButton::BS_PUSHED,
rb.GetBitmapNamed(IDR_CLOSE_BAR_P));
-
- AddChildView(close_button_);
-}
-
-void FirstRunOEMBubbleView::BubbleShown() {
- RequestFocus();
- // No button in oem_bubble to request focus.
-}
-
-void FirstRunOEMBubbleView::ButtonPressed(views::Button* sender,
- const views::Event& event) {
- UserMetrics::RecordAction(
- UserMetricsAction("FirstRunOEMBubbleView_Clicked"));
- bubble_window_->set_fade_away_on_close(true);
- bubble_window_->Close();
-}
-
-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() +
- views::kRelatedControlSmallVerticalSpacing;
-
- pref_size = label3_->GetPreferredSize();
- label3_->SetBounds(kOEMBubblePadding, next_v_space,
- canvas.width() - kOEMBubblePadding * 2,
- pref_size.height());
-}
-
-gfx::Size FirstRunOEMBubbleView::GetPreferredSize() {
- // Calculate width based on font and text.
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- const gfx::Font& font = rb.GetFont(
- ResourceBundle::MediumFont).DeriveFont(3, gfx::Font::BOLD);
- gfx::Size size = gfx::Size(
- ui::GetLocalizedContentsWidthForFont(
- IDS_FIRSTRUNOEMBUBBLE_DIALOG_WIDTH_CHARS, font),
- ui::GetLocalizedContentsHeightForFont(
- IDS_FIRSTRUNOEMBUBBLE_DIALOG_HEIGHT_LINES, font));
-
- // WARNING: HACK. Vista and XP calculate font size differently; this means
- // that a dialog box correctly proportioned for XP will appear too large in
- // Vista. The correct thing to do is to change font size calculations in
- // XP or Vista so that the length of a string is calculated properly. For
- // now, we force Vista to show a correctly-sized box by taking account of
- // the difference in font size calculation. The coefficient should not be
- // stored in a variable because it's a hack and should go away.
- if (views::NativeWidgetWin::IsAeroGlassEnabled()) {
- size.set_width(static_cast<int>(size.width() * 0.85));
- size.set_height(static_cast<int>(size.height() * 0.85));
- }
- return size;
-}
-
-void FirstRunOEMBubbleView::FocusWillChange(View* focused_before,
- View* focused_now) {
- // No buttons in oem_bubble to register focus changes.
-}
-
-// FirstRunMinimalBubbleView --------------------------------------------------
-// TODO(mirandac): combine FRBubbles more elegantly. http://crbug.com/41353
-
-class FirstRunMinimalBubbleView : public FirstRunBubbleViewBase {
- public:
- FirstRunMinimalBubbleView(FirstRunBubble* bubble_window, Profile* profile);
-
- private:
- virtual ~FirstRunMinimalBubbleView() { }
-
- // FirstRunBubbleViewBase:
- virtual 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_;
- Profile* profile_;
- views::Label* label1_;
- views::Label* label2_;
- DISALLOW_COPY_AND_ASSIGN(FirstRunMinimalBubbleView);
-};
+ views::GridLayout* layout = views::GridLayout::CreatePanel(this);
+ SetLayoutManager(layout);
+ // TODO(alicet): fix this after padding change goes in.
+ layout->SetInsets(9, 7, 3, 7);
-FirstRunMinimalBubbleView::FirstRunMinimalBubbleView(
- FirstRunBubble* bubble_window,
- Profile* profile)
- : bubble_window_(bubble_window),
- profile_(profile),
- label1_(NULL),
- label2_(NULL) {
- const gfx::Font& font =
- ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont);
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::LEADING,
+ views::GridLayout::LEADING, 1,
+ views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 0,
+ views::GridLayout::USE_PREF, 0, 0);
- label1_ = new views::Label(l10n_util::GetStringFUTF16(
- IDS_FR_SE_BUBBLE_TITLE,
- GetDefaultSearchEngineName(profile_)));
- label1_->SetFont(font.DeriveFont(3, gfx::Font::BOLD));
- label1_->SetBackgroundColor(Bubble::kBackgroundColor);
- label1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- AddChildView(label1_);
-
- gfx::Size ps = GetPreferredSize();
+ layout->StartRow(0, 0);
+ layout->AddView(label1_);
+ layout->AddView(close_button_, 1, 1, views::GridLayout::TRAILING,
+ views::GridLayout::LEADING);
+ layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
- label2_ = new views::Label(
- l10n_util::GetStringUTF16(IDS_FR_BUBBLE_SUBTEXT));
- label2_->SetMultiLine(true);
- label2_->SetFont(font);
- label2_->SetBackgroundColor(Bubble::kBackgroundColor);
- label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- label2_->SizeToFit(ps.width() - kBubblePadding * 2);
- AddChildView(label2_);
-}
+ layout->StartRow(0, 0);
+ layout->AddView(label2_);
+ layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
-void FirstRunMinimalBubbleView::BubbleShown() {
- RequestFocus();
+ bubble_window_->GetWidget()->GetFocusManager()->AddFocusChangeListener(this);
}
-void FirstRunMinimalBubbleView::Layout() {
- gfx::Size canvas = GetPreferredSize();
-
- // See comments in FirstRunOEMBubbleView::Layout explaining this hack.
- 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() +
- views::kRelatedControlSmallVerticalSpacing;
-
- pref_size = label2_->GetPreferredSize();
- label2_->SetBounds(kBubblePadding, next_v_space,
- canvas.width() - kBubblePadding * 2,
- pref_size.height());
+void FirstRunBubbleView::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ UserMetrics::RecordAction(
+ UserMetricsAction("FirstRunOEMBubbleView_Clicked"));
msw 2011/11/03 20:25:38 We should make sure we're recording the right metr
alicet1 2011/11/04 22:37:36 Interesting, I think this may be the only case we
+ bubble_window_->GetWidget()->Close();
}
-gfx::Size FirstRunMinimalBubbleView::GetPreferredSize() {
- return gfx::Size(views::Widget::GetLocalizedContentsSize(
- IDS_FIRSTRUN_MINIMAL_BUBBLE_DIALOG_WIDTH_CHARS,
- IDS_FIRSTRUN_MINIMAL_BUBBLE_DIALOG_HEIGHT_LINES));
+FirstRunBubbleView::~FirstRunBubbleView() {
+ if (GetFocusManager())
+ GetFocusManager()->RemoveFocusChangeListener(this);
}
-void FirstRunMinimalBubbleView::FocusWillChange(View* focused_before,
- View* focused_now) {
- // No buttons in minimal bubble to register focus changes.
+void FirstRunBubbleView::FocusWillChange(View* focused_before,
msw 2011/11/03 20:25:38 This is unfortunately wrong, but luckily you can r
alicet1 2011/11/04 22:37:36 Done.
+ View* focused_now) {
+ // TODO(alicet): this should be in the DidChangeFocus() call
+ // when that is checked in.
+ if (!Contains(focused_now)) {
+ bubble_window_->GetWidget()->Close();
+ }
}
-
// FirstRunBubble -------------------------------------------------------------
// static
@@ -490,60 +150,57 @@ FirstRunBubble* FirstRunBubble::Show(
Profile* profile,
views::Widget* parent,
const gfx::Rect& position_relative_to,
- views::BubbleBorder::ArrowLocation arrow_location,
- FirstRun::BubbleType bubble_type) {
- FirstRunBubble* bubble = new FirstRunBubble();
- FirstRunBubbleViewBase* view = NULL;
-
- switch (bubble_type) {
- case FirstRun::OEM_BUBBLE:
- view = new FirstRunOEMBubbleView(bubble, profile);
- break;
- case FirstRun::LARGE_BUBBLE:
- view = new FirstRunBubbleView(bubble, profile);
- break;
- case FirstRun::MINIMAL_BUBBLE:
- view = new FirstRunMinimalBubbleView(bubble, profile);
- break;
- default:
- NOTREACHED();
- }
- bubble->set_view(view);
- bubble->InitBubble(
- parent, position_relative_to, arrow_location, view, bubble);
- bubble->GetWidget()->GetFocusManager()->AddFocusChangeListener(view);
- view->BubbleShown();
- return bubble;
+ views::BubbleBorder::ArrowLocation arrow_location) {
+ FirstRunBubble* delegate =
+ new FirstRunBubble(profile,
+ parent,
+ position_relative_to,
+ arrow_location);
+ views::BubbleDelegateView::CreateBubble(delegate, parent);
+ delegate->StartFade(true);
+ return delegate;
}
-FirstRunBubble::FirstRunBubble()
- : has_been_activated_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(enable_window_method_factory_(this)),
- view_(NULL) {
+void FirstRunBubble::Init() {
+ SetLayoutManager(new views::FillLayout());
+ view = new FirstRunBubbleView(this, profile_);
+ view->InitContents();
+ AddChildView(view);
+}
+
+FirstRunBubble::FirstRunBubble(
+ Profile* profile,
+ views::Widget* parent,
+ const gfx::Rect& position_relative_to,
+ views::BubbleBorder::ArrowLocation arrow_location)
+ : views::BubbleDelegateView(position_relative_to.origin(),
+ arrow_location,
+ SK_ColorWHITE),
+ profile_(profile),
+ parent_(parent),
+ has_been_activated_(false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(enable_window_method_factory_(this)) {
}
FirstRunBubble::~FirstRunBubble() {
enable_window_method_factory_.InvalidateWeakPtrs();
- GetWidget()->GetFocusManager()->RemoveFocusChangeListener(view_);
}
+#if defined(OS_WIN) && !defined(USE_AURA)
+// TODO(alicet): do I still need this block. Must check on glass-frame mode.
msw 2011/11/03 20:25:38 It looks like this code is meant to prevent the bu
Miranda Callahan 2011/11/03 20:59:39 Yes, that's indeed what's happening; on Windows, t
Miranda Callahan 2011/11/03 21:04:07 Please see this CL, and accompanying comments for
msw 2011/11/03 21:46:24 Okay, if that's the case and we still have this my
alicet1 2011/11/04 22:37:36 ok, I'll work on that.
void FirstRunBubble::EnableParent() {
::EnableWindow(GetParent(), true);
// The EnableWindow() call above causes the parent to become active, which
// resets the flag set by Bubble's call to DisableInactiveRendering(), so we
// have to call it again before activating the bubble to prevent the parent
// window from rendering inactive.
- // TODO(beng): this only works in custom-frame mode, not glass-frame mode.
- HWND bubble_owner = GetLogicalBubbleOwner(GetNativeView());
- views::Widget* parent = views::Widget::GetWidgetForNativeView(bubble_owner);
- if (parent)
- parent->DisableInactiveRendering();
+ if (parent_)
+ parent_->DisableInactiveRendering();
// Reactivate the FirstRunBubble so it responds to OnActivate messages.
SetWindowPos(GetParent(), 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOREDRAW | SWP_SHOWWINDOW);
}
-#if defined(OS_WIN) && !defined(USE_AURA)
void FirstRunBubble::OnActivate(UINT action, BOOL minimized, HWND window) {
// Keep the bubble around for kLingerTime milliseconds, to prevent accidental
// closure.
@@ -571,8 +228,8 @@ void FirstRunBubble::OnActivate(UINT action, BOOL minimized, HWND window) {
}
#endif
-void FirstRunBubble::BubbleClosing(Bubble* bubble, bool closed_by_escape) {
+void FirstRunBubble::WindowClosing() {
// Make sure our parent window is re-enabled.
- if (!IsWindowEnabled(GetParent()))
- ::EnableWindow(GetParent(), true);
+ if (parent_ && parent_->GetNativeView())
+ GetFocusManager()->FocusNativeView(parent_->GetNativeView());
Ben Goodger (Google) 2011/11/03 20:14:07 Not your fault, just an observation: the comment h
msw 2011/11/03 20:25:38 This also shouldn't be necessary, or if it is, it'
alicet1 2011/11/04 22:37:36 removed.
}

Powered by Google App Engine
This is Rietveld 408576698