阅读:4342回复:0
Madfox 补丁解析--xml dataisland的部分支持
对xml dataisland的部分支持主要分两步。
第一步需要让解释器可以认识xml标记。前半部分代码都是做这个。 第二步是实现xml数据岛的具体功能,我是通过xbl实现的,就是将一个实现绑定到xml标记上。我只实现了一个函数,selectSingleNode,因为pconline的下载页面也只用到了这一个。 这部分代码只对xml数据岛有作用。不影响其他任何标记。 Index: htmlparser/src/nsElementTable.cpp =================================================================== --- htmlparser/src/nsElementTable.cpp (revision 9) +++ htmlparser/src/nsElementTable.cpp (revision 10) @@ -817,6 +817,15 @@ /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); Initialize( + /*tag*/ eHTMLTag_xmldataisland, + /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, + /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, + /*autoclose starttags and endtags*/ 0,0,0,0, + /*parent,incl,exclgroups*/ kBlock, kFlowEntity, kNone, + /*special props, prop-range*/ 0, kDefaultPropRange, + /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); + + Initialize( /*tag*/ eHTMLTag_menu, /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, Index: htmlparser/src/nsHTMLTags.cpp =================================================================== --- htmlparser/src/nsHTMLTags.cpp (revision 9) +++ htmlparser/src/nsHTMLTags.cpp (revision 10) @@ -174,6 +174,8 @@ {'m', 'a', 'p', '\0'}; static const PRUnichar sHTMLTagUnicodeName_marquee[] = {'m', 'a', 'r', 'q', 'u', 'e', 'e', '\0'}; +static const PRUnichar sHTMLTagUnicodeName_xmldataisland[] = + {'x', 'm', 'l', '\0'}; static const PRUnichar sHTMLTagUnicodeName_menu[] = {'m', 'e', 'n', 'u', '\0'}; static const PRUnichar sHTMLTagUnicodeName_meta[] = Index: htmlparser/public/nsHTMLTagList.h =================================================================== --- htmlparser/public/nsHTMLTagList.h (revision 9) +++ htmlparser/public/nsHTMLTagList.h (revision 10) @@ -128,6 +128,7 @@ HTML_TAG(listing, Span) HTML_TAG(map, Map) HTML_TAG(marquee, Div) +HTML_TAG(xmldataisland, Div) HTML_TAG(menu, Menu) HTML_TAG(meta, Meta) HTML_TAG(multicol, Span) Index: browser/installer/unix/browser.jst =================================================================== --- browser/installer/unix/browser.jst (revision 9) +++ browser/installer/unix/browser.jst (revision 10) @@ -100,6 +100,7 @@ registerChrome(CONTENT | DELAYED_CHROME, getFolder("Chrome","comm.jar"),"content/cookie/"); registerChrome(CONTENT | DELAYED_CHROME, getFolder("Chrome","comm.jar"),"content/wallet/"); registerChrome(CONTENT | DELAYED_CHROME, getFolder("Chrome","comm.jar"),"content/xbl-marquee/"); + registerChrome(CONTENT | DELAYED_CHROME, getFolder("Chrome","comm.jar"),"content/xbl-xmldataisland/"); registerChrome(CONTENT | DELAYED_CHROME, getFolder("Chrome","toolkit.jar"),"content/global/"); registerChrome(CONTENT | DELAYED_CHROME, getFolder("Chrome","toolkit.jar"),"content/global-region/"); Index: browser/installer/windows/browser.jst =================================================================== --- browser/installer/windows/browser.jst (revision 9) +++ browser/installer/windows/browser.jst (revision 10) @@ -529,6 +529,7 @@ registerChrome(CONTENT | DELAYED_CHROME, getFolder("Chrome","comm.jar"),"content/cookie/"); registerChrome(CONTENT | DELAYED_CHROME, getFolder("Chrome","comm.jar"),"content/wallet/"); registerChrome(CONTENT | DELAYED_CHROME, getFolder("Chrome","comm.jar"),"content/xbl-marquee/"); + registerChrome(CONTENT | DELAYED_CHROME, getFolder("Chrome","comm.jar"),"content/xbl-xmldataisland/"); registerChrome(CONTENT | DELAYED_CHROME, getFolder("Chrome","toolkit.jar"),"content/global/"); registerChrome(CONTENT | DELAYED_CHROME, getFolder("Chrome","toolkit.jar"),"content/global-region/"); Index: layout/html/document/src/quirk.css =================================================================== --- layout/html/document/src/quirk.css (revision 9) +++ layout/html/document/src/quirk.css (revision 10) @@ -292,3 +292,12 @@ input:not([type=image]), textarea { -moz-box-sizing: border-box; } + +/* + * support xml data island in quirk mode + */ +xmldataisland { + display: none; + -moz-binding: url('chrome://xbl-xmldataisland/content/xbl-xmldataisland.xml#xmldataisland'); +} + Index: layout/html/document/src/xbl-xmldataisland/resources/content/xbl-xmldataisland.xml =================================================================== --- layout/html/document/src/xbl-xmldataisland/resources/content/xbl-xmldataisland.xml (revision 0) +++ layout/html/document/src/xbl-xmldataisland/resources/content/xbl-xmldataisland.xml (revision 10) @@ -0,0 +1,74 @@ +<?xml version="1.0"?> +<!-- ***** BEGIN LICENSE BLOCK ***** + - Version: MPL 1.1/GPL 2.0/LGPL 2.1 + - + - The contents of this file are subject to the Mozilla Public License Version + - 1.1 (the "License"); you may not use this file except in compliance with + - the License. You may obtain a copy of the License at + - http://www.mozilla.org/MPL/ + - + - Software distributed under the License is distributed on an "AS IS" basis, + - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + - for the specific language governing rights and limitations under the + - License. + - + - The Original Code is from iamawalrus@gmail.com + - + - The Initial Developer of the Original Code is + - iamawalrus@gmail.com + - Portions created by the Initial Developer are Copyright (C) 2002 + - the Initial Developer. All Rights Reserved. + - + - Contributor(s): + - iamawalrus@gmail.com + - + - Alternatively, the contents of this file may be used under the terms of + - either the GNU General Public License Version 2 or later (the "GPL"), or + - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + - in which case the provisions of the GPL or the LGPL are applicable instead + - of those above. If you wish to allow use of your version of this file only + - under the terms of either the GPL or the LGPL, and not to allow others to + - use your version of this file under the terms of the MPL, indicate your + - decision by deleting the provisions above and replace them with the notice + - and other provisions required by the LGPL or the GPL. If you do not delete + - the provisions above, a recipient may use your version of this file under + - the terms of any one of the MPL, the GPL or the LGPL. + - + - ***** END LICENSE BLOCK ***** --> + +<bindings id="xmldataislandBindings" + xmlns="http://www.mozilla.org/xbl" + xmlns:html="http://www.w3.org/1999/xhtml" + xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + xmlns:xbl="http://www.mozilla.org/xbl"> + + + <binding id="xmldataisland" inheritstyle="false"> + <content> + </content> + <implementation> + <field name="innerDoc"/> + <method name="selectSingleNode"> + <parameter name="aPath"/> + <body> + function DumyNode(node){ + this.text=node.textContent; + } + var result = this.innerDoc.evaluate(aPath.toLowerCase(), + this.innerDoc, null, 9, null).singleNodeValue; + var rtv = new DumyNode(result); + return rtv; + </body> + </method> + + <constructor> + <![CDATA[ + var str = this.innerHTML; + var parser = new DOMParser; + this.innerDoc = parser.parseFromString(str, "text/xml"); + ]]> + </constructor> + </implementation> + </binding> + +</bindings> |
|