| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // our spacing to make it match. | 102 // our spacing to make it match. |
| 103 const int kLeftEdgeSpacing = 3; | 103 const int kLeftEdgeSpacing = 3; |
| 104 const int kRightEdgeSpacing = 2; | 104 const int kRightEdgeSpacing = 2; |
| 105 | 105 |
| 106 // Ash doesn't use a rounded content area and its top edge has an extra shadow. | 106 // Ash doesn't use a rounded content area and its top edge has an extra shadow. |
| 107 const int kContentShadowHeightAsh = 2; | 107 const int kContentShadowHeightAsh = 2; |
| 108 | 108 |
| 109 // Non-ash uses a rounded content area with no shadow in the assets. | 109 // Non-ash uses a rounded content area with no shadow in the assets. |
| 110 const int kContentShadowHeight = 0; | 110 const int kContentShadowHeight = 0; |
| 111 | 111 |
| 112 int GetButtonSpacing() { | |
| 113 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? | |
| 114 ToolbarView::kStandardSpacing : 0; | |
| 115 } | |
| 116 | |
| 117 bool IsStreamlinedHostedAppsEnabled() { | 112 bool IsStreamlinedHostedAppsEnabled() { |
| 118 return CommandLine::ForCurrentProcess()->HasSwitch( | 113 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 119 switches::kEnableStreamlinedHostedApps); | 114 switches::kEnableStreamlinedHostedApps); |
| 120 } | 115 } |
| 121 | 116 |
| 122 #if !defined(OS_CHROMEOS) | 117 #if !defined(OS_CHROMEOS) |
| 123 bool HasAshShell() { | 118 bool HasAshShell() { |
| 124 #if defined(USE_ASH) | 119 #if defined(USE_ASH) |
| 125 return ash::Shell::HasInstance(); | 120 return ash::Shell::HasInstance(); |
| 126 #else | 121 #else |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 DCHECK_EQ(VIEW_ID_APP_MENU, source->id()); | 405 DCHECK_EQ(VIEW_ID_APP_MENU, source->id()); |
| 411 | 406 |
| 412 bool use_new_menu = false; | 407 bool use_new_menu = false; |
| 413 bool supports_new_separators = false; | 408 bool supports_new_separators = false; |
| 414 // TODO: remove this. | 409 // TODO: remove this. |
| 415 #if defined(USE_AURA) | 410 #if defined(USE_AURA) |
| 416 supports_new_separators = | 411 supports_new_separators = |
| 417 GetNativeTheme() == ui::NativeThemeAura::instance(); | 412 GetNativeTheme() == ui::NativeThemeAura::instance(); |
| 418 use_new_menu = supports_new_separators; | 413 use_new_menu = supports_new_separators; |
| 419 #endif | 414 #endif |
| 420 #if defined(OS_WIN) | |
| 421 use_new_menu = use_new_menu || ui::GetDisplayLayout() == ui::LAYOUT_TOUCH; | |
| 422 #endif | |
| 423 | 415 |
| 424 wrench_menu_.reset(new WrenchMenu(browser_, use_new_menu, | 416 wrench_menu_.reset(new WrenchMenu(browser_, use_new_menu, |
| 425 supports_new_separators)); | 417 supports_new_separators)); |
| 426 wrench_menu_model_.reset(new WrenchMenuModel(this, browser_, use_new_menu)); | 418 wrench_menu_model_.reset(new WrenchMenuModel(this, browser_, use_new_menu)); |
| 427 wrench_menu_->Init(wrench_menu_model_.get()); | 419 wrench_menu_->Init(wrench_menu_model_.get()); |
| 428 | 420 |
| 429 FOR_EACH_OBSERVER(views::MenuListener, menu_listeners_, OnMenuOpened()); | 421 FOR_EACH_OBSERVER(views::MenuListener, menu_listeners_, OnMenuOpened()); |
| 430 | 422 |
| 431 wrench_menu_->RunMenu(app_menu_); | 423 wrench_menu_->RunMenu(app_menu_); |
| 432 } | 424 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 ui::Accelerator* accelerator) { | 532 ui::Accelerator* accelerator) { |
| 541 return GetWidget()->GetAccelerator(command_id, accelerator); | 533 return GetWidget()->GetAccelerator(command_id, accelerator); |
| 542 } | 534 } |
| 543 | 535 |
| 544 //////////////////////////////////////////////////////////////////////////////// | 536 //////////////////////////////////////////////////////////////////////////////// |
| 545 // ToolbarView, views::View overrides: | 537 // ToolbarView, views::View overrides: |
| 546 | 538 |
| 547 gfx::Size ToolbarView::GetPreferredSize() { | 539 gfx::Size ToolbarView::GetPreferredSize() { |
| 548 gfx::Size size(location_bar_->GetPreferredSize()); | 540 gfx::Size size(location_bar_->GetPreferredSize()); |
| 549 if (is_display_mode_normal()) { | 541 if (is_display_mode_normal()) { |
| 550 int button_spacing = GetButtonSpacing(); | |
| 551 size.Enlarge( | 542 size.Enlarge( |
| 552 kLeftEdgeSpacing + back_->GetPreferredSize().width() + button_spacing + | 543 kLeftEdgeSpacing + back_->GetPreferredSize().width() + |
| 553 forward_->GetPreferredSize().width() + button_spacing + | 544 forward_->GetPreferredSize().width() + |
| 554 reload_->GetPreferredSize().width() + kStandardSpacing + | 545 reload_->GetPreferredSize().width() + kStandardSpacing + |
| 555 (show_home_button_.GetValue() ? | 546 (show_home_button_.GetValue() ? |
| 556 (home_->GetPreferredSize().width() + button_spacing) : 0) + | 547 home_->GetPreferredSize().width() : 0) + |
| 557 (origin_chip_view_->visible() ? | 548 (origin_chip_view_->visible() ? |
| 558 (origin_chip_view_->GetPreferredSize().width() + | 549 (origin_chip_view_->GetPreferredSize().width() + |
| 559 2 * kStandardSpacing) : | 550 2 * kStandardSpacing) : |
| 560 0) + | 551 0) + |
| 561 browser_actions_->GetPreferredSize().width() + | 552 browser_actions_->GetPreferredSize().width() + |
| 562 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing, | 553 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing, |
| 563 0); | 554 0); |
| 564 gfx::ImageSkia* normal_background = | 555 gfx::ImageSkia* normal_background = |
| 565 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); | 556 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); |
| 566 size.SetToMax( | 557 size.SetToMax( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 // http://crbug.com/5540 | 594 // http://crbug.com/5540 |
| 604 bool maximized = browser_->window() && browser_->window()->IsMaximized(); | 595 bool maximized = browser_->window() && browser_->window()->IsMaximized(); |
| 605 int back_width = back_->GetPreferredSize().width(); | 596 int back_width = back_->GetPreferredSize().width(); |
| 606 if (maximized) { | 597 if (maximized) { |
| 607 back_->SetBounds(0, child_y, back_width + kLeftEdgeSpacing, child_height); | 598 back_->SetBounds(0, child_y, back_width + kLeftEdgeSpacing, child_height); |
| 608 back_->SetLeadingMargin(kLeftEdgeSpacing); | 599 back_->SetLeadingMargin(kLeftEdgeSpacing); |
| 609 } else { | 600 } else { |
| 610 back_->SetBounds(kLeftEdgeSpacing, child_y, back_width, child_height); | 601 back_->SetBounds(kLeftEdgeSpacing, child_y, back_width, child_height); |
| 611 back_->SetLeadingMargin(0); | 602 back_->SetLeadingMargin(0); |
| 612 } | 603 } |
| 613 int button_spacing = GetButtonSpacing(); | 604 int next_element_x = back_->bounds().right(); |
| 614 int next_element_x = back_->bounds().right() + button_spacing; | |
| 615 | 605 |
| 616 forward_->SetBounds(next_element_x, child_y, | 606 forward_->SetBounds(next_element_x, child_y, |
| 617 forward_->GetPreferredSize().width(), child_height); | 607 forward_->GetPreferredSize().width(), child_height); |
| 618 next_element_x = forward_->bounds().right() + button_spacing; | 608 next_element_x = forward_->bounds().right(); |
| 619 | 609 |
| 620 reload_->SetBounds(next_element_x, child_y, | 610 reload_->SetBounds(next_element_x, child_y, |
| 621 reload_->GetPreferredSize().width(), child_height); | 611 reload_->GetPreferredSize().width(), child_height); |
| 622 next_element_x = reload_->bounds().right(); | 612 next_element_x = reload_->bounds().right(); |
| 623 | 613 |
| 624 if (show_home_button_.GetValue() || | 614 if (show_home_button_.GetValue() || |
| 625 (browser_->is_app() && IsStreamlinedHostedAppsEnabled())) { | 615 (browser_->is_app() && IsStreamlinedHostedAppsEnabled())) { |
| 626 home_->SetVisible(true); | 616 home_->SetVisible(true); |
| 627 home_->SetBounds(next_element_x + button_spacing, child_y, | 617 home_->SetBounds(next_element_x, child_y, |
| 628 home_->GetPreferredSize().width(), child_height); | 618 home_->GetPreferredSize().width(), child_height); |
| 629 } else { | 619 } else { |
| 630 home_->SetVisible(false); | 620 home_->SetVisible(false); |
| 631 home_->SetBounds(next_element_x, child_y, 0, child_height); | 621 home_->SetBounds(next_element_x, child_y, 0, child_height); |
| 632 } | 622 } |
| 633 next_element_x = home_->bounds().right() + kStandardSpacing; | 623 next_element_x = home_->bounds().right() + kStandardSpacing; |
| 634 | 624 |
| 635 int browser_actions_width = browser_actions_->GetPreferredSize().width(); | 625 int browser_actions_width = browser_actions_->GetPreferredSize().width(); |
| 636 int app_menu_width = app_menu_->GetPreferredSize().width(); | 626 int app_menu_width = app_menu_->GetPreferredSize().width(); |
| 637 int available_width = std::max(0, width() - kRightEdgeSpacing - | 627 int available_width = std::max(0, width() - kRightEdgeSpacing - |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 | 875 |
| 886 void ToolbarView::OnShowHomeButtonChanged() { | 876 void ToolbarView::OnShowHomeButtonChanged() { |
| 887 Layout(); | 877 Layout(); |
| 888 SchedulePaint(); | 878 SchedulePaint(); |
| 889 } | 879 } |
| 890 | 880 |
| 891 int ToolbarView::content_shadow_height() const { | 881 int ToolbarView::content_shadow_height() const { |
| 892 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? | 882 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? |
| 893 kContentShadowHeightAsh : kContentShadowHeight; | 883 kContentShadowHeightAsh : kContentShadowHeight; |
| 894 } | 884 } |
| OLD | NEW |