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_); | |
247 show_home_button_.Init(prefs::kShowHomeButton, | 249 show_home_button_.Init(prefs::kShowHomeButton, |
Peter Kasting
2013/12/10 03:28:39
Nit: Blank line above this
Greg Billock
2013/12/10 17:37:59
Done.
| |
248 browser_->profile()->GetPrefs(), | 250 browser_->profile()->GetPrefs(), |
249 base::Bind(&ToolbarView::OnShowHomeButtonChanged, | 251 base::Bind(&ToolbarView::OnShowHomeButtonChanged, |
250 base::Unretained(this))); | 252 base::Unretained(this))); |
251 | 253 |
252 browser_actions_->Init(); | 254 browser_actions_->Init(); |
253 | 255 |
254 // Accessibility specific tooltip text. | 256 // Accessibility specific tooltip text. |
255 if (content::BrowserAccessibilityState::GetInstance()-> | 257 if (content::BrowserAccessibilityState::GetInstance()-> |
256 IsAccessibleBrowser()) { | 258 IsAccessibleBrowser()) { |
257 back_->SetTooltipText( | 259 back_->SetTooltipText( |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 int button_spacing = GetButtonSpacing(); | 492 int button_spacing = GetButtonSpacing(); |
491 int min_width = kLeftEdgeSpacing + | 493 int min_width = kLeftEdgeSpacing + |
492 back_->GetPreferredSize().width() + button_spacing + | 494 back_->GetPreferredSize().width() + button_spacing + |
493 forward_->GetPreferredSize().width() + button_spacing + | 495 forward_->GetPreferredSize().width() + button_spacing + |
494 reload_->GetPreferredSize().width() + kStandardSpacing + | 496 reload_->GetPreferredSize().width() + kStandardSpacing + |
495 (show_home_button_.GetValue() ? | 497 (show_home_button_.GetValue() ? |
496 (home_->GetPreferredSize().width() + button_spacing) : 0) + | 498 (home_->GetPreferredSize().width() + button_spacing) : 0) + |
497 location_bar_->GetPreferredSize().width() + | 499 location_bar_->GetPreferredSize().width() + |
498 (site_chip_view_->ShouldShow() ? | 500 (site_chip_view_->ShouldShow() ? |
499 (site_chip_view_->GetPreferredSize().width() + | 501 (site_chip_view_->GetPreferredSize().width() + |
500 2 * kStandardSpacing + 2 * button_spacing) : | 502 2 * kStandardSpacing + 2 * button_spacing) : |
Peter Kasting
2013/12/10 03:28:39
I still think adding |button_spacing| in here is w
Greg Billock
2013/12/10 17:37:59
Yeah, I'm suspicious that's a leftover from before
| |
501 0) + | 503 0) + |
502 browser_actions_->GetPreferredSize().width() + | 504 browser_actions_->GetPreferredSize().width() + |
503 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; | 505 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; |
504 gfx::ImageSkia* normal_background = | 506 gfx::ImageSkia* normal_background = |
505 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); | 507 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); |
506 return gfx::Size(min_width, | 508 return gfx::Size(min_width, |
507 normal_background->height() - content_shadow_height()); | 509 normal_background->height() - content_shadow_height()); |
508 } | 510 } |
509 | 511 |
510 const int kPopupBottomSpacingGlass = 1; | 512 const int kPopupBottomSpacingGlass = 1; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 home_->SetVisible(true); | 564 home_->SetVisible(true); |
563 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, | 565 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, |
564 child_y, home_->GetPreferredSize().width(), child_height); | 566 child_y, home_->GetPreferredSize().width(), child_height); |
565 } else { | 567 } else { |
566 home_->SetVisible(false); | 568 home_->SetVisible(false); |
567 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); | 569 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); |
568 } | 570 } |
569 | 571 |
570 int browser_actions_width = browser_actions_->GetPreferredSize().width(); | 572 int browser_actions_width = browser_actions_->GetPreferredSize().width(); |
571 | 573 |
572 // Note: spacing from location bar to site chip is 1 pixel less than | |
573 // kStandardSpacing given the edge thickness of the chip. | |
574 int site_chip_width = | |
575 (site_chip_view_->ShouldShow() ? | |
576 site_chip_view_->GetPreferredSize().width() + | |
577 kStandardSpacing : 0); | |
578 int app_menu_width = app_menu_->GetPreferredSize().width(); | 574 int app_menu_width = app_menu_->GetPreferredSize().width(); |
579 int location_x = home_->x() + home_->width() + kStandardSpacing; | 575 int location_x = home_->x() + home_->width() + kStandardSpacing; |
580 int available_width = std::max(0, width() - kRightEdgeSpacing - | 576 int available_width = std::max(0, width() - kRightEdgeSpacing - |
581 app_menu_width - browser_actions_width - location_x); | 577 app_menu_width - browser_actions_width - location_x); |
582 | 578 |
583 // Cap site chip width at 1/2 the size available to the location bar. | 579 // Cap site chip width at 1/2 the size available to the location bar. |
580 int site_chip_width = | |
581 (site_chip_view_->ShouldShow() ? | |
582 site_chip_view_->GetPreferredSize().width() + | |
Peter Kasting
2013/12/10 03:28:39
Nit: This fits on fewer lines (and reads better):
Greg Billock
2013/12/10 17:37:59
I don't think the bug obtains -- I don't think sit
Peter Kasting
2013/12/10 19:44:31
No, but (available_width - kStandardSpacing) possi
Greg Billock
2013/12/10 20:36:23
Yeah, but I thought I'd accounted for that. Anyway
| |
583 kStandardSpacing : 0); | |
584 site_chip_width = std::min(site_chip_width, available_width / 2); | 584 site_chip_width = std::min(site_chip_width, available_width / 2); |
585 available_width -= site_chip_width; | 585 available_width -= site_chip_width; |
586 | 586 |
587 int location_height = location_bar_->GetPreferredSize().height(); | 587 int location_height = location_bar_->GetPreferredSize().height(); |
588 int location_y = (height() - location_height + 1) / 2; | 588 int location_y = (height() - location_height + 1) / 2; |
589 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), | 589 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), |
590 location_height); | 590 location_height); |
591 | |
592 int browser_actions_x = location_bar_->x() + location_bar_->width(); | 591 int browser_actions_x = location_bar_->x() + location_bar_->width(); |
593 | 592 |
594 site_chip_view_->SetVisible(site_chip_view_->ShouldShow()); | 593 site_chip_view_->SetVisible(site_chip_view_->ShouldShow()); |
595 if (site_chip_view_->ShouldShow()) { | 594 if (site_chip_view_->ShouldShow()) { |
596 site_chip_view_->SetBounds(browser_actions_x + kStandardSpacing, | 595 site_chip_view_->SetBounds(browser_actions_x + kStandardSpacing, |
597 child_y, | 596 child_y, |
598 site_chip_view_->GetPreferredSize().width(), | 597 std::max(0, site_chip_width - kStandardSpacing), |
599 child_height); | 598 child_height); |
600 browser_actions_x += | 599 browser_actions_x += site_chip_width; |
601 site_chip_view_->GetPreferredSize().width() + kStandardSpacing; | |
602 } | 600 } |
603 | 601 |
604 browser_actions_->SetBounds(browser_actions_x, 0, | 602 browser_actions_->SetBounds(browser_actions_x, 0, |
605 browser_actions_width, height()); | 603 browser_actions_width, height()); |
606 | 604 |
607 // The browser actions need to do a layout explicitly, because when an | 605 // The browser actions need to do a layout explicitly, because when an |
608 // extension is loaded/unloaded/changed, BrowserActionContainer removes and | 606 // extension is loaded/unloaded/changed, BrowserActionContainer removes and |
609 // re-adds everything, regardless of whether it has a page action. For a | 607 // re-adds everything, regardless of whether it has a page action. For a |
610 // page action, browser action bounds do not change, as a result of which | 608 // page action, browser action bounds do not change, as a result of which |
611 // SetBounds does not do a layout at all. | 609 // SetBounds does not do a layout at all. |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
839 | 837 |
840 void ToolbarView::OnShowHomeButtonChanged() { | 838 void ToolbarView::OnShowHomeButtonChanged() { |
841 Layout(); | 839 Layout(); |
842 SchedulePaint(); | 840 SchedulePaint(); |
843 } | 841 } |
844 | 842 |
845 int ToolbarView::content_shadow_height() const { | 843 int ToolbarView::content_shadow_height() const { |
846 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? | 844 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? |
847 kContentShadowHeightAsh : kContentShadowHeight; | 845 kContentShadowHeightAsh : kContentShadowHeight; |
848 } | 846 } |
OLD | NEW |