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

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

Issue 2905763003: Rollback ContextMenu (Closed)
Patch Set: Rebase Created 3 years, 6 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 13 matching lines...) Expand all
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 "core/page/ContextMenuController.h" 27 #include "core/page/ContextMenuController.h"
28 28
29 #include <memory> 29 #include <memory>
30 #include "core/dom/Document.h" 30 #include "core/dom/Document.h"
31 #include "core/dom/Node.h" 31 #include "core/dom/Node.h"
32 #include "core/events/Event.h" 32 #include "core/events/Event.h"
33 #include "core/events/MouseEvent.h" 33 #include "core/events/MouseEvent.h"
34 #include "core/events/RelatedEvent.h"
35 #include "core/frame/LocalFrame.h" 34 #include "core/frame/LocalFrame.h"
36 #include "core/html/HTMLMenuElement.h"
37 #include "core/input/EventHandler.h" 35 #include "core/input/EventHandler.h"
38 #include "core/page/ContextMenuClient.h" 36 #include "core/page/ContextMenuClient.h"
39 #include "core/page/ContextMenuProvider.h" 37 #include "core/page/ContextMenuProvider.h"
40 #include "core/page/CustomContextMenuProvider.h"
41 #include "platform/ContextMenu.h" 38 #include "platform/ContextMenu.h"
42 #include "platform/ContextMenuItem.h" 39 #include "platform/ContextMenuItem.h"
43 #include "platform/wtf/PtrUtil.h" 40 #include "platform/wtf/PtrUtil.h"
44 41
45 namespace blink { 42 namespace blink {
46 43
47 using namespace HTMLNames;
48
49 ContextMenuController::ContextMenuController(Page*, ContextMenuClient* client) 44 ContextMenuController::ContextMenuController(Page*, ContextMenuClient* client)
50 : client_(client) { 45 : client_(client) {
51 DCHECK(client); 46 DCHECK(client);
52 } 47 }
53 48
54 ContextMenuController::~ContextMenuController() {} 49 ContextMenuController::~ContextMenuController() {}
55 50
56 ContextMenuController* ContextMenuController::Create( 51 ContextMenuController* ContextMenuController::Create(
57 Page* page, 52 Page* page,
58 ContextMenuClient* client) { 53 ContextMenuClient* client) {
(...skipping 15 matching lines...) Expand all
74 } 69 }
75 70
76 void ContextMenuController::DocumentDetached(Document* document) { 71 void ContextMenuController::DocumentDetached(Document* document) {
77 if (Node* inner_node = hit_test_result_.InnerNode()) { 72 if (Node* inner_node = hit_test_result_.InnerNode()) {
78 // Invalidate the context menu info if its target document is detached. 73 // Invalidate the context menu info if its target document is detached.
79 if (inner_node->GetDocument() == document) 74 if (inner_node->GetDocument() == document)
80 ClearContextMenu(); 75 ClearContextMenu();
81 } 76 }
82 } 77 }
83 78
84 void ContextMenuController::PopulateCustomContextMenu(const Event& event) {
85 if (!RuntimeEnabledFeatures::contextMenuEnabled())
86 return;
87
88 Node* node = event.target()->ToNode();
89 if (!node || !node->IsHTMLElement())
90 return;
91
92 HTMLElement& element = ToHTMLElement(*node);
93 HTMLMenuElement* menu_element = element.AssignedContextMenu();
94 if (!menu_element || !DeprecatedEqualIgnoringCase(
95 menu_element->FastGetAttribute(typeAttr), "context"))
96 return;
97 RelatedEvent* related_event =
98 RelatedEvent::Create(EventTypeNames::show, true, true, node);
99 if (menu_element->DispatchEvent(related_event) !=
100 DispatchEventResult::kNotCanceled)
101 return;
102 if (menu_element != element.AssignedContextMenu())
103 return;
104 menu_provider_ = CustomContextMenuProvider::Create(*menu_element, element);
105 menu_provider_->PopulateContextMenu(context_menu_.get());
106 }
107
108 void ContextMenuController::HandleContextMenuEvent(Event* event) { 79 void ContextMenuController::HandleContextMenuEvent(Event* event) {
109 context_menu_ = CreateContextMenu(event); 80 context_menu_ = CreateContextMenu(event);
110 if (!context_menu_) 81 if (!context_menu_)
111 return; 82 return;
112 PopulateCustomContextMenu(*event);
113 ShowContextMenu(event); 83 ShowContextMenu(event);
114 } 84 }
115 85
116 void ContextMenuController::ShowContextMenuAtPoint( 86 void ContextMenuController::ShowContextMenuAtPoint(
117 LocalFrame* frame, 87 LocalFrame* frame,
118 float x, 88 float x,
119 float y, 89 float y,
120 ContextMenuProvider* menu_provider) { 90 ContextMenuProvider* menu_provider) {
121 menu_provider_ = menu_provider; 91 menu_provider_ = menu_provider;
122 92
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 149
180 if (item->Action() < kContextMenuItemBaseCustomTag || 150 if (item->Action() < kContextMenuItemBaseCustomTag ||
181 item->Action() > kContextMenuItemLastCustomTag) 151 item->Action() > kContextMenuItemLastCustomTag)
182 return; 152 return;
183 153
184 DCHECK(menu_provider_); 154 DCHECK(menu_provider_);
185 menu_provider_->ContextMenuItemSelected(item); 155 menu_provider_->ContextMenuItemSelected(item);
186 } 156 }
187 157
188 } // namespace blink 158 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698