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 "content/public/browser/user_metrics.h" |
| 10 #include "googleurl/src/gurl.h" |
| 11 #include "grit/chromium_strings.h" |
| 12 #include "grit/generated_resources.h" |
| 13 #include "grit/theme_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/views/controls/button/text_button.h" |
| 17 #include "ui/views/controls/image_view.h" |
| 18 #include "ui/views/controls/label.h" |
| 19 #include "ui/views/layout/grid_layout.h" |
| 20 #include "ui/views/layout/layout_constants.h" |
| 21 #include "ui/views/widget/widget.h" |
| 22 |
| 23 using views::GridLayout; |
| 24 |
| 25 namespace { |
| 26 |
| 27 // Fixed with of the column holding the description label of the bubble. |
| 28 // TODO(mad): Make sure there is enough room for all languages. |
| 29 const int kWidthOfDescriptionText = 330; |
| 30 |
| 31 // We subtract 2 to account for the natural button padding, and |
| 32 // to bring the separation visually in line with the row separation |
| 33 // height. |
| 34 const int kButtonPadding = views::kRelatedButtonHSpacing - 2; |
| 35 |
| 36 } // namespace |
| 37 |
| 38 // OutdatedUpgradeBubbleView --------------------------------------------------- |
| 39 |
| 40 OutdatedUpgradeBubbleView* OutdatedUpgradeBubbleView::upgrade_bubble_ = NULL; |
| 41 |
| 42 // static |
| 43 void OutdatedUpgradeBubbleView::ShowBubble(views::View* anchor_view, |
| 44 Browser* browser) { |
| 45 // Don't show the bubble if it's already there. |
| 46 if (upgrade_bubble_ != NULL) |
| 47 return; |
| 48 upgrade_bubble_ = new OutdatedUpgradeBubbleView(anchor_view, browser); |
| 49 views::BubbleDelegateView::CreateBubble(upgrade_bubble_); |
| 50 upgrade_bubble_->StartFade(true); |
| 51 } |
| 52 |
| 53 OutdatedUpgradeBubbleView::~OutdatedUpgradeBubbleView() { |
| 54 } |
| 55 |
| 56 views::View* OutdatedUpgradeBubbleView::GetInitiallyFocusedView() { |
| 57 return reinstall_button_; |
| 58 } |
| 59 |
| 60 void OutdatedUpgradeBubbleView::WindowClosing() { |
| 61 // Reset |upgrade_bubble_| here, not in destructor, because destruction is |
| 62 // asynchronous and ShowBubble may be called before full destruction and |
| 63 // would attempt to show a bubble that is closing. |
| 64 DCHECK_EQ(upgrade_bubble_, this); |
| 65 upgrade_bubble_ = NULL; |
| 66 } |
| 67 |
| 68 void OutdatedUpgradeBubbleView::Init() { |
| 69 string16 product_name = l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); |
| 70 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 71 reinstall_button_ = new views::NativeTextButton( |
| 72 this, l10n_util::GetStringFUTF16(IDS_REINSTALL_APP, product_name)); |
| 73 reinstall_button_->SetIsDefault(true); |
| 74 reinstall_button_->SetFont(rb.GetFont(ui::ResourceBundle::BoldFont)); |
| 75 |
| 76 later_button_ = new views::NativeTextButton( |
| 77 this, l10n_util::GetStringUTF16(IDS_LATER)); |
| 78 |
| 79 views::Label* title_label = new views::Label( |
| 80 l10n_util::GetStringFUTF16(IDS_UPGRADE_BUBBLE_TITLE, product_name)); |
| 81 title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
| 82 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 83 |
| 84 views::Label* text_label = new views::Label( |
| 85 l10n_util::GetStringFUTF16(IDS_UPGRADE_BUBBLE_TEXT, product_name)); |
| 86 text_label->SetMultiLine(true); |
| 87 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 88 |
| 89 views::ImageView* image_view = new views::ImageView(); |
| 90 image_view->SetImage(rb.GetImageSkiaNamed(IDR_UPDATE_MENU3)); |
| 91 |
| 92 GridLayout* layout = new GridLayout(this); |
| 93 SetLayoutManager(layout); |
| 94 |
| 95 static const int kIconTitleColumnSetId = 0; |
| 96 views::ColumnSet* cs = layout->AddColumnSet(kIconTitleColumnSetId); |
| 97 |
| 98 // Top (icon-title) row. |
| 99 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 100 GridLayout::USE_PREF, 0, 0); |
| 101 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); |
| 102 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, |
| 103 GridLayout::USE_PREF, 0, 0); |
| 104 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); |
| 105 |
| 106 // Middle (text) row. |
| 107 static const int kTextColumnSetId = 1; |
| 108 cs = layout->AddColumnSet(kTextColumnSetId); |
| 109 cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 110 GridLayout::FIXED, kWidthOfDescriptionText, 0); |
| 111 |
| 112 // Bottom (buttons) row. |
| 113 static const int kButtonsColumnSetId = 2; |
| 114 cs = layout->AddColumnSet(kButtonsColumnSetId); |
| 115 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); |
| 116 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
| 117 GridLayout::USE_PREF, 0, 0); |
| 118 cs->AddPaddingColumn(0, kButtonPadding); |
| 119 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
| 120 GridLayout::USE_PREF, 0, 0); |
| 121 |
| 122 layout->StartRow(0, kIconTitleColumnSetId); |
| 123 layout->AddView(image_view); |
| 124 layout->AddView(title_label); |
| 125 |
| 126 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
| 127 layout->StartRow(0, kTextColumnSetId); |
| 128 layout->AddView(text_label); |
| 129 |
| 130 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| 131 |
| 132 layout->StartRow(0, kButtonsColumnSetId); |
| 133 layout->AddView(reinstall_button_); |
| 134 layout->AddView(later_button_); |
| 135 |
| 136 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); |
| 137 } |
| 138 |
| 139 OutdatedUpgradeBubbleView::OutdatedUpgradeBubbleView(views::View* anchor_view, |
| 140 Browser* browser) |
| 141 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
| 142 reinstall_button_(NULL), |
| 143 later_button_(NULL), |
| 144 browser_(browser) { |
| 145 // Compensate for built-in vertical padding in the anchor view's image. |
| 146 set_anchor_insets(gfx::Insets(5, 0, 5, 0)); |
| 147 } |
| 148 |
| 149 void OutdatedUpgradeBubbleView::ButtonPressed( |
| 150 views::Button* sender, const ui::Event& event) { |
| 151 if (event.IsMouseEvent() && |
| 152 !(static_cast<const ui::MouseEvent*>(&event))->IsOnlyLeftMouseButton()) { |
| 153 return; |
| 154 } |
| 155 HandleButtonPressed(sender); |
| 156 } |
| 157 |
| 158 void OutdatedUpgradeBubbleView::HandleButtonPressed(views::Button* sender) { |
| 159 if (sender == reinstall_button_) { |
| 160 chrome::NavigateToChromeInstallPage(browser_); |
| 161 } else { |
| 162 DCHECK_EQ(later_button_, sender); |
| 163 content::RecordAction( |
| 164 content::UserMetricsAction("OutdatedUpgradeBubble_Later")); |
| 165 } |
| 166 StartFade(false); |
| 167 } |
OLD | NEW |