| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 177 |
| 178 const HTMLElement& element = toHTMLElement(*node); | 178 const HTMLElement& element = toHTMLElement(*node); |
| 179 return element.hasTagName(uTag) || element.hasTagName(sTag) || element.hasTa
gName(strikeTag) | 179 return element.hasTagName(uTag) || element.hasTagName(sTag) || element.hasTa
gName(strikeTag) |
| 180 || element.hasTagName(iTag) || element.hasTagName(emTag) || element.hasT
agName(bTag) || element.hasTagName(strongTag); | 180 || element.hasTagName(iTag) || element.hasTagName(emTag) || element.hasT
agName(bTag) || element.hasTagName(strongTag); |
| 181 } | 181 } |
| 182 | 182 |
| 183 template<typename PositionType> | 183 template<typename PositionType> |
| 184 static bool areSameRanges(Node* node, const PositionType& startPosition, const P
ositionType& endPosition) | 184 static bool areSameRanges(Node* node, const PositionType& startPosition, const P
ositionType& endPosition) |
| 185 { | 185 { |
| 186 ASSERT(node); | 186 ASSERT(node); |
| 187 Position otherStartPosition; | 187 |
| 188 Position otherEndPosition; | 188 PositionType otherStartPosition; |
| 189 VisibleSelection::selectionFromContentsOfNode(node).toNormalizedPositions(ot
herStartPosition, otherEndPosition); | 189 PositionType otherEndPosition; |
| 190 VisibleSelection::normalizePositions(PositionType::firstPositionInNode(node)
, PositionType::lastPositionInNode(node), &otherStartPosition, &otherEndPosition
); |
| 190 return startPosition == otherStartPosition && endPosition == otherEndPositio
n; | 191 return startPosition == otherStartPosition && endPosition == otherEndPositio
n; |
| 191 } | 192 } |
| 192 | 193 |
| 193 template<typename Strategy> | 194 template<typename Strategy> |
| 194 static HTMLElement* highestAncestorToWrapMarkup(const typename Strategy::Positio
nType& startPosition, const typename Strategy::PositionType& endPosition, EAnnot
ateForInterchange shouldAnnotate, Node* constrainingAncestor) | 195 static HTMLElement* highestAncestorToWrapMarkup(const typename Strategy::Positio
nType& startPosition, const typename Strategy::PositionType& endPosition, EAnnot
ateForInterchange shouldAnnotate, Node* constrainingAncestor) |
| 195 { | 196 { |
| 196 Node* firstNode = startPosition.nodeAsRangeFirstNode(); | 197 Node* firstNode = startPosition.nodeAsRangeFirstNode(); |
| 197 // For compatibility reason, we use container node of start and end | 198 // For compatibility reason, we use container node of start and end |
| 198 // positions rather than first node and last node in selection. | 199 // positions rather than first node and last node in selection. |
| 199 Node* commonAncestor = Strategy::commonAncestor(*startPosition.containerNode
(), *endPosition.containerNode()); | 200 Node* commonAncestor = Strategy::commonAncestor(*startPosition.containerNode
(), *endPosition.containerNode()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 specialCommonAncestor = toHTMLSpanElement(Strategy::parent(*commonAncest
or)); | 233 specialCommonAncestor = toHTMLSpanElement(Strategy::parent(*commonAncest
or)); |
| 233 if (!specialCommonAncestor && isTabHTMLSpanElement(commonAncestor)) | 234 if (!specialCommonAncestor && isTabHTMLSpanElement(commonAncestor)) |
| 234 specialCommonAncestor = toHTMLSpanElement(commonAncestor); | 235 specialCommonAncestor = toHTMLSpanElement(commonAncestor); |
| 235 | 236 |
| 236 if (HTMLAnchorElement* enclosingAnchor = toHTMLAnchorElement(enclosingElemen
tWithTag(firstPositionInNode(specialCommonAncestor ? specialCommonAncestor : com
monAncestor), aTag))) | 237 if (HTMLAnchorElement* enclosingAnchor = toHTMLAnchorElement(enclosingElemen
tWithTag(firstPositionInNode(specialCommonAncestor ? specialCommonAncestor : com
monAncestor), aTag))) |
| 237 specialCommonAncestor = enclosingAnchor; | 238 specialCommonAncestor = enclosingAnchor; |
| 238 | 239 |
| 239 return specialCommonAncestor; | 240 return specialCommonAncestor; |
| 240 } | 241 } |
| 241 | 242 |
| 243 template <typename Strategy> |
| 244 class CreateMarkupAlgorithm { |
| 245 public: |
| 246 using PositionType = typename Strategy::PositionType; |
| 247 |
| 248 static String createMarkup(const PositionType& startPosition, const Position
Type& endPosition, EAnnotateForInterchange shouldAnnotate = DoNotAnnotateForInte
rchange, ConvertBlocksToInlines = ConvertBlocksToInlines::NotConvert, EAbsoluteU
RLs shouldResolveURLs = DoNotResolveURLs, Node* constrainingAncestor = nullptr); |
| 249 }; |
| 250 |
| 242 // FIXME: Shouldn't we omit style info when annotate == DoNotAnnotateForIntercha
nge? | 251 // FIXME: Shouldn't we omit style info when annotate == DoNotAnnotateForIntercha
nge? |
| 243 // FIXME: At least, annotation and style info should probably not be included in
range.markupString() | 252 // FIXME: At least, annotation and style info should probably not be included in
range.markupString() |
| 244 template <typename Strategy> | 253 template <typename Strategy> |
| 245 String CreateMarkupAlgorithm<Strategy>::createMarkup(const PositionType& startPo
sition, const PositionType& endPosition, | 254 String CreateMarkupAlgorithm<Strategy>::createMarkup(const PositionType& startPo
sition, const PositionType& endPosition, |
| 246 EAnnotateForInterchange shouldAnnotate, ConvertBlocksToInlines convertBlocks
ToInlines, EAbsoluteURLs shouldResolveURLs, Node* constrainingAncestor) | 255 EAnnotateForInterchange shouldAnnotate, ConvertBlocksToInlines convertBlocks
ToInlines, EAbsoluteURLs shouldResolveURLs, Node* constrainingAncestor) |
| 247 { | 256 { |
| 248 ASSERT(startPosition.isNotNull()); | 257 ASSERT(startPosition.isNotNull()); |
| 249 ASSERT(endPosition.isNotNull()); | 258 ASSERT(endPosition.isNotNull()); |
| 250 ASSERT(startPosition.compareTo(endPosition) <= 0); | 259 ASSERT(startPosition.compareTo(endPosition) <= 0); |
| 251 | 260 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 265 } | 274 } |
| 266 | 275 |
| 267 String createMarkup(const Range* range, EAnnotateForInterchange shouldAnnotate,
ConvertBlocksToInlines convertBlocksToInlines, EAbsoluteURLs shouldResolveURLs,
Node* constrainingAncestor) | 276 String createMarkup(const Range* range, EAnnotateForInterchange shouldAnnotate,
ConvertBlocksToInlines convertBlocksToInlines, EAbsoluteURLs shouldResolveURLs,
Node* constrainingAncestor) |
| 268 { | 277 { |
| 269 if (!range) | 278 if (!range) |
| 270 return emptyString(); | 279 return emptyString(); |
| 271 | 280 |
| 272 return CreateMarkupAlgorithm<EditingStrategy>::createMarkup(range->startPosi
tion(), range->endPosition(), shouldAnnotate, convertBlocksToInlines, shouldReso
lveURLs, constrainingAncestor); | 281 return CreateMarkupAlgorithm<EditingStrategy>::createMarkup(range->startPosi
tion(), range->endPosition(), shouldAnnotate, convertBlocksToInlines, shouldReso
lveURLs, constrainingAncestor); |
| 273 } | 282 } |
| 274 | 283 |
| 284 String createMarkup(const Position& startPosition, const Position& endPosition,
EAnnotateForInterchange shouldAnnotate, ConvertBlocksToInlines convertBlocksToIn
lines, EAbsoluteURLs shouldResolveURLs, Node* constrainingAncestor) |
| 285 { |
| 286 ASSERT(startPosition.compareTo(endPosition) <= 0); |
| 287 return CreateMarkupAlgorithm<EditingStrategy>::createMarkup(startPosition, e
ndPosition, shouldAnnotate, convertBlocksToInlines, shouldResolveURLs, constrain
ingAncestor); |
| 288 } |
| 289 |
| 275 PassRefPtrWillBeRawPtr<DocumentFragment> createFragmentFromMarkup(Document& docu
ment, const String& markup, const String& baseURL, ParserContentPolicy parserCon
tentPolicy) | 290 PassRefPtrWillBeRawPtr<DocumentFragment> createFragmentFromMarkup(Document& docu
ment, const String& markup, const String& baseURL, ParserContentPolicy parserCon
tentPolicy) |
| 276 { | 291 { |
| 277 // We use a fake body element here to trick the HTML parser to using the InB
ody insertion mode. | 292 // We use a fake body element here to trick the HTML parser to using the InB
ody insertion mode. |
| 278 RefPtrWillBeRawPtr<HTMLBodyElement> fakeBody = HTMLBodyElement::create(docum
ent); | 293 RefPtrWillBeRawPtr<HTMLBodyElement> fakeBody = HTMLBodyElement::create(docum
ent); |
| 279 RefPtrWillBeRawPtr<DocumentFragment> fragment = DocumentFragment::create(doc
ument); | 294 RefPtrWillBeRawPtr<DocumentFragment> fragment = DocumentFragment::create(doc
ument); |
| 280 | 295 |
| 281 fragment->parseHTML(markup, fakeBody.get(), parserContentPolicy); | 296 fragment->parseHTML(markup, fakeBody.get(), parserContentPolicy); |
| 282 | 297 |
| 283 if (!baseURL.isEmpty() && baseURL != blankURL() && baseURL != document.baseU
RL()) | 298 if (!baseURL.isEmpty() && baseURL != blankURL() && baseURL != document.baseU
RL()) |
| 284 completeURLs(*fragment, baseURL); | 299 completeURLs(*fragment, baseURL); |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 | 712 |
| 698 RefPtrWillBeRawPtr<Text> textNext = toText(next); | 713 RefPtrWillBeRawPtr<Text> textNext = toText(next); |
| 699 textNode->appendData(textNext->data()); | 714 textNode->appendData(textNext->data()); |
| 700 if (textNext->parentNode()) // Might have been removed by mutation event. | 715 if (textNext->parentNode()) // Might have been removed by mutation event. |
| 701 textNext->remove(exceptionState); | 716 textNext->remove(exceptionState); |
| 702 } | 717 } |
| 703 | 718 |
| 704 template class CORE_TEMPLATE_EXPORT CreateMarkupAlgorithm<EditingStrategy>; | 719 template class CORE_TEMPLATE_EXPORT CreateMarkupAlgorithm<EditingStrategy>; |
| 705 | 720 |
| 706 } | 721 } |
| OLD | NEW |