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

Side by Side 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: Sync'd to ToT Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h"
6
7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/browser_tabstrip.h"
Ben Goodger (Google) 2013/02/13 22:34:51 ... then you could remove these two #includes.
MAD 2013/02/14 14:04:06 Done.
10 #include "chrome/browser/upgrade_detector.h"
11 #include "content/public/browser/user_metrics.h"
12 #include "googleurl/src/gurl.h"
13 #include "grit/chromium_strings.h"
14 #include "grit/generated_resources.h"
15 #include "grit/theme_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/views/controls/button/text_button.h"
19 #include "ui/views/controls/image_view.h"
20 #include "ui/views/controls/label.h"
21 #include "ui/views/layout/grid_layout.h"
22 #include "ui/views/layout/layout_constants.h"
23 #include "ui/views/widget/widget.h"
24
25 using views::GridLayout;
26
27 namespace {
28
29 // Fixed width of the column holding the description label of the bubble.
30 // TODO(mad): Make sure there is enough room for all languages.
31 const int kWidthOfDescriptionText = 330;
32
33 // We subtract 2 to account for the natural button padding, and
34 // to bring the separation visually in line with the row separation
35 // height.
36 const int kButtonPadding = views::kRelatedButtonHSpacing - 2;
37
38 // The URL to be used to re-install Chrome when auto-update failed for too long.
39 const char kDownloadChromeUrl[] = "https://www.google.com/chrome/?&brand=CHWL"
40 "&utm_campaign=en&utm_source=en-et-na-us-chrome-bubble&utm_medium=et";
41
42 // The maximum number of ignored bubble we track in the NumLaterPerReinstall
43 // histogram.
44 const int kMaxIgnored = 50;
45 // The number of buckets we want the NumLaterPerReinstall histogram to use.
46 const int kNumIgnoredBuckets = 5;
47
48 } // namespace
49
50 // OutdatedUpgradeBubbleView ---------------------------------------------------
51
52 OutdatedUpgradeBubbleView* OutdatedUpgradeBubbleView::upgrade_bubble_ = NULL;
53 int OutdatedUpgradeBubbleView::num_ignored_bubbles_ = 0;
54
55 // static
56 void OutdatedUpgradeBubbleView::ShowBubble(views::View* anchor_view,
57 Browser* browser) {
58 if (IsShowing())
59 return;
60 upgrade_bubble_ = new OutdatedUpgradeBubbleView(anchor_view, browser);
61 views::BubbleDelegateView::CreateBubble(upgrade_bubble_);
62 upgrade_bubble_->StartFade(true);
63 }
64
65 OutdatedUpgradeBubbleView::~OutdatedUpgradeBubbleView() {
66 if (!chose_to_reinstall_ && num_ignored_bubbles_ < kMaxIgnored)
67 ++num_ignored_bubbles_;
68 }
69
70 views::View* OutdatedUpgradeBubbleView::GetInitiallyFocusedView() {
71 return reinstall_button_;
72 }
73
74 void OutdatedUpgradeBubbleView::WindowClosing() {
75 // Reset |upgrade_bubble_| here, not in destructor, because destruction is
76 // asynchronous and ShowBubble may be called before full destruction and
77 // would attempt to show a bubble that is closing.
78 DCHECK_EQ(upgrade_bubble_, this);
79 upgrade_bubble_ = NULL;
80 }
81
82 void OutdatedUpgradeBubbleView::Init() {
83 string16 product_name(l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
84 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
85 reinstall_button_ = new views::NativeTextButton(
86 this, l10n_util::GetStringFUTF16(IDS_REINSTALL_APP, product_name));
87 reinstall_button_->SetIsDefault(true);
88 reinstall_button_->SetFont(rb.GetFont(ui::ResourceBundle::BoldFont));
89
90 later_button_ = new views::NativeTextButton(
91 this, l10n_util::GetStringUTF16(IDS_LATER));
92
93 views::Label* title_label = new views::Label(
94 l10n_util::GetStringFUTF16(IDS_UPGRADE_BUBBLE_TITLE, product_name));
95 title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
96 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
97
98 views::Label* text_label = new views::Label(
99 l10n_util::GetStringFUTF16(IDS_UPGRADE_BUBBLE_TEXT, product_name));
100 text_label->SetMultiLine(true);
101 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
102
103 views::ImageView* image_view = new views::ImageView();
104 image_view->SetImage(rb.GetImageSkiaNamed(IDR_UPDATE_MENU3));
105
106 GridLayout* layout = new GridLayout(this);
107 SetLayoutManager(layout);
108
109 const int kIconTitleColumnSetId = 0;
110 views::ColumnSet* cs = layout->AddColumnSet(kIconTitleColumnSetId);
111
112 // Top (icon-title) row.
113 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
114 GridLayout::USE_PREF, 0, 0);
115 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
116 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
117 GridLayout::USE_PREF, 0, 0);
118 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
119
120 // Middle (text) row.
121 const int kTextColumnSetId = 1;
122 cs = layout->AddColumnSet(kTextColumnSetId);
123 cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
124 GridLayout::FIXED, kWidthOfDescriptionText, 0);
125
126 // Bottom (buttons) row.
127 const int kButtonsColumnSetId = 2;
128 cs = layout->AddColumnSet(kButtonsColumnSetId);
129 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing);
130 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
131 GridLayout::USE_PREF, 0, 0);
132 cs->AddPaddingColumn(0, kButtonPadding);
133 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
134 GridLayout::USE_PREF, 0, 0);
135
136 layout->StartRow(0, kIconTitleColumnSetId);
137 layout->AddView(image_view);
138 layout->AddView(title_label);
139
140 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
141 layout->StartRow(0, kTextColumnSetId);
142 layout->AddView(text_label);
143
144 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
145
146 layout->StartRow(0, kButtonsColumnSetId);
147 layout->AddView(reinstall_button_);
148 layout->AddView(later_button_);
149
150 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
151 }
152
153 OutdatedUpgradeBubbleView::OutdatedUpgradeBubbleView(views::View* anchor_view,
154 Browser* browser)
155 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
156 chose_to_reinstall_(false),
157 reinstall_button_(NULL),
158 later_button_(NULL),
159 browser_(browser) {
160 // Compensate for built-in vertical padding in the anchor view's image.
161 set_anchor_insets(gfx::Insets(5, 0, 5, 0));
162 }
163
164 void OutdatedUpgradeBubbleView::ButtonPressed(
165 views::Button* sender, const ui::Event& event) {
166 if (event.IsMouseEvent() &&
167 !(static_cast<const ui::MouseEvent*>(&event))->IsOnlyLeftMouseButton()) {
168 return;
169 }
170 HandleButtonPressed(sender);
171 }
172
173 void OutdatedUpgradeBubbleView::HandleButtonPressed(views::Button* sender) {
174 if (sender == reinstall_button_) {
175 DCHECK(UpgradeDetector::GetInstance()->is_outdated_install());
176 chose_to_reinstall_ = true;
177 UMA_HISTOGRAM_CUSTOM_COUNTS(
178 "OutdatedUpgradeBubble.NumLaterPerReinstall", num_ignored_bubbles_,
179 0, kMaxIgnored, kNumIgnoredBuckets);
180 content::RecordAction(
181 content::UserMetricsAction("OutdatedUpgradeBubble.Reinstall"));
182 chrome::AddSelectedTabWithURL(
183 browser_, GURL(kDownloadChromeUrl), content::PAGE_TRANSITION_LINK);
184 } else {
185 DCHECK_EQ(later_button_, sender);
186 content::RecordAction(
187 content::UserMetricsAction("OutdatedUpgradeBubble.Later"));
188 }
189 StartFade(false);
190 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698