Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/i18n/number_formatting.h" | 10 #include "base/i18n/number_formatting.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/command_updater.h" | 16 #include "chrome/browser/command_updater.h" |
| 17 #include "chrome/browser/extensions/extension_commands_global_registry.h" | 17 #include "chrome/browser/extensions/extension_commands_global_registry.h" |
| 18 #include "chrome/browser/extensions/extension_util.h" | 18 #include "chrome/browser/extensions/extension_util.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/themes/theme_properties.h" | |
| 20 #include "chrome/browser/themes/theme_service.h" | 21 #include "chrome/browser/themes/theme_service.h" |
| 21 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_command_controller.h" | 23 #include "chrome/browser/ui/browser_command_controller.h" |
| 23 #include "chrome/browser/ui/browser_commands.h" | 24 #include "chrome/browser/ui/browser_commands.h" |
| 24 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" | 25 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" |
| 25 #include "chrome/browser/ui/browser_instant_controller.h" | 26 #include "chrome/browser/ui/browser_instant_controller.h" |
| 26 #include "chrome/browser/ui/browser_tabstrip.h" | 27 #include "chrome/browser/ui/browser_tabstrip.h" |
| 27 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
| 28 #include "chrome/browser/ui/global_error/global_error_service.h" | 29 #include "chrome/browser/ui/global_error/global_error_service.h" |
| 29 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 30 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 | 85 |
| 85 #if defined(USE_ASH) | 86 #if defined(USE_ASH) |
| 86 #include "ash/shell.h" | 87 #include "ash/shell.h" |
| 87 #endif | 88 #endif |
| 88 | 89 |
| 89 using base::UserMetricsAction; | 90 using base::UserMetricsAction; |
| 90 using content::WebContents; | 91 using content::WebContents; |
| 91 | 92 |
| 92 namespace { | 93 namespace { |
| 93 | 94 |
| 94 // The edge graphics have some built-in spacing/shadowing, so we have to adjust | |
| 95 // our spacing to make it match. | |
| 96 const int kLeftEdgeSpacing = 3; | |
| 97 const int kRightEdgeSpacing = 2; | |
| 98 | |
| 99 // Ash doesn't use a rounded content area and its top edge has an extra shadow. | |
| 100 const int kContentShadowHeightAsh = 2; | |
| 101 | |
| 102 // Non-ash uses a rounded content area with no shadow in the assets. | |
| 103 const int kContentShadowHeight = 0; | |
| 104 | |
| 105 #if !defined(OS_CHROMEOS) | 95 #if !defined(OS_CHROMEOS) |
| 106 bool HasAshShell() { | 96 bool HasAshShell() { |
| 107 #if defined(USE_ASH) | 97 #if defined(USE_ASH) |
| 108 return ash::Shell::HasInstance(); | 98 return ash::Shell::HasInstance(); |
| 109 #else | 99 #else |
| 110 return false; | 100 return false; |
| 111 #endif // USE_ASH | 101 #endif // USE_ASH |
| 112 } | 102 } |
| 113 #endif // OS_CHROMEOS | 103 #endif // OS_CHROMEOS |
| 114 | 104 |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 bool ToolbarView::GetAcceleratorForCommandId(int command_id, | 479 bool ToolbarView::GetAcceleratorForCommandId(int command_id, |
| 490 ui::Accelerator* accelerator) { | 480 ui::Accelerator* accelerator) { |
| 491 return GetWidget()->GetAccelerator(command_id, accelerator); | 481 return GetWidget()->GetAccelerator(command_id, accelerator); |
| 492 } | 482 } |
| 493 | 483 |
| 494 //////////////////////////////////////////////////////////////////////////////// | 484 //////////////////////////////////////////////////////////////////////////////// |
| 495 // ToolbarView, views::View overrides: | 485 // ToolbarView, views::View overrides: |
| 496 | 486 |
| 497 gfx::Size ToolbarView::GetPreferredSize() const { | 487 gfx::Size ToolbarView::GetPreferredSize() const { |
| 498 gfx::Size size(location_bar_->GetPreferredSize()); | 488 gfx::Size size(location_bar_->GetPreferredSize()); |
| 489 ui::ThemeProvider* theme_provider = GetThemeProvider(); | |
| 499 if (is_display_mode_normal()) { | 490 if (is_display_mode_normal()) { |
| 500 int content_width = kLeftEdgeSpacing + back_->GetPreferredSize().width() + | 491 int content_width = |
| 492 theme_provider->GetDisplayProperty( | |
| 493 ThemeProperties::PROPERTY_TOOLBAR_VIEW_LEFT_EDGE_SPACING) + | |
| 494 back_->GetPreferredSize().width() + | |
| 501 forward_->GetPreferredSize().width() + | 495 forward_->GetPreferredSize().width() + |
| 502 reload_->GetPreferredSize().width() + | 496 reload_->GetPreferredSize().width() + |
| 503 (show_home_button_.GetValue() ? home_->GetPreferredSize().width() : 0) + | 497 (show_home_button_.GetValue() ? home_->GetPreferredSize().width() : 0) + |
| 504 kStandardSpacing + browser_actions_->GetPreferredSize().width() + | 498 kStandardSpacing + browser_actions_->GetPreferredSize().width() + |
| 505 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; | 499 app_menu_->GetPreferredSize().width() + |
| 500 theme_provider->GetDisplayProperty( | |
| 501 ThemeProperties::PROPERTY_TOOLBAR_VIEW_RIGHT_EDGE_SPACING); | |
| 506 size.Enlarge(content_width, 0); | 502 size.Enlarge(content_width, 0); |
| 507 } | 503 } |
| 508 return SizeForContentSize(size); | 504 return SizeForContentSize(size); |
| 509 } | 505 } |
| 510 | 506 |
| 511 gfx::Size ToolbarView::GetMinimumSize() const { | 507 gfx::Size ToolbarView::GetMinimumSize() const { |
| 512 gfx::Size size(location_bar_->GetMinimumSize()); | 508 gfx::Size size(location_bar_->GetMinimumSize()); |
| 509 ui::ThemeProvider* theme_provider = GetThemeProvider(); | |
| 513 if (is_display_mode_normal()) { | 510 if (is_display_mode_normal()) { |
| 514 int content_width = kLeftEdgeSpacing + back_->GetMinimumSize().width() + | 511 int content_width = |
| 515 forward_->GetMinimumSize().width() + reload_->GetMinimumSize().width() + | 512 theme_provider->GetDisplayProperty( |
| 513 ThemeProperties::PROPERTY_TOOLBAR_VIEW_LEFT_EDGE_SPACING) + | |
| 514 back_->GetMinimumSize().width() + forward_->GetMinimumSize().width() + | |
| 515 reload_->GetMinimumSize().width() + | |
| 516 (show_home_button_.GetValue() ? home_->GetMinimumSize().width() : 0) + | 516 (show_home_button_.GetValue() ? home_->GetMinimumSize().width() : 0) + |
| 517 kStandardSpacing + browser_actions_->GetMinimumSize().width() + | 517 kStandardSpacing + browser_actions_->GetMinimumSize().width() + |
| 518 app_menu_->GetMinimumSize().width() + kRightEdgeSpacing; | 518 app_menu_->GetMinimumSize().width() + |
| 519 theme_provider->GetDisplayProperty( | |
| 520 ThemeProperties::PROPERTY_TOOLBAR_VIEW_RIGHT_EDGE_SPACING); | |
| 519 size.Enlarge(content_width, 0); | 521 size.Enlarge(content_width, 0); |
| 520 } | 522 } |
| 521 return SizeForContentSize(size); | 523 return SizeForContentSize(size); |
| 522 } | 524 } |
| 523 | 525 |
| 524 void ToolbarView::Layout() { | 526 void ToolbarView::Layout() { |
| 525 // If we have not been initialized yet just do nothing. | 527 // If we have not been initialized yet just do nothing. |
| 526 if (back_ == NULL) | 528 if (back_ == NULL) |
| 527 return; | 529 return; |
| 528 | 530 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 541 | 543 |
| 542 // If the window is maximized, we extend the back button to the left so that | 544 // If the window is maximized, we extend the back button to the left so that |
| 543 // clicking on the left-most pixel will activate the back button. | 545 // clicking on the left-most pixel will activate the back button. |
| 544 // TODO(abarth): If the window becomes maximized but is not resized, | 546 // TODO(abarth): If the window becomes maximized but is not resized, |
| 545 // then Layout() might not be called and the back button | 547 // then Layout() might not be called and the back button |
| 546 // will be slightly the wrong size. We should force a | 548 // will be slightly the wrong size. We should force a |
| 547 // Layout() in this case. | 549 // Layout() in this case. |
| 548 // http://crbug.com/5540 | 550 // http://crbug.com/5540 |
| 549 bool maximized = browser_->window() && browser_->window()->IsMaximized(); | 551 bool maximized = browser_->window() && browser_->window()->IsMaximized(); |
| 550 int back_width = back_->GetPreferredSize().width(); | 552 int back_width = back_->GetPreferredSize().width(); |
| 553 ui::ThemeProvider* theme_provider = GetThemeProvider(); | |
| 554 const int left_edge_spacing = theme_provider->GetDisplayProperty( | |
| 555 ThemeProperties::PROPERTY_TOOLBAR_VIEW_LEFT_EDGE_SPACING); | |
| 551 if (maximized) { | 556 if (maximized) { |
| 552 back_->SetBounds(0, child_y, back_width + kLeftEdgeSpacing, child_height); | 557 back_->SetBounds(0, child_y, back_width + left_edge_spacing, child_height); |
| 553 back_->SetLeadingMargin(kLeftEdgeSpacing); | 558 back_->SetLeadingMargin(left_edge_spacing); |
| 554 } else { | 559 } else { |
| 555 back_->SetBounds(kLeftEdgeSpacing, child_y, back_width, child_height); | 560 back_->SetBounds(left_edge_spacing, child_y, back_width, child_height); |
| 556 back_->SetLeadingMargin(0); | 561 back_->SetLeadingMargin(0); |
| 557 } | 562 } |
| 558 int next_element_x = back_->bounds().right(); | 563 int next_element_x = back_->bounds().right(); |
| 559 | 564 |
| 560 forward_->SetBounds(next_element_x, child_y, | 565 forward_->SetBounds(next_element_x, child_y, |
| 561 forward_->GetPreferredSize().width(), child_height); | 566 forward_->GetPreferredSize().width(), child_height); |
| 562 next_element_x = forward_->bounds().right(); | 567 next_element_x = forward_->bounds().right(); |
| 563 | 568 |
| 564 reload_->SetBounds(next_element_x, child_y, | 569 reload_->SetBounds(next_element_x, child_y, |
| 565 reload_->GetPreferredSize().width(), child_height); | 570 reload_->GetPreferredSize().width(), child_height); |
| 566 next_element_x = reload_->bounds().right(); | 571 next_element_x = reload_->bounds().right(); |
| 567 | 572 |
| 568 if (show_home_button_.GetValue() || | 573 if (show_home_button_.GetValue() || |
| 569 (browser_->is_app() && extensions::util::IsNewBookmarkAppsEnabled())) { | 574 (browser_->is_app() && extensions::util::IsNewBookmarkAppsEnabled())) { |
| 570 home_->SetVisible(true); | 575 home_->SetVisible(true); |
| 571 home_->SetBounds(next_element_x, child_y, | 576 home_->SetBounds(next_element_x, child_y, |
| 572 home_->GetPreferredSize().width(), child_height); | 577 home_->GetPreferredSize().width(), child_height); |
| 573 } else { | 578 } else { |
| 574 home_->SetVisible(false); | 579 home_->SetVisible(false); |
| 575 home_->SetBounds(next_element_x, child_y, 0, child_height); | 580 home_->SetBounds(next_element_x, child_y, 0, child_height); |
| 576 } | 581 } |
| 577 next_element_x = home_->bounds().right() + kStandardSpacing; | 582 next_element_x = home_->bounds().right() + kStandardSpacing; |
| 578 | 583 |
| 579 int browser_actions_width = browser_actions_->GetPreferredSize().width(); | 584 int browser_actions_width = browser_actions_->GetPreferredSize().width(); |
| 580 int app_menu_width = app_menu_->GetPreferredSize().width(); | 585 int app_menu_width = app_menu_->GetPreferredSize().width(); |
| 581 int available_width = std::max(0, width() - kRightEdgeSpacing - | 586 const int right_edge_spacing = theme_provider->GetDisplayProperty( |
| 582 app_menu_width - browser_actions_width - next_element_x); | 587 ThemeProperties::PROPERTY_TOOLBAR_VIEW_RIGHT_EDGE_SPACING); |
| 588 int available_width = | |
| 589 std::max(0, width() - right_edge_spacing - app_menu_width - | |
| 590 browser_actions_width - next_element_x); | |
| 583 | 591 |
| 584 int location_height = location_bar_->GetPreferredSize().height(); | 592 int location_height = location_bar_->GetPreferredSize().height(); |
| 585 int location_y = (height() - location_height + 1) / 2; | 593 int location_y = (height() - location_height + 1) / 2; |
| 586 location_bar_->SetBounds(next_element_x, location_y, | 594 location_bar_->SetBounds(next_element_x, location_y, |
| 587 std::max(available_width, 0), location_height); | 595 std::max(available_width, 0), location_height); |
| 588 next_element_x = location_bar_->bounds().right(); | 596 next_element_x = location_bar_->bounds().right(); |
| 589 | 597 |
| 590 browser_actions_->SetBounds( | 598 browser_actions_->SetBounds( |
| 591 next_element_x, child_y, browser_actions_width, child_height); | 599 next_element_x, child_y, browser_actions_width, child_height); |
| 592 next_element_x = browser_actions_->bounds().right(); | 600 next_element_x = browser_actions_->bounds().right(); |
| 593 | 601 |
| 594 // The browser actions need to do a layout explicitly, because when an | 602 // The browser actions need to do a layout explicitly, because when an |
| 595 // extension is loaded/unloaded/changed, BrowserActionContainer removes and | 603 // extension is loaded/unloaded/changed, BrowserActionContainer removes and |
| 596 // re-adds everything, regardless of whether it has a page action. For a | 604 // re-adds everything, regardless of whether it has a page action. For a |
| 597 // page action, browser action bounds do not change, as a result of which | 605 // page action, browser action bounds do not change, as a result of which |
| 598 // SetBounds does not do a layout at all. | 606 // SetBounds does not do a layout at all. |
| 599 // TODO(sidchat): Rework the above behavior so that explicit layout is not | 607 // TODO(sidchat): Rework the above behavior so that explicit layout is not |
| 600 // required. | 608 // required. |
| 601 browser_actions_->Layout(); | 609 browser_actions_->Layout(); |
| 602 | 610 |
| 603 // Extend the app menu to the screen's right edge in maximized mode just like | 611 // Extend the app menu to the screen's right edge in maximized mode just like |
| 604 // we extend the back button to the left edge. | 612 // we extend the back button to the left edge. |
| 605 if (maximized) | 613 if (maximized) |
| 606 app_menu_width += kRightEdgeSpacing; | 614 app_menu_width += right_edge_spacing; |
| 607 app_menu_->SetBounds(next_element_x, child_y, app_menu_width, child_height); | 615 app_menu_->SetBounds(next_element_x, child_y, app_menu_width, child_height); |
| 608 } | 616 } |
| 609 | 617 |
| 610 void ToolbarView::OnPaint(gfx::Canvas* canvas) { | 618 void ToolbarView::OnPaint(gfx::Canvas* canvas) { |
| 611 View::OnPaint(canvas); | 619 View::OnPaint(canvas); |
| 612 | 620 |
| 613 if (is_display_mode_normal()) | 621 if (is_display_mode_normal()) |
| 614 return; | 622 return; |
| 615 | 623 |
| 616 // For glass, we need to draw a black line below the location bar to separate | 624 // For glass, we need to draw a black line below the location bar to separate |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 782 app_menu_, browser_, auto_update_enabled); | 790 app_menu_, browser_, auto_update_enabled); |
| 783 } | 791 } |
| 784 } | 792 } |
| 785 | 793 |
| 786 void ToolbarView::OnShowHomeButtonChanged() { | 794 void ToolbarView::OnShowHomeButtonChanged() { |
| 787 Layout(); | 795 Layout(); |
| 788 SchedulePaint(); | 796 SchedulePaint(); |
| 789 } | 797 } |
| 790 | 798 |
| 791 int ToolbarView::content_shadow_height() const { | 799 int ToolbarView::content_shadow_height() const { |
| 792 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? | 800 ui::ThemeProvider* theme_provider = GetThemeProvider(); |
| 793 kContentShadowHeightAsh : kContentShadowHeight; | 801 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH |
|
Peter Kasting
2015/07/03 20:13:08
Nit: Simpler:
return theme_provider->GetDisplay
jonross
2015/07/06 18:36:21
Done.
| |
| 802 ? theme_provider->GetDisplayProperty( | |
| 803 ThemeProperties:: | |
| 804 PROPERTY_TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT_ASH) | |
| 805 : theme_provider->GetDisplayProperty( | |
| 806 ThemeProperties:: | |
| 807 PROPERTY_TOOLBAR_VIEW_CONTENT_SHADOW_HEIGHT); | |
| 794 } | 808 } |
| OLD | NEW |