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

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

Issue 3560004: Refactor the code for loading icons into the PageInfoModel. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: cleanup Created 10 years, 2 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
« no previous file with comments | « chrome/browser/views/page_info_bubble_view.cc ('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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "app/resource_bundle.h"
8 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
9 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
10 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/cert_store.h" 10 #include "chrome/browser/cert_store.h"
12 #include "chrome/browser/certificate_viewer.h" 11 #include "chrome/browser/certificate_viewer.h"
13 #include "chrome/browser/page_info_model.h" 12 #include "chrome/browser/page_info_model.h"
14 #include "chrome/browser/page_info_window.h" 13 #include "chrome/browser/page_info_window.h"
15 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
16 #include "grit/locale_settings.h" 15 #include "grit/locale_settings.h"
17 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
18 #include "grit/theme_resources.h"
19 #include "net/base/x509_certificate.h" 17 #include "net/base/x509_certificate.h"
20 #include "views/background.h" 18 #include "views/background.h"
21 #include "views/grid_layout.h" 19 #include "views/grid_layout.h"
22 #include "views/controls/button/native_button.h" 20 #include "views/controls/button/native_button.h"
23 #include "views/controls/button/button.h" 21 #include "views/controls/button/button.h"
24 #include "views/controls/image_view.h" 22 #include "views/controls/image_view.h"
25 #include "views/controls/label.h" 23 #include "views/controls/label.h"
26 #include "views/controls/separator.h" 24 #include "views/controls/separator.h"
27 #include "views/standard_layout.h" 25 #include "views/standard_layout.h"
28 #include "views/window/dialog_delegate.h" 26 #include "views/window/dialog_delegate.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 static int opened_window_count_; 99 static int opened_window_count_;
102 100
103 DISALLOW_COPY_AND_ASSIGN(PageInfoWindowView); 101 DISALLOW_COPY_AND_ASSIGN(PageInfoWindowView);
104 }; 102 };
105 103
106 // A section contains an image that shows a status (good or bad), a title, an 104 // A section contains an image that shows a status (good or bad), a title, an
107 // optional head-line (in bold) and a description. 105 // optional head-line (in bold) and a description.
108 class Section : public views::View { 106 class Section : public views::View {
109 public: 107 public:
110 Section(const string16& title, 108 Section(const string16& title,
111 bool state,
112 const string16& head_line, 109 const string16& head_line,
113 const string16& description); 110 const string16& description,
111 const SkBitmap* icon);
114 virtual ~Section(); 112 virtual ~Section();
115 113
116 virtual int GetHeightForWidth(int w); 114 virtual int GetHeightForWidth(int w);
117 virtual void Layout(); 115 virtual void Layout();
118 116
119 private: 117 private:
120 // The text placed on top of the section (on the left of the separator bar). 118 // The text placed on top of the section (on the left of the separator bar).
121 string16 title_; 119 string16 title_;
122 120
123 // Whether to show the good/bad icon.
124 bool state_;
125
126 // The first line of the description, show in bold. 121 // The first line of the description, show in bold.
127 string16 head_line_; 122 string16 head_line_;
128 123
129 // The description, displayed below the head line. 124 // The description, displayed below the head line.
130 string16 description_; 125 string16 description_;
131 126
132 static SkBitmap* good_state_icon_;
133 static SkBitmap* bad_state_icon_;
134
135 views::Label* title_label_; 127 views::Label* title_label_;
136 views::Separator* separator_; 128 views::Separator* separator_;
137 views::ImageView* status_image_; 129 views::ImageView* status_image_;
138 views::Label* head_line_label_; 130 views::Label* head_line_label_;
139 views::Label* description_label_; 131 views::Label* description_label_;
140 132
141 DISALLOW_COPY_AND_ASSIGN(Section); 133 DISALLOW_COPY_AND_ASSIGN(Section);
142 }; 134 };
143 135
144 // static 136 // static
145 SkBitmap* Section::good_state_icon_ = NULL;
146 SkBitmap* Section::bad_state_icon_ = NULL;
147 int PageInfoWindowView::opened_window_count_ = 0; 137 int PageInfoWindowView::opened_window_count_ = 0;
148 138
149 } // namespace 139 } // namespace
150 140
151 //////////////////////////////////////////////////////////////////////////////// 141 ////////////////////////////////////////////////////////////////////////////////
152 // PageInfoWindowViews 142 // PageInfoWindowViews
153 143
154 PageInfoWindowView::PageInfoWindowView(gfx::NativeWindow parent, 144 PageInfoWindowView::PageInfoWindowView(gfx::NativeWindow parent,
155 Profile* profile, 145 Profile* profile,
156 const GURL& url, 146 const GURL& url,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 1, // Resize weight. 200 1, // Resize weight.
211 views::GridLayout::USE_PREF, // Size type. 201 views::GridLayout::USE_PREF, // Size type.
212 0, // Ignored for USE_PREF. 202 0, // Ignored for USE_PREF.
213 0); // Minimum size. 203 0); // Minimum size.
214 columns->AddPaddingColumn(0, kHorizontalPadding); 204 columns->AddPaddingColumn(0, kHorizontalPadding);
215 205
216 layout->AddPaddingRow(0, kVerticalPadding); 206 layout->AddPaddingRow(0, kVerticalPadding);
217 for (int i = 0; i < model_.GetSectionCount(); ++i) { 207 for (int i = 0; i < model_.GetSectionCount(); ++i) {
218 PageInfoModel::SectionInfo info = model_.GetSectionInfo(i); 208 PageInfoModel::SectionInfo info = model_.GetSectionInfo(i);
219 layout->StartRow(0, 0); 209 layout->StartRow(0, 0);
220 layout->AddView(new Section( 210 layout->AddView(new Section(info.title, info.headline, info.description,
221 info.title, info.state == PageInfoModel::SECTION_STATE_OK, 211 model_.GetIconImage(info.icon_id)));
222 info.headline, info.description));
223 layout->AddPaddingRow(0, kVerticalPadding); 212 layout->AddPaddingRow(0, kVerticalPadding);
224 } 213 }
225 layout->AddPaddingRow(1, kVerticalPadding); 214 layout->AddPaddingRow(1, kVerticalPadding);
226 215
227 Layout(); 216 Layout();
228 } 217 }
229 218
230 void PageInfoWindowView::Show() { 219 void PageInfoWindowView::Show() {
231 window()->Show(); 220 window()->Show();
232 opened_window_count_++; 221 opened_window_count_++;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 316 }
328 317
329 void PageInfoWindowView::ShowCertDialog(int cert_id) { 318 void PageInfoWindowView::ShowCertDialog(int cert_id) {
330 ShowCertificateViewerByID(window()->GetNativeWindow(), cert_id); 319 ShowCertificateViewerByID(window()->GetNativeWindow(), cert_id);
331 } 320 }
332 321
333 //////////////////////////////////////////////////////////////////////////////// 322 ////////////////////////////////////////////////////////////////////////////////
334 // Section 323 // Section
335 324
336 Section::Section(const string16& title, 325 Section::Section(const string16& title,
337 bool state,
338 const string16& head_line, 326 const string16& head_line,
339 const string16& description) 327 const string16& description,
328 const SkBitmap* icon)
340 : title_(title), 329 : title_(title),
341 state_(state),
342 head_line_(head_line), 330 head_line_(head_line),
343 description_(description) { 331 description_(description) {
344 if (!good_state_icon_) {
345 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
346 good_state_icon_ = rb.GetBitmapNamed(IDR_PAGEINFO_GOOD);
347 // The exclamation point has been re-purposed as a warning
348 // signal in the new code.
349 bad_state_icon_ = rb.GetBitmapNamed(IDR_PAGEINFO_WARNING_MAJOR);
350 }
351 title_label_ = new views::Label(UTF16ToWideHack(title)); 332 title_label_ = new views::Label(UTF16ToWideHack(title));
352 title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 333 title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
353 AddChildView(title_label_); 334 AddChildView(title_label_);
354 335
355 #if defined(OS_WIN) 336 #if defined(OS_WIN)
356 separator_ = new views::Separator(); 337 separator_ = new views::Separator();
357 AddChildView(separator_); 338 AddChildView(separator_);
358 #else 339 #else
359 NOTIMPLEMENTED(); 340 NOTIMPLEMENTED();
360 #endif 341 #endif
361 342
362 status_image_ = new views::ImageView(); 343 status_image_ = new views::ImageView();
363 status_image_->SetImage(state ? good_state_icon_ : bad_state_icon_); 344 status_image_->SetImage(*icon);
364 AddChildView(status_image_); 345 AddChildView(status_image_);
365 346
366 head_line_label_ = new views::Label(UTF16ToWideHack(head_line)); 347 head_line_label_ = new views::Label(UTF16ToWideHack(head_line));
367 head_line_label_->SetFont( 348 head_line_label_->SetFont(
368 head_line_label_->font().DeriveFont(0, gfx::Font::BOLD)); 349 head_line_label_->font().DeriveFont(0, gfx::Font::BOLD));
369 head_line_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 350 head_line_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
370 AddChildView(head_line_label_); 351 AddChildView(head_line_label_);
371 352
372 description_label_ = new views::Label(UTF16ToWideHack(description)); 353 description_label_ = new views::Label(UTF16ToWideHack(description));
373 description_label_->SetMultiLine(true); 354 description_label_->SetMultiLine(true);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 Profile* profile, 430 Profile* profile,
450 const GURL& url, 431 const GURL& url,
451 const NavigationEntry::SSLStatus& ssl, 432 const NavigationEntry::SSLStatus& ssl,
452 bool show_history) { 433 bool show_history) {
453 PageInfoWindowView* page_info_window = 434 PageInfoWindowView* page_info_window =
454 new PageInfoWindowView(parent, profile, url, ssl, show_history); 435 new PageInfoWindowView(parent, profile, url, ssl, show_history);
455 page_info_window->Show(); 436 page_info_window->Show();
456 } 437 }
457 438
458 } 439 }
OLDNEW
« no previous file with comments | « chrome/browser/views/page_info_bubble_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698