[webkit-changes] cvs commit: WebCore/layout-tests/fast/dom title-text-property-2-expected.txt title-text-property-2.html title-text-property-expected.txt title-text-property.html

Darin darin at opensource.apple.com
Wed Jun 22 11:22:04 PDT 2005


darin       05/06/22 11:22:03

  Modified:    .        ChangeLog
               khtml/dom html_head.cpp
               khtml/html html_headimpl.cpp
               khtml/xml dom_docimpl.cpp dom_docimpl.h
  Added:       layout-tests/fast/dom title-text-property-2-expected.txt
                        title-text-property-2.html
                        title-text-property-expected.txt
                        title-text-property.html
  Log:
          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 <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
  1.4302    +56 -14    WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.4301
  retrieving revision 1.4302
  diff -u -r1.4301 -r1.4302
  --- ChangeLog	22 Jun 2005 17:39:48 -0000	1.4301
  +++ ChangeLog	22 Jun 2005 18:21:57 -0000	1.4302
  @@ -1,3 +1,45 @@
  +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 <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-06-22  Darin Adler  <darin at apple.com>
   
           Changes by Mitz Pettel.
  @@ -50,20 +92,20 @@
   
           Patch from KevinBallard <kevin at sb.org>, reviewed by me.
   
  -	- fix build for Xcode 2.1, use ${} for INPUT_FILE_BASE to fix build with Xcode 2.1
  +        - fix build for Xcode 2.1, use ${} for INPUT_FILE_BASE to fix build with Xcode 2.1
   
           * WebCore.pbproj/project.pbxproj:
   
   2005-06-21  Justin Garcia  <justin.garcia at apple.com>
   
  -	- Fixes <rdar://problem/4114192>.
  -	- Fixes a crash in TOT Mail/Blot if you Edit -> Add Hyperlink on a Selection 
  -	   that ends at the end of the document
  -	- Fixes a problem in TOT Mail/Blot where Edit -> Add Hyperlink creates 
  -	   a link one character beyond what is expected.
  -	
  -	In replacement, during insertion, some special case code was being called inappropriately.
  -	
  +        - Fixes <rdar://problem/4114192>.
  +        - Fixes a crash in TOT Mail/Blot if you Edit -> Add Hyperlink on a Selection 
  +           that ends at the end of the document
  +        - Fixes a problem in TOT Mail/Blot where Edit -> Add Hyperlink creates 
  +           a link one character beyond what is expected.
  +        
  +        In replacement, during insertion, some special case code was being called inappropriately.
  +        
           Reviewed by Harrison
   
           Test cases added: None, requires manual interaction
  @@ -171,8 +213,8 @@
           - make eval() call processVarDecls - needed to match mozilla and
           to make the second change testable
   
  -	Test cases only, fix is in JavaScriptCore
  -	
  +        Test cases only, fix is in JavaScriptCore
  +        
           Test cases added:
           * layout-tests/fast/js/const-expected.txt: Added.
           * layout-tests/fast/js/const.html: Added.
  @@ -183,12 +225,12 @@
   
           Patch from Mark Rowe <opendarwin.org at bdash.net.nz>, reviewed by me.
   
  -	- fixed http://bugzilla.opendarwin.org/attachment.cgi?id=2483
  -	
  +        - fixed http://bugzilla.opendarwin.org/attachment.cgi?id=2483
  +        
           Test cases added: 
           * layout-tests/fast/js/hasOwnProperty-expected.txt: Added.
           * layout-tests/fast/js/hasOwnProperty.html: Added.
  -	- also fixed two mozilla JS tests
  +        - also fixed two mozilla JS tests
   	
           * khtml/ecma/kjs_binding.h:
           * khtml/ecma/kjs_css.cpp:
  
  
  
  1.10      +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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- html_head.cpp	19 Jun 2005 05:44:27 -0000	1.9
  +++ html_head.cpp	22 Jun 2005 18:22:01 -0000	1.10
  @@ -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);
   }
   
  
  
  
  1.50      +25 -16    WebCore/khtml/html/html_headimpl.cpp
  
  Index: html_headimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/html_headimpl.cpp,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- html_headimpl.cpp	19 Jun 2005 05:44:28 -0000	1.49
  +++ html_headimpl.cpp	22 Jun 2005 18:22:01 -0000	1.50
  @@ -824,7 +824,7 @@
   // -------------------------------------------------------------------------
   
   HTMLTitleElementImpl::HTMLTitleElementImpl(DocumentPtr *doc)
  -    : HTMLElementImpl(doc)
  +    : HTMLElementImpl(doc), m_title("")
   {
   }
   
  @@ -840,17 +840,13 @@
   void HTMLTitleElementImpl::insertedIntoDocument()
   {
       HTMLElementImpl::insertedIntoDocument();
  -    // Only allow title to be set by first <title> encountered.
  -    if (getDocument()->title().isEmpty())
  -        getDocument()->setTitle(m_title);
  +    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()
  @@ -861,21 +857,34 @@
   	if ((c->nodeType() == Node::TEXT_NODE) || (c->nodeType() == Node::CDATA_SECTION_NODE))
   	    m_title += c->nodeValue();
       }
  -    // Only allow title to be set by first <title> encountered.
  -    if (inDocument() && getDocument()->title().isEmpty())
  -	getDocument()->setTitle(m_title);
  +    if (inDocument())
  +        getDocument()->setTitle(m_title, this);
   }
   
   DOMString HTMLTitleElementImpl::text() const
   {
  -    // FIXME: Obviously wrong! There's no "text" attribute on a title element.
  -    // Need to do something with the children perhaps?
  -    return getAttribute(ATTR_TEXT);
  +    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)
   {
  -    // FIXME: Obviously wrong! There's no "text" attribute on a title element.
  -    // Need to do something with the children perhaps?
  -    setAttribute(ATTR_TEXT, 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.230     +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.229
  retrieving revision 1.230
  diff -u -r1.229 -r1.230
  --- dom_docimpl.cpp	19 Jun 2005 05:00:25 -0000	1.229
  +++ dom_docimpl.cpp	22 Jun 2005 18:22:02 -0000	1.230
  @@ -284,6 +284,9 @@
   DocumentImpl::DocumentImpl(DOMImplementationImpl *_implementation, KHTMLView *v)
       : ContainerNodeImpl( 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))
  @@ -431,7 +434,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;
  @@ -725,15 +731,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)
  @@ -741,7 +746,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;
  @@ -750,11 +755,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.115     +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.114
  retrieving revision 1.115
  diff -u -r1.114 -r1.115
  --- dom_docimpl.h	13 May 2005 16:48:51 -0000	1.114
  +++ dom_docimpl.h	22 Jun 2005 18:22:02 -0000	1.115
  @@ -196,7 +196,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);
   
       SharedPtr<HTMLCollectionImpl> images();
       SharedPtr<HTMLCollectionImpl> embeds();
  @@ -677,6 +678,8 @@
       bool m_usesSiblingRules;
   
       DOMString m_title;
  +    bool m_titleSetExplicitly;
  +    NodeImpl *m_titleElement;
       
       RenderArena* m_renderArena;
   
  @@ -748,6 +751,7 @@
       void unregisterDisconnectedNodeWithEventListeners(NodeImpl *node);
   
   private:
  +    void updateTitle();
       void removeAllDisconnectedNodeEventListeners();
   
       JSEditor *jsEditor();
  
  
  
  1.1                  WebCore/layout-tests/fast/dom/title-text-property-2-expected.txt
  
  Index: title-text-property-2-expected.txt
  ===================================================================
  TITLE CHANGED: 1. setting document.title
  TITLE CHANGED: 2. setting title.text
  
  
  
  
  1.1                  WebCore/layout-tests/fast/dom/title-text-property-2.html
  
  Index: title-text-property-2.html
  ===================================================================
  <html>
  <head>
  <script>
  function runTests() {
      if (window.layoutTestController) {
          layoutTestController.dumpAsText();
          layoutTestController.dumpTitleChanges();
      }
      
      document.title='1. setting document.title';
  
      title = document.getElementsByTagName('title').item(0);
      
      title.text = '2. setting title.text';
      
      newTitle = document.createElement('title');
      newTitle.appendChild(document.createTextNode('3. appending a new title node (should not trigger a title change)'));
      
      document.getElementsByTagName('head').item(0).appendChild(newTitle);
      
      // Remove both title elements 
      titleElements = document.getElementsByTagName('title');
      for (i = 0; i < titleElements.length; i++) {
          titleElement = titleElements.item(i);
          titleElement.parentNode.removeChild(titleElement);
      }
  }
  </script>
  <title>Initial title</title>
  </head> 
  <body onload="runTests();" >
  </body>
  </html>
  
  
  
  1.1                  WebCore/layout-tests/fast/dom/title-text-property-expected.txt
  
  Index: title-text-property-expected.txt
  ===================================================================
  TITLE CHANGED: This is the new title
  Original title is: Original Title
  Setting new title to: This is the new title
  New title is: This is the new title
  
  
  
  
  1.1                  WebCore/layout-tests/fast/dom/title-text-property.html
  
  Index: title-text-property.html
  ===================================================================
  <html>
  <head>
  <title>Original Title</title>
  <script>
  function debugOutput(str) {
      text = document.createTextNode(str);
      debugDiv = document.getElementById('debugDiv');
      div = document.createElement ('div');
      div.appendChild(text);
      debugDiv.appendChild(div);
  }
  
  function runTests() {
      if (window.layoutTestController) {
          layoutTestController.dumpAsText();
          layoutTestController.dumpTitleChanges();
      }
  
      titleElem = document.getElementsByTagName('title').item(0);
      debugOutput ('Original title is: ' + titleElem.text);
  
      newTitle = 'This is the new title';
      debugOutput ('Setting new title to: ' + newTitle);
      titleElem.text = newTitle;
  
      debugOutput ('New title is: ' + titleElem.text);
  }
  
  function test() {
      t = document.getElementsByTagName('title').item(0);
      alert (t.text);
      t.text = 'new title';
      alert (t.text);
  }
  </script>
  </head>
  <body onload='runTests();'>
  <div id='debugDiv'>
  </div>
  </body>
  </html>
  
  
  



More information about the webkit-changes mailing list