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

Side by Side Diff: chrome/browser/ui/views/website_settings/website_settings_popup_view.cc

Issue 10830366: Avoid overriding Bubble's GetAnchorRect() where possible. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove a redundant DCHECK. Created 8 years, 4 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/ui/views/website_settings/website_settings_popup_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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/views/website_settings/website_settings_popup_view.h " 5 #include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h "
6 6
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/certificate_viewer.h" 9 #include "chrome/browser/certificate_viewer.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 const int kHeaderMarginBottom = 10; 64 const int kHeaderMarginBottom = 10;
65 const int kHeaderPaddingBottom = 12; 65 const int kHeaderPaddingBottom = 12;
66 const int kHeaderPaddingLeft = 18; 66 const int kHeaderPaddingLeft = 18;
67 const int kHeaderPaddingRight = 8; 67 const int kHeaderPaddingRight = 8;
68 const int kHeaderPaddingTop = 12; 68 const int kHeaderPaddingTop = 12;
69 69
70 // Spacing between the site identity label and the site identity status text in 70 // Spacing between the site identity label and the site identity status text in
71 // the popup header. 71 // the popup header.
72 const int kHeaderRowSpacing = 4; 72 const int kHeaderRowSpacing = 4;
73 73
74 // In order to make the arrow of the bubble point directly at the location icon 74 // To make the bubble's arrow point directly at the location icon rather than at
75 // in the Omnibox rather then the bottom border of the Omnibox, the position of 75 // the Omnibox's edge, inset the bubble's anchor rect by this amount of pixels.
76 // the bubble must be adjusted. This is the number of pixel the bubble must be 76 const int kLocationIconVerticalMargin = 5;
77 // moved towards the top of the screen (starting from the bottom border of the
78 // Omnibox).
79 const int kLocationIconBottomMargin = 5;
80 77
81 // The margins between the popup border and the popup content. 78 // The margins between the popup border and the popup content.
82 const int kPopupMarginTop = 4; 79 const int kPopupMarginTop = 4;
83 const int kPopupMarginLeft = 0; 80 const int kPopupMarginLeft = 0;
84 const int kPopupMarginBottom = 10; 81 const int kPopupMarginBottom = 10;
85 const int kPopupMarginRight = 0; 82 const int kPopupMarginRight = 0;
86 83
87 // Padding values for sections on the permissions tab. 84 // Padding values for sections on the permissions tab.
88 const int kPermissionsSectionPaddingBottom = 6; 85 const int kPermissionsSectionPaddingBottom = 6;
89 const int kPermissionsSectionPaddingLeft = 18; 86 const int kPermissionsSectionPaddingLeft = 18;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 133
137 // Website Settings are not supported for internal Chrome pages. Instead of the 134 // Website Settings are not supported for internal Chrome pages. Instead of the
138 // |WebsiteSettingsPopupView|, the |InternalPageInfoPopupView| is 135 // |WebsiteSettingsPopupView|, the |InternalPageInfoPopupView| is
139 // displayed. 136 // displayed.
140 class InternalPageInfoPopupView : public views::BubbleDelegateView { 137 class InternalPageInfoPopupView : public views::BubbleDelegateView {
141 public: 138 public:
142 explicit InternalPageInfoPopupView(views::View* anchor_view); 139 explicit InternalPageInfoPopupView(views::View* anchor_view);
143 virtual ~InternalPageInfoPopupView(); 140 virtual ~InternalPageInfoPopupView();
144 141
145 private: 142 private:
146 // views::BubbleDelegate implementations.
147 virtual gfx::Rect GetAnchorRect() OVERRIDE;
148
149 DISALLOW_COPY_AND_ASSIGN(InternalPageInfoPopupView); 143 DISALLOW_COPY_AND_ASSIGN(InternalPageInfoPopupView);
150 }; 144 };
151 145
152 //////////////////////////////////////////////////////////////////////////////// 146 ////////////////////////////////////////////////////////////////////////////////
153 // Popup Header 147 // Popup Header
154 //////////////////////////////////////////////////////////////////////////////// 148 ////////////////////////////////////////////////////////////////////////////////
155 149
156 PopupHeaderView::PopupHeaderView(views::ButtonListener* close_button_listener) 150 PopupHeaderView::PopupHeaderView(views::ButtonListener* close_button_listener)
157 : name_(NULL), status_(NULL) { 151 : name_(NULL), status_(NULL) {
158 views::GridLayout* layout = new views::GridLayout(this); 152 views::GridLayout* layout = new views::GridLayout(this);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 status_->SetText(status); 215 status_->SetText(status);
222 status_->SetEnabledColor(text_color); 216 status_->SetEnabledColor(text_color);
223 } 217 }
224 218
225 //////////////////////////////////////////////////////////////////////////////// 219 ////////////////////////////////////////////////////////////////////////////////
226 // InternalPageInfoPopupView 220 // InternalPageInfoPopupView
227 //////////////////////////////////////////////////////////////////////////////// 221 ////////////////////////////////////////////////////////////////////////////////
228 222
229 InternalPageInfoPopupView::InternalPageInfoPopupView(views::View* anchor_view) 223 InternalPageInfoPopupView::InternalPageInfoPopupView(views::View* anchor_view)
230 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT) { 224 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT) {
225 // Compensate for built-in vertical padding in the anchor view's image.
226 set_anchor_insets(gfx::Insets(kLocationIconVerticalMargin, 0,
227 kLocationIconVerticalMargin, 0));
228
231 const int kSpacing = 4; 229 const int kSpacing = 4;
232 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, kSpacing, 230 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, kSpacing,
233 kSpacing, kSpacing)); 231 kSpacing, kSpacing));
234 views::ImageView* icon_view = new views::ImageView(); 232 views::ImageView* icon_view = new views::ImageView();
235 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 233 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
236 icon_view->SetImage(rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_26)); 234 icon_view->SetImage(rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_26));
237 AddChildView(icon_view); 235 AddChildView(icon_view);
238 236
239 views::Label* label = 237 views::Label* label =
240 new views::Label(l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE)); 238 new views::Label(l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE));
241 label->SetMultiLine(true); 239 label->SetMultiLine(true);
242 label->SetAllowCharacterBreak(true); 240 label->SetAllowCharacterBreak(true);
243 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 241 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
244 AddChildView(label); 242 AddChildView(label);
245 243
246 views::BubbleDelegateView::CreateBubble(this); 244 views::BubbleDelegateView::CreateBubble(this);
247 Show(); 245 Show();
248 SizeToContents(); 246 SizeToContents();
249 } 247 }
250 248
251 InternalPageInfoPopupView::~InternalPageInfoPopupView() { 249 InternalPageInfoPopupView::~InternalPageInfoPopupView() {
252 } 250 }
253 251
254 gfx::Rect InternalPageInfoPopupView::GetAnchorRect() {
255 // Compensate for some built-in padding in the icon. This will make the arrow
256 // point to the middle of the icon.
257 gfx::Rect anchor(BubbleDelegateView::GetAnchorRect());
258 anchor.Inset(0, anchor_view() ? kLocationIconBottomMargin : 0);
259 return anchor;
260 }
261
262 //////////////////////////////////////////////////////////////////////////////// 252 ////////////////////////////////////////////////////////////////////////////////
263 // WebsiteSettingsPopupView 253 // WebsiteSettingsPopupView
264 //////////////////////////////////////////////////////////////////////////////// 254 ////////////////////////////////////////////////////////////////////////////////
265 255
266 WebsiteSettingsPopupView::~WebsiteSettingsPopupView() { 256 WebsiteSettingsPopupView::~WebsiteSettingsPopupView() {
267 } 257 }
268 258
269 // static 259 // static
270 void WebsiteSettingsPopupView::ShowPopup(views::View* anchor_view, 260 void WebsiteSettingsPopupView::ShowPopup(views::View* anchor_view,
271 Profile* profile, 261 Profile* profile,
(...skipping 17 matching lines...) Expand all
289 header_(NULL), 279 header_(NULL),
290 tabbed_pane_(NULL), 280 tabbed_pane_(NULL),
291 site_data_content_(NULL), 281 site_data_content_(NULL),
292 cookie_dialog_link_(NULL), 282 cookie_dialog_link_(NULL),
293 permissions_content_(NULL), 283 permissions_content_(NULL),
294 identity_info_content_(NULL), 284 identity_info_content_(NULL),
295 certificate_dialog_link_(NULL), 285 certificate_dialog_link_(NULL),
296 cert_id_(0), 286 cert_id_(0),
297 connection_info_content_(NULL), 287 connection_info_content_(NULL),
298 page_info_content_(NULL) { 288 page_info_content_(NULL) {
299 views::GridLayout* layout = new views::GridLayout(this); 289 // Compensate for built-in vertical padding in the anchor view's image.
300 SetLayoutManager(layout); 290 set_anchor_insets(gfx::Insets(kLocationIconVerticalMargin, 0,
301 const int content_column = 0; 291 kLocationIconVerticalMargin, 0));
302 views::ColumnSet* column_set = layout->AddColumnSet(content_column);
303 column_set->AddColumn(views::GridLayout::FILL,
304 views::GridLayout::FILL,
305 1,
306 views::GridLayout::USE_PREF,
307 0,
308 0);
309 292
310 header_ = new PopupHeaderView(this); 293 views::GridLayout* layout = new views::GridLayout(this);
311 layout->StartRow(1, content_column); 294 SetLayoutManager(layout);
312 layout->AddView(header_); 295 const int content_column = 0;
296 views::ColumnSet* column_set = layout->AddColumnSet(content_column);
297 column_set->AddColumn(views::GridLayout::FILL,
298 views::GridLayout::FILL,
299 1,
300 views::GridLayout::USE_PREF,
301 0,
302 0);
313 303
314 layout->AddPaddingRow(1, kHeaderMarginBottom); 304 header_ = new PopupHeaderView(this);
315 tabbed_pane_ = new views::TabbedPane(); 305 layout->StartRow(1, content_column);
316 layout->StartRow(1, content_column); 306 layout->AddView(header_);
317 layout->AddView(tabbed_pane_);
318 // Tabs must be added after the tabbed_pane_ was added to the views
319 // hierachy. Adding the |tabbed_pane_| to the views hierachy triggers the
320 // initialization of the native tab UI element. If the native tab UI
321 // element is not initalized adding a tab will result in a NULL pointer
322 // excetion.
323 tabbed_pane_->AddTab(
324 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TAB_LABEL_PERMISSIONS),
325 CreatePermissionsTab());
326 tabbed_pane_->AddTab(
327 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TAB_LABEL_CONNECTION),
328 CreateConnectionTab());
329 tabbed_pane_->SelectTabAt(0);
330 tabbed_pane_->set_listener(this);
331 307
332 set_margins(gfx::Insets(kPopupMarginTop, kPopupMarginLeft, 308 layout->AddPaddingRow(1, kHeaderMarginBottom);
333 kPopupMarginBottom, kPopupMarginRight)); 309 tabbed_pane_ = new views::TabbedPane();
310 layout->StartRow(1, content_column);
311 layout->AddView(tabbed_pane_);
312 // Tabs must be added after the tabbed_pane_ was added to the views
313 // hierachy. Adding the |tabbed_pane_| to the views hierachy triggers the
314 // initialization of the native tab UI element. If the native tab UI
315 // element is not initalized adding a tab will result in a NULL pointer
316 // excetion.
317 tabbed_pane_->AddTab(
318 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TAB_LABEL_PERMISSIONS),
319 CreatePermissionsTab());
320 tabbed_pane_->AddTab(
321 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TAB_LABEL_CONNECTION),
322 CreateConnectionTab());
323 tabbed_pane_->SelectTabAt(0);
324 tabbed_pane_->set_listener(this);
334 325
335 views::BubbleDelegateView::CreateBubble(this); 326 set_margins(gfx::Insets(kPopupMarginTop, kPopupMarginLeft,
336 this->Show(); 327 kPopupMarginBottom, kPopupMarginRight));
337 SizeToContents();
338 328
339 presenter_.reset(new WebsiteSettings(this, profile, 329 views::BubbleDelegateView::CreateBubble(this);
340 tab_contents->content_settings(), 330 this->Show();
341 tab_contents->infobar_tab_helper(), 331 SizeToContents();
342 url, 332
343 ssl, 333 presenter_.reset(new WebsiteSettings(this, profile,
344 content::CertStore::GetInstance())); 334 tab_contents->content_settings(),
335 tab_contents->infobar_tab_helper(),
336 url,
337 ssl,
338 content::CertStore::GetInstance()));
345 } 339 }
346 340
347 void WebsiteSettingsPopupView::OnPermissionChanged( 341 void WebsiteSettingsPopupView::OnPermissionChanged(
348 PermissionSelectorView* permission_selector) { 342 PermissionSelectorView* permission_selector) {
349 DCHECK(permission_selector); 343 DCHECK(permission_selector);
350 presenter_->OnSitePermissionChanged( 344 presenter_->OnSitePermissionChanged(
351 permission_selector->GetPermissionType(), 345 permission_selector->GetPermissionType(),
352 permission_selector->GetSelectedSetting()); 346 permission_selector->GetSelectedSetting());
353 } 347 }
354 348
355 gfx::Rect WebsiteSettingsPopupView::GetAnchorRect() {
356 // Compensate for some built-in padding in the icon. This will make the arrow
357 // point to the middle of the icon.
358 gfx::Rect anchor(BubbleDelegateView::GetAnchorRect());
359 anchor.Inset(0, anchor_view() ? kLocationIconBottomMargin : 0);
360 return anchor;
361 }
362
363 void WebsiteSettingsPopupView::OnWidgetClosing(views::Widget* widget) { 349 void WebsiteSettingsPopupView::OnWidgetClosing(views::Widget* widget) {
364 presenter_->OnUIClosing(); 350 presenter_->OnUIClosing();
365 } 351 }
366 352
367 void WebsiteSettingsPopupView::ButtonPressed( 353 void WebsiteSettingsPopupView::ButtonPressed(
368 views::Button* button, 354 views::Button* button,
369 const ui::Event& event) { 355 const ui::Event& event) {
370 GetWidget()->Close(); 356 GetWidget()->Close();
371 } 357 }
372 358
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 694
709 if (link) { 695 if (link) {
710 content_layout->StartRow(1, 0); 696 content_layout->StartRow(1, 0);
711 content_layout->AddView(link); 697 content_layout->AddView(link);
712 } 698 }
713 699
714 layout->AddView(content_pane, 1, 1, views::GridLayout::LEADING, 700 layout->AddView(content_pane, 1, 1, views::GridLayout::LEADING,
715 views::GridLayout::LEADING); 701 views::GridLayout::LEADING);
716 layout->AddPaddingRow(0, kConnectionSectionPaddingBottom); 702 layout->AddPaddingRow(0, kConnectionSectionPaddingBottom);
717 } 703 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/website_settings/website_settings_popup_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698