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

Side by Side Diff: sky/engine/core/page/ContextMenuController.cpp

Issue 640143004: Remove context menus. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 2 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
(Empty)
1 /*
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Igalia S.L
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
25 */
26
27 #include "config.h"
28 #include "core/page/ContextMenuController.h"
29
30 #include "core/dom/Document.h"
31 #include "core/dom/Node.h"
32 #include "core/events/Event.h"
33 #include "core/events/MouseEvent.h"
34 #include "core/events/RelatedEvent.h"
35 #include "core/frame/LocalFrame.h"
36 #include "core/page/ContextMenuClient.h"
37 #include "core/page/ContextMenuProvider.h"
38 #include "core/page/EventHandler.h"
39 #include "platform/ContextMenu.h"
40 #include "platform/ContextMenuItem.h"
41
42 namespace blink {
43
44 ContextMenuController::ContextMenuController(Page*, ContextMenuClient* client)
45 : m_client(client)
46 {
47 ASSERT_ARG(client, client);
48 }
49
50 ContextMenuController::~ContextMenuController()
51 {
52 }
53
54 PassOwnPtrWillBeRawPtr<ContextMenuController> ContextMenuController::create(Page * page, ContextMenuClient* client)
55 {
56 return adoptPtrWillBeNoop(new ContextMenuController(page, client));
57 }
58
59 void ContextMenuController::trace(Visitor* visitor)
60 {
61 visitor->trace(m_hitTestResult);
62 }
63
64 void ContextMenuController::clearContextMenu()
65 {
66 m_contextMenu.clear();
67 if (m_menuProvider)
68 m_menuProvider->contextMenuCleared();
69 m_menuProvider = nullptr;
70 m_client->clearContextMenu();
71 m_hitTestResult = HitTestResult();
72 }
73
74 void ContextMenuController::documentDetached(Document* document)
75 {
76 if (Node* innerNode = m_hitTestResult.innerNode()) {
77 // Invalidate the context menu info if its target document is detached.
78 if (innerNode->document() == document)
79 clearContextMenu();
80 }
81 }
82
83 void ContextMenuController::handleContextMenuEvent(Event* event)
84 {
85 m_contextMenu = createContextMenu(event);
86 if (!m_contextMenu)
87 return;
88 showContextMenu(event);
89 }
90
91 void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenu Provider> menuProvider)
92 {
93 m_menuProvider = menuProvider;
94
95 m_contextMenu = createContextMenu(event);
96 if (!m_contextMenu) {
97 clearContextMenu();
98 return;
99 }
100
101 m_menuProvider->populateContextMenu(m_contextMenu.get());
102 showContextMenu(event);
103 }
104
105 void ContextMenuController::showContextMenuAtPoint(LocalFrame* frame, float x, f loat y, PassRefPtr<ContextMenuProvider> menuProvider)
106 {
107 m_menuProvider = menuProvider;
108
109 LayoutPoint location(x, y);
110 m_contextMenu = createContextMenu(frame, location);
111 if (!m_contextMenu) {
112 clearContextMenu();
113 return;
114 }
115
116 m_menuProvider->populateContextMenu(m_contextMenu.get());
117 showContextMenu(nullptr);
118 }
119
120 PassOwnPtr<ContextMenu> ContextMenuController::createContextMenu(Event* event)
121 {
122 ASSERT(event);
123
124 if (!event->isMouseEvent())
125 return nullptr;
126
127 MouseEvent* mouseEvent = toMouseEvent(event);
128 return createContextMenu(event->target()->toNode()->document().frame(), mous eEvent->absoluteLocation());
129 }
130
131 PassOwnPtr<ContextMenu> ContextMenuController::createContextMenu(LocalFrame* fra me, const LayoutPoint& location)
132 {
133 HitTestResult result(location);
134
135 if (frame)
136 result = frame->eventHandler().hitTestResultAtPoint(location, HitTestReq uest::ReadOnly | HitTestRequest::Active);
137
138 if (!result.innerNonSharedNode())
139 return nullptr;
140
141 m_hitTestResult = result;
142
143 return adoptPtr(new ContextMenu);
144 }
145
146 void ContextMenuController::showContextMenu(Event* event)
147 {
148 m_client->showContextMenu(m_contextMenu.get());
149 if (event)
150 event->setDefaultHandled();
151 }
152
153 void ContextMenuController::contextMenuItemSelected(const ContextMenuItem* item)
154 {
155 ASSERT(item->type() == ActionType || item->type() == CheckableActionType);
156
157 if (item->action() < ContextMenuItemBaseCustomTag || item->action() > Contex tMenuItemLastCustomTag)
158 return;
159
160 ASSERT(m_menuProvider);
161 m_menuProvider->contextMenuItemSelected(item);
162 }
163
164 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/page/ContextMenuController.h ('k') | sky/engine/core/page/ContextMenuProvider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698