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

Side by Side Diff: Source/core/html/HTMLMenuElement.cpp

Issue 243403006: Implement contextmenu attribute with basic support of <menu> (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added unit tests Created 6 years, 7 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2010 Apple Inc. All rights reserved. 4 * Copyright (C) 2010 Apple Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
11 * This library is distributed in the hope that it will be useful, 11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 14 * Library General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU Library General Public License 16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to 17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA. 19 * Boston, MA 02110-1301, USA.
20 * 20 *
21 */ 21 */
22 22
23 #include "config.h" 23 #include "config.h"
24
24 #include "core/html/HTMLMenuElement.h" 25 #include "core/html/HTMLMenuElement.h"
25 26
26 #include "HTMLNames.h" 27 #include "core/dom/ElementTraversal.h"
28 #include "core/events/RelatedEvent.h"
29 #include "core/html/HTMLMenuElementEventListener.h"
30 #include "core/html/HTMLMenuitemElement.h"
31 #include "core/page/ContextMenuController.h"
32 #include "core/page/Page.h"
27 33
28 namespace WebCore { 34 namespace WebCore {
29 35
30 using namespace HTMLNames; 36 using namespace HTMLNames;
31 37
32 inline HTMLMenuElement::HTMLMenuElement(Document& document) 38 inline HTMLMenuElement::HTMLMenuElement(Document& document)
33 : HTMLElement(menuTag, document) 39 : HTMLElement(menuTag, document)
34 { 40 {
35 ScriptWrappable::init(this); 41 ScriptWrappable::init(this);
42 RefPtr<EventListener> listener = HTMLMenuElementEventListener::create(this);
43 addEventListener("show", listener.release(), false);
esprehn 2014/06/06 22:30:42 We don't normally add event listeners like this. I
pals 2014/06/10 10:42:39 Done. Removed HTMLMenuElementEventListener. Added
36 } 44 }
37 45
38 PassRefPtrWillBeRawPtr<HTMLMenuElement> HTMLMenuElement::create(Document& docume nt) 46 PassRefPtrWillBeRawPtr<HTMLMenuElement> HTMLMenuElement::create(Document& docume nt)
39 { 47 {
40 return adoptRefWillBeRefCountedGarbageCollected(new HTMLMenuElement(document )); 48 return adoptRefWillBeRefCountedGarbageCollected(new HTMLMenuElement(document ));
41 } 49 }
42 50
51 CustomContextMenuProvider& HTMLMenuElement::ensureCustomProvider()
esprehn 2014/06/06 22:30:42 ensureMenuProvider()
pals 2014/06/10 10:42:39 Done.
52 {
53 if (!m_menuProvider) {
54 ContextMenu menu;
55 populateContextMenuItems(this, menu);
56 m_menuProvider = CustomContextMenuProvider::create(this, menu.items());
57 }
58 return *m_menuProvider;
43 } 59 }
60
61 void HTMLMenuElement::populateContextMenuItems(HTMLMenuElement* menu, ContextMen u& contextMenu)
62 {
63 for (Element* nextElement = ElementTraversal::firstWithin(*menu); nextElemen t;) {
esprehn 2014/06/06 22:30:42 Lets use a while() loop, it'll be more clear.
pals 2014/06/10 10:42:39 Done.
64 if (nextElement->hasTagName(HTMLNames::menuTag)) {
65 ContextMenu subMenu;
66 populateContextMenuItems(toHTMLMenuElement(nextElement), subMenu);
67 contextMenu.appendItem(ContextMenuItem(SubmenuType, ContextMenuItemC ustomTagNoAction, nextElement->fastGetAttribute(HTMLNames::labelAttr), &subMenu) );
68 nextElement = ElementTraversal::nextSibling(*nextElement);
69 continue;
70 } else if (nextElement->hasTagName(HTMLNames::menuitemTag)) {
71 m_menuItems.append(toHTMLElement(nextElement));
72 contextMenu.appendItem(ContextMenuItem(ActionType, static_cast<Conte xtMenuAction>(ContextMenuItemBaseCustomTag + m_menuItems.size() - 1), nextElemen t->fastGetAttribute(HTMLNames::labelAttr)));
73 }
74 nextElement = ElementTraversal::next(*nextElement, menu);
75 }
76 }
77
78 HTMLElement* HTMLMenuElement::selectedMenuItem(unsigned menuId)
79 {
80 return m_menuItems[menuId - ContextMenuItemBaseCustomTag];
esprehn 2014/06/06 22:30:42 This unsigned thing is really weird.
pals 2014/06/10 10:42:39 Done. Added checks.
81 }
82
83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698