Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: Source/core/page/ContextMenuController.cpp

Issue 243403006: Implement contextmenu attribute with basic support of <menu> (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added runtime enabled checks Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Igalia S.L 3 * Copyright (C) 2010 Igalia S.L
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 10 matching lines...) Expand all
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "core/page/ContextMenuController.h" 28 #include "core/page/ContextMenuController.h"
29 29
30 #include "core/dom/Document.h" 30 #include "core/dom/Document.h"
31 #include "core/dom/Node.h"
31 #include "core/events/Event.h" 32 #include "core/events/Event.h"
33 #include "core/events/EventDispatchMediator.h"
34 #include "core/events/EventDispatcher.h"
32 #include "core/events/MouseEvent.h" 35 #include "core/events/MouseEvent.h"
33 #include "core/dom/Node.h" 36 #include "core/events/RelatedEvent.h"
34 #include "core/frame/LocalFrame.h" 37 #include "core/frame/LocalFrame.h"
38 #include "core/html/HTMLMenuElement.h"
35 #include "core/page/ContextMenuClient.h" 39 #include "core/page/ContextMenuClient.h"
36 #include "core/page/ContextMenuProvider.h" 40 #include "core/page/ContextMenuProvider.h"
37 #include "core/page/EventHandler.h" 41 #include "core/page/EventHandler.h"
38 #include "platform/ContextMenu.h" 42 #include "platform/ContextMenu.h"
39 #include "platform/ContextMenuItem.h" 43 #include "platform/ContextMenuItem.h"
40 44
41 namespace WebCore { 45 namespace WebCore {
42 46
47 using namespace HTMLNames;
48
43 ContextMenuController::ContextMenuController(Page*, ContextMenuClient* client) 49 ContextMenuController::ContextMenuController(Page*, ContextMenuClient* client)
44 : m_client(client) 50 : m_client(client)
45 { 51 {
46 ASSERT_ARG(client, client); 52 ASSERT_ARG(client, client);
47 } 53 }
48 54
49 ContextMenuController::~ContextMenuController() 55 ContextMenuController::~ContextMenuController()
50 { 56 {
51 } 57 }
52 58
(...skipping 25 matching lines...) Expand all
78 clearContextMenu(); 84 clearContextMenu();
79 } 85 }
80 } 86 }
81 87
82 void ContextMenuController::handleContextMenuEvent(Event* event) 88 void ContextMenuController::handleContextMenuEvent(Event* event)
83 { 89 {
84 m_contextMenu = createContextMenu(event); 90 m_contextMenu = createContextMenu(event);
85 if (!m_contextMenu) 91 if (!m_contextMenu)
86 return; 92 return;
87 93
94 Node* node = event->target()->toNode();
95 if (node && node->isHTMLElement() && RuntimeEnabledFeatures::menuElementEnab led()) {
96 const HTMLElement& element = toHTMLElement(*event->target()->toNode());
Inactive 2014/07/16 20:07:26 toHTMLElement(*node)
pals 2014/07/17 15:35:47 Done.
97 if (RefPtr<HTMLMenuElement> menuElement = element.menuElement()) {
98 RefPtr<RelatedEvent> relatedEvent = RelatedEvent::create(EventTypeNa mes::show);
99 relatedEvent->setRelatedTarget(node);
100 EventDispatcher::dispatchEvent(menuElement.get(), EventDispatchMedia tor::create(relatedEvent.release()));
101 m_menuProvider = menuElement->menuProvider();
102 m_menuProvider->populateContextMenu(m_contextMenu.get());
103 }
104 }
88 showContextMenu(event); 105 showContextMenu(event);
89 } 106 }
90 107
91 void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenu Provider> menuProvider) 108 void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenu Provider> menuProvider)
92 { 109 {
93 m_menuProvider = menuProvider; 110 m_menuProvider = menuProvider;
94 111
95 m_contextMenu = createContextMenu(event); 112 m_contextMenu = createContextMenu(event);
96 if (!m_contextMenu) { 113 if (!m_contextMenu) {
97 clearContextMenu(); 114 clearContextMenu();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 ASSERT(item->type() == ActionType || item->type() == CheckableActionType); 172 ASSERT(item->type() == ActionType || item->type() == CheckableActionType);
156 173
157 if (item->action() < ContextMenuItemBaseCustomTag || item->action() > Contex tMenuItemLastCustomTag) 174 if (item->action() < ContextMenuItemBaseCustomTag || item->action() > Contex tMenuItemLastCustomTag)
158 return; 175 return;
159 176
160 ASSERT(m_menuProvider); 177 ASSERT(m_menuProvider);
161 m_menuProvider->contextMenuItemSelected(item); 178 m_menuProvider->contextMenuItemSelected(item);
162 } 179 }
163 180
164 } // namespace WebCore 181 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698