Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Unified Diff: ui/views_core/menu_runner_mac.mm

Issue 187483005: Extending the Views-on-Mac experiment: whole app list grid. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: still compiles r263560 + crrev/195793005 Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views_core/bridged_view_mac.mm ('k') | ui/views_core/views_core.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views_core/menu_runner_mac.mm
diff --git a/ui/views_core/menu_runner_mac.mm b/ui/views_core/menu_runner_mac.mm
new file mode 100644
index 0000000000000000000000000000000000000000..6a9cdb023579b7424435dac7b11a82ee25396c56
--- /dev/null
+++ b/ui/views_core/menu_runner_mac.mm
@@ -0,0 +1,142 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/views/controls/menu/menu_runner.h"
+
+#include <Cocoa/Cocoa.h>
+
+#include "base/mac/scoped_nsobject.h"
+#include "base/time/time.h"
+#include "ui/base/cocoa/menu_controller.h"
+#include "ui/base/models/menu_model.h"
+#include "ui/events/event_utils.h"
+#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/mac/point_utils.h"
+
+namespace views {
+
+class MenuModelAdapter {};
+class MenuRunnerHandler {};
+
+namespace internal {
+
+// Manages the menu. To destroy a MenuRunnerImpl invoke Release(). Release()
+// deletes immediately if the menu isn't showing. If the menu is showing
+// Release() cancels the menu and when the nested RunMenuAt() call returns
+// deletes itself and the menu.
+class MenuRunnerImpl {
+ public:
+ explicit MenuRunnerImpl(ui::MenuModel* menu_model);
+
+ NSMenu* menu() { return [menu_controller_ menu]; }
+
+ bool running() const { return [menu_controller_ isMenuOpen]; }
+
+ void Release() { menu_controller_.reset(); }
+
+ // Runs the menu.
+ MenuRunner::RunResult RunMenuAt(Widget* parent,
+ MenuButton* button,
+ const gfx::Rect& bounds,
+ ui::MenuAnchorPosition anchor,
+ int32 types) WARN_UNUSED_RESULT;
+
+ void Cancel() { [menu_controller_ cancel]; }
+
+ // Returns the time from the event which closed the menu - or 0.
+ base::TimeDelta closing_event_time() const {
+ return closing_event_time_;
+ }
+
+ private:
+ // The Cocoa menu controller that this instance is bridging.
+ base::scoped_nsobject<MenuController> menu_controller_;
+
+ // The timestamp of the event which closed the menu - or 0.
+ base::TimeDelta closing_event_time_;
+
+ DISALLOW_COPY_AND_ASSIGN(MenuRunnerImpl);
+};
+
+MenuRunnerImpl::MenuRunnerImpl(ui::MenuModel* menu)
+ : closing_event_time_(base::TimeDelta()) {
+ menu_controller_.reset([[MenuController alloc] initWithModel:menu
+ useWithPopUpButtonCell:NO]);
+}
+
+MenuRunner::RunResult MenuRunnerImpl::RunMenuAt(
+ Widget* parent,
+ MenuButton* button,
+ const gfx::Rect& bounds,
+ ui::MenuAnchorPosition anchor,
+ int32 types) {
+ closing_event_time_ = base::TimeDelta();
+ // TODO(tapted): Ensure this is OK with being invoked while already running().
+
+ if ((types & MenuRunner::FOR_DROP) != 0) {
+ NOTIMPLEMENTED();
+ return MenuRunner::NORMAL_EXIT;
+ }
+
+ [menu() popUpMenuPositioningItem:nil
+ atLocation:ScreenPointToNSPoint(bounds.origin())
+ inView:nil];
+
+ // Get the time of the event which closed this menu.
+ closing_event_time_ = ui::EventTimeForNow();
+ return MenuRunner::NORMAL_EXIT;
+}
+
+} // namespace internal
+
+MenuRunner::MenuRunner(ui::MenuModel* menu_model)
+ : holder_(new internal::MenuRunnerImpl(menu_model)) {
+}
+
+MenuRunner::MenuRunner(MenuItemView* menu) {
+ NOTIMPLEMENTED();
+}
+
+MenuRunner::~MenuRunner() {
+ holder_->Release();
+}
+
+MenuItemView* MenuRunner::GetMenu() {
+ NOTIMPLEMENTED();
+ return NULL;
+}
+
+template<>
+MenuRunner::RunResult MenuRunner::RunMenuAt(Widget* parent,
+ MenuButton* button,
+ const gfx::Rect& bounds,
+ ui::MenuAnchorPosition anchor,
+ ui::MenuSourceType source_type,
+ int32 types) {
+ // TODO(tapted): See if we need a DisplayChangeListener.
+
+ // TODO(tapted): Adjust the anchor for context menu / touch, if Cocoa can't be
+ // trusted to do it.
+
+ return holder_->RunMenuAt(parent, button, bounds, anchor, types);
+}
+
+bool MenuRunner::IsRunning() const {
+ return holder_->running();
+}
+
+void MenuRunner::Cancel() {
+ holder_->Cancel();
+}
+
+base::TimeDelta MenuRunner::closing_event_time() const {
+ return holder_->closing_event_time();
+}
+
+void MenuRunner::SetRunnerHandler(
+ scoped_ptr<MenuRunnerHandler> runner_handler) {
+ NOTIMPLEMENTED();
+}
+
+} // namespace views
« no previous file with comments | « ui/views_core/bridged_view_mac.mm ('k') | ui/views_core/views_core.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698