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

Side by Side Diff: chrome/browser/ui/views/upgrade_bubble_view.cc

Issue 11440020: Add an outdated upgrade bubble view. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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/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 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.
26 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.
27
28 const char kDownloadChromeUrl[] = "https://www.google.com/chrome/?&brand=CHWL&"
29 "utm_campaign=en&utm_source=en-et-na-us-chrome-bubble&utm_medium=et";
30
31 } // namespace
32
33 // UpgradeBubbleView ---------------------------------------------------------
34
35 UpgradeBubbleView* UpgradeBubbleView::upgrade_bubble_ = NULL;
36
37 // static
38 void UpgradeBubbleView::ShowBubble(views::View* anchor_view, Browser* browser) {
39 if (IsShowing())
40 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
41
42 upgrade_bubble_ = new UpgradeBubbleView(anchor_view, browser);
43 views::BubbleDelegateView::CreateBubble(upgrade_bubble_);
44 upgrade_bubble_->StartFade(true);
45 }
46
47 // static
48 bool UpgradeBubbleView::IsShowing() {
49 return upgrade_bubble_ != NULL;
50 }
51
52 UpgradeBubbleView::~UpgradeBubbleView() {
53 }
54
55 views::View* UpgradeBubbleView::GetInitiallyFocusedView() {
56 return reinstall_button_;
57 }
58
59 void UpgradeBubbleView::WindowClosing() {
60 // We have to reset |bubble_| here, not in our destructor, because we'll be
61 // destroyed asynchronously and the shown state will be checked before then.
62 DCHECK_EQ(upgrade_bubble_, this);
63 upgrade_bubble_ = NULL;
64 }
65
66 bool UpgradeBubbleView::AcceleratorPressed(
67 const ui::Accelerator& accelerator) {
68 if (accelerator.key_code() == ui::VKEY_RETURN) {
69 if (reinstall_button_->HasFocus())
70 HandleButtonPressed(reinstall_button_);
71 else
72 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
73 return true;
74 } else if (accelerator.key_code() == ui::VKEY_ESCAPE) {
75 HandleButtonPressed(later_button_);
76 return true;
77 }
78
79 return BubbleDelegateView::AcceleratorPressed(accelerator);
80 }
81
82 void UpgradeBubbleView::Init() {
83 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
84 reinstall_button_ = new views::NativeTextButton(
85 this, l10n_util::GetStringUTF16(IDS_REINSTALL_CHROME));
86 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
87 reinstall_button_->SetFont(rb.GetFont(ui::ResourceBundle::BoldFont));
88
89 later_button_ = new views::NativeTextButton(
90 this, l10n_util::GetStringUTF16(IDS_LATER));
91
92 views::Label* title_label = new views::Label(
93 l10n_util::GetStringUTF16(IDS_UPGRADE_BUBBLE_TITLE));
94 title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
95 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
96
97 views::Label* text_label = new views::Label(
98 l10n_util::GetStringUTF16(IDS_UPGRADE_BUBBLE_TEXT));
99 text_label->SetMultiLine(true);
100 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
101
102 views::ImageView* image_view = new views::ImageView();
103 image_view->SetImage(rb.GetImageSkiaNamed(IDR_UPDATE_MENU3));
104
105 GridLayout* layout = new GridLayout(this);
106 SetLayoutManager(layout);
107
108 views::ColumnSet* cs = layout->AddColumnSet(0);
109
110 // Top (icon-title) row.
111 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
112 GridLayout::USE_PREF, 0, 0);
113 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
114 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
115 GridLayout::USE_PREF, 0, 0);
116 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
117
118 // Middle (text) row.
119 cs = layout->AddColumnSet(1);
120 cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
121 GridLayout::FIXED, kWidthOfDescriptionText, 0);
122
123 // Bottom (buttons) row.
124 cs = layout->AddColumnSet(2);
125 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing);
126 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
127 GridLayout::USE_PREF, 0, 0);
128 // We subtract 2 to account for the natural button padding, and
129 // to bring the separation visually in line with the row separation
130 // height.
131 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.
132 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
133 GridLayout::USE_PREF, 0, 0);
134
135 layout->StartRow(0, 0);
136 layout->AddView(image_view);
137 layout->AddView(title_label);
138
139 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
140 layout->StartRow(0, 1);
141 layout->AddView(text_label);
142
143 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
144
145 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.
146 layout->AddView(reinstall_button_);
147 layout->AddView(later_button_);
148
149 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
150 }
151
152 UpgradeBubbleView::UpgradeBubbleView(views::View* anchor_view, Browser* browser)
153 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
154 reinstall_button_(NULL),
155 later_button_(NULL),
156 browser_(browser) {
157 // Compensate for built-in vertical padding in the anchor view's image.
158 set_anchor_insets(gfx::Insets(5, 0, 5, 0));
159 }
160
161 void UpgradeBubbleView::ButtonPressed(
162 views::Button* sender, const ui::Event& event) {
163 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).
164 }
165
166 void UpgradeBubbleView::HandleButtonPressed(views::Button* sender) {
167 if (sender == reinstall_button_) {
168 content::RecordAction(
169 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.
170 chrome::AddSelectedTabWithURL(
171 browser_, GURL(kDownloadChromeUrl), content::PAGE_TRANSITION_LINK);
172 StartFade(false);
173 } else {
174 DCHECK_EQ(later_button_, sender);
175 content::RecordAction(
176 content::UserMetricsAction("UpgradeBubble_Later"));
Finnur 2012/12/06 19:53:16 Ditto.
MAD 2013/01/22 15:18:29 Done.
177 StartFade(false);
178 }
179 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698