[webkit-changes] cvs commit: WebCore/khtml/xml dom_docimpl.cpp dom_docimpl.h

Adele adele at opensource.apple.com
Tue Jul 12 11:26:28 PDT 2005


adele       05/07/12 11:26:28

  Modified:    .        Tag: Safari-1-3-branch ChangeLog
               khtml/dom Tag: Safari-1-3-branch html_head.cpp
               khtml/html Tag: Safari-1-3-branch html_headimpl.cpp
                        html_headimpl.h
               khtml/xml Tag: Safari-1-3-branch dom_docimpl.cpp
                        dom_docimpl.h
  Log:
          Merged fix from TOT to Safari-1-3-branch
          <rdar://problem/4164941> REGRESSION (1.2.4-1.3): many titles with non-ASCII characters do not display properly (XHTML strict only)
  
      2005-06-22  Anders Carlsson  <andersca at mac.com>
  
          Reviewed and landed by Darin Adler.
  
          Test cases added:
          * layout-tests/fast/dom/title-text-property-expected.txt: Added
          * layout-tests/fast/dom/title-text-property.html: Added
          * layout-tests/fast/dom/title-text-property-expected-2.txt: Added
          * layout-tests/fast/dom/title-text-property-2.html: Added
  
          - fixed <rdar://problem/3831364> getting or setting text for a <title> element doesn't work
          - fixed <rdar://problem/4091225> REGRESSION (1.2.4-1.3): many titles with non-ASCII characters do not display properly (XHTML strict only)
          - fixed <http://bugzilla.opendarwin.org/show_bug.cgi?id=3586>
            Setting and getting title's text attribute does not work
  
          * khtml/dom/html_head.cpp:
          (HTMLTitleElement::text):
          (HTMLTitleElement::setText):
          Call HTMLTitleElementImpl::text() and ::setText().
  
          * khtml/html/html_headimpl.cpp:
          (HTMLTitleElementImpl::HTMLTitleElementImpl):
          (HTMLTitleElementImpl::insertedIntoDocument):
          (HTMLTitleElementImpl::removedFromDocument):
          (HTMLTitleElementImpl::childrenChanged):
          Pass the current title node to DocumentImpl::setTitle
          and ::removeTitle.
  
          (HTMLTitleElementImpl::text):
          Return the title.
  
          (HTMLTitleElementImpl::setText):
          Set the new title.
  
          * khtml/xml/dom_docimpl.cpp:
          (DocumentImpl::DocumentImpl):
          (DocumentImpl::~DocumentImpl):
          (DocumentImpl::updateTitle):
          (DocumentImpl::setTitle):
          (DocumentImpl::removeTitle):
          * khtml/xml/dom_docimpl.h:
          Only update the title if it's done by setting document.title
          or by changing the child nodes of the title element.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.4108.4.21 +50 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.4108.4.20
  retrieving revision 1.4108.4.21
  diff -u -r1.4108.4.20 -r1.4108.4.21
  --- ChangeLog	12 Jul 2005 17:52:38 -0000	1.4108.4.20
  +++ ChangeLog	12 Jul 2005 18:26:15 -0000	1.4108.4.21
  @@ -1,3 +1,53 @@
  +2005-07-12  Adele Peterson  <adele at apple.com>
  +
  +        Merged fix from TOT to Safari-1-3-branch
  +        <rdar://problem/4164941> REGRESSION (1.2.4-1.3): many titles with non-ASCII characters do not display properly (XHTML strict only)
  +
  +    2005-06-22  Anders Carlsson  <andersca at mac.com>
  +
  +        Reviewed and landed by Darin Adler.
  +
  +        Test cases added: 
  +        * layout-tests/fast/dom/title-text-property-expected.txt: Added
  +        * layout-tests/fast/dom/title-text-property.html: Added
  +        * layout-tests/fast/dom/title-text-property-expected-2.txt: Added
  +        * layout-tests/fast/dom/title-text-property-2.html: Added
  +
  +        - fixed <rdar://problem/3831364> getting or setting text for a <title> element doesn't work
  +        - fixed <rdar://problem/4091225> REGRESSION (1.2.4-1.3): many titles with non-ASCII characters do not display properly (XHTML strict only)
  +        - fixed <http://bugzilla.opendarwin.org/show_bug.cgi?id=3586>
  +          Setting and getting title's text attribute does not work
  +
  +        * khtml/dom/html_head.cpp:
  +        (HTMLTitleElement::text):
  +        (HTMLTitleElement::setText):
  +        Call HTMLTitleElementImpl::text() and ::setText().
  +
  +        * khtml/html/html_headimpl.cpp:
  +        (HTMLTitleElementImpl::HTMLTitleElementImpl):
  +        (HTMLTitleElementImpl::insertedIntoDocument):
  +        (HTMLTitleElementImpl::removedFromDocument):
  +        (HTMLTitleElementImpl::childrenChanged):
  +        Pass the current title node to DocumentImpl::setTitle
  +        and ::removeTitle.
  +
  +        (HTMLTitleElementImpl::text):
  +        Return the title.
  +
  +        (HTMLTitleElementImpl::setText):
  +        Set the new title.
  +
  +        * khtml/xml/dom_docimpl.cpp:
  +        (DocumentImpl::DocumentImpl):
  +        (DocumentImpl::~DocumentImpl):
  +        (DocumentImpl::updateTitle):
  +        (DocumentImpl::setTitle):
  +        (DocumentImpl::removeTitle):
  +        * khtml/xml/dom_docimpl.h:
  +        Only update the title if it's done by setting document.title
  +        or by changing the child nodes of the title element.
  +
  +
   2005-07-12  Vicki Murley  <vicki at apple.com>
   
   	- merge this fix from HEAD
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.8.26.1  +2 -2      WebCore/khtml/dom/html_head.cpp
  
  Index: html_head.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/dom/html_head.cpp,v
  retrieving revision 1.8
  retrieving revision 1.8.26.1
  diff -u -r1.8 -r1.8.26.1
  --- html_head.cpp	3 Nov 2003 06:32:04 -0000	1.8
  +++ html_head.cpp	12 Jul 2005 18:26:25 -0000	1.8.26.1
  @@ -513,11 +513,11 @@
   DOMString HTMLTitleElement::text() const
   {
       if(!impl) return DOMString();
  -    return ((ElementImpl *)impl)->getAttribute(ATTR_TEXT);
  +    return ((HTMLTitleElementImpl *)impl)->text();
   }
   
   void HTMLTitleElement::setText( const DOMString &value )
   {
  -    if(impl) ((ElementImpl *)impl)->setAttribute(ATTR_TEXT, value);
  +    if(impl) ((HTMLTitleElementImpl *)impl)->setText(value);
   }
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.43.14.2 +32 -17    WebCore/khtml/html/html_headimpl.cpp
  
  Index: html_headimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/html_headimpl.cpp,v
  retrieving revision 1.43.14.1
  retrieving revision 1.43.14.2
  diff -u -r1.43.14.1 -r1.43.14.2
  --- html_headimpl.cpp	5 May 2005 00:15:50 -0000	1.43.14.1
  +++ html_headimpl.cpp	12 Jul 2005 18:26:26 -0000	1.43.14.2
  @@ -538,7 +538,7 @@
   // -------------------------------------------------------------------------
   
   HTMLTitleElementImpl::HTMLTitleElementImpl(DocumentPtr *doc)
  -    : HTMLElementImpl(doc)
  +    : HTMLElementImpl(doc), m_title("")
   {
   }
   
  @@ -554,21 +554,13 @@
   void HTMLTitleElementImpl::insertedIntoDocument()
   {
       HTMLElementImpl::insertedIntoDocument();
  -#if APPLE_CHANGES
  -    // Only allow title to be set by first <title> encountered.
  -    if (getDocument()->title().isEmpty())
  -        getDocument()->setTitle(m_title);
  -#else
  -        getDocument()->setTitle(m_title);
  -#endif
  +    getDocument()->setTitle(m_title, this);
   }
   
   void HTMLTitleElementImpl::removedFromDocument()
   {
       HTMLElementImpl::removedFromDocument();
  -    // Title element removed, so we have no title... we ignore the case of multiple title elements, as it's invalid
  -    // anyway (?)
  -    getDocument()->setTitle(DOMString());
  +    getDocument()->removeTitle(this);
   }
   
   void HTMLTitleElementImpl::childrenChanged()
  @@ -579,11 +571,34 @@
   	if ((c->nodeType() == Node::TEXT_NODE) || (c->nodeType() == Node::CDATA_SECTION_NODE))
   	    m_title += c->nodeValue();
       }
  -#if APPLE_CHANGES
  -    // Only allow title to be set by first <title> encountered.
  -    if (inDocument() && getDocument()->title().isEmpty())
  -#else
       if (inDocument())
  -#endif
  -	getDocument()->setTitle(m_title);
  +        getDocument()->setTitle(m_title, this);
  +}
  +
  +DOMString HTMLTitleElementImpl::text() const
  +{
  +    DOMString val = "";
  +
  +    for (NodeImpl *n = firstChild(); n; n = n->nextSibling()) {
  +        if (n->isTextNode())
  +            val += static_cast<TextImpl *>(n)->data();
  +    }
  +
  +    return val;
  +}
  +
  +void HTMLTitleElementImpl::setText(const DOMString &value)
  +{
  +    int exceptioncode = 0;
  +    int numChildren = childNodeCount();
  +
  +    if (numChildren == 1 && firstChild()->isTextNode()) {
  +        static_cast<DOM::TextImpl *>(firstChild())->setData(value, exceptioncode);
  +    } else {  
  +        if (numChildren > 0) {
  +            removeChildren();
  +        }
  +        
  +        appendChild(getDocument()->createTextNode(value.implementation()), exceptioncode);
  +    }
   }
  
  
  
  1.15.14.2 +3 -0      WebCore/khtml/html/html_headimpl.h
  
  Index: html_headimpl.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/html_headimpl.h,v
  retrieving revision 1.15.14.1
  retrieving revision 1.15.14.2
  diff -u -r1.15.14.1 -r1.15.14.2
  --- html_headimpl.h	5 May 2005 00:15:50 -0000	1.15.14.1
  +++ html_headimpl.h	12 Jul 2005 18:26:26 -0000	1.15.14.2
  @@ -197,6 +197,9 @@
       virtual void insertedIntoDocument();
       virtual void removedFromDocument();
       virtual void childrenChanged();
  +    
  +    DOMString text() const;
  +    void setText(const DOMString &);
   
   protected:
       DOMString m_title;
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.211.4.2 +54 -8     WebCore/khtml/xml/dom_docimpl.cpp
  
  Index: dom_docimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom_docimpl.cpp,v
  retrieving revision 1.211.4.1
  retrieving revision 1.211.4.2
  diff -u -r1.211.4.1 -r1.211.4.2
  --- dom_docimpl.cpp	16 Apr 2005 00:14:16 -0000	1.211.4.1
  +++ dom_docimpl.cpp	12 Jul 2005 18:26:26 -0000	1.211.4.2
  @@ -264,6 +264,9 @@
   DocumentImpl::DocumentImpl(DOMImplementationImpl *_implementation, KHTMLView *v)
       : NodeBaseImpl( new DocumentPtr() )
         , m_domtree_version(0)
  +      , m_title("")
  +      , m_titleSetExplicitly(false)
  +      , m_titleElement(0)
         , m_imageLoadEventTimer(0)
   #ifndef KHTML_NO_XBL
         , m_bindingManager(new XBLBindingManager(this))
  @@ -407,7 +410,10 @@
           m_focusNode->deref();
       if (m_hoverNode)
           m_hoverNode->deref();
  -    
  +
  +    if (m_titleElement)
  +        m_titleElement->deref();
  +
       if (m_renderArena){
           delete m_renderArena;
           m_renderArena = 0;
  @@ -692,15 +698,14 @@
       return m_elementsByAccessKey.find(k);
   }
   
  -void DocumentImpl::setTitle(DOMString _title)
  +void DocumentImpl::updateTitle()
   {
  -    m_title = _title;
  -
  -    if (!part())
  +    KHTMLPart *p = part();
  +    if (!p)
           return;
   
   #if APPLE_CHANGES
  -    KWQ(part())->setTitle(_title);
  +    KWQ(p)->setTitle(m_title);
   #else
       QString titleStr = m_title.string();
       for (int i = 0; i < titleStr.length(); ++i)
  @@ -708,7 +713,7 @@
               titleStr[i] = ' ';
       titleStr = titleStr.stripWhiteSpace();
       titleStr.compose();
  -    if ( !part()->parentPart() ) {
  +    if ( !p->parentPart() ) {
   	if (titleStr.isNull() || titleStr.isEmpty()) {
   	    // empty title... set window caption as the URL
   	    KURL url = m_url;
  @@ -717,11 +722,52 @@
   	    titleStr = url.url();
   	}
   
  -	emit part()->setWindowCaption( KStringHandler::csqueeze( titleStr, 128 ) );
  +	emit p->setWindowCaption( KStringHandler::csqueeze( titleStr, 128 ) );
       }
   #endif
   }
   
  +void DocumentImpl::setTitle(DOMString title, NodeImpl *titleElement)
  +{
  +    if (!titleElement) {
  +        // Title set by JavaScript -- overrides any title elements.
  +        m_titleSetExplicitly = true;
  +        if (m_titleElement) {
  +            m_titleElement->deref();
  +            m_titleElement = 0;
  +        }
  +    } else if (titleElement != m_titleElement) {
  +        if (m_titleElement) {
  +            // Only allow the first title element to change the title -- others have no effect.
  +            return;
  +        }
  +        m_titleElement = titleElement;
  +        titleElement->ref();
  +    }
  +
  +    if (m_title == title)
  +        return;
  +
  +    m_title = title;
  +    updateTitle();
  +}
  +
  +void DocumentImpl::removeTitle(NodeImpl *titleElement)
  +{
  +    if (m_titleElement != titleElement)
  +        return;
  +
  +    // FIXME: Ideally we might want this to search for the first remaining title element, and use it.
  +    m_titleElement = 0;
  +
  +    titleElement->deref();
  +
  +    if (!m_title.isEmpty()) {
  +        m_title = "";
  +        updateTitle();
  +    }
  +}
  +
   DOMString DocumentImpl::nodeName() const
   {
       return "#document";
  
  
  
  1.104.4.2 +5 -1      WebCore/khtml/xml/dom_docimpl.h
  
  Index: dom_docimpl.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom_docimpl.h,v
  retrieving revision 1.104.4.1
  retrieving revision 1.104.4.2
  diff -u -r1.104.4.1 -r1.104.4.2
  --- dom_docimpl.h	16 Apr 2005 00:14:16 -0000	1.104.4.1
  +++ dom_docimpl.h	12 Jul 2005 18:26:27 -0000	1.104.4.2
  @@ -201,7 +201,8 @@
   
       // Actually part of HTMLDocument, but used for giving XML documents a window title as well
       DOMString title() const { return m_title; }
  -    void setTitle(DOMString _title);
  +    void setTitle(DOMString, NodeImpl *titleElement = 0);
  +    void removeTitle(NodeImpl *titleElement);
   
       // DOM methods overridden from  parent classes
   
  @@ -672,6 +673,8 @@
       bool m_usesSiblingRules;
   
       DOMString m_title;
  +    bool m_titleSetExplicitly;
  +    NodeImpl *m_titleElement;
       
       RenderArena* m_renderArena;
   
  @@ -743,6 +746,7 @@
       void unregisterDisconnectedNodeWithEventListeners(NodeImpl *node);
   
   private:
  +    void updateTitle();
       void removeAllDisconnectedNodeEventListeners();
   
       JSEditor *jsEditor();
  
  
  



More information about the webkit-changes mailing list