| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #import "ui/views/controls/menu/menu_runner_impl_cocoa.h" | 5 #import "ui/views/controls/menu/menu_runner_impl_cocoa.h" |
| 6 | 6 |
| 7 #include "base/mac/sdk_forward_declarations.h" | 7 #include "base/mac/sdk_forward_declarations.h" |
| 8 #import "ui/base/cocoa/menu_controller.h" | 8 #import "ui/base/cocoa/menu_controller.h" |
| 9 #include "ui/base/models/menu_model.h" | 9 #include "ui/base/models/menu_model.h" |
| 10 #include "ui/events/base_event_utils.h" | 10 #include "ui/events/base_event_utils.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 [anchor_view setHidden:YES]; | 77 [anchor_view setHidden:YES]; |
| 78 [[window contentView] addSubview:anchor_view]; | 78 [[window contentView] addSubview:anchor_view]; |
| 79 return anchor_view; | 79 return anchor_view; |
| 80 } | 80 } |
| 81 | 81 |
| 82 } // namespace | 82 } // namespace |
| 83 | 83 |
| 84 // static | 84 // static |
| 85 MenuRunnerImplInterface* MenuRunnerImplInterface::Create( | 85 MenuRunnerImplInterface* MenuRunnerImplInterface::Create( |
| 86 ui::MenuModel* menu_model, | 86 ui::MenuModel* menu_model, |
| 87 int32_t run_types) { | 87 int32_t run_types, |
| 88 const base::Closure& on_menu_closed_callback) { |
| 88 if ((run_types & kNativeRunTypes) != 0 && | 89 if ((run_types & kNativeRunTypes) != 0 && |
| 89 (run_types & MenuRunner::IS_NESTED) == 0) { | 90 (run_types & MenuRunner::IS_NESTED) == 0) { |
| 90 return new MenuRunnerImplCocoa(menu_model); | 91 return new MenuRunnerImplCocoa(menu_model, on_menu_closed_callback); |
| 91 } | 92 } |
| 92 | 93 |
| 93 return new MenuRunnerImplAdapter(menu_model); | 94 return new MenuRunnerImplAdapter(menu_model, on_menu_closed_callback); |
| 94 } | 95 } |
| 95 | 96 |
| 96 MenuRunnerImplCocoa::MenuRunnerImplCocoa(ui::MenuModel* menu) | 97 MenuRunnerImplCocoa::MenuRunnerImplCocoa( |
| 98 ui::MenuModel* menu, |
| 99 const base::Closure& on_menu_closed_callback) |
| 97 : running_(false), | 100 : running_(false), |
| 98 delete_after_run_(false), | 101 delete_after_run_(false), |
| 99 closing_event_time_(base::TimeTicks()) { | 102 closing_event_time_(base::TimeTicks()), |
| 103 on_menu_closed_callback_(on_menu_closed_callback) { |
| 100 menu_controller_.reset( | 104 menu_controller_.reset( |
| 101 [[MenuController alloc] initWithModel:menu useWithPopUpButtonCell:NO]); | 105 [[MenuController alloc] initWithModel:menu useWithPopUpButtonCell:NO]); |
| 102 } | 106 } |
| 103 | 107 |
| 104 bool MenuRunnerImplCocoa::IsRunning() const { | 108 bool MenuRunnerImplCocoa::IsRunning() const { |
| 105 return running_; | 109 return running_; |
| 106 } | 110 } |
| 107 | 111 |
| 108 void MenuRunnerImplCocoa::Release() { | 112 void MenuRunnerImplCocoa::Release() { |
| 109 if (IsRunning()) { | 113 if (IsRunning()) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 151 } |
| 148 | 152 |
| 149 closing_event_time_ = ui::EventTimeForNow(); | 153 closing_event_time_ = ui::EventTimeForNow(); |
| 150 running_ = false; | 154 running_ = false; |
| 151 | 155 |
| 152 if (delete_after_run_) { | 156 if (delete_after_run_) { |
| 153 delete this; | 157 delete this; |
| 154 return MenuRunner::MENU_DELETED; | 158 return MenuRunner::MENU_DELETED; |
| 155 } | 159 } |
| 156 | 160 |
| 161 // Don't invoke the callback if Release() was called, since that usually means |
| 162 // the owning instance is being destroyed. |
| 163 if (!on_menu_closed_callback_.is_null()) |
| 164 on_menu_closed_callback_.Run(); |
| 165 |
| 157 return MenuRunner::NORMAL_EXIT; | 166 return MenuRunner::NORMAL_EXIT; |
| 158 } | 167 } |
| 159 | 168 |
| 160 void MenuRunnerImplCocoa::Cancel() { | 169 void MenuRunnerImplCocoa::Cancel() { |
| 161 [menu_controller_ cancel]; | 170 [menu_controller_ cancel]; |
| 162 } | 171 } |
| 163 | 172 |
| 164 base::TimeTicks MenuRunnerImplCocoa::GetClosingEventTime() const { | 173 base::TimeTicks MenuRunnerImplCocoa::GetClosingEventTime() const { |
| 165 return closing_event_time_; | 174 return closing_event_time_; |
| 166 } | 175 } |
| 167 | 176 |
| 168 MenuRunnerImplCocoa::~MenuRunnerImplCocoa() { | 177 MenuRunnerImplCocoa::~MenuRunnerImplCocoa() { |
| 169 } | 178 } |
| 170 | 179 |
| 171 } // namespace internal | 180 } // namespace internal |
| 172 } // namespace views | 181 } // namespace views |
| OLD | NEW |