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

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: Menu builder algorithm 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"
tkent 2014/08/25 23:07:42 Looks unnecessary.
pals 2014/08/26 07:13:23 Done.
34 #include "core/events/EventDispatcher.h"
tkent 2014/08/25 23:07:42 Looks unnecessary.
pals 2014/08/26 07:13:23 Done.
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(const Event& event)
90 {
91 if (!RuntimeEnabledFeatures::contextMenuEnabled())
92 return;
93
94 Node* node = event.target()->toNode();
95 if (!node || !node->isHTMLElement())
96 return;
97
98 HTMLElement& element = toHTMLElement(*node);
99 RefPtrWillBeRawPtr<HTMLMenuElement> menuElement = element.contextMenu();
100 if (!menuElement || !equalIgnoringCase(menuElement->fastGetAttribute(typeAtt r), "popup"))
101 return;
102 RefPtrWillBeRawPtr<RelatedEvent> relatedEvent = RelatedEvent::create(EventTy peNames::show, true, true, node);
103 if (!menuElement->dispatchEvent(relatedEvent.release()))
104 return;
105 if (menuElement != element.contextMenu())
106 return;
107 m_menuProvider = CustomContextMenuProvider::create(*menuElement, element);
108 m_menuProvider->populateContextMenu(m_contextMenu.get());
109 }
110
82 void ContextMenuController::handleContextMenuEvent(Event* event) 111 void ContextMenuController::handleContextMenuEvent(Event* event)
83 { 112 {
84 m_contextMenu = createContextMenu(event); 113 m_contextMenu = createContextMenu(event);
85 if (!m_contextMenu) 114 if (!m_contextMenu)
86 return; 115 return;
87 116 populateCustomContextMenu(*event);
88 showContextMenu(event); 117 showContextMenu(event);
89 } 118 }
90 119
91 void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenu Provider> menuProvider) 120 void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenu Provider> menuProvider)
92 { 121 {
93 m_menuProvider = menuProvider; 122 m_menuProvider = menuProvider;
94 123
95 m_contextMenu = createContextMenu(event); 124 m_contextMenu = createContextMenu(event);
96 if (!m_contextMenu) { 125 if (!m_contextMenu) {
97 clearContextMenu(); 126 clearContextMenu();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 ASSERT(item->type() == ActionType || item->type() == CheckableActionType); 184 ASSERT(item->type() == ActionType || item->type() == CheckableActionType);
156 185
157 if (item->action() < ContextMenuItemBaseCustomTag || item->action() > Contex tMenuItemLastCustomTag) 186 if (item->action() < ContextMenuItemBaseCustomTag || item->action() > Contex tMenuItemLastCustomTag)
158 return; 187 return;
159 188
160 ASSERT(m_menuProvider); 189 ASSERT(m_menuProvider);
161 m_menuProvider->contextMenuItemSelected(item); 190 m_menuProvider->contextMenuItemSelected(item);
162 } 191 }
163 192
164 } // namespace blink 193 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698