void CustomContextMenuProvider::populateContextMenuItems(const HTMLMenuElement& menu, ContextMenu& contextMenu) { HTMLElement* nextElement = Traversal<HTMLElement>::firstWithin(menu); while (nextElement) { if (isHTMLHRElement(*nextElement)) { appendSeparator(contextMenu); nextElement = Traversal<HTMLElement>::next(*nextElement, &menu); } else if (isHTMLMenuElement(*nextElement)) { ContextMenu subMenu; String labelString = nextElement->fastGetAttribute(labelAttr); if (labelString.isNull()) { appendSeparator(contextMenu); populateContextMenuItems(*toHTMLMenuElement(nextElement), contextMenu); appendSeparator(contextMenu); } else if (!labelString.isEmpty()) { populateContextMenuItems(*toHTMLMenuElement(nextElement), subMenu); contextMenu.appendItem(ContextMenuItem(SubmenuType, ContextMenuItemCustomTagNoAction, labelString, String(), &subMenu)); } nextElement = Traversal<HTMLElement>::nextSibling(*nextElement); } else if (isHTMLMenuItemElement(*nextElement)) { appendMenuItem(toHTMLMenuItemElement(nextElement), contextMenu); if (ContextMenuItemBaseCustomTag + m_menuItems.size() >= ContextMenuItemLastCustomTag) break; nextElement = Traversal<HTMLElement>::next(*nextElement, &menu); } else { nextElement = Traversal<HTMLElement>::next(*nextElement, &menu); } } // Remove separators at the end of the menu and any submenus. while (contextMenu.items().size() && contextMenu.items().last().type() == SeparatorType) contextMenu.removeLastItem(); }
v8::Handle<v8::Value> V8InspectorFrontendHost::showContextMenuCallback(const v8::Arguments& args) { if (args.Length() < 2) return v8::Undefined(); v8::Local<v8::Object> eventWrapper = v8::Local<v8::Object>::Cast(args[0]); if (!V8MouseEvent::info.equals(V8DOMWrapper::domWrapperType(eventWrapper))) return v8::Undefined(); Event* event = V8Event::toNative(eventWrapper); if (!args[1]->IsArray()) return v8::Undefined(); v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(args[1]); ContextMenu menu; populateContextMenuItems(array, menu); InspectorFrontendHost* frontendHost = V8InspectorFrontendHost::toNative(args.Holder()); #if !USE(CROSS_PLATFORM_CONTEXT_MENUS) Vector<ContextMenuItem> items = contextMenuItemVector(menu.platformDescription()); #else Vector<ContextMenuItem> items = menu.items(); #endif frontendHost->showContextMenu(event, items); return v8::Undefined(); }
static bool populateContextMenuItems(v8::Isolate* isolate, const v8::Local<v8::Array>& itemArray, ContextMenu& menu) { v8::Local<v8::Context> context = isolate->GetCurrentContext(); for (size_t i = 0; i < itemArray->Length(); ++i) { v8::Local<v8::Object> item = itemArray->Get(context, i).ToLocalChecked().As<v8::Object>(); v8::Local<v8::Value> type; v8::Local<v8::Value> id; v8::Local<v8::Value> label; v8::Local<v8::Value> enabled; v8::Local<v8::Value> checked; v8::Local<v8::Value> subItems; if (!item->Get(context, v8AtomicString(isolate, "type")).ToLocal(&type) || !item->Get(context, v8AtomicString(isolate, "id")).ToLocal(&id) || !item->Get(context, v8AtomicString(isolate, "label")).ToLocal(&label) || !item->Get(context, v8AtomicString(isolate, "enabled")) .ToLocal(&enabled) || !item->Get(context, v8AtomicString(isolate, "checked")) .ToLocal(&checked) || !item->Get(context, v8AtomicString(isolate, "subItems")) .ToLocal(&subItems)) return false; if (!type->IsString()) continue; String typeString = toCoreStringWithNullCheck(type.As<v8::String>()); if (typeString == "separator") { ContextMenuItem item(ContextMenuItem( SeparatorType, ContextMenuItemCustomTagNoAction, String(), String())); menu.appendItem(item); } else if (typeString == "subMenu" && subItems->IsArray()) { ContextMenu subMenu; v8::Local<v8::Array> subItemsArray = v8::Local<v8::Array>::Cast(subItems); if (!populateContextMenuItems(isolate, subItemsArray, subMenu)) return false; TOSTRING_DEFAULT(V8StringResource<TreatNullAsNullString>, labelString, label, false); ContextMenuItem item(SubmenuType, ContextMenuItemCustomTagNoAction, labelString, String(), &subMenu); menu.appendItem(item); } else { int32_t int32Id; if (!v8Call(id->Int32Value(context), int32Id)) return false; ContextMenuAction typedId = static_cast<ContextMenuAction>( ContextMenuItemBaseCustomTag + int32Id); TOSTRING_DEFAULT(V8StringResource<TreatNullAsNullString>, labelString, label, false); ContextMenuItem menuItem( (typeString == "checkbox" ? CheckableActionType : ActionType), typedId, labelString, String()); if (checked->IsBoolean()) menuItem.setChecked(checked.As<v8::Boolean>()->Value()); if (enabled->IsBoolean()) menuItem.setEnabled(enabled.As<v8::Boolean>()->Value()); menu.appendItem(menuItem); } } return true; }
static void populateContextMenuItems(ExecState* exec, JSArray* array, ContextMenu& menu) { for (size_t i = 0; i < array->length(); ++i) { JSObject* item = asObject(array->getIndex(exec, i)); JSValue label = item->get(exec, Identifier::fromString(exec, "label")); JSValue type = item->get(exec, Identifier::fromString(exec, "type")); JSValue id = item->get(exec, Identifier::fromString(exec, "id")); JSValue enabled = item->get(exec, Identifier::fromString(exec, "enabled")); JSValue checked = item->get(exec, Identifier::fromString(exec, "checked")); JSValue subItems = item->get(exec, Identifier::fromString(exec, "subItems")); if (!type.isString()) continue; String typeString = type.toWTFString(exec); if (typeString == "separator") { ContextMenuItem item(SeparatorType, ContextMenuItemTagNoAction, String()); menu.appendItem(item); } else if (typeString == "subMenu" && subItems.inherits(JSArray::info())) { ContextMenu subMenu; JSArray* subItemsArray = asArray(subItems); populateContextMenuItems(exec, subItemsArray, subMenu); ContextMenuItem item(SubmenuType, ContextMenuItemTagNoAction, label.toWTFString(exec), &subMenu); menu.appendItem(item); } else { ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(exec)); ContextMenuItem menuItem((typeString == "checkbox" ? CheckableActionType : ActionType), typedId, label.toWTFString(exec)); if (!enabled.isUndefined()) menuItem.setEnabled(enabled.toBoolean(exec)); if (!checked.isUndefined()) menuItem.setChecked(checked.toBoolean(exec)); menu.appendItem(menuItem); } } }
void CustomContextMenuProvider::appendMenuItem(HTMLMenuItemElement* menuItem, ContextMenu& contextMenu) { // Avoid menuitems with no label. String labelString = menuItem->fastGetAttribute(labelAttr); if (labelString.isEmpty()) return; m_menuItems.append(menuItem); bool enabled = !menuItem->fastHasAttribute(disabledAttr); String icon = menuItem->fastGetAttribute(iconAttr); if (!icon.isEmpty()) { // To obtain the absolute URL of the icon when the attribute's value is not // the empty string, the attribute's value must be resolved relative to the // element. KURL iconURL = KURL(menuItem->baseURI(), icon); icon = iconURL.getString(); } ContextMenuAction action = static_cast<ContextMenuAction>( ContextMenuItemBaseCustomTag + m_menuItems.size() - 1); if (equalIgnoringCase(menuItem->fastGetAttribute(typeAttr), "checkbox") || equalIgnoringCase(menuItem->fastGetAttribute(typeAttr), "radio")) contextMenu.appendItem( ContextMenuItem(CheckableActionType, action, labelString, icon, enabled, menuItem->fastHasAttribute(checkedAttr))); else contextMenu.appendItem( ContextMenuItem(ActionType, action, labelString, icon, enabled, false)); }
//! Insert a menu item at specified position. ContextMenuItem* ContextMenu::insertItem(unsigned int idx, const std::string& text, int commandId, bool enabled, bool hasSubMenu, bool checked, bool autoChecking) { ContextMenuItem* newItem = new ContextMenuItem( this, text ); newItem->setEnabled( enabled ); newItem->setSubElement( true ); newItem->setChecked( checked ); newItem->setAutoChecking( autoChecking ); newItem->setText( text ); newItem->setFlag( ContextMenuItem::drawSubmenuSprite ); newItem->setIsSeparator( text.empty() ); newItem->setCommandId( commandId ); sendChildToBack( newItem ); if (hasSubMenu) { ContextMenu* subMenu = newItem->addSubMenu( commandId ); subMenu->setVisible( false ); } if ( idx < _d->items.size() ) { _d->items.insert( _d->items.begin() + idx, newItem ); } else { _d->items.push_back( newItem ); } return newItem; }
MainWindow :: MainWindow(HINSTANCE instance, const wchar_t* caption, _Controller* controller, Model* model) : SDIWindow(instance, caption), _windowList(10, IDM_WINDOW_WINDOWS), _recentFiles(10, IDM_FILE_FILES), _recentProjects(10, IDM_FILE_PROJECTS), _contextBrowser(model) { _controller = controller; _model = model; _tabTTHandle = NULL; _controlCount = 14; _controls = (_BaseControl**)malloc(_controlCount << 2); _controls[0] = NULL; _controls[CTRL_MENU] = new Menu(instance, IDR_IDE_ACCELERATORS, ::GetMenu(getHandle())); _controls[CTRL_CONTEXTMENU] = new ContextMenu(); _windowList.assign((Menu*)_controls[CTRL_MENU]); _recentFiles.assign((Menu*)_controls[CTRL_MENU]); _recentProjects.assign((Menu*)_controls[CTRL_MENU]); ContextMenu* contextMenu = (ContextMenu*)_controls[CTRL_CONTEXTMENU]; contextMenu->create(8, contextMenuInfo); _controls[CTRL_STATUSBAR] = new StatusBar(this, 5, StatusBarWidths); _controls[CTRL_TOOLBAR] = new ToolBar(this, 16, AppToolBarButtonNumber, AppToolBarButtons); _controls[CTRL_EDITFRAME] = new EditFrame(this, true, contextMenu, model); _controls[CTRL_TABBAR] = new TabBar(this, _model->tabWithAboveScore); _controls[CTRL_OUTPUT] = new Output((Control*)_controls[CTRL_TABBAR], this); _controls[CTRL_MESSAGELIST] = new MessageLog((Control*)_controls[CTRL_TABBAR]); _controls[CTRL_CALLLIST] = new CallStackLog((Control*)_controls[CTRL_TABBAR]); _controls[CTRL_BSPLITTER] = new Splitter(this, (Control*)_controls[CTRL_TABBAR], false, IDM_LAYOUT_CHANGED); _controls[CTRL_CONTEXTBOWSER] = new TreeView((Control*)_controls[CTRL_TABBAR], true); _controls[CTRL_PROJECTVIEW] = new TreeView(this, false); _controls[CTRL_HSPLITTER] = new Splitter(this, (Control*)_controls[CTRL_PROJECTVIEW], true, IDM_LAYOUT_CHANGED); ((Control*)_controls[CTRL_TABBAR])->_setHeight(120); ((Control*)_controls[CTRL_BSPLITTER])->_setConstraint(60, 100); ((Control*)_controls[CTRL_PROJECTVIEW])->_setWidth(200); _statusBar = (StatusBar*)_controls[CTRL_STATUSBAR]; EditFrame* frame = (EditFrame*)_controls[CTRL_EDITFRAME]; TextView* textView = new TextView(frame, 5, 28, 400, 400); frame->populate(textView); textView->setReceptor(this); _contextBrowser.assign((Control*)_controls[CTRL_CONTEXTBOWSER]); setLeft(CTRL_HSPLITTER); setTop(CTRL_TOOLBAR); setClient(CTRL_EDITFRAME); setBottom(CTRL_BSPLITTER); frame->init(model); showControls(CTRL_STATUSBAR, CTRL_EDITFRAME); showControls(CTRL_PROJECTVIEW, CTRL_PROJECTVIEW); }
void TimelineWidget::polishSessionExplorerContextMenu(Subject &subject, const std::string &signal, const boost::any &v) { SessionExplorer &ses = dynamic_cast<SessionExplorer&>(subject); if(ses.getItemViewType() == SessionExplorer::ANIMATION_ITEMS) { ContextMenu *pMenu = boost::any_cast<ContextMenu*>(v); VERIFYNRV(pMenu); pMenu->addAction(mpNewAnimationAction, "TIMELINEWIDGET_NEW_ANIMATION_ACTION"); } }
void SceneGraphExplorerPanel::contextMenuEvent (QContextMenuEvent* event) { QPoint globalPoint = event->globalPos(); QListWidgetItem* selectedItem = m_listWidget->itemAt(m_listWidget->mapFromGlobal(globalPoint)); GUIStateNode_ptr selectedGUIStateNode = m_guiStateNodesByItem[selectedItem]; if(selectedGUIStateNode != NULL && selectedGUIStateNode->getContextMenu() != NULL ) { ContextMenu* contextMenu = selectedGUIStateNode->getContextMenu(); QAction* action = contextMenu->exec(globalPoint); } }
void CustomContextMenuProvider::appendSeparator(ContextMenu& contextMenu) { // Avoid separators at the start of any menu and submenu. if (!contextMenu.items().size()) return; // Collapse all sequences of two or more adjacent separators in the menu or // any submenus to a single separator. ContextMenuItem lastItem = contextMenu.items().last(); if (lastItem.type() == SeparatorType) return; contextMenu.appendItem(ContextMenuItem(SeparatorType, ContextMenuItemCustomTagNoAction, String(), String())); }
void V8DevToolsHost::showContextMenuAtPointMethodCustom( const v8::FunctionCallbackInfo<v8::Value>& info) { if (info.Length() < 3) return; ExceptionState exceptionState(ExceptionState::ExecutionContext, "showContextMenuAtPoint", "DevToolsHost", info.Holder(), info.GetIsolate()); v8::Isolate* isolate = info.GetIsolate(); float x = toRestrictedFloat(isolate, info[0], exceptionState); if (exceptionState.hadException()) return; float y = toRestrictedFloat(isolate, info[1], exceptionState); if (exceptionState.hadException()) return; v8::Local<v8::Value> array = v8::Local<v8::Value>::Cast(info[2]); if (!array->IsArray()) return; ContextMenu menu; if (!populateContextMenuItems(isolate, v8::Local<v8::Array>::Cast(array), menu)) return; Document* document = nullptr; if (info.Length() >= 4 && v8::Local<v8::Value>::Cast(info[3])->IsObject()) { v8::Local<v8::Object> documentWrapper = v8::Local<v8::Object>::Cast(info[3]); if (!V8HTMLDocument::wrapperTypeInfo.equals( toWrapperTypeInfo(documentWrapper))) return; document = V8HTMLDocument::toImpl(documentWrapper); } else { v8::Local<v8::Object> windowWrapper = V8Window::findInstanceInPrototypeChain( isolate->GetEnteredContext()->Global(), isolate); if (windowWrapper.IsEmpty()) return; DOMWindow* window = V8Window::toImpl(windowWrapper); document = window ? toLocalDOMWindow(window)->document() : nullptr; } if (!document || !document->frame()) return; DevToolsHost* devtoolsHost = V8DevToolsHost::toImpl(info.Holder()); Vector<ContextMenuItem> items = menu.items(); devtoolsHost->showContextMenu(document->frame(), x, y, items); }
void BWebPage::handleMouseEvent(const BMessage* message) { WebCore::Frame* frame = fMainFrame->Frame(); if (!frame->view() || !frame->document()) return; PlatformMouseEvent event(message); switch (message->what) { case B_MOUSE_DOWN: // Handle context menus, if necessary. if (event.button() == RightButton) { fPage->contextMenuController()->clearContextMenu(); WebCore::Frame* focusedFrame = fPage->focusController()->focusedOrMainFrame(); focusedFrame->eventHandler()->sendContextMenuEvent(event); // If the web page implements it's own context menu handling, then // the contextMenu() pointer will be zero. In this case, we should // also swallow the event. ContextMenu* contextMenu = fPage->contextMenuController()->contextMenu(); if (contextMenu) { BMenu* platformMenu = contextMenu->releasePlatformDescription(); if (platformMenu) { // Need to convert the BMenu into BPopUpMenu. BPopUpMenu* popupMenu = new BPopUpMenu("context menu"); for (int32 i = platformMenu->CountItems() - 1; i >= 0; i--) { BMenuItem* item = platformMenu->RemoveItem(i); popupMenu->AddItem(item, 0); } BPoint screenLocation(event.globalPosition().x() + 2, event.globalPosition().y() + 2); popupMenu->Go(screenLocation, true, true, true); delete platformMenu; } } break; } // Handle regular mouse events. frame->eventHandler()->handleMousePressEvent(event); break; case B_MOUSE_UP: frame->eventHandler()->handleMouseReleaseEvent(event); break; case B_MOUSE_MOVED: default: frame->eventHandler()->mouseMoved(event); break; } }
JSValue JSInspectorFrontendHost::showContextMenu(ExecState& state) { #if ENABLE(CONTEXT_MENUS) if (state.argumentCount() < 2) return jsUndefined(); Event* event = JSEvent::toWrapped(state.argument(0)); JSArray* array = asArray(state.argument(1)); ContextMenu menu; populateContextMenuItems(&state, array, menu); wrapped().showContextMenu(event, menu.items()); #else UNUSED_PARAM(state); #endif return jsUndefined(); }
void RangeProfilePlotManager::updateContextMenu(Subject& subject, const std::string& signal, const boost::any& value) { ContextMenu* pMenu = boost::any_cast<ContextMenu*>(value); if (pMenu == NULL) { return; } QAction* pDiffAction = new QAction("Calculate Difference", pMenu->getActionParent()); VERIFYNRV(mpView); int numSelectedObjects = mpView->getNumSelectedObjects(true); if (numSelectedObjects != 2) { pDiffAction->setEnabled(false); } else { std::list<PlotObject*> objects; mpView->getSelectedObjects(objects, true); for (std::list<PlotObject*>::const_iterator obj = objects.begin(); obj != objects.end(); ++obj) { std::string name; (*obj)->getObjectName(name); if (name == "Difference") { pDiffAction->setEnabled(false); break; } } } VERIFYNR(connect(pDiffAction, SIGNAL(triggered()), this, SLOT(calculateDifferences()))); pMenu->addActionBefore(pDiffAction, "SPECTRAL_RANGEPROFILEPLOT_DIFFERENCE_ACTION", APP_PLOTWIDGET_PRINT_ACTION); QAction* pDelAction = new QAction( (numSelectedObjects > 1) ? "Delete Plots" : "Delete Plot", pMenu->getActionParent()); if (mpView != NULL && numSelectedObjects == 0) { pDelAction->setEnabled(false); } VERIFYNR(connect(pDelAction, SIGNAL(triggered()), this, SLOT(deleteSelectedPlots()))); pMenu->addActionAfter(pDelAction, "SPECTRAL_RANGEPROFILEPLOT_DELETE_ACTION", "SPECTRAL_RANGEPROFILEPLOT_DIFFERENCE_ACTION"); }
static bool populateContextMenuItems(v8::Local<v8::Array>& itemArray, ContextMenu& menu, v8::Isolate* isolate) { for (size_t i = 0; i < itemArray->Length(); ++i) { v8::Local<v8::Object> item = v8::Local<v8::Object>::Cast(itemArray->Get(i)); v8::Local<v8::Value> type = item->Get(v8AtomicString(isolate, "type")); v8::Local<v8::Value> id = item->Get(v8AtomicString(isolate, "id")); v8::Local<v8::Value> label = item->Get(v8AtomicString(isolate, "label")); v8::Local<v8::Value> enabled = item->Get(v8AtomicString(isolate, "enabled")); v8::Local<v8::Value> checked = item->Get(v8AtomicString(isolate, "checked")); v8::Local<v8::Value> subItems = item->Get(v8AtomicString(isolate, "subItems")); if (!type->IsString()) continue; String typeString = toCoreStringWithNullCheck(type.As<v8::String>()); if (typeString == "separator") { ContextMenuItem item(ContextMenuItem(SeparatorType, ContextMenuItemCustomTagNoAction, String())); menu.appendItem(item); } else if (typeString == "subMenu" && subItems->IsArray()) { ContextMenu subMenu; v8::Local<v8::Array> subItemsArray = v8::Local<v8::Array>::Cast(subItems); if (!populateContextMenuItems(subItemsArray, subMenu, isolate)) return false; V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<WithNullCheck>, labelString, label, false); ContextMenuItem item(SubmenuType, ContextMenuItemCustomTagNoAction, labelString, &subMenu); menu.appendItem(item); } else { ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id->ToInt32()->Value()); V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<WithNullCheck>, labelString, label, false); ContextMenuItem menuItem((typeString == "checkbox" ? CheckableActionType : ActionType), typedId, labelString); if (checked->IsBoolean()) menuItem.setChecked(checked->ToBoolean()->Value()); if (enabled->IsBoolean()) menuItem.setEnabled(enabled->ToBoolean()->Value()); menu.appendItem(menuItem); } } return true; }
void WebContextMenu::menuItemsWithUserData(Vector<WebContextMenuItemData> &menuItems, RefPtr<API::Object>& userData) const { ContextMenuController& controller = m_page->corePage()->contextMenuController(); ContextMenu* menu = controller.contextMenu(); if (!menu) return; // Give the bundle client a chance to process the menu. #if USE(CROSS_PLATFORM_CONTEXT_MENUS) const Vector<ContextMenuItem>& coreItems = menu->items(); #else Vector<ContextMenuItem> coreItems = contextMenuItemVector(menu->platformDescription()); #endif Vector<WebContextMenuItemData> proposedMenu = kitItems(coreItems, menu); Vector<WebContextMenuItemData> newMenu; RefPtr<InjectedBundleHitTestResult> hitTestResult = InjectedBundleHitTestResult::create(controller.hitTestResult()); if (m_page->injectedBundleContextMenuClient().getCustomMenuFromDefaultItems(m_page, hitTestResult.get(), proposedMenu, newMenu, userData)) proposedMenu = newMenu; menuItems = proposedMenu; }
JSValue JSInspectorFrontendHost::showContextMenu(ExecState& state) { #if ENABLE(CONTEXT_MENUS) if (state.argumentCount() < 2) return jsUndefined(); Event* event = JSEvent::toWrapped(state.argument(0)); JSArray* array = asArray(state.argument(1)); ContextMenu menu; populateContextMenuItems(&state, array, menu); #if !USE(CROSS_PLATFORM_CONTEXT_MENUS) Vector<ContextMenuItem> items = contextMenuItemVector(menu.platformDescription()); #else Vector<ContextMenuItem> items = menu.items(); #endif wrapped().showContextMenu(event, items); #else UNUSED_PARAM(state); #endif return jsUndefined(); }
JSValue JSInspectorFrontendHost::showContextMenu(ExecState* exec) { #if ENABLE(CONTEXT_MENUS) if (exec->argumentCount() < 2) return jsUndefined(); Event* event = toEvent(exec->argument(0)); JSArray* array = asArray(exec->argument(1)); ContextMenu menu; populateContextMenuItems(exec, array, menu); #if !USE(CROSS_PLATFORM_CONTEXT_MENUS) Vector<ContextMenuItem> items = contextMenuItemVector(menu.platformDescription()); #else Vector<ContextMenuItem> items = menu.items(); #endif impl()->showContextMenu(event, items); #else UNUSED_PARAM(exec); #endif return jsUndefined(); }
void V8InspectorFrontendHost::showContextMenuMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) { if (info.Length() < 2) return; v8::Local<v8::Object> eventWrapper = v8::Local<v8::Object>::Cast(info[0]); if (!V8MouseEvent::wrapperTypeInfo.equals(toWrapperTypeInfo(eventWrapper))) return; Event* event = V8Event::toNative(eventWrapper); if (!info[1]->IsArray()) return; v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(info[1]); ContextMenu menu; if (!populateContextMenuItems(array, menu, info.GetIsolate())) return; InspectorFrontendHost* frontendHost = V8InspectorFrontendHost::toNative(info.Holder()); Vector<ContextMenuItem> items = menu.items(); frontendHost->showContextMenu(event, items); }
void WebContextMenu::show() { ContextMenuController* controller = m_page->corePage()->contextMenuController(); if (!controller) return; ContextMenu* menu = controller->contextMenu(); if (!menu) return; Node* node = controller->hitTestResult().innerNonSharedNode(); if (!node) return; Frame* frame = node->document()->frame(); if (!frame) return; FrameView* view = frame->view(); if (!view) return; // Give the bundle client a chance to process the menu. #if USE(CROSS_PLATFORM_CONTEXT_MENUS) const Vector<ContextMenuItem>& coreItems = menu->items(); #else Vector<ContextMenuItem> coreItems = contextMenuItemVector(menu->platformDescription()); #endif Vector<WebContextMenuItemData> proposedMenu = kitItems(coreItems, menu); Vector<WebContextMenuItemData> newMenu; RefPtr<APIObject> userData; RefPtr<InjectedBundleHitTestResult> hitTestResult = InjectedBundleHitTestResult::create(controller->hitTestResult()); if (m_page->injectedBundleContextMenuClient().getCustomMenuFromDefaultItems(m_page, hitTestResult.get(), proposedMenu, newMenu, userData)) proposedMenu = newMenu; ContextMenuState contextMenuState; contextMenuState.absoluteImageURLString = controller->hitTestResult().absoluteImageURL().string(); contextMenuState.absoluteLinkURLString = controller->hitTestResult().absoluteLinkURL().string(); // Notify the UIProcess. m_page->send(Messages::WebPageProxy::ShowContextMenu(view->contentsToWindow(controller->hitTestResult().point()), contextMenuState, proposedMenu, InjectedBundleUserMessageEncoder(userData.get()))); }
static void populateContextMenuItems(v8::Local<v8::Array>& itemArray, ContextMenu& menu) { for (size_t i = 0; i < itemArray->Length(); ++i) { v8::Local<v8::Object> item = v8::Local<v8::Object>::Cast(itemArray->Get(i)); v8::Local<v8::Value> type = item->Get(v8::String::New("type")); v8::Local<v8::Value> id = item->Get(v8::String::New("id")); v8::Local<v8::Value> label = item->Get(v8::String::New("label")); v8::Local<v8::Value> enabled = item->Get(v8::String::New("enabled")); v8::Local<v8::Value> checked = item->Get(v8::String::New("checked")); v8::Local<v8::Value> subItems = item->Get(v8::String::New("subItems")); if (!type->IsString()) continue; String typeString = toWebCoreStringWithNullCheck(type); if (typeString == "separator") { ContextMenuItem item(ContextMenuItem(SeparatorType, ContextMenuItemCustomTagNoAction, String())); menu.appendItem(item); } else if (typeString == "subMenu" && subItems->IsArray()) { ContextMenu subMenu; v8::Local<v8::Array> subItemsArray = v8::Local<v8::Array>::Cast(subItems); populateContextMenuItems(subItemsArray, subMenu); ContextMenuItem item(SubmenuType, ContextMenuItemCustomTagNoAction, toWebCoreStringWithNullCheck(label), &subMenu); menu.appendItem(item); } else { ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id->ToInt32()->Value()); ContextMenuItem menuItem((typeString == "checkbox" ? CheckableActionType : ActionType), typedId, toWebCoreStringWithNullCheck(label)); if (checked->IsBoolean()) menuItem.setChecked(checked->ToBoolean()->Value()); if (enabled->IsBoolean()) menuItem.setEnabled(enabled->ToBoolean()->Value()); menu.appendItem(menuItem); } } }
v8::Handle<v8::Value> V8InspectorFrontendHost::showContextMenuMethodCustom(const v8::Arguments& args) { if (args.Length() < 2) return v8::Undefined(); v8::Local<v8::Object> eventWrapper = v8::Local<v8::Object>::Cast(args[0]); if (!V8MouseEvent::info.equals(toWrapperTypeInfo(eventWrapper))) return v8::Undefined(); Event* event = V8Event::toNative(eventWrapper); if (!args[1]->IsArray()) return v8::Undefined(); v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(args[1]); ContextMenu menu; populateContextMenuItems(array, menu); InspectorFrontendHost* frontendHost = V8InspectorFrontendHost::toNative(args.Holder()); Vector<ContextMenuItem> items = menu.items(); frontendHost->showContextMenu(event, items); return v8::Undefined(); }
void MenuPanel::onLoseFocus(const EventArgs& args) { if(mDesc->menupanel_owner != NULL) { Ogre::String ownerClass = mDesc->menupanel_owner->getClass(); if(ownerClass == "Menu") { ToolBar* tb = dynamic_cast<Menu*>(mDesc->menupanel_owner)->getToolBar(); if(tb != NULL) { if(mDesc->guiManager->getLastClickedWidget() == NULL) tb->closeMenus(); else if(!mDesc->guiManager->getLastClickedWidget()->isComponentOf(tb) && !mDesc->guiManager->getLastClickedWidget()->isChildOf(tb)) tb->closeMenus(); } else { ContextMenu* cm = dynamic_cast<Menu*>(mDesc->menupanel_owner)->getContextMenu(); if((cm != NULL) && (cm->findWidget(mDesc->sheet->getWindowInFocus()->getName()) == NULL)) cm->hide(); } } else if(ownerClass == "ComboBox") { ComboBox* cb = dynamic_cast<ComboBox*>(mDesc->menupanel_owner); // If we click a widget other than the combobox, hide the list. // If we did click the combobox, the combobox will hide the list automatically. if(mDesc->guiManager->getLastClickedWidget() == NULL) cb->hideDropDownList(); else if(!mDesc->guiManager->getLastClickedWidget()->isComponentOf(cb)) cb->hideDropDownList(); } } }
TopMenu::TopMenu(Widget* parent, const int height , bool useIcon) : MainMenu( parent, Rect( 0, 0, parent->width(), height ) ), _d( new Impl ) { setupUI( ":/gui/topmenu.gui" ); setGeometry( Rect( 0, 0, parent->width(), height ) ); _d->initBackground( size() ); _d->useIcon = useIcon; GET_DWIDGET_FROM_UI( _d, lbPopulation ) GET_DWIDGET_FROM_UI( _d, lbFunds ) GET_DWIDGET_FROM_UI( _d, lbDate ) if( _d->lbPopulation ) { _d->lbPopulation->setPosition( Point( width() - populationLabelOffset, 0 ) ); _d->lbPopulation->setIcon( useIcon ? Picture( "population", 1 ) : Picture() ); } if( _d->lbFunds ) { _d->lbFunds->setPosition( Point( width() - fundLabelOffset, 0) ); _d->lbFunds->setIcon( useIcon ? Picture( "paneling", 332 ) : Picture() ); } if( _d->lbDate ) _d->lbDate->setPosition( Point( width() - dateLabelOffset, 0) ); ContextMenuItem* tmp = addItem( _("##gmenu_file##"), -1, true, true, false, false ); ContextMenu* file = tmp->addSubMenu(); ContextMenuItem* restart = file->addItem( _("##gmenu_file_restart##"), -1, true, false, false, false ); ContextMenuItem* load = file->addItem( _("##mainmenu_loadgame##"), -1, true, false, false, false ); ContextMenuItem* save = file->addItem( _("##gmenu_file_save##"), -1, true, false, false, false ); ContextMenuItem* mainMenu = file->addItem( _("##gmenu_file_mainmenu##"), -1, true, false, false, false ); ContextMenuItem* exit = file->addItem( _("##gmenu_exit_game##"), -1, true, false, false, false ); CONNECT( restart, onClicked(), &_d->onRestartSignal, Signal0<>::_emit ); CONNECT( exit, onClicked(), &_d->onExitSignal, Signal0<>::_emit ); CONNECT( save, onClicked(), &_d->onSaveSignal, Signal0<>::_emit ); CONNECT( load, onClicked(), &_d->onLoadSignal, Signal0<>::_emit ); CONNECT( mainMenu, onClicked(), &_d->onEndSignal, Signal0<>::_emit ); tmp = addItem( _("##gmenu_options##"), -1, true, true, false, false ); ContextMenu* options = tmp->addSubMenu(); ContextMenuItem* screen = options->addItem( _("##screen_settings##"), -1, true, false, false, false ); ContextMenuItem* sound = options->addItem( _("##sound_settings##"), -1, true, false, false, false ); ContextMenuItem* speed = options->addItem( _("##speed_settings##"), -1, true, false, false, false ); ContextMenuItem* cityopts = options->addItem( _("##city_settings##"), -1, true, false, false, false ); CONNECT( screen, onClicked(), &_d->onShowVideoOptionsSignal, Signal0<>::_emit ); CONNECT( speed, onClicked(), &_d->onShowGameSpeedOptionsSignal, Signal0<>::_emit ); CONNECT( sound, onClicked(), &_d->onShowSoundOptionsSignal, Signal0<>::_emit ); CONNECT( cityopts, onClicked(), &_d->onShowCityOptionsSignal, Signal0<>::_emit ); tmp = addItem( _("##gmenu_help##"), -1, true, true, false, false ); ContextMenu* helpMenu = tmp->addSubMenu(); ContextMenuItem* aboutItem = helpMenu->addItem( _("##gmenu_about##"), -1 ); ContextMenuItem* shortkeysItem = helpMenu->addItem( _("##gmenu_shortkeys##"), -1 ); CONNECT( aboutItem, onClicked(), _d.data(), Impl::showAboutInfo ); CONNECT( shortkeysItem, onClicked(), _d.data(), Impl::showShortKeyInfo ); tmp = addItem( _("##gmenu_advisors##"), -1, true, true, false, false ); ContextMenu* advisersMenu = tmp->addSubMenu(); advisersMenu->addItem( _("##visit_labor_advisor##"), advisor::employers ); advisersMenu->addItem( _("##visit_military_advisor##" ), advisor::military ); advisersMenu->addItem( _("##visit_imperial_advisor##" ), advisor::empire ); advisersMenu->addItem( _("##visit_rating_advisor##" ), advisor::ratings ); advisersMenu->addItem( _("##visit_trade_advisor##" ), advisor::trading ); advisersMenu->addItem( _("##visit_population_advisor##" ), advisor::population ); advisersMenu->addItem( _("##visit_health_advisor##" ), advisor::health ); advisersMenu->addItem( _("##visit_education_advisor##" ), advisor::education ); advisersMenu->addItem( _("##visit_religion_advisor##" ), advisor::religion ); advisersMenu->addItem( _("##visit_entertainment_advisor##"), advisor::entertainment ); advisersMenu->addItem( _("##visit_financial_advisor##" ), advisor::finance ); advisersMenu->addItem( _("##visit_chief_advisor##" ), advisor::main ); CONNECT( advisersMenu, onItemAction(), _d.data(), Impl::resolveAdvisorShow ); _d->updateDate(); }
void BuddyListContact::openContextMenu() { ContextMenu *w = new ContactContextMenu(*this); w->show(); }
void PlotSetImp::updateContextMenu(Subject& subject, const string& signal, const boost::any& value) { ContextMenu* pMenu = boost::any_cast<ContextMenu*>(value); if (pMenu == NULL) { return; } QObject* pParent = pMenu->getActionParent(); vector<SessionItem*> items = pMenu->getSessionItems(); if (items.empty() == true) { return; } bool bAddSeparator = false; bool bAddActivate = false; bool bAddDelete = false; string afterId; vector<DockWindow*> windowItems = pMenu->getSessionItems<DockWindow>(); if (windowItems.size() == 1) { DockWindow* pDockWindow = windowItems.front(); if (pDockWindow != NULL) { PlotSetGroup* pPlotSetGroup = dynamic_cast<PlotSetGroup*>(pDockWindow->getWidget()); if (pPlotSetGroup != NULL) { if (dynamic_cast<PlotSetImp*>(pPlotSetGroup->getCurrentPlotSet()) == this) { bAddSeparator = true; bAddDelete = true; } } } } else if (dynamic_cast<SessionExplorer*>(&subject) != NULL) { // Make sure all of the selected session items for the menu are plot widgets vector<PlotWidget*> plots = pMenu->getSessionItems<PlotWidget>(); if (plots.size() != items.size()) { return; } // Make sure all selected plot widget items are contained in this plot set vector<PlotWidget*>::iterator iter; for (iter = plots.begin(); iter != plots.end(); ++iter) { PlotWidget* pPlot = *iter; if (pPlot != NULL) { if (containsPlot(pPlot) == false) { return; } } } // Check for only one selected plot widget item if (plots.size() == 1) { bAddSeparator = true; // Add an activate action if the selected plot widget is not currently active PlotWidget* pPlot = plots.front(); if (pPlot != NULL) { if (pPlot != getCurrentPlot()) { bAddActivate = true; } } } bAddDelete = true; afterId = APP_PLOTWIDGET_PRINT_ACTION; } // Separator if (bAddSeparator == true) { QAction* pSeparatorAction = new QAction(pParent); pSeparatorAction->setSeparator(true); pMenu->addActionAfter(pSeparatorAction, APP_PLOTSET_SEPARATOR_ACTION, afterId); if (afterId.empty() == false) { afterId = APP_PLOTSET_SEPARATOR_ACTION; } } // Activate if (bAddActivate == true) { QAction* pActivateAction = new QAction("&Activate", pParent); pActivateAction->setAutoRepeat(false); pActivateAction->setStatusTip("Activates the selected plot in the plot set"); VERIFYNR(connect(pActivateAction, SIGNAL(triggered()), this, SLOT(activateSelectedPlot()))); pMenu->addActionAfter(pActivateAction, APP_PLOTSET_ACTIVATE_ACTION, afterId); if (afterId.empty() == false) { afterId = APP_PLOTSET_ACTIVATE_ACTION; } } // Delete if (bAddDelete == true) { QAction* pDeleteAction = new QAction(QIcon(":/icons/Delete"), "&Delete", pParent); pDeleteAction->setAutoRepeat(false); VERIFYNR(connect(pDeleteAction, SIGNAL(triggered()), this, SLOT(destroyCurrentPlot()))); pMenu->addActionAfter(pDeleteAction, APP_PLOTSET_DELETE_ACTION, afterId); } }
void BuddyListBuddy::openContextMenu() { ContextMenu *w = new BuddyContextMenu(*this); w->show(); }
void SpectralLibraryMatchResults::updateContextMenu(Subject& subject, const std::string& signal, const boost::any& value) { ContextMenu* pMenu = boost::any_cast<ContextMenu*>(value); if (pMenu == NULL) { return; } // only add actions if there are some results if (mpTabWidget->count() > 0) { bool isSessionItem(false); if (dynamic_cast<SessionExplorer*>(&subject) != NULL) { std::vector<SessionItem*> items = pMenu->getSessionItems(); if (items.size() > 1) // make sure only one item selected { return; } DockWindow* pWindow = getDockWindow(); if (items.front() != pWindow) // make sure it's the results window { return; } isSessionItem = true; } QObject* pParent = pMenu->getActionParent(); // add separator QAction* pSeparatorAction = new QAction(pParent); pSeparatorAction->setSeparator(true); pMenu->addAction(pSeparatorAction, SPECTRAL_LIBRARY_MATCH_RESULTS_SEPARATOR_ACTION); QAction* pClearAction = new QAction("&Clear", pParent); pClearAction->setAutoRepeat(false); pClearAction->setStatusTip("Clears the results from the current page"); VERIFYNR(connect(pClearAction, SIGNAL(triggered()), this, SLOT(clearPage()))); pMenu->addAction(pClearAction, SPECTRAL_LIBRARY_MATCH_RESULTS_CLEAR_RESULTS_ACTION); QAction* pAutoClearAction = new QAction("&AutoClear", pParent); pAutoClearAction->setAutoRepeat(false); pAutoClearAction->setCheckable(true); pAutoClearAction->setStatusTip("Enable/disable clearing existing results before adding new results"); ResultsPage* pPage = dynamic_cast<ResultsPage*>(mpTabWidget->currentWidget()); if (pPage != NULL) { pAutoClearAction->setChecked(pPage->getAutoClear()); VERIFYNR(connect(pAutoClearAction, SIGNAL(toggled(bool)), pPage, SLOT(setAutoClear(bool)))); pMenu->addAction(pAutoClearAction, SPECTRAL_LIBRARY_MATCH_RESULTS_AUTOCLEAR_ACTION); } QAction* pExpandAllAction = new QAction("&Expand All", pParent); pExpandAllAction->setAutoRepeat(false); pExpandAllAction->setStatusTip("Expands all the results nodes on the current page"); VERIFYNR(connect(pExpandAllAction, SIGNAL(triggered()), this, SLOT(expandAllPage()))); pMenu->addAction(pExpandAllAction, SPECTRAL_LIBRARY_MATCH_RESULTS_EXPAND_ALL_ACTION); QAction* pCollapseAllAction = new QAction("&Collapse All", pParent); pCollapseAllAction->setAutoRepeat(false); pCollapseAllAction->setStatusTip("Collapses all the results nodes on the current page"); VERIFYNR(connect(pCollapseAllAction, SIGNAL(triggered()), this, SLOT(collapseAllPage()))); pMenu->addAction(pCollapseAllAction, SPECTRAL_LIBRARY_MATCH_RESULTS_COLLAPSE_ALL_ACTION); QAction* pDeleteTabAction = new QAction("&Delete Page", pParent); pDeleteTabAction->setAutoRepeat(false); pDeleteTabAction->setStatusTip("Deletes the current page"); VERIFYNR(connect(pDeleteTabAction, SIGNAL(triggered()), this, SLOT(deletePage()))); pMenu->addAction(pDeleteTabAction, SPECTRAL_LIBRARY_MATCH_RESULTS_DELETE_PAGE_ACTION); if (isSessionItem == false) { QAction* pLocateAction = new QAction("&Locate Signatures", pParent); pLocateAction->setAutoRepeat(false); pLocateAction->setStatusTip("Locates the selected Signatures in the spatial data view"); VERIFYNR(connect(pLocateAction, SIGNAL(triggered()), this, SLOT(locateSignaturesInScene()))); pMenu->addAction(pLocateAction, SPECTRAL_LIBRARY_MATCH_RESULTS_LOCATE_ACTION); QAction* pCreateAverageAction = new QAction("&Create average Signature", pParent); pCreateAverageAction->setAutoRepeat(false); pCreateAverageAction->setStatusTip("Creates an average Signature from the selected " "Signatures in the spatial data view"); VERIFYNR(connect(pCreateAverageAction, SIGNAL(triggered()), this, SLOT(createAverageSignature()))); pMenu->addAction(pCreateAverageAction, SPECTRAL_LIBRARY_MATCH_RESULTS_CREATE_AVERAGE_ACTION); } } }
void HistogramWindowImp::updateContextMenu(Subject& subject, const string& signal, const boost::any& value) { ContextMenu* pMenu = boost::any_cast<ContextMenu*>(value); if (pMenu == NULL) { return; } bool bAddActions = false; bool bRemoveActions = false; PlotWidget* pActionWidget = NULL; if (dynamic_cast<SessionExplorer*>(&subject) != NULL) { // Make sure all of the selected session items for the menu are plot widgets vector<SessionItem*> items = pMenu->getSessionItems(); vector<PlotWidget*> plots = pMenu->getSessionItems<PlotWidget>(); if (plots.size() != items.size()) { return; } // Make sure all selected plot widget items are contained in this plot set vector<PlotWidget*>::iterator iter; for (iter = plots.begin(); iter != plots.end(); ++iter) { PlotWidget* pPlot = *iter; if (pPlot != NULL) { if (mpPlotSetGroup->containsPlot(pPlot) == true) { if (plots.size() == 1) { bAddActions = true; pActionWidget = pPlot; } HistogramPlotImp* pHistogramPlot = dynamic_cast<HistogramPlotImp*>(pPlot->getPlot()); if (pHistogramPlot != NULL) { if (pHistogramPlot->getLayer() != NULL) { bRemoveActions = true; } } } else { return; } } } } else if (dynamic_cast<HistogramWindowImp*>(&subject) == this) { if (mpPlotSetGroup->getNumPlotSets() > 0) { bRemoveActions = true; } } else { PlotWidget* pPlotWidget = dynamic_cast<PlotWidget*>(&subject); if ((pPlotWidget != NULL) && (mpPlotSetGroup->containsPlot(pPlotWidget) == true)) { bAddActions = true; pActionWidget = pPlotWidget; } } // Add the sync zoom action if ((bAddActions == true) && (pActionWidget != NULL)) { HistogramPlotImp* pHistogramPlot = dynamic_cast<HistogramPlotImp*>(pActionWidget->getPlot()); if (pHistogramPlot != NULL) { RasterLayer* pLayer = dynamic_cast<RasterLayer*>(pHistogramPlot->getLayer()); if ((pLayer != NULL) && (pHistogramPlot->getRasterChannelType() != GRAY)) { mpSyncAutoZoomAction->setData(QVariant::fromValue(dynamic_cast<SessionItem*>(pHistogramPlot))); pMenu->addActionBefore(mpSyncAutoZoomAction, APP_HISTOGRAMPLOT_SYNCHRONIZE_AUTO_ZOOM_ACTION, APP_HISTOGRAMPLOT_RASTER_MENUS_SEPARATOR_ACTION); } } } // Remove the delete action if (bRemoveActions == true) { pMenu->removeAction(APP_PLOTSET_DELETE_ACTION); } // Add statistics actions if (bAddActions) { pMenu->addActionBefore(mpStatisticsShowAction, APP_HISTOGRAMPLOT_STATISTICS_ACTION, APP_HISTOGRAMPLOT_REFRESH_STATISTICS_ACTION); } }
void BuddyListGroup::openContextMenu() { ContextMenu *w = new GroupContextMenu(*this); w->show(); }