OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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/panels/about_panel_bubble.h" |
| 6 |
| 7 #include "base/i18n/time_formatting.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/ui/panels/panel_originator_delegate.h" |
| 11 #include "grit/generated_resources.h" |
| 12 #include "grit/locale_settings.h" |
| 13 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "views/controls/image_view.h" |
| 16 #include "views/controls/label.h" |
| 17 #include "views/controls/link.h" |
| 18 #include "views/controls/textfield/textfield.h" |
| 19 #include "views/window/window.h" |
| 20 |
| 21 namespace { |
| 22 |
| 23 // Extra padding to put around content over what the InfoBubble provides. |
| 24 const int kBubblePadding = 4; |
| 25 |
| 26 // Vertical spacing between two controls. |
| 27 const int kControlVerticalSpacing = 10; |
| 28 |
| 29 // Horizontal spacing between the text and the left/right of a description. |
| 30 const int kDescriptionHorizontalSpacing = 6; |
| 31 |
| 32 // Vertical spacing between the text and the top/bottom of a description. |
| 33 const int kDescriptionVertialSpacing = 4; |
| 34 |
| 35 // Horizontal spacing between two links. |
| 36 const int kLinksHorizontalSpacing = 20; |
| 37 |
| 38 // Text color of a description. |
| 39 const SkColor kDescriptionTextColor = SK_ColorBLACK; |
| 40 |
| 41 // Background color of a description. |
| 42 const SkColor kDescriptionBackgroundColor = 0xFFE8E8EE; |
| 43 |
| 44 } |
| 45 |
| 46 // AboutPanelBubbleView -------------------------------------------------------- |
| 47 |
| 48 AboutPanelBubble::AboutPanelBubbleView::AboutPanelBubbleView( |
| 49 SkBitmap icon, PanelOriginatorDelegate* originator) |
| 50 : icon_(NULL), |
| 51 title_(NULL), |
| 52 install_date_(NULL), |
| 53 description_(NULL), |
| 54 uninstall_link_(NULL), |
| 55 report_abuse_link_(NULL) { |
| 56 const gfx::Font& font = |
| 57 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); |
| 58 |
| 59 icon_ = new views::ImageView(); |
| 60 icon_->SetImage(icon); |
| 61 AddChildView(icon_); |
| 62 |
| 63 std::string name = originator->GetOriginatorName(); |
| 64 title_ = new views::Label(UTF8ToWide(name)); |
| 65 title_->SetFont(font.DeriveFont(0, gfx::Font::BOLD)); |
| 66 title_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 67 AddChildView(title_); |
| 68 |
| 69 install_date_ = new views::Label(UTF16ToWide( |
| 70 l10n_util::GetStringFUTF16( |
| 71 IDS_ABOUT_PANEL_BUBBLE_EXTENSION_INSTALL_DATE, |
| 72 base::TimeFormatFriendlyDate( |
| 73 originator->GetOriginatorInstallTime())))); |
| 74 install_date_->SetMultiLine(true); |
| 75 install_date_->SetFont(font); |
| 76 install_date_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 77 install_date_->SizeToFit(GetPreferredSize().width() - kBubblePadding * 2); |
| 78 AddChildView(install_date_); |
| 79 |
| 80 description_ = new views::Textfield(views::Textfield::STYLE_MULTILINE); |
| 81 description_->SetText(UTF8ToUTF16(originator->GetOriginatorDescription())); |
| 82 description_->SetHeightInLines(2); |
| 83 description_->SetHorizontalMargins(kDescriptionHorizontalSpacing, |
| 84 kDescriptionHorizontalSpacing); |
| 85 description_->SetVerticalMargins(kDescriptionVertialSpacing, |
| 86 kDescriptionVertialSpacing); |
| 87 description_->SetFont(font); |
| 88 description_->SetTextColor(kDescriptionTextColor); |
| 89 description_->SetBackgroundColor(kDescriptionBackgroundColor); |
| 90 description_->RemoveBorder(); |
| 91 description_->SetReadOnly(true); |
| 92 AddChildView(description_); |
| 93 |
| 94 uninstall_link_ = new views::Link(UTF16ToWide( |
| 95 l10n_util::GetStringFUTF16(IDS_ABOUT_PANEL_BUBBLE_UNINSTALL_EXTENSION, |
| 96 UTF8ToUTF16(name)))); |
| 97 AddChildView(uninstall_link_); |
| 98 |
| 99 report_abuse_link_ = new views::Link(UTF16ToWide( |
| 100 l10n_util::GetStringUTF16(IDS_ABOUT_PANEL_BUBBLE_REPORT_ABUSE))); |
| 101 AddChildView(report_abuse_link_); |
| 102 } |
| 103 |
| 104 void AboutPanelBubble::AboutPanelBubbleView::Layout() { |
| 105 gfx::Size canvas = GetPreferredSize(); |
| 106 gfx::Size icon_size = icon_->GetPreferredSize(); |
| 107 int start_x = 2 * kBubblePadding + icon_size.width(); |
| 108 int width = canvas.width() - kBubblePadding * 3 - icon_size.width(); |
| 109 |
| 110 icon_->SetBounds(kBubblePadding, |
| 111 kBubblePadding, |
| 112 icon_size.width(), |
| 113 icon_size.height()); |
| 114 |
| 115 gfx::Size pref_size = title_->GetPreferredSize(); |
| 116 title_->SetBounds(start_x, |
| 117 kBubblePadding, |
| 118 width, |
| 119 pref_size.height()); |
| 120 |
| 121 int next_y = title_->y() + pref_size.height() + kControlVerticalSpacing; |
| 122 |
| 123 pref_size = install_date_->GetPreferredSize(); |
| 124 install_date_->SetBounds(start_x, |
| 125 next_y, |
| 126 width, |
| 127 pref_size.height()); |
| 128 |
| 129 next_y = install_date_->y() + install_date_->height() + |
| 130 kControlVerticalSpacing; |
| 131 |
| 132 pref_size = description_->GetPreferredSize(); |
| 133 description_->SetBounds( |
| 134 start_x, |
| 135 next_y, |
| 136 width, |
| 137 pref_size.height() + kDescriptionVertialSpacing * 2); |
| 138 |
| 139 next_y = description_->y() + description_->height() + |
| 140 kControlVerticalSpacing; |
| 141 |
| 142 pref_size = uninstall_link_->GetPreferredSize(); |
| 143 uninstall_link_->SetBounds(start_x, |
| 144 next_y, |
| 145 pref_size.width(), |
| 146 pref_size.height()); |
| 147 |
| 148 pref_size = report_abuse_link_->GetPreferredSize(); |
| 149 report_abuse_link_->SetBounds( |
| 150 start_x + uninstall_link_->width() + kLinksHorizontalSpacing, |
| 151 next_y, |
| 152 pref_size.width(), |
| 153 pref_size.height()); |
| 154 } |
| 155 |
| 156 gfx::Size AboutPanelBubble::AboutPanelBubbleView::GetPreferredSize() { |
| 157 return views::Window::GetLocalizedContentsSize( |
| 158 IDS_ABOUTPANELBUBBLE_DIALOG_WIDTH_CHARS, |
| 159 IDS_ABOUTPANELBUBBLE_DIALOG_HEIGHT_LINES); |
| 160 } |
| 161 |
| 162 void AboutPanelBubble::AboutPanelBubbleView::LinkClicked(views::Link* source, |
| 163 int event_flags) { |
| 164 NOTIMPLEMENTED(); |
| 165 } |
| 166 |
| 167 // AboutPanelBubble ------------------------------------------------------------ |
| 168 |
| 169 // static |
| 170 AboutPanelBubble* AboutPanelBubble::Show( |
| 171 views::Widget* parent, |
| 172 const gfx::Rect& position_relative_to, |
| 173 BubbleBorder::ArrowLocation arrow_location, |
| 174 SkBitmap icon, |
| 175 PanelOriginatorDelegate* originator) { |
| 176 AboutPanelBubble* bubble = new AboutPanelBubble(); |
| 177 AboutPanelBubbleView* view = new AboutPanelBubbleView(icon, originator); |
| 178 bubble->InitBubble( |
| 179 parent, position_relative_to, arrow_location, view, bubble); |
| 180 return bubble; |
| 181 } |
| 182 |
| 183 AboutPanelBubble::AboutPanelBubble() { |
| 184 } |
| 185 |
| 186 bool AboutPanelBubble::CloseOnEscape() { |
| 187 return true; |
| 188 } |
| 189 |
| 190 bool AboutPanelBubble::FadeInOnShow() { |
| 191 return false; |
| 192 } |
| 193 |
| 194 std::wstring AboutPanelBubble::accessible_name() { |
| 195 return L"AboutPanelBubble"; |
| 196 } |
OLD | NEW |