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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 int left_bound = display.bounds().x(); | 214 int left_bound = display.bounds().x(); |
215 #endif | 215 #endif |
216 if (menu_position.x() < left_bound) | 216 if (menu_position.x() < left_bound) |
217 menu_position.set_x(left_bound); | 217 menu_position.set_x(left_bound); |
218 | 218 |
219 // Make the button look depressed while the menu is open. | 219 // Make the button look depressed while the menu is open. |
220 SetState(STATE_PRESSED); | 220 SetState(STATE_PRESSED); |
221 | 221 |
222 menu_showing_ = true; | 222 menu_showing_ = true; |
223 | 223 |
224 AnimateInkDrop(views::InkDropState::ACTIVATED); | 224 AnimateInkDrop(views::InkDropState::ACTIVATED, nullptr /* event */); |
225 | 225 |
226 // Exit if the model is null. | 226 // Exit if the model is null. |
227 if (!model_.get()) | 227 if (!model_.get()) |
228 return; | 228 return; |
229 | 229 |
230 // Create and run menu. | 230 // Create and run menu. |
231 menu_model_adapter_.reset(new views::MenuModelAdapter( | 231 menu_model_adapter_.reset(new views::MenuModelAdapter( |
232 model_.get(), | 232 model_.get(), |
233 base::Bind(&ToolbarButton::OnMenuClosed, base::Unretained(this)))); | 233 base::Bind(&ToolbarButton::OnMenuClosed, base::Unretained(this)))); |
234 menu_model_adapter_->set_triggerable_event_flags(triggerable_event_flags()); | 234 menu_model_adapter_->set_triggerable_event_flags(triggerable_event_flags()); |
235 menu_runner_.reset(new views::MenuRunner( | 235 menu_runner_.reset(new views::MenuRunner( |
236 menu_model_adapter_->CreateMenu(), | 236 menu_model_adapter_->CreateMenu(), |
237 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::ASYNC)); | 237 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::ASYNC)); |
238 ignore_result(menu_runner_->RunMenuAt( | 238 ignore_result(menu_runner_->RunMenuAt( |
239 GetWidget(), nullptr, gfx::Rect(menu_position, gfx::Size(0, 0)), | 239 GetWidget(), nullptr, gfx::Rect(menu_position, gfx::Size(0, 0)), |
240 views::MENU_ANCHOR_TOPLEFT, source_type)); | 240 views::MENU_ANCHOR_TOPLEFT, source_type)); |
241 } | 241 } |
242 | 242 |
243 void ToolbarButton::OnMenuClosed() { | 243 void ToolbarButton::OnMenuClosed() { |
244 AnimateInkDrop(views::InkDropState::DEACTIVATED); | 244 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); |
245 | 245 |
246 menu_showing_ = false; | 246 menu_showing_ = false; |
247 | 247 |
248 // Need to explicitly clear mouse handler so that events get sent | 248 // Need to explicitly clear mouse handler so that events get sent |
249 // properly after the menu finishes running. If we don't do this, then | 249 // properly after the menu finishes running. If we don't do this, then |
250 // the first click to other parts of the UI is eaten. | 250 // the first click to other parts of the UI is eaten. |
251 SetMouseHandler(nullptr); | 251 SetMouseHandler(nullptr); |
252 | 252 |
253 // Set the state back to normal after the drop down menu is closed. | 253 // Set the state back to normal after the drop down menu is closed. |
254 if (state() != STATE_DISABLED) | 254 if (state() != STATE_DISABLED) |
255 SetState(STATE_NORMAL); | 255 SetState(STATE_NORMAL); |
256 | 256 |
257 menu_runner_.reset(); | 257 menu_runner_.reset(); |
258 menu_model_adapter_.reset(); | 258 menu_model_adapter_.reset(); |
259 } | 259 } |
260 | 260 |
261 const char* ToolbarButton::GetClassName() const { | 261 const char* ToolbarButton::GetClassName() const { |
262 return "ToolbarButton"; | 262 return "ToolbarButton"; |
263 } | 263 } |
OLD | NEW |