Only use default accelerator in Windows/Linux app menu
This commit is contained in:
parent
6381f44f26
commit
2faf00dc19
21 changed files with 125 additions and 69 deletions
|
@ -290,7 +290,7 @@ bool NativeWindow::IsDocumentEdited() {
|
|||
void NativeWindow::SetFocusable(bool focusable) {
|
||||
}
|
||||
|
||||
void NativeWindow::SetMenu(ui::MenuModel* menu) {
|
||||
void NativeWindow::SetMenu(AtomMenuModel* menu) {
|
||||
}
|
||||
|
||||
bool NativeWindow::HasModalDialog() {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "atom/browser/native_window_observer.h"
|
||||
#include "atom/browser/ui/accelerator_util.h"
|
||||
#include "atom/browser/ui/atom_menu_model.h"
|
||||
#include "base/cancelable_callback.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
|
@ -43,10 +44,6 @@ namespace mate {
|
|||
class Dictionary;
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
class MenuModel;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
struct DraggableRegion;
|
||||
|
@ -157,7 +154,7 @@ class NativeWindow : public base::SupportsUserData,
|
|||
virtual void SetIgnoreMouseEvents(bool ignore) = 0;
|
||||
virtual void SetContentProtection(bool enable) = 0;
|
||||
virtual void SetFocusable(bool focusable);
|
||||
virtual void SetMenu(ui::MenuModel* menu);
|
||||
virtual void SetMenu(AtomMenuModel* menu);
|
||||
virtual bool HasModalDialog();
|
||||
virtual void SetParentWindow(NativeWindow* parent);
|
||||
virtual gfx::NativeWindow GetNativeWindow() = 0;
|
||||
|
|
|
@ -748,7 +748,7 @@ void NativeWindowViews::SetFocusable(bool focusable) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) {
|
||||
void NativeWindowViews::SetMenu(AtomMenuModel* menu_model) {
|
||||
if (menu_model == nullptr) {
|
||||
// Remove accelerators
|
||||
accelerator_table_.clear();
|
||||
|
@ -1182,7 +1182,7 @@ bool NativeWindowViews::AcceleratorPressed(const ui::Accelerator& accelerator) {
|
|||
&accelerator_table_, accelerator);
|
||||
}
|
||||
|
||||
void NativeWindowViews::RegisterAccelerators(ui::MenuModel* menu_model) {
|
||||
void NativeWindowViews::RegisterAccelerators(AtomMenuModel* menu_model) {
|
||||
// Clear previous accelerators.
|
||||
views::FocusManager* focus_manager = GetFocusManager();
|
||||
accelerator_table_.clear();
|
||||
|
|
|
@ -98,7 +98,7 @@ class NativeWindowViews : public NativeWindow,
|
|||
void SetIgnoreMouseEvents(bool ignore) override;
|
||||
void SetContentProtection(bool enable) override;
|
||||
void SetFocusable(bool focusable) override;
|
||||
void SetMenu(ui::MenuModel* menu_model) override;
|
||||
void SetMenu(AtomMenuModel* menu_model) override;
|
||||
void SetParentWindow(NativeWindow* parent) override;
|
||||
gfx::NativeWindow GetNativeWindow() override;
|
||||
void SetOverlayIcon(const gfx::Image& overlay,
|
||||
|
@ -176,7 +176,7 @@ class NativeWindowViews : public NativeWindow,
|
|||
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
||||
|
||||
// Register accelerators supported by the menu model.
|
||||
void RegisterAccelerators(ui::MenuModel* menu_model);
|
||||
void RegisterAccelerators(AtomMenuModel* menu_model);
|
||||
|
||||
// Returns the restore state for the window.
|
||||
ui::WindowShowState GetRestoredState();
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_split.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "ui/base/models/simple_menu_model.h"
|
||||
|
||||
namespace accelerator_util {
|
||||
|
||||
|
@ -69,16 +68,17 @@ bool StringToAccelerator(const std::string& shortcut,
|
|||
return true;
|
||||
}
|
||||
|
||||
void GenerateAcceleratorTable(AcceleratorTable* table, ui::MenuModel* model) {
|
||||
void GenerateAcceleratorTable(AcceleratorTable* table,
|
||||
atom::AtomMenuModel* model) {
|
||||
int count = model->GetItemCount();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
ui::MenuModel::ItemType type = model->GetTypeAt(i);
|
||||
if (type == ui::MenuModel::TYPE_SUBMENU) {
|
||||
ui::MenuModel* submodel = model->GetSubmenuModelAt(i);
|
||||
atom::AtomMenuModel::ItemType type = model->GetTypeAt(i);
|
||||
if (type == atom::AtomMenuModel::TYPE_SUBMENU) {
|
||||
auto submodel = model->GetSubmenuModelAt(i);
|
||||
GenerateAcceleratorTable(table, submodel);
|
||||
} else {
|
||||
ui::Accelerator accelerator;
|
||||
if (model->GetAcceleratorAt(i, &accelerator)) {
|
||||
if (model->GetAcceleratorAtWithParams(i, true, &accelerator)) {
|
||||
MenuItem item = { i, model };
|
||||
(*table)[accelerator] = item;
|
||||
}
|
||||
|
|
|
@ -8,15 +8,12 @@
|
|||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "atom/browser/ui/atom_menu_model.h"
|
||||
#include "ui/base/accelerators/accelerator.h"
|
||||
|
||||
namespace ui {
|
||||
class MenuModel;
|
||||
}
|
||||
|
||||
namespace accelerator_util {
|
||||
|
||||
typedef struct { int position; ui::MenuModel* model; } MenuItem;
|
||||
typedef struct { int position; atom::AtomMenuModel* model; } MenuItem;
|
||||
typedef std::map<ui::Accelerator, MenuItem> AcceleratorTable;
|
||||
|
||||
// Parse a string as an accelerator.
|
||||
|
@ -27,7 +24,8 @@ bool StringToAccelerator(const std::string& description,
|
|||
void SetPlatformAccelerator(ui::Accelerator* accelerator);
|
||||
|
||||
// Generate a table that contains memu model's accelerators and command ids.
|
||||
void GenerateAcceleratorTable(AcceleratorTable* table, ui::MenuModel* model);
|
||||
void GenerateAcceleratorTable(AcceleratorTable* table,
|
||||
atom::AtomMenuModel* model);
|
||||
|
||||
// Trigger command from the accelerators table.
|
||||
bool TriggerAcceleratorTableCommand(AcceleratorTable* table,
|
||||
|
|
|
@ -45,4 +45,9 @@ void AtomMenuModel::MenuClosed() {
|
|||
FOR_EACH_OBSERVER(Observer, observers_, MenuClosed());
|
||||
}
|
||||
|
||||
AtomMenuModel* AtomMenuModel::GetSubmenuModelAt(int index) {
|
||||
return static_cast<AtomMenuModel*>(
|
||||
ui::SimpleMenuModel::GetSubmenuModelAt(index));
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -28,7 +28,7 @@ class AtomMenuModel : public ui::SimpleMenuModel {
|
|||
bool GetAcceleratorForCommandId(int command_id,
|
||||
ui::Accelerator* accelerator) {
|
||||
return GetAcceleratorForCommandIdWithParams(
|
||||
command_id, true, accelerator);
|
||||
command_id, false, accelerator);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -55,6 +55,9 @@ class AtomMenuModel : public ui::SimpleMenuModel {
|
|||
// ui::SimpleMenuModel:
|
||||
void MenuClosed() override;
|
||||
|
||||
using SimpleMenuModel::GetSubmenuModelAt;
|
||||
AtomMenuModel* GetSubmenuModelAt(int index);
|
||||
|
||||
private:
|
||||
Delegate* delegate_; // weak ref.
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ void TrayIconGtk::SetToolTip(const std::string& tool_tip) {
|
|||
icon_->SetToolTip(base::UTF8ToUTF16(tool_tip));
|
||||
}
|
||||
|
||||
void TrayIconGtk::SetContextMenu(ui::SimpleMenuModel* menu_model) {
|
||||
void TrayIconGtk::SetContextMenu(AtomMenuModel* menu_model) {
|
||||
icon_->UpdatePlatformContextMenu(menu_model);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class TrayIconGtk : public TrayIcon,
|
|||
// TrayIcon:
|
||||
void SetImage(const gfx::Image& image) override;
|
||||
void SetToolTip(const std::string& tool_tip) override;
|
||||
void SetContextMenu(ui::SimpleMenuModel* menu_model) override;
|
||||
void SetContextMenu(AtomMenuModel* menu_model) override;
|
||||
|
||||
private:
|
||||
// views::StatusIconLinux::Delegate:
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <glib-object.h>
|
||||
|
||||
#include "atom/browser/native_window_views.h"
|
||||
#include "atom/browser/ui/atom_menu_model.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
|
@ -23,7 +24,6 @@
|
|||
#include "ui/aura/window.h"
|
||||
#include "ui/aura/window_tree_host.h"
|
||||
#include "ui/base/accelerators/menu_label_accelerator_util_linux.h"
|
||||
#include "ui/base/models/menu_model.h"
|
||||
#include "ui/events/keycodes/keyboard_code_conversion_x.h"
|
||||
|
||||
// libdbusmenu-glib types
|
||||
|
@ -141,8 +141,8 @@ void EnsureMethodsLoaded() {
|
|||
dlsym(dbusmenu_lib, "dbusmenu_server_set_root"));
|
||||
}
|
||||
|
||||
ui::MenuModel* ModelForMenuItem(DbusmenuMenuitem* item) {
|
||||
return reinterpret_cast<ui::MenuModel*>(
|
||||
AtomMenuModel* ModelForMenuItem(DbusmenuMenuitem* item) {
|
||||
return reinterpret_cast<AtomMenuModel*>(
|
||||
g_object_get_data(G_OBJECT(item), "model"));
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,7 @@ std::string GlobalMenuBarX11::GetPathForWindow(gfx::AcceleratedWidget xid) {
|
|||
return base::StringPrintf("/com/canonical/menu/%lX", xid);
|
||||
}
|
||||
|
||||
void GlobalMenuBarX11::SetMenu(ui::MenuModel* menu_model) {
|
||||
void GlobalMenuBarX11::SetMenu(AtomMenuModel* menu_model) {
|
||||
if (!IsServerStarted())
|
||||
return;
|
||||
|
||||
|
@ -218,14 +218,14 @@ void GlobalMenuBarX11::OnWindowUnmapped() {
|
|||
GlobalMenuBarRegistrarX11::GetInstance()->OnWindowUnmapped(xid_);
|
||||
}
|
||||
|
||||
void GlobalMenuBarX11::BuildMenuFromModel(ui::MenuModel* model,
|
||||
void GlobalMenuBarX11::BuildMenuFromModel(AtomMenuModel* model,
|
||||
DbusmenuMenuitem* parent) {
|
||||
for (int i = 0; i < model->GetItemCount(); ++i) {
|
||||
DbusmenuMenuitem* item = menuitem_new();
|
||||
menuitem_property_set_bool(item, kPropertyVisible, model->IsVisibleAt(i));
|
||||
|
||||
ui::MenuModel::ItemType type = model->GetTypeAt(i);
|
||||
if (type == ui::MenuModel::TYPE_SEPARATOR) {
|
||||
AtomMenuModel::ItemType type = model->GetTypeAt(i);
|
||||
if (type == AtomMenuModel::TYPE_SEPARATOR) {
|
||||
menuitem_property_set(item, kPropertyType, kTypeSeparator);
|
||||
} else {
|
||||
std::string label = ui::ConvertAcceleratorsFromWindowsStyle(
|
||||
|
@ -236,22 +236,22 @@ void GlobalMenuBarX11::BuildMenuFromModel(ui::MenuModel* model,
|
|||
g_object_set_data(G_OBJECT(item), "model", model);
|
||||
SetMenuItemID(item, i);
|
||||
|
||||
if (type == ui::MenuModel::TYPE_SUBMENU) {
|
||||
if (type == AtomMenuModel::TYPE_SUBMENU) {
|
||||
menuitem_property_set(item, kPropertyChildrenDisplay, kDisplaySubmenu);
|
||||
g_signal_connect(item, "about-to-show",
|
||||
G_CALLBACK(OnSubMenuShowThunk), this);
|
||||
} else {
|
||||
ui::Accelerator accelerator;
|
||||
if (model->GetAcceleratorAt(i, &accelerator))
|
||||
if (model->GetAcceleratorAtWithParams(i, true, &accelerator))
|
||||
RegisterAccelerator(item, accelerator);
|
||||
|
||||
g_signal_connect(item, "item-activated",
|
||||
G_CALLBACK(OnItemActivatedThunk), this);
|
||||
|
||||
if (type == ui::MenuModel::TYPE_CHECK ||
|
||||
type == ui::MenuModel::TYPE_RADIO) {
|
||||
if (type == AtomMenuModel::TYPE_CHECK ||
|
||||
type == AtomMenuModel::TYPE_RADIO) {
|
||||
menuitem_property_set(item, kPropertyToggleType,
|
||||
type == ui::MenuModel::TYPE_CHECK ? kToggleCheck : kToggleRadio);
|
||||
type == AtomMenuModel::TYPE_CHECK ? kToggleCheck : kToggleRadio);
|
||||
menuitem_property_set_int(item, kPropertyToggleState,
|
||||
model->IsItemCheckedAt(i));
|
||||
}
|
||||
|
@ -296,14 +296,14 @@ void GlobalMenuBarX11::RegisterAccelerator(DbusmenuMenuitem* item,
|
|||
void GlobalMenuBarX11::OnItemActivated(DbusmenuMenuitem* item,
|
||||
unsigned int timestamp) {
|
||||
int id;
|
||||
ui::MenuModel* model = ModelForMenuItem(item);
|
||||
AtomMenuModel* model = ModelForMenuItem(item);
|
||||
if (model && GetMenuItemID(item, &id))
|
||||
model->ActivatedAt(id, 0);
|
||||
}
|
||||
|
||||
void GlobalMenuBarX11::OnSubMenuShow(DbusmenuMenuitem* item) {
|
||||
int id;
|
||||
ui::MenuModel* model = ModelForMenuItem(item);
|
||||
AtomMenuModel* model = ModelForMenuItem(item);
|
||||
if (!model || !GetMenuItemID(item, &id))
|
||||
return;
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "atom/browser/ui/atom_menu_model.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/compiler_specific.h"
|
||||
#include "ui/base/glib/glib_signal.h"
|
||||
|
@ -17,7 +18,6 @@ typedef struct _DbusmenuServer DbusmenuServer;
|
|||
|
||||
namespace ui {
|
||||
class Accelerator;
|
||||
class MenuModel;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
@ -43,7 +43,7 @@ class GlobalMenuBarX11 {
|
|||
// Creates the object path for DbusmenuServer which is attached to |xid|.
|
||||
static std::string GetPathForWindow(gfx::AcceleratedWidget xid);
|
||||
|
||||
void SetMenu(ui::MenuModel* menu_model);
|
||||
void SetMenu(AtomMenuModel* menu_model);
|
||||
bool IsServerStarted() const;
|
||||
|
||||
// Called by NativeWindow when it show/hides.
|
||||
|
@ -55,7 +55,7 @@ class GlobalMenuBarX11 {
|
|||
void InitServer(gfx::AcceleratedWidget xid);
|
||||
|
||||
// Create a menu from menu model.
|
||||
void BuildMenuFromModel(ui::MenuModel* model, DbusmenuMenuitem* parent);
|
||||
void BuildMenuFromModel(AtomMenuModel* model, DbusmenuMenuitem* parent);
|
||||
|
||||
// Sets the accelerator for |item|.
|
||||
void RegisterAccelerator(DbusmenuMenuitem* item,
|
||||
|
|
|
@ -58,7 +58,7 @@ MenuBar::MenuBar()
|
|||
MenuBar::~MenuBar() {
|
||||
}
|
||||
|
||||
void MenuBar::SetMenu(ui::MenuModel* model) {
|
||||
void MenuBar::SetMenu(AtomMenuModel* model) {
|
||||
menu_model_ = model;
|
||||
RemoveAllChildViews(true);
|
||||
|
||||
|
@ -105,7 +105,7 @@ int MenuBar::GetItemCount() const {
|
|||
}
|
||||
|
||||
bool MenuBar::GetMenuButtonFromScreenPoint(const gfx::Point& point,
|
||||
ui::MenuModel** menu_model,
|
||||
AtomMenuModel** menu_model,
|
||||
views::MenuButton** button) {
|
||||
gfx::Point location(point);
|
||||
views::View::ConvertPointFromScreen(this, &location);
|
||||
|
@ -117,7 +117,7 @@ bool MenuBar::GetMenuButtonFromScreenPoint(const gfx::Point& point,
|
|||
for (int i = 0; i < child_count(); ++i) {
|
||||
views::View* view = child_at(i);
|
||||
if (view->bounds().Contains(location) &&
|
||||
(menu_model_->GetTypeAt(i) == ui::MenuModel::TYPE_SUBMENU)) {
|
||||
(menu_model_->GetTypeAt(i) == AtomMenuModel::TYPE_SUBMENU)) {
|
||||
*menu_model = menu_model_->GetSubmenuModelAt(i);
|
||||
*button = static_cast<views::MenuButton*>(view);
|
||||
return true;
|
||||
|
@ -144,8 +144,8 @@ void MenuBar::OnMenuButtonClicked(views::MenuButton* source,
|
|||
return;
|
||||
|
||||
int id = source->tag();
|
||||
ui::MenuModel::ItemType type = menu_model_->GetTypeAt(id);
|
||||
if (type != ui::MenuModel::TYPE_SUBMENU) {
|
||||
AtomMenuModel::ItemType type = menu_model_->GetTypeAt(id);
|
||||
if (type != AtomMenuModel::TYPE_SUBMENU) {
|
||||
menu_model_->ActivatedAt(id, 0);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -5,14 +5,11 @@
|
|||
#ifndef ATOM_BROWSER_UI_VIEWS_MENU_BAR_H_
|
||||
#define ATOM_BROWSER_UI_VIEWS_MENU_BAR_H_
|
||||
|
||||
#include "atom/browser/ui/atom_menu_model.h"
|
||||
#include "ui/views/controls/button/button.h"
|
||||
#include "ui/views/controls/button/menu_button_listener.h"
|
||||
#include "ui/views/view.h"
|
||||
|
||||
namespace ui {
|
||||
class MenuModel;
|
||||
}
|
||||
|
||||
namespace views {
|
||||
class MenuButton;
|
||||
}
|
||||
|
@ -29,7 +26,7 @@ class MenuBar : public views::View,
|
|||
virtual ~MenuBar();
|
||||
|
||||
// Replaces current menu with a new one.
|
||||
void SetMenu(ui::MenuModel* menu_model);
|
||||
void SetMenu(AtomMenuModel* menu_model);
|
||||
|
||||
// Shows underline under accelerators.
|
||||
void SetAcceleratorVisibility(bool visible);
|
||||
|
@ -46,7 +43,7 @@ class MenuBar : public views::View,
|
|||
|
||||
// Get the menu under specified screen point.
|
||||
bool GetMenuButtonFromScreenPoint(const gfx::Point& point,
|
||||
ui::MenuModel** menu_model,
|
||||
AtomMenuModel** menu_model,
|
||||
views::MenuButton** button);
|
||||
|
||||
protected:
|
||||
|
@ -74,7 +71,7 @@ class MenuBar : public views::View,
|
|||
SkColor hover_color_;
|
||||
#endif
|
||||
|
||||
ui::MenuModel* menu_model_;
|
||||
AtomMenuModel* menu_model_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(MenuBar);
|
||||
};
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
#include "atom/browser/ui/views/menu_delegate.h"
|
||||
|
||||
#include "atom/browser/ui/views/menu_bar.h"
|
||||
#include "atom/browser/ui/views/menu_model_adapter.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "ui/views/controls/button/menu_button.h"
|
||||
#include "ui/views/controls/menu/menu_item_view.h"
|
||||
#include "ui/views/controls/menu/menu_model_adapter.h"
|
||||
#include "ui/views/controls/menu/menu_runner.h"
|
||||
#include "ui/views/widget/widget.h"
|
||||
|
||||
|
@ -22,7 +22,7 @@ MenuDelegate::MenuDelegate(MenuBar* menu_bar)
|
|||
MenuDelegate::~MenuDelegate() {
|
||||
}
|
||||
|
||||
void MenuDelegate::RunMenu(ui::MenuModel* model, views::MenuButton* button) {
|
||||
void MenuDelegate::RunMenu(AtomMenuModel* model, views::MenuButton* button) {
|
||||
gfx::Point screen_loc;
|
||||
views::View::ConvertPointToScreen(button, &screen_loc);
|
||||
// Subtract 1 from the height to make the popup flush with the button border.
|
||||
|
@ -30,10 +30,10 @@ void MenuDelegate::RunMenu(ui::MenuModel* model, views::MenuButton* button) {
|
|||
button->height() - 1);
|
||||
|
||||
id_ = button->tag();
|
||||
adapter_.reset(new views::MenuModelAdapter(model));
|
||||
adapter_.reset(new atom::MenuModelAdapter(model));
|
||||
|
||||
views::MenuItemView* item = new views::MenuItemView(this);
|
||||
static_cast<views::MenuModelAdapter*>(adapter_.get())->BuildMenu(item);
|
||||
static_cast<atom::MenuModelAdapter*>(adapter_.get())->BuildMenu(item);
|
||||
|
||||
menu_runner_.reset(new views::MenuRunner(
|
||||
item,
|
||||
|
@ -102,7 +102,7 @@ views::MenuItemView* MenuDelegate::GetSiblingMenu(
|
|||
bool* has_mnemonics,
|
||||
views::MenuButton**) {
|
||||
views::MenuButton* button;
|
||||
ui::MenuModel* model;
|
||||
AtomMenuModel* model;
|
||||
if (menu_bar_->GetMenuButtonFromScreenPoint(screen_point, &model, &button) &&
|
||||
button->tag() != id_) {
|
||||
DCHECK(menu_runner_->IsRunning());
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#ifndef ATOM_BROWSER_UI_VIEWS_MENU_DELEGATE_H_
|
||||
#define ATOM_BROWSER_UI_VIEWS_MENU_DELEGATE_H_
|
||||
|
||||
#include "atom/browser/ui/atom_menu_model.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "ui/views/controls/menu/menu_delegate.h"
|
||||
|
||||
|
@ -12,10 +13,6 @@ namespace views {
|
|||
class MenuRunner;
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
class MenuModel;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
class MenuBar;
|
||||
|
@ -25,7 +22,7 @@ class MenuDelegate : public views::MenuDelegate {
|
|||
explicit MenuDelegate(MenuBar* menu_bar);
|
||||
virtual ~MenuDelegate();
|
||||
|
||||
void RunMenu(ui::MenuModel* model, views::MenuButton* button);
|
||||
void RunMenu(AtomMenuModel* model, views::MenuButton* button);
|
||||
|
||||
protected:
|
||||
// views::MenuDelegate:
|
||||
|
|
28
atom/browser/ui/views/menu_model_adapter.cc
Normal file
28
atom/browser/ui/views/menu_model_adapter.cc
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Copyright (c) 2016 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/ui/views/menu_model_adapter.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
MenuModelAdapter::MenuModelAdapter(AtomMenuModel* menu_model)
|
||||
: views::MenuModelAdapter(menu_model),
|
||||
menu_model_(menu_model) {
|
||||
}
|
||||
|
||||
MenuModelAdapter::~MenuModelAdapter() {
|
||||
}
|
||||
|
||||
bool MenuModelAdapter::GetAccelerator(int id,
|
||||
ui::Accelerator* accelerator) const {
|
||||
ui::MenuModel* model = menu_model_;
|
||||
int index = 0;
|
||||
if (ui::MenuModel::GetModelAndIndexForCommandId(id, &model, &index)) {
|
||||
return static_cast<AtomMenuModel*>(model)->
|
||||
GetAcceleratorAtWithParams(index, true, accelerator);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace atom
|
29
atom/browser/ui/views/menu_model_adapter.h
Normal file
29
atom/browser/ui/views/menu_model_adapter.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) 2016 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_UI_VIEWS_MENU_MODEL_ADAPTER_H_
|
||||
#define ATOM_BROWSER_UI_VIEWS_MENU_MODEL_ADAPTER_H_
|
||||
|
||||
#include "atom/browser/ui/atom_menu_model.h"
|
||||
#include "ui/views/controls/menu/menu_model_adapter.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class MenuModelAdapter : public views::MenuModelAdapter {
|
||||
public:
|
||||
explicit MenuModelAdapter(AtomMenuModel* menu_model);
|
||||
virtual ~MenuModelAdapter();
|
||||
|
||||
protected:
|
||||
bool GetAccelerator(int id, ui::Accelerator* accelerator) const override;
|
||||
|
||||
private:
|
||||
AtomMenuModel* menu_model_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(MenuModelAdapter);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_UI_VIEWS_MENU_MODEL_ADAPTER_H_
|
|
@ -132,7 +132,7 @@ void NotifyIcon::DisplayBalloon(HICON icon,
|
|||
}
|
||||
|
||||
void NotifyIcon::PopUpContextMenu(const gfx::Point& pos,
|
||||
ui::SimpleMenuModel* menu_model) {
|
||||
AtomMenuModel* menu_model) {
|
||||
// Returns if context menu isn't set.
|
||||
if (menu_model == nullptr && menu_model_ == nullptr)
|
||||
return;
|
||||
|
@ -154,7 +154,7 @@ void NotifyIcon::PopUpContextMenu(const gfx::Point& pos,
|
|||
NULL, NULL, rect, views::MENU_ANCHOR_TOPLEFT, ui::MENU_SOURCE_MOUSE));
|
||||
}
|
||||
|
||||
void NotifyIcon::SetContextMenu(ui::SimpleMenuModel* menu_model) {
|
||||
void NotifyIcon::SetContextMenu(AtomMenuModel* menu_model) {
|
||||
menu_model_ = menu_model;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,8 +52,8 @@ class NotifyIcon : public TrayIcon {
|
|||
const base::string16& title,
|
||||
const base::string16& contents) override;
|
||||
void PopUpContextMenu(const gfx::Point& pos,
|
||||
ui::SimpleMenuModel* menu_model) override;
|
||||
void SetContextMenu(ui::SimpleMenuModel* menu_model) override;
|
||||
AtomMenuModel* menu_model) override;
|
||||
void SetContextMenu(AtomMenuModel* menu_model) override;
|
||||
gfx::Rect GetBounds() override;
|
||||
|
||||
private:
|
||||
|
@ -75,7 +75,7 @@ class NotifyIcon : public TrayIcon {
|
|||
base::win::ScopedHICON icon_;
|
||||
|
||||
// The context menu.
|
||||
ui::SimpleMenuModel* menu_model_;
|
||||
AtomMenuModel* menu_model_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(NotifyIcon);
|
||||
};
|
||||
|
|
|
@ -275,6 +275,8 @@
|
|||
'atom/browser/ui/views/menu_delegate.h',
|
||||
'atom/browser/ui/views/menu_layout.cc',
|
||||
'atom/browser/ui/views/menu_layout.h',
|
||||
'atom/browser/ui/views/menu_model_adapter.cc',
|
||||
'atom/browser/ui/views/menu_model_adapter.h',
|
||||
'atom/browser/ui/views/native_frame_view.cc',
|
||||
'atom/browser/ui/views/native_frame_view.h',
|
||||
'atom/browser/ui/views/submenu_button.cc',
|
||||
|
|
Loading…
Reference in a new issue