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

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

Issue 2581493002: PageInfo bubble: Use the non-client view's window title and close button. (Closed)
Patch Set: const Created 3 years, 11 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/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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "ui/views/border.h" 48 #include "ui/views/border.h"
49 #include "ui/views/bubble/bubble_frame_view.h" 49 #include "ui/views/bubble/bubble_frame_view.h"
50 #include "ui/views/controls/button/image_button.h" 50 #include "ui/views/controls/button/image_button.h"
51 #include "ui/views/controls/button/md_text_button.h" 51 #include "ui/views/controls/button/md_text_button.h"
52 #include "ui/views/controls/image_view.h" 52 #include "ui/views/controls/image_view.h"
53 #include "ui/views/controls/label.h" 53 #include "ui/views/controls/label.h"
54 #include "ui/views/controls/link.h" 54 #include "ui/views/controls/link.h"
55 #include "ui/views/controls/styled_label.h" 55 #include "ui/views/controls/styled_label.h"
56 #include "ui/views/layout/box_layout.h" 56 #include "ui/views/layout/box_layout.h"
57 #include "ui/views/layout/grid_layout.h" 57 #include "ui/views/layout/grid_layout.h"
58 #include "ui/views/layout/layout_constants.h"
58 #include "ui/views/layout/layout_manager.h" 59 #include "ui/views/layout/layout_manager.h"
59 #include "ui/views/view.h" 60 #include "ui/views/view.h"
60 #include "ui/views/widget/widget.h" 61 #include "ui/views/widget/widget.h"
61 #include "url/gurl.h" 62 #include "url/gurl.h"
62 63
63 namespace { 64 namespace {
64 65
65 // NOTE(jdonnelly): This use of this process-wide variable assumes that there's 66 // NOTE(jdonnelly): This use of this process-wide variable assumes that there's
66 // never more than one website settings popup shown and that it's associated 67 // never more than one website settings popup shown and that it's associated
67 // with the current window. If this assumption fails in the future, we'll need 68 // with the current window. If this assumption fails in the future, we'll need
68 // to return a weak pointer from ShowPopup so callers can associate it with the 69 // to return a weak pointer from ShowPopup so callers can associate it with the
69 // current window (or other context) and check if the popup they care about is 70 // current window (or other context) and check if the popup they care about is
70 // showing. 71 // showing.
71 WebsiteSettingsPopupView::PopupType g_shown_popup_type = 72 WebsiteSettingsPopupView::PopupType g_shown_popup_type =
72 WebsiteSettingsPopupView::POPUP_NONE; 73 WebsiteSettingsPopupView::POPUP_NONE;
73 74
74 // General constants ----------------------------------------------------------- 75 // General constants -----------------------------------------------------------
75 76
76 // Popup width constraints. 77 // Popup width constraints.
77 const int kMinPopupWidth = 320; 78 const int kMinPopupWidth = 320;
78 const int kMaxPopupWidth = 1000; 79 const int kMaxPopupWidth = 1000;
79 80
80 // Margin and padding values shared by all sections. 81 // Margin and padding values shared by all sections.
81 const int kSectionPaddingHorizontal = 16; 82 const int kSectionPaddingHorizontal = views::kPanelHorizMargin;
82 83
83 // Padding for the bottom of the bubble. 84 // Padding for the bottom of the bubble.
84 const int kPopupMarginBottom = 16; 85 const int kPopupMarginBottom = views::kPanelVertMargin;
85 86
86 // Security Section (PopupHeaderView) ------------------------------------------ 87 // Security Section (PopupHeaderView) ------------------------------------------
87 88
88 // Margin and padding values for the |PopupHeaderView|. 89 // Margin and padding values for the |PopupHeaderView|.
89 const int kHeaderMarginBottom = 10; 90 const int kHeaderMarginBottom = 10;
90 const int kHeaderPaddingBottom = 16; 91 const int kHeaderPaddingBottom = views::kPanelVertMargin;
91 const int kHeaderPaddingTop = 16;
92 const int kHeaderPaddingForCloseButton = 8;
93 92
94 // Spacing between labels in the header. 93 // Spacing between labels in the header.
95 const int kHeaderLabelSpacing = 4; 94 const int kHeaderLabelSpacing = 4;
96 95
97 // Site Settings Section ------------------------------------------------------- 96 // Site Settings Section -------------------------------------------------------
98 97
99 // Spacing above and below the cookies view. 98 // Spacing above and below the cookies view.
100 const int kCookiesViewVerticalPadding = 6; 99 const int kCookiesViewVerticalPadding = 6;
101 100
102 // Spacing between a permission image and the text. 101 // Spacing between a permission image and the text.
103 const int kPermissionImageSpacing = 6; 102 const int kPermissionImageSpacing = 6;
104 103
105 // Spacing between rows in the site settings section 104 // Spacing between rows in the site settings section
106 const int kPermissionsVerticalSpacing = 12; 105 const int kPermissionsVerticalSpacing = 12;
107 106
108 // Button/styled label/link IDs ------------------------------------------------ 107 // Button/styled label/link IDs ------------------------------------------------
109 const int BUTTON_CLOSE = 1337; 108 const int BUTTON_CLOSE = 1337;
110 const int STYLED_LABEL_SECURITY_DETAILS = 1338; 109 const int STYLED_LABEL_SECURITY_DETAILS = 1338;
111 const int STYLED_LABEL_RESET_CERTIFICATE_DECISIONS = 1339; 110 const int STYLED_LABEL_RESET_CERTIFICATE_DECISIONS = 1339;
112 const int LINK_COOKIE_DIALOG = 1340; 111 const int LINK_COOKIE_DIALOG = 1340;
113 const int LINK_SITE_SETTINGS = 1341; 112 const int LINK_SITE_SETTINGS = 1341;
114 113
114 // The default, ui::kTitleFontSizeDelta, is too large for the website settings
115 // bubble (e.g. +3). Use +1 to obtain a smaller font.
116 constexpr int kSummaryFontSizeDelta = 1;
117
115 } // namespace 118 } // namespace
116 119
117 // |PopupHeaderView| is the UI element (view) that represents the header of the 120 // |PopupHeaderView| is the UI element (view) that represents the header of the
118 // |WebsiteSettingsPopupView|. The header shows the status of the site's 121 // |WebsiteSettingsPopupView|. The header shows the status of the site's
119 // identity check and the name of the site's identity. 122 // identity check and the name of the site's identity.
120 class PopupHeaderView : public views::View { 123 class PopupHeaderView : public views::View {
121 public: 124 public:
122 explicit PopupHeaderView(views::ButtonListener* button_listener, 125 explicit PopupHeaderView(views::ButtonListener* button_listener,
123 views::StyledLabelListener* styled_label_listener); 126 views::StyledLabelListener* styled_label_listener);
124 ~PopupHeaderView() override; 127 ~PopupHeaderView() override;
125 128
126 // Sets the security summary for the current page. 129 // Sets the security summary for the current page.
127 void SetSummary(const base::string16& summary_text); 130 void SetSummary(const base::string16& summary_text);
128 131
129 // Sets the security details for the current page. 132 // Sets the security details for the current page.
130 void SetDetails(const base::string16& details_text); 133 void SetDetails(const base::string16& details_text);
131 134
132 void AddResetDecisionsLabel(); 135 void AddResetDecisionsLabel();
133 136
134 private: 137 private:
135 // The listener for the styled labels in this view. 138 // The listener for the styled labels in this view.
136 views::StyledLabelListener* styled_label_listener_; 139 views::StyledLabelListener* styled_label_listener_;
137 140
138 // The label that displays security summary for the current page.
139 views::Label* summary_label_;
140
141 // The label that displays the status of the identity check for this site. 141 // The label that displays the status of the identity check for this site.
142 // Includes a link to open the Chrome Help Center article about connection 142 // Includes a link to open the Chrome Help Center article about connection
143 // security. 143 // security.
144 views::StyledLabel* details_label_; 144 views::StyledLabel* details_label_;
145 145
146 // A container for the styled label with a link for resetting cert decisions. 146 // A container for the styled label with a link for resetting cert decisions.
147 // This is only shown sometimes, so we use a container to keep track of 147 // This is only shown sometimes, so we use a container to keep track of
148 // where to place it (if needed). 148 // where to place it (if needed).
149 views::View* reset_decisions_label_container_; 149 views::View* reset_decisions_label_container_;
150 views::StyledLabel* reset_decisions_label_; 150 views::StyledLabel* reset_decisions_label_;
(...skipping 26 matching lines...) Expand all
177 }; 177 };
178 178
179 //////////////////////////////////////////////////////////////////////////////// 179 ////////////////////////////////////////////////////////////////////////////////
180 // Popup Header 180 // Popup Header
181 //////////////////////////////////////////////////////////////////////////////// 181 ////////////////////////////////////////////////////////////////////////////////
182 182
183 PopupHeaderView::PopupHeaderView( 183 PopupHeaderView::PopupHeaderView(
184 views::ButtonListener* button_listener, 184 views::ButtonListener* button_listener,
185 views::StyledLabelListener* styled_label_listener) 185 views::StyledLabelListener* styled_label_listener)
186 : styled_label_listener_(styled_label_listener), 186 : styled_label_listener_(styled_label_listener),
187 summary_label_(nullptr),
188 details_label_(nullptr), 187 details_label_(nullptr),
189 reset_decisions_label_container_(nullptr), 188 reset_decisions_label_container_(nullptr),
190 reset_decisions_label_(nullptr) { 189 reset_decisions_label_(nullptr) {
191 views::GridLayout* layout = new views::GridLayout(this); 190 views::GridLayout* layout = new views::GridLayout(this);
192 SetLayoutManager(layout); 191 SetLayoutManager(layout);
193 192
194 const int label_column = 0;
195 views::ColumnSet* column_set = layout->AddColumnSet(label_column);
196 column_set->AddPaddingColumn(0, kSectionPaddingHorizontal);
197 column_set->AddColumn(views::GridLayout::FILL,
198 views::GridLayout::FILL,
199 1,
200 views::GridLayout::USE_PREF,
201 0,
202 0);
203 column_set->AddPaddingColumn(1, 0);
204 column_set->AddColumn(views::GridLayout::FILL,
205 views::GridLayout::FILL,
206 1,
207 views::GridLayout::USE_PREF,
208 0,
209 0);
210 column_set->AddPaddingColumn(0, kHeaderPaddingForCloseButton);
211
212 // First we add the padding needed for the close button.
213 // In order to move down the summary, we simulate additional padding by giving
214 // it an empty border on top later on.
215 layout->AddPaddingRow(0, kHeaderPaddingForCloseButton);
216
217 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
218
219 layout->StartRow(0, label_column);
220 const gfx::FontList& font_list = rb.GetFontListWithDelta(1);
221 summary_label_ = new views::Label(base::string16(), font_list);
222 summary_label_->SetMultiLine(true);
223 summary_label_->SetBorder(views::CreateEmptyBorder(
224 kHeaderPaddingTop - kHeaderPaddingForCloseButton, 0, 0, 0));
225 layout->AddView(summary_label_, 1, 1, views::GridLayout::LEADING,
226 views::GridLayout::TRAILING);
227 views::ImageButton* close_button = new views::ImageButton(button_listener);
228 close_button->set_id(BUTTON_CLOSE);
229 close_button->SetImage(views::CustomButton::STATE_NORMAL,
230 rb.GetImageNamed(IDR_CLOSE_2).ToImageSkia());
231 close_button->SetImage(views::CustomButton::STATE_HOVERED,
232 rb.GetImageNamed(IDR_CLOSE_2_H).ToImageSkia());
233 close_button->SetImage(views::CustomButton::STATE_PRESSED,
234 rb.GetImageNamed(IDR_CLOSE_2_P).ToImageSkia());
235 layout->AddView(close_button, 1, 1, views::GridLayout::TRAILING,
236 views::GridLayout::LEADING);
237
238 layout->AddPaddingRow(0, kHeaderLabelSpacing);
239
240 const int label_column_status = 1; 193 const int label_column_status = 1;
241 views::ColumnSet* column_set_status = 194 views::ColumnSet* column_set_status =
242 layout->AddColumnSet(label_column_status); 195 layout->AddColumnSet(label_column_status);
243 column_set_status->AddPaddingColumn(0, kSectionPaddingHorizontal); 196 column_set_status->AddPaddingColumn(0, kSectionPaddingHorizontal);
244 column_set_status->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 197 column_set_status->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
245 1, views::GridLayout::USE_PREF, 0, 0); 198 1, views::GridLayout::USE_PREF, 0, 0);
246 column_set_status->AddPaddingColumn(0, kSectionPaddingHorizontal); 199 column_set_status->AddPaddingColumn(0, kSectionPaddingHorizontal);
247 200
248 layout->AddPaddingRow(0, kHeaderLabelSpacing); 201 layout->AddPaddingRow(0, kHeaderLabelSpacing);
249 202
250 layout->StartRow(0, label_column_status); 203 layout->StartRow(0, label_column_status);
251 details_label_ = 204 details_label_ =
252 new views::StyledLabel(base::string16(), styled_label_listener); 205 new views::StyledLabel(base::string16(), styled_label_listener);
253 details_label_->set_id(STYLED_LABEL_SECURITY_DETAILS); 206 details_label_->set_id(STYLED_LABEL_SECURITY_DETAILS);
254 layout->AddView(details_label_, 1, 1, views::GridLayout::FILL, 207 layout->AddView(details_label_, 1, 1, views::GridLayout::FILL,
255 views::GridLayout::LEADING); 208 views::GridLayout::LEADING);
256 209
257 layout->StartRow(0, label_column_status); 210 layout->StartRow(0, label_column_status);
258 reset_decisions_label_container_ = new views::View(); 211 reset_decisions_label_container_ = new views::View();
259 reset_decisions_label_container_->SetLayoutManager( 212 reset_decisions_label_container_->SetLayoutManager(
260 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); 213 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
261 layout->AddView(reset_decisions_label_container_, 1, 1, 214 layout->AddView(reset_decisions_label_container_, 1, 1,
262 views::GridLayout::FILL, views::GridLayout::LEADING); 215 views::GridLayout::FILL, views::GridLayout::LEADING);
263 216
264 layout->AddPaddingRow(1, kHeaderPaddingBottom); 217 layout->AddPaddingRow(1, kHeaderPaddingBottom);
265 } 218 }
266 219
267 PopupHeaderView::~PopupHeaderView() {} 220 PopupHeaderView::~PopupHeaderView() {}
268 221
269 void PopupHeaderView::SetSummary(const base::string16& summary_text) {
270 summary_label_->SetText(summary_text);
271 }
272
273 void PopupHeaderView::SetDetails(const base::string16& details_text) { 222 void PopupHeaderView::SetDetails(const base::string16& details_text) {
274 std::vector<base::string16> subst; 223 std::vector<base::string16> subst;
275 subst.push_back(details_text); 224 subst.push_back(details_text);
276 subst.push_back(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); 225 subst.push_back(l10n_util::GetStringUTF16(IDS_LEARN_MORE));
277 226
278 std::vector<size_t> offsets; 227 std::vector<size_t> offsets;
279 228
280 base::string16 text = base::ReplaceStringPlaceholders( 229 base::string16 text = base::ReplaceStringPlaceholders(
281 base::ASCIIToUTF16("$1 $2"), subst, &offsets); 230 base::ASCIIToUTF16("$1 $2"), subst, &offsets);
282 details_label_->SetText(text); 231 details_label_->SetText(text);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 layout->AddView(separator_); 428 layout->AddView(separator_);
480 429
481 layout->AddPaddingRow(1, kHeaderMarginBottom); 430 layout->AddPaddingRow(1, kHeaderMarginBottom);
482 layout->StartRow(1, content_column); 431 layout->StartRow(1, content_column);
483 432
484 site_settings_view_ = CreateSiteSettingsView(); 433 site_settings_view_ = CreateSiteSettingsView();
485 layout->AddView(site_settings_view_); 434 layout->AddView(site_settings_view_);
486 435
487 // Each section handles its own padding. 436 // Each section handles its own padding.
488 set_margins(gfx::Insets(0, 0, kPopupMarginBottom, 0)); 437 set_margins(gfx::Insets(0, 0, kPopupMarginBottom, 0));
489
490 views::BubbleDialogDelegateView::CreateBubble(this); 438 views::BubbleDialogDelegateView::CreateBubble(this);
491 439
492 presenter_.reset(new WebsiteSettings( 440 presenter_.reset(new WebsiteSettings(
493 this, profile, TabSpecificContentSettings::FromWebContents(web_contents), 441 this, profile, TabSpecificContentSettings::FromWebContents(web_contents),
494 web_contents, url, security_info)); 442 web_contents, url, security_info));
495 } 443 }
496 444
497 void WebsiteSettingsPopupView::RenderFrameDeleted( 445 void WebsiteSettingsPopupView::RenderFrameDeleted(
498 content::RenderFrameHost* render_frame_host) { 446 content::RenderFrameHost* render_frame_host) {
499 if (render_frame_host == web_contents()->GetMainFrame()) 447 if (render_frame_host == web_contents()->GetMainFrame())
(...skipping 10 matching lines...) Expand all
510 // The menu buttons for the permissions might have longer strings now, so we 458 // The menu buttons for the permissions might have longer strings now, so we
511 // need to size the whole bubble. 459 // need to size the whole bubble.
512 SizeToContents(); 460 SizeToContents();
513 } 461 }
514 462
515 void WebsiteSettingsPopupView::OnChosenObjectDeleted( 463 void WebsiteSettingsPopupView::OnChosenObjectDeleted(
516 const WebsiteSettingsUI::ChosenObjectInfo& info) { 464 const WebsiteSettingsUI::ChosenObjectInfo& info) {
517 presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object); 465 presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object);
518 } 466 }
519 467
468 base::string16 WebsiteSettingsPopupView::GetWindowTitle() const {
469 return summary_text_;
470 }
471
472 bool WebsiteSettingsPopupView::ShouldShowCloseButton() const {
473 return true;
474 }
475
520 void WebsiteSettingsPopupView::OnWidgetDestroying(views::Widget* widget) { 476 void WebsiteSettingsPopupView::OnWidgetDestroying(views::Widget* widget) {
521 g_shown_popup_type = POPUP_NONE; 477 g_shown_popup_type = POPUP_NONE;
522 presenter_->OnUIClosing(); 478 presenter_->OnUIClosing();
523 } 479 }
524 480
525 int WebsiteSettingsPopupView::GetDialogButtons() const { 481 int WebsiteSettingsPopupView::GetDialogButtons() const {
526 return ui::DIALOG_BUTTON_NONE; 482 return ui::DIALOG_BUTTON_NONE;
527 } 483 }
528 484
485 const gfx::FontList& WebsiteSettingsPopupView::GetTitleFontList() const {
486 return ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta(
487 kSummaryFontSizeDelta);
488 }
489
529 void WebsiteSettingsPopupView::ButtonPressed(views::Button* button, 490 void WebsiteSettingsPopupView::ButtonPressed(views::Button* button,
530 const ui::Event& event) { 491 const ui::Event& event) {
531 DCHECK_EQ(BUTTON_CLOSE, button->id()); 492 DCHECK_EQ(BUTTON_CLOSE, button->id());
532 GetWidget()->Close(); 493 GetWidget()->Close();
533 } 494 }
534 495
535 void WebsiteSettingsPopupView::LinkClicked(views::Link* source, 496 void WebsiteSettingsPopupView::LinkClicked(views::Link* source,
536 int event_flags) { 497 int event_flags) {
537 // The popup closes automatically when the collected cookies dialog or the 498 // The popup closes automatically when the collected cookies dialog or the
538 // certificate viewer opens. So delay handling of the link clicked to avoid 499 // certificate viewer opens. So delay handling of the link clicked to avoid
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 site_settings_view_->AddChildView(link_section); 656 site_settings_view_->AddChildView(link_section);
696 657
697 SizeToContents(); 658 SizeToContents();
698 } 659 }
699 660
700 void WebsiteSettingsPopupView::SetIdentityInfo( 661 void WebsiteSettingsPopupView::SetIdentityInfo(
701 const IdentityInfo& identity_info) { 662 const IdentityInfo& identity_info) {
702 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> security_description = 663 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> security_description =
703 identity_info.GetSecurityDescription(); 664 identity_info.GetSecurityDescription();
704 665
705 header_->SetSummary(security_description->summary); 666 summary_text_ = security_description->summary;
667 GetWidget()->UpdateWindowTitle();
706 668
707 if (identity_info.certificate) { 669 if (identity_info.certificate) {
708 certificate_ = identity_info.certificate; 670 certificate_ = identity_info.certificate;
709 671
710 if (identity_info.show_ssl_decision_revoke_button) 672 if (identity_info.show_ssl_decision_revoke_button)
711 header_->AddResetDecisionsLabel(); 673 header_->AddResetDecisionsLabel();
712 } 674 }
713 675
714 header_->SetDetails(security_description->details); 676 header_->SetDetails(security_description->details);
715 677
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 WebsiteSettings::WEBSITE_SETTINGS_CONNECTION_HELP_OPENED); 741 WebsiteSettings::WEBSITE_SETTINGS_CONNECTION_HELP_OPENED);
780 break; 742 break;
781 case STYLED_LABEL_RESET_CERTIFICATE_DECISIONS: 743 case STYLED_LABEL_RESET_CERTIFICATE_DECISIONS:
782 presenter_->OnRevokeSSLErrorBypassButtonPressed(); 744 presenter_->OnRevokeSSLErrorBypassButtonPressed();
783 GetWidget()->Close(); 745 GetWidget()->Close();
784 break; 746 break;
785 default: 747 default:
786 NOTREACHED(); 748 NOTREACHED();
787 } 749 }
788 } 750 }
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