void ContextMenuClientImpl::populateCustomMenuItems(WebCore::ContextMenu* defaultMenu, WebContextMenuData* data) { Vector<WebMenuItemInfo> customItems; for (size_t i = 0; i < defaultMenu->itemCount(); ++i) { ContextMenuItem* inputItem = defaultMenu->itemAtIndex(i, defaultMenu->platformDescription()); if (inputItem->action() < ContextMenuItemBaseCustomTag || inputItem->action() > ContextMenuItemLastCustomTag) continue; WebMenuItemInfo outputItem; outputItem.label = inputItem->title(); outputItem.enabled = inputItem->enabled(); outputItem.checked = inputItem->checked(); outputItem.action = static_cast<unsigned>(inputItem->action() - ContextMenuItemBaseCustomTag); switch (inputItem->type()) { case ActionType: outputItem.type = WebMenuItemInfo::Option; break; case CheckableActionType: outputItem.type = WebMenuItemInfo::CheckableOption; break; case SeparatorType: outputItem.type = WebMenuItemInfo::Separator; break; case SubmenuType: outputItem.type = WebMenuItemInfo::Group; break; } customItems.append(outputItem); } WebVector<WebMenuItemInfo> outputItems(customItems.size()); for (size_t i = 0; i < customItems.size(); ++i) outputItems[i] = customItems[i]; data->customItems.swap(outputItems); }
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 WebContextMenuProxyGtk::append(ContextMenuItem& menuItem) { unsigned long signalHandlerId; GtkAction* action = menuItem.gtkAction(); if (action) { switch (menuItem.type()) { case ActionType: case CheckableActionType: g_object_set_data(G_OBJECT(action), gContextMenuActionId, GINT_TO_POINTER(menuItem.action())); signalHandlerId = g_signal_connect(action, "activate", G_CALLBACK(contextMenuItemActivatedCallback), m_page); m_signalHandlers.set(signalHandlerId, action); // Fall through. case SubmenuType: signalHandlerId = g_signal_connect(action, "notify::visible", G_CALLBACK(contextMenuItemVisibilityChanged), this); m_signalHandlers.set(signalHandlerId, action); break; case SeparatorType: break; } } m_menu.appendItem(menuItem); }
void ContextMenu::checkOrEnableIfNeeded(ContextMenuItem& item) const { if (item.type() == SeparatorType) return; Frame* frame = m_hitTestResult.innerNonSharedNode()->document()->frame(); if (!frame) return; bool shouldEnable = true; bool shouldCheck = false; switch (item.action()) { case ContextMenuItemTagCheckSpelling: shouldEnable = frame->editor()->canEdit(); break; case ContextMenuItemTagDefaultDirection: shouldCheck = false; shouldEnable = false; break; case ContextMenuItemTagLeftToRight: case ContextMenuItemTagRightToLeft: { ExceptionCode ec = 0; RefPtr<CSSStyleDeclaration> style = frame->document()->createCSSStyleDeclaration(); String direction = item.action() == ContextMenuItemTagLeftToRight ? "ltr" : "rtl"; style->setProperty(CSSPropertyDirection, direction, false, ec); shouldCheck = frame->editor()->selectionHasStyle(style.get()) != FalseTriState; shouldEnable = true; break; } case ContextMenuItemTagTextDirectionDefault: { Editor::Command command = frame->editor()->command("MakeTextWritingDirectionNatural"); shouldCheck = command.state() == TrueTriState; shouldEnable = command.isEnabled(); break; } case ContextMenuItemTagTextDirectionLeftToRight: { Editor::Command command = frame->editor()->command("MakeTextWritingDirectionLeftToRight"); shouldCheck = command.state() == TrueTriState; shouldEnable = command.isEnabled(); break; } case ContextMenuItemTagTextDirectionRightToLeft: { Editor::Command command = frame->editor()->command("MakeTextWritingDirectionRightToLeft"); shouldCheck = command.state() == TrueTriState; shouldEnable = command.isEnabled(); break; } case ContextMenuItemTagCopy: shouldEnable = frame->editor()->canDHTMLCopy() || frame->editor()->canCopy(); break; case ContextMenuItemTagCut: shouldEnable = frame->editor()->canDHTMLCut() || frame->editor()->canCut(); break; case ContextMenuItemTagIgnoreSpelling: case ContextMenuItemTagLearnSpelling: shouldEnable = frame->selection()->isRange(); break; case ContextMenuItemTagPaste: shouldEnable = frame->editor()->canDHTMLPaste() || frame->editor()->canPaste(); break; #if PLATFORM(GTK) case ContextMenuItemTagDelete: shouldEnable = frame->editor()->canDelete(); break; case ContextMenuItemTagSelectAll: case ContextMenuItemTagInputMethods: case ContextMenuItemTagUnicode: shouldEnable = true; break; #endif case ContextMenuItemTagUnderline: { ExceptionCode ec = 0; RefPtr<CSSStyleDeclaration> style = frame->document()->createCSSStyleDeclaration(); style->setProperty(CSSPropertyWebkitTextDecorationsInEffect, "underline", false, ec); shouldCheck = frame->editor()->selectionHasStyle(style.get()) != FalseTriState; shouldEnable = frame->editor()->canEditRichly(); break; } case ContextMenuItemTagLookUpInDictionary: shouldEnable = frame->selection()->isRange(); break; case ContextMenuItemTagCheckGrammarWithSpelling: #ifndef BUILDING_ON_TIGER if (frame->editor()->isGrammarCheckingEnabled()) shouldCheck = true; shouldEnable = true; #endif break; case ContextMenuItemTagItalic: { ExceptionCode ec = 0; RefPtr<CSSStyleDeclaration> style = frame->document()->createCSSStyleDeclaration(); style->setProperty(CSSPropertyFontStyle, "italic", false, ec); shouldCheck = frame->editor()->selectionHasStyle(style.get()) != FalseTriState; shouldEnable = frame->editor()->canEditRichly(); break; } case ContextMenuItemTagBold: { ExceptionCode ec = 0; RefPtr<CSSStyleDeclaration> style = frame->document()->createCSSStyleDeclaration(); style->setProperty(CSSPropertyFontWeight, "bold", false, ec); shouldCheck = frame->editor()->selectionHasStyle(style.get()) != FalseTriState; shouldEnable = frame->editor()->canEditRichly(); break; } case ContextMenuItemTagOutline: shouldEnable = false; break; case ContextMenuItemTagShowSpellingPanel: #ifndef BUILDING_ON_TIGER if (frame->editor()->spellingPanelIsShowing()) item.setTitle(contextMenuItemTagShowSpellingPanel(false)); else item.setTitle(contextMenuItemTagShowSpellingPanel(true)); #endif shouldEnable = frame->editor()->canEdit(); break; case ContextMenuItemTagNoGuessesFound: shouldEnable = false; break; case ContextMenuItemTagCheckSpellingWhileTyping: shouldCheck = frame->editor()->isContinuousSpellCheckingEnabled(); break; #if PLATFORM(GTK) case ContextMenuItemTagGoBack: shouldEnable = frame->loader()->canGoBackOrForward(-1); break; case ContextMenuItemTagGoForward: shouldEnable = frame->loader()->canGoBackOrForward(1); break; case ContextMenuItemTagStop: shouldEnable = frame->loader()->documentLoader()->isLoadingInAPISense(); break; case ContextMenuItemTagReload: shouldEnable = !frame->loader()->documentLoader()->isLoadingInAPISense(); break; case ContextMenuItemTagFontMenu: shouldEnable = frame->editor()->canEditRichly(); break; #else case ContextMenuItemTagGoBack: case ContextMenuItemTagGoForward: case ContextMenuItemTagStop: case ContextMenuItemTagReload: case ContextMenuItemTagFontMenu: #endif case ContextMenuItemTagNoAction: case ContextMenuItemTagOpenLinkInNewWindow: case ContextMenuItemTagDownloadLinkToDisk: case ContextMenuItemTagCopyLinkToClipboard: case ContextMenuItemTagOpenImageInNewWindow: case ContextMenuItemTagDownloadImageToDisk: case ContextMenuItemTagCopyImageToClipboard: case ContextMenuItemTagOpenFrameInNewWindow: case ContextMenuItemTagSpellingGuess: case ContextMenuItemTagOther: case ContextMenuItemTagSearchInSpotlight: case ContextMenuItemTagSearchWeb: case ContextMenuItemTagOpenWithDefaultApplication: case ContextMenuItemPDFActualSize: case ContextMenuItemPDFZoomIn: case ContextMenuItemPDFZoomOut: case ContextMenuItemPDFAutoSize: case ContextMenuItemPDFSinglePage: case ContextMenuItemPDFFacingPages: case ContextMenuItemPDFContinuous: case ContextMenuItemPDFNextPage: case ContextMenuItemPDFPreviousPage: case ContextMenuItemTagOpenLink: case ContextMenuItemTagIgnoreGrammar: case ContextMenuItemTagSpellingMenu: case ContextMenuItemTagShowFonts: case ContextMenuItemTagStyles: case ContextMenuItemTagShowColors: case ContextMenuItemTagSpeechMenu: case ContextMenuItemTagStartSpeaking: case ContextMenuItemTagStopSpeaking: case ContextMenuItemTagWritingDirectionMenu: case ContextMenuItemTagTextDirectionMenu: case ContextMenuItemTagPDFSinglePageScrolling: case ContextMenuItemTagPDFFacingPagesScrolling: case ContextMenuItemTagInspectElement: case ContextMenuItemBaseApplicationTag: break; } item.setChecked(shouldCheck); item.setEnabled(shouldEnable); }