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

Side by Side Diff: chrome/browser/views/page_info_bubble_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/page_info_model.cc ('k') | chrome/browser/views/page_info_window_view.cc » ('j') | 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"
9 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/browser_list.h" 9 #include "chrome/browser/browser_list.h"
11 #include "chrome/browser/certificate_viewer.h" 10 #include "chrome/browser/certificate_viewer.h"
12 #include "chrome/browser/views/frame/browser_view.h" 11 #include "chrome/browser/views/frame/browser_view.h"
13 #include "chrome/browser/views/info_bubble.h" 12 #include "chrome/browser/views/info_bubble.h"
14 #include "chrome/browser/views/toolbar_view.h" 13 #include "chrome/browser/views/toolbar_view.h"
15 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
16 #include "grit/locale_settings.h" 15 #include "grit/locale_settings.h"
17 #include "grit/theme_resources.h"
18 #include "views/controls/image_view.h" 16 #include "views/controls/image_view.h"
19 #include "views/controls/label.h" 17 #include "views/controls/label.h"
20 #include "views/controls/separator.h" 18 #include "views/controls/separator.h"
21 #include "views/grid_layout.h" 19 #include "views/grid_layout.h"
22 #include "views/widget/widget.h" 20 #include "views/widget/widget.h"
23 #include "views/window/window.h" 21 #include "views/window/window.h"
24 22
25 namespace { 23 namespace {
26 24
27 // Layout constants. 25 // Layout constants.
28 const int kHGapToBorder = 11; 26 const int kHGapToBorder = 11;
29 const int kVGapToImage = 10; 27 const int kVGapToImage = 10;
30 const int kVGapToHeadline = 7; 28 const int kVGapToHeadline = 7;
31 const int kHGapImageToDescription = 6; 29 const int kHGapImageToDescription = 6;
32 const int kTextPaddingRight = 10; 30 const int kTextPaddingRight = 10;
33 const int kPaddingBelowSeparator = 4; 31 const int kPaddingBelowSeparator = 4;
34 const int kPaddingAboveSeparator = 13; 32 const int kPaddingAboveSeparator = 13;
35 const int kIconOffset = 28; 33 const int kIconOffset = 28;
36 34
37 // A section contains an image that shows a status (good or bad), a title, an 35 // A section contains an image that shows a status (good or bad), a title, an
38 // optional head-line (in bold) and a description. 36 // optional head-line (in bold) and a description.
39 class Section : public views::View, 37 class Section : public views::View,
40 public views::LinkController { 38 public views::LinkController {
41 public: 39 public:
42 Section(PageInfoBubbleView* owner, 40 Section(PageInfoBubbleView* owner,
43 const PageInfoModel::SectionInfo& section_info, 41 const PageInfoModel::SectionInfo& section_info,
42 const SkBitmap* status_icon,
44 bool show_cert); 43 bool show_cert);
45 virtual ~Section(); 44 virtual ~Section();
46 45
47 // views::View methods: 46 // views::View methods:
48 virtual int GetHeightForWidth(int w); 47 virtual int GetHeightForWidth(int w);
49 virtual void Layout(); 48 virtual void Layout();
50 49
51 // views::LinkController methods: 50 // views::LinkController methods:
52 virtual void LinkActivated(views::Link* source, int event_flags); 51 virtual void LinkActivated(views::Link* source, int event_flags);
53 52
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 views::GridLayout::USE_PREF, // Size type. 107 views::GridLayout::USE_PREF, // Size type.
109 0, // Ignored for USE_PREF. 108 0, // Ignored for USE_PREF.
110 0); // Minimum size. 109 0); // Minimum size.
111 110
112 int count = model_.GetSectionCount(); 111 int count = model_.GetSectionCount();
113 for (int i = 0; i < count; ++i) { 112 for (int i = 0; i < count; ++i) {
114 PageInfoModel::SectionInfo info = model_.GetSectionInfo(i); 113 PageInfoModel::SectionInfo info = model_.GetSectionInfo(i);
115 layout->StartRow(0, 0); 114 layout->StartRow(0, 0);
116 // TODO(finnur): Remove title from the info struct, since it is 115 // TODO(finnur): Remove title from the info struct, since it is
117 // not used anymore. 116 // not used anymore.
118 layout->AddView(new Section(this, info, cert_id_ > 0)); 117 const SkBitmap* icon = model_.GetIconImage(info.icon_id);
118 layout->AddView(new Section(this, info, icon, cert_id_ > 0));
119 119
120 // Add separator after all sections. 120 // Add separator after all sections.
121 layout->AddPaddingRow(0, kPaddingAboveSeparator); 121 layout->AddPaddingRow(0, kPaddingAboveSeparator);
122 layout->StartRow(0, 0); 122 layout->StartRow(0, 0);
123 layout->AddView(new views::Separator()); 123 layout->AddView(new views::Separator());
124 layout->AddPaddingRow(0, kPaddingBelowSeparator); 124 layout->AddPaddingRow(0, kPaddingBelowSeparator);
125 } 125 }
126 126
127 // Then add the help center link at the bottom. 127 // Then add the help center link at the bottom.
128 layout->StartRow(0, 0); 128 layout->StartRow(0, 0);
129 help_center_link_ = 129 help_center_link_ =
130 new views::Link(l10n_util::GetString(IDS_PAGE_INFO_HELP_CENTER_LINK)); 130 new views::Link(l10n_util::GetString(IDS_PAGE_INFO_HELP_CENTER_LINK));
131 help_center_link_->SetController(this); 131 help_center_link_->SetController(this);
132 layout->AddView(help_center_link_); 132 layout->AddView(help_center_link_);
133 } 133 }
134 134
135 gfx::Size PageInfoBubbleView::GetPreferredSize() { 135 gfx::Size PageInfoBubbleView::GetPreferredSize() {
136 gfx::Size size(views::Window::GetLocalizedContentsSize( 136 gfx::Size size(views::Window::GetLocalizedContentsSize(
137 IDS_PAGEINFOBUBBLE_WIDTH_CHARS, IDS_PAGEINFOBUBBLE_HEIGHT_LINES)); 137 IDS_PAGEINFOBUBBLE_WIDTH_CHARS, IDS_PAGEINFOBUBBLE_HEIGHT_LINES));
138 size.set_height(0); 138 size.set_height(0);
139 139
140 int count = model_.GetSectionCount(); 140 int count = model_.GetSectionCount();
141 for (int i = 0; i < count; ++i) { 141 for (int i = 0; i < count; ++i) {
142 PageInfoModel::SectionInfo info = model_.GetSectionInfo(i); 142 PageInfoModel::SectionInfo info = model_.GetSectionInfo(i);
143 Section section(this, info, cert_id_ > 0); 143 const SkBitmap* icon = model_.GetIconImage(info.icon_id);
144 Section section(this, info, icon, cert_id_ > 0);
144 size.Enlarge(0, section.GetHeightForWidth(size.width())); 145 size.Enlarge(0, section.GetHeightForWidth(size.width()));
145 } 146 }
146 147
147 // Calculate how much space the separators take up (with padding). 148 // Calculate how much space the separators take up (with padding).
148 views::Separator separator; 149 views::Separator separator;
149 gfx::Size separator_size = separator.GetPreferredSize(); 150 gfx::Size separator_size = separator.GetPreferredSize();
150 gfx::Size separator_plus_padding(0, separator_size.height() + 151 gfx::Size separator_plus_padding(0, separator_size.height() +
151 kPaddingAboveSeparator + 152 kPaddingAboveSeparator +
152 kPaddingBelowSeparator); 153 kPaddingBelowSeparator);
153 154
(...skipping 17 matching lines...) Expand all
171 GURL url = GURL(l10n_util::GetStringUTF16(IDS_PAGE_INFO_HELP_CENTER)); 172 GURL url = GURL(l10n_util::GetStringUTF16(IDS_PAGE_INFO_HELP_CENTER));
172 Browser* browser = BrowserList::GetLastActive(); 173 Browser* browser = BrowserList::GetLastActive();
173 browser->OpenURL(url, GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); 174 browser->OpenURL(url, GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK);
174 } 175 }
175 176
176 //////////////////////////////////////////////////////////////////////////////// 177 ////////////////////////////////////////////////////////////////////////////////
177 // Section 178 // Section
178 179
179 Section::Section(PageInfoBubbleView* owner, 180 Section::Section(PageInfoBubbleView* owner,
180 const PageInfoModel::SectionInfo& section_info, 181 const PageInfoModel::SectionInfo& section_info,
182 const SkBitmap* state_icon,
181 bool show_cert) 183 bool show_cert)
182 : owner_(owner), 184 : owner_(owner),
183 info_(section_info), 185 info_(section_info),
184 status_image_(NULL), 186 status_image_(NULL),
185 link_(NULL) { 187 link_(NULL) {
186 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 188 if (state_icon) {
187
188 if (info_.type == PageInfoModel::SECTION_INFO_IDENTITY ||
189 info_.type == PageInfoModel::SECTION_INFO_CONNECTION) {
190 status_image_ = new views::ImageView(); 189 status_image_ = new views::ImageView();
191 switch (info_.state) { 190 status_image_->SetImage(*state_icon);
192 case PageInfoModel::SECTION_STATE_OK:
193 status_image_->SetImage(rb.GetBitmapNamed(IDR_PAGEINFO_GOOD));
194 break;
195 case PageInfoModel::SECTION_STATE_WARNING_MAJOR:
196 status_image_->SetImage(rb.GetBitmapNamed(IDR_PAGEINFO_WARNING_MAJOR));
197 break;
198 case PageInfoModel::SECTION_STATE_WARNING_MINOR:
199 status_image_->SetImage(rb.GetBitmapNamed(IDR_PAGEINFO_WARNING_MINOR));
200 break;
201 case PageInfoModel::SECTION_STATE_ERROR:
202 status_image_->SetImage(rb.GetBitmapNamed(IDR_PAGEINFO_BAD));
203 break;
204 default:
205 NOTREACHED(); // Do you need to add a case here?
206 }
207 AddChildView(status_image_);
208 } else if (info_.type == PageInfoModel::SECTION_INFO_FIRST_VISIT) {
209 status_image_ = new views::ImageView();
210 status_image_->SetImage(info_.state == PageInfoModel::SECTION_STATE_OK ?
211 rb.GetBitmapNamed(IDR_PAGEINFO_INFO) :
212 rb.GetBitmapNamed(IDR_PAGEINFO_WARNING_MAJOR));
213 AddChildView(status_image_); 191 AddChildView(status_image_);
214 } 192 }
215 193
216 headline_label_ = new views::Label(UTF16ToWideHack(info_.headline)); 194 headline_label_ = new views::Label(UTF16ToWideHack(info_.headline));
217 headline_label_->SetFont( 195 headline_label_->SetFont(
218 headline_label_->font().DeriveFont(0, gfx::Font::BOLD)); 196 headline_label_->font().DeriveFont(0, gfx::Font::BOLD));
219 headline_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 197 headline_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
220 AddChildView(headline_label_); 198 AddChildView(headline_label_);
221 199
222 description_label_ = new views::Label(UTF16ToWideHack(info_.description)); 200 description_label_ = new views::Label(UTF16ToWideHack(info_.description));
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 PageInfoBubbleView* page_info_bubble = 298 PageInfoBubbleView* page_info_bubble =
321 new PageInfoBubbleView(parent, profile, url, ssl, show_history); 299 new PageInfoBubbleView(parent, profile, url, ssl, show_history);
322 InfoBubble* info_bubble = 300 InfoBubble* info_bubble =
323 InfoBubble::Show(browser_view->GetWidget(), bounds, 301 InfoBubble::Show(browser_view->GetWidget(), bounds,
324 BubbleBorder::TOP_LEFT, 302 BubbleBorder::TOP_LEFT,
325 page_info_bubble, page_info_bubble); 303 page_info_bubble, page_info_bubble);
326 page_info_bubble->set_info_bubble(info_bubble); 304 page_info_bubble->set_info_bubble(info_bubble);
327 } 305 }
328 306
329 } 307 }
OLDNEW
« no previous file with comments | « chrome/browser/page_info_model.cc ('k') | chrome/browser/views/page_info_window_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698