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

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: Fixed comments 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
« no previous file with comments | « Source/core/page/ContextMenuController.h ('k') | Source/core/page/CustomContextMenuProvider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
32 #include "core/events/MouseEvent.h" 33 #include "core/events/MouseEvent.h"
33 #include "core/dom/Node.h" 34 #include "core/events/RelatedEvent.h"
34 #include "core/frame/LocalFrame.h" 35 #include "core/frame/LocalFrame.h"
36 #include "core/html/HTMLMenuElement.h"
35 #include "core/page/ContextMenuClient.h" 37 #include "core/page/ContextMenuClient.h"
36 #include "core/page/ContextMenuProvider.h" 38 #include "core/page/ContextMenuProvider.h"
39 #include "core/page/CustomContextMenuProvider.h"
37 #include "core/page/EventHandler.h" 40 #include "core/page/EventHandler.h"
38 #include "platform/ContextMenu.h" 41 #include "platform/ContextMenu.h"
39 #include "platform/ContextMenuItem.h" 42 #include "platform/ContextMenuItem.h"
40 43
41 namespace blink { 44 namespace blink {
42 45
46 using namespace HTMLNames;
47
43 ContextMenuController::ContextMenuController(Page*, ContextMenuClient* client) 48 ContextMenuController::ContextMenuController(Page*, ContextMenuClient* client)
44 : m_client(client) 49 : m_client(client)
45 { 50 {
46 ASSERT_ARG(client, client); 51 ASSERT_ARG(client, client);
47 } 52 }
48 53
49 ContextMenuController::~ContextMenuController() 54 ContextMenuController::~ContextMenuController()
50 { 55 {
51 } 56 }
52 57
(...skipping 19 matching lines...) Expand all
72 77
73 void ContextMenuController::documentDetached(Document* document) 78 void ContextMenuController::documentDetached(Document* document)
74 { 79 {
75 if (Node* innerNode = m_hitTestResult.innerNode()) { 80 if (Node* innerNode = m_hitTestResult.innerNode()) {
76 // Invalidate the context menu info if its target document is detached. 81 // Invalidate the context menu info if its target document is detached.
77 if (innerNode->document() == document) 82 if (innerNode->document() == document)
78 clearContextMenu(); 83 clearContextMenu();
79 } 84 }
80 } 85 }
81 86
87 void ContextMenuController::populateCustomContextMenu(const Event& event)
88 {
89 if (!RuntimeEnabledFeatures::contextMenuEnabled())
90 return;
91
92 Node* node = event.target()->toNode();
93 if (!node || !node->isHTMLElement())
94 return;
95
96 HTMLElement& element = toHTMLElement(*node);
97 RefPtrWillBeRawPtr<HTMLMenuElement> menuElement = element.contextMenu();
98 if (!menuElement || !equalIgnoringCase(menuElement->fastGetAttribute(typeAtt r), "popup"))
99 return;
100 RefPtrWillBeRawPtr<RelatedEvent> relatedEvent = RelatedEvent::create(EventTy peNames::show, true, true, node);
101 if (!menuElement->dispatchEvent(relatedEvent.release()))
102 return;
103 if (menuElement != element.contextMenu())
104 return;
105 m_menuProvider = CustomContextMenuProvider::create(*menuElement, element);
106 m_menuProvider->populateContextMenu(m_contextMenu.get());
107 }
108
82 void ContextMenuController::handleContextMenuEvent(Event* event) 109 void ContextMenuController::handleContextMenuEvent(Event* event)
83 { 110 {
84 m_contextMenu = createContextMenu(event); 111 m_contextMenu = createContextMenu(event);
85 if (!m_contextMenu) 112 if (!m_contextMenu)
86 return; 113 return;
87 114 populateCustomContextMenu(*event);
88 showContextMenu(event); 115 showContextMenu(event);
89 } 116 }
90 117
91 void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenu Provider> menuProvider) 118 void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenu Provider> menuProvider)
92 { 119 {
93 m_menuProvider = menuProvider; 120 m_menuProvider = menuProvider;
94 121
95 m_contextMenu = createContextMenu(event); 122 m_contextMenu = createContextMenu(event);
96 if (!m_contextMenu) { 123 if (!m_contextMenu) {
97 clearContextMenu(); 124 clearContextMenu();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 ASSERT(item->type() == ActionType || item->type() == CheckableActionType); 182 ASSERT(item->type() == ActionType || item->type() == CheckableActionType);
156 183
157 if (item->action() < ContextMenuItemBaseCustomTag || item->action() > Contex tMenuItemLastCustomTag) 184 if (item->action() < ContextMenuItemBaseCustomTag || item->action() > Contex tMenuItemLastCustomTag)
158 return; 185 return;
159 186
160 ASSERT(m_menuProvider); 187 ASSERT(m_menuProvider);
161 m_menuProvider->contextMenuItemSelected(item); 188 m_menuProvider->contextMenuItemSelected(item);
162 } 189 }
163 190
164 } // namespace blink 191 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/page/ContextMenuController.h ('k') | Source/core/page/CustomContextMenuProvider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698