OLD | NEW |
---|---|
(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 "chrome/browser/ui/browser_commands.h" | |
8 #include "chrome/browser/ui/browser_tabstrip.h" | |
9 #include "chrome/browser/upgrade_detector.h" | |
10 #include "content/public/browser/user_metrics.h" | |
11 #include "googleurl/src/gurl.h" | |
12 #include "grit/chromium_strings.h" | |
13 #include "grit/generated_resources.h" | |
14 #include "grit/theme_resources.h" | |
15 #include "ui/base/l10n/l10n_util.h" | |
16 #include "ui/base/resource/resource_bundle.h" | |
17 #include "ui/views/controls/button/text_button.h" | |
18 #include "ui/views/controls/image_view.h" | |
19 #include "ui/views/controls/label.h" | |
20 #include "ui/views/layout/grid_layout.h" | |
21 #include "ui/views/layout/layout_constants.h" | |
22 #include "ui/views/widget/widget.h" | |
23 | |
24 using views::GridLayout; | |
25 | |
26 namespace { | |
27 | |
28 // Fixed with of the column holding the description label of the bubble. | |
Finnur
2013/02/04 11:12:04
s/with/width/
MAD
2013/02/04 16:01:29
Done.
| |
29 // TODO(mad): Make sure there is enough room for all languages. | |
30 const int kWidthOfDescriptionText = 330; | |
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 | |
34 // height. | |
35 const int kButtonPadding = views::kRelatedButtonHSpacing - 2; | |
36 | |
37 // The URL to be used to re-install Chrome when auto-update failed for too long. | |
38 const char kDownloadChromeUrl[] = "https://www.google.com/chrome/?&brand=CHWL" | |
39 "&utm_campaign=en&utm_source=en-et-na-us-chrome-bubble&utm_medium=et"; | |
40 | |
41 } // namespace | |
42 | |
43 // OutdatedUpgradeBubbleView --------------------------------------------------- | |
44 | |
45 OutdatedUpgradeBubbleView* OutdatedUpgradeBubbleView::upgrade_bubble_ = NULL; | |
46 | |
47 // static | |
48 void OutdatedUpgradeBubbleView::ShowBubble(views::View* anchor_view, | |
49 Browser* browser) { | |
50 if (IsShowing()) | |
51 return; | |
52 upgrade_bubble_ = new OutdatedUpgradeBubbleView(anchor_view, browser); | |
53 views::BubbleDelegateView::CreateBubble(upgrade_bubble_); | |
54 upgrade_bubble_->StartFade(true); | |
55 } | |
56 | |
57 OutdatedUpgradeBubbleView::~OutdatedUpgradeBubbleView() { | |
58 } | |
59 | |
60 views::View* OutdatedUpgradeBubbleView::GetInitiallyFocusedView() { | |
61 return reinstall_button_; | |
62 } | |
63 | |
64 void OutdatedUpgradeBubbleView::WindowClosing() { | |
65 // Reset |upgrade_bubble_| here, not in destructor, because destruction is | |
66 // asynchronous and ShowBubble may be called before full destruction and | |
67 // would attempt to show a bubble that is closing. | |
68 DCHECK_EQ(upgrade_bubble_, this); | |
69 upgrade_bubble_ = NULL; | |
70 } | |
71 | |
72 void OutdatedUpgradeBubbleView::Init() { | |
73 string16 product_name(l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); | |
74 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
75 reinstall_button_ = new views::NativeTextButton( | |
76 this, l10n_util::GetStringFUTF16(IDS_REINSTALL_APP, product_name)); | |
77 reinstall_button_->SetIsDefault(true); | |
78 reinstall_button_->SetFont(rb.GetFont(ui::ResourceBundle::BoldFont)); | |
79 | |
80 later_button_ = new views::NativeTextButton( | |
81 this, l10n_util::GetStringUTF16(IDS_LATER)); | |
82 | |
83 views::Label* title_label = new views::Label( | |
84 l10n_util::GetStringFUTF16(IDS_UPGRADE_BUBBLE_TITLE, product_name)); | |
85 title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | |
86 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
87 | |
88 views::Label* text_label = new views::Label( | |
89 l10n_util::GetStringFUTF16(IDS_UPGRADE_BUBBLE_TEXT, product_name)); | |
90 text_label->SetMultiLine(true); | |
91 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
92 | |
93 views::ImageView* image_view = new views::ImageView(); | |
94 image_view->SetImage(rb.GetImageSkiaNamed(IDR_UPDATE_MENU3)); | |
95 | |
96 GridLayout* layout = new GridLayout(this); | |
97 SetLayoutManager(layout); | |
98 | |
99 const int kIconTitleColumnSetId = 0; | |
100 views::ColumnSet* cs = layout->AddColumnSet(kIconTitleColumnSetId); | |
101 | |
102 // Top (icon-title) row. | |
103 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | |
104 GridLayout::USE_PREF, 0, 0); | |
105 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); | |
106 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, | |
107 GridLayout::USE_PREF, 0, 0); | |
108 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); | |
109 | |
110 // Middle (text) row. | |
111 const int kTextColumnSetId = 1; | |
112 cs = layout->AddColumnSet(kTextColumnSetId); | |
113 cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | |
114 GridLayout::FIXED, kWidthOfDescriptionText, 0); | |
115 | |
116 // Bottom (buttons) row. | |
117 const int kButtonsColumnSetId = 2; | |
118 cs = layout->AddColumnSet(kButtonsColumnSetId); | |
119 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); | |
120 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | |
121 GridLayout::USE_PREF, 0, 0); | |
122 cs->AddPaddingColumn(0, kButtonPadding); | |
123 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | |
124 GridLayout::USE_PREF, 0, 0); | |
125 | |
126 layout->StartRow(0, kIconTitleColumnSetId); | |
127 layout->AddView(image_view); | |
128 layout->AddView(title_label); | |
129 | |
130 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | |
131 layout->StartRow(0, kTextColumnSetId); | |
132 layout->AddView(text_label); | |
133 | |
134 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | |
135 | |
136 layout->StartRow(0, kButtonsColumnSetId); | |
137 layout->AddView(reinstall_button_); | |
138 layout->AddView(later_button_); | |
139 | |
140 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); | |
141 } | |
142 | |
143 OutdatedUpgradeBubbleView::OutdatedUpgradeBubbleView(views::View* anchor_view, | |
144 Browser* browser) | |
145 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | |
146 reinstall_button_(NULL), | |
147 later_button_(NULL), | |
148 browser_(browser) { | |
149 // Compensate for built-in vertical padding in the anchor view's image. | |
150 set_anchor_insets(gfx::Insets(5, 0, 5, 0)); | |
151 } | |
152 | |
153 void OutdatedUpgradeBubbleView::ButtonPressed( | |
154 views::Button* sender, const ui::Event& event) { | |
155 if (event.IsMouseEvent() && | |
156 !(static_cast<const ui::MouseEvent*>(&event))->IsOnlyLeftMouseButton()) { | |
157 return; | |
158 } | |
159 HandleButtonPressed(sender); | |
160 } | |
161 | |
162 void OutdatedUpgradeBubbleView::HandleButtonPressed(views::Button* sender) { | |
163 if (sender == reinstall_button_) { | |
164 DCHECK(UpgradeDetector::GetInstance()->is_outdated_install()); | |
165 content::RecordAction( | |
166 content::UserMetricsAction("OutdatedUpgradeReinstall")); | |
167 chrome::AddSelectedTabWithURL( | |
168 browser_, GURL(kDownloadChromeUrl), content::PAGE_TRANSITION_LINK); | |
169 } else { | |
170 DCHECK_EQ(later_button_, sender); | |
171 content::RecordAction( | |
172 content::UserMetricsAction("OutdatedUpgradeBubble_Later")); | |
Finnur
2013/02/04 11:12:04
You use two different ways of reporting which acti
MAD
2013/02/04 16:01:29
Done.
| |
173 } | |
Finnur
2013/02/04 11:12:04
Also: In my experience the UMA_HISTOGRAM macros ar
MAD
2013/02/04 16:01:29
I believe more metrics is almost always better...
Finnur
2013/02/05 10:52:19
If it were me, I'd probably want to know how many
MAD
2013/02/05 16:49:16
OK, thanks, I'll ask Jeff what he would like to se
Finnur
2013/02/05 22:14:50
Don't feel the need to wait on just this. The UMA
| |
174 StartFade(false); | |
175 } | |
OLD | NEW |