| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package com.dom_distiller.client; | 5 package com.dom_distiller.client; |
| 6 | 6 |
| 7 import com.google.gwt.core.client.JsArray; | 7 import com.google.gwt.core.client.JsArray; |
| 8 import com.google.gwt.dom.client.Element; | 8 import com.google.gwt.dom.client.Element; |
| 9 import com.google.gwt.dom.client.Node; | 9 import com.google.gwt.dom.client.Node; |
| 10 import com.google.gwt.dom.client.Text; | 10 import com.google.gwt.dom.client.Text; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 @Override | 39 @Override |
| 40 public boolean visit(Node n) { | 40 public boolean visit(Node n) { |
| 41 switch (n.getNodeType()) { | 41 switch (n.getNodeType()) { |
| 42 case Node.TEXT_NODE: | 42 case Node.TEXT_NODE: |
| 43 textNodes.add(n); | 43 textNodes.add(n); |
| 44 String text = Text.as(n).getData(); | 44 String text = Text.as(n).getData(); |
| 45 handler.characters(text.toCharArray(), 0, text.length()); | 45 handler.characters(text.toCharArray(), 0, text.length()); |
| 46 return false; | 46 return false; |
| 47 case Node.ELEMENT_NODE: | 47 case Node.ELEMENT_NODE: |
| 48 Element e = Element.as(n); | 48 Element e = Element.as(n); |
| 49 Attributes attrs = getSaxAttributes(e); | 49 Attributes attrs = getAttributes(e); |
| 50 handler.startElement(sHtmlNamespace, e.getTagName(), e.getTagNam
e(), attrs); | 50 handler.startElement(e, attrs); |
| 51 return true; | 51 return true; |
| 52 case Node.DOCUMENT_NODE: // Don't recurse into sub-documents. | 52 case Node.DOCUMENT_NODE: // Don't recurse into sub-documents. |
| 53 default: // This case is for comment nodes. | 53 default: // This case is for comment nodes. |
| 54 return false; | 54 return false; |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 @Override | 58 @Override |
| 59 public void exit(Node n) { | 59 public void exit(Node n) { |
| 60 Element e = Element.as(n); | 60 Element e = Element.as(n); |
| 61 handler.endElement(sHtmlNamespace, e.getTagName(), e.getTagName()); | 61 handler.endElement(e); |
| 62 } | 62 } |
| 63 | 63 |
| 64 /** | 64 /** |
| 65 * @Return The element's attribute list converted to {@link Attributes}. | 65 * @Return The element's attribute list converted to {@link Attributes}. |
| 66 */ | 66 */ |
| 67 public static Attributes getSaxAttributes(Element e) { | 67 public static Attributes getAttributes(Element e) { |
| 68 AttributesImpl attrs = new AttributesImpl(); | 68 AttributesImpl attrs = new AttributesImpl(); |
| 69 | 69 |
| 70 JsArray<Node> jsAttrs = DomUtil.getAttributes(e); | 70 JsArray<Node> jsAttrs = DomUtil.getAttributes(e); |
| 71 for (int i = 0; i < jsAttrs.length(); ++i) { | 71 for (int i = 0; i < jsAttrs.length(); ++i) { |
| 72 final Node jsAttr = jsAttrs.get(i); | 72 final Node jsAttr = jsAttrs.get(i); |
| 73 attrs.addAttribute("", jsAttr.getNodeName(), jsAttr.getNodeName(), "
CDATA", | 73 attrs.addAttribute(jsAttr.getNodeName(), jsAttr.getNodeValue()); |
| 74 jsAttr.getNodeValue()); | |
| 75 } | 74 } |
| 76 | 75 |
| 77 return attrs; | 76 return attrs; |
| 78 } | 77 } |
| 79 } | 78 } |
| OLD | NEW |