2 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
3 * Copyright (C) 2010 Apple Inc. All rights reserved.
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.
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.
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.
24 #include "HTMLNoScriptElement.h"
26 #include "CSSStyleSelector.h"
27 #include "HTMLNames.h"
28 #include "RenderObject.h"
32 using namespace HTMLNames;
34 inline HTMLNoScriptElement::HTMLNoScriptElement(const QualifiedName& tagName, Document* document)
35 : HTMLElement(tagName, document)
37 ASSERT(hasTagName(noscriptTag));
39 setHasCustomWillOrDidRecalcStyle();
41 setHasCustomStyleForRenderer();
45 PassRefPtr<HTMLNoScriptElement> HTMLNoScriptElement::create(const QualifiedName& tagName, Document* document)
47 return adoptRef(new HTMLNoScriptElement(tagName, document));
50 void HTMLNoScriptElement::attach()
52 HTMLElement::attach();
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();
62 bool HTMLNoScriptElement::willRecalcStyle(StyleChange)
64 if (!document()->shouldProcessNoscriptElement() || !renderer() || !renderer()->style())
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);
72 // Create renderers for its children
73 if (hasChildNodes()) {
74 for (Node* n = firstChild(); n; n = n->traverseNextNode(this))
76 n->createRendererIfNeeded();
83 PassRefPtr<RenderStyle> HTMLNoScriptElement::customStyleForRenderer()
85 // noscript needs the display property protected - it's a special case
87 return document()->styleSelector()->styleForElement(static_cast<Element*>(this), 0, false/*allowSharing*/);
91 bool HTMLNoScriptElement::childShouldCreateRenderer(Node*) const
93 return document()->shouldProcessNoscriptElement();