linux: Implement context menu with views.

This commit is contained in:
Cheng Zhao 2014-07-10 12:07:01 +08:00
Родитель 83ff00dc29
Коммит 49160819d2
5 изменённых файлов: 54 добавлений и 59 удалений

Просмотреть файл

@ -54,8 +54,8 @@
'atom/browser/api/atom_api_dialog.cc',
'atom/browser/api/atom_api_menu.cc',
'atom/browser/api/atom_api_menu.h',
'atom/browser/api/atom_api_menu_gtk.cc',
'atom/browser/api/atom_api_menu_gtk.h',
'atom/browser/api/atom_api_menu_views.cc',
'atom/browser/api/atom_api_menu_views.h',
'atom/browser/api/atom_api_menu_mac.h',
'atom/browser/api/atom_api_menu_mac.mm',
'atom/browser/api/atom_api_menu_win.cc',

Просмотреть файл

@ -1,48 +0,0 @@
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/api/atom_api_menu_gtk.h"
#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"
namespace atom {
namespace api {
MenuGtk::MenuGtk() {
}
void MenuGtk::Popup(Window* window) {
/*
uint32_t triggering_event_time;
gfx::Point point;
NativeWindow* native_window = window->window();
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);
*/
}
// static
mate::Wrappable* Menu::Create() {
return new MenuGtk();
}
} // namespace api
} // namespace atom

Просмотреть файл

@ -0,0 +1,40 @@
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/api/atom_api_menu_views.h"
#include "atom/browser/native_window_views.h"
#include "ui/gfx/screen.h"
#include "ui/views/controls/menu/menu_runner.h"
namespace atom {
namespace api {
MenuViews::MenuViews() {
}
void MenuViews::Popup(Window* window) {
gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
menu_runner_.reset(new views::MenuRunner(model()));
views::MenuRunner::RunResult result = menu_runner_->RunMenuAt(
static_cast<NativeWindowViews*>(window->window())->widget(),
NULL,
gfx::Rect(cursor, gfx::Size()),
views::MenuItemView::TOPLEFT,
ui::MENU_SOURCE_MOUSE,
views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU);
if (result == views::MenuRunner::MENU_DELETED)
LOG(ERROR) << "Menu deleted when running";
}
// static
mate::Wrappable* Menu::Create() {
return new MenuViews();
}
} // namespace api
} // namespace atom

Просмотреть файл

@ -2,32 +2,34 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_API_ATOM_API_MENU_GTK_H_
#define ATOM_BROWSER_API_ATOM_API_MENU_GTK_H_
#ifndef ATOM_BROWSER_API_ATOM_API_MENU_VIEWS_H_
#define ATOM_BROWSER_API_ATOM_API_MENU_VIEWS_H_
#include "atom/browser/api/atom_api_menu.h"
#include "chrome/browser/ui/gtk/menu_gtk.h"
namespace views {
class MenuRunner;
}
namespace atom {
namespace api {
class MenuGtk : public Menu,
public ::MenuGtk::Delegate {
class MenuViews : public Menu {
public:
MenuGtk();
MenuViews();
protected:
virtual void Popup(Window* window) OVERRIDE;
private:
scoped_ptr<::MenuGtk> menu_gtk_;
scoped_ptr<views::MenuRunner> menu_runner_;
DISALLOW_COPY_AND_ASSIGN(MenuGtk);
DISALLOW_COPY_AND_ASSIGN(MenuViews);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_ATOM_API_MENU_GTK_H_
#endif // ATOM_BROWSER_API_ATOM_API_MENU_VIEWS_H_

Просмотреть файл

@ -70,6 +70,7 @@ class NativeWindowViews : public NativeWindow,
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
SkRegion* draggable_region() const { return draggable_region_.get(); }
views::Widget* widget() const { return window_.get(); }
private:
// NativeWindow: