[webkit-changes] cvs commit: WebCore/layout-tests/fast/xsl document-function-expected.txt document-function.xml document-function.xsl

Darin darin at opensource.apple.com
Wed Jun 29 22:57:19 PDT 2005


darin       05/06/29 22:57:18

  Modified:    .        ChangeLog
               khtml/xsl xslt_processorimpl.cpp xslt_processorimpl.h
  Added:       layout-tests/fast/xsl document-function-expected.txt
                        document-function.xml document-function.xsl
  Log:
          Reviewed and landed by Darin Adler.
  
          - Fix <http://bugzilla.opendarwin.org/show_bug.cgi?id=3274>
          document() not supported
  
          Test cases added:
          * layout-tests/fast/xsl/document-function-expected.txt: Added.
          * layout-tests/fast/xsl/document-function.xml: Added.
          * layout-tests/fast/xsl/document-function.xsl: Added.
          * layout-tests/fast/xsl/resources/document-function-source.xml: Added.
  
          * khtml/xsl/xslt_processorimpl.cpp:
          (DOM::parseErrorFunc):
          Stub to prevent errors from getting written to the console.
  
          (DOM::stylesheetLoadFunc):
          Fetch and parse documents.
  
          (DOM::XSLTProcessorImpl::transformDocument):
          Use the processor as the global variable instead of the
          style sheet.
  
          * khtml/xsl/xslt_processorimpl.h:
          (DOM::XSLTProcessorImpl::stylesheet):
          (DOM::XSLTProcessorImpl::sourceDocument):
          Add accessors for source document and stylesheet.
  
  Revision  Changes    Path
  1.4343    +56 -27    WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.4342
  retrieving revision 1.4343
  diff -u -r1.4342 -r1.4343
  --- ChangeLog	30 Jun 2005 03:19:08 -0000	1.4342
  +++ ChangeLog	30 Jun 2005 05:57:14 -0000	1.4343
  @@ -1,3 +1,32 @@
  +2005-06-29  Anders Carlsson  <andersca at mac.com>
  +
  +        Reviewed and landed by Darin Adler.
  +
  +        - Fix <http://bugzilla.opendarwin.org/show_bug.cgi?id=3274>
  +        document() not supported
  +
  +        Test cases added:
  +        * layout-tests/fast/xsl/document-function-expected.txt: Added.
  +        * layout-tests/fast/xsl/document-function.xml: Added.
  +        * layout-tests/fast/xsl/document-function.xsl: Added.
  +        * layout-tests/fast/xsl/resources/document-function-source.xml: Added.
  +        
  +        * khtml/xsl/xslt_processorimpl.cpp:
  +        (DOM::parseErrorFunc):
  +        Stub to prevent errors from getting written to the console.
  +        
  +        (DOM::stylesheetLoadFunc):
  +        Fetch and parse documents.
  +        
  +        (DOM::XSLTProcessorImpl::transformDocument):
  +        Use the processor as the global variable instead of the 
  +        style sheet.
  +        
  +        * khtml/xsl/xslt_processorimpl.h:
  +        (DOM::XSLTProcessorImpl::stylesheet):
  +        (DOM::XSLTProcessorImpl::sourceDocument):
  +        Add accessors for source document and stylesheet.
  +
   2005-06-29  Maciej Stachowiak  <mjs at apple.com>
   
           Unreviewed - fixing build breakage with gcc 4.
  @@ -6,10 +35,10 @@
   
   2005-06-29  David Harrison  <harrison at apple.com>
   
  -		Temporarily enable tab coalescing ahead of white-space:pre-wrap
  -		change because of problems with keeping the tabs separate.  Will
  -		revert when problems are fixed or remove if I do pre-wrap
  -		first.
  +        Temporarily enable tab coalescing ahead of white-space:pre-wrap
  +        change because of problems with keeping the tabs separate.  Will
  +        revert when problems are fixed or remove if I do pre-wrap
  +        first.
   
           * khtml/editing/insert_text_command.cpp:
           (khtml::InsertTextCommand::prepareForTextInsertion):
  @@ -165,12 +194,12 @@
   
   2005-06-29  Geoffrey Garen  <ggaren at apple.com>
   
  -	Contributed by Francisco Tolmasky <tolmasky at gmail.com>
  +        Contributed by Francisco Tolmasky <tolmasky at gmail.com>
   
  -	-test cases for fix to http://bugzilla.opendarwin.org/show_bug.cgi?id=3667
  -	Core JavaScript 1.5 Reference:Objects:Array:forEach
  +        -test cases for fix to http://bugzilla.opendarwin.org/show_bug.cgi?id=3667
  +        Core JavaScript 1.5 Reference:Objects:Array:forEach
   
  -	See JavaScriptCore Changelog for details on the patch.
  +        See JavaScriptCore Changelog for details on the patch.
   
           Reviewed by darin.
   
  @@ -192,7 +221,7 @@
   
   2005-06-29  Geoffrey Garen  <ggaren at apple.com>
   
  -	DOM compatibility tests for HTMLDocument::writeln
  +        DOM compatibility tests for HTMLDocument::writeln
   
           Reviewed by justing.
   
  @@ -213,7 +242,7 @@
   
   2005-06-29  Geoffrey Garen  <ggaren at apple.com>
   
  -	DOM compatibility tests for HTMLDocument::write
  +        DOM compatibility tests for HTMLDocument::write
   
           Reviewed by justing.
   
  @@ -225,7 +254,7 @@
   
   2005-06-29  Geoffrey Garen  <ggaren at apple.com>
   
  -	DOM compatibility tests for HTMLDocument::title
  +        DOM compatibility tests for HTMLDocument::title
   
           Reviewed by justing.
   
  @@ -240,9 +269,9 @@
           Reviewed by Darin.
   
           Added iterator support to new hashtable class, the HashSet API is
  -	now essentially complete.
  +        now essentially complete.
   
  -	Added support for consistency check mode.
  +        Added support for consistency check mode.
   
           * khtml/misc/hashset.h:
           (khtml::HashSet::capacity): Added
  @@ -256,19 +285,19 @@
           * khtml/misc/hashtable.h:
           (khtml::HashTableIterator): New class with all the obvious iterator stuff.
           (khtml::HashTableConstIterator::HashTableConstIterator): New class with all the obvious
  -	const iterator stuff.
  +        const iterator stuff.
           (khtml::HashTable::begin): Added (both const and non-consts)
           (khtml::HashTable::end): Added (both const and non-consts)
           (khtml::HashTable::capacity): Added
           (khtml::HashTable::insert): Implement non-template method in terms
  -	of template method.
  +        of template method.
           (khtml::HashTable::contains): Added (implemented in terms of find)
           (khtml::HashTable::remove): Implemented key remove in terms of find and 
  -	iterator remove.
  +        iterator remove.
           (khtml::HashTable::hash): Made static
           (khtml::HashTable::equal): Made static
           (khtml::HashTable::identityConvert): Added - no-op convert method so template insert
  -	method can be implemented in terms of non-template
  +        method can be implemented in terms of non-template
           (khtml::HashTable::insert): Changed to return iterator
           (khtml::HashTable::reinsert): Recoded to be more like the other functions
           (khtml::HashTable::find): Added
  @@ -285,10 +314,10 @@
   
   2005-06-29  Geoffrey Garen  <ggaren at apple.com>
   
  -	-added test case for fix to http://bugzilla.opendarwin.org/show_bug.cgi?id=3743
  -	Incorrect error message given for certain calls
  -	
  -	See JavaScriptCore Changelog for details about the patch.
  +        -added test case for fix to http://bugzilla.opendarwin.org/show_bug.cgi?id=3743
  +        Incorrect error message given for certain calls
  +
  +        See JavaScriptCore Changelog for details about the patch.
   
           Reviewed by me.
   
  @@ -315,10 +344,10 @@
   
   2005-06-29  Geoffrey Garen  <ggaren at apple.com>
   
  -	Patch by Joost de Valk <webkit at joostdevalk.nl>
  +        Patch by Joost de Valk <webkit at joostdevalk.nl>
   
  -	- http://bugzilla.opendarwin.org/show_bug.cgi?id=3732
  -	Testcase for accesskeys that will run with run-webkit-tests.
  +        - http://bugzilla.opendarwin.org/show_bug.cgi?id=3732
  +        Testcase for accesskeys that will run with run-webkit-tests.
   
           Reviewed by Darin.
   
  @@ -346,10 +375,10 @@
   
   2005-06-29  Geoffrey Garen  <ggaren at apple.com>
   
  -	Patch by Antoine Quint <ml at graougraou.com>
  +        Patch by Antoine Quint <ml at graougraou.com>
   
  -	-fixes http://bugzilla.opendarwin.org/show_bug.cgi?id=3648
  -	quadraticCurveTo() method in <canvas> APIs JS bindings does not exist
  +        -fixes http://bugzilla.opendarwin.org/show_bug.cgi?id=3648
  +        quadraticCurveTo() method in <canvas> APIs JS bindings does not exist
   
           Reviewed by Darin.
   
  
  
  
  1.6       +73 -27    WebCore/khtml/xsl/xslt_processorimpl.cpp
  
  Index: xslt_processorimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xsl/xslt_processorimpl.cpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- xslt_processorimpl.cpp	27 May 2005 22:48:07 -0000	1.5
  +++ xslt_processorimpl.cpp	30 Jun 2005 05:57:17 -0000	1.6
  @@ -27,6 +27,9 @@
   #include "loader.h"
   #include "khtmlview.h"
   #include "khtml_part.h"
  +#include "KWQLoader.h"
  +
  +#include <kio/job.h>
   
   #include <libxslt/xsltutils.h>
   #include <libxslt/documents.h>
  @@ -54,19 +57,49 @@
           m_sourceDocument->deref();
   }
   
  -static XSLStyleSheetImpl* globalSheet = 0;
  +static void parseErrorFunc(void *ctxt, const char *msg, ...)
  +{
  +    // FIXME: It would be nice to display error messages somewhere.
  +}
  +
  +static XSLTProcessorImpl *globalProcessor = 0;
   static xmlDocPtr stylesheetLoadFunc(const xmlChar* uri,
                                       xmlDictPtr dict,
                                       int options,
                                       void* ctxt,
                                       xsltLoadType type)
   {
  -    if (type != XSLT_LOAD_STYLESHEET)
  -        return NULL; // FIXME: Add support for XSLT_LOAD_DOCUMENT for the document() function.
  -    
  -    if (!globalSheet)
  +    if (!globalProcessor)
           return NULL;
  -    return globalSheet->locateStylesheetSubResource(((xsltStylesheetPtr)ctxt)->doc, uri);
  +    
  +    switch (type) {
  +        case XSLT_LOAD_DOCUMENT: {
  +            KURL url = KURL((char *)uri);
  +            KURL finalURL;
  +            KIO::TransferJob *job = KIO::get(url, true, false);
  +            QByteArray data;
  +            QString headers;
  +            xmlDocPtr doc;
  +            xmlGenericErrorFunc oldErrorFunc = xmlGenericError;
  +            void *oldErrorContext = xmlGenericErrorContext;
  +            
  +            data = KWQServeSynchronousRequest(khtml::Cache::loader(), 
  +                                              globalProcessor->sourceDocument()->docLoader(), job, finalURL, headers);
  +        
  +            xmlSetGenericErrorFunc(0, parseErrorFunc);
  +            // We don't specify an encoding here. Neither Gecko nor WinIE respects
  +            // the encoding specified in the HTTP headers.
  +            doc = xmlReadMemory(data.data(), data.size(), (const char *)uri, 0, options);
  +            xmlSetGenericErrorFunc(oldErrorContext, oldErrorFunc);
  +            return doc;
  +        }
  +        case XSLT_LOAD_STYLESHEET:
  +            return globalProcessor->stylesheet()->locateStylesheetSubResource(((xsltStylesheetPtr)ctxt)->doc, uri);
  +        default:
  +            break;
  +    }
  +    
  +    return NULL;
   }
   
   DocumentImpl* XSLTProcessorImpl::transformDocument(DocumentImpl* doc)
  @@ -77,20 +110,26 @@
   
       if (!m_stylesheet || !m_stylesheet->document()) return 0;
           
  -    globalSheet = m_stylesheet;
  +    globalProcessor = this;
       xsltSetLoaderFunc(stylesheetLoadFunc);
   
       xsltStylesheetPtr sheet = m_stylesheet->compileStyleSheet();
   
  -    globalSheet = 0;
  -    xsltSetLoaderFunc(0);
  -
  -    if (!sheet) return 0;
  +    if (!sheet) {
  +        globalProcessor = 0;
  +        xsltSetLoaderFunc(0);
  +        return 0;
  +    }
  +    
       m_stylesheet->clearDocuments();
     
       // Get the parsed source document.
       xmlDocPtr sourceDoc = (xmlDocPtr)doc->transformSource();
       xmlDocPtr resultDoc = xsltApplyStylesheet(sheet, sourceDoc, NULL);
  +    
  +    globalProcessor = 0;
  +    xsltSetLoaderFunc(0);
  +
       DocumentImpl* result = documentFromXMLDocPtr(resultDoc, sheet);
       xsltFreeStylesheet(sheet);
       return result;
  @@ -107,12 +146,14 @@
       m_resultOutput += QString(buffer, len);
   }
   
  -DocumentImpl* XSLTProcessorImpl::documentFromXMLDocPtr(xmlDocPtr resultDoc, xsltStylesheetPtr sheet)
  +DocumentImpl *XSLTProcessorImpl::documentFromXMLDocPtr(xmlDocPtr resultDoc, xsltStylesheetPtr sheet)
   {
  -    // FIXME: For now we serialize and then reparse.  It might be more optimal to write a DOM
  -    // converter.
  -    if (!resultDoc || !sheet) return 0;
  -    DocumentImpl* result = 0;
  +    // FIXME: For now we serialize and then reparse. It might be more optimal to write a DOM  converter.
  +
  +    if (!resultDoc || !sheet)
  +        return 0;
  +
  +    DocumentImpl *result = 0;
       xmlOutputBufferPtr outputBuf = xmlAllocOutputBuffer(NULL);
       if (outputBuf) {
           outputBuf->context = this;
  @@ -124,12 +165,12 @@
           // There are three types of output we need to be able to deal with:
           // HTML (create an HTML document), XML (create an XML document), and text (wrap in a <pre> and
           // make an XML document).
  -        KHTMLView* view = m_sourceDocument->view();
  -        const xmlChar* method;
  +        KHTMLView *view = m_sourceDocument->view();
  +        const xmlChar *method;
           XSLT_GET_IMPORT_PTR(method, sheet, method);
           if (method == NULL && resultDoc->type == XML_HTML_DOCUMENT_NODE)
  -            method = (const xmlChar*)"html";
  -        if (xmlStrEqual(method, (const xmlChar*)"html"))
  +            method = (const xmlChar *)"html";
  +        if (xmlStrEqual(method, (const xmlChar *)"html"))
               result = m_sourceDocument->implementation()->createHTMLDocument(view);
           else
               result = m_sourceDocument->implementation()->createDocument(view);
  @@ -140,16 +181,20 @@
           result->docLoader()->setShowAnimations(m_sourceDocument->docLoader()->showAnimations());
           result->setTransformSourceDocument(m_sourceDocument);
   
  -        if (xmlStrEqual(method, (const xmlChar*)"text")) {
  -            // Modify the output so that it is a well-formed XHTML document with a <pre> tag enclosing
  -            // the text.
  -            QString beforeString("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<body>\n<pre>\n<![CDATA[");
  -            QString afterString("]]>\n</pre>\n</body>\n</html>\n");
  -            m_resultOutput = beforeString + m_resultOutput + afterString;
  +        if (xmlStrEqual(method, (const xmlChar *)"text")) {
  +            // Modify the output so that it is a well-formed XHTML document with a <pre> tag enclosing the text.
  +            m_resultOutput = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/strict.dtd\">\n"
  +                "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
  +                "<body>\n"
  +                "<pre>\n"
  +                "<![CDATA[" + m_resultOutput + "]]>\n"
  +                "</pre>\n"
  +                "</body>\n"
  +                "</html>\n";
           }
           
           // Before parsing, we need to detach the old document completely and get the new document
  -        // in place.  We have to do this only if we're rendering the result document.
  +        // in place. We have to do this only if we're rendering the result document.
           if (view) {
               view->clear();
               view->part()->replaceDocImpl(result);
  @@ -170,4 +215,5 @@
   }
   
   }
  +
   #endif
  
  
  
  1.3       +3 -0      WebCore/khtml/xsl/xslt_processorimpl.h
  
  Index: xslt_processorimpl.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xsl/xslt_processorimpl.h,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- xslt_processorimpl.h	19 Aug 2004 22:50:30 -0000	1.2
  +++ xslt_processorimpl.h	30 Jun 2005 05:57:17 -0000	1.3
  @@ -53,6 +53,9 @@
       // Helpers
       void addToResult(const char* buffer, int len);
       
  +    XSLStyleSheetImpl *stylesheet() { return m_stylesheet; }
  +    DocumentImpl *sourceDocument() { return m_sourceDocument; }
  +    
   protected:
       XSLStyleSheetImpl* m_stylesheet;
       QString m_resultOutput;
  
  
  
  1.1                  WebCore/layout-tests/fast/xsl/document-function-expected.txt
  
  Index: document-function-expected.txt
  ===================================================================
  layer at (0,0) size 800x600
    RenderCanvas at (0,0) size 800x600
  layer at (0,0) size 800x152
    RenderBlock {HTML} at (0,0) size 800x152
      RenderBody {BODY} at (8,16) size 784x120
        RenderBlock {P} at (0,0) size 784x18
          RenderText {TEXT} at (0,0) size 650x18
            text run at (0,0) width 650: "This tests the xslt document() function. If this test is successful, there should be three paragraphs below."
        RenderBlock {P} at (0,34) size 784x18
          RenderText {TEXT} at (0,0) size 120x18
            text run at (0,0) width 120: "This is a paragraph"
        RenderBlock {P} at (0,68) size 784x18
          RenderText {TEXT} at (0,0) size 160x18
            text run at (0,0) width 160: "This is another paragraph"
        RenderBlock {P} at (0,102) size 784x18
          RenderText {TEXT} at (0,0) size 157x18
            text run at (0,0) width 157: "This is a third paragraph."
  
  
  
  1.1                  WebCore/layout-tests/fast/xsl/document-function.xml
  
  Index: document-function.xml
  ===================================================================
  <?xml version="1.0"?>
  <?xml-stylesheet type="text/xsl" href="document-function.xsl"?>
  <doc>
  <para>This tests the xslt document() function. If this test is successful, there should be three paragraphs below.</para>
  <para>This is a paragraph</para>
  <para>This is another paragraph</para>
  </doc>
  
  
  
  1.1                  WebCore/layout-tests/fast/xsl/document-function.xsl
  
  Index: document-function.xsl
  ===================================================================
  <?xml version="1.0"?>
  <xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <xsl:template match="/">
    <html>
      <xsl:apply-templates/>
  	<xsl:apply-templates select="document('resources/document-function-source.xml')/doc"/>
    </html>
  </xsl:template>
  
  <xsl:template match="para">
  <p><xsl:value-of select="."/></p>
  </xsl:template>
  </xsl:stylesheet>
  
  
  



More information about the webkit-changes mailing list