| 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 fragment->parseHTML(markup, fakeBody.get(), parserContentPolicy); | 280 fragment->parseHTML(markup, fakeBody.get(), parserContentPolicy); |
| 281 | 281 |
| 282 if (!baseURL.isEmpty() && baseURL != blankURL() && baseURL != document.baseU
RL()) | 282 if (!baseURL.isEmpty() && baseURL != blankURL() && baseURL != document.baseU
RL()) |
| 283 completeURLs(*fragment, baseURL); | 283 completeURLs(*fragment, baseURL); |
| 284 | 284 |
| 285 return fragment.release(); | 285 return fragment.release(); |
| 286 } | 286 } |
| 287 | 287 |
| 288 static const char fragmentMarkerTag[] = "webkit-fragment-marker"; | 288 static const char fragmentMarkerTag[] = "webkit-fragment-marker"; |
| 289 | 289 |
| 290 static bool findNodesSurroundingContext(Document* document, RefPtrWillBeRawPtr<C
omment>& nodeBeforeContext, RefPtrWillBeRawPtr<Comment>& nodeAfterContext) | 290 static bool findNodesSurroundingContext(DocumentFragment* fragment, RefPtrWillBe
RawPtr<Comment>& nodeBeforeContext, RefPtrWillBeRawPtr<Comment>& nodeAfterContex
t) |
| 291 { | 291 { |
| 292 for (Node& node : NodeTraversal::startsAt(document->firstChild())) { | 292 for (Node& node : NodeTraversal::startsAt(fragment->firstChild())) { |
| 293 if (node.nodeType() == Node::COMMENT_NODE && toComment(node).data() == f
ragmentMarkerTag) { | 293 if (node.nodeType() == Node::COMMENT_NODE && toComment(node).data() == f
ragmentMarkerTag) { |
| 294 if (!nodeBeforeContext) | 294 if (!nodeBeforeContext) |
| 295 nodeBeforeContext = &toComment(node); | 295 nodeBeforeContext = &toComment(node); |
| 296 else { | 296 else { |
| 297 nodeAfterContext = &toComment(node); | 297 nodeAfterContext = &toComment(node); |
| 298 return true; | 298 return true; |
| 299 } | 299 } |
| 300 } | 300 } |
| 301 } | 301 } |
| 302 return false; | 302 return false; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 330 // FIXME: Need to handle the case where the markup already contains these ma
rkers. | 330 // FIXME: Need to handle the case where the markup already contains these ma
rkers. |
| 331 | 331 |
| 332 StringBuilder taggedMarkup; | 332 StringBuilder taggedMarkup; |
| 333 taggedMarkup.append(markup.left(fragmentStart)); | 333 taggedMarkup.append(markup.left(fragmentStart)); |
| 334 MarkupAccumulator::appendComment(taggedMarkup, fragmentMarkerTag); | 334 MarkupAccumulator::appendComment(taggedMarkup, fragmentMarkerTag); |
| 335 taggedMarkup.append(markup.substring(fragmentStart, fragmentEnd - fragmentSt
art)); | 335 taggedMarkup.append(markup.substring(fragmentStart, fragmentEnd - fragmentSt
art)); |
| 336 MarkupAccumulator::appendComment(taggedMarkup, fragmentMarkerTag); | 336 MarkupAccumulator::appendComment(taggedMarkup, fragmentMarkerTag); |
| 337 taggedMarkup.append(markup.substring(fragmentEnd)); | 337 taggedMarkup.append(markup.substring(fragmentEnd)); |
| 338 | 338 |
| 339 RefPtrWillBeRawPtr<DocumentFragment> taggedFragment = createFragmentFromMark
up(document, taggedMarkup.toString(), baseURL, parserContentPolicy); | 339 RefPtrWillBeRawPtr<DocumentFragment> taggedFragment = createFragmentFromMark
up(document, taggedMarkup.toString(), baseURL, parserContentPolicy); |
| 340 |
| 341 RefPtrWillBeRawPtr<Comment> nodeBeforeContext = nullptr; |
| 342 RefPtrWillBeRawPtr<Comment> nodeAfterContext = nullptr; |
| 343 if (!findNodesSurroundingContext(taggedFragment.get(), nodeBeforeContext, no
deAfterContext)) |
| 344 return nullptr; |
| 345 |
| 340 RefPtrWillBeRawPtr<Document> taggedDocument = Document::create(); | 346 RefPtrWillBeRawPtr<Document> taggedDocument = Document::create(); |
| 341 taggedDocument->setContextFeatures(document.contextFeatures()); | 347 taggedDocument->setContextFeatures(document.contextFeatures()); |
| 342 | 348 |
| 343 // FIXME: It's not clear what this code is trying to do. It puts nodes as di
rect children of a | 349 RefPtrWillBeRawPtr<Element> root = Element::create(QualifiedName::null(), ta
ggedDocument.get()); |
| 344 // Document that are not normally allowed by using the parser machinery. | 350 root->appendChild(taggedFragment.get()); |
| 345 taggedDocument->parserTakeAllChildrenFrom(*taggedFragment); | 351 taggedDocument->appendChild(root); |
| 346 | |
| 347 RefPtrWillBeRawPtr<Comment> nodeBeforeContext = nullptr; | |
| 348 RefPtrWillBeRawPtr<Comment> nodeAfterContext = nullptr; | |
| 349 if (!findNodesSurroundingContext(taggedDocument.get(), nodeBeforeContext, no
deAfterContext)) | |
| 350 return nullptr; | |
| 351 | 352 |
| 352 RefPtrWillBeRawPtr<Range> range = Range::create(*taggedDocument.get(), | 353 RefPtrWillBeRawPtr<Range> range = Range::create(*taggedDocument.get(), |
| 353 positionAfterNode(nodeBeforeContext.get()).parentAnchoredEquivalent(), | 354 positionAfterNode(nodeBeforeContext.get()).parentAnchoredEquivalent(), |
| 354 positionBeforeNode(nodeAfterContext.get()).parentAnchoredEquivalent()); | 355 positionBeforeNode(nodeAfterContext.get()).parentAnchoredEquivalent()); |
| 355 | 356 |
| 356 Node* commonAncestor = range->commonAncestorContainer(); | 357 Node* commonAncestor = range->commonAncestorContainer(); |
| 357 HTMLElement* specialCommonAncestor = ancestorToRetainStructureAndAppearanceW
ithNoLayoutObject(commonAncestor); | 358 HTMLElement* specialCommonAncestor = ancestorToRetainStructureAndAppearanceW
ithNoLayoutObject(commonAncestor); |
| 358 | 359 |
| 359 // When there's a special common ancestor outside of the fragment, we must i
nclude it as well to | 360 // When there's a special common ancestor outside of the fragment, we must i
nclude it as well to |
| 360 // preserve the structure and appearance of the fragment. For example, if th
e fragment contains | 361 // preserve the structure and appearance of the fragment. For example, if th
e fragment contains |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 | 696 |
| 696 RefPtrWillBeRawPtr<Text> textNext = toText(next); | 697 RefPtrWillBeRawPtr<Text> textNext = toText(next); |
| 697 textNode->appendData(textNext->data()); | 698 textNode->appendData(textNext->data()); |
| 698 if (textNext->parentNode()) // Might have been removed by mutation event. | 699 if (textNext->parentNode()) // Might have been removed by mutation event. |
| 699 textNext->remove(exceptionState); | 700 textNext->remove(exceptionState); |
| 700 } | 701 } |
| 701 | 702 |
| 702 template class CORE_TEMPLATE_EXPORT CreateMarkupAlgorithm<EditingStrategy>; | 703 template class CORE_TEMPLATE_EXPORT CreateMarkupAlgorithm<EditingStrategy>; |
| 703 | 704 |
| 704 } | 705 } |
| OLD | NEW |