bd3fc4fca23d81c90d4d265b7314772e25a48b22
[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 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
85 #include "HTMLInputElement.h"
86 #endif
87
88 using namespace WTF;
89 using namespace Unicode;
90
91 namespace WebCore {
92
93 ContextMenuController::ContextMenuController(Page* page, ContextMenuClient* client)
94     : m_page(page)
95     , m_client(client)
96 {
97     ASSERT_ARG(page, page);
98     ASSERT_ARG(client, client);
99 }
100
101 ContextMenuController::~ContextMenuController()
102 {
103     m_client->contextMenuDestroyed();
104 }
105
106 PassOwnPtr<ContextMenuController> ContextMenuController::create(Page* page, ContextMenuClient* client)
107 {
108     return adoptPtr(new ContextMenuController(page, client));
109 }
110
111 void ContextMenuController::clearContextMenu()
112 {
113     m_contextMenu.clear();
114     if (m_menuProvider)
115         m_menuProvider->contextMenuCleared();
116     m_menuProvider = 0;
117 }
118
119 void ContextMenuController::handleContextMenuEvent(Event* event)
120 {
121     m_contextMenu = createContextMenu(event);
122     if (!m_contextMenu)
123         return;
124
125     populate();
126
127     showContextMenu(event);
128 }
129
130 static PassOwnPtr<ContextMenuItem> separatorItem()
131 {
132     return adoptPtr(new ContextMenuItem(SeparatorType, ContextMenuItemTagNoAction, String()));
133 }
134
135 void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenuProvider> menuProvider)
136 {
137     m_menuProvider = menuProvider;
138
139     m_contextMenu = createContextMenu(event);
140     if (!m_contextMenu) {
141         clearContextMenu();
142         return;
143     }
144
145     m_menuProvider->populateContextMenu(m_contextMenu.get());
146     if (m_hitTestResult.isSelected()) {
147         appendItem(*separatorItem(), m_contextMenu.get());
148         populate();
149     }
150     showContextMenu(event);
151 }
152
153 PassOwnPtr<ContextMenu> ContextMenuController::createContextMenu(Event* event)
154 {
155     if (!event->isMouseEvent())
156         return nullptr;
157
158     MouseEvent* mouseEvent = static_cast<MouseEvent*>(event);
159     HitTestResult result(mouseEvent->absoluteLocation());
160
161     if (Frame* frame = event->target()->toNode()->document()->frame())
162         result = frame->eventHandler()->hitTestResultAtPoint(mouseEvent->absoluteLocation(), false);
163
164     if (!result.innerNonSharedNode())
165         return nullptr;
166
167     m_hitTestResult = result;
168
169     return adoptPtr(new ContextMenu);
170 }
171
172 void ContextMenuController::showContextMenu(Event* event)
173 {
174 #if ENABLE(INSPECTOR)
175     if (m_page->inspectorController()->enabled())
176         addInspectElementItem();
177 #endif
178
179 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
180     m_contextMenu = m_client->customizeMenu(m_contextMenu.release());
181 #else
182     PlatformMenuDescription customMenu = m_client->getCustomMenuFromDefaultItems(m_contextMenu.get());
183     m_contextMenu->setPlatformDescription(customMenu);
184 #endif
185     event->setDefaultHandled();
186 }
187
188 static void openNewWindow(const KURL& urlToLoad, Frame* frame)
189 {
190     if (Page* oldPage = frame->page()) {
191         FrameLoadRequest request(frame->document()->securityOrigin(), ResourceRequest(urlToLoad, frame->loader()->outgoingReferrer()));
192         if (Page* newPage = oldPage->chrome()->createWindow(frame, request, WindowFeatures(), NavigationAction(request.resourceRequest()))) {
193             newPage->mainFrame()->loader()->loadFrameRequest(request, false, false, 0, 0, MaybeSendReferrer);
194             newPage->chrome()->show();
195         }
196     }
197 }
198
199 #if PLATFORM(GTK)
200 static void insertUnicodeCharacter(UChar character, Frame* frame)
201 {
202     String text(&character, 1);
203     if (!frame->editor()->shouldInsertText(text, frame->selection()->toNormalizedRange().get(), EditorInsertActionTyped))
204         return;
205
206     TypingCommand::insertText(frame->document(), text, 0, TypingCommand::TextCompositionNone);
207 }
208 #endif
209
210 void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
211 {
212     ASSERT(item->type() == ActionType || item->type() == CheckableActionType);
213
214     if (item->action() >= ContextMenuItemBaseApplicationTag) {
215         m_client->contextMenuItemSelected(item, m_contextMenu.get());
216         return;
217     }
218
219     if (item->action() >= ContextMenuItemBaseCustomTag) {
220         ASSERT(m_menuProvider);
221         m_menuProvider->contextMenuItemSelected(item);
222         return;
223     }
224
225     Frame* frame = m_hitTestResult.innerNonSharedNode()->document()->frame();
226     if (!frame)
227         return;
228
229 #if ENABLE(TIZEN_PASTEBOARD)
230     if (Page* page = frame->page()) {
231         if (item->action() == ContextMenuItemTagCopyLinkToClipboard
232             || item->action() == ContextMenuItemTagCopyImageToClipboard
233             || item->action() == ContextMenuItemTagCopyImageUrlToClipboard
234             || item->action() == ContextMenuItemTagCopyMediaLinkToClipboard
235             || item->action() == ContextMenuItemTagCopy
236             || item->action() == ContextMenuItemTagCut)
237             Pasteboard::generalPasteboard()->setPage(page);
238     }
239 #endif
240
241     switch (item->action()) {
242     case ContextMenuItemTagOpenLinkInNewWindow:
243         openNewWindow(m_hitTestResult.absoluteLinkURL(), frame);
244         break;
245     case ContextMenuItemTagDownloadLinkToDisk:
246         // FIXME: Some day we should be able to do this from within WebCore.
247         m_client->downloadURL(m_hitTestResult.absoluteLinkURL());
248         break;
249     case ContextMenuItemTagCopyLinkToClipboard:
250         frame->editor()->copyURL(m_hitTestResult.absoluteLinkURL(), m_hitTestResult.textContent());
251         break;
252     case ContextMenuItemTagOpenImageInNewWindow:
253         openNewWindow(m_hitTestResult.absoluteImageURL(), frame);
254         break;
255     case ContextMenuItemTagDownloadImageToDisk:
256         // FIXME: Some day we should be able to do this from within WebCore.
257         m_client->downloadURL(m_hitTestResult.absoluteImageURL());
258         break;
259     case ContextMenuItemTagCopyImageToClipboard:
260         // FIXME: The Pasteboard class is not written yet
261         // For now, call into the client. This is temporary!
262         frame->editor()->copyImage(m_hitTestResult);
263         break;
264 #if PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
265     case ContextMenuItemTagCopyImageUrlToClipboard:
266         frame->editor()->copyURL(m_hitTestResult.absoluteImageURL(), m_hitTestResult.textContent());
267         break;
268 #endif
269     case ContextMenuItemTagOpenMediaInNewWindow:
270         openNewWindow(m_hitTestResult.absoluteMediaURL(), frame);
271         break;
272     case ContextMenuItemTagCopyMediaLinkToClipboard:
273         frame->editor()->copyURL(m_hitTestResult.absoluteMediaURL(), m_hitTestResult.textContent());
274         break;
275     case ContextMenuItemTagToggleMediaControls:
276         m_hitTestResult.toggleMediaControlsDisplay();
277         break;
278     case ContextMenuItemTagToggleMediaLoop:
279         m_hitTestResult.toggleMediaLoopPlayback();
280         break;
281     case ContextMenuItemTagEnterVideoFullscreen:
282         m_hitTestResult.enterFullscreenForVideo();
283         break;
284     case ContextMenuItemTagMediaPlayPause:
285         m_hitTestResult.toggleMediaPlayState();
286         break;
287     case ContextMenuItemTagMediaMute:
288         m_hitTestResult.toggleMediaMuteState();
289         break;
290     case ContextMenuItemTagOpenFrameInNewWindow: {
291         DocumentLoader* loader = frame->loader()->documentLoader();
292         if (!loader->unreachableURL().isEmpty())
293             openNewWindow(loader->unreachableURL(), frame);
294         else
295             openNewWindow(loader->url(), frame);
296         break;
297     }
298     case ContextMenuItemTagCopy: {
299         frame->editor()->copy();
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 ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
846         if (m_hitTestResult.isSelected() || frame->selection()->isRange())
847             appendItem(SelectAllItem, m_contextMenu.get());
848 #endif
849         if (!linkURL.isEmpty()) {
850 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
851             if (m_hitTestResult.isSelected() || frame->selection()->isRange()) {
852                 if (selectionContainsPossibleWord(frame)) {
853                     appendItem(SearchWebItem, m_contextMenu.get());
854                 }
855                 appendItem(CopyItem, m_contextMenu.get());
856                 return;
857             }
858 #endif
859 #if ENABLE(TIZEN_DOWNLOAD_LINK_FILTER)
860             if (loader->client()->canHandleRequest(ResourceRequest(linkURL)) &&
861                (linkURL.protocolIs("http") || linkURL.protocolIs("https") || linkURL.protocolIs("ftp") || linkURL.protocolIs("ftps"))) {
862 #else
863             if (loader->client()->canHandleRequest(ResourceRequest(linkURL))) {
864 #endif
865                 appendItem(OpenLinkItem, m_contextMenu.get());
866                 appendItem(OpenLinkInNewWindowItem, m_contextMenu.get());
867                 appendItem(DownloadFileItem, m_contextMenu.get());
868             }
869 #if PLATFORM(QT)
870             if (m_hitTestResult.isSelected()) 
871                 appendItem(CopyItem, m_contextMenu.get());
872 #endif
873             appendItem(CopyLinkItem, m_contextMenu.get());
874         }
875
876         KURL imageURL = m_hitTestResult.absoluteImageURL();
877         if (!imageURL.isEmpty()) {
878             if (!linkURL.isEmpty())
879                 appendItem(*separatorItem(), m_contextMenu.get());
880
881             appendItem(OpenImageInNewWindowItem, m_contextMenu.get());
882             appendItem(DownloadImageItem, m_contextMenu.get());
883             if (imageURL.isLocalFile() || m_hitTestResult.image())
884                 appendItem(CopyImageItem, m_contextMenu.get());
885 #if PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
886             appendItem(CopyImageUrlItem, m_contextMenu.get());
887 #endif
888         }
889
890         KURL mediaURL = m_hitTestResult.absoluteMediaURL();
891         if (!mediaURL.isEmpty()) {
892             if (!linkURL.isEmpty() || !imageURL.isEmpty())
893                 appendItem(*separatorItem(), m_contextMenu.get());
894
895             appendItem(MediaPlayPause, m_contextMenu.get());
896 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
897             if (m_hitTestResult.mediaMuted())
898                 appendItem(MediaUnMute, m_contextMenu.get());
899             else
900                 appendItem(MediaMute, m_contextMenu.get());
901 #else
902             appendItem(MediaMute, m_contextMenu.get());
903 #endif
904             appendItem(ToggleMediaControls, m_contextMenu.get());
905             appendItem(ToggleMediaLoop, m_contextMenu.get());
906             appendItem(EnterVideoFullscreen, m_contextMenu.get());
907
908             appendItem(*separatorItem(), m_contextMenu.get());
909             appendItem(CopyMediaLinkItem, m_contextMenu.get());
910             appendItem(OpenMediaInNewWindowItem, m_contextMenu.get());
911         }
912
913 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
914         if ((!linkURL.isEmpty() || !imageURL.isEmpty()) && mediaURL.isEmpty())
915             appendItem(TextSelectionModeItem, m_contextMenu.get());
916 #endif
917
918 #if ENABLE(TIZEN_DRAG_SUPPORT)
919         if (imageURL.isEmpty() && linkURL.isEmpty() && mediaURL.isEmpty() && !m_hitTestResult.isDragSupport()) {
920 #else
921         if (imageURL.isEmpty() && linkURL.isEmpty() && mediaURL.isEmpty()) {
922 #endif
923             if (m_hitTestResult.isSelected()) {
924                 if (selectionContainsPossibleWord(frame)) {
925 #if PLATFORM(MAC)
926                     String selectedString = frame->displayStringModifiedByEncoding(frame->editor()->selectedText());
927                     ContextMenuItem LookUpInDictionaryItem(ActionType, ContextMenuItemTagLookUpInDictionary, contextMenuItemTagLookUpInDictionary(selectedString));
928
929 #if INCLUDE_SPOTLIGHT_CONTEXT_MENU_ITEM
930                     appendItem(SearchSpotlightItem, m_contextMenu.get());
931 #else
932                     appendItem(LookUpInDictionaryItem, m_contextMenu.get());
933 #endif
934 #endif
935
936 #if !PLATFORM(GTK)
937                     appendItem(SearchWebItem, m_contextMenu.get());
938                     appendItem(*separatorItem(), m_contextMenu.get());
939 #endif
940
941 #if PLATFORM(MAC) && INCLUDE_SPOTLIGHT_CONTEXT_MENU_ITEM
942                     appendItem(LookUpInDictionaryItem, m_contextMenu.get());
943                     appendItem(*separatorItem(), m_contextMenu.get());
944 #endif
945                 }
946
947                 appendItem(CopyItem, m_contextMenu.get());
948 #if PLATFORM(MAC)
949                 appendItem(*separatorItem(), m_contextMenu.get());
950
951                 ContextMenuItem SpeechMenuItem(SubmenuType, ContextMenuItemTagSpeechMenu, contextMenuItemTagSpeechMenu());
952                 createAndAppendSpeechSubMenu(SpeechMenuItem);
953                 appendItem(SpeechMenuItem, m_contextMenu.get());
954 #endif                
955             } else {
956 #if ENABLE(INSPECTOR)
957                 if (!(frame->page() && frame->page()->inspectorController()->hasInspectorFrontendClient())) {
958 #endif
959
960                 // In GTK+ unavailable items are not hidden but insensitive
961 #if PLATFORM(GTK)
962                 appendItem(BackItem, m_contextMenu.get());
963                 appendItem(ForwardItem, m_contextMenu.get());
964                 appendItem(StopItem, m_contextMenu.get());
965                 appendItem(ReloadItem, m_contextMenu.get());
966 #else
967 #if !ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
968                 if (frame->page() && frame->page()->backForward()->canGoBackOrForward(-1))
969                     appendItem(BackItem, m_contextMenu.get());
970
971                 if (frame->page() && frame->page()->backForward()->canGoBackOrForward(1))
972                     appendItem(ForwardItem, m_contextMenu.get());
973
974                 // use isLoadingInAPISense rather than isLoading because Stop/Reload are
975                 // intended to match WebKit's API, not WebCore's internal notion of loading status
976                 if (loader->documentLoader()->isLoadingInAPISense())
977                     appendItem(StopItem, m_contextMenu.get());
978                 else
979                     appendItem(ReloadItem, m_contextMenu.get());
980 #endif
981 #endif
982 #if ENABLE(INSPECTOR)
983                 }
984 #endif
985
986                 if (frame->page() && frame != frame->page()->mainFrame())
987                     appendItem(OpenFrameItem, m_contextMenu.get());
988             }
989         }
990 #if ENABLE(TIZEN_DRAG_SUPPORT)
991         if (frame->page() && m_hitTestResult.isDragSupport()) {
992             TIZEN_LOGI("appendItem for drag");
993             appendItem(DragItem, m_contextMenu.get());
994         }
995 #endif
996     } else { // Make an editing context menu
997         FrameSelection* selection = frame->selection();
998         bool inPasswordField = selection->isInPasswordField();
999         if (!inPasswordField) {
1000             bool haveContextMenuItemsForMisspellingOrGrammer = false;
1001             bool spellCheckingEnabled = frame->editor()->isSpellCheckingEnabledFor(node);
1002             if (spellCheckingEnabled) {
1003                 // Consider adding spelling-related or grammar-related context menu items (never both, since a single selected range
1004                 // is never considered a misspelling and bad grammar at the same time)
1005 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
1006                 bool misspelling = false;
1007                 bool badGrammar = false;
1008 #else
1009                 bool misspelling;
1010                 bool badGrammar;
1011 #endif
1012                 Vector<String> guesses = frame->editor()->guessesForMisspelledOrUngrammaticalSelection(misspelling, badGrammar);
1013                 if (misspelling || badGrammar) {
1014                     size_t size = guesses.size();
1015                     if (!size) {
1016                         // If there's bad grammar but no suggestions (e.g., repeated word), just leave off the suggestions
1017                         // list and trailing separator rather than adding a "No Guesses Found" item (matches AppKit)
1018                         if (misspelling) {
1019                             appendItem(NoGuessesItem, m_contextMenu.get());
1020                             appendItem(*separatorItem(), m_contextMenu.get());
1021                         }
1022                     } else {
1023                         for (unsigned i = 0; i < size; i++) {
1024                             const String &guess = guesses[i];
1025                             if (!guess.isEmpty()) {
1026                                 ContextMenuItem item(ActionType, ContextMenuItemTagSpellingGuess, guess);
1027                                 appendItem(item, m_contextMenu.get());
1028                             }
1029                         }
1030                         appendItem(*separatorItem(), m_contextMenu.get());
1031                     }
1032                     if (misspelling) {
1033                         appendItem(IgnoreSpellingItem, m_contextMenu.get());
1034                         appendItem(LearnSpellingItem, m_contextMenu.get());
1035                     } else
1036                         appendItem(IgnoreGrammarItem, m_contextMenu.get());
1037                     appendItem(*separatorItem(), m_contextMenu.get());
1038                     haveContextMenuItemsForMisspellingOrGrammer = true;
1039 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
1040                 } else {
1041                     // If the string was autocorrected, generate a contextual menu item allowing it to be changed back.
1042                     String replacedString = m_hitTestResult.replacedString();
1043                     if (!replacedString.isEmpty()) {
1044                         ContextMenuItem item(ActionType, ContextMenuItemTagChangeBack, contextMenuItemTagChangeBack(replacedString));
1045                         appendItem(item, m_contextMenu.get());
1046                         appendItem(*separatorItem(), m_contextMenu.get());
1047                         haveContextMenuItemsForMisspellingOrGrammer = true;
1048                     }
1049 #endif
1050                 }
1051             }
1052
1053             if (!haveContextMenuItemsForMisspellingOrGrammer) {
1054                 // Spelling and grammar checking is mutually exclusive with dictation alternatives.
1055                 Vector<String> dictationAlternatives = m_hitTestResult.dictationAlternatives();
1056                 if (!dictationAlternatives.isEmpty()) {
1057                     for (size_t i = 0; i < dictationAlternatives.size(); ++i) {
1058                         ContextMenuItem item(ActionType, ContextMenuItemTagDictationAlternative, dictationAlternatives[i]);
1059                         appendItem(item, m_contextMenu.get());
1060                     }
1061                     appendItem(*separatorItem(), m_contextMenu.get());
1062                 }
1063             }
1064         }
1065
1066         FrameLoader* loader = frame->loader();
1067         KURL linkURL = m_hitTestResult.absoluteLinkURL();
1068         if (!linkURL.isEmpty()) {
1069             if (loader->client()->canHandleRequest(ResourceRequest(linkURL))) {
1070                 appendItem(OpenLinkItem, m_contextMenu.get());
1071                 appendItem(OpenLinkInNewWindowItem, m_contextMenu.get());
1072                 appendItem(DownloadFileItem, m_contextMenu.get());
1073             }
1074             appendItem(CopyLinkItem, m_contextMenu.get());
1075             appendItem(*separatorItem(), m_contextMenu.get());
1076         }
1077
1078         if (m_hitTestResult.isSelected() && !inPasswordField && selectionContainsPossibleWord(frame)) {
1079 #if PLATFORM(MAC)
1080             String selectedString = frame->displayStringModifiedByEncoding(frame->editor()->selectedText());
1081             ContextMenuItem LookUpInDictionaryItem(ActionType, ContextMenuItemTagLookUpInDictionary, contextMenuItemTagLookUpInDictionary(selectedString));
1082
1083 #if INCLUDE_SPOTLIGHT_CONTEXT_MENU_ITEM
1084             appendItem(SearchSpotlightItem, m_contextMenu.get());
1085 #else
1086             appendItem(LookUpInDictionaryItem, m_contextMenu.get());
1087 #endif
1088 #endif
1089
1090 #if !PLATFORM(GTK)
1091             appendItem(SearchWebItem, m_contextMenu.get());
1092             appendItem(*separatorItem(), m_contextMenu.get());
1093 #endif
1094
1095 #if PLATFORM(MAC) && INCLUDE_SPOTLIGHT_CONTEXT_MENU_ITEM
1096             appendItem(LookUpInDictionaryItem, m_contextMenu.get());
1097             appendItem(*separatorItem(), m_contextMenu.get());
1098 #endif
1099         }
1100
1101 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
1102         bool isInputPickerType = false;
1103 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1104         HTMLInputElement* inputElement = node->toInputElement();
1105         if (inputElement &&
1106             (inputElement->isDateField() || inputElement->isDateTimeField() || inputElement->isDateTimeLocalField()
1107             || inputElement->isMonthField() || inputElement->isTimeField() || inputElement->isWeekField()))
1108             isInputPickerType = true;
1109 #endif
1110         if (m_hitTestResult.isSelected() && !inPasswordField) {
1111             if (!isInputPickerType)
1112                 appendItem(CutItem, m_contextMenu.get());
1113             appendItem(CopyItem, m_contextMenu.get());
1114         }
1115         if (!isInputPickerType) {
1116             appendItem(PasteItem, m_contextMenu.get());
1117 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
1118             appendItem(ClipboardItem, m_contextMenu.get());
1119 #endif
1120         }
1121 #else
1122         appendItem(CutItem, m_contextMenu.get());
1123         appendItem(CopyItem, m_contextMenu.get());
1124         appendItem(PasteItem, m_contextMenu.get());
1125 #endif
1126 #if PLATFORM(GTK)
1127         appendItem(DeleteItem, m_contextMenu.get());
1128         appendItem(*separatorItem(), m_contextMenu.get());
1129 #endif
1130 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
1131         if (frame->selection()) {
1132             Node* baseNode = frame->selection()->base().containerNode();
1133             if (baseNode && baseNode->isTextNode() && (!(baseNode->textContent().isEmpty()))) {
1134                 if (inPasswordField) {
1135                     if (!m_hitTestResult.isSelected())
1136                         appendItem(SelectWordItem, m_contextMenu.get());
1137                 } else {
1138 #endif
1139 #if PLATFORM(GTK) || PLATFORM(QT) || PLATFORM(EFL)
1140                     appendItem(SelectAllItem, m_contextMenu.get());
1141 #endif
1142 #if ENABLE(TIZEN_CONTEXT_MENU_SELECT)
1143                     appendItem(SelectWordItem, m_contextMenu.get());
1144 #endif
1145 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
1146                 }
1147             }
1148         }
1149 #endif
1150
1151         if (!inPasswordField) {
1152 #if !PLATFORM(GTK)
1153 #if !ENABLE(TIZEN_CONTEXT_MENU_TEMPORARY_FIX)
1154             appendItem(*separatorItem(), m_contextMenu.get());
1155             ContextMenuItem SpellingAndGrammarMenuItem(SubmenuType, ContextMenuItemTagSpellingMenu, 
1156                 contextMenuItemTagSpellingMenu());
1157             createAndAppendSpellingAndGrammarSubMenu(SpellingAndGrammarMenuItem);
1158             appendItem(SpellingAndGrammarMenuItem, m_contextMenu.get());
1159 #endif //TIZEN_CONTEXT_MENU_TEMPORARY_FIX
1160 #endif
1161 #if PLATFORM(MAC)
1162             ContextMenuItem substitutionsMenuItem(SubmenuType, ContextMenuItemTagSubstitutionsMenu, 
1163                 contextMenuItemTagSubstitutionsMenu());
1164             createAndAppendSubstitutionsSubMenu(substitutionsMenuItem);
1165             appendItem(substitutionsMenuItem, m_contextMenu.get());
1166             ContextMenuItem transformationsMenuItem(SubmenuType, ContextMenuItemTagTransformationsMenu, 
1167                 contextMenuItemTagTransformationsMenu());
1168             createAndAppendTransformationsSubMenu(transformationsMenuItem);
1169             appendItem(transformationsMenuItem, m_contextMenu.get());
1170 #endif
1171 #if PLATFORM(GTK)
1172             bool shouldShowFontMenu = frame->editor()->canEditRichly();
1173 #else
1174 #if ENABLE(TIZEN_CONTEXT_MENU_TEMPORARY_FIX)
1175             bool shouldShowFontMenu = false;
1176 #else
1177             bool shouldShowFontMenu = true;
1178 #endif //TIZEN_CONTEXT_MENU_TEMPORARY_FIX
1179 #endif
1180             if (shouldShowFontMenu) {
1181                 ContextMenuItem FontMenuItem(SubmenuType, ContextMenuItemTagFontMenu, 
1182                     contextMenuItemTagFontMenu());
1183                 createAndAppendFontSubMenu(FontMenuItem);
1184                 appendItem(FontMenuItem, m_contextMenu.get());
1185             }
1186 #if PLATFORM(MAC)
1187             ContextMenuItem SpeechMenuItem(SubmenuType, ContextMenuItemTagSpeechMenu, contextMenuItemTagSpeechMenu());
1188             createAndAppendSpeechSubMenu(SpeechMenuItem);
1189             appendItem(SpeechMenuItem, m_contextMenu.get());
1190 #endif
1191 #if PLATFORM(GTK)
1192             EditorClient* client = frame->editor()->client();
1193             if (client && client->shouldShowUnicodeMenu()) {
1194                 ContextMenuItem UnicodeMenuItem(SubmenuType, ContextMenuItemTagUnicode, contextMenuItemTagUnicode());
1195                 createAndAppendUnicodeSubMenu(UnicodeMenuItem);
1196                 appendItem(*separatorItem(), m_contextMenu.get());
1197                 appendItem(UnicodeMenuItem, m_contextMenu.get());
1198             }
1199 #else
1200             ContextMenuItem WritingDirectionMenuItem(SubmenuType, ContextMenuItemTagWritingDirectionMenu, 
1201                 contextMenuItemTagWritingDirectionMenu());
1202 #if !ENABLE(TIZEN_CONTEXT_MENU_TEMPORARY_FIX)
1203             createAndAppendWritingDirectionSubMenu(WritingDirectionMenuItem);
1204             appendItem(WritingDirectionMenuItem, m_contextMenu.get());
1205             if (Page* page = frame->page()) {
1206                 if (Settings* settings = page->settings()) {
1207                     bool includeTextDirectionSubmenu = settings->textDirectionSubmenuInclusionBehavior() == TextDirectionSubmenuAlwaysIncluded
1208                         || (settings->textDirectionSubmenuInclusionBehavior() == TextDirectionSubmenuAutomaticallyIncluded && frame->editor()->hasBidiSelection());
1209                     if (includeTextDirectionSubmenu) {
1210                         ContextMenuItem TextDirectionMenuItem(SubmenuType, ContextMenuItemTagTextDirectionMenu, 
1211                             contextMenuItemTagTextDirectionMenu());
1212                         createAndAppendTextDirectionSubMenu(TextDirectionMenuItem);
1213                         appendItem(TextDirectionMenuItem, m_contextMenu.get());
1214                     }
1215                 }
1216             }
1217 #endif //TIZEN_CONTEXT_MENU_TEMPORARY_FIX
1218 #endif
1219         }
1220     }
1221 }
1222
1223 #if ENABLE(INSPECTOR)
1224 void ContextMenuController::addInspectElementItem()
1225 {
1226     Node* node = m_hitTestResult.innerNonSharedNode();
1227     if (!node)
1228         return;
1229
1230     Frame* frame = node->document()->frame();
1231     if (!frame)
1232         return;
1233
1234     Page* page = frame->page();
1235     if (!page)
1236         return;
1237
1238     if (!page->inspectorController())
1239         return;
1240
1241     ContextMenuItem InspectElementItem(ActionType, ContextMenuItemTagInspectElement, contextMenuItemTagInspectElement());
1242 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
1243     if (!m_contextMenu->items().isEmpty())
1244 #else
1245     if (m_contextMenu->itemCount())
1246 #endif
1247         appendItem(*separatorItem(), m_contextMenu.get());
1248     appendItem(InspectElementItem, m_contextMenu.get());
1249 }
1250 #endif // ENABLE(INSPECTOR)
1251
1252 void ContextMenuController::checkOrEnableIfNeeded(ContextMenuItem& item) const
1253 {
1254     if (item.type() == SeparatorType)
1255         return;
1256     
1257     Frame* frame = m_hitTestResult.innerNonSharedNode()->document()->frame();
1258     if (!frame)
1259         return;
1260
1261     // Custom items already have proper checked and enabled values.
1262     if (ContextMenuItemBaseCustomTag <= item.action() && item.action() <= ContextMenuItemLastCustomTag)
1263         return;
1264
1265     bool shouldEnable = true;
1266     bool shouldCheck = false; 
1267
1268     switch (item.action()) {
1269         case ContextMenuItemTagCheckSpelling:
1270             shouldEnable = frame->editor()->canEdit();
1271             break;
1272         case ContextMenuItemTagDefaultDirection:
1273             shouldCheck = false;
1274             shouldEnable = false;
1275             break;
1276         case ContextMenuItemTagLeftToRight:
1277         case ContextMenuItemTagRightToLeft: {
1278             String direction = item.action() == ContextMenuItemTagLeftToRight ? "ltr" : "rtl";
1279             shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyDirection, direction) != FalseTriState;
1280             shouldEnable = true;
1281             break;
1282         }
1283         case ContextMenuItemTagTextDirectionDefault: {
1284             Editor::Command command = frame->editor()->command("MakeTextWritingDirectionNatural");
1285             shouldCheck = command.state() == TrueTriState;
1286             shouldEnable = command.isEnabled();
1287             break;
1288         }
1289         case ContextMenuItemTagTextDirectionLeftToRight: {
1290             Editor::Command command = frame->editor()->command("MakeTextWritingDirectionLeftToRight");
1291             shouldCheck = command.state() == TrueTriState;
1292             shouldEnable = command.isEnabled();
1293             break;
1294         }
1295         case ContextMenuItemTagTextDirectionRightToLeft: {
1296             Editor::Command command = frame->editor()->command("MakeTextWritingDirectionRightToLeft");
1297             shouldCheck = command.state() == TrueTriState;
1298             shouldEnable = command.isEnabled();
1299             break;
1300         }
1301         case ContextMenuItemTagCopy:
1302             shouldEnable = frame->editor()->canDHTMLCopy() || frame->editor()->canCopy();
1303             break;
1304         case ContextMenuItemTagCut:
1305             shouldEnable = frame->editor()->canDHTMLCut() || frame->editor()->canCut();
1306             break;
1307         case ContextMenuItemTagIgnoreSpelling:
1308         case ContextMenuItemTagLearnSpelling:
1309             shouldEnable = frame->selection()->isRange();
1310             break;
1311         case ContextMenuItemTagPaste:
1312             shouldEnable = frame->editor()->canDHTMLPaste() || frame->editor()->canPaste();
1313             break;
1314 #if ENABLE(TIZEN_CONTEXT_MENU_SELECT)
1315         case ContextMenuItemTagSelectWord:
1316             shouldEnable = frame->editor()->canSelectRange();
1317             break;
1318 #endif
1319 #if PLATFORM(GTK)
1320         case ContextMenuItemTagDelete:
1321             shouldEnable = frame->editor()->canDelete();
1322             break;
1323         case ContextMenuItemTagInputMethods:
1324         case ContextMenuItemTagUnicode:
1325         case ContextMenuItemTagUnicodeInsertLRMMark:
1326         case ContextMenuItemTagUnicodeInsertRLMMark:
1327         case ContextMenuItemTagUnicodeInsertLREMark:
1328         case ContextMenuItemTagUnicodeInsertRLEMark:
1329         case ContextMenuItemTagUnicodeInsertLROMark:
1330         case ContextMenuItemTagUnicodeInsertRLOMark:
1331         case ContextMenuItemTagUnicodeInsertPDFMark:
1332         case ContextMenuItemTagUnicodeInsertZWSMark:
1333         case ContextMenuItemTagUnicodeInsertZWJMark:
1334         case ContextMenuItemTagUnicodeInsertZWNJMark:
1335             shouldEnable = true;
1336             break;
1337 #endif
1338 #if PLATFORM(GTK) || PLATFORM(EFL)
1339         case ContextMenuItemTagSelectAll:
1340             shouldEnable = true;
1341             break;
1342 #endif
1343         case ContextMenuItemTagUnderline: {
1344             shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyWebkitTextDecorationsInEffect, "underline") != FalseTriState;
1345             shouldEnable = frame->editor()->canEditRichly();
1346             break;
1347         }
1348         case ContextMenuItemTagLookUpInDictionary:
1349             shouldEnable = frame->selection()->isRange();
1350             break;
1351         case ContextMenuItemTagCheckGrammarWithSpelling:
1352             if (frame->editor()->isGrammarCheckingEnabled())
1353                 shouldCheck = true;
1354             shouldEnable = true;
1355             break;
1356         case ContextMenuItemTagItalic: {
1357             shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyFontStyle, "italic") != FalseTriState;
1358             shouldEnable = frame->editor()->canEditRichly();
1359             break;
1360         }
1361         case ContextMenuItemTagBold: {
1362             shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyFontWeight, "bold") != FalseTriState;
1363             shouldEnable = frame->editor()->canEditRichly();
1364             break;
1365         }
1366         case ContextMenuItemTagOutline:
1367             shouldEnable = false;
1368             break;
1369         case ContextMenuItemTagShowSpellingPanel:
1370             if (frame->editor()->spellingPanelIsShowing())
1371                 item.setTitle(contextMenuItemTagShowSpellingPanel(false));
1372             else
1373                 item.setTitle(contextMenuItemTagShowSpellingPanel(true));
1374             shouldEnable = frame->editor()->canEdit();
1375             break;
1376         case ContextMenuItemTagNoGuessesFound:
1377             shouldEnable = false;
1378             break;
1379         case ContextMenuItemTagCheckSpellingWhileTyping:
1380             shouldCheck = frame->editor()->isContinuousSpellCheckingEnabled();
1381             break;
1382 #if PLATFORM(MAC)
1383         case ContextMenuItemTagSubstitutionsMenu:
1384         case ContextMenuItemTagTransformationsMenu:
1385             break;
1386         case ContextMenuItemTagShowSubstitutions:
1387             if (frame->editor()->substitutionsPanelIsShowing())
1388                 item.setTitle(contextMenuItemTagShowSubstitutions(false));
1389             else
1390                 item.setTitle(contextMenuItemTagShowSubstitutions(true));
1391             shouldEnable = frame->editor()->canEdit();
1392             break;
1393         case ContextMenuItemTagMakeUpperCase:
1394         case ContextMenuItemTagMakeLowerCase:
1395         case ContextMenuItemTagCapitalize:
1396         case ContextMenuItemTagChangeBack:
1397             shouldEnable = frame->editor()->canEdit();
1398             break;
1399         case ContextMenuItemTagCorrectSpellingAutomatically:
1400             shouldCheck = frame->editor()->isAutomaticSpellingCorrectionEnabled();
1401             break;
1402         case ContextMenuItemTagSmartCopyPaste:
1403             shouldCheck = frame->editor()->smartInsertDeleteEnabled();
1404             break;
1405         case ContextMenuItemTagSmartQuotes:
1406             shouldCheck = frame->editor()->isAutomaticQuoteSubstitutionEnabled();
1407             break;
1408         case ContextMenuItemTagSmartDashes:
1409             shouldCheck = frame->editor()->isAutomaticDashSubstitutionEnabled();
1410             break;
1411         case ContextMenuItemTagSmartLinks:
1412             shouldCheck = frame->editor()->isAutomaticLinkDetectionEnabled();
1413             break;
1414         case ContextMenuItemTagTextReplacement:
1415             shouldCheck = frame->editor()->isAutomaticTextReplacementEnabled();
1416             break;
1417         case ContextMenuItemTagStopSpeaking:
1418             shouldEnable = client() && client()->isSpeaking();
1419             break;
1420 #else // PLATFORM(MAC) ends here
1421         case ContextMenuItemTagStopSpeaking:
1422             break;
1423 #endif
1424 #if PLATFORM(GTK)
1425         case ContextMenuItemTagGoBack:
1426             shouldEnable = frame->page() && frame->page()->backForward()->canGoBackOrForward(-1);
1427             break;
1428         case ContextMenuItemTagGoForward:
1429             shouldEnable = frame->page() && frame->page()->backForward()->canGoBackOrForward(1);
1430             break;
1431         case ContextMenuItemTagStop:
1432             shouldEnable = frame->loader()->documentLoader()->isLoadingInAPISense();
1433             break;
1434         case ContextMenuItemTagReload:
1435             shouldEnable = !frame->loader()->documentLoader()->isLoadingInAPISense();
1436             break;
1437         case ContextMenuItemTagFontMenu:
1438             shouldEnable = frame->editor()->canEditRichly();
1439             break;
1440 #else
1441         case ContextMenuItemTagGoBack:
1442         case ContextMenuItemTagGoForward:
1443         case ContextMenuItemTagStop:
1444         case ContextMenuItemTagReload:
1445         case ContextMenuItemTagFontMenu:
1446 #endif
1447         case ContextMenuItemTagNoAction:
1448         case ContextMenuItemTagOpenLinkInNewWindow:
1449         case ContextMenuItemTagDownloadLinkToDisk:
1450         case ContextMenuItemTagCopyLinkToClipboard:
1451         case ContextMenuItemTagOpenImageInNewWindow:
1452         case ContextMenuItemTagDownloadImageToDisk:
1453         case ContextMenuItemTagCopyImageToClipboard:
1454 #if PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
1455         case ContextMenuItemTagCopyImageUrlToClipboard:
1456 #endif
1457             break;
1458         case ContextMenuItemTagOpenMediaInNewWindow:
1459             if (m_hitTestResult.mediaIsVideo())
1460                 item.setTitle(contextMenuItemTagOpenVideoInNewWindow());
1461             else
1462                 item.setTitle(contextMenuItemTagOpenAudioInNewWindow());
1463             break;
1464         case ContextMenuItemTagCopyMediaLinkToClipboard:
1465             if (m_hitTestResult.mediaIsVideo())
1466                 item.setTitle(contextMenuItemTagCopyVideoLinkToClipboard());
1467             else
1468                 item.setTitle(contextMenuItemTagCopyAudioLinkToClipboard());
1469             break;
1470         case ContextMenuItemTagToggleMediaControls:
1471             shouldCheck = m_hitTestResult.mediaControlsEnabled();
1472             break;
1473         case ContextMenuItemTagToggleMediaLoop:
1474             shouldCheck = m_hitTestResult.mediaLoopEnabled();
1475             break;
1476         case ContextMenuItemTagEnterVideoFullscreen:
1477             shouldEnable = m_hitTestResult.mediaSupportsFullscreen();
1478             break;
1479         case ContextMenuItemTagOpenFrameInNewWindow:
1480         case ContextMenuItemTagSpellingGuess:
1481         case ContextMenuItemTagOther:
1482         case ContextMenuItemTagSearchInSpotlight:
1483         case ContextMenuItemTagSearchWeb:
1484         case ContextMenuItemTagOpenWithDefaultApplication:
1485         case ContextMenuItemPDFActualSize:
1486         case ContextMenuItemPDFZoomIn:
1487         case ContextMenuItemPDFZoomOut:
1488         case ContextMenuItemPDFAutoSize:
1489         case ContextMenuItemPDFSinglePage:
1490         case ContextMenuItemPDFFacingPages:
1491         case ContextMenuItemPDFContinuous:
1492         case ContextMenuItemPDFNextPage:
1493         case ContextMenuItemPDFPreviousPage:
1494         case ContextMenuItemTagOpenLink:
1495         case ContextMenuItemTagIgnoreGrammar:
1496         case ContextMenuItemTagSpellingMenu:
1497         case ContextMenuItemTagShowFonts:
1498         case ContextMenuItemTagStyles:
1499         case ContextMenuItemTagShowColors:
1500         case ContextMenuItemTagSpeechMenu:
1501         case ContextMenuItemTagStartSpeaking:
1502         case ContextMenuItemTagWritingDirectionMenu:
1503         case ContextMenuItemTagTextDirectionMenu:
1504         case ContextMenuItemTagPDFSinglePageScrolling:
1505         case ContextMenuItemTagPDFFacingPagesScrolling:
1506 #if ENABLE(INSPECTOR)
1507         case ContextMenuItemTagInspectElement:
1508 #endif
1509 #if ENABLE(TIZEN_DRAG_SUPPORT)
1510         case ContextMenuItemTagDrag:
1511 #endif
1512         case ContextMenuItemBaseCustomTag:
1513         case ContextMenuItemCustomTagNoAction:
1514         case ContextMenuItemLastCustomTag:
1515         case ContextMenuItemBaseApplicationTag:
1516         case ContextMenuItemTagDictationAlternative:
1517             break;
1518         case ContextMenuItemTagMediaPlayPause:
1519             if (m_hitTestResult.mediaPlaying())
1520                 item.setTitle(contextMenuItemTagMediaPause());
1521             else
1522                 item.setTitle(contextMenuItemTagMediaPlay());
1523             break;
1524         case ContextMenuItemTagMediaMute:
1525             shouldEnable = m_hitTestResult.mediaHasAudio();
1526             shouldCheck = shouldEnable &&  m_hitTestResult.mediaMuted();
1527             break;
1528 #if ENABLE(TIZEN_DAILY_UPVERSIONING)
1529         default:
1530             break;
1531 #endif
1532     }
1533
1534     item.setChecked(shouldCheck);
1535     item.setEnabled(shouldEnable);
1536 }
1537
1538 #if USE(ACCESSIBILITY_CONTEXT_MENUS)
1539 void ContextMenuController::showContextMenuAt(Frame* frame, const IntPoint& clickPoint)
1540 {
1541     // Simulate a click in the middle of the accessibility object.
1542     PlatformMouseEvent mouseEvent(clickPoint, clickPoint, RightButton, PlatformEvent::MousePressed, 1, false, false, false, false, currentTime());
1543     bool handled = frame->eventHandler()->sendContextMenuEvent(mouseEvent);
1544     if (handled && client())
1545         client()->showContextMenu();
1546 }
1547 #endif
1548
1549 } // namespace WebCore
1550
1551 #endif // ENABLE(CONTEXT_MENUS)