Merge "Use EwkView's variables instead of drawingScaleFactor and drawingScrollPositio...
[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 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
779     ContextMenuItem MediaUnMute(ActionType, ContextMenuItemTagMediaMute,
780         contextMenuItemTagMediaUnMute());
781 #endif
782     ContextMenuItem ToggleMediaControls(CheckableActionType, ContextMenuItemTagToggleMediaControls, 
783         contextMenuItemTagToggleMediaControls());
784     ContextMenuItem ToggleMediaLoop(CheckableActionType, ContextMenuItemTagToggleMediaLoop, 
785         contextMenuItemTagToggleMediaLoop());
786     ContextMenuItem EnterVideoFullscreen(ActionType, ContextMenuItemTagEnterVideoFullscreen, 
787         contextMenuItemTagEnterVideoFullscreen());
788 #if PLATFORM(MAC)
789     ContextMenuItem SearchSpotlightItem(ActionType, ContextMenuItemTagSearchInSpotlight, 
790         contextMenuItemTagSearchInSpotlight());
791 #endif
792 #if !PLATFORM(GTK)
793     ContextMenuItem SearchWebItem(ActionType, ContextMenuItemTagSearchWeb, contextMenuItemTagSearchWeb());
794 #endif
795     ContextMenuItem CopyItem(ActionType, ContextMenuItemTagCopy, contextMenuItemTagCopy());
796     ContextMenuItem BackItem(ActionType, ContextMenuItemTagGoBack, contextMenuItemTagGoBack());
797     ContextMenuItem ForwardItem(ActionType, ContextMenuItemTagGoForward,  contextMenuItemTagGoForward());
798     ContextMenuItem StopItem(ActionType, ContextMenuItemTagStop, contextMenuItemTagStop());
799     ContextMenuItem ReloadItem(ActionType, ContextMenuItemTagReload, contextMenuItemTagReload());
800     ContextMenuItem OpenFrameItem(ActionType, ContextMenuItemTagOpenFrameInNewWindow, 
801         contextMenuItemTagOpenFrameInNewWindow());
802     ContextMenuItem NoGuessesItem(ActionType, ContextMenuItemTagNoGuessesFound, 
803         contextMenuItemTagNoGuessesFound());
804     ContextMenuItem IgnoreSpellingItem(ActionType, ContextMenuItemTagIgnoreSpelling, 
805         contextMenuItemTagIgnoreSpelling());
806     ContextMenuItem LearnSpellingItem(ActionType, ContextMenuItemTagLearnSpelling, 
807         contextMenuItemTagLearnSpelling());
808     ContextMenuItem IgnoreGrammarItem(ActionType, ContextMenuItemTagIgnoreGrammar, 
809         contextMenuItemTagIgnoreGrammar());
810     ContextMenuItem CutItem(ActionType, ContextMenuItemTagCut, contextMenuItemTagCut());
811     ContextMenuItem PasteItem(ActionType, ContextMenuItemTagPaste, contextMenuItemTagPaste());
812 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
813     ContextMenuItem ClipboardItem(ActionType, ContextMenuItemTagClipboard, contextMenuItemTagClipboard());
814 #endif
815 #if PLATFORM(GTK)
816     ContextMenuItem DeleteItem(ActionType, ContextMenuItemTagDelete, contextMenuItemTagDelete());
817 #endif
818 #if PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL)
819     ContextMenuItem SelectAllItem(ActionType, ContextMenuItemTagSelectAll, contextMenuItemTagSelectAll());
820 #endif
821 #if ENABLE(TIZEN_CONTEXT_MENU_SELECT)
822     ContextMenuItem SelectWordItem(ActionType, ContextMenuItemTagSelectWord, contextMenuItemTagSelectWord());
823 #endif
824 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
825     ContextMenuItem TextSelectionModeItem(ActionType, ContextMenuItemTagTextSelectionMode, contextMenuItemTagTextSelectionMode());
826 #endif
827 #if ENABLE(TIZEN_DRAG_SUPPORT)
828     ContextMenuItem DragItem(ActionType, ContextMenuItemTagDrag, contextMenuItemTagDrag());
829 #endif
830
831     Node* node = m_hitTestResult.innerNonSharedNode();
832     if (!node)
833         return;
834 #if PLATFORM(GTK)
835     if (!m_hitTestResult.isContentEditable() && (node->isElementNode() && static_cast<Element*>(node)->isFormControlElement()))
836         return;
837 #endif
838     Frame* frame = node->document()->frame();
839     if (!frame)
840         return;
841
842     if (!m_hitTestResult.isContentEditable()) {
843         FrameLoader* loader = frame->loader();
844         KURL linkURL = m_hitTestResult.absoluteLinkURL();
845         if (!linkURL.isEmpty()) {
846 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
847             if (m_hitTestResult.isSelected()) {
848                 if (selectionContainsPossibleWord(frame)) {
849                     appendItem(SearchWebItem, m_contextMenu.get());
850                 }
851                 appendItem(CopyItem, m_contextMenu.get());
852                 return;
853             }
854 #endif
855 #if ENABLE(TIZEN_DOWNLOAD_LINK_FILTER)
856             if (loader->client()->canHandleRequest(ResourceRequest(linkURL)) &&
857                (linkURL.protocolIs("http") || linkURL.protocolIs("https") || linkURL.protocolIs("ftp") || linkURL.protocolIs("ftps"))) {
858 #else
859             if (loader->client()->canHandleRequest(ResourceRequest(linkURL))) {
860 #endif
861                 appendItem(OpenLinkItem, m_contextMenu.get());
862                 appendItem(OpenLinkInNewWindowItem, m_contextMenu.get());
863                 appendItem(DownloadFileItem, m_contextMenu.get());
864             }
865 #if PLATFORM(QT)
866             if (m_hitTestResult.isSelected()) 
867                 appendItem(CopyItem, m_contextMenu.get());
868 #endif
869             appendItem(CopyLinkItem, m_contextMenu.get());
870         }
871
872         KURL imageURL = m_hitTestResult.absoluteImageURL();
873         if (!imageURL.isEmpty()) {
874             if (!linkURL.isEmpty())
875                 appendItem(*separatorItem(), m_contextMenu.get());
876
877             appendItem(OpenImageInNewWindowItem, m_contextMenu.get());
878             appendItem(DownloadImageItem, m_contextMenu.get());
879             if (imageURL.isLocalFile() || m_hitTestResult.image())
880                 appendItem(CopyImageItem, m_contextMenu.get());
881 #if PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
882             appendItem(CopyImageUrlItem, m_contextMenu.get());
883 #endif
884         }
885
886         KURL mediaURL = m_hitTestResult.absoluteMediaURL();
887         if (!mediaURL.isEmpty()) {
888             if (!linkURL.isEmpty() || !imageURL.isEmpty())
889                 appendItem(*separatorItem(), m_contextMenu.get());
890
891             appendItem(MediaPlayPause, m_contextMenu.get());
892 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
893             if (m_hitTestResult.mediaMuted())
894                 appendItem(MediaUnMute, m_contextMenu.get());
895             else
896                 appendItem(MediaMute, m_contextMenu.get());
897 #else
898             appendItem(MediaMute, m_contextMenu.get());
899 #endif
900             appendItem(ToggleMediaControls, m_contextMenu.get());
901             appendItem(ToggleMediaLoop, m_contextMenu.get());
902             appendItem(EnterVideoFullscreen, m_contextMenu.get());
903
904             appendItem(*separatorItem(), m_contextMenu.get());
905             appendItem(CopyMediaLinkItem, m_contextMenu.get());
906             appendItem(OpenMediaInNewWindowItem, m_contextMenu.get());
907         }
908
909 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
910         if (!linkURL.isEmpty() && imageURL.isEmpty() && mediaURL.isEmpty())
911             appendItem(TextSelectionModeItem, m_contextMenu.get());
912 #endif
913
914 #if ENABLE(TIZEN_DRAG_SUPPORT)
915         if (imageURL.isEmpty() && linkURL.isEmpty() && mediaURL.isEmpty() && !m_hitTestResult.isDragSupport()) {
916 #else
917         if (imageURL.isEmpty() && linkURL.isEmpty() && mediaURL.isEmpty()) {
918 #endif
919             if (m_hitTestResult.isSelected()) {
920                 if (selectionContainsPossibleWord(frame)) {
921 #if PLATFORM(MAC)
922                     String selectedString = frame->displayStringModifiedByEncoding(frame->editor()->selectedText());
923                     ContextMenuItem LookUpInDictionaryItem(ActionType, ContextMenuItemTagLookUpInDictionary, contextMenuItemTagLookUpInDictionary(selectedString));
924
925 #if INCLUDE_SPOTLIGHT_CONTEXT_MENU_ITEM
926                     appendItem(SearchSpotlightItem, m_contextMenu.get());
927 #else
928                     appendItem(LookUpInDictionaryItem, m_contextMenu.get());
929 #endif
930 #endif
931
932 #if !PLATFORM(GTK)
933                     appendItem(SearchWebItem, m_contextMenu.get());
934                     appendItem(*separatorItem(), m_contextMenu.get());
935 #endif
936
937 #if PLATFORM(MAC) && INCLUDE_SPOTLIGHT_CONTEXT_MENU_ITEM
938                     appendItem(LookUpInDictionaryItem, m_contextMenu.get());
939                     appendItem(*separatorItem(), m_contextMenu.get());
940 #endif
941                 }
942
943                 appendItem(CopyItem, m_contextMenu.get());
944 #if PLATFORM(MAC)
945                 appendItem(*separatorItem(), m_contextMenu.get());
946
947                 ContextMenuItem SpeechMenuItem(SubmenuType, ContextMenuItemTagSpeechMenu, contextMenuItemTagSpeechMenu());
948                 createAndAppendSpeechSubMenu(SpeechMenuItem);
949                 appendItem(SpeechMenuItem, m_contextMenu.get());
950 #endif                
951             } else {
952 #if ENABLE(INSPECTOR)
953                 if (!(frame->page() && frame->page()->inspectorController()->hasInspectorFrontendClient())) {
954 #endif
955
956                 // In GTK+ unavailable items are not hidden but insensitive
957 #if PLATFORM(GTK)
958                 appendItem(BackItem, m_contextMenu.get());
959                 appendItem(ForwardItem, m_contextMenu.get());
960                 appendItem(StopItem, m_contextMenu.get());
961                 appendItem(ReloadItem, m_contextMenu.get());
962 #else
963                 if (frame->page() && frame->page()->backForward()->canGoBackOrForward(-1))
964                     appendItem(BackItem, m_contextMenu.get());
965
966                 if (frame->page() && frame->page()->backForward()->canGoBackOrForward(1))
967                     appendItem(ForwardItem, m_contextMenu.get());
968
969                 // use isLoadingInAPISense rather than isLoading because Stop/Reload are
970                 // intended to match WebKit's API, not WebCore's internal notion of loading status
971                 if (loader->documentLoader()->isLoadingInAPISense())
972                     appendItem(StopItem, m_contextMenu.get());
973                 else
974                     appendItem(ReloadItem, m_contextMenu.get());
975 #endif
976 #if ENABLE(INSPECTOR)
977                 }
978 #endif
979
980                 if (frame->page() && frame != frame->page()->mainFrame())
981                     appendItem(OpenFrameItem, m_contextMenu.get());
982             }
983         }
984 #if ENABLE(TIZEN_DRAG_SUPPORT)
985         if (frame->page() && m_hitTestResult.isDragSupport()) {
986             TIZEN_LOGI("appendItem for drag");
987             appendItem(DragItem, m_contextMenu.get());
988         }
989 #endif
990     } else { // Make an editing context menu
991         FrameSelection* selection = frame->selection();
992         bool inPasswordField = selection->isInPasswordField();
993         if (!inPasswordField) {
994             bool haveContextMenuItemsForMisspellingOrGrammer = false;
995             bool spellCheckingEnabled = frame->editor()->isSpellCheckingEnabledFor(node);
996             if (spellCheckingEnabled) {
997                 // Consider adding spelling-related or grammar-related context menu items (never both, since a single selected range
998                 // is never considered a misspelling and bad grammar at the same time)
999 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
1000                 bool misspelling = false;
1001                 bool badGrammar = false;
1002 #else
1003                 bool misspelling;
1004                 bool badGrammar;
1005 #endif
1006                 Vector<String> guesses = frame->editor()->guessesForMisspelledOrUngrammaticalSelection(misspelling, badGrammar);
1007                 if (misspelling || badGrammar) {
1008                     size_t size = guesses.size();
1009                     if (!size) {
1010                         // If there's bad grammar but no suggestions (e.g., repeated word), just leave off the suggestions
1011                         // list and trailing separator rather than adding a "No Guesses Found" item (matches AppKit)
1012                         if (misspelling) {
1013                             appendItem(NoGuessesItem, m_contextMenu.get());
1014                             appendItem(*separatorItem(), m_contextMenu.get());
1015                         }
1016                     } else {
1017                         for (unsigned i = 0; i < size; i++) {
1018                             const String &guess = guesses[i];
1019                             if (!guess.isEmpty()) {
1020                                 ContextMenuItem item(ActionType, ContextMenuItemTagSpellingGuess, guess);
1021                                 appendItem(item, m_contextMenu.get());
1022                             }
1023                         }
1024                         appendItem(*separatorItem(), m_contextMenu.get());
1025                     }
1026                     if (misspelling) {
1027                         appendItem(IgnoreSpellingItem, m_contextMenu.get());
1028                         appendItem(LearnSpellingItem, m_contextMenu.get());
1029                     } else
1030                         appendItem(IgnoreGrammarItem, m_contextMenu.get());
1031                     appendItem(*separatorItem(), m_contextMenu.get());
1032                     haveContextMenuItemsForMisspellingOrGrammer = true;
1033 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
1034                 } else {
1035                     // If the string was autocorrected, generate a contextual menu item allowing it to be changed back.
1036                     String replacedString = m_hitTestResult.replacedString();
1037                     if (!replacedString.isEmpty()) {
1038                         ContextMenuItem item(ActionType, ContextMenuItemTagChangeBack, contextMenuItemTagChangeBack(replacedString));
1039                         appendItem(item, m_contextMenu.get());
1040                         appendItem(*separatorItem(), m_contextMenu.get());
1041                         haveContextMenuItemsForMisspellingOrGrammer = true;
1042                     }
1043 #endif
1044                 }
1045             }
1046
1047             if (!haveContextMenuItemsForMisspellingOrGrammer) {
1048                 // Spelling and grammar checking is mutually exclusive with dictation alternatives.
1049                 Vector<String> dictationAlternatives = m_hitTestResult.dictationAlternatives();
1050                 if (!dictationAlternatives.isEmpty()) {
1051                     for (size_t i = 0; i < dictationAlternatives.size(); ++i) {
1052                         ContextMenuItem item(ActionType, ContextMenuItemTagDictationAlternative, dictationAlternatives[i]);
1053                         appendItem(item, m_contextMenu.get());
1054                     }
1055                     appendItem(*separatorItem(), m_contextMenu.get());
1056                 }
1057             }
1058         }
1059
1060         FrameLoader* loader = frame->loader();
1061         KURL linkURL = m_hitTestResult.absoluteLinkURL();
1062         if (!linkURL.isEmpty()) {
1063             if (loader->client()->canHandleRequest(ResourceRequest(linkURL))) {
1064                 appendItem(OpenLinkItem, m_contextMenu.get());
1065                 appendItem(OpenLinkInNewWindowItem, m_contextMenu.get());
1066                 appendItem(DownloadFileItem, m_contextMenu.get());
1067             }
1068             appendItem(CopyLinkItem, m_contextMenu.get());
1069             appendItem(*separatorItem(), m_contextMenu.get());
1070         }
1071
1072         if (m_hitTestResult.isSelected() && !inPasswordField && selectionContainsPossibleWord(frame)) {
1073 #if PLATFORM(MAC)
1074             String selectedString = frame->displayStringModifiedByEncoding(frame->editor()->selectedText());
1075             ContextMenuItem LookUpInDictionaryItem(ActionType, ContextMenuItemTagLookUpInDictionary, contextMenuItemTagLookUpInDictionary(selectedString));
1076
1077 #if INCLUDE_SPOTLIGHT_CONTEXT_MENU_ITEM
1078             appendItem(SearchSpotlightItem, m_contextMenu.get());
1079 #else
1080             appendItem(LookUpInDictionaryItem, m_contextMenu.get());
1081 #endif
1082 #endif
1083
1084 #if !PLATFORM(GTK)
1085             appendItem(SearchWebItem, m_contextMenu.get());
1086             appendItem(*separatorItem(), m_contextMenu.get());
1087 #endif
1088
1089 #if PLATFORM(MAC) && INCLUDE_SPOTLIGHT_CONTEXT_MENU_ITEM
1090             appendItem(LookUpInDictionaryItem, m_contextMenu.get());
1091             appendItem(*separatorItem(), m_contextMenu.get());
1092 #endif
1093         }
1094
1095 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
1096         if (m_hitTestResult.isSelected() && !inPasswordField) {
1097             appendItem(CutItem, m_contextMenu.get());
1098             appendItem(CopyItem, m_contextMenu.get());
1099         }
1100 #else
1101         appendItem(CutItem, m_contextMenu.get());
1102         appendItem(CopyItem, m_contextMenu.get());
1103 #endif
1104         appendItem(PasteItem, m_contextMenu.get());
1105 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
1106         appendItem(ClipboardItem, m_contextMenu.get());
1107 #endif
1108 #if PLATFORM(GTK)
1109         appendItem(DeleteItem, m_contextMenu.get());
1110         appendItem(*separatorItem(), m_contextMenu.get());
1111 #endif
1112 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
1113         if (frame->selection()) {
1114             Node* baseNode = frame->selection()->base().containerNode();
1115             if (baseNode && baseNode->isTextNode() && (!(baseNode->textContent().isEmpty()))) {
1116                 if (inPasswordField) {
1117                     if (!m_hitTestResult.isSelected())
1118                         appendItem(SelectWordItem, m_contextMenu.get());
1119                 } else {
1120 #endif
1121 #if PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL)
1122                     appendItem(SelectAllItem, m_contextMenu.get());
1123 #endif
1124 #if ENABLE(TIZEN_CONTEXT_MENU_SELECT)
1125                     appendItem(SelectWordItem, m_contextMenu.get());
1126 #endif
1127 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
1128                 }
1129             }
1130         }
1131 #endif
1132
1133         if (!inPasswordField) {
1134 #if !PLATFORM(GTK)
1135 #if !ENABLE(TIZEN_CONTEXT_MENU_TEMPORARY_FIX)
1136             appendItem(*separatorItem(), m_contextMenu.get());
1137             ContextMenuItem SpellingAndGrammarMenuItem(SubmenuType, ContextMenuItemTagSpellingMenu, 
1138                 contextMenuItemTagSpellingMenu());
1139             createAndAppendSpellingAndGrammarSubMenu(SpellingAndGrammarMenuItem);
1140             appendItem(SpellingAndGrammarMenuItem, m_contextMenu.get());
1141 #endif //TIZEN_CONTEXT_MENU_TEMPORARY_FIX
1142 #endif
1143 #if PLATFORM(MAC)
1144             ContextMenuItem substitutionsMenuItem(SubmenuType, ContextMenuItemTagSubstitutionsMenu, 
1145                 contextMenuItemTagSubstitutionsMenu());
1146             createAndAppendSubstitutionsSubMenu(substitutionsMenuItem);
1147             appendItem(substitutionsMenuItem, m_contextMenu.get());
1148             ContextMenuItem transformationsMenuItem(SubmenuType, ContextMenuItemTagTransformationsMenu, 
1149                 contextMenuItemTagTransformationsMenu());
1150             createAndAppendTransformationsSubMenu(transformationsMenuItem);
1151             appendItem(transformationsMenuItem, m_contextMenu.get());
1152 #endif
1153 #if PLATFORM(GTK)
1154             bool shouldShowFontMenu = frame->editor()->canEditRichly();
1155 #else
1156 #if ENABLE(TIZEN_CONTEXT_MENU_TEMPORARY_FIX)
1157             bool shouldShowFontMenu = false;
1158 #else
1159             bool shouldShowFontMenu = true;
1160 #endif //TIZEN_CONTEXT_MENU_TEMPORARY_FIX
1161 #endif
1162             if (shouldShowFontMenu) {
1163                 ContextMenuItem FontMenuItem(SubmenuType, ContextMenuItemTagFontMenu, 
1164                     contextMenuItemTagFontMenu());
1165                 createAndAppendFontSubMenu(FontMenuItem);
1166                 appendItem(FontMenuItem, m_contextMenu.get());
1167             }
1168 #if PLATFORM(MAC)
1169             ContextMenuItem SpeechMenuItem(SubmenuType, ContextMenuItemTagSpeechMenu, contextMenuItemTagSpeechMenu());
1170             createAndAppendSpeechSubMenu(SpeechMenuItem);
1171             appendItem(SpeechMenuItem, m_contextMenu.get());
1172 #endif
1173 #if PLATFORM(GTK)
1174             EditorClient* client = frame->editor()->client();
1175             if (client && client->shouldShowUnicodeMenu()) {
1176                 ContextMenuItem UnicodeMenuItem(SubmenuType, ContextMenuItemTagUnicode, contextMenuItemTagUnicode());
1177                 createAndAppendUnicodeSubMenu(UnicodeMenuItem);
1178                 appendItem(*separatorItem(), m_contextMenu.get());
1179                 appendItem(UnicodeMenuItem, m_contextMenu.get());
1180             }
1181 #else
1182             ContextMenuItem WritingDirectionMenuItem(SubmenuType, ContextMenuItemTagWritingDirectionMenu, 
1183                 contextMenuItemTagWritingDirectionMenu());
1184 #if !ENABLE(TIZEN_CONTEXT_MENU_TEMPORARY_FIX)
1185             createAndAppendWritingDirectionSubMenu(WritingDirectionMenuItem);
1186             appendItem(WritingDirectionMenuItem, m_contextMenu.get());
1187             if (Page* page = frame->page()) {
1188                 if (Settings* settings = page->settings()) {
1189                     bool includeTextDirectionSubmenu = settings->textDirectionSubmenuInclusionBehavior() == TextDirectionSubmenuAlwaysIncluded
1190                         || (settings->textDirectionSubmenuInclusionBehavior() == TextDirectionSubmenuAutomaticallyIncluded && frame->editor()->hasBidiSelection());
1191                     if (includeTextDirectionSubmenu) {
1192                         ContextMenuItem TextDirectionMenuItem(SubmenuType, ContextMenuItemTagTextDirectionMenu, 
1193                             contextMenuItemTagTextDirectionMenu());
1194                         createAndAppendTextDirectionSubMenu(TextDirectionMenuItem);
1195                         appendItem(TextDirectionMenuItem, m_contextMenu.get());
1196                     }
1197                 }
1198             }
1199 #endif //TIZEN_CONTEXT_MENU_TEMPORARY_FIX
1200 #endif
1201         }
1202     }
1203 }
1204
1205 #if ENABLE(INSPECTOR)
1206 void ContextMenuController::addInspectElementItem()
1207 {
1208     Node* node = m_hitTestResult.innerNonSharedNode();
1209     if (!node)
1210         return;
1211
1212     Frame* frame = node->document()->frame();
1213     if (!frame)
1214         return;
1215
1216     Page* page = frame->page();
1217     if (!page)
1218         return;
1219
1220     if (!page->inspectorController())
1221         return;
1222
1223     ContextMenuItem InspectElementItem(ActionType, ContextMenuItemTagInspectElement, contextMenuItemTagInspectElement());
1224 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
1225     if (!m_contextMenu->items().isEmpty())
1226 #else
1227     if (m_contextMenu->itemCount())
1228 #endif
1229         appendItem(*separatorItem(), m_contextMenu.get());
1230     appendItem(InspectElementItem, m_contextMenu.get());
1231 }
1232 #endif // ENABLE(INSPECTOR)
1233
1234 void ContextMenuController::checkOrEnableIfNeeded(ContextMenuItem& item) const
1235 {
1236     if (item.type() == SeparatorType)
1237         return;
1238     
1239     Frame* frame = m_hitTestResult.innerNonSharedNode()->document()->frame();
1240     if (!frame)
1241         return;
1242
1243     // Custom items already have proper checked and enabled values.
1244     if (ContextMenuItemBaseCustomTag <= item.action() && item.action() <= ContextMenuItemLastCustomTag)
1245         return;
1246
1247     bool shouldEnable = true;
1248     bool shouldCheck = false; 
1249
1250     switch (item.action()) {
1251         case ContextMenuItemTagCheckSpelling:
1252             shouldEnable = frame->editor()->canEdit();
1253             break;
1254         case ContextMenuItemTagDefaultDirection:
1255             shouldCheck = false;
1256             shouldEnable = false;
1257             break;
1258         case ContextMenuItemTagLeftToRight:
1259         case ContextMenuItemTagRightToLeft: {
1260             String direction = item.action() == ContextMenuItemTagLeftToRight ? "ltr" : "rtl";
1261             shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyDirection, direction) != FalseTriState;
1262             shouldEnable = true;
1263             break;
1264         }
1265         case ContextMenuItemTagTextDirectionDefault: {
1266             Editor::Command command = frame->editor()->command("MakeTextWritingDirectionNatural");
1267             shouldCheck = command.state() == TrueTriState;
1268             shouldEnable = command.isEnabled();
1269             break;
1270         }
1271         case ContextMenuItemTagTextDirectionLeftToRight: {
1272             Editor::Command command = frame->editor()->command("MakeTextWritingDirectionLeftToRight");
1273             shouldCheck = command.state() == TrueTriState;
1274             shouldEnable = command.isEnabled();
1275             break;
1276         }
1277         case ContextMenuItemTagTextDirectionRightToLeft: {
1278             Editor::Command command = frame->editor()->command("MakeTextWritingDirectionRightToLeft");
1279             shouldCheck = command.state() == TrueTriState;
1280             shouldEnable = command.isEnabled();
1281             break;
1282         }
1283         case ContextMenuItemTagCopy:
1284             shouldEnable = frame->editor()->canDHTMLCopy() || frame->editor()->canCopy();
1285             break;
1286         case ContextMenuItemTagCut:
1287             shouldEnable = frame->editor()->canDHTMLCut() || frame->editor()->canCut();
1288             break;
1289         case ContextMenuItemTagIgnoreSpelling:
1290         case ContextMenuItemTagLearnSpelling:
1291             shouldEnable = frame->selection()->isRange();
1292             break;
1293         case ContextMenuItemTagPaste:
1294             shouldEnable = frame->editor()->canDHTMLPaste() || frame->editor()->canPaste();
1295             break;
1296 #if ENABLE(TIZEN_CONTEXT_MENU_SELECT)
1297         case ContextMenuItemTagSelectWord:
1298             shouldEnable = frame->editor()->canSelectRange();
1299             break;
1300 #endif
1301 #if PLATFORM(GTK)
1302         case ContextMenuItemTagDelete:
1303             shouldEnable = frame->editor()->canDelete();
1304             break;
1305         case ContextMenuItemTagInputMethods:
1306         case ContextMenuItemTagUnicode:
1307         case ContextMenuItemTagUnicodeInsertLRMMark:
1308         case ContextMenuItemTagUnicodeInsertRLMMark:
1309         case ContextMenuItemTagUnicodeInsertLREMark:
1310         case ContextMenuItemTagUnicodeInsertRLEMark:
1311         case ContextMenuItemTagUnicodeInsertLROMark:
1312         case ContextMenuItemTagUnicodeInsertRLOMark:
1313         case ContextMenuItemTagUnicodeInsertPDFMark:
1314         case ContextMenuItemTagUnicodeInsertZWSMark:
1315         case ContextMenuItemTagUnicodeInsertZWJMark:
1316         case ContextMenuItemTagUnicodeInsertZWNJMark:
1317             shouldEnable = true;
1318             break;
1319 #endif
1320 #if PLATFORM(GTK) || PLATFORM(EFL)
1321         case ContextMenuItemTagSelectAll:
1322             shouldEnable = true;
1323             break;
1324 #endif
1325         case ContextMenuItemTagUnderline: {
1326             shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyWebkitTextDecorationsInEffect, "underline") != FalseTriState;
1327             shouldEnable = frame->editor()->canEditRichly();
1328             break;
1329         }
1330         case ContextMenuItemTagLookUpInDictionary:
1331             shouldEnable = frame->selection()->isRange();
1332             break;
1333         case ContextMenuItemTagCheckGrammarWithSpelling:
1334             if (frame->editor()->isGrammarCheckingEnabled())
1335                 shouldCheck = true;
1336             shouldEnable = true;
1337             break;
1338         case ContextMenuItemTagItalic: {
1339             shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyFontStyle, "italic") != FalseTriState;
1340             shouldEnable = frame->editor()->canEditRichly();
1341             break;
1342         }
1343         case ContextMenuItemTagBold: {
1344             shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyFontWeight, "bold") != FalseTriState;
1345             shouldEnable = frame->editor()->canEditRichly();
1346             break;
1347         }
1348         case ContextMenuItemTagOutline:
1349             shouldEnable = false;
1350             break;
1351         case ContextMenuItemTagShowSpellingPanel:
1352             if (frame->editor()->spellingPanelIsShowing())
1353                 item.setTitle(contextMenuItemTagShowSpellingPanel(false));
1354             else
1355                 item.setTitle(contextMenuItemTagShowSpellingPanel(true));
1356             shouldEnable = frame->editor()->canEdit();
1357             break;
1358         case ContextMenuItemTagNoGuessesFound:
1359             shouldEnable = false;
1360             break;
1361         case ContextMenuItemTagCheckSpellingWhileTyping:
1362             shouldCheck = frame->editor()->isContinuousSpellCheckingEnabled();
1363             break;
1364 #if PLATFORM(MAC)
1365         case ContextMenuItemTagSubstitutionsMenu:
1366         case ContextMenuItemTagTransformationsMenu:
1367             break;
1368         case ContextMenuItemTagShowSubstitutions:
1369             if (frame->editor()->substitutionsPanelIsShowing())
1370                 item.setTitle(contextMenuItemTagShowSubstitutions(false));
1371             else
1372                 item.setTitle(contextMenuItemTagShowSubstitutions(true));
1373             shouldEnable = frame->editor()->canEdit();
1374             break;
1375         case ContextMenuItemTagMakeUpperCase:
1376         case ContextMenuItemTagMakeLowerCase:
1377         case ContextMenuItemTagCapitalize:
1378         case ContextMenuItemTagChangeBack:
1379             shouldEnable = frame->editor()->canEdit();
1380             break;
1381         case ContextMenuItemTagCorrectSpellingAutomatically:
1382             shouldCheck = frame->editor()->isAutomaticSpellingCorrectionEnabled();
1383             break;
1384         case ContextMenuItemTagSmartCopyPaste:
1385             shouldCheck = frame->editor()->smartInsertDeleteEnabled();
1386             break;
1387         case ContextMenuItemTagSmartQuotes:
1388             shouldCheck = frame->editor()->isAutomaticQuoteSubstitutionEnabled();
1389             break;
1390         case ContextMenuItemTagSmartDashes:
1391             shouldCheck = frame->editor()->isAutomaticDashSubstitutionEnabled();
1392             break;
1393         case ContextMenuItemTagSmartLinks:
1394             shouldCheck = frame->editor()->isAutomaticLinkDetectionEnabled();
1395             break;
1396         case ContextMenuItemTagTextReplacement:
1397             shouldCheck = frame->editor()->isAutomaticTextReplacementEnabled();
1398             break;
1399         case ContextMenuItemTagStopSpeaking:
1400             shouldEnable = client() && client()->isSpeaking();
1401             break;
1402 #else // PLATFORM(MAC) ends here
1403         case ContextMenuItemTagStopSpeaking:
1404             break;
1405 #endif
1406 #if PLATFORM(GTK)
1407         case ContextMenuItemTagGoBack:
1408             shouldEnable = frame->page() && frame->page()->backForward()->canGoBackOrForward(-1);
1409             break;
1410         case ContextMenuItemTagGoForward:
1411             shouldEnable = frame->page() && frame->page()->backForward()->canGoBackOrForward(1);
1412             break;
1413         case ContextMenuItemTagStop:
1414             shouldEnable = frame->loader()->documentLoader()->isLoadingInAPISense();
1415             break;
1416         case ContextMenuItemTagReload:
1417             shouldEnable = !frame->loader()->documentLoader()->isLoadingInAPISense();
1418             break;
1419         case ContextMenuItemTagFontMenu:
1420             shouldEnable = frame->editor()->canEditRichly();
1421             break;
1422 #else
1423         case ContextMenuItemTagGoBack:
1424         case ContextMenuItemTagGoForward:
1425         case ContextMenuItemTagStop:
1426         case ContextMenuItemTagReload:
1427         case ContextMenuItemTagFontMenu:
1428 #endif
1429         case ContextMenuItemTagNoAction:
1430         case ContextMenuItemTagOpenLinkInNewWindow:
1431         case ContextMenuItemTagDownloadLinkToDisk:
1432         case ContextMenuItemTagCopyLinkToClipboard:
1433         case ContextMenuItemTagOpenImageInNewWindow:
1434         case ContextMenuItemTagDownloadImageToDisk:
1435         case ContextMenuItemTagCopyImageToClipboard:
1436 #if PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
1437         case ContextMenuItemTagCopyImageUrlToClipboard:
1438 #endif
1439             break;
1440         case ContextMenuItemTagOpenMediaInNewWindow:
1441             if (m_hitTestResult.mediaIsVideo())
1442                 item.setTitle(contextMenuItemTagOpenVideoInNewWindow());
1443             else
1444                 item.setTitle(contextMenuItemTagOpenAudioInNewWindow());
1445             break;
1446         case ContextMenuItemTagCopyMediaLinkToClipboard:
1447             if (m_hitTestResult.mediaIsVideo())
1448                 item.setTitle(contextMenuItemTagCopyVideoLinkToClipboard());
1449             else
1450                 item.setTitle(contextMenuItemTagCopyAudioLinkToClipboard());
1451             break;
1452         case ContextMenuItemTagToggleMediaControls:
1453             shouldCheck = m_hitTestResult.mediaControlsEnabled();
1454             break;
1455         case ContextMenuItemTagToggleMediaLoop:
1456             shouldCheck = m_hitTestResult.mediaLoopEnabled();
1457             break;
1458         case ContextMenuItemTagEnterVideoFullscreen:
1459             shouldEnable = m_hitTestResult.mediaSupportsFullscreen();
1460             break;
1461         case ContextMenuItemTagOpenFrameInNewWindow:
1462         case ContextMenuItemTagSpellingGuess:
1463         case ContextMenuItemTagOther:
1464         case ContextMenuItemTagSearchInSpotlight:
1465         case ContextMenuItemTagSearchWeb:
1466         case ContextMenuItemTagOpenWithDefaultApplication:
1467         case ContextMenuItemPDFActualSize:
1468         case ContextMenuItemPDFZoomIn:
1469         case ContextMenuItemPDFZoomOut:
1470         case ContextMenuItemPDFAutoSize:
1471         case ContextMenuItemPDFSinglePage:
1472         case ContextMenuItemPDFFacingPages:
1473         case ContextMenuItemPDFContinuous:
1474         case ContextMenuItemPDFNextPage:
1475         case ContextMenuItemPDFPreviousPage:
1476         case ContextMenuItemTagOpenLink:
1477         case ContextMenuItemTagIgnoreGrammar:
1478         case ContextMenuItemTagSpellingMenu:
1479         case ContextMenuItemTagShowFonts:
1480         case ContextMenuItemTagStyles:
1481         case ContextMenuItemTagShowColors:
1482         case ContextMenuItemTagSpeechMenu:
1483         case ContextMenuItemTagStartSpeaking:
1484         case ContextMenuItemTagWritingDirectionMenu:
1485         case ContextMenuItemTagTextDirectionMenu:
1486         case ContextMenuItemTagPDFSinglePageScrolling:
1487         case ContextMenuItemTagPDFFacingPagesScrolling:
1488 #if ENABLE(INSPECTOR)
1489         case ContextMenuItemTagInspectElement:
1490 #endif
1491 #if ENABLE(TIZEN_DRAG_SUPPORT)
1492         case ContextMenuItemTagDrag:
1493 #endif
1494         case ContextMenuItemBaseCustomTag:
1495         case ContextMenuItemCustomTagNoAction:
1496         case ContextMenuItemLastCustomTag:
1497         case ContextMenuItemBaseApplicationTag:
1498         case ContextMenuItemTagDictationAlternative:
1499             break;
1500         case ContextMenuItemTagMediaPlayPause:
1501             if (m_hitTestResult.mediaPlaying())
1502                 item.setTitle(contextMenuItemTagMediaPause());
1503             else
1504                 item.setTitle(contextMenuItemTagMediaPlay());
1505             break;
1506         case ContextMenuItemTagMediaMute:
1507             shouldEnable = m_hitTestResult.mediaHasAudio();
1508             shouldCheck = shouldEnable &&  m_hitTestResult.mediaMuted();
1509             break;
1510     }
1511
1512     item.setChecked(shouldCheck);
1513     item.setEnabled(shouldEnable);
1514 }
1515
1516 #if USE(ACCESSIBILITY_CONTEXT_MENUS)
1517 void ContextMenuController::showContextMenuAt(Frame* frame, const IntPoint& clickPoint)
1518 {
1519     // Simulate a click in the middle of the accessibility object.
1520     PlatformMouseEvent mouseEvent(clickPoint, clickPoint, RightButton, PlatformEvent::MousePressed, 1, false, false, false, false, currentTime());
1521     bool handled = frame->eventHandler()->sendContextMenuEvent(mouseEvent);
1522     if (handled && client())
1523         client()->showContextMenu();
1524 }
1525 #endif
1526
1527 } // namespace WebCore
1528
1529 #endif // ENABLE(CONTEXT_MENUS)