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_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" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } | 57 } |
58 | 58 |
59 gfx::Size ToolbarButton::GetPreferredSize() const { | 59 gfx::Size ToolbarButton::GetPreferredSize() const { |
60 gfx::Size size(image()->GetPreferredSize()); | 60 gfx::Size size(image()->GetPreferredSize()); |
61 gfx::Size label_size = label()->GetPreferredSize(); | 61 gfx::Size label_size = label()->GetPreferredSize(); |
62 if (label_size.width() > 0) { | 62 if (label_size.width() > 0) { |
63 size.Enlarge( | 63 size.Enlarge( |
64 label_size.width() + GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING), | 64 label_size.width() + GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING), |
65 0); | 65 0); |
66 } | 66 } |
67 gfx::Insets insets(GetLayoutInsets(TOOLBAR_BUTTON)); | 67 const int pad = GetLayoutConstant(TOOLBAR_BUTTON_PADDING); |
68 size.Enlarge(insets.width(), insets.height()); | 68 size.Enlarge(2 * pad, 2 * pad); |
69 return size; | 69 return 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(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(GetLayoutInsets(TOOLBAR_BUTTON)); | 153 border->set_insets(gfx::Insets(GetLayoutConstant(TOOLBAR_BUTTON_PADDING))); |
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 Loading... |
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 } |
OLD | NEW |