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