#include "browser/api/atom_api_menu_gtk.h"
-#include "browser/native_window.h"
+#include "browser/native_window_gtk.h"
+#include "common/v8/native_type_conversions.h"
#include "content/public/browser/render_widget_host_view.h"
#include "ui/gfx/point.h"
#include "ui/gfx/screen.h"
+#include "common/v8/node_common.h"
+
namespace atom {
namespace api {
// static
void Menu::AttachToWindow(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ Menu* self = ObjectWrap::Unwrap<Menu>(args.This());
+ if (self == NULL)
+ return node::ThrowError("Menu is already destroyed");
+
+ NativeWindow* native_window;
+ if (!FromV8Arguments(args, &native_window))
+ return node::ThrowTypeError("Bad argument");
+
+ static_cast<NativeWindowGtk*>(native_window)->SetMenu(self->model_.get());
}
// static
base::DictionaryValue* options)
: NativeWindow(web_contents, options),
window_(GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL))),
+ vbox_(gtk_vbox_new(FALSE, 0)),
state_(GDK_WINDOW_STATE_WITHDRAWN),
is_always_on_top_(false) {
- gtk_container_add(GTK_CONTAINER(window_),
+ gtk_container_add(GTK_CONTAINER(window_), vbox_);
+ gtk_container_add(GTK_CONTAINER(vbox_),
GetWebContents()->GetView()->GetNativeView());
int width = 800, height = 600;
return window_;
}
+void NativeWindowGtk::SetMenu(ui::MenuModel* menu_model) {
+ menu_.reset(new ::MenuGtk(this, menu_model, true));
+ gtk_box_pack_start(GTK_BOX(vbox_), menu_->widget(), FALSE, FALSE, 0);
+ gtk_box_reorder_child(GTK_BOX(vbox_), menu_->widget(), 0);
+}
+
void NativeWindowGtk::UpdateDraggableRegions(
const std::vector<DraggableRegion>& regions) {
// Draggable region is not supported for non-frameless window.
#include <gtk/gtk.h>
#include "browser/native_window.h"
+#include "browser/ui/gtk/menu_gtk.h"
#include "third_party/skia/include/core/SkRegion.h"
#include "ui/base/gtk/gtk_signal.h"
#include "ui/gfx/size.h"
namespace atom {
-class NativeWindowGtk : public NativeWindow {
+class NativeWindowGtk : public NativeWindow,
+ public MenuGtk::Delegate {
public:
explicit NativeWindowGtk(content::WebContents* web_contents,
base::DictionaryValue* options);
virtual bool HasModalDialog() OVERRIDE;
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
+ // Set the native window menu.
+ void SetMenu(ui::MenuModel* menu_model);
+
protected:
virtual void UpdateDraggableRegions(
const std::vector<DraggableRegion>& regions) OVERRIDE;
GdkEventButton*);
GtkWindow* window_;
+ GtkWidget* vbox_;
GdkWindowState state_;
bool is_always_on_top_;
// custom frame border. We set it to NULL if we want the default cursor.
GdkCursor* frame_cursor_;
+ // The window menu.
+ scoped_ptr<MenuGtk> menu_;
+
DISALLOW_COPY_AND_ASSIGN(NativeWindowGtk);
};
bool is_menubar)
: delegate_(delegate),
model_(model),
+ is_menubar_(is_menubar),
dummy_accel_group_(gtk_accel_group_new()),
menu_(is_menubar ? gtk_menu_bar_new() : gtk_custom_menu_new()),
weak_factory_(this) {
}
void MenuGtk::Cancel() {
- gtk_menu_popdown(GTK_MENU(menu_));
+ if (!is_menubar_)
+ gtk_menu_popdown(GTK_MENU(menu_));
}
void MenuGtk::UpdateMenu() {
}
void MenuGtk::OnSubMenuHidden(GtkWidget* submenu) {
+ if (is_menubar_)
+ return;
+
// Increase the reference count of the old submenu, and schedule it to be
// deleted later. We get this hide notification before we've processed menu
// activations, so if we were to delete the submenu now, we might lose the
// menu (overriding the delegate as a controller).
ui::MenuModel* model_;
+ // Whether this is a menu bar.
+ bool is_menubar_;
+
// For some menu items, we want to show the accelerator, but not actually
// explicitly handle it. To this end we connect those menu items' accelerators
// to this group, but don't attach this group to any top level window.