| 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/website_settings/permission_bubble_request.h" | 8 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
| 9 #include "grit/generated_resources.h" | 9 #include "grit/generated_resources.h" |
| 10 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
| 11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/gfx/text_constants.h" | 12 #include "ui/gfx/text_constants.h" |
| 13 #include "ui/views/bubble/bubble_delegate.h" | 13 #include "ui/views/bubble/bubble_delegate.h" |
| 14 #include "ui/views/controls/button/checkbox.h" | 14 #include "ui/views/controls/button/checkbox.h" |
| 15 #include "ui/views/controls/button/label_button.h" | 15 #include "ui/views/controls/button/label_button.h" |
| 16 #include "ui/views/controls/label.h" | 16 #include "ui/views/controls/label.h" |
| 17 #include "ui/views/layout/box_layout.h" | 17 #include "ui/views/layout/box_layout.h" |
| 18 #include "ui/views/layout/grid_layout.h" | 18 #include "ui/views/layout/grid_layout.h" |
| 19 | 19 |
| 20 namespace { |
| 21 |
| 22 // Spacing constant for outer margin. This is added to the |
| 23 // bubble margin itself to equalize the margins at 20px. |
| 24 const int kBubbleOuterMargin = 12; |
| 25 |
| 26 // Spacing between major items should be 10px. |
| 27 const int kItemMajorSpacing = 10; |
| 28 |
| 29 // Button border size, draws inside the spacing distance. |
| 30 const int kButtonBorderSize = 2; |
| 31 |
| 32 } // namespace |
| 33 |
| 20 // View implementation for the permissions bubble. | 34 // View implementation for the permissions bubble. |
| 21 class PermissionsBubbleDelegateView : public views::BubbleDelegateView, | 35 class PermissionsBubbleDelegateView : public views::BubbleDelegateView, |
| 22 public views::ButtonListener { | 36 public views::ButtonListener { |
| 23 public: | 37 public: |
| 24 explicit PermissionsBubbleDelegateView( | 38 explicit PermissionsBubbleDelegateView( |
| 25 views::View* anchor, | 39 views::View* anchor, |
| 26 PermissionBubbleViewViews* owner, | 40 PermissionBubbleViewViews* owner, |
| 27 const std::vector<PermissionBubbleRequest*>& requests, | 41 const std::vector<PermissionBubbleRequest*>& requests, |
| 28 const std::vector<bool>& accept_state, | 42 const std::vector<bool>& accept_state, |
| 29 bool customization_mode); | 43 bool customization_mode); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 : views::BubbleDelegateView(anchor, views::BubbleBorder::TOP_LEFT), | 75 : views::BubbleDelegateView(anchor, views::BubbleBorder::TOP_LEFT), |
| 62 owner_(owner), | 76 owner_(owner), |
| 63 allow_(NULL), | 77 allow_(NULL), |
| 64 deny_(NULL), | 78 deny_(NULL), |
| 65 customize_(NULL) { | 79 customize_(NULL) { |
| 66 RemoveAllChildViews(true); | 80 RemoveAllChildViews(true); |
| 67 set_close_on_esc(false); | 81 set_close_on_esc(false); |
| 68 set_close_on_deactivate(false); | 82 set_close_on_deactivate(false); |
| 69 | 83 |
| 70 SetLayoutManager(new views::BoxLayout( | 84 SetLayoutManager(new views::BoxLayout( |
| 71 views::BoxLayout::kVertical, 30, 0, 20)); | 85 views::BoxLayout::kVertical, kBubbleOuterMargin, 0, kItemMajorSpacing)); |
| 72 | 86 |
| 73 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 87 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 74 | 88 |
| 75 if (requests.size() == 1) { | 89 if (requests.size() == 1) { |
| 76 title_ = requests[0]->GetMessageText(); | 90 title_ = requests[0]->GetMessageText(); |
| 77 if (GetWidget()) | 91 if (GetWidget()) |
| 78 GetWidget()->UpdateWindowTitle(); | 92 GetWidget()->UpdateWindowTitle(); |
| 79 } else { | 93 } else { |
| 80 for (std::vector<PermissionBubbleRequest*>::const_iterator it = | 94 for (std::vector<PermissionBubbleRequest*>::const_iterator it = |
| 81 requests.begin(); | 95 requests.begin(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 99 } | 113 } |
| 100 | 114 |
| 101 views::View* button_row = new views::View(); | 115 views::View* button_row = new views::View(); |
| 102 views::GridLayout* button_layout = new views::GridLayout(button_row); | 116 views::GridLayout* button_layout = new views::GridLayout(button_row); |
| 103 views::ColumnSet* columns = button_layout->AddColumnSet(0); | 117 views::ColumnSet* columns = button_layout->AddColumnSet(0); |
| 104 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, | 118 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
| 105 100.0, views::GridLayout::USE_PREF, 0, 0); | 119 100.0, views::GridLayout::USE_PREF, 0, 0); |
| 106 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, | 120 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, |
| 107 0, views::GridLayout::USE_PREF, 0, 0); | 121 0, views::GridLayout::USE_PREF, 0, 0); |
| 108 if (!customization_mode) { | 122 if (!customization_mode) { |
| 109 columns->AddPaddingColumn(0, 10); // padding between buttons | 123 columns->AddPaddingColumn(0, kItemMajorSpacing - (2*kButtonBorderSize)); |
| 110 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, | 124 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, |
| 111 0, views::GridLayout::USE_PREF, 0, 0); | 125 0, views::GridLayout::USE_PREF, 0, 0); |
| 112 } | 126 } |
| 113 | 127 |
| 114 button_row->SetLayoutManager(button_layout); | 128 button_row->SetLayoutManager(button_layout); |
| 115 AddChildView(button_row); | 129 AddChildView(button_row); |
| 116 | 130 |
| 117 button_layout->StartRow(0, 0); | 131 button_layout->StartRow(0, 0); |
| 118 | 132 |
| 119 // Customization case: empty "Customize" label and an "OK" button | 133 // Customization case: empty "Customize" label and an "OK" button |
| 120 if (customization_mode) { | 134 if (customization_mode) { |
| 121 button_layout->AddView(new views::View()); | 135 button_layout->AddView(new views::View()); |
| 122 | 136 |
| 123 views::LabelButton* ok_button = | 137 views::LabelButton* ok_button = |
| 124 new views::LabelButton(this, l10n_util::GetStringUTF16( | 138 new views::LabelButton(this, l10n_util::GetStringUTF16( |
| 125 IDS_OK)); | 139 IDS_OK)); |
| 126 ok_button->SetStyle(views::Button::STYLE_BUTTON); | 140 ok_button->SetStyle(views::Button::STYLE_BUTTON); |
| 127 button_layout->AddView(ok_button); | 141 button_layout->AddView(ok_button); |
| 128 allow_ = ok_button; | 142 allow_ = ok_button; |
| 129 | 143 |
| 130 button_layout->AddPaddingRow(0, 12); | 144 button_layout->AddPaddingRow(0, kBubbleOuterMargin); |
| 131 return; | 145 return; |
| 132 } | 146 } |
| 133 | 147 |
| 134 // Only show the "Customize" button if there is more than one option. | 148 // Only show the "Customize" button if there is more than one option. |
| 135 if (requests.size() > 1) { | 149 if (requests.size() > 1) { |
| 136 views::LabelButton* customize = new views::LabelButton(this, | 150 views::LabelButton* customize = new views::LabelButton(this, |
| 137 l10n_util::GetStringUTF16(IDS_PERMISSION_CUSTOMIZE)); | 151 l10n_util::GetStringUTF16(IDS_PERMISSION_CUSTOMIZE)); |
| 138 customize->SetStyle(views::Button::STYLE_TEXTBUTTON); | 152 customize->SetStyle(views::Button::STYLE_TEXTBUTTON); |
| 139 customize->SetTextColor(views::Button::STATE_NORMAL, SK_ColorBLUE); | 153 customize->SetTextColor(views::Button::STATE_NORMAL, SK_ColorBLUE); |
| 140 customize->SetTextColor(views::Button::STATE_HOVERED, SK_ColorBLUE); | 154 customize->SetTextColor(views::Button::STATE_HOVERED, SK_ColorBLUE); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 163 deny_button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); | 177 deny_button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); |
| 164 button_layout->AddView(deny_button); | 178 button_layout->AddView(deny_button); |
| 165 deny_ = deny_button; | 179 deny_ = deny_button; |
| 166 | 180 |
| 167 views::LabelButton* allow_button = new views::LabelButton(this, allow_text); | 181 views::LabelButton* allow_button = new views::LabelButton(this, allow_text); |
| 168 allow_button->SetStyle(views::Button::STYLE_BUTTON); | 182 allow_button->SetStyle(views::Button::STYLE_BUTTON); |
| 169 allow_button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); | 183 allow_button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); |
| 170 button_layout->AddView(allow_button); | 184 button_layout->AddView(allow_button); |
| 171 allow_ = allow_button; | 185 allow_ = allow_button; |
| 172 | 186 |
| 173 button_layout->AddPaddingRow(0, 30); | 187 button_layout->AddPaddingRow(0, kBubbleOuterMargin); |
| 174 } | 188 } |
| 175 | 189 |
| 176 PermissionsBubbleDelegateView::~PermissionsBubbleDelegateView() { | 190 PermissionsBubbleDelegateView::~PermissionsBubbleDelegateView() { |
| 177 if (owner_) | 191 if (owner_) |
| 178 owner_->Closing(); | 192 owner_->Closing(); |
| 179 } | 193 } |
| 180 | 194 |
| 181 void PermissionsBubbleDelegateView::ResetOwner() { | 195 void PermissionsBubbleDelegateView::ResetOwner() { |
| 182 owner_ = NULL; | 196 owner_ = NULL; |
| 183 } | 197 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 293 |
| 280 void PermissionBubbleViewViews::Deny() { | 294 void PermissionBubbleViewViews::Deny() { |
| 281 if (delegate_) | 295 if (delegate_) |
| 282 delegate_->Deny(); | 296 delegate_->Deny(); |
| 283 } | 297 } |
| 284 | 298 |
| 285 void PermissionBubbleViewViews::SetCustomizationMode() { | 299 void PermissionBubbleViewViews::SetCustomizationMode() { |
| 286 if (delegate_) | 300 if (delegate_) |
| 287 delegate_->SetCustomizationMode(); | 301 delegate_->SetCustomizationMode(); |
| 288 } | 302 } |
| OLD | NEW |