WebCore:
[WebKit-https.git] / WebCore / platform / ContextMenu.cpp
index 249240d6448a1b5f9f6506891ba925180b21fef7..89f5b4a5b4a6289c31afdff04d6acde991fb4f27 100644 (file)
@@ -49,6 +49,86 @@ ContextMenuController* ContextMenu::controller() const
     return 0;
 }
 
+static void createFontSubMenu(const HitTestResult& result, ContextMenuItem& fontMenuItem)
+{
+    static ContextMenuItem SeparatorItem(SeparatorType, ContextMenuItemTagNoAction, String());
+
+    MENU_ACTION_ITEM(ShowFonts, "Show Fonts");
+    MENU_ACTION_ITEM(Bold, "Bold");
+    MENU_ACTION_ITEM(Italic, "Italic");
+    MENU_ACTION_ITEM(Underline, "Underline");
+    MENU_ACTION_ITEM(Outline, "Outline");
+    MENU_ACTION_ITEM(Styles, "Styles...");
+    MENU_ACTION_ITEM(ShowColors, "Show Colors");
+    
+    ContextMenu* fontMenu = new ContextMenu(result);
+    fontMenu->appendItem(ShowFontsItem);
+    fontMenu->appendItem(BoldItem);
+    fontMenu->appendItem(ItalicItem);
+    fontMenu->appendItem(UnderlineItem);
+    fontMenu->appendItem(OutlineItem);
+    fontMenu->appendItem(StylesItem);
+    fontMenu->appendItem(SeparatorItem);
+    fontMenu->appendItem(ShowColorsItem);
+    fontMenuItem.setSubMenu(fontMenu);
+}
+
+#ifndef BUILDING_ON_TIGER
+static void createSpellingAndGrammarSubMenu(const HitTestResult& result, ContextMenuItem& spellingAndGrammarMenuItem)
+{
+    MENU_ACTION_ITEM(ShowSpellingAndGrammar, "Show Spelling and Grammar");
+    MENU_ACTION_ITEM(CheckDocumentNow, "Check Document Now");
+    MENU_ACTION_ITEM(CheckSpellingWhileTyping, "Check Spelling While Typing");
+    MENU_ACTION_ITEM(CheckGrammarWithSpelling, "Check Grammar With Spelling");
+
+    ContextMenu* spellingAndGrammarMenu = new ContextMenu(result);
+    spellingAndGrammarMenu->appendItem(ShowSpellingAndGrammarItem);
+    spellingAndGrammarMenu->appendItem(CheckDocumentNowItem);
+    spellingAndGrammarMenu->appendItem(CheckSpellingWhileTypingItem);
+    spellingAndGrammarMenu->appendItem(CheckGrammarWithSpellingItem);
+    spellingAndGrammarMenuItem.setSubMenu(spellingAndGrammarMenu);
+}
+#else
+static void createSpellingSubMenu(const HitTestResult& result, ContextMenuItem& spellingMenuItem)
+{
+    MENU_ACTION_ITEM(SpellingMenuItem, "Spelling...");
+    MENU_ACTION_ITEM(CheckSpelling, "Check Spelling");
+    MENU_ACTION_ITEM(CheckSpellingWhileTyping, "Check Spelling as You Type");
+
+    ContextMenu* spellingMenu = new ContextMenu(result);
+    spellingMenu->appendItem(SpellingMenuItemItem);
+    spellingMenu->appendItem(CheckSpellingItem);
+    spellingMenu->appendItem(CheckSpellingWhileTypingItem);
+    spellingMenuItem.setSubMenu(spellingMenu);
+}
+#endif
+
+#if PLATFORM(MAC)
+static void createSpeechSubMenu(const HitTestResult& result, ContextMenuItem& speechMenuItem)
+{
+    MENU_ACTION_ITEM(StartSpeaking, "Start Speaking");
+    MENU_ACTION_ITEM(StopSpeaking, "Stop Speaking");
+
+    ContextMenu* speechMenu = new ContextMenu(result);
+    speechMenu->appendItem(StartSpeakingItem);
+    speechMenu->appendItem(StopSpeakingItem);
+    speechMenuItem.setSubMenu(speechMenu);
+}
+#endif
+
+static void createWritingDirectionSubMenu(const HitTestResult& result, ContextMenuItem& writingDirectionMenuItem)
+{
+    MENU_ACTION_ITEM(DefaultDirection, "Default");
+    MENU_ACTION_ITEM(LeftToRight, "Left to Right");
+    MENU_ACTION_ITEM(RightToLeft, "Right to Left");
+
+    ContextMenu* writingDirectionMenu = new ContextMenu(result);
+    writingDirectionMenu->appendItem(DefaultDirectionItem);
+    writingDirectionMenu->appendItem(LeftToRightItem);
+    writingDirectionMenu->appendItem(RightToLeftItem);
+    writingDirectionMenuItem.setSubMenu(writingDirectionMenu);
+}
+
 void ContextMenu::populate()
 {
     static ContextMenuItem SeparatorItem(SeparatorType, ContextMenuItemTagNoAction, String());
@@ -76,7 +156,7 @@ void ContextMenu::populate()
 #endif
     MENU_ACTION_ITEM(SearchWeb, "Search in Google");
     MENU_ACTION_ITEM(LookUpInDictionary, "Look Up in Dictionary");
-    // FIXME: Add PDF action items
+    MENU_ACTION_ITEM(OpenLink, "Open Link");
 
     HitTestResult result = hitTestResult();
     
@@ -92,6 +172,7 @@ void ContextMenu::populate()
         KURL linkURL = result.absoluteLinkURL();
         if (!linkURL.isEmpty()) {
             if (loader->canHandleRequest(ResourceRequest(linkURL))) {
+                appendItem(OpenLinkItem);
                 appendItem(OpenLinkInNewWindowItem);
                 appendItem(DownloadLinkToDiskItem);
             }
@@ -171,12 +252,36 @@ void ContextMenu::populate()
             appendItem(LookUpInDictionaryItem);
             appendItem(SeparatorItem);
         }
-        
+
         appendItem(CutItem);
         appendItem(CopyItem);
         appendItem(PasteItem);
 
-        // FIXME: Add a separator, then "Spelling [and Grammar, on Leopard]", "Font", "Speech", "Writing Direction" submenus here.
+        if (!inPasswordField) {
+            appendItem(SeparatorItem);
+#ifndef BUILDING_ON_TIGER
+            ContextMenuItem SpellingAndGrammarMenuItem(SubmenuType, ContextMenuItemTagSpellingAndGrammarMenu,
+                "Spelling and Grammar");
+            createSpellingAndGrammarSubMenu(m_hitTestResult, SpellingAndGrammarMenuItem);
+            appendItem(SpellingAndGrammarMenuItem);
+#else
+            ContextMenuItem SpellingMenuItem(SubmenuType, ContextMenuItemTagSpellingMenu, "Spelling");
+            createSpellingSubMenu(m_hitTestResult, SpellingMenuItem);
+            appendItem(SpellingMenuItem);
+#endif
+            ContextMenuItem FontMenuItem(SubmenuType, ContextMenuItemTagFontMenu, "Font");
+            createFontSubMenu(m_hitTestResult, FontMenuItem);
+            appendItem(FontMenuItem);
+#if PLATFORM(MAC)
+            ContextMenuItem SpeechMenuItem(SubmenuType, ContextMenuItemTagSpeechMenu, "Speech");
+            createSpeechSubMenu(m_hitTestResult, SpeechMenuItem);
+            appendItem(SpeechMenuItem);
+#endif
+            ContextMenuItem WritingDirectionMenuItem(SubmenuType, ContextMenuItemTagWritingDirectionMenu,
+                "Writing Direction");
+            createWritingDirectionSubMenu(m_hitTestResult, WritingDirectionMenuItem);
+            appendItem(WritingDirectionMenuItem);
+        }
     }
 }