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

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

Issue 10829038: (Views only) Resize the menu buttons on the Website Settings UI to fit the button text (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " 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
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/permission_selector_view.h" 5 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/ui/website_settings/website_settings_ui.h" 8 #include "chrome/browser/ui/website_settings/website_settings_ui.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"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 class PermissionMenuButton : public views::MenuButton, 87 class PermissionMenuButton : public views::MenuButton,
88 public views::MenuButtonListener { 88 public views::MenuButtonListener {
89 public: 89 public:
90 // Creates a new |PermissionMenuButton| with the passed |text|. The ownership 90 // Creates a new |PermissionMenuButton| with the passed |text|. The ownership
91 // of the |model| remains with the caller and is not transfered to the 91 // of the |model| remains with the caller and is not transfered to the
92 // |PermissionMenuButton|. 92 // |PermissionMenuButton|.
93 PermissionMenuButton(const string16& text, 93 PermissionMenuButton(const string16& text,
94 PermissionMenuModel* model); 94 PermissionMenuModel* model);
95 virtual ~PermissionMenuButton(); 95 virtual ~PermissionMenuButton();
96 96
97 // Overridden from views::MenuButton.
98 virtual gfx::Size GetPreferredSize() OVERRIDE;
99
100 // Overridden from views::TextButton.
101 virtual void SetText(const string16& text) OVERRIDE;
102
97 private: 103 private:
98 // Overridden from views::MenuButtonListener: 104 // Overridden from views::MenuButtonListener.
99 virtual void OnMenuButtonClicked(View* source, 105 virtual void OnMenuButtonClicked(View* source,
100 const gfx::Point& point) OVERRIDE; 106 const gfx::Point& point) OVERRIDE;
101 107
102 PermissionMenuModel* menu_model_; // Owned by |PermissionSelectorView|. 108 PermissionMenuModel* menu_model_; // Owned by |PermissionSelectorView|.
103 scoped_ptr<views::MenuRunner> menu_runner_; 109 scoped_ptr<views::MenuRunner> menu_runner_;
104 110
105 DISALLOW_COPY_AND_ASSIGN(PermissionMenuButton); 111 DISALLOW_COPY_AND_ASSIGN(PermissionMenuButton);
106 }; 112 };
107 113
108 /////////////////////////////////////////////////////////////////////////////// 114 ///////////////////////////////////////////////////////////////////////////////
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // Accelerators are not supported. 157 // Accelerators are not supported.
152 return false; 158 return false;
153 } 159 }
154 160
155 void PermissionMenuModel::ExecuteCommand(int command_id) { 161 void PermissionMenuModel::ExecuteCommand(int command_id) {
156 current_setting_ = kSettingsForCommandIDs[command_id]; 162 current_setting_ = kSettingsForCommandIDs[command_id];
157 permission_selector_->SelectionChanged(); 163 permission_selector_->SelectionChanged();
158 } 164 }
159 165
160 /////////////////////////////////////////////////////////////////////////////// 166 ///////////////////////////////////////////////////////////////////////////////
161 // PermissionMenuModel 167 // PermissionMenuButton
162 /////////////////////////////////////////////////////////////////////////////// 168 ///////////////////////////////////////////////////////////////////////////////
163 169
164 PermissionMenuButton::PermissionMenuButton(const string16& text, 170 PermissionMenuButton::PermissionMenuButton(const string16& text,
165 PermissionMenuModel* model) 171 PermissionMenuModel* model)
166 : ALLOW_THIS_IN_INITIALIZER_LIST(MenuButton(NULL, text, this, true)), 172 : ALLOW_THIS_IN_INITIALIZER_LIST(MenuButton(NULL, text, this, true)),
167 menu_model_(model) { 173 menu_model_(model) {
168 } 174 }
169 175
170 PermissionMenuButton::~PermissionMenuButton() { 176 PermissionMenuButton::~PermissionMenuButton() {
171 } 177 }
172 178
179 gfx::Size PermissionMenuButton::GetPreferredSize() {
180 gfx::Insets insets = GetInsets();
181 // Scale the button to the current text size.
msw 2012/07/26 20:01:33 Should there be a minimum size? What does this loo
markusheintz_ 2012/07/30 12:55:37 The minimum size is the size to fit the menu marke
msw 2012/07/30 15:48:42 OK, that seems fine.
182 gfx::Size prefsize(text_size_.width() + insets.width(),
183 text_size_.height() + insets.height());
184 if (max_width_ > 0)
185 prefsize.set_width(std::min(max_width_, prefsize.width()));
186 if (show_menu_marker()) {
187 prefsize.Enlarge(menu_marker()->width() + 2 /*marke padding left + right*/,
msw 2012/07/26 20:01:33 Shouldn't this use/match kMenuMarkerPaddingLeft an
markusheintz_ 2012/07/30 12:55:37 Uups done. On 2012/07/26 20:01:33, msw wrote:
188 0);
189 }
190 return prefsize;
191 }
192
193 void PermissionMenuButton::SetText(const string16& text) {
194 MenuButton::SetText(text);
195 SizeToPreferredSize();
196 }
197
173 void PermissionMenuButton::OnMenuButtonClicked(View* source, 198 void PermissionMenuButton::OnMenuButtonClicked(View* source,
174 const gfx::Point& point) { 199 const gfx::Point& point) {
175 views::MenuModelAdapter menu_model_adapter(menu_model_); 200 views::MenuModelAdapter menu_model_adapter(menu_model_);
176 menu_runner_.reset(new views::MenuRunner(menu_model_adapter.CreateMenu())); 201 menu_runner_.reset(new views::MenuRunner(menu_model_adapter.CreateMenu()));
177 202
178 gfx::Point p(point); 203 gfx::Point p(point);
179 p.Offset(-source->width(), 0); 204 p.Offset(-source->width(), 0);
180 if (menu_runner_->RunMenuAt( 205 if (menu_runner_->RunMenuAt(
181 source->GetWidget()->GetTopLevelWidget(), 206 source->GetWidget()->GetTopLevelWidget(),
182 this, 207 this,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 304 }
280 305
281 ContentSetting PermissionSelectorView::GetSelectedSetting() const { 306 ContentSetting PermissionSelectorView::GetSelectedSetting() const {
282 return menu_button_model_->current_setting(); 307 return menu_button_model_->current_setting();
283 } 308 }
284 309
285 ContentSettingsType PermissionSelectorView::GetPermissionType() const { 310 ContentSettingsType PermissionSelectorView::GetPermissionType() const {
286 return menu_button_model_->site_permission(); 311 return menu_button_model_->site_permission();
287 } 312 }
288 313
314 void PermissionSelectorView::ChildPreferredSizeChanged(View* child) {
315 SizeToPreferredSize();
316 // The parent is only a plain |View| that is used as a container/box/panel.
317 // In order to not implment a custom |View| class with its own implementation
msw 2012/07/26 20:01:33 nit: use indirect verbiage here: "Call SizeToPrefe
markusheintz_ 2012/07/30 12:55:37 Done.
318 // of the ChildPreferredSizeChanged method, we call the SizeToPreferredSize
319 // method of the parent directly from here.
320 parent()->SizeToPreferredSize();
msw 2012/07/26 20:01:33 It's a little odd (perhaps bad) to make assumption
markusheintz_ 2012/07/30 12:55:37 I totally agree with you this is odd. It would be
321 }
322
289 PermissionSelectorView::~PermissionSelectorView() { 323 PermissionSelectorView::~PermissionSelectorView() {
290 } 324 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698