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. | |
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 // Don't show the bubble if it's already there. | |
Finnur
2013/01/30 15:50:48
nit: The code is now self documenting and this com
MAD
2013/01/31 21:31:42
Done.
| |
51 if (IsShowing()) | |
52 return; | |
53 upgrade_bubble_ = new OutdatedUpgradeBubbleView(anchor_view, browser); | |
54 views::BubbleDelegateView::CreateBubble(upgrade_bubble_); | |
55 upgrade_bubble_->StartFade(true); | |
56 } | |
57 | |
58 OutdatedUpgradeBubbleView::~OutdatedUpgradeBubbleView() { | |
59 } | |
60 | |
61 views::View* OutdatedUpgradeBubbleView::GetInitiallyFocusedView() { | |
62 return reinstall_button_; | |
63 } | |
64 | |
65 void OutdatedUpgradeBubbleView::WindowClosing() { | |
66 // Reset |upgrade_bubble_| here, not in destructor, because destruction is | |
67 // asynchronous and ShowBubble may be called before full destruction and | |
68 // would attempt to show a bubble that is closing. | |
69 DCHECK_EQ(upgrade_bubble_, this); | |
70 upgrade_bubble_ = NULL; | |
71 } | |
72 | |
73 void OutdatedUpgradeBubbleView::Init() { | |
74 string16 product_name = l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); | |
Finnur
2013/01/30 15:50:48
nit: As I recall, people prefer:
string16 foo(bar)
MAD
2013/01/31 21:31:42
Done.
| |
75 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
76 reinstall_button_ = new views::NativeTextButton( | |
77 this, l10n_util::GetStringFUTF16(IDS_REINSTALL_APP, product_name)); | |
78 reinstall_button_->SetIsDefault(true); | |
79 reinstall_button_->SetFont(rb.GetFont(ui::ResourceBundle::BoldFont)); | |
80 | |
81 later_button_ = new views::NativeTextButton( | |
82 this, l10n_util::GetStringUTF16(IDS_LATER)); | |
83 | |
84 views::Label* title_label = new views::Label( | |
85 l10n_util::GetStringFUTF16(IDS_UPGRADE_BUBBLE_TITLE, product_name)); | |
86 title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | |
87 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
88 | |
89 views::Label* text_label = new views::Label( | |
90 l10n_util::GetStringFUTF16(IDS_UPGRADE_BUBBLE_TEXT, product_name)); | |
91 text_label->SetMultiLine(true); | |
92 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
93 | |
94 views::ImageView* image_view = new views::ImageView(); | |
95 image_view->SetImage(rb.GetImageSkiaNamed(IDR_UPDATE_MENU3)); | |
96 | |
97 GridLayout* layout = new GridLayout(this); | |
98 SetLayoutManager(layout); | |
99 | |
100 const int kIconTitleColumnSetId = 0; | |
101 views::ColumnSet* cs = layout->AddColumnSet(kIconTitleColumnSetId); | |
102 | |
103 // Top (icon-title) row. | |
104 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | |
105 GridLayout::USE_PREF, 0, 0); | |
106 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); | |
107 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, | |
108 GridLayout::USE_PREF, 0, 0); | |
109 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); | |
110 | |
111 // Middle (text) row. | |
112 const int kTextColumnSetId = 1; | |
113 cs = layout->AddColumnSet(kTextColumnSetId); | |
114 cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | |
115 GridLayout::FIXED, kWidthOfDescriptionText, 0); | |
116 | |
117 // Bottom (buttons) row. | |
118 const int kButtonsColumnSetId = 2; | |
119 cs = layout->AddColumnSet(kButtonsColumnSetId); | |
120 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); | |
121 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | |
122 GridLayout::USE_PREF, 0, 0); | |
123 cs->AddPaddingColumn(0, kButtonPadding); | |
124 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | |
125 GridLayout::USE_PREF, 0, 0); | |
126 | |
127 layout->StartRow(0, kIconTitleColumnSetId); | |
128 layout->AddView(image_view); | |
129 layout->AddView(title_label); | |
130 | |
131 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | |
132 layout->StartRow(0, kTextColumnSetId); | |
133 layout->AddView(text_label); | |
134 | |
135 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | |
136 | |
137 layout->StartRow(0, kButtonsColumnSetId); | |
138 layout->AddView(reinstall_button_); | |
139 layout->AddView(later_button_); | |
140 | |
141 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); | |
142 } | |
143 | |
144 OutdatedUpgradeBubbleView::OutdatedUpgradeBubbleView(views::View* anchor_view, | |
145 Browser* browser) | |
146 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | |
147 reinstall_button_(NULL), | |
148 later_button_(NULL), | |
149 browser_(browser) { | |
150 // Compensate for built-in vertical padding in the anchor view's image. | |
151 set_anchor_insets(gfx::Insets(5, 0, 5, 0)); | |
152 } | |
153 | |
154 void OutdatedUpgradeBubbleView::ButtonPressed( | |
155 views::Button* sender, const ui::Event& event) { | |
156 if (event.IsMouseEvent() && | |
157 !(static_cast<const ui::MouseEvent*>(&event))->IsOnlyLeftMouseButton()) { | |
158 return; | |
159 } | |
160 HandleButtonPressed(sender); | |
161 } | |
162 | |
163 void OutdatedUpgradeBubbleView::HandleButtonPressed(views::Button* sender) { | |
164 if (sender == reinstall_button_) { | |
165 DCHECK(UpgradeDetector::GetInstance()->is_outdated_install()); | |
166 content::RecordAction( | |
167 content::UserMetricsAction("OutdatedUpgradeReinstall")); | |
168 chrome::AddSelectedTabWithURL( | |
169 browser_, GURL(kDownloadChromeUrl), content::PAGE_TRANSITION_LINK); | |
170 } else { | |
171 DCHECK_EQ(later_button_, sender); | |
172 content::RecordAction( | |
173 content::UserMetricsAction("OutdatedUpgradeBubble_Later")); | |
174 } | |
175 StartFade(false); | |
176 } | |
OLD | NEW |