Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: chrome/browser/views/page_info_bubble_view.cc

Issue 3221005: Tweaks to the SSL InfoBubble dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/views/page_info_bubble_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/views/page_info_bubble_view.h" 5 #include "chrome/browser/views/page_info_bubble_view.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/certificate_viewer.h" 11 #include "chrome/browser/certificate_viewer.h"
11 #include "chrome/browser/views/frame/browser_view.h" 12 #include "chrome/browser/views/frame/browser_view.h"
12 #include "chrome/browser/views/info_bubble.h" 13 #include "chrome/browser/views/info_bubble.h"
13 #include "chrome/browser/views/toolbar_view.h" 14 #include "chrome/browser/views/toolbar_view.h"
14 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
15 #include "grit/locale_settings.h" 16 #include "grit/locale_settings.h"
16 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
17 #include "views/controls/image_view.h" 18 #include "views/controls/image_view.h"
18 #include "views/controls/label.h" 19 #include "views/controls/label.h"
19 #include "views/controls/link.h"
20 #include "views/controls/separator.h" 20 #include "views/controls/separator.h"
21 #include "views/grid_layout.h" 21 #include "views/grid_layout.h"
22 #include "views/widget/widget.h" 22 #include "views/widget/widget.h"
23 #include "views/window/window.h" 23 #include "views/window/window.h"
24 24
25 namespace { 25 namespace {
26 26
27 // Layout constants. 27 // Layout constants.
28 const int kHGapToBorder = 11; 28 const int kHGapToBorder = 11;
29 const int kVGapToImage = 10; 29 const int kVGapToImage = 10;
30 const int kVGapToHeadline = 7; 30 const int kVGapToHeadline = 7;
31 const int kHGapImageToDescription = 6; 31 const int kHGapImageToDescription = 6;
32 const int kTextPaddingRight = 10; 32 const int kTextPaddingRight = 10;
33 const int kPaddingBelowSeparator = 4; 33 const int kPaddingBelowSeparator = 4;
34 const int kPaddingAboveSeparator = 13; 34 const int kPaddingAboveSeparator = 13;
35 const int kIconOffset = 28; 35 const int kIconOffset = 28;
36 36
37 // A section contains an image that shows a status (good or bad), a title, an 37 // A section contains an image that shows a status (good or bad), a title, an
38 // optional head-line (in bold) and a description. 38 // optional head-line (in bold) and a description.
39 class Section : public views::View, 39 class Section : public views::View,
40 public views::LinkController { 40 public views::LinkController {
41 public: 41 public:
42 Section(PageInfoBubbleView* owner, 42 Section(PageInfoBubbleView* owner,
43 const PageInfoModel::SectionInfo& section_info); 43 const PageInfoModel::SectionInfo& section_info,
44 bool show_cert);
44 virtual ~Section(); 45 virtual ~Section();
45 46
46 // views::View methods: 47 // views::View methods:
47 virtual int GetHeightForWidth(int w); 48 virtual int GetHeightForWidth(int w);
48 virtual void Layout(); 49 virtual void Layout();
49 50
50 // views::LinkController methods: 51 // views::LinkController methods:
51 virtual void LinkActivated(views::Link* source, int event_flags); 52 virtual void LinkActivated(views::Link* source, int event_flags);
52 53
53 private: 54 private:
(...skipping 30 matching lines...) Expand all
84 85
85 PageInfoBubbleView::PageInfoBubbleView(gfx::NativeWindow parent_window, 86 PageInfoBubbleView::PageInfoBubbleView(gfx::NativeWindow parent_window,
86 Profile* profile, 87 Profile* profile,
87 const GURL& url, 88 const GURL& url,
88 const NavigationEntry::SSLStatus& ssl, 89 const NavigationEntry::SSLStatus& ssl,
89 bool show_history) 90 bool show_history)
90 : ALLOW_THIS_IN_INITIALIZER_LIST(model_(profile, url, ssl, 91 : ALLOW_THIS_IN_INITIALIZER_LIST(model_(profile, url, ssl,
91 show_history, this)), 92 show_history, this)),
92 parent_window_(parent_window), 93 parent_window_(parent_window),
93 cert_id_(ssl.cert_id()), 94 cert_id_(ssl.cert_id()),
94 info_bubble_(NULL) { 95 info_bubble_(NULL),
96 help_center_link_(NULL) {
95 LayoutSections(); 97 LayoutSections();
96 } 98 }
97 99
98 PageInfoBubbleView::~PageInfoBubbleView() { 100 PageInfoBubbleView::~PageInfoBubbleView() {
99 } 101 }
100 102
101 void PageInfoBubbleView::ShowCertDialog() { 103 void PageInfoBubbleView::ShowCertDialog() {
102 ShowCertificateViewerByID(parent_window_, cert_id_); 104 ShowCertificateViewerByID(parent_window_, cert_id_);
103 } 105 }
104 106
(...skipping 10 matching lines...) Expand all
115 views::GridLayout::USE_PREF, // Size type. 117 views::GridLayout::USE_PREF, // Size type.
116 0, // Ignored for USE_PREF. 118 0, // Ignored for USE_PREF.
117 0); // Minimum size. 119 0); // Minimum size.
118 120
119 int count = model_.GetSectionCount(); 121 int count = model_.GetSectionCount();
120 for (int i = 0; i < count; ++i) { 122 for (int i = 0; i < count; ++i) {
121 PageInfoModel::SectionInfo info = model_.GetSectionInfo(i); 123 PageInfoModel::SectionInfo info = model_.GetSectionInfo(i);
122 layout->StartRow(0, 0); 124 layout->StartRow(0, 0);
123 // TODO(finnur): Remove title from the info struct, since it is 125 // TODO(finnur): Remove title from the info struct, since it is
124 // not used anymore. 126 // not used anymore.
125 layout->AddView(new Section(this, info)); 127 layout->AddView(new Section(this, info, cert_id_ > 0));
126 128
127 // Add separator after all sections except the last. 129 // Add separator after all sections.
128 if (i < count - 1) { 130 layout->AddPaddingRow(0, kPaddingAboveSeparator);
129 layout->AddPaddingRow(0, kPaddingAboveSeparator); 131 layout->StartRow(0, 0);
130 layout->StartRow(0, 0); 132 layout->AddView(new views::Separator());
131 layout->AddView(new views::Separator()); 133 layout->AddPaddingRow(0, kPaddingBelowSeparator);
132 layout->AddPaddingRow(0, kPaddingBelowSeparator);
133 }
134 } 134 }
135
136 // Then add the help center link at the bottom.
137 layout->StartRow(0, 0);
138 help_center_link_ =
139 new views::Link(l10n_util::GetString(IDS_PAGE_INFO_HELP_CENTER_LINK));
140 help_center_link_->SetController(this);
141 layout->AddView(help_center_link_);
135 } 142 }
136 143
137 gfx::Size PageInfoBubbleView::GetPreferredSize() { 144 gfx::Size PageInfoBubbleView::GetPreferredSize() {
138 gfx::Size size(views::Window::GetLocalizedContentsSize( 145 gfx::Size size(views::Window::GetLocalizedContentsSize(
139 IDS_PAGEINFOBUBBLE_WIDTH_CHARS, IDS_PAGEINFOBUBBLE_HEIGHT_LINES)); 146 IDS_PAGEINFOBUBBLE_WIDTH_CHARS, IDS_PAGEINFOBUBBLE_HEIGHT_LINES));
140 size.set_height(0); 147 size.set_height(0);
141 148
142 int count = model_.GetSectionCount(); 149 int count = model_.GetSectionCount();
143 for (int i = 0; i < count; ++i) { 150 for (int i = 0; i < count; ++i) {
144 PageInfoModel::SectionInfo info = model_.GetSectionInfo(i); 151 PageInfoModel::SectionInfo info = model_.GetSectionInfo(i);
145 Section section(this, info); 152 Section section(this, info, cert_id_ > 0);
146 size.Enlarge(0, section.GetHeightForWidth(size.width())); 153 size.Enlarge(0, section.GetHeightForWidth(size.width()));
147 } 154 }
148 155
149 // Account for the separators and padding. 156 // Calculate how much space the separators take up (with padding).
150 views::Separator separator; 157 views::Separator separator;
151 gfx::Size separator_size = separator.GetPreferredSize(); 158 gfx::Size separator_size = separator.GetPreferredSize();
152 size.Enlarge(0, (count - 1) * (separator_size.height() + 159 gfx::Size separator_plus_padding(0, separator_size.height() +
153 kPaddingAboveSeparator + 160 kPaddingAboveSeparator +
154 kPaddingBelowSeparator)); 161 kPaddingBelowSeparator);
162
163 // Account for the separators and padding within sections.
164 size.Enlarge(0, (count - 1) * separator_plus_padding.height());
165
166 // Account for the Help Center link and the separator above it.
167 gfx::Size link_size = help_center_link_->GetPreferredSize();
168 size.Enlarge(0, separator_plus_padding.height() +
169 link_size.height());
170
155 return size; 171 return size;
156 } 172 }
157 173
158 void PageInfoBubbleView::ModelChanged() { 174 void PageInfoBubbleView::ModelChanged() {
159 LayoutSections(); 175 LayoutSections();
160 info_bubble_->SizeToContents(); 176 info_bubble_->SizeToContents();
161 } 177 }
162 178
179 void PageInfoBubbleView::LinkActivated(views::Link* source, int event_flags) {
180 GURL url = GURL(l10n_util::GetStringUTF16(IDS_PAGE_INFO_HELP_CENTER));
181 Browser* browser = BrowserList::GetLastActive();
182 browser->OpenURL(url, GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK);
183 }
184
163 //////////////////////////////////////////////////////////////////////////////// 185 ////////////////////////////////////////////////////////////////////////////////
164 // Section 186 // Section
165 187
166 Section::Section(PageInfoBubbleView* owner, 188 Section::Section(PageInfoBubbleView* owner,
167 const PageInfoModel::SectionInfo& section_info) 189 const PageInfoModel::SectionInfo& section_info,
190 bool show_cert)
168 : owner_(owner), 191 : owner_(owner),
169 info_(section_info) { 192 info_(section_info),
193 link_(NULL) {
170 if (!good_state_icon_) { 194 if (!good_state_icon_) {
171 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 195 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
172 good_state_icon_ = rb.GetBitmapNamed(IDR_PAGEINFO_GOOD); 196 good_state_icon_ = rb.GetBitmapNamed(IDR_PAGEINFO_GOOD);
173 bad_state_icon_ = rb.GetBitmapNamed(IDR_PAGEINFO_BAD); 197 bad_state_icon_ = rb.GetBitmapNamed(IDR_PAGEINFO_BAD);
174 mixed_state_icon_ = rb.GetBitmapNamed(IDR_PAGEINFO_MIXED); 198 mixed_state_icon_ = rb.GetBitmapNamed(IDR_PAGEINFO_MIXED);
175 } 199 }
176 200
177 if (info_.type == PageInfoModel::SECTION_INFO_IDENTITY || 201 if (info_.type == PageInfoModel::SECTION_INFO_IDENTITY ||
178 info_.type == PageInfoModel::SECTION_INFO_CONNECTION) { 202 info_.type == PageInfoModel::SECTION_INFO_CONNECTION) {
179 status_image_ = new views::ImageView(); 203 status_image_ = new views::ImageView();
(...skipping 21 matching lines...) Expand all
201 AddChildView(headline_label_); 225 AddChildView(headline_label_);
202 226
203 description_label_ = new views::Label(UTF16ToWideHack(info_.description)); 227 description_label_ = new views::Label(UTF16ToWideHack(info_.description));
204 description_label_->SetMultiLine(true); 228 description_label_->SetMultiLine(true);
205 description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 229 description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
206 // Allow linebreaking in the middle of words if necessary, so that extremely 230 // Allow linebreaking in the middle of words if necessary, so that extremely
207 // long hostnames (longer than one line) will still be completely shown. 231 // long hostnames (longer than one line) will still be completely shown.
208 description_label_->SetAllowCharacterBreak(true); 232 description_label_->SetAllowCharacterBreak(true);
209 AddChildView(description_label_); 233 AddChildView(description_label_);
210 234
211 if (info_.type == PageInfoModel::SECTION_INFO_IDENTITY) { 235 if (info_.type == PageInfoModel::SECTION_INFO_IDENTITY && show_cert) {
212 link_ = new views::Link( 236 link_ = new views::Link(
213 l10n_util::GetString(IDS_PAGEINFO_CERT_INFO_BUTTON)); 237 l10n_util::GetString(IDS_PAGEINFO_CERT_INFO_BUTTON));
214 link_->SetController(this); 238 link_->SetController(this);
215 AddChildView(link_); 239 AddChildView(link_);
216 } 240 }
217 } 241 }
218 242
219 Section::~Section() { 243 Section::~Section() {
220 } 244 }
221 245
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } 282 }
259 if (w > 0) { 283 if (w > 0) {
260 int height = description_label_->GetHeightForWidth(w); 284 int height = description_label_->GetHeightForWidth(w);
261 if (!compute_bounds_only) 285 if (!compute_bounds_only)
262 description_label_->SetBounds(x, y, w, height); 286 description_label_->SetBounds(x, y, w, height);
263 y += height; 287 y += height;
264 } else { 288 } else {
265 if (!compute_bounds_only) 289 if (!compute_bounds_only)
266 description_label_->SetBounds(x, y, 0, 0); 290 description_label_->SetBounds(x, y, 0, 0);
267 } 291 }
268 if (info_.type == PageInfoModel::SECTION_INFO_IDENTITY) { 292 if (info_.type == PageInfoModel::SECTION_INFO_IDENTITY && link_) {
269 size = link_->GetPreferredSize(); 293 size = link_->GetPreferredSize();
270 link_->SetBounds(x, y, size.width(), size.height()); 294 link_->SetBounds(x, y, size.width(), size.height());
271 y += size.height(); 295 y += size.height();
272 } 296 }
273 297
274 // Make sure the image is not truncated if the text doesn't contain much. 298 // Make sure the image is not truncated if the text doesn't contain much.
275 y = std::max(y, image_height); 299 y = std::max(y, image_height);
276 return gfx::Size(width, y); 300 return gfx::Size(width, y);
277 } 301 }
278 302
(...skipping 18 matching lines...) Expand all
297 PageInfoBubbleView* page_info_bubble = 321 PageInfoBubbleView* page_info_bubble =
298 new PageInfoBubbleView(parent, profile, url, ssl, show_history); 322 new PageInfoBubbleView(parent, profile, url, ssl, show_history);
299 InfoBubble* info_bubble = 323 InfoBubble* info_bubble =
300 InfoBubble::Show(browser_view->GetWidget(), bounds, 324 InfoBubble::Show(browser_view->GetWidget(), bounds,
301 BubbleBorder::TOP_LEFT, 325 BubbleBorder::TOP_LEFT,
302 page_info_bubble, page_info_bubble); 326 page_info_bubble, page_info_bubble);
303 page_info_bubble->set_info_bubble(info_bubble); 327 page_info_bubble->set_info_bubble(info_bubble);
304 } 328 }
305 329
306 } 330 }
OLDNEW
« no previous file with comments | « chrome/browser/views/page_info_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698