| 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" | 15 #include "chrome/browser/ui/layout_constants.h" |
| 16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 17 #include "ui/accessibility/ax_view_state.h" | 17 #include "ui/accessibility/ax_view_state.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/material_design/material_design_controller.h" | |
| 20 #include "ui/base/models/menu_model.h" | 19 #include "ui/base/models/menu_model.h" |
| 21 #include "ui/base/theme_provider.h" | |
| 22 #include "ui/display/display.h" | 20 #include "ui/display/display.h" |
| 23 #include "ui/display/screen.h" | 21 #include "ui/display/screen.h" |
| 24 #include "ui/strings/grit/ui_strings.h" | 22 #include "ui/strings/grit/ui_strings.h" |
| 25 #include "ui/views/controls/button/label_button_border.h" | 23 #include "ui/views/controls/button/label_button_border.h" |
| 26 #include "ui/views/controls/menu/menu_item_view.h" | 24 #include "ui/views/controls/menu/menu_item_view.h" |
| 27 #include "ui/views/controls/menu/menu_model_adapter.h" | 25 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 28 #include "ui/views/controls/menu/menu_runner.h" | 26 #include "ui/views/controls/menu/menu_runner.h" |
| 29 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
| 30 | 28 |
| 31 ToolbarButton::ToolbarButton(Profile* profile, | 29 ToolbarButton::ToolbarButton(Profile* profile, |
| 32 views::ButtonListener* listener, | 30 views::ButtonListener* listener, |
| 33 ui::MenuModel* model) | 31 ui::MenuModel* model) |
| 34 : views::LabelButton(listener, base::string16()), | 32 : views::LabelButton(listener, base::string16()), |
| 35 profile_(profile), | 33 profile_(profile), |
| 36 model_(model), | 34 model_(model), |
| 37 menu_showing_(false), | 35 menu_showing_(false), |
| 38 y_position_on_lbuttondown_(0), | 36 y_position_on_lbuttondown_(0), |
| 39 show_menu_factory_(this) { | 37 show_menu_factory_(this) { |
| 40 set_has_ink_drop_action_on_click(true); | 38 set_has_ink_drop_action_on_click(true); |
| 41 set_context_menu_controller(this); | 39 set_context_menu_controller(this); |
| 42 if (ui::MaterialDesignController::IsModeMaterial()) { | 40 SetInkDropMode(InkDropMode::ON); |
| 43 SetInkDropMode(InkDropMode::ON); | 41 SetFocusPainter(nullptr); |
| 44 SetFocusPainter(nullptr); | |
| 45 } | |
| 46 } | 42 } |
| 47 | 43 |
| 48 ToolbarButton::~ToolbarButton() {} | 44 ToolbarButton::~ToolbarButton() {} |
| 49 | 45 |
| 50 void ToolbarButton::Init() { | 46 void ToolbarButton::Init() { |
| 51 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 47 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 52 image()->EnableCanvasFlippingForRTLUI(true); | 48 image()->EnableCanvasFlippingForRTLUI(true); |
| 53 } | 49 } |
| 54 | 50 |
| 55 void ToolbarButton::ClearPendingMenu() { | 51 void ToolbarButton::ClearPendingMenu() { |
| 56 show_menu_factory_.InvalidateWeakPtrs(); | 52 show_menu_factory_.InvalidateWeakPtrs(); |
| 57 } | 53 } |
| 58 | 54 |
| 59 bool ToolbarButton::IsMenuShowing() const { | 55 bool ToolbarButton::IsMenuShowing() const { |
| 60 return menu_showing_; | 56 return menu_showing_; |
| 61 } | 57 } |
| 62 | 58 |
| 63 gfx::Size ToolbarButton::GetPreferredSize() const { | 59 gfx::Size ToolbarButton::GetPreferredSize() const { |
| 64 gfx::Size size(image()->GetPreferredSize()); | 60 gfx::Size size(image()->GetPreferredSize()); |
| 65 gfx::Size label_size = label()->GetPreferredSize(); | 61 gfx::Size label_size = label()->GetPreferredSize(); |
| 66 if (label_size.width() > 0) { | 62 if (label_size.width() > 0) { |
| 67 size.Enlarge( | 63 size.Enlarge( |
| 68 label_size.width() + GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING), | 64 label_size.width() + GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING), |
| 69 0); | 65 0); |
| 70 } | 66 } |
| 71 // For non-material assets the entire size of the button is captured in the | 67 gfx::Insets insets(GetLayoutInsets(TOOLBAR_BUTTON)); |
| 72 // image resource. For Material Design the excess whitespace is being removed | 68 size.Enlarge(insets.width(), insets.height()); |
| 73 // from the image assets. Enlarge the button by the theme provided insets. | |
| 74 if (ui::MaterialDesignController::IsModeMaterial()) { | |
| 75 const ui::ThemeProvider* provider = GetThemeProvider(); | |
| 76 if (provider) { | |
| 77 gfx::Insets insets(GetLayoutInsets(TOOLBAR_BUTTON)); | |
| 78 size.Enlarge(insets.width(), insets.height()); | |
| 79 } | |
| 80 } | |
| 81 return size; | 69 return size; |
| 82 } | 70 } |
| 83 | 71 |
| 84 bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) { | 72 bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) { |
| 85 if (IsTriggerableEvent(event) && enabled() && ShouldShowMenu() && | 73 if (IsTriggerableEvent(event) && enabled() && ShouldShowMenu() && |
| 86 HitTestPoint(event.location())) { | 74 HitTestPoint(event.location())) { |
| 87 // 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 |
| 88 // 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 |
| 89 // drag down menu immediately, instead of waiting for the timer) | 77 // drag down menu immediately, instead of waiting for the timer) |
| 90 y_position_on_lbuttondown_ = event.y(); | 78 y_position_on_lbuttondown_ = event.y(); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 if (state() != STATE_DISABLED) | 242 if (state() != STATE_DISABLED) |
| 255 SetState(STATE_NORMAL); | 243 SetState(STATE_NORMAL); |
| 256 | 244 |
| 257 menu_runner_.reset(); | 245 menu_runner_.reset(); |
| 258 menu_model_adapter_.reset(); | 246 menu_model_adapter_.reset(); |
| 259 } | 247 } |
| 260 | 248 |
| 261 const char* ToolbarButton::GetClassName() const { | 249 const char* ToolbarButton::GetClassName() const { |
| 262 return "ToolbarButton"; | 250 return "ToolbarButton"; |
| 263 } | 251 } |
| OLD | NEW |