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

Side by Side Diff: ui/views/window/dialog_client_view.cc

Issue 1141253002: [Views] Allow dialog delegates to use a custom padding for the extra view (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
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 "ui/views/window/dialog_client_view.h" 5 #include "ui/views/window/dialog_client_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ui/events/keycodes/keyboard_codes.h" 9 #include "ui/events/keycodes/keyboard_codes.h"
10 #include "ui/views/background.h" 10 #include "ui/views/background.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 170
171 void DialogClientView::OnDidChangeFocus(View* focused_before, 171 void DialogClientView::OnDidChangeFocus(View* focused_before,
172 View* focused_now) { 172 View* focused_now) {
173 } 173 }
174 174
175 //////////////////////////////////////////////////////////////////////////////// 175 ////////////////////////////////////////////////////////////////////////////////
176 // DialogClientView, View overrides: 176 // DialogClientView, View overrides:
177 177
178 gfx::Size DialogClientView::GetPreferredSize() const { 178 gfx::Size DialogClientView::GetPreferredSize() const {
179 // Initialize the size to fit the buttons and extra view row. 179 // Initialize the size to fit the buttons and extra view row.
180 int extra_view_padding = 0;
181 if (!GetDialogDelegate()->GetExtraViewPadding(&extra_view_padding))
182 extra_view_padding = kRelatedButtonHSpacing;
180 gfx::Size size( 183 gfx::Size size(
181 (ok_button_ ? ok_button_->GetPreferredSize().width() : 0) + 184 (ok_button_ ? ok_button_->GetPreferredSize().width() : 0) +
182 (cancel_button_ ? cancel_button_->GetPreferredSize().width() : 0) + 185 (cancel_button_ ? cancel_button_->GetPreferredSize().width() : 0) +
183 (cancel_button_ && ok_button_ ? kRelatedButtonHSpacing : 0) + 186 (cancel_button_ && ok_button_ ? kRelatedButtonHSpacing : 0) +
184 (ShouldShow(extra_view_) ? extra_view_->GetPreferredSize().width() : 0) + 187 (ShouldShow(extra_view_) ? extra_view_->GetPreferredSize().width() : 0) +
185 (ShouldShow(extra_view_) && has_dialog_buttons() ? 188 (ShouldShow(extra_view_) && has_dialog_buttons() ?
186 kRelatedButtonHSpacing : 0), 189 extra_view_padding : 0),
187 0); 190 0);
188 191
189 int buttons_height = GetButtonsAndExtraViewRowHeight(); 192 int buttons_height = GetButtonsAndExtraViewRowHeight();
190 if (buttons_height != 0) { 193 if (buttons_height != 0) {
191 size.Enlarge(0, buttons_height + kRelatedControlVerticalSpacing); 194 size.Enlarge(0, buttons_height + kRelatedControlVerticalSpacing);
192 // Inset the buttons and extra view. 195 // Inset the buttons and extra view.
193 const gfx::Insets insets = GetButtonRowInsets(); 196 const gfx::Insets insets = GetButtonRowInsets();
194 size.Enlarge(insets.width(), insets.height()); 197 size.Enlarge(insets.width(), insets.height());
195 } 198 }
196 199
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 gfx::Rect row_bounds(bounds.x(), bounds.bottom() - height, 235 gfx::Rect row_bounds(bounds.x(), bounds.bottom() - height,
233 bounds.width(), height); 236 bounds.width(), height);
234 if (kIsOkButtonOnLeftSide) { 237 if (kIsOkButtonOnLeftSide) {
235 LayoutButton(cancel_button_, &row_bounds); 238 LayoutButton(cancel_button_, &row_bounds);
236 LayoutButton(ok_button_, &row_bounds); 239 LayoutButton(ok_button_, &row_bounds);
237 } else { 240 } else {
238 LayoutButton(ok_button_, &row_bounds); 241 LayoutButton(ok_button_, &row_bounds);
239 LayoutButton(cancel_button_, &row_bounds); 242 LayoutButton(cancel_button_, &row_bounds);
240 } 243 }
241 if (extra_view_) { 244 if (extra_view_) {
245 int custom_padding = 0;
246 if (has_dialog_buttons() &&
247 GetDialogDelegate()->GetExtraViewPadding(&custom_padding)) {
248 // The call to LayoutButton() will already have accounted for some of
249 // the padding.
250 custom_padding -= kRelatedButtonHSpacing;
251 row_bounds.set_width(row_bounds.width() - custom_padding);
252 }
242 row_bounds.set_width(std::min(row_bounds.width(), 253 row_bounds.set_width(std::min(row_bounds.width(),
243 extra_view_->GetPreferredSize().width())); 254 extra_view_->GetPreferredSize().width()));
244 extra_view_->SetBoundsRect(row_bounds); 255 extra_view_->SetBoundsRect(row_bounds);
245 } 256 }
246 257
247 if (height > 0) 258 if (height > 0)
248 bounds.Inset(0, 0, 0, height + kRelatedControlVerticalSpacing); 259 bounds.Inset(0, 0, 0, height + kRelatedControlVerticalSpacing);
249 } 260 }
250 261
251 // Layout the contents view to the top and side edges of the contents bounds. 262 // Layout the contents view to the top and side edges of the contents bounds.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 gfx::Insets(0, kButtonHEdgeMarginNew, 430 gfx::Insets(0, kButtonHEdgeMarginNew,
420 kButtonVEdgeMarginNew, kButtonHEdgeMarginNew); 431 kButtonVEdgeMarginNew, kButtonHEdgeMarginNew);
421 } 432 }
422 433
423 void DialogClientView::Close() { 434 void DialogClientView::Close() {
424 GetWidget()->Close(); 435 GetWidget()->Close();
425 GetDialogDelegate()->OnClosed(); 436 GetDialogDelegate()->OnClosed();
426 } 437 }
427 438
428 } // namespace views 439 } // namespace views
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc ('k') | ui/views/window/dialog_client_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698