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