 Chromium Code Reviews
 Chromium Code Reviews Issue 464903002:
  Add contextmenu attribute for HTMLElement.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master
    
  
    Issue 464903002:
  Add contextmenu attribute for HTMLElement.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master| Index: Source/core/html/HTMLElement.cpp | 
| diff --git a/Source/core/html/HTMLElement.cpp b/Source/core/html/HTMLElement.cpp | 
| index 041571390d1c06175442ff1acafa8f5410bc8275..7f192dc360c17804c26279c6a8574a25d5bcf840 100644 | 
| --- a/Source/core/html/HTMLElement.cpp | 
| +++ b/Source/core/html/HTMLElement.cpp | 
| @@ -48,6 +48,7 @@ | 
| #include "core/html/HTMLBRElement.h" | 
| #include "core/html/HTMLFormElement.h" | 
| #include "core/html/HTMLInputElement.h" | 
| +#include "core/html/HTMLMenuElement.h" | 
| #include "core/html/HTMLTemplateElement.h" | 
| #include "core/html/HTMLTextFormControlElement.h" | 
| #include "core/html/parser/HTMLParserIdioms.h" | 
| @@ -901,6 +902,38 @@ bool HTMLElement::isInteractiveContent() const | 
| return false; | 
| } | 
| + | 
| +HTMLMenuElement* HTMLElement::contextMenu() const | 
| +{ | 
| + const AtomicString& contextMenuId(fastGetAttribute(contextmenuAttr)); | 
| + if (contextMenuId.isNull()) | 
| + return nullptr; | 
| + | 
| + Element* element = treeScope().getElementById(contextMenuId); | 
| + // Not checking if the menu element is of type "popup". | 
| + // Ignoring menu element type attribute is intentional according to the standard. | 
| + return isHTMLMenuElement(element) ? toHTMLMenuElement(element) : nullptr; | 
| +} | 
| + | 
| +void HTMLElement::setContextMenu(HTMLMenuElement* contextMenu) | 
| +{ | 
| + if (!contextMenu) | 
| 
tkent
2014/08/19 01:14:41
The specification isn't clear, but I think |elemen
 
pals
2014/08/19 10:12:32
Done.
 | 
| + return; | 
| + | 
| + // http://www.whatwg.org/specs/web-apps/current-work/multipage/infrastructure.html#reflecting-content-attributes-in-idl-attributes | 
| + // On setting, if the given element has an id attribute, and has the same home | 
| + // subtree as the element of the attribute being set, and the given element is the | 
| + // first element in that home subtree whose ID is the value of that id attribute, | 
| + // then the content attribute must be set to the value of that id attribute. | 
| + // Otherwise, the content attribute must be set to the empty string. | 
| + const AtomicString& contextMenuId(contextMenu->fastGetAttribute(idAttr)); | 
| + | 
| + if (!contextMenuId.isNull() && (contextMenu == treeScope().getElementById(contextMenuId)) && contextMenu->isInTreeScope()) | 
| 
tkent
2014/08/19 01:14:41
The parentheses on the second condition is unneces
 
pals
2014/08/19 10:12:32
Done.
 | 
| + setAttribute(contextmenuAttr, contextMenuId); | 
| + else | 
| + setAttribute(contextmenuAttr, ""); | 
| +} | 
| + | 
| void HTMLElement::defaultEventHandler(Event* event) | 
| { | 
| if (event->type() == EventTypeNames::keypress && event->isKeyboardEvent()) { |