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

Side by Side Diff: chrome/browser/views/toolbar_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 "chrome/browser/views/toolbar_view.h" 5 #include "chrome/browser/views/toolbar_view.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 app_menu_->SetIcon(*rb.GetBitmapNamed(IDR_MENU_CHROME)); 255 app_menu_->SetIcon(*rb.GetBitmapNamed(IDR_MENU_CHROME));
256 256
257 app_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_APP)); 257 app_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_APP));
258 app_menu_->SetTooltipText(l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, 258 app_menu_->SetTooltipText(l10n_util::GetStringF(IDS_APPMENU_TOOLTIP,
259 l10n_util::GetString(IDS_PRODUCT_NAME))); 259 l10n_util::GetString(IDS_PRODUCT_NAME)));
260 app_menu_->SetID(VIEW_ID_APP_MENU); 260 app_menu_->SetID(VIEW_ID_APP_MENU);
261 AddChildView(app_menu_); 261 AddChildView(app_menu_);
262 } 262 }
263 263
264 void BrowserToolbarView::Layout() { 264 void BrowserToolbarView::Layout() {
265 CSize sz; 265 gfx::Size sz;
266 266
267 // If we have not been initialized yet just do nothing. 267 // If we have not been initialized yet just do nothing.
268 if (back_ == NULL) 268 if (back_ == NULL)
269 return; 269 return;
270 270
271 int location_bar_y = kControlVertOffset; 271 int location_bar_y = kControlVertOffset;
272 int location_bar_height = 0; 272 int location_bar_height = 0;
273 // The width of all of the controls to the left of the location bar. 273 // The width of all of the controls to the left of the location bar.
274 int left_side_width = 0; 274 int left_side_width = 0;
275 // The width of all of the controls to the right of the location bar. 275 // The width of all of the controls to the right of the location bar.
276 int right_side_width = 0; 276 int right_side_width = 0;
277 if (IsDisplayModeNormal()) { 277 if (IsDisplayModeNormal()) {
278 back_->GetPreferredSize(&sz); 278 sz = back_->GetPreferredSize();
279 back_->SetBounds(kControlIndent, kControlVertOffset, sz.cx, sz.cy); 279 back_->SetBounds(kControlIndent, kControlVertOffset, sz.width(),
280 sz.height());
280 281
281 forward_->GetPreferredSize(&sz); 282 sz = forward_->GetPreferredSize();
282 forward_->SetBounds(back_->x() + back_->width(), kControlVertOffset, 283 forward_->SetBounds(back_->x() + back_->width(), kControlVertOffset,
283 sz.cx, sz.cy); 284 sz.width(), sz.height());
284 285
285 reload_->GetPreferredSize(&sz); 286 sz = reload_->GetPreferredSize();
286 reload_->SetBounds(forward_->x() + forward_->width() + 287 reload_->SetBounds(forward_->x() + forward_->width() +
287 kControlHorizOffset, 288 kControlHorizOffset,
288 kControlVertOffset, sz.cx, sz.cy); 289 kControlVertOffset, sz.width(), sz.height());
289 290
290 int offset = 0; 291 int offset = 0;
291 if (show_home_button_.GetValue()) { 292 if (show_home_button_.GetValue()) {
292 home_->GetPreferredSize(&sz); 293 sz = home_->GetPreferredSize();
293 offset = kControlHorizOffset; 294 offset = kControlHorizOffset;
294 home_->SetVisible(true); 295 home_->SetVisible(true);
295 } else { 296 } else {
296 sz = CSize(0, 0); 297 sz = gfx::Size();
297 home_->SetVisible(false); 298 home_->SetVisible(false);
298 } 299 }
299 home_->SetBounds(reload_->x() + reload_->width() + offset, 300 home_->SetBounds(reload_->x() + reload_->width() + offset,
300 kControlVertOffset, sz.cx, sz.cy); 301 kControlVertOffset, sz.width(), sz.height());
301 302
302 star_->GetPreferredSize(&sz); 303 sz = star_->GetPreferredSize();
303 star_->SetBounds(home_->x() + home_->width() + kControlHorizOffset, 304 star_->SetBounds(home_->x() + home_->width() + kControlHorizOffset,
304 kControlVertOffset, sz.cx, sz.cy); 305 kControlVertOffset, sz.width(), sz.height());
305 306
306 page_menu_->GetPreferredSize(&sz); 307 sz = page_menu_->GetPreferredSize();
307 right_side_width = sz.cx + kMenuButtonOffset; 308 right_side_width = sz.width() + kMenuButtonOffset;
308 309
309 app_menu_->GetPreferredSize(&sz); 310 sz = app_menu_->GetPreferredSize();
310 right_side_width += sz.cx + kPaddingRight; 311 right_side_width += sz.width() + kPaddingRight;
311 312
312 go_->GetPreferredSize(&sz); 313 sz = go_->GetPreferredSize();
313 location_bar_height = sz.cy; 314 location_bar_height = sz.height();
314 right_side_width += sz.cx; 315 right_side_width += sz.width();
315 316
316 left_side_width = star_->x() + star_->width(); 317 left_side_width = star_->x() + star_->width();
317 } else { 318 } else {
318 CSize temp; 319 gfx::Size temp = location_bar_->GetPreferredSize();
319 location_bar_->GetPreferredSize(&temp); 320 location_bar_height = temp.height();
320 location_bar_height = temp.cy;
321 left_side_width = kToolbarHorizontalMargin; 321 left_side_width = kToolbarHorizontalMargin;
322 right_side_width = kToolbarHorizontalMargin; 322 right_side_width = kToolbarHorizontalMargin;
323 location_bar_y = kControlVertOffsetLocationOnly; 323 location_bar_y = kControlVertOffsetLocationOnly;
324 } 324 }
325 325
326 location_bar_->SetBounds(left_side_width, location_bar_y, 326 location_bar_->SetBounds(left_side_width, location_bar_y,
327 width() - left_side_width - right_side_width, 327 width() - left_side_width - right_side_width,
328 location_bar_height); 328 location_bar_height);
329 329
330 if (IsDisplayModeNormal()) { 330 if (IsDisplayModeNormal()) {
331 go_->SetBounds(location_bar_->x() + location_bar_->width(), 331 go_->SetBounds(location_bar_->x() + location_bar_->width(),
332 kControlVertOffset, sz.cx, sz.cy); 332 kControlVertOffset, sz.width(), sz.height());
333 333
334 // Make sure the Page menu never overlaps the location bar. 334 // Make sure the Page menu never overlaps the location bar.
335 int page_x = go_->x() + go_->width() + kMenuButtonOffset; 335 int page_x = go_->x() + go_->width() + kMenuButtonOffset;
336 page_menu_->GetPreferredSize(&sz); 336 sz = page_menu_->GetPreferredSize();
337 page_menu_->SetBounds(page_x, kControlVertOffset, sz.cx, go_->height()); 337 page_menu_->SetBounds(page_x, kControlVertOffset, sz.width(),
338 app_menu_->GetPreferredSize(&sz); 338 go_->height());
339 sz = app_menu_->GetPreferredSize();
339 app_menu_->SetBounds(page_menu_->x() + page_menu_->width(), 340 app_menu_->SetBounds(page_menu_->x() + page_menu_->width(),
340 page_menu_->y(), sz.cx, go_->height()); 341 page_menu_->y(), sz.width(), go_->height());
341 } 342 }
342 } 343 }
343 344
344 void BrowserToolbarView::DidChangeBounds(const CRect& previous, 345 void BrowserToolbarView::DidChangeBounds(const CRect& previous,
345 const CRect& current) { 346 const CRect& current) {
346 Layout(); 347 Layout();
347 } 348 }
348 349
349 void BrowserToolbarView::DidGainFocus() { 350 void BrowserToolbarView::DidGainFocus() {
350 // Find first accessible child (-1 for start search at parent). 351 // Find first accessible child (-1 for start search at parent).
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 463
463 bool BrowserToolbarView::OnKeyReleased(const ChromeViews::KeyEvent& e) { 464 bool BrowserToolbarView::OnKeyReleased(const ChromeViews::KeyEvent& e) {
464 // Paranoia check, button should be initialized upon toolbar gaining focus. 465 // Paranoia check, button should be initialized upon toolbar gaining focus.
465 if (!acc_focused_view_) 466 if (!acc_focused_view_)
466 return false; 467 return false;
467 468
468 // Have keys be handled by the views themselves. 469 // Have keys be handled by the views themselves.
469 return acc_focused_view_->OnKeyReleased(e); 470 return acc_focused_view_->OnKeyReleased(e);
470 } 471 }
471 472
472 void BrowserToolbarView::GetPreferredSize(CSize* out) { 473 gfx::Size BrowserToolbarView::GetPreferredSize() {
473 DCHECK(out);
474 out->cx = 0;
475
476 if (IsDisplayModeNormal()) { 474 if (IsDisplayModeNormal()) {
477 static SkBitmap normal_background; 475 static SkBitmap normal_background;
478 if (normal_background.isNull()) { 476 if (normal_background.isNull()) {
479 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 477 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
480 normal_background = *rb.GetBitmapNamed(IDR_CONTENT_TOP_CENTER); 478 normal_background = *rb.GetBitmapNamed(IDR_CONTENT_TOP_CENTER);
481 } 479 }
482 out->cy = normal_background.height(); 480 return gfx::Size(0, normal_background.height());
483 } else {
484 CSize ps;
485 location_bar_->GetPreferredSize(&ps);
486 out->cy = ps.cy + 2 * kControlVertOffsetLocationOnly;
487 } 481 }
482
483 int locbar_height = location_bar_->GetPreferredSize().height();
484 return gfx::Size(0, locbar_height + 2 * kControlVertOffsetLocationOnly);
488 } 485 }
489 486
490 void BrowserToolbarView::RunPageMenu(const CPoint& pt, HWND hwnd) { 487 void BrowserToolbarView::RunPageMenu(const CPoint& pt, HWND hwnd) {
491 Menu::AnchorPoint anchor = Menu::TOPRIGHT; 488 Menu::AnchorPoint anchor = Menu::TOPRIGHT;
492 if (UILayoutIsRightToLeft()) 489 if (UILayoutIsRightToLeft())
493 anchor = Menu::TOPLEFT; 490 anchor = Menu::TOPLEFT;
494 491
495 Menu menu(this, anchor, hwnd); 492 Menu menu(this, anchor, hwnd);
496 // The install menu may be dynamically generated with a contextual label. 493 // The install menu may be dynamically generated with a contextual label.
497 // See browser_commands.cc. 494 // See browser_commands.cc.
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 *accel = ChromeViews::Accelerator(L'C', false, true, false); 733 *accel = ChromeViews::Accelerator(L'C', false, true, false);
737 return true; 734 return true;
738 case IDC_PASTE: 735 case IDC_PASTE:
739 *accel = ChromeViews::Accelerator(L'V', false, true, false); 736 *accel = ChromeViews::Accelerator(L'V', false, true, false);
740 return true; 737 return true;
741 } 738 }
742 // Else, we retrieve the accelerator information from the frame. 739 // Else, we retrieve the accelerator information from the frame.
743 return GetViewContainer()->GetAccelerator(id, accel); 740 return GetViewContainer()->GetAccelerator(id, accel);
744 } 741 }
745 742
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698