.SetMethod("isEnabledAt", &Menu::IsEnabledAt)
.SetMethod("isVisibleAt", &Menu::IsVisibleAt)
.SetMethod("attachToWindow", &Menu::AttachToWindow)
- .SetMethod("_popup", &Menu::Popup);
+ .SetMethod("_popup", &Menu::Popup)
+ .SetMethod("_popupAt", &Menu::PopupAt);
}
} // namespace api
virtual void AttachToWindow(Window* window);
virtual void Popup(Window* window) = 0;
+ virtual void PopupAt(Window* window, int x, int y) = 0;
scoped_ptr<ui::SimpleMenuModel> model_;
Menu* parent_;
MenuMac();
virtual void Popup(Window* window) OVERRIDE;
+ virtual void PopupAt(Window* window, int x, int y) OVERRIDE;
base::scoped_nsobject<AtomMenuController> menu_controller_;
forView:web_contents->GetContentNativeView()];
}
+void MenuMac::PopupAt(Window* window, int x, int y) {
+ base::scoped_nsobject<AtomMenuController> menu_controller(
+ [[AtomMenuController alloc] initWithModel:model_.get()]);
+
+ NativeWindow* native_window = window->window();
+ content::WebContents* web_contents = native_window->GetWebContents();
+ NSView* view = web_contents->GetContentNativeView();
+ NSMenu* menu = [menu_controller menu];
+
+ // Show the menu.
+ [menu popUpMenuPositioningItem:[menu itemAtIndex:0]
+ atLocation:NSMakePoint(x, [view frame].size.height - y)
+ inView:view];
+}
+
// static
void Menu::SetApplicationMenu(Menu* base_menu) {
MenuMac* menu = static_cast<MenuMac*>(base_menu);
#include "atom/browser/api/atom_api_menu_views.h"
#include "atom/browser/native_window_views.h"
+#include "content/public/browser/render_widget_host_view.h"
#include "ui/gfx/screen.h"
#include "ui/views/controls/menu/menu_runner.h"
}
void MenuViews::Popup(Window* window) {
- gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
+ PopupAtPoint(window, gfx::Screen::GetNativeScreen()->GetCursorScreenPoint());
+}
+
+void MenuViews::PopupAt(Window* window, int x, int y) {
+ NativeWindow* nativeWindowViews = static_cast<NativeWindow*>(window->window());
+ content::RenderWidgetHostView* view = nativeWindowViews->GetWebContents()->GetRenderWidgetHostView();
+ gfx::Point viewOrigin = view->GetViewBounds().origin();
+ PopupAtPoint(window, gfx::Point(viewOrigin.x() + x, viewOrigin.y() + y));
+}
+
+void MenuViews::PopupAtPoint(Window* window, gfx::Point point) {
views::MenuRunner menu_runner(
model(),
views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS);
ignore_result(menu_runner.RunMenuAt(
static_cast<NativeWindowViews*>(window->window())->widget(),
NULL,
- gfx::Rect(cursor, gfx::Size()),
+ gfx::Rect(point, gfx::Size()),
views::MENU_ANCHOR_TOPLEFT,
ui::MENU_SOURCE_MOUSE));
}
#define ATOM_BROWSER_API_ATOM_API_MENU_VIEWS_H_
#include "atom/browser/api/atom_api_menu.h"
+#include "ui/gfx/screen.h"
namespace atom {
protected:
virtual void Popup(Window* window) OVERRIDE;
+ virtual void PopupAt(Window* window, int x, int y) OVERRIDE;
private:
+ void PopupAtPoint(Window* window, gfx::Point point);
DISALLOW_COPY_AND_ASSIGN(MenuViews);
};
break
v8Util.setHiddenValue group[0], 'checked', true unless checked
-Menu::popup = (window) ->
+Menu::popup = (window, x, y) ->
throw new TypeError('Invalid window') unless window?.constructor is BrowserWindow
- @_popup window
+ if x? and y?
+ @_popupAt(window, x, y)
+ else
+ @_popup window
Menu::append = (item) ->
@insert @getItemCount(), item