| 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" |
| 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" | |
| 17 #include "ui/accessibility/ax_node_data.h" | 15 #include "ui/accessibility/ax_node_data.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/models/menu_model.h" | 17 #include "ui/base/models/menu_model.h" |
| 20 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
| 21 #include "ui/display/screen.h" | 19 #include "ui/display/screen.h" |
| 22 #include "ui/strings/grit/ui_strings.h" | 20 #include "ui/strings/grit/ui_strings.h" |
| 23 #include "ui/views/controls/button/label_button_border.h" | 21 #include "ui/views/controls/button/label_button_border.h" |
| 24 #include "ui/views/controls/menu/menu_item_view.h" | 22 #include "ui/views/controls/menu/menu_item_view.h" |
| 25 #include "ui/views/controls/menu/menu_model_adapter.h" | 23 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 26 #include "ui/views/controls/menu/menu_runner.h" | 24 #include "ui/views/controls/menu/menu_runner.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 50 | 48 |
| 51 void ToolbarButton::ClearPendingMenu() { | 49 void ToolbarButton::ClearPendingMenu() { |
| 52 show_menu_factory_.InvalidateWeakPtrs(); | 50 show_menu_factory_.InvalidateWeakPtrs(); |
| 53 } | 51 } |
| 54 | 52 |
| 55 bool ToolbarButton::IsMenuShowing() const { | 53 bool ToolbarButton::IsMenuShowing() const { |
| 56 return menu_showing_; | 54 return menu_showing_; |
| 57 } | 55 } |
| 58 | 56 |
| 59 gfx::Size ToolbarButton::GetPreferredSize() const { | 57 gfx::Size ToolbarButton::GetPreferredSize() const { |
| 60 gfx::Size size(image()->GetPreferredSize()); | 58 DCHECK(label()->text().empty()); |
| 61 gfx::Size label_size = label()->GetPreferredSize(); | 59 gfx::Rect rect(gfx::Size(image()->GetPreferredSize())); |
| 62 if (label_size.width() > 0) { | 60 rect.Inset(gfx::Insets(-kInteriorPadding)); |
| 63 size.Enlarge( | 61 return rect.size(); |
| 64 label_size.width() + GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING), | |
| 65 0); | |
| 66 } | |
| 67 const int pad = GetLayoutConstant(TOOLBAR_BUTTON_PADDING); | |
| 68 size.Enlarge(2 * pad, 2 * pad); | |
| 69 return size; | |
| 70 } | 62 } |
| 71 | 63 |
| 72 bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) { | 64 bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) { |
| 73 if (IsTriggerableEvent(event) && enabled() && ShouldShowMenu() && | 65 if (IsTriggerableEvent(event) && enabled() && ShouldShowMenu() && |
| 74 HitTestPoint(event.location())) { | 66 HitTestPoint(event.location())) { |
| 75 // Store the y pos of the mouse coordinates so we can use them later to | 67 // 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 | 68 // determine if the user dragged the mouse down (which should pop up the |
| 77 // drag down menu immediately, instead of waiting for the timer) | 69 // drag down menu immediately, instead of waiting for the timer) |
| 78 y_position_on_lbuttondown_ = event.y(); | 70 y_position_on_lbuttondown_ = event.y(); |
| 79 | 71 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 ui::AX_ATTR_ACTION, l10n_util::GetStringUTF8(IDS_APP_ACCACTION_PRESS)); | 135 ui::AX_ATTR_ACTION, l10n_util::GetStringUTF8(IDS_APP_ACCACTION_PRESS)); |
| 144 node_data->AddStateFlag(ui::AX_STATE_HASPOPUP); | 136 node_data->AddStateFlag(ui::AX_STATE_HASPOPUP); |
| 145 } | 137 } |
| 146 | 138 |
| 147 std::unique_ptr<views::LabelButtonBorder> ToolbarButton::CreateDefaultBorder() | 139 std::unique_ptr<views::LabelButtonBorder> ToolbarButton::CreateDefaultBorder() |
| 148 const { | 140 const { |
| 149 std::unique_ptr<views::LabelButtonBorder> border = | 141 std::unique_ptr<views::LabelButtonBorder> border = |
| 150 views::LabelButton::CreateDefaultBorder(); | 142 views::LabelButton::CreateDefaultBorder(); |
| 151 | 143 |
| 152 if (ThemeServiceFactory::GetForProfile(profile_)->UsingSystemTheme()) | 144 if (ThemeServiceFactory::GetForProfile(profile_)->UsingSystemTheme()) |
| 153 border->set_insets(gfx::Insets(GetLayoutConstant(TOOLBAR_BUTTON_PADDING))); | 145 border->set_insets(gfx::Insets(kInteriorPadding)); |
| 154 | 146 |
| 155 return border; | 147 return border; |
| 156 } | 148 } |
| 157 | 149 |
| 158 void ToolbarButton::ShowContextMenuForView(View* source, | 150 void ToolbarButton::ShowContextMenuForView(View* source, |
| 159 const gfx::Point& point, | 151 const gfx::Point& point, |
| 160 ui::MenuSourceType source_type) { | 152 ui::MenuSourceType source_type) { |
| 161 if (!enabled()) | 153 if (!enabled()) |
| 162 return; | 154 return; |
| 163 | 155 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 if (state() != STATE_DISABLED) | 230 if (state() != STATE_DISABLED) |
| 239 SetState(STATE_NORMAL); | 231 SetState(STATE_NORMAL); |
| 240 | 232 |
| 241 menu_runner_.reset(); | 233 menu_runner_.reset(); |
| 242 menu_model_adapter_.reset(); | 234 menu_model_adapter_.reset(); |
| 243 } | 235 } |
| 244 | 236 |
| 245 const char* ToolbarButton::GetClassName() const { | 237 const char* ToolbarButton::GetClassName() const { |
| 246 return "ToolbarButton"; | 238 return "ToolbarButton"; |
| 247 } | 239 } |
| OLD | NEW |