OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights |
3 * reserved. | 3 * reserved. |
4 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. | 4 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. |
5 * Copyright (C) 2011 Igalia S.L. | 5 * Copyright (C) 2011 Igalia S.L. |
6 * Copyright (C) 2011 Motorola Mobility. All rights reserved. | 6 * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
7 * | 7 * |
8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
10 * are met: | 10 * are met: |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } | 238 } |
239 | 239 |
240 template <typename Strategy> | 240 template <typename Strategy> |
241 class CreateMarkupAlgorithm { | 241 class CreateMarkupAlgorithm { |
242 public: | 242 public: |
243 static String CreateMarkup( | 243 static String CreateMarkup( |
244 const PositionTemplate<Strategy>& start_position, | 244 const PositionTemplate<Strategy>& start_position, |
245 const PositionTemplate<Strategy>& end_position, | 245 const PositionTemplate<Strategy>& end_position, |
246 EAnnotateForInterchange should_annotate = kDoNotAnnotateForInterchange, | 246 EAnnotateForInterchange should_annotate = kDoNotAnnotateForInterchange, |
247 ConvertBlocksToInlines = ConvertBlocksToInlines::kNotConvert, | 247 ConvertBlocksToInlines = ConvertBlocksToInlines::kNotConvert, |
248 EAbsoluteURLs should_resolve_ur_ls = kDoNotResolveURLs, | 248 EAbsoluteURLs should_resolve_urls = kDoNotResolveURLs, |
249 Node* constraining_ancestor = nullptr); | 249 Node* constraining_ancestor = nullptr); |
250 }; | 250 }; |
251 | 251 |
252 // FIXME: Shouldn't we omit style info when annotate == | 252 // FIXME: Shouldn't we omit style info when annotate == |
253 // DoNotAnnotateForInterchange? | 253 // DoNotAnnotateForInterchange? |
254 // FIXME: At least, annotation and style info should probably not be included in | 254 // FIXME: At least, annotation and style info should probably not be included in |
255 // range.markupString() | 255 // range.markupString() |
256 template <typename Strategy> | 256 template <typename Strategy> |
257 String CreateMarkupAlgorithm<Strategy>::CreateMarkup( | 257 String CreateMarkupAlgorithm<Strategy>::CreateMarkup( |
258 const PositionTemplate<Strategy>& start_position, | 258 const PositionTemplate<Strategy>& start_position, |
259 const PositionTemplate<Strategy>& end_position, | 259 const PositionTemplate<Strategy>& end_position, |
260 EAnnotateForInterchange should_annotate, | 260 EAnnotateForInterchange should_annotate, |
261 ConvertBlocksToInlines convert_blocks_to_inlines, | 261 ConvertBlocksToInlines convert_blocks_to_inlines, |
262 EAbsoluteURLs should_resolve_ur_ls, | 262 EAbsoluteURLs should_resolve_urls, |
263 Node* constraining_ancestor) { | 263 Node* constraining_ancestor) { |
264 if (start_position.IsNull() || end_position.IsNull()) | 264 if (start_position.IsNull() || end_position.IsNull()) |
265 return g_empty_string; | 265 return g_empty_string; |
266 | 266 |
267 CHECK_LE(start_position.CompareTo(end_position), 0); | 267 CHECK_LE(start_position.CompareTo(end_position), 0); |
268 | 268 |
269 bool collapsed = start_position == end_position; | 269 bool collapsed = start_position == end_position; |
270 if (collapsed) | 270 if (collapsed) |
271 return g_empty_string; | 271 return g_empty_string; |
272 Node* common_ancestor = | 272 Node* common_ancestor = |
273 Strategy::CommonAncestor(*start_position.ComputeContainerNode(), | 273 Strategy::CommonAncestor(*start_position.ComputeContainerNode(), |
274 *end_position.ComputeContainerNode()); | 274 *end_position.ComputeContainerNode()); |
275 if (!common_ancestor) | 275 if (!common_ancestor) |
276 return g_empty_string; | 276 return g_empty_string; |
277 | 277 |
278 Document* document = start_position.GetDocument(); | 278 Document* document = start_position.GetDocument(); |
279 | 279 |
280 DCHECK(!document->NeedsLayoutTreeUpdate()); | 280 DCHECK(!document->NeedsLayoutTreeUpdate()); |
281 DocumentLifecycle::DisallowTransitionScope disallow_transition( | 281 DocumentLifecycle::DisallowTransitionScope disallow_transition( |
282 document->Lifecycle()); | 282 document->Lifecycle()); |
283 | 283 |
284 HTMLElement* special_common_ancestor = HighestAncestorToWrapMarkup<Strategy>( | 284 HTMLElement* special_common_ancestor = HighestAncestorToWrapMarkup<Strategy>( |
285 start_position, end_position, should_annotate, constraining_ancestor); | 285 start_position, end_position, should_annotate, constraining_ancestor); |
286 StyledMarkupSerializer<Strategy> serializer( | 286 StyledMarkupSerializer<Strategy> serializer( |
287 should_resolve_ur_ls, should_annotate, start_position, end_position, | 287 should_resolve_urls, should_annotate, start_position, end_position, |
288 special_common_ancestor, convert_blocks_to_inlines); | 288 special_common_ancestor, convert_blocks_to_inlines); |
289 return serializer.CreateMarkup(); | 289 return serializer.CreateMarkup(); |
290 } | 290 } |
291 | 291 |
292 String CreateMarkup(const Position& start_position, | 292 String CreateMarkup(const Position& start_position, |
293 const Position& end_position, | 293 const Position& end_position, |
294 EAnnotateForInterchange should_annotate, | 294 EAnnotateForInterchange should_annotate, |
295 ConvertBlocksToInlines convert_blocks_to_inlines, | 295 ConvertBlocksToInlines convert_blocks_to_inlines, |
296 EAbsoluteURLs should_resolve_ur_ls, | 296 EAbsoluteURLs should_resolve_urls, |
297 Node* constraining_ancestor) { | 297 Node* constraining_ancestor) { |
298 return CreateMarkupAlgorithm<EditingStrategy>::CreateMarkup( | 298 return CreateMarkupAlgorithm<EditingStrategy>::CreateMarkup( |
299 start_position, end_position, should_annotate, convert_blocks_to_inlines, | 299 start_position, end_position, should_annotate, convert_blocks_to_inlines, |
300 should_resolve_ur_ls, constraining_ancestor); | 300 should_resolve_urls, constraining_ancestor); |
301 } | 301 } |
302 | 302 |
303 String CreateMarkup(const PositionInFlatTree& start_position, | 303 String CreateMarkup(const PositionInFlatTree& start_position, |
304 const PositionInFlatTree& end_position, | 304 const PositionInFlatTree& end_position, |
305 EAnnotateForInterchange should_annotate, | 305 EAnnotateForInterchange should_annotate, |
306 ConvertBlocksToInlines convert_blocks_to_inlines, | 306 ConvertBlocksToInlines convert_blocks_to_inlines, |
307 EAbsoluteURLs should_resolve_ur_ls, | 307 EAbsoluteURLs should_resolve_urls, |
308 Node* constraining_ancestor) { | 308 Node* constraining_ancestor) { |
309 return CreateMarkupAlgorithm<EditingInFlatTreeStrategy>::CreateMarkup( | 309 return CreateMarkupAlgorithm<EditingInFlatTreeStrategy>::CreateMarkup( |
310 start_position, end_position, should_annotate, convert_blocks_to_inlines, | 310 start_position, end_position, should_annotate, convert_blocks_to_inlines, |
311 should_resolve_ur_ls, constraining_ancestor); | 311 should_resolve_urls, constraining_ancestor); |
312 } | 312 } |
313 | 313 |
314 DocumentFragment* CreateFragmentFromMarkup( | 314 DocumentFragment* CreateFragmentFromMarkup( |
315 Document& document, | 315 Document& document, |
316 const String& markup, | 316 const String& markup, |
317 const String& base_url, | 317 const String& base_url, |
318 ParserContentPolicy parser_content_policy) { | 318 ParserContentPolicy parser_content_policy) { |
319 // We use a fake body element here to trick the HTML parser to using the | 319 // We use a fake body element here to trick the HTML parser to using the |
320 // InBody insertion mode. | 320 // InBody insertion mode. |
321 HTMLBodyElement* fake_body = HTMLBodyElement::Create(document); | 321 HTMLBodyElement* fake_body = HTMLBodyElement::Create(document); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 else | 427 else |
428 fragment->ParserTakeAllChildrenFrom(ToContainerNode(*common_ancestor)); | 428 fragment->ParserTakeAllChildrenFrom(ToContainerNode(*common_ancestor)); |
429 | 429 |
430 TrimFragment(fragment, node_before_context, node_after_context); | 430 TrimFragment(fragment, node_before_context, node_after_context); |
431 | 431 |
432 return fragment; | 432 return fragment; |
433 } | 433 } |
434 | 434 |
435 String CreateMarkup(const Node* node, | 435 String CreateMarkup(const Node* node, |
436 EChildrenOnly children_only, | 436 EChildrenOnly children_only, |
437 EAbsoluteURLs should_resolve_ur_ls) { | 437 EAbsoluteURLs should_resolve_urls) { |
438 if (!node) | 438 if (!node) |
439 return ""; | 439 return ""; |
440 | 440 |
441 MarkupAccumulator accumulator(should_resolve_ur_ls); | 441 MarkupAccumulator accumulator(should_resolve_urls); |
442 return SerializeNodes<EditingStrategy>(accumulator, const_cast<Node&>(*node), | 442 return SerializeNodes<EditingStrategy>(accumulator, const_cast<Node&>(*node), |
443 children_only); | 443 children_only); |
444 } | 444 } |
445 | 445 |
446 static void FillContainerFromString(ContainerNode* paragraph, | 446 static void FillContainerFromString(ContainerNode* paragraph, |
447 const String& string) { | 447 const String& string) { |
448 Document& document = paragraph->GetDocument(); | 448 Document& document = paragraph->GetDocument(); |
449 | 449 |
450 if (string.IsEmpty()) { | 450 if (string.IsEmpty()) { |
451 paragraph->AppendChild(HTMLBRElement::Create(document)); | 451 paragraph->AppendChild(HTMLBRElement::Create(document)); |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 text_node->appendData(text_next->data()); | 757 text_node->appendData(text_next->data()); |
758 if (text_next->parentNode()) // Might have been removed by mutation event. | 758 if (text_next->parentNode()) // Might have been removed by mutation event. |
759 text_next->remove(exception_state); | 759 text_next->remove(exception_state); |
760 } | 760 } |
761 | 761 |
762 template class CORE_TEMPLATE_EXPORT CreateMarkupAlgorithm<EditingStrategy>; | 762 template class CORE_TEMPLATE_EXPORT CreateMarkupAlgorithm<EditingStrategy>; |
763 template class CORE_TEMPLATE_EXPORT | 763 template class CORE_TEMPLATE_EXPORT |
764 CreateMarkupAlgorithm<EditingInFlatTreeStrategy>; | 764 CreateMarkupAlgorithm<EditingInFlatTreeStrategy>; |
765 | 765 |
766 } // namespace blink | 766 } // namespace blink |
OLD | NEW |