OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. |
4 * Copyright (C) 2011 Igalia S.L. | 4 * Copyright (C) 2011 Igalia S.L. |
5 * Copyright (C) 2011 Motorola Mobility. All rights reserved. | 5 * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
6 * | 6 * |
7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
9 * are met: | 9 * are met: |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 { | 86 { |
87 m_element->setAttribute(m_name, m_value); | 87 m_element->setAttribute(m_name, m_value); |
88 } | 88 } |
89 | 89 |
90 private: | 90 private: |
91 RefPtr<Element> m_element; | 91 RefPtr<Element> m_element; |
92 QualifiedName m_name; | 92 QualifiedName m_name; |
93 String m_value; | 93 String m_value; |
94 }; | 94 }; |
95 | 95 |
96 static void completeURLs(DocumentFragment* fragment, const String& baseURL) | 96 static void completeURLs(DocumentFragment& fragment, const String& baseURL) |
97 { | 97 { |
98 Vector<AttributeChange> changes; | 98 Vector<AttributeChange> changes; |
99 | 99 |
100 KURL parsedBaseURL(ParsedURLString, baseURL); | 100 KURL parsedBaseURL(ParsedURLString, baseURL); |
101 | 101 |
102 for (Element* element = ElementTraversal::firstWithin(fragment); element; el
ement = ElementTraversal::next(*element, fragment)) { | 102 for (Element* element = ElementTraversal::firstWithin(fragment); element; el
ement = ElementTraversal::next(*element, &fragment)) { |
103 if (!element->hasAttributes()) | 103 if (!element->hasAttributes()) |
104 continue; | 104 continue; |
105 unsigned length = element->attributeCount(); | 105 unsigned length = element->attributeCount(); |
106 for (unsigned i = 0; i < length; i++) { | 106 for (unsigned i = 0; i < length; i++) { |
107 const Attribute* attribute = element->attributeItem(i); | 107 const Attribute* attribute = element->attributeItem(i); |
108 if (element->isURLAttribute(*attribute) && !attribute->value().isEmp
ty()) | 108 if (element->isURLAttribute(*attribute) && !attribute->value().isEmp
ty()) |
109 changes.append(AttributeChange(element, attribute->name(), KURL(
parsedBaseURL, attribute->value()).string())); | 109 changes.append(AttributeChange(element, attribute->name(), KURL(
parsedBaseURL, attribute->value()).string())); |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 | 641 |
642 PassRefPtr<DocumentFragment> createFragmentFromMarkup(Document& document, const
String& markup, const String& baseURL, ParserContentPolicy parserContentPolicy) | 642 PassRefPtr<DocumentFragment> createFragmentFromMarkup(Document& document, const
String& markup, const String& baseURL, ParserContentPolicy parserContentPolicy) |
643 { | 643 { |
644 // We use a fake body element here to trick the HTML parser to using the InB
ody insertion mode. | 644 // We use a fake body element here to trick the HTML parser to using the InB
ody insertion mode. |
645 RefPtr<HTMLBodyElement> fakeBody = HTMLBodyElement::create(document); | 645 RefPtr<HTMLBodyElement> fakeBody = HTMLBodyElement::create(document); |
646 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document); | 646 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document); |
647 | 647 |
648 fragment->parseHTML(markup, fakeBody.get(), parserContentPolicy); | 648 fragment->parseHTML(markup, fakeBody.get(), parserContentPolicy); |
649 | 649 |
650 if (!baseURL.isEmpty() && baseURL != blankURL() && baseURL != document.baseU
RL()) | 650 if (!baseURL.isEmpty() && baseURL != blankURL() && baseURL != document.baseU
RL()) |
651 completeURLs(fragment.get(), baseURL); | 651 completeURLs(*fragment, baseURL); |
652 | 652 |
653 return fragment.release(); | 653 return fragment.release(); |
654 } | 654 } |
655 | 655 |
656 static const char fragmentMarkerTag[] = "webkit-fragment-marker"; | 656 static const char fragmentMarkerTag[] = "webkit-fragment-marker"; |
657 | 657 |
658 static bool findNodesSurroundingContext(Document* document, RefPtr<Node>& nodeBe
foreContext, RefPtr<Node>& nodeAfterContext) | 658 static bool findNodesSurroundingContext(Document* document, RefPtr<Node>& nodeBe
foreContext, RefPtr<Node>& nodeAfterContext) |
659 { | 659 { |
660 for (Node* node = document->firstChild(); node; node = NodeTraversal::next(*
node)) { | 660 for (Node* node = document->firstChild(); node; node = NodeTraversal::next(*
node)) { |
661 if (node->nodeType() == Node::COMMENT_NODE && toCharacterData(node)->dat
a() == fragmentMarkerTag) { | 661 if (node->nodeType() == Node::COMMENT_NODE && toCharacterData(node)->dat
a() == fragmentMarkerTag) { |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 return; | 1083 return; |
1084 | 1084 |
1085 RefPtr<Text> textNode = toText(node.get()); | 1085 RefPtr<Text> textNode = toText(node.get()); |
1086 RefPtr<Text> textNext = toText(next); | 1086 RefPtr<Text> textNext = toText(next); |
1087 textNode->appendData(textNext->data()); | 1087 textNode->appendData(textNext->data()); |
1088 if (textNext->parentNode()) // Might have been removed by mutation event. | 1088 if (textNext->parentNode()) // Might have been removed by mutation event. |
1089 textNext->remove(es); | 1089 textNext->remove(es); |
1090 } | 1090 } |
1091 | 1091 |
1092 } | 1092 } |
OLD | NEW |