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

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

Issue 243403006: Implement contextmenu attribute with basic support of <menu> (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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 #ifndef HTMLMenuElement_h 23 #ifndef HTMLMenuElement_h
24 #define HTMLMenuElement_h 24 #define HTMLMenuElement_h
25 25
26 #include "core/html/HTMLElement.h" 26 #include "core/html/HTMLElement.h"
27 #include "core/page/ContextMenuProvider.h"
28 #include "platform/ContextMenu.h"
29 #include "platform/ContextMenuItem.h"
27 30
28 namespace WebCore { 31 namespace WebCore {
29 32
33 class HTMLMenuElement;
34 class CustomContextMenuProvider;
35
30 class HTMLMenuElement FINAL : public HTMLElement { 36 class HTMLMenuElement FINAL : public HTMLElement {
31 public: 37 public:
32 static PassRefPtr<HTMLMenuElement> create(Document&); 38 static PassRefPtr<HTMLMenuElement> create(Document&);
33 39
40 void buildCustomProvider();
41 PassRefPtr<CustomContextMenuProvider> getCustomProvider() { return m_menuPro vider; }
esprehn 2014/05/20 05:51:34 Getters don't start with "get". Instead you want c
pals 2014/05/21 07:55:12 Done.
42 void populateContextMenuItems(HTMLMenuElement* menu, ContextMenu& contextMen u);
esprehn 2014/05/20 05:51:34 You don't need the argument names, they don't add
pals 2014/05/21 07:55:12 Done.
43 HTMLElement* getSelectedMenuItem(unsigned menuId);
esprehn 2014/05/20 05:51:34 Getters don't start with "get", selectedMenuItem(m
pals 2014/05/21 07:55:12 Done.
34 private: 44 private:
35 explicit HTMLMenuElement(Document&); 45 explicit HTMLMenuElement(Document&);
46 RefPtr<CustomContextMenuProvider> m_menuProvider;
47 Vector<HTMLElement*> m_menuItems;
36 }; 48 };
37 49
50 class CustomContextMenuProvider FINAL : public ContextMenuProvider {
esprehn 2014/05/20 05:51:34 This doesn't need to be all inline. Give it its ow
pals 2014/05/21 07:55:12 Done.
51 public:
52 static PassRefPtr<CustomContextMenuProvider> create(HTMLMenuElement* menu, c onst Vector<ContextMenuItem>& items)
53 {
54 return adoptRef(new CustomContextMenuProvider(menu, items));
55 }
56
57 void disconnect()
esprehn 2014/05/20 05:51:34 What is this for?
pals 2014/05/21 07:55:12 Done. Removed.
58 {
59 }
60
61 private:
62 CustomContextMenuProvider(HTMLMenuElement* menu, const Vector<ContextMenuIte m>& items)
63 : m_menu(menu)
64 , m_items(items)
65 {
66 }
67
68 virtual ~CustomContextMenuProvider()
esprehn 2014/05/20 05:51:34 These don't need to be inline.
pals 2014/05/21 07:55:12 Done.
69 {
70 contextMenuCleared();
71 }
72
73 virtual void populateContextMenu(ContextMenu* menu) OVERRIDE
74 {
75 for (size_t i = 0; i < m_items.size(); ++i)
76 menu->appendItem(m_items[i]);
77 }
78
79 virtual void contextMenuItemSelected(const ContextMenuItem* item) OVERRIDE
80 {
81 if (m_menu) {
82 if (HTMLElement* element = m_menu->getSelectedMenuItem(item->action( )))
83 element->click();
84 }
85 }
86
87 virtual void contextMenuCleared() OVERRIDE
88 {
89 m_items.clear();
90 }
91
92 HTMLMenuElement* m_menu;
esprehn 2014/05/20 05:51:34 Does this need to be a ref ptr? What keeps m_menu
pals 2014/05/21 07:55:12 Done.
93 Vector<ContextMenuItem> m_items;
94 };
95
96
38 } //namespace 97 } //namespace
39 98
40 #endif 99 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698