OLD | NEW |
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 Loading... |
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 Loading... |
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) |
| 90 { |
| 91 if (!RuntimeEnabledFeatures::contextMenuEnabled()) |
| 92 return; |
| 93 |
| 94 Node* node = event->target()->toNode(); |
| 95 if (node && node->isHTMLElement()) { |
| 96 HTMLElement& element = toHTMLElement(*node); |
| 97 RefPtrWillBeRawPtr<HTMLMenuElement> menuElement = element.contextMenu(); |
| 98 RefPtrWillBeRawPtr<RelatedEvent> relatedEvent = RelatedEvent::create(Eve
ntTypeNames::show, true, true, node); |
| 99 if (!menuElement->dispatchEvent(relatedEvent.release())) |
| 100 return; |
| 101 if (menuElement != element.contextMenu()) |
| 102 return; |
| 103 m_menuProvider = CustomContextMenuProvider::create(*menuElement, element
); |
| 104 m_menuProvider->populateContextMenu(m_contextMenu.get()); |
| 105 } |
| 106 } |
| 107 |
82 void ContextMenuController::handleContextMenuEvent(Event* event) | 108 void ContextMenuController::handleContextMenuEvent(Event* event) |
83 { | 109 { |
84 m_contextMenu = createContextMenu(event); | 110 m_contextMenu = createContextMenu(event); |
85 if (!m_contextMenu) | 111 if (!m_contextMenu) |
86 return; | 112 return; |
87 | 113 populateCustomContextMenu(event); |
88 showContextMenu(event); | 114 showContextMenu(event); |
89 } | 115 } |
90 | 116 |
91 void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenu
Provider> menuProvider) | 117 void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenu
Provider> menuProvider) |
92 { | 118 { |
93 m_menuProvider = menuProvider; | 119 m_menuProvider = menuProvider; |
94 | 120 |
95 m_contextMenu = createContextMenu(event); | 121 m_contextMenu = createContextMenu(event); |
96 if (!m_contextMenu) { | 122 if (!m_contextMenu) { |
97 clearContextMenu(); | 123 clearContextMenu(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 ASSERT(item->type() == ActionType || item->type() == CheckableActionType); | 181 ASSERT(item->type() == ActionType || item->type() == CheckableActionType); |
156 | 182 |
157 if (item->action() < ContextMenuItemBaseCustomTag || item->action() > Contex
tMenuItemLastCustomTag) | 183 if (item->action() < ContextMenuItemBaseCustomTag || item->action() > Contex
tMenuItemLastCustomTag) |
158 return; | 184 return; |
159 | 185 |
160 ASSERT(m_menuProvider); | 186 ASSERT(m_menuProvider); |
161 m_menuProvider->contextMenuItemSelected(item); | 187 m_menuProvider->contextMenuItemSelected(item); |
162 } | 188 } |
163 | 189 |
164 } // namespace blink | 190 } // namespace blink |
OLD | NEW |