OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/views/touchui/touch_selection_menu_runner_views.h" |
| 6 |
| 7 #include "ui/aura/window.h" |
| 8 #include "ui/gfx/geometry/rect.h" |
| 9 #include "ui/gfx/geometry/size.h" |
| 10 |
| 11 namespace views { |
| 12 |
| 13 TouchSelectionMenuRunnerViews::TouchSelectionMenuRunnerViews() |
| 14 : menu_(nullptr), |
| 15 client_(nullptr) { |
| 16 SetInstance(this); |
| 17 } |
| 18 |
| 19 TouchSelectionMenuRunnerViews::~TouchSelectionMenuRunnerViews() { |
| 20 SetInstance(nullptr); |
| 21 } |
| 22 |
| 23 void TouchSelectionMenuRunnerViews::RunMenu( |
| 24 ui::TouchSelectionMenuClient* client, |
| 25 const gfx::Rect& anchor_rect, |
| 26 const gfx::Size& handle_image_size, |
| 27 aura::Window* context) { |
| 28 CloseMenu(); |
| 29 |
| 30 DCHECK(!menu_); |
| 31 DCHECK(!client_); |
| 32 |
| 33 client_ = client; |
| 34 menu_ = TouchEditingMenuView::Create(this, anchor_rect, handle_image_size, |
| 35 context); |
| 36 |
| 37 if (!menu_) |
| 38 client_ = nullptr; |
| 39 } |
| 40 |
| 41 void TouchSelectionMenuRunnerViews::CloseMenu() { |
| 42 if (menu_) { |
| 43 menu_->Close(); |
| 44 menu_ = nullptr; |
| 45 client_ = nullptr; |
| 46 } |
| 47 } |
| 48 |
| 49 bool TouchSelectionMenuRunnerViews::IsRunning() const { |
| 50 return menu_ != nullptr; |
| 51 } |
| 52 |
| 53 bool TouchSelectionMenuRunnerViews::IsCommandIdEnabled(int command_id) const { |
| 54 return client_->IsCommandIdEnabled(command_id); |
| 55 } |
| 56 |
| 57 void TouchSelectionMenuRunnerViews::ExecuteCommand(int command_id, |
| 58 int event_flags) { |
| 59 return client_->ExecuteCommand(command_id, event_flags); |
| 60 } |
| 61 |
| 62 void TouchSelectionMenuRunnerViews::OpenContextMenu() { |
| 63 return client_->OpenContextMenu(); |
| 64 } |
| 65 |
| 66 void TouchSelectionMenuRunnerViews::OnMenuClosed(TouchEditingMenuView* menu) { |
| 67 DCHECK(menu == menu_); // or nullptr? |
| 68 menu_ = nullptr; |
| 69 client_ = nullptr; |
| 70 } |
| 71 |
| 72 } // namespace views |
OLD | NEW |