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

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: Created 6 years, 7 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 20 matching lines...) Expand all
73 clearContextMenu(); 79 clearContextMenu();
74 } 80 }
75 } 81 }
76 82
77 void ContextMenuController::handleContextMenuEvent(Event* event) 83 void ContextMenuController::handleContextMenuEvent(Event* event)
78 { 84 {
79 m_contextMenu = createContextMenu(event); 85 m_contextMenu = createContextMenu(event);
80 if (!m_contextMenu) 86 if (!m_contextMenu)
81 return; 87 return;
82 88
89 Node* node = event->target()->toNode();
90 if (node && node->isElementNode()) {
esprehn 2014/05/20 05:51:34 I think you want isHTMLElement
pals 2014/05/21 07:55:12 Done.
91 const HTMLElement& element = toHTMLElement(*event->target()->toNode());
esprehn 2014/05/20 05:51:34 This is not safe, it could be an SVG element or ju
pals 2014/05/21 07:55:12 Changed to isHTMLElement() above.
92 if (HTMLMenuElement* menuElement = element.menuElement()) {
esprehn 2014/05/20 05:51:34 This probably needs to be a RefPtr, the script bel
pals 2014/05/21 07:55:12 Done.
93 RefPtr<RelatedEvent> relatedEvent = RelatedEvent::create("show");
94 relatedEvent->setRelatedTarget(node);
95 EventDispatcher::dispatchEvent(menuElement, EventDispatchMediator::c reate(relatedEvent));
esprehn 2014/05/20 05:51:34 Are you sure it's safe to synchronously execute sc
pals 2014/05/21 07:55:12 m_menuProvider below which is populated by menu el
96 m_menuProvider = menuElement->getCustomProvider();
97 m_menuProvider->populateContextMenu(m_contextMenu.get());
98 }
99 }
83 showContextMenu(event); 100 showContextMenu(event);
84 } 101 }
85 102
86 void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenu Provider> menuProvider) 103 void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenu Provider> menuProvider)
87 { 104 {
88 m_menuProvider = menuProvider; 105 m_menuProvider = menuProvider;
89 106
90 m_contextMenu = createContextMenu(event); 107 m_contextMenu = createContextMenu(event);
91 if (!m_contextMenu) { 108 if (!m_contextMenu) {
92 clearContextMenu(); 109 clearContextMenu();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 ASSERT(item->type() == ActionType || item->type() == CheckableActionType); 146 ASSERT(item->type() == ActionType || item->type() == CheckableActionType);
130 147
131 if (item->action() < ContextMenuItemBaseCustomTag || item->action() > Contex tMenuItemLastCustomTag) 148 if (item->action() < ContextMenuItemBaseCustomTag || item->action() > Contex tMenuItemLastCustomTag)
132 return; 149 return;
133 150
134 ASSERT(m_menuProvider); 151 ASSERT(m_menuProvider);
135 m_menuProvider->contextMenuItemSelected(item); 152 m_menuProvider->contextMenuItemSelected(item);
136 } 153 }
137 154
138 } // namespace WebCore 155 } // namespace WebCore
OLDNEW
« Source/core/html/HTMLMenuitemElement.idl ('K') | « Source/core/html/HTMLTagNames.in ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698