OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/toolbar/toolbar_view.h" | 5 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/i18n/number_formatting.h" | 9 #include "base/i18n/number_formatting.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 LoadImages(); | 237 LoadImages(); |
238 | 238 |
239 // Add any necessary badges to the menu item based on the system state. | 239 // Add any necessary badges to the menu item based on the system state. |
240 // Do this after |app_menu_| has been added as a bubble may be shown that | 240 // Do this after |app_menu_| has been added as a bubble may be shown that |
241 // needs the widget (widget found by way of app_menu_->GetWidget()). | 241 // needs the widget (widget found by way of app_menu_->GetWidget()). |
242 UpdateAppMenuState(); | 242 UpdateAppMenuState(); |
243 | 243 |
244 location_bar_->Init(); | 244 location_bar_->Init(); |
245 | 245 |
246 site_chip_view_->Init(); | 246 site_chip_view_->Init(); |
247 if (site_chip_view_->ShouldShow()) | |
248 location_bar_->set_site_chip_view(site_chip_view_); | |
249 | |
247 show_home_button_.Init(prefs::kShowHomeButton, | 250 show_home_button_.Init(prefs::kShowHomeButton, |
248 browser_->profile()->GetPrefs(), | 251 browser_->profile()->GetPrefs(), |
249 base::Bind(&ToolbarView::OnShowHomeButtonChanged, | 252 base::Bind(&ToolbarView::OnShowHomeButtonChanged, |
250 base::Unretained(this))); | 253 base::Unretained(this))); |
251 | 254 |
252 browser_actions_->Init(); | 255 browser_actions_->Init(); |
253 | 256 |
254 // Accessibility specific tooltip text. | 257 // Accessibility specific tooltip text. |
255 if (content::BrowserAccessibilityState::GetInstance()-> | 258 if (content::BrowserAccessibilityState::GetInstance()-> |
256 IsAccessibleBrowser()) { | 259 IsAccessibleBrowser()) { |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 if (is_display_mode_normal()) { | 493 if (is_display_mode_normal()) { |
491 int button_spacing = GetButtonSpacing(); | 494 int button_spacing = GetButtonSpacing(); |
492 size.Enlarge( | 495 size.Enlarge( |
493 kLeftEdgeSpacing + back_->GetPreferredSize().width() + button_spacing + | 496 kLeftEdgeSpacing + back_->GetPreferredSize().width() + button_spacing + |
494 forward_->GetPreferredSize().width() + button_spacing + | 497 forward_->GetPreferredSize().width() + button_spacing + |
495 reload_->GetPreferredSize().width() + kStandardSpacing + | 498 reload_->GetPreferredSize().width() + kStandardSpacing + |
496 (show_home_button_.GetValue() ? | 499 (show_home_button_.GetValue() ? |
497 (home_->GetPreferredSize().width() + button_spacing) : 0) + | 500 (home_->GetPreferredSize().width() + button_spacing) : 0) + |
498 (site_chip_view_->ShouldShow() ? | 501 (site_chip_view_->ShouldShow() ? |
499 (site_chip_view_->GetPreferredSize().width() + | 502 (site_chip_view_->GetPreferredSize().width() + |
500 2 * kStandardSpacing + 2 * button_spacing) : | 503 2 * kStandardSpacing) : |
501 0) + | 504 0) + |
502 browser_actions_->GetPreferredSize().width() + | 505 browser_actions_->GetPreferredSize().width() + |
503 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing, | 506 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing, |
504 0); | 507 0); |
505 gfx::ImageSkia* normal_background = | 508 gfx::ImageSkia* normal_background = |
506 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); | 509 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); |
507 size.SetToMax( | 510 size.SetToMax( |
508 gfx::Size(0, normal_background->height() - content_shadow_height())); | 511 gfx::Size(0, normal_background->height() - content_shadow_height())); |
509 } else { | 512 } else { |
510 const int kPopupBottomSpacingGlass = 1; | 513 const int kPopupBottomSpacingGlass = 1; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
563 home_->SetVisible(true); | 566 home_->SetVisible(true); |
564 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, | 567 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, |
565 child_y, home_->GetPreferredSize().width(), child_height); | 568 child_y, home_->GetPreferredSize().width(), child_height); |
566 } else { | 569 } else { |
567 home_->SetVisible(false); | 570 home_->SetVisible(false); |
568 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); | 571 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); |
569 } | 572 } |
570 | 573 |
571 int browser_actions_width = browser_actions_->GetPreferredSize().width(); | 574 int browser_actions_width = browser_actions_->GetPreferredSize().width(); |
572 | 575 |
573 // Note: spacing from location bar to site chip is 1 pixel less than | |
574 // kStandardSpacing given the edge thickness of the chip. | |
575 int site_chip_width = | |
576 (site_chip_view_->ShouldShow() ? | |
577 site_chip_view_->GetPreferredSize().width() + | |
578 kStandardSpacing : 0); | |
579 int app_menu_width = app_menu_->GetPreferredSize().width(); | 576 int app_menu_width = app_menu_->GetPreferredSize().width(); |
580 int location_x = home_->x() + home_->width() + kStandardSpacing; | 577 int location_x = home_->x() + home_->width() + kStandardSpacing; |
581 int available_width = std::max(0, width() - kRightEdgeSpacing - | 578 int available_width = std::max(0, width() - kRightEdgeSpacing - |
582 app_menu_width - browser_actions_width - location_x); | 579 app_menu_width - browser_actions_width - location_x); |
583 | 580 |
584 // Cap site chip width at 1/2 the size available to the location bar. | 581 // Cap site chip width at 1/2 the size available to the location bar. |
585 site_chip_width = std::min(site_chip_width, available_width / 2); | 582 site_chip_view_->SetVisible(site_chip_view_->ShouldShow()); |
586 available_width -= site_chip_width; | 583 int site_chip_width = site_chip_view_->GetPreferredSize().width(); |
584 site_chip_width = std::max(0, std::min(site_chip_width, | |
585 (available_width - kStandardSpacing) / 2)); | |
586 if (site_chip_view_->visible()) | |
587 available_width -= site_chip_width; | |
587 | 588 |
588 int location_height = location_bar_->GetPreferredSize().height(); | 589 int location_height = location_bar_->GetPreferredSize().height(); |
589 int location_y = (height() - location_height + 1) / 2; | 590 int location_y = (height() - location_height + 1) / 2; |
590 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), | 591 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), |
591 location_height); | 592 location_height); |
592 | |
593 int browser_actions_x = location_bar_->x() + location_bar_->width(); | 593 int browser_actions_x = location_bar_->x() + location_bar_->width(); |
594 | 594 |
595 site_chip_view_->SetVisible(site_chip_view_->ShouldShow()); | 595 if (site_chip_view_->visible()) { |
596 if (site_chip_view_->ShouldShow()) { | |
597 site_chip_view_->SetBounds(browser_actions_x + kStandardSpacing, | 596 site_chip_view_->SetBounds(browser_actions_x + kStandardSpacing, |
598 child_y, | 597 child_y, |
599 site_chip_view_->GetPreferredSize().width(), | 598 site_chip_width, |
600 child_height); | 599 child_height); |
601 browser_actions_x += | 600 browser_actions_x = site_chip_view_->x() + site_chip_view_->width(); |
Peter Kasting
2013/12/10 19:44:31
Nit: Just "site_chip_view_->bounds().right()" suff
Greg Billock
2013/12/10 20:36:23
OK. I noticed that but followed the browser_action
| |
602 site_chip_view_->GetPreferredSize().width() + kStandardSpacing; | |
603 } | 601 } |
604 | 602 |
605 browser_actions_->SetBounds(browser_actions_x, 0, | 603 browser_actions_->SetBounds(browser_actions_x, 0, |
606 browser_actions_width, height()); | 604 browser_actions_width, height()); |
607 | 605 |
608 // The browser actions need to do a layout explicitly, because when an | 606 // The browser actions need to do a layout explicitly, because when an |
609 // extension is loaded/unloaded/changed, BrowserActionContainer removes and | 607 // extension is loaded/unloaded/changed, BrowserActionContainer removes and |
610 // re-adds everything, regardless of whether it has a page action. For a | 608 // re-adds everything, regardless of whether it has a page action. For a |
611 // page action, browser action bounds do not change, as a result of which | 609 // page action, browser action bounds do not change, as a result of which |
612 // SetBounds does not do a layout at all. | 610 // SetBounds does not do a layout at all. |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
840 | 838 |
841 void ToolbarView::OnShowHomeButtonChanged() { | 839 void ToolbarView::OnShowHomeButtonChanged() { |
842 Layout(); | 840 Layout(); |
843 SchedulePaint(); | 841 SchedulePaint(); |
844 } | 842 } |
845 | 843 |
846 int ToolbarView::content_shadow_height() const { | 844 int ToolbarView::content_shadow_height() const { |
847 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? | 845 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? |
848 kContentShadowHeightAsh : kContentShadowHeight; | 846 kContentShadowHeightAsh : kContentShadowHeight; |
849 } | 847 } |
OLD | NEW |