| 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" |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 browser_actions_->Layout(); | 621 browser_actions_->Layout(); |
| 622 | 622 |
| 623 // Extend the app menu to the screen's right edge in maximized mode just like | 623 // Extend the app menu to the screen's right edge in maximized mode just like |
| 624 // we extend the back button to the left edge. | 624 // we extend the back button to the left edge. |
| 625 if (maximized) | 625 if (maximized) |
| 626 app_menu_width += insets.right(); | 626 app_menu_width += insets.right(); |
| 627 app_menu_button_->SetBounds(next_element_x, child_y, app_menu_width, | 627 app_menu_button_->SetBounds(next_element_x, child_y, app_menu_width, |
| 628 child_height); | 628 child_height); |
| 629 } | 629 } |
| 630 | 630 |
| 631 void ToolbarView::OnPaint(gfx::Canvas* canvas) { | |
| 632 View::OnPaint(canvas); | |
| 633 | |
| 634 if (is_display_mode_normal()) | |
| 635 return; | |
| 636 | |
| 637 // For glass, we need to draw a black line below the location bar to separate | |
| 638 // it from the content area. For non-glass, the NonClientView draws the | |
| 639 // toolbar background below the location bar for us. | |
| 640 // NOTE: Keep this in sync with BrowserView::GetInfoBarSeparatorColor()! | |
| 641 if (GetWidget()->ShouldWindowContentsBeTransparent()) | |
| 642 canvas->FillRect(gfx::Rect(0, height() - 1, width(), 1), SK_ColorBLACK); | |
| 643 } | |
| 644 | |
| 645 void ToolbarView::OnThemeChanged() { | 631 void ToolbarView::OnThemeChanged() { |
| 646 LoadImages(); | 632 LoadImages(); |
| 647 } | 633 } |
| 648 | 634 |
| 649 const char* ToolbarView::GetClassName() const { | 635 const char* ToolbarView::GetClassName() const { |
| 650 return kViewClassName; | 636 return kViewClassName; |
| 651 } | 637 } |
| 652 | 638 |
| 653 bool ToolbarView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 639 bool ToolbarView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 654 const views::View* focused_view = focus_manager()->GetFocusedView(); | 640 const views::View* focused_view = focus_manager()->GetFocusedView(); |
| 655 if (focused_view && (focused_view->id() == VIEW_ID_OMNIBOX)) | 641 if (focused_view && (focused_view->id() == VIEW_ID_OMNIBOX)) |
| 656 return false; // Let the omnibox handle all accelerator events. | 642 return false; // Let the omnibox handle all accelerator events. |
| 657 return AccessiblePaneView::AcceleratorPressed(accelerator); | 643 return AccessiblePaneView::AcceleratorPressed(accelerator); |
| 658 } | 644 } |
| 659 | 645 |
| 660 bool ToolbarView::ShouldPaintBackground() const { | |
| 661 return display_mode_ == DISPLAYMODE_NORMAL; | |
| 662 } | |
| 663 | |
| 664 //////////////////////////////////////////////////////////////////////////////// | 646 //////////////////////////////////////////////////////////////////////////////// |
| 665 // ToolbarView, protected: | 647 // ToolbarView, protected: |
| 666 | 648 |
| 667 // Override this so that when the user presses F6 to rotate toolbar panes, | 649 // Override this so that when the user presses F6 to rotate toolbar panes, |
| 668 // the location bar gets focus, not the first control in the toolbar - and | 650 // the location bar gets focus, not the first control in the toolbar - and |
| 669 // also so that it selects all content in the location bar. | 651 // also so that it selects all content in the location bar. |
| 670 bool ToolbarView::SetPaneFocusAndFocusDefault() { | 652 bool ToolbarView::SetPaneFocusAndFocusDefault() { |
| 671 if (!location_bar_->HasFocus()) { | 653 if (!location_bar_->HasFocus()) { |
| 672 SetPaneFocus(location_bar_); | 654 SetPaneFocus(location_bar_); |
| 673 location_bar_->FocusLocation(true); | 655 location_bar_->FocusLocation(true); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 #if defined(OS_WIN) | 712 #if defined(OS_WIN) |
| 731 ConflictingModuleView::MaybeShow(browser_, app_menu_button_); | 713 ConflictingModuleView::MaybeShow(browser_, app_menu_button_); |
| 732 #endif | 714 #endif |
| 733 } | 715 } |
| 734 incompatibility_badge_showing = true; | 716 incompatibility_badge_showing = true; |
| 735 return; | 717 return; |
| 736 } | 718 } |
| 737 } | 719 } |
| 738 | 720 |
| 739 int ToolbarView::PopupTopSpacing() const { | 721 int ToolbarView::PopupTopSpacing() const { |
| 740 const int kPopupTopSpacingNonGlass = 3; | 722 const int kAdditionalPopupTopSpacingNonGlass = 2; |
| 741 return GetWidget()->ShouldWindowContentsBeTransparent() ? | 723 return views::NonClientFrameView::kClientEdgeThickness + |
| 742 0 : kPopupTopSpacingNonGlass; | 724 (GetWidget()->ShouldWindowContentsBeTransparent() ? |
| 725 0 : kAdditionalPopupTopSpacingNonGlass); |
| 743 } | 726 } |
| 744 | 727 |
| 745 gfx::Size ToolbarView::SizeForContentSize(gfx::Size size) const { | 728 gfx::Size ToolbarView::SizeForContentSize(gfx::Size size) const { |
| 746 if (is_display_mode_normal()) { | 729 if (is_display_mode_normal()) { |
| 747 // For Material Design the size of the toolbar is computed using the size | 730 // For Material Design the size of the toolbar is computed using the size |
| 748 // of the location bar and constant padding values. For non-material the | 731 // of the location bar and constant padding values. For non-material the |
| 749 // size is based on the provided assets. | 732 // size is based on the provided assets. |
| 750 if (ui::MaterialDesignController::IsModeMaterial()) { | 733 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 751 int content_height = std::max(back_->GetPreferredSize().height(), | 734 int content_height = std::max(back_->GetPreferredSize().height(), |
| 752 location_bar_->GetPreferredSize().height()); | 735 location_bar_->GetPreferredSize().height()); |
| 753 int padding = GetLayoutInsets(TOOLBAR).height(); | 736 int padding = GetLayoutInsets(TOOLBAR).height(); |
| 754 size.SetToMax(gfx::Size(0, content_height + padding)); | 737 size.SetToMax(gfx::Size(0, content_height + padding)); |
| 755 } else { | 738 } else { |
| 756 gfx::ImageSkia* normal_background = | 739 gfx::ImageSkia* normal_background = |
| 757 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); | 740 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); |
| 758 size.SetToMax( | 741 size.SetToMax( |
| 759 gfx::Size(0, normal_background->height() - content_shadow_height())); | 742 gfx::Size(0, normal_background->height() - content_shadow_height())); |
| 760 } | 743 } |
| 761 } else if (size.height() == 0) { | 744 } else if (size.height() == 0) { |
| 762 // Location mode with a 0 height location bar. If on ash, expand by one | 745 // Location mode with a 0 height location bar. If on ash, expand by one |
| 763 // pixel to show a border in the title bar, otherwise leave the size as zero | 746 // pixel to show a border in the title bar, otherwise leave the size as zero |
| 764 // height. | 747 // height. |
| 765 const int kAshBorderSpacing = 1; | 748 const int kAshBorderSpacing = 1; |
| 766 if (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) | 749 if (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) |
| 767 size.Enlarge(0, kAshBorderSpacing); | 750 size.Enlarge(0, kAshBorderSpacing); |
| 768 } else { | 751 } else { |
| 769 const int kPopupBottomSpacingGlass = 1; | |
| 770 const int kPopupBottomSpacingNonGlass = 2; | |
| 771 size.Enlarge( | 752 size.Enlarge( |
| 772 0, | 753 0, PopupTopSpacing() + views::NonClientFrameView::kClientEdgeThickness); |
| 773 PopupTopSpacing() + (GetWidget()->ShouldWindowContentsBeTransparent() ? | |
| 774 kPopupBottomSpacingGlass : kPopupBottomSpacingNonGlass)); | |
| 775 } | 754 } |
| 776 return size; | 755 return size; |
| 777 } | 756 } |
| 778 | 757 |
| 779 void ToolbarView::LoadImages() { | 758 void ToolbarView::LoadImages() { |
| 780 ui::ThemeProvider* tp = GetThemeProvider(); | 759 ui::ThemeProvider* tp = GetThemeProvider(); |
| 781 | 760 |
| 782 if (ui::MaterialDesignController::IsModeMaterial()) { | 761 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 783 const int kButtonSize = 16; | 762 const int kButtonSize = 16; |
| 784 const SkColor normal_color = | 763 const SkColor normal_color = |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 void ToolbarView::OnShowHomeButtonChanged() { | 817 void ToolbarView::OnShowHomeButtonChanged() { |
| 839 Layout(); | 818 Layout(); |
| 840 SchedulePaint(); | 819 SchedulePaint(); |
| 841 } | 820 } |
| 842 | 821 |
| 843 int ToolbarView::content_shadow_height() const { | 822 int ToolbarView::content_shadow_height() const { |
| 844 return GetLayoutConstant( | 823 return GetLayoutConstant( |
| 845 (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) ? | 824 (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) ? |
| 846 TOOLBAR_CONTENT_SHADOW_HEIGHT_ASH : TOOLBAR_CONTENT_SHADOW_HEIGHT); | 825 TOOLBAR_CONTENT_SHADOW_HEIGHT_ASH : TOOLBAR_CONTENT_SHADOW_HEIGHT); |
| 847 } | 826 } |
| OLD | NEW |