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