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

Side by Side Diff: chrome/browser/ui/views/toolbar/toolbar_button.cc

Issue 2555623002: Last round of cleaning up MD layout constants. (Closed)
Patch Set: rebase Created 4 years 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
OLDNEW
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_button.h" 5 #include "chrome/browser/ui/views/toolbar/toolbar_button.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/themes/theme_service.h" 13 #include "chrome/browser/themes/theme_service.h"
14 #include "chrome/browser/themes/theme_service_factory.h" 14 #include "chrome/browser/themes/theme_service_factory.h"
15 #include "chrome/browser/ui/layout_constants.h"
16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
17 #include "ui/accessibility/ax_node_data.h" 16 #include "ui/accessibility/ax_node_data.h"
18 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/models/menu_model.h" 18 #include "ui/base/models/menu_model.h"
20 #include "ui/display/display.h" 19 #include "ui/display/display.h"
21 #include "ui/display/screen.h" 20 #include "ui/display/screen.h"
22 #include "ui/strings/grit/ui_strings.h" 21 #include "ui/strings/grit/ui_strings.h"
23 #include "ui/views/controls/button/label_button_border.h" 22 #include "ui/views/controls/button/label_button_border.h"
24 #include "ui/views/controls/menu/menu_item_view.h" 23 #include "ui/views/controls/menu/menu_item_view.h"
25 #include "ui/views/controls/menu/menu_model_adapter.h" 24 #include "ui/views/controls/menu/menu_model_adapter.h"
(...skipping 25 matching lines...) Expand all
51 void ToolbarButton::ClearPendingMenu() { 50 void ToolbarButton::ClearPendingMenu() {
52 show_menu_factory_.InvalidateWeakPtrs(); 51 show_menu_factory_.InvalidateWeakPtrs();
53 } 52 }
54 53
55 bool ToolbarButton::IsMenuShowing() const { 54 bool ToolbarButton::IsMenuShowing() const {
56 return menu_showing_; 55 return menu_showing_;
57 } 56 }
58 57
59 gfx::Size ToolbarButton::GetPreferredSize() const { 58 gfx::Size ToolbarButton::GetPreferredSize() const {
60 gfx::Size size(image()->GetPreferredSize()); 59 gfx::Size size(image()->GetPreferredSize());
60 // TODO(estade): do we ever actually set text on a ToolbarButton?
Peter Kasting 2016/12/08 20:57:50 Maybe for extensions?
Evan Stade 2016/12/13 01:31:19 I don't see how extensions could reach this becaus
61 gfx::Size label_size = label()->GetPreferredSize(); 61 gfx::Size label_size = label()->GetPreferredSize();
62 CHECK_EQ(0, label_size.width());
Peter Kasting 2016/12/08 20:57:50 I'd kinda rather add something like this in a sepa
Evan Stade 2016/12/13 01:31:19 oops --- this was just meant to be debug code I se
62 if (label_size.width() > 0) { 63 if (label_size.width() > 0) {
63 size.Enlarge( 64 size.Enlarge(label_size.width() /* + LocationBarView::kHorizontalPadding*/,
Peter Kasting 2016/12/08 20:57:50 Commenting this out seems wrong?
Evan Stade 2016/12/13 01:31:19 yea, removed.
64 label_size.width() + GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING), 65 0);
65 0);
66 } 66 }
67 const int pad = GetLayoutConstant(TOOLBAR_BUTTON_PADDING); 67 gfx::Rect rect(size);
68 size.Enlarge(2 * pad, 2 * pad); 68 rect.Inset(gfx::Insets(-kInteriorPadding));
69 return size; 69 return rect.size();
70 } 70 }
71 71
72 bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) { 72 bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) {
73 if (IsTriggerableEvent(event) && enabled() && ShouldShowMenu() && 73 if (IsTriggerableEvent(event) && enabled() && ShouldShowMenu() &&
74 HitTestPoint(event.location())) { 74 HitTestPoint(event.location())) {
75 // Store the y pos of the mouse coordinates so we can use them later to 75 // Store the y pos of the mouse coordinates so we can use them later to
76 // determine if the user dragged the mouse down (which should pop up the 76 // determine if the user dragged the mouse down (which should pop up the
77 // drag down menu immediately, instead of waiting for the timer) 77 // drag down menu immediately, instead of waiting for the timer)
78 y_position_on_lbuttondown_ = event.y(); 78 y_position_on_lbuttondown_ = event.y();
79 79
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 ui::AX_ATTR_ACTION, l10n_util::GetStringUTF8(IDS_APP_ACCACTION_PRESS)); 143 ui::AX_ATTR_ACTION, l10n_util::GetStringUTF8(IDS_APP_ACCACTION_PRESS));
144 node_data->AddStateFlag(ui::AX_STATE_HASPOPUP); 144 node_data->AddStateFlag(ui::AX_STATE_HASPOPUP);
145 } 145 }
146 146
147 std::unique_ptr<views::LabelButtonBorder> ToolbarButton::CreateDefaultBorder() 147 std::unique_ptr<views::LabelButtonBorder> ToolbarButton::CreateDefaultBorder()
148 const { 148 const {
149 std::unique_ptr<views::LabelButtonBorder> border = 149 std::unique_ptr<views::LabelButtonBorder> border =
150 views::LabelButton::CreateDefaultBorder(); 150 views::LabelButton::CreateDefaultBorder();
151 151
152 if (ThemeServiceFactory::GetForProfile(profile_)->UsingSystemTheme()) 152 if (ThemeServiceFactory::GetForProfile(profile_)->UsingSystemTheme())
153 border->set_insets(gfx::Insets(GetLayoutConstant(TOOLBAR_BUTTON_PADDING))); 153 border->set_insets(gfx::Insets(kInteriorPadding));
154 154
155 return border; 155 return border;
156 } 156 }
157 157
158 void ToolbarButton::ShowContextMenuForView(View* source, 158 void ToolbarButton::ShowContextMenuForView(View* source,
159 const gfx::Point& point, 159 const gfx::Point& point,
160 ui::MenuSourceType source_type) { 160 ui::MenuSourceType source_type) {
161 if (!enabled()) 161 if (!enabled())
162 return; 162 return;
163 163
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 if (state() != STATE_DISABLED) 238 if (state() != STATE_DISABLED)
239 SetState(STATE_NORMAL); 239 SetState(STATE_NORMAL);
240 240
241 menu_runner_.reset(); 241 menu_runner_.reset();
242 menu_model_adapter_.reset(); 242 menu_model_adapter_.reset();
243 } 243 }
244 244
245 const char* ToolbarButton::GetClassName() const { 245 const char* ToolbarButton::GetClassName() const {
246 return "ToolbarButton"; 246 return "ToolbarButton";
247 } 247 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698