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