| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/toolbar/toolbar_actions_bar.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" | 28 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" |
| 29 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_observer.h" | 29 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_observer.h" |
| 30 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/grit/theme_resources.h" | 31 #include "chrome/grit/theme_resources.h" |
| 32 #include "components/crx_file/id_util.h" | 32 #include "components/crx_file/id_util.h" |
| 33 #include "components/pref_registry/pref_registry_syncable.h" | 33 #include "components/pref_registry/pref_registry_syncable.h" |
| 34 #include "extensions/browser/extension_system.h" | 34 #include "extensions/browser/extension_system.h" |
| 35 #include "extensions/browser/runtime_data.h" | 35 #include "extensions/browser/runtime_data.h" |
| 36 #include "extensions/common/extension.h" | 36 #include "extensions/common/extension.h" |
| 37 #include "extensions/common/feature_switch.h" | 37 #include "extensions/common/feature_switch.h" |
| 38 #include "ui/base/material_design/material_design_controller.h" |
| 38 #include "ui/base/resource/resource_bundle.h" | 39 #include "ui/base/resource/resource_bundle.h" |
| 39 #include "ui/gfx/image/image_skia.h" | 40 #include "ui/gfx/image/image_skia.h" |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 43 using WeakToolbarActions = std::vector<ToolbarActionViewController*>; | 44 using WeakToolbarActions = std::vector<ToolbarActionViewController*>; |
| 44 | 45 |
| 45 enum DimensionType { WIDTH, HEIGHT }; | 46 enum DimensionType { WIDTH, HEIGHT }; |
| 46 | 47 |
| 48 // Returns the width or height of the toolbar action icon size. |
| 49 int GetIconDimension(DimensionType type) { |
| 50 if (ui::MaterialDesignController::IsModeMaterial()) |
| 51 #if defined(OS_MACOSX) |
| 52 // On the Mac, the spec is a 24x24 button in a 28x28 space. |
| 53 return 24; |
| 54 #else |
| 55 return 28; |
| 56 #endif |
| 57 |
| 58 static bool initialized = false; |
| 59 static int icon_height = 0; |
| 60 static int icon_width = 0; |
| 61 if (!initialized) { |
| 62 initialized = true; |
| 63 gfx::ImageSkia* skia = |
| 64 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 65 IDR_BROWSER_ACTION); |
| 66 icon_height = skia->height(); |
| 67 icon_width = skia->width(); |
| 68 } |
| 69 return type == WIDTH ? icon_width : icon_height; |
| 70 } |
| 71 |
| 47 // Takes a reference vector |reference| of length n, where n is less than or | 72 // Takes a reference vector |reference| of length n, where n is less than or |
| 48 // equal to the length of |to_sort|, and rearranges |to_sort| so that | 73 // equal to the length of |to_sort|, and rearranges |to_sort| so that |
| 49 // |to_sort|'s first n elements match the n elements of |reference| (the order | 74 // |to_sort|'s first n elements match the n elements of |reference| (the order |
| 50 // of any remaining elements in |to_sort| is unspecified). | 75 // of any remaining elements in |to_sort| is unspecified). |
| 51 // |equal| is used to compare the elements of |to_sort| and |reference|. | 76 // |equal| is used to compare the elements of |to_sort| and |reference|. |
| 52 // This allows us to sort a vector to match another vector of two different | 77 // This allows us to sort a vector to match another vector of two different |
| 53 // types without needing to construct a more cumbersome comparator class. | 78 // types without needing to construct a more cumbersome comparator class. |
| 54 // |FunctionType| should equate to (something similar to) | 79 // |FunctionType| should equate to (something similar to) |
| 55 // bool Equal(const Type1&, const Type2&), but we can't enforce this | 80 // bool Equal(const Type1&, const Type2&), but we can't enforce this |
| 56 // because of MSVC compilation limitations. | 81 // because of MSVC compilation limitations. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // We don't just call DeleteActions() here because it makes assumptions about | 148 // We don't just call DeleteActions() here because it makes assumptions about |
| 124 // the order of deletion between the views and the ToolbarActionsBar. | 149 // the order of deletion between the views and the ToolbarActionsBar. |
| 125 DCHECK(toolbar_actions_.empty()) << | 150 DCHECK(toolbar_actions_.empty()) << |
| 126 "Must call DeleteActions() before destruction."; | 151 "Must call DeleteActions() before destruction."; |
| 127 for (ToolbarActionsBarObserver& observer : observers_) | 152 for (ToolbarActionsBarObserver& observer : observers_) |
| 128 observer.OnToolbarActionsBarDestroyed(); | 153 observer.OnToolbarActionsBarDestroyed(); |
| 129 } | 154 } |
| 130 | 155 |
| 131 // static | 156 // static |
| 132 int ToolbarActionsBar::IconWidth(bool include_padding) { | 157 int ToolbarActionsBar::IconWidth(bool include_padding) { |
| 133 return IconHeight() + | 158 return GetIconDimension(WIDTH) + |
| 134 (include_padding ? GetLayoutConstant(TOOLBAR_STANDARD_SPACING) : 0); | 159 (include_padding ? GetLayoutConstant(TOOLBAR_STANDARD_SPACING) : 0); |
| 135 } | 160 } |
| 136 | 161 |
| 137 // static | 162 // static |
| 138 int ToolbarActionsBar::IconHeight() { | 163 int ToolbarActionsBar::IconHeight() { |
| 139 #if defined(OS_MACOSX) | 164 return GetIconDimension(HEIGHT); |
| 140 // On the Mac, the spec is a 24x24 button in a 28x28 space. | |
| 141 return 24; | |
| 142 #else | |
| 143 return 28; | |
| 144 #endif | |
| 145 } | 165 } |
| 146 | 166 |
| 147 // static | 167 // static |
| 148 void ToolbarActionsBar::RegisterProfilePrefs( | 168 void ToolbarActionsBar::RegisterProfilePrefs( |
| 149 user_prefs::PrefRegistrySyncable* registry) { | 169 user_prefs::PrefRegistrySyncable* registry) { |
| 150 registry->RegisterBooleanPref( | 170 registry->RegisterBooleanPref( |
| 151 prefs::kToolbarIconSurfacingBubbleAcknowledged, | 171 prefs::kToolbarIconSurfacingBubbleAcknowledged, |
| 152 false, | 172 false, |
| 153 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 173 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 154 registry->RegisterInt64Pref(prefs::kToolbarIconSurfacingBubbleLastShowTime, | 174 registry->RegisterInt64Pref(prefs::kToolbarIconSurfacingBubbleLastShowTime, |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 for (ToolbarActionViewController* action : toolbar_actions_) { | 822 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 803 if (action->GetId() == action_id) | 823 if (action->GetId() == action_id) |
| 804 return action; | 824 return action; |
| 805 } | 825 } |
| 806 return nullptr; | 826 return nullptr; |
| 807 } | 827 } |
| 808 | 828 |
| 809 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 829 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 810 return browser_->tab_strip_model()->GetActiveWebContents(); | 830 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 811 } | 831 } |
| OLD | NEW |