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" | 19 #include "ui/base/material_design/material_design_controller.h" |
20 #include "ui/base/models/menu_model.h" | 20 #include "ui/base/models/menu_model.h" |
21 #include "ui/base/theme_provider.h" | 21 #include "ui/base/theme_provider.h" |
22 #include "ui/display/display.h" | 22 #include "ui/display/display.h" |
23 #include "ui/display/screen.h" | 23 #include "ui/display/screen.h" |
24 #include "ui/strings/grit/ui_strings.h" | 24 #include "ui/strings/grit/ui_strings.h" |
25 #include "ui/views/animation/button_ink_drop_delegate.h" | |
26 #include "ui/views/controls/button/label_button_border.h" | 25 #include "ui/views/controls/button/label_button_border.h" |
27 #include "ui/views/controls/menu/menu_item_view.h" | 26 #include "ui/views/controls/menu/menu_item_view.h" |
28 #include "ui/views/controls/menu/menu_model_adapter.h" | 27 #include "ui/views/controls/menu/menu_model_adapter.h" |
29 #include "ui/views/controls/menu/menu_runner.h" | 28 #include "ui/views/controls/menu/menu_runner.h" |
30 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
31 | 30 |
32 ToolbarButton::ToolbarButton(Profile* profile, | 31 ToolbarButton::ToolbarButton(Profile* profile, |
33 views::ButtonListener* listener, | 32 views::ButtonListener* listener, |
34 ui::MenuModel* model) | 33 ui::MenuModel* model) |
35 : views::LabelButton(listener, base::string16()), | 34 : views::LabelButton(listener, base::string16()), |
36 profile_(profile), | 35 profile_(profile), |
37 model_(model), | 36 model_(model), |
38 menu_showing_(false), | 37 menu_showing_(false), |
39 y_position_on_lbuttondown_(0), | 38 y_position_on_lbuttondown_(0), |
40 show_menu_factory_(this) { | 39 show_menu_factory_(this) { |
41 set_ink_drop_delegate( | 40 SetHasInkDrop(true); |
42 base::WrapUnique(new views::ButtonInkDropDelegate(this, this))); | |
43 set_has_ink_drop_action_on_click(true); | 41 set_has_ink_drop_action_on_click(true); |
44 set_context_menu_controller(this); | 42 set_context_menu_controller(this); |
45 if (ui::MaterialDesignController::IsModeMaterial()) | 43 if (ui::MaterialDesignController::IsModeMaterial()) |
46 SetFocusPainter(nullptr); | 44 SetFocusPainter(nullptr); |
47 } | 45 } |
48 | 46 |
49 ToolbarButton::~ToolbarButton() {} | 47 ToolbarButton::~ToolbarButton() {} |
50 | 48 |
51 void ToolbarButton::Init() { | 49 void ToolbarButton::Init() { |
52 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 50 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 int left_bound = display.bounds().x(); | 213 int left_bound = display.bounds().x(); |
216 #endif | 214 #endif |
217 if (menu_position.x() < left_bound) | 215 if (menu_position.x() < left_bound) |
218 menu_position.set_x(left_bound); | 216 menu_position.set_x(left_bound); |
219 | 217 |
220 // Make the button look depressed while the menu is open. | 218 // Make the button look depressed while the menu is open. |
221 SetState(STATE_PRESSED); | 219 SetState(STATE_PRESSED); |
222 | 220 |
223 menu_showing_ = true; | 221 menu_showing_ = true; |
224 | 222 |
225 ink_drop_delegate()->OnAction(views::InkDropState::ACTIVATED); | 223 AnimateInkDrop(views::InkDropState::ACTIVATED); |
226 | 224 |
227 // Exit if the model is null. | 225 // Exit if the model is null. |
228 if (!model_.get()) | 226 if (!model_.get()) |
229 return; | 227 return; |
230 | 228 |
231 // Create and run menu. | 229 // Create and run menu. |
232 menu_model_adapter_.reset(new views::MenuModelAdapter( | 230 menu_model_adapter_.reset(new views::MenuModelAdapter( |
233 model_.get(), | 231 model_.get(), |
234 base::Bind(&ToolbarButton::OnMenuClosed, base::Unretained(this)))); | 232 base::Bind(&ToolbarButton::OnMenuClosed, base::Unretained(this)))); |
235 menu_model_adapter_->set_triggerable_event_flags(triggerable_event_flags()); | 233 menu_model_adapter_->set_triggerable_event_flags(triggerable_event_flags()); |
236 menu_runner_.reset(new views::MenuRunner( | 234 menu_runner_.reset(new views::MenuRunner( |
237 menu_model_adapter_->CreateMenu(), | 235 menu_model_adapter_->CreateMenu(), |
238 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::ASYNC)); | 236 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::ASYNC)); |
239 ignore_result(menu_runner_->RunMenuAt( | 237 ignore_result(menu_runner_->RunMenuAt( |
240 GetWidget(), nullptr, gfx::Rect(menu_position, gfx::Size(0, 0)), | 238 GetWidget(), nullptr, gfx::Rect(menu_position, gfx::Size(0, 0)), |
241 views::MENU_ANCHOR_TOPLEFT, source_type)); | 239 views::MENU_ANCHOR_TOPLEFT, source_type)); |
242 } | 240 } |
243 | 241 |
244 void ToolbarButton::OnMenuClosed() { | 242 void ToolbarButton::OnMenuClosed() { |
245 ink_drop_delegate()->OnAction(views::InkDropState::DEACTIVATED); | 243 AnimateInkDrop(views::InkDropState::DEACTIVATED); |
246 | 244 |
247 menu_showing_ = false; | 245 menu_showing_ = false; |
248 | 246 |
249 // Need to explicitly clear mouse handler so that events get sent | 247 // Need to explicitly clear mouse handler so that events get sent |
250 // properly after the menu finishes running. If we don't do this, then | 248 // properly after the menu finishes running. If we don't do this, then |
251 // the first click to other parts of the UI is eaten. | 249 // the first click to other parts of the UI is eaten. |
252 SetMouseHandler(nullptr); | 250 SetMouseHandler(nullptr); |
253 | 251 |
254 // Set the state back to normal after the drop down menu is closed. | 252 // Set the state back to normal after the drop down menu is closed. |
255 if (state() != STATE_DISABLED) | 253 if (state() != STATE_DISABLED) |
256 SetState(STATE_NORMAL); | 254 SetState(STATE_NORMAL); |
257 | 255 |
258 menu_runner_.reset(); | 256 menu_runner_.reset(); |
259 menu_model_adapter_.reset(); | 257 menu_model_adapter_.reset(); |
260 } | 258 } |
261 | 259 |
262 const char* ToolbarButton::GetClassName() const { | 260 const char* ToolbarButton::GetClassName() const { |
263 return "ToolbarButton"; | 261 return "ToolbarButton"; |
264 } | 262 } |
OLD | NEW |