electron/atom/browser/api/atom_api_menu_gtk.cc

52 lines
1.3 KiB
C++
Raw Normal View History

2014-02-14 13:41:20 +00:00
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
2014-03-16 00:30:26 +00:00
#include "atom/browser/api/atom_api_menu_gtk.h"
2014-02-14 13:41:20 +00:00
2014-03-16 00:30:26 +00:00
#include "atom/browser/native_window_gtk.h"
2014-03-14 12:59:11 +00:00
#include "content/public/browser/render_widget_host_view.h"
#include "ui/gfx/point.h"
#include "ui/gfx/screen.h"
#include "atom/common/node_includes.h"
2014-02-14 13:41:20 +00:00
namespace atom {
namespace api {
2014-04-21 15:40:10 +00:00
MenuGtk::MenuGtk() {
2014-02-14 13:41:20 +00:00
}
void MenuGtk::Popup(Window* window) {
2014-03-14 12:59:11 +00:00
uint32_t triggering_event_time;
gfx::Point point;
2014-04-23 04:45:48 +00:00
NativeWindow* native_window = window->window();
2014-03-14 12:59:11 +00:00
GdkEventButton* event = native_window->GetWebContents()->
GetRenderWidgetHostView()->GetLastMouseDown();
if (event) {
triggering_event_time = event->time;
point = gfx::Point(event->x_root, event->y_root);
} else {
triggering_event_time = GDK_CURRENT_TIME;
point = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
}
menu_gtk_.reset(new ::MenuGtk(this, model_.get()));
menu_gtk_->PopupAsContext(point, triggering_event_time);
2014-02-14 13:41:20 +00:00
}
void Menu::AttachToWindow(Window* window) {
static_cast<NativeWindowGtk*>(window->window())->SetMenu(model_.get());
2014-02-14 13:41:20 +00:00
}
// static
2014-04-21 15:40:10 +00:00
mate::Wrappable* Menu::Create() {
return new MenuGtk();
2014-02-14 13:41:20 +00:00
}
} // namespace api
} // namespace atom