| 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/browser_actions_container.h" | 5 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "third_party/skia/include/core/SkColor.h" | 33 #include "third_party/skia/include/core/SkColor.h" |
| 34 #include "ui/accessibility/ax_view_state.h" | 34 #include "ui/accessibility/ax_view_state.h" |
| 35 #include "ui/base/dragdrop/drag_utils.h" | 35 #include "ui/base/dragdrop/drag_utils.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 37 #include "ui/base/nine_image_painter_factory.h" | 37 #include "ui/base/nine_image_painter_factory.h" |
| 38 #include "ui/base/resource/resource_bundle.h" | 38 #include "ui/base/resource/resource_bundle.h" |
| 39 #include "ui/base/theme_provider.h" | 39 #include "ui/base/theme_provider.h" |
| 40 #include "ui/gfx/animation/slide_animation.h" | 40 #include "ui/gfx/animation/slide_animation.h" |
| 41 #include "ui/gfx/canvas.h" | 41 #include "ui/gfx/canvas.h" |
| 42 #include "ui/gfx/geometry/rect.h" | 42 #include "ui/gfx/geometry/rect.h" |
| 43 #include "ui/views/controls/button/label_button_border.h" |
| 43 #include "ui/views/controls/resize_area.h" | 44 #include "ui/views/controls/resize_area.h" |
| 44 #include "ui/views/metrics.h" | 45 #include "ui/views/metrics.h" |
| 45 #include "ui/views/painter.h" | 46 #include "ui/views/painter.h" |
| 46 #include "ui/views/widget/widget.h" | 47 #include "ui/views/widget/widget.h" |
| 47 | 48 |
| 48 using extensions::Extension; | 49 using extensions::Extension; |
| 49 | 50 |
| 50 namespace { | 51 namespace { |
| 51 | 52 |
| 52 // Horizontal spacing between most items in the container, as well as after the | 53 // Horizontal spacing between most items in the container, as well as after the |
| 53 // last item or chevron (if visible). | 54 // last item or chevron (if visible). |
| 54 const int kItemSpacing = ToolbarView::kStandardSpacing; | 55 const int kItemSpacing = ToolbarView::kStandardSpacing; |
| 55 | 56 |
| 56 // Horizontal spacing before the chevron (if visible). | 57 // Horizontal spacing before the chevron (if visible). |
| 57 const int kChevronSpacing = kItemSpacing - 2; | 58 const int kChevronSpacing = kItemSpacing - 2; |
| 58 | 59 |
| 60 // A version of MenuButton with almost empty insets to fit properly on the |
| 61 // toolbar. |
| 62 class ChevronMenuButton : public views::MenuButton { |
| 63 public: |
| 64 ChevronMenuButton(views::ButtonListener* listener, |
| 65 const base::string16& text, |
| 66 views::MenuButtonListener* menu_button_listener, |
| 67 bool show_menu_marker) |
| 68 : views::MenuButton(listener, |
| 69 text, |
| 70 menu_button_listener, |
| 71 show_menu_marker) { |
| 72 } |
| 73 |
| 74 virtual ~ChevronMenuButton() {} |
| 75 |
| 76 virtual scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const |
| 77 OVERRIDE { |
| 78 // The chevron resource was designed to not have any insets. |
| 79 scoped_ptr<views::LabelButtonBorder> border = |
| 80 views::MenuButton::CreateDefaultBorder(); |
| 81 border->set_insets(gfx::Insets()); |
| 82 return border.Pass(); |
| 83 } |
| 84 |
| 85 private: |
| 86 DISALLOW_COPY_AND_ASSIGN(ChevronMenuButton); |
| 87 }; |
| 88 |
| 59 } // namespace | 89 } // namespace |
| 60 | 90 |
| 61 // static | 91 // static |
| 62 bool BrowserActionsContainer::disable_animations_during_testing_ = false; | 92 bool BrowserActionsContainer::disable_animations_during_testing_ = false; |
| 63 | 93 |
| 64 //////////////////////////////////////////////////////////////////////////////// | 94 //////////////////////////////////////////////////////////////////////////////// |
| 65 // BrowserActionsContainer | 95 // BrowserActionsContainer |
| 66 | 96 |
| 67 BrowserActionsContainer::BrowserActionsContainer(Browser* browser, | 97 BrowserActionsContainer::BrowserActionsContainer(Browser* browser, |
| 68 View* owner_view) | 98 View* owner_view) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 90 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( | 120 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( |
| 91 browser->profile(), | 121 browser->profile(), |
| 92 owner_view->GetFocusManager(), | 122 owner_view->GetFocusManager(), |
| 93 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, | 123 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, |
| 94 this)); | 124 this)); |
| 95 | 125 |
| 96 resize_animation_.reset(new gfx::SlideAnimation(this)); | 126 resize_animation_.reset(new gfx::SlideAnimation(this)); |
| 97 resize_area_ = new views::ResizeArea(this); | 127 resize_area_ = new views::ResizeArea(this); |
| 98 AddChildView(resize_area_); | 128 AddChildView(resize_area_); |
| 99 | 129 |
| 100 chevron_ = new views::MenuButton(NULL, base::string16(), this, false); | 130 chevron_ = new ChevronMenuButton(NULL, base::string16(), this, false); |
| 101 chevron_->SetBorder(views::Border::NullBorder()); | |
| 102 chevron_->EnableCanvasFlippingForRTLUI(true); | 131 chevron_->EnableCanvasFlippingForRTLUI(true); |
| 103 chevron_->SetAccessibleName( | 132 chevron_->SetAccessibleName( |
| 104 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); | 133 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); |
| 105 chevron_->SetVisible(false); | 134 chevron_->SetVisible(false); |
| 106 AddChildView(chevron_); | 135 AddChildView(chevron_); |
| 107 } | 136 } |
| 108 | 137 |
| 109 BrowserActionsContainer::~BrowserActionsContainer() { | 138 BrowserActionsContainer::~BrowserActionsContainer() { |
| 110 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 139 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
| 111 observers_, | 140 observers_, |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 // we delete and recreate everything here, but that's how it's done in | 817 // we delete and recreate everything here, but that's how it's done in |
| 789 // BrowserActionMoved(), too. If we want to optimize it, we could move the | 818 // BrowserActionMoved(), too. If we want to optimize it, we could move the |
| 790 // existing icons, instead of deleting it all. | 819 // existing icons, instead of deleting it all. |
| 791 DeleteBrowserActionViews(); | 820 DeleteBrowserActionViews(); |
| 792 CreateBrowserActionViews(); | 821 CreateBrowserActionViews(); |
| 793 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, browser_action_views_.size()); | 822 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, browser_action_views_.size()); |
| 794 } | 823 } |
| 795 | 824 |
| 796 void BrowserActionsContainer::LoadImages() { | 825 void BrowserActionsContainer::LoadImages() { |
| 797 ui::ThemeProvider* tp = GetThemeProvider(); | 826 ui::ThemeProvider* tp = GetThemeProvider(); |
| 798 chevron_->SetIcon(*tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); | 827 chevron_->SetImage(views::Button::STATE_NORMAL, |
| 799 chevron_->SetHoverIcon(*tp->GetImageSkiaNamed( | 828 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); |
| 800 IDR_BROWSER_ACTIONS_OVERFLOW_H)); | |
| 801 chevron_->SetPushedIcon(*tp->GetImageSkiaNamed( | |
| 802 IDR_BROWSER_ACTIONS_OVERFLOW_P)); | |
| 803 | 829 |
| 804 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); | 830 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); |
| 805 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); | 831 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); |
| 806 } | 832 } |
| 807 | 833 |
| 808 void BrowserActionsContainer::SetContainerWidth() { | 834 void BrowserActionsContainer::SetContainerWidth() { |
| 809 int visible_actions = model_->GetVisibleIconCount(); | 835 int visible_actions = model_->GetVisibleIconCount(); |
| 810 if (visible_actions < 0) // All icons should be visible. | 836 if (visible_actions < 0) // All icons should be visible. |
| 811 visible_actions = model_->toolbar_items().size(); | 837 visible_actions = model_->toolbar_items().size(); |
| 812 chevron_->SetVisible( | 838 chevron_->SetVisible( |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 views::BubbleBorder::TOP_RIGHT, | 975 views::BubbleBorder::TOP_RIGHT, |
| 950 show_action); | 976 show_action); |
| 951 popup_->GetWidget()->AddObserver(this); | 977 popup_->GetWidget()->AddObserver(this); |
| 952 popup_button_ = button; | 978 popup_button_ = button; |
| 953 | 979 |
| 954 // Only set button as pushed if it was triggered by a user click. | 980 // Only set button as pushed if it was triggered by a user click. |
| 955 if (should_grant) | 981 if (should_grant) |
| 956 popup_button_->SetButtonPushed(); | 982 popup_button_->SetButtonPushed(); |
| 957 return true; | 983 return true; |
| 958 } | 984 } |
| OLD | NEW |