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

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

Issue 492753002: Add support to populate custom context menu items. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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"
41 #include "core/page/CustomContextMenuProvider.h"
37 #include "core/page/EventHandler.h" 42 #include "core/page/EventHandler.h"
38 #include "platform/ContextMenu.h" 43 #include "platform/ContextMenu.h"
39 #include "platform/ContextMenuItem.h" 44 #include "platform/ContextMenuItem.h"
40 45
41 namespace blink { 46 namespace blink {
42 47
48 using namespace HTMLNames;
49
43 ContextMenuController::ContextMenuController(Page*, ContextMenuClient* client) 50 ContextMenuController::ContextMenuController(Page*, ContextMenuClient* client)
44 : m_client(client) 51 : m_client(client)
45 { 52 {
46 ASSERT_ARG(client, client); 53 ASSERT_ARG(client, client);
47 } 54 }
48 55
49 ContextMenuController::~ContextMenuController() 56 ContextMenuController::~ContextMenuController()
50 { 57 {
51 } 58 }
52 59
(...skipping 19 matching lines...) Expand all
72 79
73 void ContextMenuController::documentDetached(Document* document) 80 void ContextMenuController::documentDetached(Document* document)
74 { 81 {
75 if (Node* innerNode = m_hitTestResult.innerNode()) { 82 if (Node* innerNode = m_hitTestResult.innerNode()) {
76 // Invalidate the context menu info if its target document is detached. 83 // Invalidate the context menu info if its target document is detached.
77 if (innerNode->document() == document) 84 if (innerNode->document() == document)
78 clearContextMenu(); 85 clearContextMenu();
79 } 86 }
80 } 87 }
81 88
89 void ContextMenuController::populateCustomContextMenu(Event* event)
tkent 2014/08/21 01:34:39 Event* -> Even&
pals 2014/08/25 14:19:41 Done.
90 {
91 if (!RuntimeEnabledFeatures::contextMenuEnabled())
92 return;
93
94 Node* node = event->target()->toNode();
95 if (node && node->isHTMLElement()) {
tkent 2014/08/21 01:34:39 We prefer early return. if (!node || !node->isHTM
pals 2014/08/25 14:19:41 Done.
96 HTMLElement& element = toHTMLElement(*node);
97 RefPtrWillBeRawPtr<HTMLMenuElement> menuElement = element.contextMenu();
98 if (!menuElement)
99 return;
100 RefPtrWillBeRawPtr<RelatedEvent> relatedEvent = RelatedEvent::create(Eve ntTypeNames::show, true, true, node);
tkent 2014/08/21 01:34:38 Should we check type=popup?
pals 2014/08/25 14:19:41 Done.
101 if (!menuElement->dispatchEvent(relatedEvent.release()))
102 return;
tkent 2014/08/21 01:34:39 We need a layout test of canceling |show| event.
pals 2014/08/25 14:19:41 Done.
103 if (menuElement != element.contextMenu())
104 return;
tkent 2014/08/21 01:34:39 Need a layout test for this too.
pals 2014/08/25 14:19:41 Done.
105 m_menuProvider = CustomContextMenuProvider::create(*menuElement, element );
106 m_menuProvider->populateContextMenu(m_contextMenu.get());
107 }
108 }
109
82 void ContextMenuController::handleContextMenuEvent(Event* event) 110 void ContextMenuController::handleContextMenuEvent(Event* event)
83 { 111 {
84 m_contextMenu = createContextMenu(event); 112 m_contextMenu = createContextMenu(event);
85 if (!m_contextMenu) 113 if (!m_contextMenu)
86 return; 114 return;
87 115 populateCustomContextMenu(event);
88 showContextMenu(event); 116 showContextMenu(event);
89 } 117 }
90 118
91 void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenu Provider> menuProvider) 119 void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenu Provider> menuProvider)
92 { 120 {
93 m_menuProvider = menuProvider; 121 m_menuProvider = menuProvider;
94 122
95 m_contextMenu = createContextMenu(event); 123 m_contextMenu = createContextMenu(event);
96 if (!m_contextMenu) { 124 if (!m_contextMenu) {
97 clearContextMenu(); 125 clearContextMenu();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 ASSERT(item->type() == ActionType || item->type() == CheckableActionType); 183 ASSERT(item->type() == ActionType || item->type() == CheckableActionType);
156 184
157 if (item->action() < ContextMenuItemBaseCustomTag || item->action() > Contex tMenuItemLastCustomTag) 185 if (item->action() < ContextMenuItemBaseCustomTag || item->action() > Contex tMenuItemLastCustomTag)
158 return; 186 return;
159 187
160 ASSERT(m_menuProvider); 188 ASSERT(m_menuProvider);
161 m_menuProvider->contextMenuItemSelected(item); 189 m_menuProvider->contextMenuItemSelected(item);
162 } 190 }
163 191
164 } // namespace blink 192 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698