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

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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "chrome/browser/ui/browser_tabstrip.h"
8 #include "content/public/browser/user_metrics.h"
9 #include "googleurl/src/gurl.h"
10 #include "grit/generated_resources.h"
11 #include "grit/theme_resources.h"
12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/views/controls/button/text_button.h"
15 #include "ui/views/controls/image_view.h"
16 #include "ui/views/controls/label.h"
17 #include "ui/views/layout/grid_layout.h"
18 #include "ui/views/layout/layout_constants.h"
19 #include "ui/views/widget/widget.h"
20
21 using views::GridLayout;
22
23 namespace {
24
25 // Fixed with of the column holding the description label of the bubble.
26 // 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...
27 const int kWidthOfDescriptionText = 330;
28
29 const char kDownloadChromeUrl[] = "https://www.google.com/chrome/?&brand=CHWL&"
30 "utm_campaign=en&utm_source=en-et-na-us-chrome-bubble&utm_medium=et";
31
32 // We subtract 2 to account for the natural button padding, and
33 // 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
34 // height.
35 const int kButtonPadding = views::kRelatedButtonHSpacing - 2;
36
37 } // namespace
38
39 // OutdatedUpgradeBubbleView ---------------------------------------------------
40
41 OutdatedUpgradeBubbleView* OutdatedUpgradeBubbleView::upgrade_bubble_ = NULL;
42
43 // static
44 void OutdatedUpgradeBubbleView::ShowBubble(views::View* anchor_view,
45 Browser* browser) {
46 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
47 upgrade_bubble_ = new OutdatedUpgradeBubbleView(anchor_view, browser);
48 views::BubbleDelegateView::CreateBubble(upgrade_bubble_);
49 upgrade_bubble_->StartFade(true);
50 }
51
52 // static
53 bool OutdatedUpgradeBubbleView::IsShowing() {
54 return upgrade_bubble_ != NULL;
55 }
56
57 OutdatedUpgradeBubbleView::~OutdatedUpgradeBubbleView() {
58 }
59
60 views::View* OutdatedUpgradeBubbleView::GetInitiallyFocusedView() {
61 return reinstall_button_;
62 }
63
64 void OutdatedUpgradeBubbleView::WindowClosing() {
65 // We have to reset |bubble_| here, not in our destructor, because we'll be
66 // 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.
67 DCHECK_EQ(upgrade_bubble_, this);
68 upgrade_bubble_ = NULL;
69 }
Finnur 2013/01/23 10:39:17 nit: Weird indentation.
MAD 2013/01/23 20:57:59 Done.
70
71 void OutdatedUpgradeBubbleView::Init() {
72 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
73 reinstall_button_ = new views::NativeTextButton(
74 this, l10n_util::GetStringUTF16(IDS_REINSTALL_CHROME));
75 reinstall_button_->SetIsDefault(true);
76 reinstall_button_->SetFont(rb.GetFont(ui::ResourceBundle::BoldFont));
77
78 later_button_ = new views::NativeTextButton(
79 this, l10n_util::GetStringUTF16(IDS_LATER));
80
81 views::Label* title_label = new views::Label(
82 l10n_util::GetStringUTF16(IDS_UPGRADE_BUBBLE_TITLE));
83 title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
84 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
85
86 views::Label* text_label = new views::Label(
87 l10n_util::GetStringUTF16(IDS_UPGRADE_BUBBLE_TEXT));
88 text_label->SetMultiLine(true);
89 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
90
91 views::ImageView* image_view = new views::ImageView();
92 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...
93
94 GridLayout* layout = new GridLayout(this);
95 SetLayoutManager(layout);
96
97 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.
98 views::ColumnSet* cs = layout->AddColumnSet(kIconTitleColumnSetId);
99
100 // Top (icon-title) row.
101 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
102 GridLayout::USE_PREF, 0, 0);
103 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
104 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
105 GridLayout::USE_PREF, 0, 0);
106 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
107
108 // Middle (text) row.
109 static const int kTextColumnSetId = 1;
110 cs = layout->AddColumnSet(kTextColumnSetId);
111 cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
112 GridLayout::FIXED, kWidthOfDescriptionText, 0);
113
114 // Bottom (buttons) row.
115 static const int kButtonsColumnSetId = 2;
116 cs = layout->AddColumnSet(kButtonsColumnSetId);
117 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing);
118 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
119 GridLayout::USE_PREF, 0, 0);
120 cs->AddPaddingColumn(0, kButtonPadding);
121 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
122 GridLayout::USE_PREF, 0, 0);
123
124 layout->StartRow(0, kIconTitleColumnSetId);
125 layout->AddView(image_view);
126 layout->AddView(title_label);
127
128 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
129 layout->StartRow(0, kTextColumnSetId);
130 layout->AddView(text_label);
131
132 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
133
134 layout->StartRow(0, kButtonsColumnSetId);
135 layout->AddView(reinstall_button_);
136 layout->AddView(later_button_);
137
138 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
139 }
140
141 OutdatedUpgradeBubbleView::OutdatedUpgradeBubbleView(views::View* anchor_view,
142 Browser* browser)
143 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
144 reinstall_button_(NULL),
145 later_button_(NULL),
146 browser_(browser) {
147 // Compensate for built-in vertical padding in the anchor view's image.
148 set_anchor_insets(gfx::Insets(5, 0, 5, 0));
149 }
150
151 void OutdatedUpgradeBubbleView::ButtonPressed(
152 views::Button* sender, const ui::Event& event) {
153 if (event.IsOnlyLeftMouseButton())
154 HandleButtonPressed(sender);
155 }
156
157 void OutdatedUpgradeBubbleView::HandleButtonPressed(views::Button* sender) {
158 if (sender == reinstall_button_) {
159 content::RecordAction(
160 content::UserMetricsAction("OutdatedUpgradeBubble_Reinstall"));
161 chrome::AddSelectedTabWithURL(
162 browser_, GURL(kDownloadChromeUrl), content::PAGE_TRANSITION_LINK);
163 StartFade(false);
164 } else {
165 DCHECK_EQ(later_button_, sender);
166 content::RecordAction(
167 content::UserMetricsAction("OutdatedUpgradeBubble_Later"));
168 StartFade(false);
169 }
170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698