initial import
[vuplus_webkit] / Source / WebCore / html / HTMLNoScriptElement.cpp
1 /*
2  * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
3  * Copyright (C) 2010 Apple Inc. All rights reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #include "config.h"
22
23 #if ENABLE(XHTMLMP)
24 #include "HTMLNoScriptElement.h"
25
26 #include "CSSStyleSelector.h"
27 #include "HTMLNames.h"
28 #include "RenderObject.h"
29
30 namespace WebCore {
31
32 using namespace HTMLNames;
33
34 inline HTMLNoScriptElement::HTMLNoScriptElement(const QualifiedName& tagName, Document* document)
35     : HTMLElement(tagName, document)
36 {
37     ASSERT(hasTagName(noscriptTag));
38
39     setHasCustomWillOrDidRecalcStyle();
40 #if ENABLE(XHTMLMP)
41     setHasCustomStyleForRenderer();
42 #endif
43 }
44
45 PassRefPtr<HTMLNoScriptElement> HTMLNoScriptElement::create(const QualifiedName& tagName, Document* document)
46 {
47     return adoptRef(new HTMLNoScriptElement(tagName, document));
48 }
49
50 void HTMLNoScriptElement::attach()
51 {
52     HTMLElement::attach();
53
54     // If no need to process <noscript>, we hide it by setting display:none temporarily
55     if (!document()->shouldProcessNoscriptElement()) {
56         if (renderer() && renderer()->style())
57             renderer()->style()->setDisplay(NONE);
58         setNeedsStyleRecalc();
59     }
60 }
61
62 bool HTMLNoScriptElement::willRecalcStyle(StyleChange)
63 {
64     if (!document()->shouldProcessNoscriptElement() || !renderer() || !renderer()->style())
65         return false;
66
67     // If <noscript> needs processing, we make it visiable here, including its visible children
68     RefPtr<RenderStyle> style = renderer()->style();
69     if (style->display() == NONE) {
70         style->setDisplay(INLINE);
71
72         // Create renderers for its children
73         if (hasChildNodes()) {
74             for (Node* n = firstChild(); n; n = n->traverseNextNode(this))
75                 if (!n->renderer())
76                     n->createRendererIfNeeded();
77         }
78     }
79     return false;
80 }
81     
82 #if ENABLE(XHTMLMP)
83 PassRefPtr<RenderStyle> HTMLNoScriptElement::customStyleForRenderer()
84 {
85     // noscript needs the display property protected - it's a special case
86     // FIXME: Why?
87     return document()->styleSelector()->styleForElement(static_cast<Element*>(this), 0, false/*allowSharing*/);
88 }
89 #endif
90
91 bool HTMLNoScriptElement::childShouldCreateRenderer(Node*) const
92 {
93     return document()->shouldProcessNoscriptElement();
94 }
95
96 }
97
98 #endif