Chromium Code Reviews| 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/controls/menu/menu_runner_impl_cocoa.h" | |
|
tapted
2014/06/25 08:30:28
nit: import
Andre
2014/06/27 01:18:08
Done.
| |
| 6 | |
| 7 #include "ui/base/cocoa/menu_controller.h" | |
|
tapted
2014/06/25 08:30:28
nit: import
Andre
2014/06/27 01:18:08
Done.
| |
| 8 #include "ui/events/event_utils.h" | |
| 9 #include "ui/gfx/geometry/rect.h" | |
| 10 | |
| 11 namespace views { | |
| 12 | |
| 13 internal::MenuRunnerImplInterface* MenuRunner::CreateNativeImpl() { | |
| 14 DCHECK(menu_model_); | |
| 15 return new internal::MenuRunnerImplCocoa(menu_model_); | |
| 16 } | |
| 17 | |
| 18 namespace internal { | |
| 19 | |
| 20 MenuRunnerImplCocoa::MenuRunnerImplCocoa(ui::MenuModel* menu) | |
| 21 : closing_event_time_(base::TimeDelta()) { | |
| 22 menu_controller_.reset( | |
| 23 [[MenuController alloc] initWithModel:menu useWithPopUpButtonCell:NO]); | |
| 24 } | |
| 25 | |
| 26 bool MenuRunnerImplCocoa::running() const { | |
| 27 return [menu_controller_ isMenuOpen]; | |
| 28 } | |
| 29 | |
| 30 void MenuRunnerImplCocoa::Release() { | |
| 31 } | |
| 32 | |
| 33 MenuRunner::RunResult MenuRunnerImplCocoa::RunMenuAt(Widget* parent, | |
| 34 MenuButton* button, | |
| 35 const gfx::Rect& bounds, | |
| 36 MenuAnchorPosition anchor, | |
| 37 int32 types) { | |
| 38 DCHECK(types & MenuRunner::CONTEXT_MENU); | |
| 39 DCHECK(!running()); | |
| 40 closing_event_time_ = base::TimeDelta(); | |
| 41 [NSMenu popUpContextMenu:[menu_controller_ menu] | |
| 42 withEvent:[NSApp currentEvent] | |
| 43 forView:nil]; | |
| 44 closing_event_time_ = ui::EventTimeForNow(); | |
| 45 return MenuRunner::NORMAL_EXIT; | |
| 46 } | |
| 47 | |
| 48 void MenuRunnerImplCocoa::Cancel() { | |
| 49 [menu_controller_ cancel]; | |
| 50 } | |
| 51 | |
| 52 base::TimeDelta MenuRunnerImplCocoa::closing_event_time() const { | |
| 53 return closing_event_time_; | |
| 54 } | |
| 55 | |
| 56 MenuRunnerImplCocoa::~MenuRunnerImplCocoa() { | |
| 57 } | |
| 58 | |
| 59 } // namespace internal | |
| 60 } // namespace views | |
| OLD | NEW |