Chromium Code Reviews| 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..ba358f817d33dac1681c1731603b3b84b30a6024 100644 |
| --- a/chrome/browser/ui/views/first_run_bubble.cc |
| +++ b/chrome/browser/ui/views/first_run_bubble.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/bind.h" |
| #include "base/utf_string_conversions.h" |
| +#include "chrome/browser/ui/views/bubble/bubble.h" // for kBackgroundColor |
| #include "chrome/browser/first_run/first_run.h" |
| #include "chrome/browser/search_engines/util.h" |
| #include "chrome/browser/ui/browser.h" |
| @@ -19,13 +20,17 @@ |
| #include "ui/base/l10n/l10n_font_util.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/resource/resource_bundle.h" |
| +#include "views/bubble/bubble_view.h" |
|
msw
2011/10/20 19:17:50
remove to merge with the latest bubble changes.
alicet1
2011/10/21 19:13:16
Done.
|
| #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/layout_constants.h" |
| +#if defined(OS_WIN) && !defined(USE_AURA) |
| #include "views/widget/native_widget_win.h" |
| +#endif |
| #include "views/widget/widget.h" |
| namespace { |
| @@ -38,22 +43,9 @@ const int kBubblePadding = 4; |
| // 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 |
| // Base class for implementations of the client view which appears inside the |
| @@ -64,7 +56,7 @@ class FirstRunBubbleViewBase : public views::View, |
| public: |
| // Called by FirstRunBubble::Show to request focus for the proper button |
| // in the FirstRunBubbleView when it is shown. |
| - virtual void BubbleShown() = 0; |
| + virtual void BubbleShown() = 0; |
|
msw
2011/10/20 19:17:50
remove extra space
alicet1
2011/10/21 19:13:16
Done.
|
| }; |
| // FirstRunBubbleView --------------------------------------------------------- |
| @@ -72,17 +64,16 @@ class FirstRunBubbleViewBase : public views::View, |
| class FirstRunBubbleView : public FirstRunBubbleViewBase { |
| public: |
| FirstRunBubbleView(FirstRunBubble* bubble_window, Profile* profile); |
| + // Override from FirstRunBubbleViewBase: |
|
msw
2011/10/20 19:17:50
Add a blank line above this comment.
alicet1
2011/10/21 19:13:16
Done.
|
| + void BubbleShown(); |
| private: |
| - virtual ~FirstRunBubbleView() {} |
| - |
| - // FirstRunBubbleViewBase: |
| - virtual void BubbleShown(); |
| + virtual ~FirstRunBubbleView(); |
| // Overridden from View: |
| virtual void ButtonPressed(views::Button* sender, const views::Event& event); |
| - virtual void Layout(); |
| virtual gfx::Size GetPreferredSize(); |
| + virtual void Layout(); |
| // FocusChangeListener: |
| virtual void FocusWillChange(View* focused_before, View* focused_now); |
| @@ -91,8 +82,8 @@ class FirstRunBubbleView : public FirstRunBubbleViewBase { |
| views::Label* label1_; |
| views::Label* label2_; |
| views::Label* label3_; |
| - views::NativeTextButton* change_button_; |
| views::NativeTextButton* keep_button_; |
| + views::NativeTextButton* change_button_; |
| Profile* profile_; |
| DISALLOW_COPY_AND_ASSIGN(FirstRunBubbleView); |
| @@ -137,28 +128,27 @@ FirstRunBubbleView::FirstRunBubbleView(FirstRunBubble* bubble_window, |
| label3_->SizeToFit(ps.width() - kBubblePadding * 2); |
| AddChildView(label3_); |
| - std::wstring keep_str = UTF16ToWide(l10n_util::GetStringFUTF16( |
| + string16 keep_str = l10n_util::GetStringFUTF16( |
| IDS_FR_BUBBLE_OK, |
| - GetDefaultSearchEngineName(profile))); |
| + 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)); |
| + string16 change_str = l10n_util::GetStringUTF16(IDS_FR_BUBBLE_CHANGE); |
| change_button_ = new views::NativeTextButton(this, change_str); |
| AddChildView(change_button_); |
| } |
| -void FirstRunBubbleView::BubbleShown() { |
| - keep_button_->RequestFocus(); |
| +FirstRunBubbleView::~FirstRunBubbleView() { |
| + GetFocusManager()->RemoveFocusChangeListener(this); |
|
msw
2011/10/20 19:17:50
This belongs in ~FirstRunBubbleViewBase.
alicet1
2011/10/21 19:13:16
Done.
|
| } |
| 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(); |
| + // Fades out. |
| + GetWidget()->client_view()->AsBubbleView()->StartFade(false); |
|
msw
2011/10/20 19:17:50
You can just call StartFade on a BubbleDelegateVie
alicet1
2011/10/21 19:13:16
Done.
|
| if (change_button_ == sender) { |
| UserMetrics::RecordAction( |
| UserMetricsAction("FirstRunBubbleView_ChangeButton")); |
| @@ -168,6 +158,11 @@ void FirstRunBubbleView::ButtonPressed(views::Button* sender, |
| browser->OpenSearchEngineOptionsDialog(); |
| } |
| } |
| + GetWidget()->Close(); |
| +} |
| + |
| +void FirstRunBubbleView::BubbleShown() { |
| + keep_button_->RequestFocus(); |
|
msw
2011/10/20 19:17:50
Couldn't this be accomplished by overriding GetIni
alicet1
2011/10/21 19:13:16
if this is a delegate, then it would have GetIniti
|
| } |
| void FirstRunBubbleView::Layout() { |
| @@ -241,16 +236,15 @@ class FirstRunOEMBubbleView : public FirstRunBubbleViewBase { |
| public: |
| FirstRunOEMBubbleView(FirstRunBubble* bubble_window, Profile* profile); |
| + // Override from FirstRunBubbleViewBase: |
| + void BubbleShown(); |
| private: |
|
msw
2011/10/20 19:17:50
add a blank line above private.
alicet1
2011/10/21 19:13:16
Done.
|
| - virtual ~FirstRunOEMBubbleView() { } |
| - |
| - // FirstRunBubbleViewBase: |
| - virtual void BubbleShown(); |
| + virtual ~FirstRunOEMBubbleView(); |
| // Overridden from View: |
| virtual void ButtonPressed(views::Button* sender, const views::Event& event); |
| - virtual void Layout(); |
| virtual gfx::Size GetPreferredSize(); |
| + virtual void Layout(); |
| // FocusChangeListener: |
| virtual void FocusWillChange(View* focused_before, View* focused_now); |
| @@ -315,15 +309,18 @@ FirstRunOEMBubbleView::FirstRunOEMBubbleView(FirstRunBubble* bubble_window, |
| void FirstRunOEMBubbleView::BubbleShown() { |
| RequestFocus(); |
| - // No button in oem_bubble to request focus. |
| +} |
| + |
| +FirstRunOEMBubbleView::~FirstRunOEMBubbleView() { |
| + GetFocusManager()->RemoveFocusChangeListener(this); |
|
msw
2011/10/20 19:17:50
Ditto, this belongs in ~FirstRunBubbleViewBase.
alicet1
2011/10/21 19:13:16
Done.
|
| } |
| 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(); |
| + GetWidget()->client_view()->AsBubbleView()->StartFade(/*fade_in=*/false); |
|
msw
2011/10/20 19:17:50
Ditto on BubbleDelegateView::StartFade comment, al
alicet1
2011/10/21 19:13:16
Done.
|
| + GetWidget()->Close(); |
| } |
| void FirstRunOEMBubbleView::Layout() { |
| @@ -366,7 +363,7 @@ gfx::Size FirstRunOEMBubbleView::GetPreferredSize() { |
| IDS_FIRSTRUNOEMBUBBLE_DIALOG_WIDTH_CHARS, font), |
| ui::GetLocalizedContentsHeightForFont( |
| IDS_FIRSTRUNOEMBUBBLE_DIALOG_HEIGHT_LINES, font)); |
| - |
| +#if defined(OS_WIN) && !defined(USE_AURA) |
| // 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 |
| @@ -378,6 +375,7 @@ gfx::Size FirstRunOEMBubbleView::GetPreferredSize() { |
| size.set_width(static_cast<int>(size.width() * 0.85)); |
| size.set_height(static_cast<int>(size.height() * 0.85)); |
| } |
| +#endif |
| return size; |
| } |
| @@ -393,17 +391,17 @@ class FirstRunMinimalBubbleView : public FirstRunBubbleViewBase { |
| public: |
| FirstRunMinimalBubbleView(FirstRunBubble* bubble_window, Profile* profile); |
| - private: |
| - virtual ~FirstRunMinimalBubbleView() { } |
| + // Override from FirstRunBubbleViewBase: |
|
msw
2011/10/20 19:17:50
Can you go through and make sure all the override
alicet1
2011/10/21 19:13:16
Done.
|
| + void BubbleShown(); |
| - // FirstRunBubbleViewBase: |
| - virtual void BubbleShown(); |
| + private: |
| + virtual ~FirstRunMinimalBubbleView(); |
| // Overridden from View: |
| virtual void ButtonPressed(views::Button* sender, |
| const views::Event& event) { } |
| - virtual void Layout(); |
| virtual gfx::Size GetPreferredSize(); |
| + virtual void Layout(); |
| // FocusChangeListener: |
| virtual void FocusWillChange(View* focused_before, View* focused_now); |
| @@ -446,6 +444,10 @@ FirstRunMinimalBubbleView::FirstRunMinimalBubbleView( |
| AddChildView(label2_); |
| } |
| +FirstRunMinimalBubbleView::~FirstRunMinimalBubbleView() { |
| + GetFocusManager()->RemoveFocusChangeListener(this); |
|
msw
2011/10/20 19:17:50
Ditto, this belongs in ~FirstRunBubbleViewBase.
alicet1
2011/10/21 19:13:16
Done.
|
| +} |
| + |
| void FirstRunMinimalBubbleView::BubbleShown() { |
| RequestFocus(); |
| } |
| @@ -486,47 +488,70 @@ void FirstRunMinimalBubbleView::FocusWillChange(View* focused_before, |
| // FirstRunBubble ------------------------------------------------------------- |
| // static |
| -FirstRunBubble* FirstRunBubble::Show( |
| +views::Widget* 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; |
| + FirstRunBubble* delegate = |
| + new FirstRunBubble(profile, |
| + parent, |
| + position_relative_to, |
| + arrow_location, |
| + bubble_type); |
| + views::Widget* widget = |
| + views::BubbleDelegateView::CreateBubble(delegate, parent); |
| + // StartFade and show. |
| + widget->client_view()->AsBubbleView()->StartFade(/*fade_in=*/true); |
|
msw
2011/10/20 19:17:50
Ditto on BubbleDelegateView::StartFade comment, al
alicet1
2011/10/21 19:13:16
Done.
|
| + return widget; |
| +} |
| - switch (bubble_type) { |
| +void FirstRunBubble::Init() { |
| + SetLayoutManager(new views::FillLayout()); |
| + FirstRunBubbleViewBase* view = NULL; |
| + switch (bubble_type_) { |
| case FirstRun::OEM_BUBBLE: |
| - view = new FirstRunOEMBubbleView(bubble, profile); |
| + view = new FirstRunOEMBubbleView(this, profile_); |
| break; |
| case FirstRun::LARGE_BUBBLE: |
| - view = new FirstRunBubbleView(bubble, profile); |
| + view = new FirstRunBubbleView(this, profile_); |
| break; |
| case FirstRun::MINIMAL_BUBBLE: |
| - view = new FirstRunMinimalBubbleView(bubble, profile); |
| + view = new FirstRunMinimalBubbleView(this, profile_); |
| break; |
| default: |
| NOTREACHED(); |
| } |
| - bubble->set_view(view); |
| - bubble->InitBubble( |
| - parent, position_relative_to, arrow_location, view, bubble); |
| - bubble->GetWidget()->GetFocusManager()->AddFocusChangeListener(view); |
| + AddChildView(view); |
| + parent_->GetFocusManager()->AddFocusChangeListener(view); |
|
msw
2011/10/20 19:17:50
I think you can just call GetFocusManager on this
alicet1
2011/10/21 19:13:16
Init() is called before we have a widget for this
|
| view->BubbleShown(); |
| - return bubble; |
| } |
| -FirstRunBubble::FirstRunBubble() |
| - : has_been_activated_(false), |
| - ALLOW_THIS_IN_INITIALIZER_LIST(enable_window_method_factory_(this)), |
| - view_(NULL) { |
| +FirstRunBubble::FirstRunBubble( |
| + Profile* profile, |
| + views::Widget* parent, |
| + const gfx::Rect& position_relative_to, |
| + views::BubbleBorder::ArrowLocation arrow_location, |
| + FirstRun::BubbleType bubble_type) |
| + : profile_(profile), |
|
msw
2011/10/20 19:17:50
You can use the new BubbleDelegateView ctor here t
alicet1
2011/10/21 19:13:16
Done.
|
| + parent_(parent), |
| + position_relative_to_(position_relative_to), |
| + arrow_location_(arrow_location), |
| + bubble_type_(bubble_type), |
| + 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_); |
| } |
| +gfx::Point FirstRunBubble::GetAnchorPoint() const { |
| + return position_relative_to_.origin(); |
| +} |
| + |
| +#if defined(OS_WIN) && !defined(USE_AURA) |
| void FirstRunBubble::EnableParent() { |
| ::EnableWindow(GetParent(), true); |
| // The EnableWindow() call above causes the parent to become active, which |
| @@ -534,16 +559,13 @@ void FirstRunBubble::EnableParent() { |
| // 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 +593,7 @@ 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); |
| + parent_->GetRootView()->SetEnabled(true); |
|
msw
2011/10/20 19:17:50
I don't think this is right... perhaps try the Foc
alicet1
2011/10/21 19:13:16
I'm not sure why we need to explicitly enable/set
|
| } |