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

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

Issue 11440020: Add an outdated upgrade bubble view. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed CR comments... Created 7 years, 11 months 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/outdated_upgrade_bubble_view.cc
diff --git a/chrome/browser/ui/views/outdated_upgrade_bubble_view.cc b/chrome/browser/ui/views/outdated_upgrade_bubble_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6a642285a971bf213e4092a0747abab9336b2153
--- /dev/null
+++ b/chrome/browser/ui/views/outdated_upgrade_bubble_view.cc
@@ -0,0 +1,170 @@
+// 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/outdated_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 column holding the description label of the bubble.
+// TODO(mad): Make sure there is enought room for all languages.
Finnur 2013/01/23 10:39:17 s/enought/enough. Out of curiosity, were you plan
MAD 2013/01/23 20:57:59 Yes...
+const int kWidthOfDescriptionText = 330;
+
+const char kDownloadChromeUrl[] = "https://www.google.com/chrome/?&brand=CHWL&"
+ "utm_campaign=en&utm_source=en-et-na-us-chrome-bubble&utm_medium=et";
+
+// We subtract 2 to account for the natural button padding, and
+// to bring the separation visually in line with the row separation
Finnur 2013/01/23 10:39:17 seperation height? Do you mean separator height?
MAD 2013/01/23 20:57:59 Again, I stole this from the bookmark bubble, I to
+// height.
+const int kButtonPadding = views::kRelatedButtonHSpacing - 2;
+
+} // namespace
+
+// OutdatedUpgradeBubbleView ---------------------------------------------------
+
+OutdatedUpgradeBubbleView* OutdatedUpgradeBubbleView::upgrade_bubble_ = NULL;
+
+// static
+void OutdatedUpgradeBubbleView::ShowBubble(views::View* anchor_view,
+ Browser* browser) {
+ DCHECK(!IsShowing());
Finnur 2013/01/24 10:13:32 I kind of liked that function. It made the code mo
MAD 2013/01/24 17:29:35 Because I use it in a single place within the clas
+ upgrade_bubble_ = new OutdatedUpgradeBubbleView(anchor_view, browser);
+ views::BubbleDelegateView::CreateBubble(upgrade_bubble_);
+ upgrade_bubble_->StartFade(true);
+}
+
+// static
+bool OutdatedUpgradeBubbleView::IsShowing() {
+ return upgrade_bubble_ != NULL;
+}
+
+OutdatedUpgradeBubbleView::~OutdatedUpgradeBubbleView() {
+}
+
+views::View* OutdatedUpgradeBubbleView::GetInitiallyFocusedView() {
+ return reinstall_button_;
+}
+
+void OutdatedUpgradeBubbleView::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.
Finnur 2013/01/23 10:39:17 What is the shown state referring to? Is this from
MAD 2013/01/23 20:57:59 Done.
+ DCHECK_EQ(upgrade_bubble_, this);
+ upgrade_bubble_ = NULL;
+ }
Finnur 2013/01/23 10:39:17 nit: Weird indentation.
MAD 2013/01/23 20:57:59 Done.
+
+void OutdatedUpgradeBubbleView::Init() {
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ reinstall_button_ = new views::NativeTextButton(
+ this, l10n_util::GetStringUTF16(IDS_REINSTALL_CHROME));
+ reinstall_button_->SetIsDefault(true);
+ 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));
Finnur 2013/01/23 10:39:17 What was the reasoning behind UPDATE_MENU3 and not
MAD 2013/01/23 20:57:59 The icon was chosen by the UI designers...
+
+ GridLayout* layout = new GridLayout(this);
+ SetLayoutManager(layout);
+
+ static const int kIconTitleColumnSetId = 0;
Finnur 2013/01/23 10:39:17 Why not just const int? (same below)
MAD 2013/01/23 20:57:59 Why not static?
Finnur 2013/01/24 10:13:32 Mark Mentovai addressed this in an email thread on
MAD 2013/01/24 17:29:35 I guess I missed that thread... Thanks! Done.
+ views::ColumnSet* cs = layout->AddColumnSet(kIconTitleColumnSetId);
+
+ // 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.
+ static const int kTextColumnSetId = 1;
+ cs = layout->AddColumnSet(kTextColumnSetId);
+ cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
+ GridLayout::FIXED, kWidthOfDescriptionText, 0);
+
+ // Bottom (buttons) row.
+ static const int kButtonsColumnSetId = 2;
+ cs = layout->AddColumnSet(kButtonsColumnSetId);
+ cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing);
+ cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
+ GridLayout::USE_PREF, 0, 0);
+ cs->AddPaddingColumn(0, kButtonPadding);
+ cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
+ GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(0, kIconTitleColumnSetId);
+ layout->AddView(image_view);
+ layout->AddView(title_label);
+
+ layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
+ layout->StartRow(0, kTextColumnSetId);
+ layout->AddView(text_label);
+
+ layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
+
+ layout->StartRow(0, kButtonsColumnSetId);
+ layout->AddView(reinstall_button_);
+ layout->AddView(later_button_);
+
+ AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
+}
+
+OutdatedUpgradeBubbleView::OutdatedUpgradeBubbleView(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 OutdatedUpgradeBubbleView::ButtonPressed(
+ views::Button* sender, const ui::Event& event) {
+ if (event.IsOnlyLeftMouseButton())
+ HandleButtonPressed(sender);
+}
+
+void OutdatedUpgradeBubbleView::HandleButtonPressed(views::Button* sender) {
+ if (sender == reinstall_button_) {
+ content::RecordAction(
+ content::UserMetricsAction("OutdatedUpgradeBubble_Reinstall"));
+ chrome::AddSelectedTabWithURL(
+ browser_, GURL(kDownloadChromeUrl), content::PAGE_TRANSITION_LINK);
+ StartFade(false);
+ } else {
+ DCHECK_EQ(later_button_, sender);
+ content::RecordAction(
+ content::UserMetricsAction("OutdatedUpgradeBubble_Later"));
+ StartFade(false);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698