Added context menu for input field
[framework/web/webkit-efl.git] / Source / WebCore / page / ContextMenuController.cpp
1 /*
2  * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3  * Copyright (C) 2010 Igalia S.L
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
25  */
26
27 #include "config.h"
28 #include "ContextMenuController.h"
29
30 #if ENABLE(CONTEXT_MENUS)
31
32 #include "BackForwardController.h"
33 #include "Chrome.h"
34 #include "ContextMenu.h"
35 #include "ContextMenuClient.h"
36 #include "ContextMenuItem.h"
37 #include "ContextMenuProvider.h"
38 #include "Document.h"
39 #include "DocumentFragment.h"
40 #include "DocumentLoader.h"
41 #include "Editor.h"
42 #include "EditorClient.h"
43 #include "Event.h"
44 #include "EventHandler.h"
45 #include "EventNames.h"
46 #include "FormState.h"
47 #include "Frame.h"
48 #include "FrameLoadRequest.h"
49 #include "FrameLoader.h"
50 #include "FrameLoaderClient.h"
51 #include "FrameSelection.h"
52 #include "HTMLFormElement.h"
53 #include "HitTestRequest.h"
54 #include "HitTestResult.h"
55 #include "InspectorController.h"
56 #include "LocalizedStrings.h"
57 #include "MouseEvent.h"
58 #include "NavigationAction.h"
59 #include "Node.h"
60 #include "Page.h"
61 #include "PlatformEvent.h"
62 #include "RenderObject.h"
63 #include "ReplaceSelectionCommand.h"
64 #include "ResourceRequest.h"
65 #include "Settings.h"
66 #include "TextIterator.h"
67 #include "TypingCommand.h"
68 #include "UserTypingGestureIndicator.h"
69 #include "WindowFeatures.h"
70 #include "markup.h"
71 #include <wtf/unicode/Unicode.h>
72 #if ENABLE(TIZEN_DRAG_SUPPORT)
73 #include "DragController.h"
74 #endif
75
76 #if PLATFORM(GTK)
77 #include <wtf/gobject/GOwnPtr.h>
78 #endif
79
80 #if ENABLE(TIZEN_PASTEBOARD)
81 #include "Pasteboard.h"
82 #endif
83
84 using namespace WTF;
85 using namespace Unicode;
86
87 namespace WebCore {
88
89 ContextMenuController::ContextMenuController(Page* page, ContextMenuClient* client)
90     : m_page(page)
91     , m_client(client)
92 {
93     ASSERT_ARG(page, page);
94     ASSERT_ARG(client, client);
95 }
96
97 ContextMenuController::~ContextMenuController()
98 {
99     m_client->contextMenuDestroyed();
100 }
101
102 PassOwnPtr<ContextMenuController> ContextMenuController::create(Page* page, ContextMenuClient* client)
103 {
104     return adoptPtr(new ContextMenuController(page, client));
105 }
106
107 void ContextMenuController::clearContextMenu()
108 {
109     m_contextMenu.clear();
110     if (m_menuProvider)
111         m_menuProvider->contextMenuCleared();
112     m_menuProvider = 0;
113 }
114
115 void ContextMenuController::handleContextMenuEvent(Event* event)
116 {
117     m_contextMenu = createContextMenu(event);
118     if (!m_contextMenu)
119         return;
120
121     populate();
122
123     showContextMenu(event);
124 }
125
126 static PassOwnPtr<ContextMenuItem> separatorItem()
127 {
128     return adoptPtr(new ContextMenuItem(SeparatorType, ContextMenuItemTagNoAction, String()));
129 }
130
131 void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenuProvider> menuProvider)
132 {
133     m_menuProvider = menuProvider;
134
135     m_contextMenu = createContextMenu(event);
136     if (!m_contextMenu) {
137         clearContextMenu();
138         return;
139     }
140
141     m_menuProvider->populateContextMenu(m_contextMenu.get());
142     if (m_hitTestResult.isSelected()) {
143         appendItem(*separatorItem(), m_contextMenu.get());
144         populate();
145     }
146     showContextMenu(event);
147 }
148
149 PassOwnPtr<ContextMenu> ContextMenuController::createContextMenu(Event* event)
150 {
151     if (!event->isMouseEvent())
152         return nullptr;
153
154     MouseEvent* mouseEvent = static_cast<MouseEvent*>(event);
155     HitTestResult result(mouseEvent->absoluteLocation());
156
157     if (Frame* frame = event->target()->toNode()->document()->frame())
158         result = frame->eventHandler()->hitTestResultAtPoint(mouseEvent->absoluteLocation(), false);
159
160     if (!result.innerNonSharedNode())
161         return nullptr;
162
163     m_hitTestResult = result;
164
165     return adoptPtr(new ContextMenu);
166 }
167
168 void ContextMenuController::showContextMenu(Event* event)
169 {
170 #if ENABLE(INSPECTOR)
171     if (m_page->inspectorController()->enabled())
172         addInspectElementItem();
173 #endif
174
175 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
176     m_contextMenu = m_client->customizeMenu(m_contextMenu.release());
177 #else
178     PlatformMenuDescription customMenu = m_client->getCustomMenuFromDefaultItems(m_contextMenu.get());
179     m_contextMenu->setPlatformDescription(customMenu);
180 #endif
181     event->setDefaultHandled();
182 }
183
184 static void openNewWindow(const KURL& urlToLoad, Frame* frame)
185 {
186     if (Page* oldPage = frame->page()) {
187         FrameLoadRequest request(frame->document()->securityOrigin(), ResourceRequest(urlToLoad, frame->loader()->outgoingReferrer()));
188         if (Page* newPage = oldPage->chrome()->createWindow(frame, request, WindowFeatures(), NavigationAction(request.resourceRequest()))) {
189             newPage->mainFrame()->loader()->loadFrameRequest(request, false, false, 0, 0, MaybeSendReferrer);
190             newPage->chrome()->show();
191         }
192     }
193 }
194
195 #if PLATFORM(GTK)
196 static void insertUnicodeCharacter(UChar character, Frame* frame)
197 {
198     String text(&character, 1);
199     if (!frame->editor()->shouldInsertText(text, frame->selection()->toNormalizedRange().get(), EditorInsertActionTyped))
200         return;
201
202     TypingCommand::insertText(frame->document(), text, 0, TypingCommand::TextCompositionNone);
203 }
204 #endif
205
206 void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
207 {
208     ASSERT(item->type() == ActionType || item->type() == CheckableActionType);
209
210     if (item->action() >= ContextMenuItemBaseApplicationTag) {
211         m_client->contextMenuItemSelected(item, m_contextMenu.get());
212         return;
213     }
214
215     if (item->action() >= ContextMenuItemBaseCustomTag) {
216         ASSERT(m_menuProvider);
217         m_menuProvider->contextMenuItemSelected(item);
218         return;
219     }
220
221     Frame* frame = m_hitTestResult.innerNonSharedNode()->document()->frame();
222     if (!frame)
223         return;
224
225 #if ENABLE(TIZEN_PASTEBOARD)
226     if (Page* page = frame->page()) {
227         if (item->action() == ContextMenuItemTagCopyLinkToClipboard
228             || item->action() == ContextMenuItemTagCopyImageToClipboard
229             || item->action() == ContextMenuItemTagCopyImageUrlToClipboard
230             || item->action() == ContextMenuItemTagCopyMediaLinkToClipboard
231             || item->action() == ContextMenuItemTagCopy
232             || item->action() == ContextMenuItemTagCut)
233             Pasteboard::generalPasteboard()->setPage(page);
234     }
235 #endif
236
237     switch (item->action()) {
238     case ContextMenuItemTagOpenLinkInNewWindow:
239         openNewWindow(m_hitTestResult.absoluteLinkURL(), frame);
240         break;
241     case ContextMenuItemTagDownloadLinkToDisk:
242         // FIXME: Some day we should be able to do this from within WebCore.
243         m_client->downloadURL(m_hitTestResult.absoluteLinkURL());
244         break;
245     case ContextMenuItemTagCopyLinkToClipboard:
246         frame->editor()->copyURL(m_hitTestResult.absoluteLinkURL(), m_hitTestResult.textContent());
247         break;
248     case ContextMenuItemTagOpenImageInNewWindow:
249         openNewWindow(m_hitTestResult.absoluteImageURL(), frame);
250         break;
251     case ContextMenuItemTagDownloadImageToDisk:
252         // FIXME: Some day we should be able to do this from within WebCore.
253         m_client->downloadURL(m_hitTestResult.absoluteImageURL());
254         break;
255     case ContextMenuItemTagCopyImageToClipboard:
256         // FIXME: The Pasteboard class is not written yet
257         // For now, call into the client. This is temporary!
258         frame->editor()->copyImage(m_hitTestResult);
259         break;
260 #if PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
261     case ContextMenuItemTagCopyImageUrlToClipboard:
262         frame->editor()->copyURL(m_hitTestResult.absoluteImageURL(), m_hitTestResult.textContent());
263         break;
264 #endif
265     case ContextMenuItemTagOpenMediaInNewWindow:
266         openNewWindow(m_hitTestResult.absoluteMediaURL(), frame);
267         break;
268     case ContextMenuItemTagCopyMediaLinkToClipboard:
269         frame->editor()->copyURL(m_hitTestResult.absoluteMediaURL(), m_hitTestResult.textContent());
270         break;
271     case ContextMenuItemTagToggleMediaControls:
272         m_hitTestResult.toggleMediaControlsDisplay();
273         break;
274     case ContextMenuItemTagToggleMediaLoop:
275         m_hitTestResult.toggleMediaLoopPlayback();
276         break;
277     case ContextMenuItemTagEnterVideoFullscreen:
278         m_hitTestResult.enterFullscreenForVideo();
279         break;
280     case ContextMenuItemTagMediaPlayPause:
281         m_hitTestResult.toggleMediaPlayState();
282         break;
283     case ContextMenuItemTagMediaMute:
284         m_hitTestResult.toggleMediaMuteState();
285         break;
286     case ContextMenuItemTagOpenFrameInNewWindow: {
287         DocumentLoader* loader = frame->loader()->documentLoader();
288         if (!loader->unreachableURL().isEmpty())
289             openNewWindow(loader->unreachableURL(), frame);
290         else
291             openNewWindow(loader->url(), frame);
292         break;
293     }
294     case ContextMenuItemTagCopy: {
295         frame->editor()->copy();
296 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
297         if (frame->selection())
298             frame->editor()->command("Unselect").execute();
299 #endif
300         break;
301     }
302     case ContextMenuItemTagGoBack:
303         if (Page* page = frame->page())
304             page->backForward()->goBackOrForward(-1);
305         break;
306     case ContextMenuItemTagGoForward:
307         if (Page* page = frame->page())
308             page->backForward()->goBackOrForward(1);
309         break;
310     case ContextMenuItemTagStop:
311         frame->loader()->stop();
312         break;
313     case ContextMenuItemTagReload:
314         frame->loader()->reload();
315         break;
316     case ContextMenuItemTagCut:
317         frame->editor()->command("Cut").execute();
318         break;
319     case ContextMenuItemTagPaste:
320         frame->editor()->command("Paste").execute();
321         break;
322 #if PLATFORM(GTK)
323     case ContextMenuItemTagDelete:
324         frame->editor()->performDelete();
325         break;
326     case ContextMenuItemTagUnicodeInsertLRMMark:
327         insertUnicodeCharacter(leftToRightMark, frame);
328         break;
329     case ContextMenuItemTagUnicodeInsertRLMMark:
330         insertUnicodeCharacter(rightToLeftMark, frame);
331         break;
332     case ContextMenuItemTagUnicodeInsertLREMark:
333         insertUnicodeCharacter(leftToRightEmbed, frame);
334         break;
335     case ContextMenuItemTagUnicodeInsertRLEMark:
336         insertUnicodeCharacter(rightToLeftEmbed, frame);
337         break;
338     case ContextMenuItemTagUnicodeInsertLROMark:
339         insertUnicodeCharacter(leftToRightOverride, frame);
340         break;
341     case ContextMenuItemTagUnicodeInsertRLOMark:
342         insertUnicodeCharacter(rightToLeftOverride, frame);
343         break;
344     case ContextMenuItemTagUnicodeInsertPDFMark:
345         insertUnicodeCharacter(popDirectionalFormatting, frame);
346         break;
347     case ContextMenuItemTagUnicodeInsertZWSMark:
348         insertUnicodeCharacter(zeroWidthSpace, frame);
349         break;
350     case ContextMenuItemTagUnicodeInsertZWJMark:
351         insertUnicodeCharacter(zeroWidthJoiner, frame);
352         break;
353     case ContextMenuItemTagUnicodeInsertZWNJMark:
354         insertUnicodeCharacter(zeroWidthNonJoiner, frame);
355         break;
356 #endif
357 #if PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL)
358     case ContextMenuItemTagSelectAll:
359         frame->editor()->command("SelectAll").execute();
360         break;
361 #endif
362 #if ENABLE(TIZEN_CONTEXT_MENU_SELECT)
363     case ContextMenuItemTagSelectWord:
364         frame->editor()->command("SelectWord").execute();
365         break;
366 #endif
367     case ContextMenuItemTagSpellingGuess:
368         ASSERT(frame->editor()->selectedText().length());
369         if (frame->editor()->shouldInsertText(item->title(), frame->selection()->toNormalizedRange().get(), EditorInsertActionPasted)) {
370             Document* document = frame->document();
371             RefPtr<ReplaceSelectionCommand> command = ReplaceSelectionCommand::create(document, createFragmentFromMarkup(document, item->title(), ""), ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::MatchStyle | ReplaceSelectionCommand::PreventNesting);
372             applyCommand(command);
373             frame->selection()->revealSelection(ScrollAlignment::alignToEdgeIfNeeded);
374         }
375         break;
376     case ContextMenuItemTagIgnoreSpelling:
377         frame->editor()->ignoreSpelling();
378         break;
379     case ContextMenuItemTagLearnSpelling:
380         frame->editor()->learnSpelling();
381         break;
382     case ContextMenuItemTagSearchWeb:
383         m_client->searchWithGoogle(frame);
384         break;
385     case ContextMenuItemTagLookUpInDictionary:
386         // FIXME: Some day we may be able to do this from within WebCore.
387         m_client->lookUpInDictionary(frame);
388         break;
389     case ContextMenuItemTagOpenLink:
390         if (Frame* targetFrame = m_hitTestResult.targetFrame())
391             targetFrame->loader()->loadFrameRequest(FrameLoadRequest(frame->document()->securityOrigin(), ResourceRequest(m_hitTestResult.absoluteLinkURL(), frame->loader()->outgoingReferrer())), false, false, 0, 0, MaybeSendReferrer);
392         else
393             openNewWindow(m_hitTestResult.absoluteLinkURL(), frame);
394         break;
395     case ContextMenuItemTagBold:
396         frame->editor()->command("ToggleBold").execute();
397         break;
398     case ContextMenuItemTagItalic:
399         frame->editor()->command("ToggleItalic").execute();
400         break;
401     case ContextMenuItemTagUnderline:
402         frame->editor()->toggleUnderline();
403         break;
404     case ContextMenuItemTagOutline:
405         // We actually never enable this because CSS does not have a way to specify an outline font,
406         // which may make this difficult to implement. Maybe a special case of text-shadow?
407         break;
408     case ContextMenuItemTagStartSpeaking: {
409         ExceptionCode ec;
410         RefPtr<Range> selectedRange = frame->selection()->toNormalizedRange();
411         if (!selectedRange || selectedRange->collapsed(ec)) {
412             Document* document = m_hitTestResult.innerNonSharedNode()->document();
413             selectedRange = document->createRange();
414             selectedRange->selectNode(document->documentElement(), ec);
415         }
416         m_client->speak(plainText(selectedRange.get()));
417         break;
418     }
419     case ContextMenuItemTagStopSpeaking:
420         m_client->stopSpeaking();
421         break;
422     case ContextMenuItemTagDefaultDirection:
423         frame->editor()->setBaseWritingDirection(NaturalWritingDirection);
424         break;
425     case ContextMenuItemTagLeftToRight:
426         frame->editor()->setBaseWritingDirection(LeftToRightWritingDirection);
427         break;
428     case ContextMenuItemTagRightToLeft:
429         frame->editor()->setBaseWritingDirection(RightToLeftWritingDirection);
430         break;
431     case ContextMenuItemTagTextDirectionDefault:
432         frame->editor()->command("MakeTextWritingDirectionNatural").execute();
433         break;
434     case ContextMenuItemTagTextDirectionLeftToRight:
435         frame->editor()->command("MakeTextWritingDirectionLeftToRight").execute();
436         break;
437     case ContextMenuItemTagTextDirectionRightToLeft:
438         frame->editor()->command("MakeTextWritingDirectionRightToLeft").execute();
439         break;
440 #if PLATFORM(MAC)
441     case ContextMenuItemTagSearchInSpotlight:
442         m_client->searchWithSpotlight();
443         break;
444 #endif
445     case ContextMenuItemTagShowSpellingPanel:
446         frame->editor()->showSpellingGuessPanel();
447         break;
448     case ContextMenuItemTagCheckSpelling:
449         frame->editor()->advanceToNextMisspelling();
450         break;
451     case ContextMenuItemTagCheckSpellingWhileTyping:
452         frame->editor()->toggleContinuousSpellChecking();
453         break;
454     case ContextMenuItemTagCheckGrammarWithSpelling:
455         frame->editor()->toggleGrammarChecking();
456         break;
457 #if PLATFORM(MAC)
458     case ContextMenuItemTagShowFonts:
459         frame->editor()->showFontPanel();
460         break;
461     case ContextMenuItemTagStyles:
462         frame->editor()->showStylesPanel();
463         break;
464     case ContextMenuItemTagShowColors:
465         frame->editor()->showColorPanel();
466         break;
467 #endif
468 #if USE(APPKIT)
469     case ContextMenuItemTagMakeUpperCase:
470         frame->editor()->uppercaseWord();
471         break;
472     case ContextMenuItemTagMakeLowerCase:
473         frame->editor()->lowercaseWord();
474         break;
475     case ContextMenuItemTagCapitalize:
476         frame->editor()->capitalizeWord();
477         break;
478 #endif
479 #if PLATFORM(MAC)
480     case ContextMenuItemTagChangeBack:
481         frame->editor()->changeBackToReplacedString(m_hitTestResult.replacedString());
482         break;
483 #endif
484 #if USE(AUTOMATIC_TEXT_REPLACEMENT)
485     case ContextMenuItemTagShowSubstitutions:
486         frame->editor()->showSubstitutionsPanel();
487         break;
488     case ContextMenuItemTagSmartCopyPaste:
489         frame->editor()->toggleSmartInsertDelete();
490         break;
491     case ContextMenuItemTagSmartQuotes:
492         frame->editor()->toggleAutomaticQuoteSubstitution();
493         break;
494     case ContextMenuItemTagSmartDashes:
495         frame->editor()->toggleAutomaticDashSubstitution();
496         break;
497     case ContextMenuItemTagSmartLinks:
498         frame->editor()->toggleAutomaticLinkDetection();
499         break;
500     case ContextMenuItemTagTextReplacement:
501         frame->editor()->toggleAutomaticTextReplacement();
502         break;
503     case ContextMenuItemTagCorrectSpellingAutomatically:
504         frame->editor()->toggleAutomaticSpellingCorrection();
505         break;
506 #endif
507 #if ENABLE(INSPECTOR)
508     case ContextMenuItemTagInspectElement:
509         if (Page* page = frame->page())
510             page->inspectorController()->inspect(m_hitTestResult.innerNonSharedNode());
511         break;
512 #endif
513     case ContextMenuItemTagDictationAlternative:
514         frame->editor()->applyDictationAlternativelternative(item->title());
515         break;
516 #if ENABLE(TIZEN_DRAG_SUPPORT)
517     case ContextMenuItemTagDrag:
518         TIZEN_LOGI("ContextMenuItemTagDrag");
519         if (Page* page = frame->page()) {
520             page->dragController()->setDragState(true);
521             frame->eventHandler()->handleMousePressEvent(page->dragController()->dragPositionEvent());
522             page->dragController()->setDragState(false);
523         }
524         break;
525 #endif
526     default:
527         break;
528     }
529 }
530
531 void ContextMenuController::appendItem(ContextMenuItem& menuItem, ContextMenu* parentMenu)
532 {
533     checkOrEnableIfNeeded(menuItem);
534     if (parentMenu)
535         parentMenu->appendItem(menuItem);
536 }
537
538 void ContextMenuController::createAndAppendFontSubMenu(ContextMenuItem& fontMenuItem)
539 {
540     ContextMenu fontMenu;
541
542 #if PLATFORM(MAC)
543     ContextMenuItem showFonts(ActionType, ContextMenuItemTagShowFonts, contextMenuItemTagShowFonts());
544 #endif
545     ContextMenuItem bold(CheckableActionType, ContextMenuItemTagBold, contextMenuItemTagBold());
546     ContextMenuItem italic(CheckableActionType, ContextMenuItemTagItalic, contextMenuItemTagItalic());
547     ContextMenuItem underline(CheckableActionType, ContextMenuItemTagUnderline, contextMenuItemTagUnderline());
548     ContextMenuItem outline(ActionType, ContextMenuItemTagOutline, contextMenuItemTagOutline());
549 #if PLATFORM(MAC)
550     ContextMenuItem styles(ActionType, ContextMenuItemTagStyles, contextMenuItemTagStyles());
551     ContextMenuItem showColors(ActionType, ContextMenuItemTagShowColors, contextMenuItemTagShowColors());
552 #endif
553
554 #if PLATFORM(MAC)
555     appendItem(showFonts, &fontMenu);
556 #endif
557     appendItem(bold, &fontMenu);
558     appendItem(italic, &fontMenu);
559     appendItem(underline, &fontMenu);
560     appendItem(outline, &fontMenu);
561 #if PLATFORM(MAC)
562     appendItem(styles, &fontMenu);
563     appendItem(*separatorItem(), &fontMenu);
564     appendItem(showColors, &fontMenu);
565 #endif
566
567     fontMenuItem.setSubMenu(&fontMenu);
568 }
569
570
571 #if !PLATFORM(GTK)
572
573 void ContextMenuController::createAndAppendSpellingAndGrammarSubMenu(ContextMenuItem& spellingAndGrammarMenuItem)
574 {
575     ContextMenu spellingAndGrammarMenu;
576
577     ContextMenuItem showSpellingPanel(ActionType, ContextMenuItemTagShowSpellingPanel, 
578         contextMenuItemTagShowSpellingPanel(true));
579     ContextMenuItem checkSpelling(ActionType, ContextMenuItemTagCheckSpelling, 
580         contextMenuItemTagCheckSpelling());
581     ContextMenuItem checkAsYouType(CheckableActionType, ContextMenuItemTagCheckSpellingWhileTyping, 
582         contextMenuItemTagCheckSpellingWhileTyping());
583     ContextMenuItem grammarWithSpelling(CheckableActionType, ContextMenuItemTagCheckGrammarWithSpelling, 
584         contextMenuItemTagCheckGrammarWithSpelling());
585 #if PLATFORM(MAC)
586     ContextMenuItem correctSpelling(CheckableActionType, ContextMenuItemTagCorrectSpellingAutomatically, 
587         contextMenuItemTagCorrectSpellingAutomatically());
588 #endif
589
590     appendItem(showSpellingPanel, &spellingAndGrammarMenu);
591     appendItem(checkSpelling, &spellingAndGrammarMenu);
592 #if PLATFORM(MAC)
593     appendItem(*separatorItem(), &spellingAndGrammarMenu);
594 #endif
595     appendItem(checkAsYouType, &spellingAndGrammarMenu);
596     appendItem(grammarWithSpelling, &spellingAndGrammarMenu);
597 #if PLATFORM(MAC)
598     appendItem(correctSpelling, &spellingAndGrammarMenu);
599 #endif
600
601     spellingAndGrammarMenuItem.setSubMenu(&spellingAndGrammarMenu);
602 }
603
604 #endif // !PLATFORM(GTK)
605
606
607 #if PLATFORM(MAC)
608
609 void ContextMenuController::createAndAppendSpeechSubMenu(ContextMenuItem& speechMenuItem)
610 {
611     ContextMenu speechMenu;
612
613     ContextMenuItem start(ActionType, ContextMenuItemTagStartSpeaking, contextMenuItemTagStartSpeaking());
614     ContextMenuItem stop(ActionType, ContextMenuItemTagStopSpeaking, contextMenuItemTagStopSpeaking());
615
616     appendItem(start, &speechMenu);
617     appendItem(stop, &speechMenu);
618
619     speechMenuItem.setSubMenu(&speechMenu);
620 }
621
622 #endif
623  
624 #if PLATFORM(GTK)
625
626 void ContextMenuController::createAndAppendUnicodeSubMenu(ContextMenuItem& unicodeMenuItem)
627 {
628     ContextMenu unicodeMenu;
629
630     ContextMenuItem leftToRightMarkMenuItem(ActionType, ContextMenuItemTagUnicodeInsertLRMMark, contextMenuItemTagUnicodeInsertLRMMark());
631     ContextMenuItem rightToLeftMarkMenuItem(ActionType, ContextMenuItemTagUnicodeInsertRLMMark, contextMenuItemTagUnicodeInsertRLMMark());
632     ContextMenuItem leftToRightEmbedMenuItem(ActionType, ContextMenuItemTagUnicodeInsertLREMark, contextMenuItemTagUnicodeInsertLREMark());
633     ContextMenuItem rightToLeftEmbedMenuItem(ActionType, ContextMenuItemTagUnicodeInsertRLEMark, contextMenuItemTagUnicodeInsertRLEMark());
634     ContextMenuItem leftToRightOverrideMenuItem(ActionType, ContextMenuItemTagUnicodeInsertLROMark, contextMenuItemTagUnicodeInsertLROMark());
635     ContextMenuItem rightToLeftOverrideMenuItem(ActionType, ContextMenuItemTagUnicodeInsertRLOMark, contextMenuItemTagUnicodeInsertRLOMark());
636     ContextMenuItem popDirectionalFormattingMenuItem(ActionType, ContextMenuItemTagUnicodeInsertPDFMark, contextMenuItemTagUnicodeInsertPDFMark());
637     ContextMenuItem zeroWidthSpaceMenuItem(ActionType, ContextMenuItemTagUnicodeInsertZWSMark, contextMenuItemTagUnicodeInsertZWSMark());
638     ContextMenuItem zeroWidthJoinerMenuItem(ActionType, ContextMenuItemTagUnicodeInsertZWJMark, contextMenuItemTagUnicodeInsertZWJMark());
639     ContextMenuItem zeroWidthNonJoinerMenuItem(ActionType, ContextMenuItemTagUnicodeInsertZWNJMark, contextMenuItemTagUnicodeInsertZWNJMark());
640
641     appendItem(leftToRightMarkMenuItem, &unicodeMenu);
642     appendItem(rightToLeftMarkMenuItem, &unicodeMenu);
643     appendItem(leftToRightEmbedMenuItem, &unicodeMenu);
644     appendItem(rightToLeftEmbedMenuItem, &unicodeMenu);
645     appendItem(leftToRightOverrideMenuItem, &unicodeMenu);
646     appendItem(rightToLeftOverrideMenuItem, &unicodeMenu);
647     appendItem(popDirectionalFormattingMenuItem, &unicodeMenu);
648     appendItem(zeroWidthSpaceMenuItem, &unicodeMenu);
649     appendItem(zeroWidthJoinerMenuItem, &unicodeMenu);
650     appendItem(zeroWidthNonJoinerMenuItem, &unicodeMenu);
651
652     unicodeMenuItem.setSubMenu(&unicodeMenu);
653 }
654
655 #else
656
657 void ContextMenuController::createAndAppendWritingDirectionSubMenu(ContextMenuItem& writingDirectionMenuItem)
658 {
659     ContextMenu writingDirectionMenu;
660
661     ContextMenuItem defaultItem(ActionType, ContextMenuItemTagDefaultDirection, 
662         contextMenuItemTagDefaultDirection());
663     ContextMenuItem ltr(CheckableActionType, ContextMenuItemTagLeftToRight, contextMenuItemTagLeftToRight());
664     ContextMenuItem rtl(CheckableActionType, ContextMenuItemTagRightToLeft, contextMenuItemTagRightToLeft());
665
666     appendItem(defaultItem, &writingDirectionMenu);
667     appendItem(ltr, &writingDirectionMenu);
668     appendItem(rtl, &writingDirectionMenu);
669
670     writingDirectionMenuItem.setSubMenu(&writingDirectionMenu);
671 }
672
673 void ContextMenuController::createAndAppendTextDirectionSubMenu(ContextMenuItem& textDirectionMenuItem)
674 {
675     ContextMenu textDirectionMenu;
676
677     ContextMenuItem defaultItem(ActionType, ContextMenuItemTagTextDirectionDefault, contextMenuItemTagDefaultDirection());
678     ContextMenuItem ltr(CheckableActionType, ContextMenuItemTagTextDirectionLeftToRight, contextMenuItemTagLeftToRight());
679     ContextMenuItem rtl(CheckableActionType, ContextMenuItemTagTextDirectionRightToLeft, contextMenuItemTagRightToLeft());
680
681     appendItem(defaultItem, &textDirectionMenu);
682     appendItem(ltr, &textDirectionMenu);
683     appendItem(rtl, &textDirectionMenu);
684
685     textDirectionMenuItem.setSubMenu(&textDirectionMenu);
686 }
687
688 #endif
689
690 #if PLATFORM(MAC)
691
692 void ContextMenuController::createAndAppendSubstitutionsSubMenu(ContextMenuItem& substitutionsMenuItem)
693 {
694     ContextMenu substitutionsMenu;
695
696     ContextMenuItem showSubstitutions(ActionType, ContextMenuItemTagShowSubstitutions, contextMenuItemTagShowSubstitutions(true));
697     ContextMenuItem smartCopyPaste(CheckableActionType, ContextMenuItemTagSmartCopyPaste, contextMenuItemTagSmartCopyPaste());
698     ContextMenuItem smartQuotes(CheckableActionType, ContextMenuItemTagSmartQuotes, contextMenuItemTagSmartQuotes());
699     ContextMenuItem smartDashes(CheckableActionType, ContextMenuItemTagSmartDashes, contextMenuItemTagSmartDashes());
700     ContextMenuItem smartLinks(CheckableActionType, ContextMenuItemTagSmartLinks, contextMenuItemTagSmartLinks());
701     ContextMenuItem textReplacement(CheckableActionType, ContextMenuItemTagTextReplacement, contextMenuItemTagTextReplacement());
702
703     appendItem(showSubstitutions, &substitutionsMenu);
704     appendItem(*separatorItem(), &substitutionsMenu);
705     appendItem(smartCopyPaste, &substitutionsMenu);
706     appendItem(smartQuotes, &substitutionsMenu);
707     appendItem(smartDashes, &substitutionsMenu);
708     appendItem(smartLinks, &substitutionsMenu);
709     appendItem(textReplacement, &substitutionsMenu);
710
711     substitutionsMenuItem.setSubMenu(&substitutionsMenu);
712 }
713
714 void ContextMenuController::createAndAppendTransformationsSubMenu(ContextMenuItem& transformationsMenuItem)
715 {
716     ContextMenu transformationsMenu;
717
718     ContextMenuItem makeUpperCase(ActionType, ContextMenuItemTagMakeUpperCase, contextMenuItemTagMakeUpperCase());
719     ContextMenuItem makeLowerCase(ActionType, ContextMenuItemTagMakeLowerCase, contextMenuItemTagMakeLowerCase());
720     ContextMenuItem capitalize(ActionType, ContextMenuItemTagCapitalize, contextMenuItemTagCapitalize());
721
722     appendItem(makeUpperCase, &transformationsMenu);
723     appendItem(makeLowerCase, &transformationsMenu);
724     appendItem(capitalize, &transformationsMenu);
725
726     transformationsMenuItem.setSubMenu(&transformationsMenu);
727 }
728
729 #endif
730
731 static bool selectionContainsPossibleWord(Frame* frame)
732 {
733     // Current algorithm: look for a character that's not just a separator.
734     for (TextIterator it(frame->selection()->toNormalizedRange().get()); !it.atEnd(); it.advance()) {
735         int length = it.length();
736         const UChar* characters = it.characters();
737         for (int i = 0; i < length; ++i)
738             if (!(category(characters[i]) & (Separator_Space | Separator_Line | Separator_Paragraph)))
739                 return true;
740     }
741     return false;
742 }
743
744 #if PLATFORM(MAC)
745 #if __MAC_OS_X_VERSION_MIN_REQUIRED == 1060
746 #define INCLUDE_SPOTLIGHT_CONTEXT_MENU_ITEM 1
747 #else
748 #define INCLUDE_SPOTLIGHT_CONTEXT_MENU_ITEM 0
749 #endif
750 #endif
751
752 void ContextMenuController::populate()
753 {
754     ContextMenuItem OpenLinkItem(ActionType, ContextMenuItemTagOpenLink, contextMenuItemTagOpenLink());
755     ContextMenuItem OpenLinkInNewWindowItem(ActionType, ContextMenuItemTagOpenLinkInNewWindow, 
756         contextMenuItemTagOpenLinkInNewWindow());
757     ContextMenuItem DownloadFileItem(ActionType, ContextMenuItemTagDownloadLinkToDisk, 
758         contextMenuItemTagDownloadLinkToDisk());
759     ContextMenuItem CopyLinkItem(ActionType, ContextMenuItemTagCopyLinkToClipboard, 
760         contextMenuItemTagCopyLinkToClipboard());
761     ContextMenuItem OpenImageInNewWindowItem(ActionType, ContextMenuItemTagOpenImageInNewWindow, 
762         contextMenuItemTagOpenImageInNewWindow());
763     ContextMenuItem DownloadImageItem(ActionType, ContextMenuItemTagDownloadImageToDisk, 
764         contextMenuItemTagDownloadImageToDisk());
765     ContextMenuItem CopyImageItem(ActionType, ContextMenuItemTagCopyImageToClipboard, 
766         contextMenuItemTagCopyImageToClipboard());
767 #if PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
768     ContextMenuItem CopyImageUrlItem(ActionType, ContextMenuItemTagCopyImageUrlToClipboard, 
769         contextMenuItemTagCopyImageUrlToClipboard());
770 #endif
771     ContextMenuItem OpenMediaInNewWindowItem(ActionType, ContextMenuItemTagOpenMediaInNewWindow, String());
772     ContextMenuItem CopyMediaLinkItem(ActionType, ContextMenuItemTagCopyMediaLinkToClipboard, 
773         String());
774     ContextMenuItem MediaPlayPause(ActionType, ContextMenuItemTagMediaPlayPause, 
775         contextMenuItemTagMediaPlay());
776     ContextMenuItem MediaMute(ActionType, ContextMenuItemTagMediaMute, 
777         contextMenuItemTagMediaMute());
778     ContextMenuItem ToggleMediaControls(CheckableActionType, ContextMenuItemTagToggleMediaControls, 
779         contextMenuItemTagToggleMediaControls());
780     ContextMenuItem ToggleMediaLoop(CheckableActionType, ContextMenuItemTagToggleMediaLoop, 
781         contextMenuItemTagToggleMediaLoop());
782     ContextMenuItem EnterVideoFullscreen(ActionType, ContextMenuItemTagEnterVideoFullscreen, 
783         contextMenuItemTagEnterVideoFullscreen());
784 #if PLATFORM(MAC)
785     ContextMenuItem SearchSpotlightItem(ActionType, ContextMenuItemTagSearchInSpotlight, 
786         contextMenuItemTagSearchInSpotlight());
787 #endif
788 #if !PLATFORM(GTK)
789     ContextMenuItem SearchWebItem(ActionType, ContextMenuItemTagSearchWeb, contextMenuItemTagSearchWeb());
790 #endif
791     ContextMenuItem CopyItem(ActionType, ContextMenuItemTagCopy, contextMenuItemTagCopy());
792     ContextMenuItem BackItem(ActionType, ContextMenuItemTagGoBack, contextMenuItemTagGoBack());
793     ContextMenuItem ForwardItem(ActionType, ContextMenuItemTagGoForward,  contextMenuItemTagGoForward());
794     ContextMenuItem StopItem(ActionType, ContextMenuItemTagStop, contextMenuItemTagStop());
795     ContextMenuItem ReloadItem(ActionType, ContextMenuItemTagReload, contextMenuItemTagReload());
796     ContextMenuItem OpenFrameItem(ActionType, ContextMenuItemTagOpenFrameInNewWindow, 
797         contextMenuItemTagOpenFrameInNewWindow());
798     ContextMenuItem NoGuessesItem(ActionType, ContextMenuItemTagNoGuessesFound, 
799         contextMenuItemTagNoGuessesFound());
800     ContextMenuItem IgnoreSpellingItem(ActionType, ContextMenuItemTagIgnoreSpelling, 
801         contextMenuItemTagIgnoreSpelling());
802     ContextMenuItem LearnSpellingItem(ActionType, ContextMenuItemTagLearnSpelling, 
803         contextMenuItemTagLearnSpelling());
804     ContextMenuItem IgnoreGrammarItem(ActionType, ContextMenuItemTagIgnoreGrammar, 
805         contextMenuItemTagIgnoreGrammar());
806     ContextMenuItem CutItem(ActionType, ContextMenuItemTagCut, contextMenuItemTagCut());
807     ContextMenuItem PasteItem(ActionType, ContextMenuItemTagPaste, contextMenuItemTagPaste());
808 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
809     ContextMenuItem ClipboardItem(ActionType, ContextMenuItemTagClipboard, contextMenuItemTagClipboard());
810 #endif
811 #if PLATFORM(GTK)
812     ContextMenuItem DeleteItem(ActionType, ContextMenuItemTagDelete, contextMenuItemTagDelete());
813 #endif
814 #if PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL)
815     ContextMenuItem SelectAllItem(ActionType, ContextMenuItemTagSelectAll, contextMenuItemTagSelectAll());
816 #endif
817 #if ENABLE(TIZEN_CONTEXT_MENU_SELECT)
818     ContextMenuItem SelectWordItem(ActionType, ContextMenuItemTagSelectWord, contextMenuItemTagSelectWord());
819 #endif
820 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
821     ContextMenuItem TextSelectionModeItem(ActionType, ContextMenuItemTagTextSelectionMode, contextMenuItemTagTextSelectionMode());
822 #endif
823 #if ENABLE(TIZEN_DRAG_SUPPORT)
824     ContextMenuItem DragItem(ActionType, ContextMenuItemTagDrag, contextMenuItemTagDrag());
825 #endif
826
827     Node* node = m_hitTestResult.innerNonSharedNode();
828     if (!node)
829         return;
830 #if PLATFORM(GTK)
831     if (!m_hitTestResult.isContentEditable() && (node->isElementNode() && static_cast<Element*>(node)->isFormControlElement()))
832         return;
833 #endif
834     Frame* frame = node->document()->frame();
835     if (!frame)
836         return;
837
838     if (!m_hitTestResult.isContentEditable()) {
839         FrameLoader* loader = frame->loader();
840         KURL linkURL = m_hitTestResult.absoluteLinkURL();
841         if (!linkURL.isEmpty()) {
842 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
843             if (m_hitTestResult.isSelected()) {
844                 if (selectionContainsPossibleWord(frame)) {
845                     appendItem(SearchWebItem, m_contextMenu.get());
846                 }
847                 appendItem(CopyItem, m_contextMenu.get());
848                 return;
849             }
850 #endif
851 #if ENABLE(TIZEN_DOWNLOAD_LINK_FILTER)
852             if (loader->client()->canHandleRequest(ResourceRequest(linkURL)) &&
853                (linkURL.protocolIs("http") || linkURL.protocolIs("https") || linkURL.protocolIs("ftp") || linkURL.protocolIs("ftps"))) {
854 #else
855             if (loader->client()->canHandleRequest(ResourceRequest(linkURL))) {
856 #endif
857                 appendItem(OpenLinkItem, m_contextMenu.get());
858                 appendItem(OpenLinkInNewWindowItem, m_contextMenu.get());
859                 appendItem(DownloadFileItem, m_contextMenu.get());
860             }
861 #if PLATFORM(QT)
862             if (m_hitTestResult.isSelected()) 
863                 appendItem(CopyItem, m_contextMenu.get());
864 #endif
865             appendItem(CopyLinkItem, m_contextMenu.get());
866         }
867
868         KURL imageURL = m_hitTestResult.absoluteImageURL();
869         if (!imageURL.isEmpty()) {
870             if (!linkURL.isEmpty())
871                 appendItem(*separatorItem(), m_contextMenu.get());
872
873             appendItem(OpenImageInNewWindowItem, m_contextMenu.get());
874             appendItem(DownloadImageItem, m_contextMenu.get());
875             if (imageURL.isLocalFile() || m_hitTestResult.image())
876                 appendItem(CopyImageItem, m_contextMenu.get());
877 #if PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
878             appendItem(CopyImageUrlItem, m_contextMenu.get());
879 #endif
880         }
881
882         KURL mediaURL = m_hitTestResult.absoluteMediaURL();
883         if (!mediaURL.isEmpty()) {
884             if (!linkURL.isEmpty() || !imageURL.isEmpty())
885                 appendItem(*separatorItem(), m_contextMenu.get());
886
887             appendItem(MediaPlayPause, m_contextMenu.get());
888             appendItem(MediaMute, m_contextMenu.get());
889             appendItem(ToggleMediaControls, m_contextMenu.get());
890             appendItem(ToggleMediaLoop, m_contextMenu.get());
891             appendItem(EnterVideoFullscreen, m_contextMenu.get());
892
893             appendItem(*separatorItem(), m_contextMenu.get());
894             appendItem(CopyMediaLinkItem, m_contextMenu.get());
895             appendItem(OpenMediaInNewWindowItem, m_contextMenu.get());
896         }
897
898 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
899         if (!linkURL.isEmpty() && imageURL.isEmpty() && mediaURL.isEmpty())
900             appendItem(TextSelectionModeItem, m_contextMenu.get());
901 #endif
902
903 #if ENABLE(TIZEN_DRAG_SUPPORT)
904         if (imageURL.isEmpty() && linkURL.isEmpty() && mediaURL.isEmpty() && !m_hitTestResult.isDragSupport()) {
905 #else
906         if (imageURL.isEmpty() && linkURL.isEmpty() && mediaURL.isEmpty()) {
907 #endif
908             if (m_hitTestResult.isSelected()) {
909                 if (selectionContainsPossibleWord(frame)) {
910 #if PLATFORM(MAC)
911                     String selectedString = frame->displayStringModifiedByEncoding(frame->editor()->selectedText());
912                     ContextMenuItem LookUpInDictionaryItem(ActionType, ContextMenuItemTagLookUpInDictionary, contextMenuItemTagLookUpInDictionary(selectedString));
913
914 #if INCLUDE_SPOTLIGHT_CONTEXT_MENU_ITEM
915                     appendItem(SearchSpotlightItem, m_contextMenu.get());
916 #else
917                     appendItem(LookUpInDictionaryItem, m_contextMenu.get());
918 #endif
919 #endif
920
921 #if !PLATFORM(GTK)
922                     appendItem(SearchWebItem, m_contextMenu.get());
923                     appendItem(*separatorItem(), m_contextMenu.get());
924 #endif
925
926 #if PLATFORM(MAC) && INCLUDE_SPOTLIGHT_CONTEXT_MENU_ITEM
927                     appendItem(LookUpInDictionaryItem, m_contextMenu.get());
928                     appendItem(*separatorItem(), m_contextMenu.get());
929 #endif
930                 }
931
932                 appendItem(CopyItem, m_contextMenu.get());
933 #if PLATFORM(MAC)
934                 appendItem(*separatorItem(), m_contextMenu.get());
935
936                 ContextMenuItem SpeechMenuItem(SubmenuType, ContextMenuItemTagSpeechMenu, contextMenuItemTagSpeechMenu());
937                 createAndAppendSpeechSubMenu(SpeechMenuItem);
938                 appendItem(SpeechMenuItem, m_contextMenu.get());
939 #endif                
940             } else {
941 #if ENABLE(INSPECTOR)
942                 if (!(frame->page() && frame->page()->inspectorController()->hasInspectorFrontendClient())) {
943 #endif
944
945                 // In GTK+ unavailable items are not hidden but insensitive
946 #if PLATFORM(GTK)
947                 appendItem(BackItem, m_contextMenu.get());
948                 appendItem(ForwardItem, m_contextMenu.get());
949                 appendItem(StopItem, m_contextMenu.get());
950                 appendItem(ReloadItem, m_contextMenu.get());
951 #else
952                 if (frame->page() && frame->page()->backForward()->canGoBackOrForward(-1))
953                     appendItem(BackItem, m_contextMenu.get());
954
955                 if (frame->page() && frame->page()->backForward()->canGoBackOrForward(1))
956                     appendItem(ForwardItem, m_contextMenu.get());
957
958                 // use isLoadingInAPISense rather than isLoading because Stop/Reload are
959                 // intended to match WebKit's API, not WebCore's internal notion of loading status
960                 if (loader->documentLoader()->isLoadingInAPISense())
961                     appendItem(StopItem, m_contextMenu.get());
962                 else
963                     appendItem(ReloadItem, m_contextMenu.get());
964 #endif
965 #if ENABLE(INSPECTOR)
966                 }
967 #endif
968
969                 if (frame->page() && frame != frame->page()->mainFrame())
970                     appendItem(OpenFrameItem, m_contextMenu.get());
971             }
972         }
973 #if ENABLE(TIZEN_DRAG_SUPPORT)
974         if (frame->page() && m_hitTestResult.isDragSupport()) {
975             TIZEN_LOGI("appendItem for drag");
976             appendItem(DragItem, m_contextMenu.get());
977         }
978 #endif
979     } else { // Make an editing context menu
980         FrameSelection* selection = frame->selection();
981         bool inPasswordField = selection->isInPasswordField();
982         if (!inPasswordField) {
983             bool haveContextMenuItemsForMisspellingOrGrammer = false;
984             bool spellCheckingEnabled = frame->editor()->isSpellCheckingEnabledFor(node);
985             if (spellCheckingEnabled) {
986                 // Consider adding spelling-related or grammar-related context menu items (never both, since a single selected range
987                 // is never considered a misspelling and bad grammar at the same time)
988 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
989                 bool misspelling = false;
990                 bool badGrammar = false;
991 #else
992                 bool misspelling;
993                 bool badGrammar;
994 #endif
995                 Vector<String> guesses = frame->editor()->guessesForMisspelledOrUngrammaticalSelection(misspelling, badGrammar);
996                 if (misspelling || badGrammar) {
997                     size_t size = guesses.size();
998                     if (!size) {
999                         // If there's bad grammar but no suggestions (e.g., repeated word), just leave off the suggestions
1000                         // list and trailing separator rather than adding a "No Guesses Found" item (matches AppKit)
1001                         if (misspelling) {
1002                             appendItem(NoGuessesItem, m_contextMenu.get());
1003                             appendItem(*separatorItem(), m_contextMenu.get());
1004                         }
1005                     } else {
1006                         for (unsigned i = 0; i < size; i++) {
1007                             const String &guess = guesses[i];
1008                             if (!guess.isEmpty()) {
1009                                 ContextMenuItem item(ActionType, ContextMenuItemTagSpellingGuess, guess);
1010                                 appendItem(item, m_contextMenu.get());
1011                             }
1012                         }
1013                         appendItem(*separatorItem(), m_contextMenu.get());
1014                     }
1015                     if (misspelling) {
1016                         appendItem(IgnoreSpellingItem, m_contextMenu.get());
1017                         appendItem(LearnSpellingItem, m_contextMenu.get());
1018                     } else
1019                         appendItem(IgnoreGrammarItem, m_contextMenu.get());
1020                     appendItem(*separatorItem(), m_contextMenu.get());
1021                     haveContextMenuItemsForMisspellingOrGrammer = true;
1022 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
1023                 } else {
1024                     // If the string was autocorrected, generate a contextual menu item allowing it to be changed back.
1025                     String replacedString = m_hitTestResult.replacedString();
1026                     if (!replacedString.isEmpty()) {
1027                         ContextMenuItem item(ActionType, ContextMenuItemTagChangeBack, contextMenuItemTagChangeBack(replacedString));
1028                         appendItem(item, m_contextMenu.get());
1029                         appendItem(*separatorItem(), m_contextMenu.get());
1030                         haveContextMenuItemsForMisspellingOrGrammer = true;
1031                     }
1032 #endif
1033                 }
1034             }
1035
1036             if (!haveContextMenuItemsForMisspellingOrGrammer) {
1037                 // Spelling and grammar checking is mutually exclusive with dictation alternatives.
1038                 Vector<String> dictationAlternatives = m_hitTestResult.dictationAlternatives();
1039                 if (!dictationAlternatives.isEmpty()) {
1040                     for (size_t i = 0; i < dictationAlternatives.size(); ++i) {
1041                         ContextMenuItem item(ActionType, ContextMenuItemTagDictationAlternative, dictationAlternatives[i]);
1042                         appendItem(item, m_contextMenu.get());
1043                     }
1044                     appendItem(*separatorItem(), m_contextMenu.get());
1045                 }
1046             }
1047         }
1048
1049         FrameLoader* loader = frame->loader();
1050         KURL linkURL = m_hitTestResult.absoluteLinkURL();
1051         if (!linkURL.isEmpty()) {
1052             if (loader->client()->canHandleRequest(ResourceRequest(linkURL))) {
1053                 appendItem(OpenLinkItem, m_contextMenu.get());
1054                 appendItem(OpenLinkInNewWindowItem, m_contextMenu.get());
1055                 appendItem(DownloadFileItem, m_contextMenu.get());
1056             }
1057             appendItem(CopyLinkItem, m_contextMenu.get());
1058             appendItem(*separatorItem(), m_contextMenu.get());
1059         }
1060
1061         if (m_hitTestResult.isSelected() && !inPasswordField && selectionContainsPossibleWord(frame)) {
1062 #if PLATFORM(MAC)
1063             String selectedString = frame->displayStringModifiedByEncoding(frame->editor()->selectedText());
1064             ContextMenuItem LookUpInDictionaryItem(ActionType, ContextMenuItemTagLookUpInDictionary, contextMenuItemTagLookUpInDictionary(selectedString));
1065
1066 #if INCLUDE_SPOTLIGHT_CONTEXT_MENU_ITEM
1067             appendItem(SearchSpotlightItem, m_contextMenu.get());
1068 #else
1069             appendItem(LookUpInDictionaryItem, m_contextMenu.get());
1070 #endif
1071 #endif
1072
1073 #if !PLATFORM(GTK)
1074             appendItem(SearchWebItem, m_contextMenu.get());
1075             appendItem(*separatorItem(), m_contextMenu.get());
1076 #endif
1077
1078 #if PLATFORM(MAC) && INCLUDE_SPOTLIGHT_CONTEXT_MENU_ITEM
1079             appendItem(LookUpInDictionaryItem, m_contextMenu.get());
1080             appendItem(*separatorItem(), m_contextMenu.get());
1081 #endif
1082         }
1083
1084 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
1085         if (m_hitTestResult.isSelected() && !inPasswordField) {
1086             appendItem(CutItem, m_contextMenu.get());
1087             appendItem(CopyItem, m_contextMenu.get());
1088         }
1089 #else
1090         appendItem(CutItem, m_contextMenu.get());
1091         appendItem(CopyItem, m_contextMenu.get());
1092 #endif
1093         appendItem(PasteItem, m_contextMenu.get());
1094 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
1095         appendItem(ClipboardItem, m_contextMenu.get());
1096 #endif
1097 #if PLATFORM(GTK)
1098         appendItem(DeleteItem, m_contextMenu.get());
1099         appendItem(*separatorItem(), m_contextMenu.get());
1100 #endif
1101 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
1102         if (frame->selection()) {
1103             Node* baseNode = frame->selection()->base().containerNode();
1104             if (baseNode && baseNode->isTextNode() && (!(baseNode->textContent().isEmpty()))) {
1105                 if (inPasswordField) {
1106                     if (!m_hitTestResult.isSelected())
1107                         appendItem(SelectWordItem, m_contextMenu.get());
1108                 } else {
1109 #endif
1110 #if PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL)
1111                     appendItem(SelectAllItem, m_contextMenu.get());
1112 #endif
1113 #if ENABLE(TIZEN_CONTEXT_MENU_SELECT)
1114                     appendItem(SelectWordItem, m_contextMenu.get());
1115 #endif
1116 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
1117                 }
1118             }
1119         }
1120 #endif
1121
1122         if (!inPasswordField) {
1123 #if !PLATFORM(GTK)
1124 #if !ENABLE(TIZEN_CONTEXT_MENU_TEMPORARY_FIX)
1125             appendItem(*separatorItem(), m_contextMenu.get());
1126             ContextMenuItem SpellingAndGrammarMenuItem(SubmenuType, ContextMenuItemTagSpellingMenu, 
1127                 contextMenuItemTagSpellingMenu());
1128             createAndAppendSpellingAndGrammarSubMenu(SpellingAndGrammarMenuItem);
1129             appendItem(SpellingAndGrammarMenuItem, m_contextMenu.get());
1130 #endif //TIZEN_CONTEXT_MENU_TEMPORARY_FIX
1131 #endif
1132 #if PLATFORM(MAC)
1133             ContextMenuItem substitutionsMenuItem(SubmenuType, ContextMenuItemTagSubstitutionsMenu, 
1134                 contextMenuItemTagSubstitutionsMenu());
1135             createAndAppendSubstitutionsSubMenu(substitutionsMenuItem);
1136             appendItem(substitutionsMenuItem, m_contextMenu.get());
1137             ContextMenuItem transformationsMenuItem(SubmenuType, ContextMenuItemTagTransformationsMenu, 
1138                 contextMenuItemTagTransformationsMenu());
1139             createAndAppendTransformationsSubMenu(transformationsMenuItem);
1140             appendItem(transformationsMenuItem, m_contextMenu.get());
1141 #endif
1142 #if PLATFORM(GTK)
1143             bool shouldShowFontMenu = frame->editor()->canEditRichly();
1144 #else
1145 #if ENABLE(TIZEN_CONTEXT_MENU_TEMPORARY_FIX)
1146             bool shouldShowFontMenu = false;
1147 #else
1148             bool shouldShowFontMenu = true;
1149 #endif //TIZEN_CONTEXT_MENU_TEMPORARY_FIX
1150 #endif
1151             if (shouldShowFontMenu) {
1152                 ContextMenuItem FontMenuItem(SubmenuType, ContextMenuItemTagFontMenu, 
1153                     contextMenuItemTagFontMenu());
1154                 createAndAppendFontSubMenu(FontMenuItem);
1155                 appendItem(FontMenuItem, m_contextMenu.get());
1156             }
1157 #if PLATFORM(MAC)
1158             ContextMenuItem SpeechMenuItem(SubmenuType, ContextMenuItemTagSpeechMenu, contextMenuItemTagSpeechMenu());
1159             createAndAppendSpeechSubMenu(SpeechMenuItem);
1160             appendItem(SpeechMenuItem, m_contextMenu.get());
1161 #endif
1162 #if PLATFORM(GTK)
1163             EditorClient* client = frame->editor()->client();
1164             if (client && client->shouldShowUnicodeMenu()) {
1165                 ContextMenuItem UnicodeMenuItem(SubmenuType, ContextMenuItemTagUnicode, contextMenuItemTagUnicode());
1166                 createAndAppendUnicodeSubMenu(UnicodeMenuItem);
1167                 appendItem(*separatorItem(), m_contextMenu.get());
1168                 appendItem(UnicodeMenuItem, m_contextMenu.get());
1169             }
1170 #else
1171             ContextMenuItem WritingDirectionMenuItem(SubmenuType, ContextMenuItemTagWritingDirectionMenu, 
1172                 contextMenuItemTagWritingDirectionMenu());
1173 #if !ENABLE(TIZEN_CONTEXT_MENU_TEMPORARY_FIX)
1174             createAndAppendWritingDirectionSubMenu(WritingDirectionMenuItem);
1175             appendItem(WritingDirectionMenuItem, m_contextMenu.get());
1176             if (Page* page = frame->page()) {
1177                 if (Settings* settings = page->settings()) {
1178                     bool includeTextDirectionSubmenu = settings->textDirectionSubmenuInclusionBehavior() == TextDirectionSubmenuAlwaysIncluded
1179                         || (settings->textDirectionSubmenuInclusionBehavior() == TextDirectionSubmenuAutomaticallyIncluded && frame->editor()->hasBidiSelection());
1180                     if (includeTextDirectionSubmenu) {
1181                         ContextMenuItem TextDirectionMenuItem(SubmenuType, ContextMenuItemTagTextDirectionMenu, 
1182                             contextMenuItemTagTextDirectionMenu());
1183                         createAndAppendTextDirectionSubMenu(TextDirectionMenuItem);
1184                         appendItem(TextDirectionMenuItem, m_contextMenu.get());
1185                     }
1186                 }
1187             }
1188 #endif //TIZEN_CONTEXT_MENU_TEMPORARY_FIX
1189 #endif
1190         }
1191     }
1192 }
1193
1194 #if ENABLE(INSPECTOR)
1195 void ContextMenuController::addInspectElementItem()
1196 {
1197     Node* node = m_hitTestResult.innerNonSharedNode();
1198     if (!node)
1199         return;
1200
1201     Frame* frame = node->document()->frame();
1202     if (!frame)
1203         return;
1204
1205     Page* page = frame->page();
1206     if (!page)
1207         return;
1208
1209     if (!page->inspectorController())
1210         return;
1211
1212     ContextMenuItem InspectElementItem(ActionType, ContextMenuItemTagInspectElement, contextMenuItemTagInspectElement());
1213 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
1214     if (!m_contextMenu->items().isEmpty())
1215 #else
1216     if (m_contextMenu->itemCount())
1217 #endif
1218         appendItem(*separatorItem(), m_contextMenu.get());
1219     appendItem(InspectElementItem, m_contextMenu.get());
1220 }
1221 #endif // ENABLE(INSPECTOR)
1222
1223 void ContextMenuController::checkOrEnableIfNeeded(ContextMenuItem& item) const
1224 {
1225     if (item.type() == SeparatorType)
1226         return;
1227     
1228     Frame* frame = m_hitTestResult.innerNonSharedNode()->document()->frame();
1229     if (!frame)
1230         return;
1231
1232     // Custom items already have proper checked and enabled values.
1233     if (ContextMenuItemBaseCustomTag <= item.action() && item.action() <= ContextMenuItemLastCustomTag)
1234         return;
1235
1236     bool shouldEnable = true;
1237     bool shouldCheck = false; 
1238
1239     switch (item.action()) {
1240         case ContextMenuItemTagCheckSpelling:
1241             shouldEnable = frame->editor()->canEdit();
1242             break;
1243         case ContextMenuItemTagDefaultDirection:
1244             shouldCheck = false;
1245             shouldEnable = false;
1246             break;
1247         case ContextMenuItemTagLeftToRight:
1248         case ContextMenuItemTagRightToLeft: {
1249             String direction = item.action() == ContextMenuItemTagLeftToRight ? "ltr" : "rtl";
1250             shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyDirection, direction) != FalseTriState;
1251             shouldEnable = true;
1252             break;
1253         }
1254         case ContextMenuItemTagTextDirectionDefault: {
1255             Editor::Command command = frame->editor()->command("MakeTextWritingDirectionNatural");
1256             shouldCheck = command.state() == TrueTriState;
1257             shouldEnable = command.isEnabled();
1258             break;
1259         }
1260         case ContextMenuItemTagTextDirectionLeftToRight: {
1261             Editor::Command command = frame->editor()->command("MakeTextWritingDirectionLeftToRight");
1262             shouldCheck = command.state() == TrueTriState;
1263             shouldEnable = command.isEnabled();
1264             break;
1265         }
1266         case ContextMenuItemTagTextDirectionRightToLeft: {
1267             Editor::Command command = frame->editor()->command("MakeTextWritingDirectionRightToLeft");
1268             shouldCheck = command.state() == TrueTriState;
1269             shouldEnable = command.isEnabled();
1270             break;
1271         }
1272         case ContextMenuItemTagCopy:
1273             shouldEnable = frame->editor()->canDHTMLCopy() || frame->editor()->canCopy();
1274             break;
1275         case ContextMenuItemTagCut:
1276             shouldEnable = frame->editor()->canDHTMLCut() || frame->editor()->canCut();
1277             break;
1278         case ContextMenuItemTagIgnoreSpelling:
1279         case ContextMenuItemTagLearnSpelling:
1280             shouldEnable = frame->selection()->isRange();
1281             break;
1282         case ContextMenuItemTagPaste:
1283             shouldEnable = frame->editor()->canDHTMLPaste() || frame->editor()->canPaste();
1284             break;
1285 #if ENABLE(TIZEN_CONTEXT_MENU_SELECT)
1286         case ContextMenuItemTagSelectWord:
1287             shouldEnable = frame->editor()->canSelectRange();
1288             break;
1289 #endif
1290 #if PLATFORM(GTK)
1291         case ContextMenuItemTagDelete:
1292             shouldEnable = frame->editor()->canDelete();
1293             break;
1294         case ContextMenuItemTagInputMethods:
1295         case ContextMenuItemTagUnicode:
1296         case ContextMenuItemTagUnicodeInsertLRMMark:
1297         case ContextMenuItemTagUnicodeInsertRLMMark:
1298         case ContextMenuItemTagUnicodeInsertLREMark:
1299         case ContextMenuItemTagUnicodeInsertRLEMark:
1300         case ContextMenuItemTagUnicodeInsertLROMark:
1301         case ContextMenuItemTagUnicodeInsertRLOMark:
1302         case ContextMenuItemTagUnicodeInsertPDFMark:
1303         case ContextMenuItemTagUnicodeInsertZWSMark:
1304         case ContextMenuItemTagUnicodeInsertZWJMark:
1305         case ContextMenuItemTagUnicodeInsertZWNJMark:
1306             shouldEnable = true;
1307             break;
1308 #endif
1309 #if PLATFORM(GTK) || PLATFORM(EFL)
1310         case ContextMenuItemTagSelectAll:
1311             shouldEnable = true;
1312             break;
1313 #endif
1314         case ContextMenuItemTagUnderline: {
1315             shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyWebkitTextDecorationsInEffect, "underline") != FalseTriState;
1316             shouldEnable = frame->editor()->canEditRichly();
1317             break;
1318         }
1319         case ContextMenuItemTagLookUpInDictionary:
1320             shouldEnable = frame->selection()->isRange();
1321             break;
1322         case ContextMenuItemTagCheckGrammarWithSpelling:
1323             if (frame->editor()->isGrammarCheckingEnabled())
1324                 shouldCheck = true;
1325             shouldEnable = true;
1326             break;
1327         case ContextMenuItemTagItalic: {
1328             shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyFontStyle, "italic") != FalseTriState;
1329             shouldEnable = frame->editor()->canEditRichly();
1330             break;
1331         }
1332         case ContextMenuItemTagBold: {
1333             shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyFontWeight, "bold") != FalseTriState;
1334             shouldEnable = frame->editor()->canEditRichly();
1335             break;
1336         }
1337         case ContextMenuItemTagOutline:
1338             shouldEnable = false;
1339             break;
1340         case ContextMenuItemTagShowSpellingPanel:
1341             if (frame->editor()->spellingPanelIsShowing())
1342                 item.setTitle(contextMenuItemTagShowSpellingPanel(false));
1343             else
1344                 item.setTitle(contextMenuItemTagShowSpellingPanel(true));
1345             shouldEnable = frame->editor()->canEdit();
1346             break;
1347         case ContextMenuItemTagNoGuessesFound:
1348             shouldEnable = false;
1349             break;
1350         case ContextMenuItemTagCheckSpellingWhileTyping:
1351             shouldCheck = frame->editor()->isContinuousSpellCheckingEnabled();
1352             break;
1353 #if PLATFORM(MAC)
1354         case ContextMenuItemTagSubstitutionsMenu:
1355         case ContextMenuItemTagTransformationsMenu:
1356             break;
1357         case ContextMenuItemTagShowSubstitutions:
1358             if (frame->editor()->substitutionsPanelIsShowing())
1359                 item.setTitle(contextMenuItemTagShowSubstitutions(false));
1360             else
1361                 item.setTitle(contextMenuItemTagShowSubstitutions(true));
1362             shouldEnable = frame->editor()->canEdit();
1363             break;
1364         case ContextMenuItemTagMakeUpperCase:
1365         case ContextMenuItemTagMakeLowerCase:
1366         case ContextMenuItemTagCapitalize:
1367         case ContextMenuItemTagChangeBack:
1368             shouldEnable = frame->editor()->canEdit();
1369             break;
1370         case ContextMenuItemTagCorrectSpellingAutomatically:
1371             shouldCheck = frame->editor()->isAutomaticSpellingCorrectionEnabled();
1372             break;
1373         case ContextMenuItemTagSmartCopyPaste:
1374             shouldCheck = frame->editor()->smartInsertDeleteEnabled();
1375             break;
1376         case ContextMenuItemTagSmartQuotes:
1377             shouldCheck = frame->editor()->isAutomaticQuoteSubstitutionEnabled();
1378             break;
1379         case ContextMenuItemTagSmartDashes:
1380             shouldCheck = frame->editor()->isAutomaticDashSubstitutionEnabled();
1381             break;
1382         case ContextMenuItemTagSmartLinks:
1383             shouldCheck = frame->editor()->isAutomaticLinkDetectionEnabled();
1384             break;
1385         case ContextMenuItemTagTextReplacement:
1386             shouldCheck = frame->editor()->isAutomaticTextReplacementEnabled();
1387             break;
1388         case ContextMenuItemTagStopSpeaking:
1389             shouldEnable = client() && client()->isSpeaking();
1390             break;
1391 #else // PLATFORM(MAC) ends here
1392         case ContextMenuItemTagStopSpeaking:
1393             break;
1394 #endif
1395 #if PLATFORM(GTK)
1396         case ContextMenuItemTagGoBack:
1397             shouldEnable = frame->page() && frame->page()->backForward()->canGoBackOrForward(-1);
1398             break;
1399         case ContextMenuItemTagGoForward:
1400             shouldEnable = frame->page() && frame->page()->backForward()->canGoBackOrForward(1);
1401             break;
1402         case ContextMenuItemTagStop:
1403             shouldEnable = frame->loader()->documentLoader()->isLoadingInAPISense();
1404             break;
1405         case ContextMenuItemTagReload:
1406             shouldEnable = !frame->loader()->documentLoader()->isLoadingInAPISense();
1407             break;
1408         case ContextMenuItemTagFontMenu:
1409             shouldEnable = frame->editor()->canEditRichly();
1410             break;
1411 #else
1412         case ContextMenuItemTagGoBack:
1413         case ContextMenuItemTagGoForward:
1414         case ContextMenuItemTagStop:
1415         case ContextMenuItemTagReload:
1416         case ContextMenuItemTagFontMenu:
1417 #endif
1418         case ContextMenuItemTagNoAction:
1419         case ContextMenuItemTagOpenLinkInNewWindow:
1420         case ContextMenuItemTagDownloadLinkToDisk:
1421         case ContextMenuItemTagCopyLinkToClipboard:
1422         case ContextMenuItemTagOpenImageInNewWindow:
1423         case ContextMenuItemTagDownloadImageToDisk:
1424         case ContextMenuItemTagCopyImageToClipboard:
1425 #if PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
1426         case ContextMenuItemTagCopyImageUrlToClipboard:
1427 #endif
1428             break;
1429         case ContextMenuItemTagOpenMediaInNewWindow:
1430             if (m_hitTestResult.mediaIsVideo())
1431                 item.setTitle(contextMenuItemTagOpenVideoInNewWindow());
1432             else
1433                 item.setTitle(contextMenuItemTagOpenAudioInNewWindow());
1434             break;
1435         case ContextMenuItemTagCopyMediaLinkToClipboard:
1436             if (m_hitTestResult.mediaIsVideo())
1437                 item.setTitle(contextMenuItemTagCopyVideoLinkToClipboard());
1438             else
1439                 item.setTitle(contextMenuItemTagCopyAudioLinkToClipboard());
1440             break;
1441         case ContextMenuItemTagToggleMediaControls:
1442             shouldCheck = m_hitTestResult.mediaControlsEnabled();
1443             break;
1444         case ContextMenuItemTagToggleMediaLoop:
1445             shouldCheck = m_hitTestResult.mediaLoopEnabled();
1446             break;
1447         case ContextMenuItemTagEnterVideoFullscreen:
1448             shouldEnable = m_hitTestResult.mediaSupportsFullscreen();
1449             break;
1450         case ContextMenuItemTagOpenFrameInNewWindow:
1451         case ContextMenuItemTagSpellingGuess:
1452         case ContextMenuItemTagOther:
1453         case ContextMenuItemTagSearchInSpotlight:
1454         case ContextMenuItemTagSearchWeb:
1455         case ContextMenuItemTagOpenWithDefaultApplication:
1456         case ContextMenuItemPDFActualSize:
1457         case ContextMenuItemPDFZoomIn:
1458         case ContextMenuItemPDFZoomOut:
1459         case ContextMenuItemPDFAutoSize:
1460         case ContextMenuItemPDFSinglePage:
1461         case ContextMenuItemPDFFacingPages:
1462         case ContextMenuItemPDFContinuous:
1463         case ContextMenuItemPDFNextPage:
1464         case ContextMenuItemPDFPreviousPage:
1465         case ContextMenuItemTagOpenLink:
1466         case ContextMenuItemTagIgnoreGrammar:
1467         case ContextMenuItemTagSpellingMenu:
1468         case ContextMenuItemTagShowFonts:
1469         case ContextMenuItemTagStyles:
1470         case ContextMenuItemTagShowColors:
1471         case ContextMenuItemTagSpeechMenu:
1472         case ContextMenuItemTagStartSpeaking:
1473         case ContextMenuItemTagWritingDirectionMenu:
1474         case ContextMenuItemTagTextDirectionMenu:
1475         case ContextMenuItemTagPDFSinglePageScrolling:
1476         case ContextMenuItemTagPDFFacingPagesScrolling:
1477 #if ENABLE(INSPECTOR)
1478         case ContextMenuItemTagInspectElement:
1479 #endif
1480 #if ENABLE(TIZEN_DRAG_SUPPORT)
1481         case ContextMenuItemTagDrag:
1482 #endif
1483         case ContextMenuItemBaseCustomTag:
1484         case ContextMenuItemCustomTagNoAction:
1485         case ContextMenuItemLastCustomTag:
1486         case ContextMenuItemBaseApplicationTag:
1487         case ContextMenuItemTagDictationAlternative:
1488             break;
1489         case ContextMenuItemTagMediaPlayPause:
1490             if (m_hitTestResult.mediaPlaying())
1491                 item.setTitle(contextMenuItemTagMediaPause());
1492             else
1493                 item.setTitle(contextMenuItemTagMediaPlay());
1494             break;
1495         case ContextMenuItemTagMediaMute:
1496             shouldEnable = m_hitTestResult.mediaHasAudio();
1497             shouldCheck = shouldEnable &&  m_hitTestResult.mediaMuted();
1498             break;
1499     }
1500
1501     item.setChecked(shouldCheck);
1502     item.setEnabled(shouldEnable);
1503 }
1504
1505 #if USE(ACCESSIBILITY_CONTEXT_MENUS)
1506 void ContextMenuController::showContextMenuAt(Frame* frame, const IntPoint& clickPoint)
1507 {
1508     // Simulate a click in the middle of the accessibility object.
1509     PlatformMouseEvent mouseEvent(clickPoint, clickPoint, RightButton, PlatformEvent::MousePressed, 1, false, false, false, false, currentTime());
1510     bool handled = frame->eventHandler()->sendContextMenuEvent(mouseEvent);
1511     if (handled && client())
1512         client()->showContextMenu();
1513 }
1514 #endif
1515
1516 } // namespace WebCore
1517
1518 #endif // ENABLE(CONTEXT_MENUS)