/*
 * Copyright (C) 2017 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

WI.DOMNodeTreeElement = class DOMNodeTreeElement extends WI.GeneralTreeElement
{
    constructor(domNode)
    {
        console.assert(domNode instanceof WI.DOMNode);

        const subtitle = null;
        super("dom-node", domNode.displayName, subtitle, domNode, {hasChildren: true});

        this.status = WI.linkifyNodeReferenceElement(domNode, WI.createGoToArrowButton());
        this.tooltipHandledSeparately = true;
    }

    // Protected

    ondelete()
    {
        WI.domDebuggerManager.removeDOMBreakpointsForNode(this.representedObject);
        return true;
    }

    populateContextMenu(contextMenu, event)
    {
        contextMenu.appendSeparator();

        const allowEditing = true;
        WI.DOMBreakpointTreeController.appendBreakpointContextMenuItems(contextMenu, this.representedObject, allowEditing);

        contextMenu.appendSeparator();

        contextMenu.appendItem(WI.UIString("Reveal in DOM Tree"), () => {
            WI.domTreeManager.inspectElement(this.representedObject.id);
        });
    }
};
