1/*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1.  Redistributions of source code must retain the above copyright
9 *     notice, this list of conditions and the following disclaimer.
10 * 2.  Redistributions in binary form must reproduce the above copyright
11 *     notice, this list of conditions and the following disclaimer in the
12 *     documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#if ENABLE(DIALOG_ELEMENT)
28#include "HTMLDialogElement.h"
29
30#include "ExceptionCode.h"
31#include "RenderDialog.h"
32
33namespace WebCore {
34
35using namespace HTMLNames;
36
37HTMLDialogElement::HTMLDialogElement(const QualifiedName& tagName, Document* document)
38    : HTMLElement(tagName, document)
39{
40    ASSERT(hasTagName(dialogTag));
41}
42
43PassRefPtr<HTMLDialogElement> HTMLDialogElement::create(const QualifiedName& tagName, Document* document)
44{
45    return adoptRef(new HTMLDialogElement(tagName, document));
46}
47
48void HTMLDialogElement::close(ExceptionCode& ec)
49{
50    if (!fastHasAttribute(openAttr)) {
51        ec = INVALID_STATE_ERR;
52        return;
53    }
54    setBooleanAttribute(openAttr, false);
55    document()->removeFromTopLayer(this);
56}
57
58void HTMLDialogElement::show()
59{
60    if (fastHasAttribute(openAttr))
61        return;
62    setBooleanAttribute(openAttr, true);
63}
64
65void HTMLDialogElement::showModal(ExceptionCode& ec)
66{
67    if (fastHasAttribute(openAttr) || !inDocument()) {
68        ec = INVALID_STATE_ERR;
69        return;
70    }
71    setBooleanAttribute(openAttr, true);
72    document()->addToTopLayer(this);
73}
74
75bool HTMLDialogElement::isPresentationAttribute(const QualifiedName& name) const
76{
77    // FIXME: Workaround for <https://bugs.webkit.org/show_bug.cgi?id=91058>: modifying an attribute for which there is an attribute selector
78    // in html.css sometimes does not trigger a style recalc.
79    if (name == openAttr)
80        return true;
81
82    return HTMLElement::isPresentationAttribute(name);
83}
84
85RenderObject* HTMLDialogElement::createRenderer(RenderArena* arena, RenderStyle*)
86{
87    return new (arena) RenderDialog(this);
88}
89
90}
91
92#endif
93