Chromium Code Reviews| Index: chrome/browser/ui/views/upgrade_bubble_view.cc |
| diff --git a/chrome/browser/ui/views/upgrade_bubble_view.cc b/chrome/browser/ui/views/upgrade_bubble_view.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..089751b544cf411488c26481a8d9831cf0406c62 |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/upgrade_bubble_view.cc |
| @@ -0,0 +1,179 @@ |
| +// Copyright (c) 2012 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. |
| + |
| +#include "chrome/browser/ui/views/upgrade_bubble_view.h" |
| + |
| +#include "chrome/browser/ui/browser_tabstrip.h" |
| +#include "content/public/browser/user_metrics.h" |
| +#include "googleurl/src/gurl.h" |
| +#include "grit/generated_resources.h" |
| +#include "grit/theme_resources.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| +#include "ui/views/controls/button/text_button.h" |
| +#include "ui/views/controls/image_view.h" |
| +#include "ui/views/controls/label.h" |
| +#include "ui/views/layout/grid_layout.h" |
| +#include "ui/views/layout/layout_constants.h" |
| +#include "ui/views/widget/widget.h" |
| + |
| +using views::GridLayout; |
| + |
| +namespace { |
| + |
| +// Fixed with of the text label with the description of the bubble. |
|
Finnur
2012/12/06 19:53:16
nit: Technically, this is the fixed width of the _
MAD
2013/01/22 15:18:29
Done.
|
| +const int kWidthOfDescriptionText = 330; |
|
Finnur
2012/12/06 19:53:16
I don't know how much room there is to spare, but
MAD
2013/01/22 15:18:29
Good point, I will leave a TODO in the mean time.
|
| + |
| +const char kDownloadChromeUrl[] = "https://www.google.com/chrome/?&brand=CHWL&" |
| + "utm_campaign=en&utm_source=en-et-na-us-chrome-bubble&utm_medium=et"; |
| + |
| +} // namespace |
| + |
| +// UpgradeBubbleView --------------------------------------------------------- |
| + |
| +UpgradeBubbleView* UpgradeBubbleView::upgrade_bubble_ = NULL; |
| + |
| +// static |
| +void UpgradeBubbleView::ShowBubble(views::View* anchor_view, Browser* browser) { |
| + if (IsShowing()) |
| + return; |
|
Finnur
2012/12/06 19:53:16
Under what conditions does this happen?
MAD
2013/01/22 15:18:29
Again, stolen from bookmark bar, but the IsShowing
|
| + |
| + upgrade_bubble_ = new UpgradeBubbleView(anchor_view, browser); |
| + views::BubbleDelegateView::CreateBubble(upgrade_bubble_); |
| + upgrade_bubble_->StartFade(true); |
| +} |
| + |
| +// static |
| +bool UpgradeBubbleView::IsShowing() { |
| + return upgrade_bubble_ != NULL; |
| +} |
| + |
| +UpgradeBubbleView::~UpgradeBubbleView() { |
| +} |
| + |
| +views::View* UpgradeBubbleView::GetInitiallyFocusedView() { |
| + return reinstall_button_; |
| +} |
| + |
| +void UpgradeBubbleView::WindowClosing() { |
| + // We have to reset |bubble_| here, not in our destructor, because we'll be |
| + // destroyed asynchronously and the shown state will be checked before then. |
| + DCHECK_EQ(upgrade_bubble_, this); |
| + upgrade_bubble_ = NULL; |
| + } |
| + |
| +bool UpgradeBubbleView::AcceleratorPressed( |
| + const ui::Accelerator& accelerator) { |
| + if (accelerator.key_code() == ui::VKEY_RETURN) { |
| + if (reinstall_button_->HasFocus()) |
| + HandleButtonPressed(reinstall_button_); |
| + else |
| + HandleButtonPressed(later_button_); |
|
Finnur
2012/12/06 19:53:16
I maybe totally off here, but I don't remember hav
MAD
2013/01/22 15:18:29
Again, stolen from bookmark bar... But you are rig
Finnur
2013/01/23 10:39:17
Again, check with the owner. Maybe they put this i
|
| + return true; |
| + } else if (accelerator.key_code() == ui::VKEY_ESCAPE) { |
| + HandleButtonPressed(later_button_); |
| + return true; |
| + } |
| + |
| + return BubbleDelegateView::AcceleratorPressed(accelerator); |
| +} |
| + |
| +void UpgradeBubbleView::Init() { |
| + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| + reinstall_button_ = new views::NativeTextButton( |
| + this, l10n_util::GetStringUTF16(IDS_REINSTALL_CHROME)); |
| + reinstall_button_->SetIsDefault(true); |
|
Finnur
2012/12/06 19:53:16
Just wondering... Reinstall currently just takes y
MAD
2013/01/22 15:18:29
The plan is to always go to an install page not do
|
| + reinstall_button_->SetFont(rb.GetFont(ui::ResourceBundle::BoldFont)); |
| + |
| + later_button_ = new views::NativeTextButton( |
| + this, l10n_util::GetStringUTF16(IDS_LATER)); |
| + |
| + views::Label* title_label = new views::Label( |
| + l10n_util::GetStringUTF16(IDS_UPGRADE_BUBBLE_TITLE)); |
| + title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
| + title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + |
| + views::Label* text_label = new views::Label( |
| + l10n_util::GetStringUTF16(IDS_UPGRADE_BUBBLE_TEXT)); |
| + text_label->SetMultiLine(true); |
| + text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + |
| + views::ImageView* image_view = new views::ImageView(); |
| + image_view->SetImage(rb.GetImageSkiaNamed(IDR_UPDATE_MENU3)); |
| + |
| + GridLayout* layout = new GridLayout(this); |
| + SetLayoutManager(layout); |
| + |
| + views::ColumnSet* cs = layout->AddColumnSet(0); |
| + |
| + // Top (icon-title) row. |
| + cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| + GridLayout::USE_PREF, 0, 0); |
| + cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); |
| + cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, |
| + GridLayout::USE_PREF, 0, 0); |
| + cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); |
| + |
| + // Middle (text) row. |
| + cs = layout->AddColumnSet(1); |
| + cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| + GridLayout::FIXED, kWidthOfDescriptionText, 0); |
| + |
| + // Bottom (buttons) row. |
| + cs = layout->AddColumnSet(2); |
| + cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); |
| + cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
| + GridLayout::USE_PREF, 0, 0); |
| + // We subtract 2 to account for the natural button padding, and |
| + // to bring the separation visually in line with the row separation |
| + // height. |
| + cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2); |
|
Finnur
2012/12/06 19:53:16
nit: Make a constant at top and move the comment u
MAD
2013/01/22 15:18:29
Done.
|
| + cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
| + GridLayout::USE_PREF, 0, 0); |
| + |
| + layout->StartRow(0, 0); |
| + layout->AddView(image_view); |
| + layout->AddView(title_label); |
| + |
| + layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
| + layout->StartRow(0, 1); |
| + layout->AddView(text_label); |
| + |
| + layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| + |
| + layout->StartRow(0, 2); |
|
Finnur
2012/12/06 19:53:16
You should make local consts with descriptive name
MAD
2013/01/22 15:18:29
Done.
|
| + layout->AddView(reinstall_button_); |
| + layout->AddView(later_button_); |
| + |
| + AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); |
| +} |
| + |
| +UpgradeBubbleView::UpgradeBubbleView(views::View* anchor_view, Browser* browser) |
| + : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
| + reinstall_button_(NULL), |
| + later_button_(NULL), |
| + browser_(browser) { |
| + // Compensate for built-in vertical padding in the anchor view's image. |
| + set_anchor_insets(gfx::Insets(5, 0, 5, 0)); |
| +} |
| + |
| +void UpgradeBubbleView::ButtonPressed( |
| + views::Button* sender, const ui::Event& event) { |
| + HandleButtonPressed(sender); |
|
Finnur
2012/12/06 19:53:16
I would probably say we should not be clicking the
MAD
2013/01/22 15:18:29
CriticalNotificationBubbleView::ButtonPressed does
Finnur
2013/01/23 10:39:17
That would be good, thank you (can be another CL).
|
| +} |
| + |
| +void UpgradeBubbleView::HandleButtonPressed(views::Button* sender) { |
| + if (sender == reinstall_button_) { |
| + content::RecordAction( |
| + content::UserMetricsAction("UpgradeBubble_Reinstall")); |
|
Finnur
2012/12/06 19:53:16
Same comment applies here (this is bit too general
MAD
2013/01/22 15:18:29
Done.
|
| + chrome::AddSelectedTabWithURL( |
| + browser_, GURL(kDownloadChromeUrl), content::PAGE_TRANSITION_LINK); |
| + StartFade(false); |
| + } else { |
| + DCHECK_EQ(later_button_, sender); |
| + content::RecordAction( |
| + content::UserMetricsAction("UpgradeBubble_Later")); |
|
Finnur
2012/12/06 19:53:16
Ditto.
MAD
2013/01/22 15:18:29
Done.
|
| + StartFade(false); |
| + } |
| +} |