OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/permissions_bubble_view.h" | 5 #include "chrome/browser/ui/views/website_settings/permissions_bubble_view.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h" | 8 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h" |
9 #include "chrome/browser/ui/views/website_settings/permission_selector_view_obse rver.h" | 9 #include "chrome/browser/ui/views/website_settings/permission_selector_view_obse rver.h" |
10 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 10 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 #include "ui/views/controls/combobox/combobox.h" | 24 #include "ui/views/controls/combobox/combobox.h" |
25 #include "ui/views/controls/combobox/combobox_listener.h" | 25 #include "ui/views/controls/combobox/combobox_listener.h" |
26 #include "ui/views/controls/label.h" | 26 #include "ui/views/controls/label.h" |
27 #include "ui/views/controls/menu/menu_runner.h" | 27 #include "ui/views/controls/menu/menu_runner.h" |
28 #include "ui/views/layout/box_layout.h" | 28 #include "ui/views/layout/box_layout.h" |
29 #include "ui/views/layout/grid_layout.h" | 29 #include "ui/views/layout/grid_layout.h" |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 // Spacing constant for outer margin. This is added to the | 33 // Spacing constant for outer margin. This is added to the |
34 // bubble margin itself to equalize the margins at 20px. | 34 // bubble margin itself to equalize the margins at 13px. |
35 const int kBubbleOuterMargin = 12; | 35 const int kBubbleOuterMargin = 5; |
36 | 36 |
37 // Spacing between major items should be 10px. | 37 // Spacing between major items should be 9px. |
38 const int kItemMajorSpacing = 10; | 38 const int kItemMajorSpacing = 9; |
39 | 39 |
40 // Button border size, draws inside the spacing distance. | 40 // Button border size, draws inside the spacing distance. |
41 const int kButtonBorderSize = 2; | 41 const int kButtonBorderSize = 2; |
42 | 42 |
43 // (Square) pixel size of icon. | |
44 const int kIconSize = 18; | |
45 | |
46 // Number of pixels to indent the permission request labels. | |
47 const int kPermissionIndentSize = 12; | |
Justin Donnelly
2014/06/18 14:12:47
s/Size/Spacing/ for consistency with parameter nam
Greg Billock
2014/06/19 16:42:33
Done.
| |
48 | |
43 } // namespace | 49 } // namespace |
44 | 50 |
45 // This class is a MenuButton which is given a PermissionMenuModel. It | 51 // This class is a MenuButton which is given a PermissionMenuModel. It |
46 // shows the current checked item in the menu model, and notifies its listener | 52 // shows the current checked item in the menu model, and notifies its listener |
47 // about any updates to the state of the selection. | 53 // about any updates to the state of the selection. |
48 // TODO: refactor PermissionMenuButton to work like this and re-use? | 54 // TODO: refactor PermissionMenuButton to work like this and re-use? |
49 class PermissionCombobox : public views::MenuButton, | 55 class PermissionCombobox : public views::MenuButton, |
50 public views::MenuButtonListener { | 56 public views::MenuButtonListener { |
51 public: | 57 public: |
52 // Get notifications when the selection changes. | 58 // Get notifications when the selection changes. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 else | 161 else |
156 return l10n_util::GetStringUTF16(IDS_PERMISSION_CUSTOMIZE); | 162 return l10n_util::GetStringUTF16(IDS_PERMISSION_CUSTOMIZE); |
157 } | 163 } |
158 | 164 |
159 int CustomizeAllowComboboxModel::GetDefaultIndex() const { | 165 int CustomizeAllowComboboxModel::GetDefaultIndex() const { |
160 return INDEX_ALLOW; | 166 return INDEX_ALLOW; |
161 } | 167 } |
162 | 168 |
163 /////////////////////////////////////////////////////////////////////////////// | 169 /////////////////////////////////////////////////////////////////////////////// |
164 // View implementation for the permissions bubble. | 170 // View implementation for the permissions bubble. |
165 | |
166 class PermissionsBubbleDelegateView : public views::BubbleDelegateView, | 171 class PermissionsBubbleDelegateView : public views::BubbleDelegateView, |
167 public views::ButtonListener, | 172 public views::ButtonListener, |
168 public views::ComboboxListener, | 173 public views::ComboboxListener, |
169 public PermissionCombobox::Listener { | 174 public PermissionCombobox::Listener { |
170 public: | 175 public: |
171 PermissionsBubbleDelegateView( | 176 PermissionsBubbleDelegateView( |
172 views::View* anchor, | 177 views::View* anchor, |
173 PermissionBubbleViewViews* owner, | 178 PermissionBubbleViewViews* owner, |
174 const std::vector<PermissionBubbleRequest*>& requests, | 179 const std::vector<PermissionBubbleRequest*>& requests, |
175 const std::vector<bool>& accept_state, | 180 const std::vector<bool>& accept_state, |
176 bool customization_mode); | 181 bool customization_mode); |
177 virtual ~PermissionsBubbleDelegateView(); | 182 virtual ~PermissionsBubbleDelegateView(); |
178 | 183 |
179 void Close(); | 184 void Close(); |
180 void SizeToContents(); | 185 void SizeToContents(); |
181 | 186 |
182 // BubbleDelegateView: | 187 // BubbleDelegateView: |
183 virtual bool ShouldShowCloseButton() const OVERRIDE; | 188 virtual bool ShouldShowCloseButton() const OVERRIDE; |
184 virtual bool ShouldShowWindowTitle() const OVERRIDE; | 189 virtual bool ShouldShowWindowTitle() const OVERRIDE; |
190 virtual const gfx::FontList& GetTitleFontList() const OVERRIDE; | |
Justin Donnelly
2014/06/18 14:12:47
Do you intend to use this somewhere else?
Greg Billock
2014/06/19 16:42:33
This is an override of a (new) bubble delegate met
| |
185 virtual base::string16 GetWindowTitle() const OVERRIDE; | 191 virtual base::string16 GetWindowTitle() const OVERRIDE; |
186 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; | 192 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; |
187 | 193 |
188 // ButtonListener: | 194 // ButtonListener: |
189 virtual void ButtonPressed(views::Button* button, | 195 virtual void ButtonPressed(views::Button* button, |
190 const ui::Event& event) OVERRIDE; | 196 const ui::Event& event) OVERRIDE; |
191 | 197 |
192 // ComboboxListener: | 198 // ComboboxListener: |
193 virtual void OnPerformAction(views::Combobox* combobox) OVERRIDE; | 199 virtual void OnPerformAction(views::Combobox* combobox) OVERRIDE; |
194 | 200 |
(...skipping 27 matching lines...) Expand all Loading... | |
222 DCHECK(!requests.empty()); | 228 DCHECK(!requests.empty()); |
223 | 229 |
224 RemoveAllChildViews(true); | 230 RemoveAllChildViews(true); |
225 customize_comboboxes_.clear(); | 231 customize_comboboxes_.clear(); |
226 set_close_on_esc(false); | 232 set_close_on_esc(false); |
227 set_close_on_deactivate(false); | 233 set_close_on_deactivate(false); |
228 | 234 |
229 SetLayoutManager(new views::BoxLayout( | 235 SetLayoutManager(new views::BoxLayout( |
230 views::BoxLayout::kVertical, kBubbleOuterMargin, 0, kItemMajorSpacing)); | 236 views::BoxLayout::kVertical, kBubbleOuterMargin, 0, kItemMajorSpacing)); |
231 | 237 |
232 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
233 | |
234 // TODO(gbillock): account for different requests from different hosts. | 238 // TODO(gbillock): account for different requests from different hosts. |
235 hostname_ = requests[0]->GetRequestingHostname().host(); | 239 hostname_ = requests[0]->GetRequestingHostname().host(); |
236 | 240 |
237 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 241 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
238 for (size_t index = 0; index < requests.size(); index++) { | 242 for (size_t index = 0; index < requests.size(); index++) { |
239 DCHECK(index < accept_state.size()); | 243 DCHECK(index < accept_state.size()); |
240 // The row is laid out containing a leading-aligned label area and a | 244 // The row is laid out containing a leading-aligned label area and a |
241 // trailing column which will be filled during customization with a | 245 // trailing column which will be filled during customization with a |
242 // combobox. | 246 // combobox. |
243 views::View* row = new views::View(); | 247 views::View* row = new views::View(); |
244 views::GridLayout* row_layout = new views::GridLayout(row); | 248 views::GridLayout* row_layout = new views::GridLayout(row); |
245 row->SetLayoutManager(row_layout); | 249 row->SetLayoutManager(row_layout); |
246 views::ColumnSet* columns = row_layout->AddColumnSet(0); | 250 views::ColumnSet* columns = row_layout->AddColumnSet(0); |
247 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, | 251 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, |
248 0, views::GridLayout::USE_PREF, 0, 0); | 252 0, views::GridLayout::USE_PREF, 0, 0); |
249 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, | 253 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, |
250 100, views::GridLayout::USE_PREF, 0, 0); | 254 100, views::GridLayout::USE_PREF, 0, 0); |
251 row_layout->StartRow(0, 0); | 255 row_layout->StartRow(0, 0); |
252 | 256 |
253 views::View* label_container = new views::View(); | 257 views::View* label_container = new views::View(); |
254 label_container->SetLayoutManager( | 258 label_container->SetLayoutManager( |
255 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 5)); | 259 new views::BoxLayout(views::BoxLayout::kHorizontal, |
260 kPermissionIndentSize, | |
261 0, kBubbleOuterMargin)); | |
256 views::ImageView* icon = new views::ImageView(); | 262 views::ImageView* icon = new views::ImageView(); |
257 icon->SetImage(bundle.GetImageSkiaNamed(requests.at(index)->GetIconID())); | 263 icon->SetImage(bundle.GetImageSkiaNamed(requests.at(index)->GetIconID())); |
264 icon->SetImageSize(gfx::Size(kIconSize, kIconSize)); | |
258 label_container->AddChildView(icon); | 265 label_container->AddChildView(icon); |
259 views::Label* label = | 266 views::Label* label = |
260 new views::Label(requests.at(index)->GetMessageTextFragment()); | 267 new views::Label(requests.at(index)->GetMessageTextFragment()); |
261 label->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); | |
262 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 268 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
263 label_container->AddChildView(label); | 269 label_container->AddChildView(label); |
264 row_layout->AddView(label_container); | 270 row_layout->AddView(label_container); |
265 | 271 |
266 if (customization_mode) { | 272 if (customization_mode) { |
267 PermissionCombobox* combobox = new PermissionCombobox( | 273 PermissionCombobox* combobox = new PermissionCombobox( |
268 this, | 274 this, |
269 index, | 275 index, |
270 requests[index]->GetRequestingHostname(), | 276 requests[index]->GetRequestingHostname(), |
271 accept_state[index] ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); | 277 accept_state[index] ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 button_layout->StartRow(0, 0); | 315 button_layout->StartRow(0, 0); |
310 | 316 |
311 // Allow button is a regular button when there's only one option, and a | 317 // Allow button is a regular button when there's only one option, and a |
312 // STYLE_ACTION Combobox when there are more than one option and | 318 // STYLE_ACTION Combobox when there are more than one option and |
313 // customization is an option. | 319 // customization is an option. |
314 | 320 |
315 base::string16 allow_text = l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW); | 321 base::string16 allow_text = l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW); |
316 if (requests.size() == 1) { | 322 if (requests.size() == 1) { |
317 views::LabelButton* allow_button = new views::LabelButton(this, allow_text); | 323 views::LabelButton* allow_button = new views::LabelButton(this, allow_text); |
318 allow_button->SetStyle(views::Button::STYLE_BUTTON); | 324 allow_button->SetStyle(views::Button::STYLE_BUTTON); |
319 allow_button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); | |
320 button_layout->AddView(allow_button); | 325 button_layout->AddView(allow_button); |
321 allow_ = allow_button; | 326 allow_ = allow_button; |
322 } else { | 327 } else { |
323 views::Combobox* allow_combobox = new views::Combobox( | 328 views::Combobox* allow_combobox = new views::Combobox( |
324 new CustomizeAllowComboboxModel()); | 329 new CustomizeAllowComboboxModel()); |
325 allow_combobox->set_listener(this); | 330 allow_combobox->set_listener(this); |
326 allow_combobox->SetStyle(views::Combobox::STYLE_ACTION); | 331 allow_combobox->SetStyle(views::Combobox::STYLE_ACTION); |
327 button_layout->AddView(allow_combobox); | 332 button_layout->AddView(allow_combobox); |
328 allow_combobox_ = allow_combobox; | 333 allow_combobox_ = allow_combobox; |
329 } | 334 } |
330 | 335 |
331 base::string16 deny_text = l10n_util::GetStringUTF16(IDS_PERMISSION_DENY); | 336 base::string16 deny_text = l10n_util::GetStringUTF16(IDS_PERMISSION_DENY); |
332 views::LabelButton* deny_button = new views::LabelButton(this, deny_text); | 337 views::LabelButton* deny_button = new views::LabelButton(this, deny_text); |
333 deny_button->SetStyle(views::Button::STYLE_BUTTON); | 338 deny_button->SetStyle(views::Button::STYLE_BUTTON); |
334 deny_button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); | |
335 button_layout->AddView(deny_button); | 339 button_layout->AddView(deny_button); |
336 deny_ = deny_button; | 340 deny_ = deny_button; |
337 | 341 |
338 button_layout->AddPaddingRow(0, kBubbleOuterMargin); | 342 button_layout->AddPaddingRow(0, kBubbleOuterMargin); |
339 } | 343 } |
340 | 344 |
341 PermissionsBubbleDelegateView::~PermissionsBubbleDelegateView() { | 345 PermissionsBubbleDelegateView::~PermissionsBubbleDelegateView() { |
342 if (owner_) | 346 if (owner_) |
343 owner_->Closing(); | 347 owner_->Closing(); |
344 } | 348 } |
345 | 349 |
346 void PermissionsBubbleDelegateView::Close() { | 350 void PermissionsBubbleDelegateView::Close() { |
347 owner_ = NULL; | 351 owner_ = NULL; |
348 GetWidget()->Close(); | 352 GetWidget()->Close(); |
349 } | 353 } |
350 | 354 |
351 bool PermissionsBubbleDelegateView::ShouldShowCloseButton() const { | 355 bool PermissionsBubbleDelegateView::ShouldShowCloseButton() const { |
352 return true; | 356 return true; |
353 } | 357 } |
354 | 358 |
355 bool PermissionsBubbleDelegateView::ShouldShowWindowTitle() const { | 359 bool PermissionsBubbleDelegateView::ShouldShowWindowTitle() const { |
356 return true; | 360 return true; |
357 } | 361 } |
358 | 362 |
363 const gfx::FontList& PermissionsBubbleDelegateView::GetTitleFontList() const { | |
364 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
365 return rb.GetFontList(ui::ResourceBundle::BaseFont); | |
366 } | |
367 | |
359 base::string16 PermissionsBubbleDelegateView::GetWindowTitle() const { | 368 base::string16 PermissionsBubbleDelegateView::GetWindowTitle() const { |
360 if (!title_.empty()) { | 369 if (!title_.empty()) { |
361 return title_; | 370 return title_; |
362 } | 371 } |
363 | 372 |
364 return l10n_util::GetStringFUTF16(IDS_PERMISSIONS_BUBBLE_PROMPT, | 373 return l10n_util::GetStringFUTF16(IDS_PERMISSIONS_BUBBLE_PROMPT, |
365 base::UTF8ToUTF16(hostname_)); | 374 base::UTF8ToUTF16(hostname_)); |
366 } | 375 } |
367 | 376 |
368 void PermissionsBubbleDelegateView::SizeToContents() { | 377 void PermissionsBubbleDelegateView::SizeToContents() { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 | 475 |
467 void PermissionBubbleViewViews::Deny() { | 476 void PermissionBubbleViewViews::Deny() { |
468 if (delegate_) | 477 if (delegate_) |
469 delegate_->Deny(); | 478 delegate_->Deny(); |
470 } | 479 } |
471 | 480 |
472 void PermissionBubbleViewViews::SetCustomizationMode() { | 481 void PermissionBubbleViewViews::SetCustomizationMode() { |
473 if (delegate_) | 482 if (delegate_) |
474 delegate_->SetCustomizationMode(); | 483 delegate_->SetCustomizationMode(); |
475 } | 484 } |
OLD | NEW |