| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/page/CustomContextMenuProvider.h" | 6 #include "core/page/CustomContextMenuProvider.h" |
| 7 | 7 |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/ElementTraversal.h" | 9 #include "core/dom/ElementTraversal.h" |
| 10 #include "core/events/EventDispatcher.h" | 10 #include "core/events/EventDispatcher.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 } | 73 } |
| 74 | 74 |
| 75 void CustomContextMenuProvider::appendMenuItem(HTMLMenuItemElement* menuItem, Co
ntextMenu& contextMenu) | 75 void CustomContextMenuProvider::appendMenuItem(HTMLMenuItemElement* menuItem, Co
ntextMenu& contextMenu) |
| 76 { | 76 { |
| 77 // Avoid menuitems with no label. | 77 // Avoid menuitems with no label. |
| 78 String labelString = menuItem->fastGetAttribute(labelAttr); | 78 String labelString = menuItem->fastGetAttribute(labelAttr); |
| 79 if (labelString.isEmpty()) | 79 if (labelString.isEmpty()) |
| 80 return; | 80 return; |
| 81 | 81 |
| 82 m_menuItems.append(menuItem); | 82 m_menuItems.append(menuItem); |
| 83 contextMenu.appendItem(ContextMenuItem(ActionType, static_cast<ContextMenuAc
tion>(ContextMenuItemBaseCustomTag + m_menuItems.size() - 1), labelString, !menu
Item->fastHasAttribute(disabledAttr), false)); | 83 |
| 84 bool enabled = !menuItem->fastHasAttribute(disabledAttr); |
| 85 ContextMenuAction action = static_cast<ContextMenuAction>(ContextMenuItemBas
eCustomTag + m_menuItems.size() - 1); |
| 86 if (equalIgnoringCase(menuItem->fastGetAttribute(typeAttr), "checkbox")) |
| 87 contextMenu.appendItem(ContextMenuItem(CheckableActionType, action, labe
lString, enabled, menuItem->fastHasAttribute(checkedAttr))); |
| 88 else |
| 89 contextMenu.appendItem(ContextMenuItem(ActionType, action, labelString,
enabled, false)); |
| 84 } | 90 } |
| 85 | 91 |
| 86 void CustomContextMenuProvider::populateContextMenuItems(const HTMLMenuElement&
menu, ContextMenu& contextMenu) | 92 void CustomContextMenuProvider::populateContextMenuItems(const HTMLMenuElement&
menu, ContextMenu& contextMenu) |
| 87 { | 93 { |
| 88 HTMLElement* nextElement = Traversal<HTMLElement>::firstWithin(menu); | 94 HTMLElement* nextElement = Traversal<HTMLElement>::firstWithin(menu); |
| 89 while (nextElement) { | 95 while (nextElement) { |
| 90 if (isHTMLHRElement(*nextElement)) { | 96 if (isHTMLHRElement(*nextElement)) { |
| 91 appendSeparator(contextMenu); | 97 appendSeparator(contextMenu); |
| 92 nextElement = Traversal<HTMLElement>::next(*nextElement, &menu); | 98 nextElement = Traversal<HTMLElement>::next(*nextElement, &menu); |
| 93 } else if (isHTMLMenuElement(*nextElement)) { | 99 } else if (isHTMLMenuElement(*nextElement)) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 119 | 125 |
| 120 HTMLElement* CustomContextMenuProvider::menuItemAt(unsigned menuId) | 126 HTMLElement* CustomContextMenuProvider::menuItemAt(unsigned menuId) |
| 121 { | 127 { |
| 122 int itemIndex = menuId - ContextMenuItemBaseCustomTag; | 128 int itemIndex = menuId - ContextMenuItemBaseCustomTag; |
| 123 if (itemIndex < 0 || static_cast<unsigned long>(itemIndex) >= m_menuItems.si
ze()) | 129 if (itemIndex < 0 || static_cast<unsigned long>(itemIndex) >= m_menuItems.si
ze()) |
| 124 return nullptr; | 130 return nullptr; |
| 125 return m_menuItems[itemIndex].get(); | 131 return m_menuItems[itemIndex].get(); |
| 126 } | 132 } |
| 127 | 133 |
| 128 } // namespace blink | 134 } // namespace blink |
| OLD | NEW |