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

Side by Side Diff: chrome/views/dialog_client_view.cc

Issue 7344: Convert GetPreferredSize from:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 2 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <windows.h> 5 #include <windows.h>
6 #include <uxtheme.h> 6 #include <uxtheme.h>
7 #include <vsstyle.h> 7 #include <vsstyle.h>
8 8
9 #include "chrome/views/dialog_client_view.h" 9 #include "chrome/views/dialog_client_view.h"
10 10
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 ClientView::ViewHierarchyChanged(is_add, parent, child); 231 ClientView::ViewHierarchyChanged(is_add, parent, child);
232 UpdateDialogButtons(); 232 UpdateDialogButtons();
233 Layout(); 233 Layout();
234 } 234 }
235 } 235 }
236 236
237 void DialogClientView::DidChangeBounds(const CRect& prev, const CRect& next) { 237 void DialogClientView::DidChangeBounds(const CRect& prev, const CRect& next) {
238 Layout(); 238 Layout();
239 } 239 }
240 240
241 void DialogClientView::GetPreferredSize(CSize* out) { 241 gfx::Size DialogClientView::GetPreferredSize() {
242 DCHECK(out); 242 gfx::Size prefsize = contents_view()->GetPreferredSize();
243 contents_view()->GetPreferredSize(out);
244 int button_height = 0; 243 int button_height = 0;
245 if (has_dialog_buttons()) { 244 if (has_dialog_buttons()) {
246 if (cancel_button_) 245 if (cancel_button_)
247 button_height = cancel_button_->height(); 246 button_height = cancel_button_->height();
248 else 247 else
249 button_height = ok_button_->height(); 248 button_height = ok_button_->height();
250 // Account for padding above and below the button. 249 // Account for padding above and below the button.
251 button_height += kDialogButtonContentSpacing + kButtonVEdgeMargin; 250 button_height += kDialogButtonContentSpacing + kButtonVEdgeMargin;
252 } 251 }
253 out->cy += button_height; 252 prefsize.Enlarge(0, button_height);
253 return prefsize;
254 } 254 }
255 255
256 bool DialogClientView::AcceleratorPressed(const Accelerator& accelerator) { 256 bool DialogClientView::AcceleratorPressed(const Accelerator& accelerator) {
257 DCHECK(accelerator.GetKeyCode() == VK_ESCAPE); // We only expect Escape key. 257 DCHECK(accelerator.GetKeyCode() == VK_ESCAPE); // We only expect Escape key.
258 window()->Close(); 258 window()->Close();
259 return true; 259 return true;
260 } 260 }
261 261
262 //////////////////////////////////////////////////////////////////////////////// 262 ////////////////////////////////////////////////////////////////////////////////
263 // DialogClientView, NativeButton::Listener implementation: 263 // DialogClientView, NativeButton::Listener implementation:
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 if (cancel_button_) 313 if (cancel_button_)
314 return cancel_button_->height() + kDialogButtonContentSpacing; 314 return cancel_button_->height() + kDialogButtonContentSpacing;
315 return ok_button_->height() + kDialogButtonContentSpacing; 315 return ok_button_->height() + kDialogButtonContentSpacing;
316 } 316 }
317 return 0; 317 return 0;
318 } 318 }
319 319
320 void DialogClientView::LayoutDialogButtons() { 320 void DialogClientView::LayoutDialogButtons() {
321 CRect extra_bounds; 321 CRect extra_bounds;
322 if (cancel_button_) { 322 if (cancel_button_) {
323 CSize ps; 323 gfx::Size ps = cancel_button_->GetPreferredSize();
324 cancel_button_->GetPreferredSize(&ps);
325 CRect lb; 324 CRect lb;
326 GetLocalBounds(&lb, false); 325 GetLocalBounds(&lb, false);
327 int button_width = GetButtonWidth(DialogDelegate::DIALOGBUTTON_CANCEL); 326 int button_width = GetButtonWidth(DialogDelegate::DIALOGBUTTON_CANCEL);
328 CRect bounds; 327 CRect bounds;
329 bounds.left = lb.right - button_width - kButtonHEdgeMargin; 328 bounds.left = lb.right - button_width - kButtonHEdgeMargin;
330 bounds.top = lb.bottom - ps.cy - kButtonVEdgeMargin; 329 bounds.top = lb.bottom - ps.height() - kButtonVEdgeMargin;
331 bounds.right = bounds.left + button_width; 330 bounds.right = bounds.left + button_width;
332 bounds.bottom = bounds.top + ps.cy; 331 bounds.bottom = bounds.top + ps.height();
333 cancel_button_->SetBounds(bounds); 332 cancel_button_->SetBounds(bounds);
334 // The extra view bounds are dependent on this button. 333 // The extra view bounds are dependent on this button.
335 extra_bounds.right = bounds.left; 334 extra_bounds.right = bounds.left;
336 extra_bounds.top = bounds.top; 335 extra_bounds.top = bounds.top;
337 } 336 }
338 if (ok_button_) { 337 if (ok_button_) {
339 CSize ps; 338 gfx::Size ps = ok_button_->GetPreferredSize();
340 ok_button_->GetPreferredSize(&ps);
341 CRect lb; 339 CRect lb;
342 GetLocalBounds(&lb, false); 340 GetLocalBounds(&lb, false);
343 int button_width = GetButtonWidth(DialogDelegate::DIALOGBUTTON_OK); 341 int button_width = GetButtonWidth(DialogDelegate::DIALOGBUTTON_OK);
344 int ok_button_right = lb.right - kButtonHEdgeMargin; 342 int ok_button_right = lb.right - kButtonHEdgeMargin;
345 if (cancel_button_) 343 if (cancel_button_)
346 ok_button_right = cancel_button_->x() - kRelatedButtonHSpacing; 344 ok_button_right = cancel_button_->x() - kRelatedButtonHSpacing;
347 CRect bounds; 345 CRect bounds;
348 bounds.left = ok_button_right - button_width; 346 bounds.left = ok_button_right - button_width;
349 bounds.top = lb.bottom - ps.cy - kButtonVEdgeMargin; 347 bounds.top = lb.bottom - ps.height() - kButtonVEdgeMargin;
350 bounds.right = ok_button_right; 348 bounds.right = ok_button_right;
351 bounds.bottom = bounds.top + ps.cy; 349 bounds.bottom = bounds.top + ps.height();
352 ok_button_->SetBounds(bounds); 350 ok_button_->SetBounds(bounds);
353 // The extra view bounds are dependent on this button. 351 // The extra view bounds are dependent on this button.
354 extra_bounds.right = bounds.left; 352 extra_bounds.right = bounds.left;
355 extra_bounds.top = bounds.top; 353 extra_bounds.top = bounds.top;
356 } 354 }
357 if (extra_view_) { 355 if (extra_view_) {
358 CSize ps; 356 gfx::Size ps = extra_view_->GetPreferredSize();
359 extra_view_->GetPreferredSize(&ps);
360 CRect lb; 357 CRect lb;
361 GetLocalBounds(&lb, false); 358 GetLocalBounds(&lb, false);
362 extra_bounds.left = lb.left + kButtonHEdgeMargin; 359 extra_bounds.left = lb.left + kButtonHEdgeMargin;
363 extra_bounds.bottom = extra_bounds.top + ps.cy; 360 extra_bounds.bottom = extra_bounds.top + ps.height();
364 extra_view_->SetBounds(extra_bounds); 361 extra_view_->SetBounds(extra_bounds);
365 } 362 }
366 } 363 }
367 364
368 void DialogClientView::LayoutContentsView() { 365 void DialogClientView::LayoutContentsView() {
369 CRect lb; 366 CRect lb;
370 GetLocalBounds(&lb, false); 367 GetLocalBounds(&lb, false);
371 lb.bottom = std::max(0, static_cast<int>(lb.bottom - GetButtonsHeight())); 368 lb.bottom = std::max(0, static_cast<int>(lb.bottom - GetButtonsHeight()));
372 contents_view()->SetBounds(lb); 369 contents_view()->SetBounds(lb);
373 contents_view()->Layout(); 370 contents_view()->Layout();
(...skipping 10 matching lines...) Expand all
384 static bool initialized = false; 381 static bool initialized = false;
385 if (!initialized) { 382 if (!initialized) {
386 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 383 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
387 dialog_button_font_ = rb.GetFont(ResourceBundle::BaseFont); 384 dialog_button_font_ = rb.GetFont(ResourceBundle::BaseFont);
388 initialized = true; 385 initialized = true;
389 } 386 }
390 } 387 }
391 388
392 } 389 }
393 390
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698