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

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: Move to oilpan 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 blink { 45 namespace blink {
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->isHTMLElement() && RuntimeEnabledFeatures::menuElementEnab led()) {
91 const HTMLElement& element = toHTMLElement(*node);
92 if (RefPtrWillBeRawPtr<HTMLMenuElement> menuElement = element.menuElemen t()) {
93 RefPtr<RelatedEvent> relatedEvent = RelatedEvent::create(EventTypeNa mes::show);
94 relatedEvent->setRelatedTarget(node);
95 EventDispatcher::dispatchEvent(menuElement.get(), EventDispatchMedia tor::create(relatedEvent.release()));
tkent 2014/07/25 04:42:38 Why don't you use menuElement->dispatchEvent(relat
pals 2014/07/30 09:47:44 Done.
96 m_menuProvider = menuElement->menuProvider();
tkent 2014/07/25 04:42:38 We should construct menu items here, not in HTMLMe
pals 2014/07/30 09:47:44 Done.
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 ASSERT(item->type() == ActionType || item->type() == CheckableActionType); 167 ASSERT(item->type() == ActionType || item->type() == CheckableActionType);
151 168
152 if (item->action() < ContextMenuItemBaseCustomTag || item->action() > Contex tMenuItemLastCustomTag) 169 if (item->action() < ContextMenuItemBaseCustomTag || item->action() > Contex tMenuItemLastCustomTag)
153 return; 170 return;
154 171
155 ASSERT(m_menuProvider); 172 ASSERT(m_menuProvider);
156 m_menuProvider->contextMenuItemSelected(item); 173 m_menuProvider->contextMenuItemSelected(item);
157 } 174 }
158 175
159 } // namespace blink 176 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698