} // namespace
-Menu::Menu() : model_(new ui::SimpleMenuModel(this)) {
+Menu::Menu()
+ : model_(new ui::SimpleMenuModel(this)),
+ parent_(NULL) {
}
Menu::~Menu() {
int command_id,
const base::string16& label,
Menu* menu) {
+ menu->parent_ = this;
model_->InsertSubMenuAt(index, command_id, label, menu->model_.get());
}
.SetMethod("isVisibleAt", &Menu::IsVisibleAt)
#if defined(OS_WIN) || defined(TOOLKIT_GTK)
.SetMethod("_attachToWindow", &Menu::AttachToWindow)
+#endif
+#if defined(OS_WIN)
+ .SetMethod("_updateStates", &Menu::UpdateStates)
#endif
.SetMethod("_popup", &Menu::Popup);
}
virtual void Popup(Window* window) = 0;
scoped_ptr<ui::SimpleMenuModel> model_;
+ Menu* parent_;
private:
void InsertItemAt(int index, int command_id, const base::string16& label);
bool IsEnabledAt(int index) const;
bool IsVisibleAt(int index) const;
+#if defined(OS_WIN)
+ virtual void UpdateStates() = 0;
+#endif
+
#if defined(OS_WIN) || defined(TOOLKIT_GTK)
- void AttachToWindow(Window* window);
+ virtual void AttachToWindow(Window* window) = 0;
#endif
DISALLOW_COPY_AND_ASSIGN(Menu);
menu_gtk_->PopupAsContext(point, triggering_event_time);
}
-void Menu::AttachToWindow(Window* window) {
+void MenuGtk::AttachToWindow(Window* window) {
static_cast<NativeWindowGtk*>(window->window())->SetMenu(model_.get());
}
protected:
virtual void Popup(Window* window) OVERRIDE;
+ virtual void AttachToWindow(Window* window) OVERRIDE;
private:
scoped_ptr<::MenuGtk> menu_gtk_;
namespace api {
-MenuWin::MenuWin() {
+MenuWin::MenuWin() : menu_(NULL) {
}
void MenuWin::Popup(Window* window) {
gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
- menu_.reset(new atom::Menu2(model_.get()));
+ popup_menu_.reset(new atom::Menu2(model_.get()));
+ menu_ = popup_menu_.get();
menu_->RunContextMenuAt(cursor);
}
-void Menu::AttachToWindow(Window* window) {
- static_cast<NativeWindowWin*>(window->window())->SetMenu(model_.get());
+void MenuWin::UpdateStates() {
+ MenuWin* top = this;
+ while (top->parent_)
+ top = static_cast<MenuWin*>(top->parent_);
+ if (top->menu_)
+ top->menu_->UpdateStates();
+}
+
+void MenuWin::AttachToWindow(Window* window) {
+ NativeWindowWin* nw = static_cast<NativeWindowWin*>(window->window());
+ nw->SetMenu(model_.get());
+ menu_ = nw->menu();
}
// static
protected:
virtual void Popup(Window* window) OVERRIDE;
+ virtual void UpdateStates() OVERRIDE;
+ virtual void AttachToWindow(Window* window) OVERRIDE;
private:
- scoped_ptr<atom::Menu2> menu_;
+ atom::Menu2* menu_; // Weak ref, could be window menu or popup menu.
+ scoped_ptr<atom::Menu2> popup_menu_;
DISALLOW_COPY_AND_ASSIGN(MenuWin);
};
switch item.type
when 'normal' then @insertItem pos, item.commandId, item.label
- when 'checkbox' then @insertCheckItem pos, item.commandId, item.label
+ when 'checkbox'
+ # Update states when clicked on Windows.
+ if process.platform is 'win32'
+ v8Util.setHiddenValue item, 'checked', item.checked
+ Object.defineProperty item, 'checked',
+ enumerable: true
+ get: -> v8Util.getHiddenValue item, 'checked'
+ set: (val) =>
+ v8Util.setHiddenValue item, 'checked', val
+ @_updateStates() if process.platform is 'win32'
+
+ @insertCheckItem pos, item.commandId, item.label
when 'separator' then @insertSeparator pos
when 'submenu' then @insertSubMenu pos, item.commandId, item.label, item.submenu
when 'radio'
v8Util.setHiddenValue otherItem, 'checked', false
v8Util.setHiddenValue item, 'checked', true
+ # Update states when clicked on Windows.
+ @_updateStates() if process.platform is 'win32'
+
@insertRadioItem pos, item.commandId, item.label, item.groupId
@setSublabel pos, item.sublabel if item.sublabel?
void SetMenu(ui::MenuModel* menu_model);
views::Widget* window() const { return window_.get(); }
+ atom::Menu2* menu() const { return menu_.get(); }
SkRegion* draggable_region() { return draggable_region_.get(); }
protected: