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