Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_actions_bar.cc

Issue 2466343002: Reland of Some more pre-material cleanups (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/layout_constants.cc ('k') | chrome/browser/ui/views/infobars/infobar_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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"
39 #include "ui/base/resource/resource_bundle.h" 38 #include "ui/base/resource/resource_bundle.h"
40 #include "ui/gfx/image/image_skia.h" 39 #include "ui/gfx/image/image_skia.h"
41 40
42 namespace { 41 namespace {
43 42
44 using WeakToolbarActions = std::vector<ToolbarActionViewController*>; 43 using WeakToolbarActions = std::vector<ToolbarActionViewController*>;
45 44
46 enum DimensionType { WIDTH, HEIGHT }; 45 enum DimensionType { WIDTH, HEIGHT };
47 46
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
72 // Takes a reference vector |reference| of length n, where n is less than or 47 // Takes a reference vector |reference| of length n, where n is less than or
73 // equal to the length of |to_sort|, and rearranges |to_sort| so that 48 // equal to the length of |to_sort|, and rearranges |to_sort| so that
74 // |to_sort|'s first n elements match the n elements of |reference| (the order 49 // |to_sort|'s first n elements match the n elements of |reference| (the order
75 // of any remaining elements in |to_sort| is unspecified). 50 // of any remaining elements in |to_sort| is unspecified).
76 // |equal| is used to compare the elements of |to_sort| and |reference|. 51 // |equal| is used to compare the elements of |to_sort| and |reference|.
77 // This allows us to sort a vector to match another vector of two different 52 // This allows us to sort a vector to match another vector of two different
78 // types without needing to construct a more cumbersome comparator class. 53 // types without needing to construct a more cumbersome comparator class.
79 // |FunctionType| should equate to (something similar to) 54 // |FunctionType| should equate to (something similar to)
80 // bool Equal(const Type1&, const Type2&), but we can't enforce this 55 // bool Equal(const Type1&, const Type2&), but we can't enforce this
81 // because of MSVC compilation limitations. 56 // because of MSVC compilation limitations.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // We don't just call DeleteActions() here because it makes assumptions about 123 // We don't just call DeleteActions() here because it makes assumptions about
149 // the order of deletion between the views and the ToolbarActionsBar. 124 // the order of deletion between the views and the ToolbarActionsBar.
150 DCHECK(toolbar_actions_.empty()) << 125 DCHECK(toolbar_actions_.empty()) <<
151 "Must call DeleteActions() before destruction."; 126 "Must call DeleteActions() before destruction.";
152 for (ToolbarActionsBarObserver& observer : observers_) 127 for (ToolbarActionsBarObserver& observer : observers_)
153 observer.OnToolbarActionsBarDestroyed(); 128 observer.OnToolbarActionsBarDestroyed();
154 } 129 }
155 130
156 // static 131 // static
157 int ToolbarActionsBar::IconWidth(bool include_padding) { 132 int ToolbarActionsBar::IconWidth(bool include_padding) {
158 return GetIconDimension(WIDTH) + 133 return IconHeight() +
159 (include_padding ? GetLayoutConstant(TOOLBAR_STANDARD_SPACING) : 0); 134 (include_padding ? GetLayoutConstant(TOOLBAR_STANDARD_SPACING) : 0);
160 } 135 }
161 136
162 // static 137 // static
163 int ToolbarActionsBar::IconHeight() { 138 int ToolbarActionsBar::IconHeight() {
164 return GetIconDimension(HEIGHT); 139 #if defined(OS_MACOSX)
140 // On the Mac, the spec is a 24x24 button in a 28x28 space.
141 return 24;
142 #else
143 return 28;
144 #endif
165 } 145 }
166 146
167 // static 147 // static
168 void ToolbarActionsBar::RegisterProfilePrefs( 148 void ToolbarActionsBar::RegisterProfilePrefs(
169 user_prefs::PrefRegistrySyncable* registry) { 149 user_prefs::PrefRegistrySyncable* registry) {
170 registry->RegisterBooleanPref( 150 registry->RegisterBooleanPref(
171 prefs::kToolbarIconSurfacingBubbleAcknowledged, 151 prefs::kToolbarIconSurfacingBubbleAcknowledged,
172 false, 152 false,
173 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 153 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
174 registry->RegisterInt64Pref(prefs::kToolbarIconSurfacingBubbleLastShowTime, 154 registry->RegisterInt64Pref(prefs::kToolbarIconSurfacingBubbleLastShowTime,
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 for (ToolbarActionViewController* action : toolbar_actions_) { 802 for (ToolbarActionViewController* action : toolbar_actions_) {
823 if (action->GetId() == action_id) 803 if (action->GetId() == action_id)
824 return action; 804 return action;
825 } 805 }
826 return nullptr; 806 return nullptr;
827 } 807 }
828 808
829 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { 809 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() {
830 return browser_->tab_strip_model()->GetActiveWebContents(); 810 return browser_->tab_strip_model()->GetActiveWebContents();
831 } 811 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/layout_constants.cc ('k') | chrome/browser/ui/views/infobars/infobar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698