OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 ContainerNode* context = element->parentNode(); | 585 ContainerNode* context = element->parentNode(); |
586 | 586 |
587 // If Mail wraps the fragment with a Paste as Quotation blockquote, or if | 587 // If Mail wraps the fragment with a Paste as Quotation blockquote, or if |
588 // you're pasting into a quoted region, styles from blockquoteNode are | 588 // you're pasting into a quoted region, styles from blockquoteNode are |
589 // allowed to override those from the source document, see | 589 // allowed to override those from the source document, see |
590 // <rdar://problem/4930986> and <rdar://problem/5089327>. | 590 // <rdar://problem/4930986> and <rdar://problem/5089327>. |
591 HTMLQuoteElement* blockquote_element = | 591 HTMLQuoteElement* blockquote_element = |
592 !context | 592 !context |
593 ? ToHTMLQuoteElement(context) | 593 ? ToHTMLQuoteElement(context) |
594 : ToHTMLQuoteElement(EnclosingNodeOfType( | 594 : ToHTMLQuoteElement(EnclosingNodeOfType( |
595 Position::FirstPositionInNode(context), | 595 Position::FirstPositionInNode(*context), |
596 IsMailHTMLBlockquoteElement, kCanCrossEditingBoundary)); | 596 IsMailHTMLBlockquoteElement, kCanCrossEditingBoundary)); |
597 | 597 |
598 // EditingStyle::removeStyleFromRulesAndContext() uses StyleResolver, | 598 // EditingStyle::removeStyleFromRulesAndContext() uses StyleResolver, |
599 // which requires clean style. | 599 // which requires clean style. |
600 // TODO(editing-dev): There is currently no way to update style without | 600 // TODO(editing-dev): There is currently no way to update style without |
601 // updating layout. We might want to have updateLifcycleToStyleClean() | 601 // updating layout. We might want to have updateLifcycleToStyleClean() |
602 // similar to FrameView::updateLifecylceToLayoutClean() in Document. | 602 // similar to FrameView::updateLifecylceToLayoutClean() in Document. |
603 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); | 603 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); |
604 | 604 |
605 if (blockquote_element) | 605 if (blockquote_element) |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 // We can skip this optimization for fragments not wrapped in one of | 1247 // We can skip this optimization for fragments not wrapped in one of |
1248 // our style spans and for positions inside list items | 1248 // our style spans and for positions inside list items |
1249 // since insertAsListItems already does the right thing. | 1249 // since insertAsListItems already does the right thing. |
1250 if (!match_style_ && !EnclosingList(insertion_pos.ComputeContainerNode())) { | 1250 if (!match_style_ && !EnclosingList(insertion_pos.ComputeContainerNode())) { |
1251 if (insertion_pos.ComputeContainerNode()->IsTextNode() && | 1251 if (insertion_pos.ComputeContainerNode()->IsTextNode() && |
1252 insertion_pos.OffsetInContainerNode() && | 1252 insertion_pos.OffsetInContainerNode() && |
1253 !insertion_pos.AtLastEditingPositionForNode()) { | 1253 !insertion_pos.AtLastEditingPositionForNode()) { |
1254 SplitTextNode(ToText(insertion_pos.ComputeContainerNode()), | 1254 SplitTextNode(ToText(insertion_pos.ComputeContainerNode()), |
1255 insertion_pos.OffsetInContainerNode()); | 1255 insertion_pos.OffsetInContainerNode()); |
1256 insertion_pos = | 1256 insertion_pos = |
1257 Position::FirstPositionInNode(insertion_pos.ComputeContainerNode()); | 1257 Position::FirstPositionInNode(*insertion_pos.ComputeContainerNode()); |
1258 } | 1258 } |
1259 | 1259 |
1260 if (HTMLElement* element_to_split_to = | 1260 if (HTMLElement* element_to_split_to = |
1261 ElementToSplitToAvoidPastingIntoInlineElementsWithStyle( | 1261 ElementToSplitToAvoidPastingIntoInlineElementsWithStyle( |
1262 insertion_pos)) { | 1262 insertion_pos)) { |
1263 if (insertion_pos.ComputeContainerNode() != | 1263 if (insertion_pos.ComputeContainerNode() != |
1264 element_to_split_to->parentNode()) { | 1264 element_to_split_to->parentNode()) { |
1265 Node* split_start = insertion_pos.ComputeNodeAfterPosition(); | 1265 Node* split_start = insertion_pos.ComputeNodeAfterPosition(); |
1266 if (!split_start) | 1266 if (!split_start) |
1267 split_start = insertion_pos.ComputeContainerNode(); | 1267 split_start = insertion_pos.ComputeContainerNode(); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1536 Element* enclosing_block_element = EnclosingBlock( | 1536 Element* enclosing_block_element = EnclosingBlock( |
1537 end_of_inserted_content.DeepEquivalent().AnchorNode()); | 1537 end_of_inserted_content.DeepEquivalent().AnchorNode()); |
1538 if (IsListItem(enclosing_block_element)) { | 1538 if (IsListItem(enclosing_block_element)) { |
1539 HTMLLIElement* new_list_item = HTMLLIElement::Create(GetDocument()); | 1539 HTMLLIElement* new_list_item = HTMLLIElement::Create(GetDocument()); |
1540 InsertNodeAfter(new_list_item, enclosing_block_element, | 1540 InsertNodeAfter(new_list_item, enclosing_block_element, |
1541 editing_state); | 1541 editing_state); |
1542 if (editing_state->IsAborted()) | 1542 if (editing_state->IsAborted()) |
1543 return; | 1543 return; |
1544 SetEndingSelection( | 1544 SetEndingSelection( |
1545 SelectionInDOMTree::Builder() | 1545 SelectionInDOMTree::Builder() |
1546 .Collapse(Position::FirstPositionInNode(new_list_item)) | 1546 .Collapse(Position::FirstPositionInNode(*new_list_item)) |
1547 .Build()); | 1547 .Build()); |
1548 } else { | 1548 } else { |
1549 // Use a default paragraph element (a plain div) for the empty | 1549 // Use a default paragraph element (a plain div) for the empty |
1550 // paragraph, using the last paragraph block's style seems to annoy | 1550 // paragraph, using the last paragraph block's style seems to annoy |
1551 // users. | 1551 // users. |
1552 InsertParagraphSeparator( | 1552 InsertParagraphSeparator( |
1553 editing_state, true, | 1553 editing_state, true, |
1554 !start_is_inside_mail_blockquote && | 1554 !start_is_inside_mail_blockquote && |
1555 HighestEnclosingNodeOfType( | 1555 HighestEnclosingNodeOfType( |
1556 end_of_inserted_content.DeepEquivalent(), | 1556 end_of_inserted_content.DeepEquivalent(), |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1707 start_node, end_of_inserted_content_.OffsetInContainerNode() + 1); | 1707 start_node, end_of_inserted_content_.OffsetInContainerNode() + 1); |
1708 } else { | 1708 } else { |
1709 Text* node = GetDocument().CreateEditingTextNode( | 1709 Text* node = GetDocument().CreateEditingTextNode( |
1710 collapse_white_space ? NonBreakingSpaceString() : " "); | 1710 collapse_white_space ? NonBreakingSpaceString() : " "); |
1711 // Don't updateNodesInserted. Doing so would set m_endOfInsertedContent to | 1711 // Don't updateNodesInserted. Doing so would set m_endOfInsertedContent to |
1712 // be the node containing the leading space, but m_endOfInsertedContent is | 1712 // be the node containing the leading space, but m_endOfInsertedContent is |
1713 // supposed to mark the end of pasted content. | 1713 // supposed to mark the end of pasted content. |
1714 InsertNodeBefore(node, start_node, editing_state); | 1714 InsertNodeBefore(node, start_node, editing_state); |
1715 if (editing_state->IsAborted()) | 1715 if (editing_state->IsAborted()) |
1716 return; | 1716 return; |
1717 start_of_inserted_content_ = Position::FirstPositionInNode(node); | 1717 start_of_inserted_content_ = Position::FirstPositionInNode(*node); |
1718 } | 1718 } |
1719 } | 1719 } |
1720 } | 1720 } |
1721 | 1721 |
1722 void ReplaceSelectionCommand::CompleteHTMLReplacement( | 1722 void ReplaceSelectionCommand::CompleteHTMLReplacement( |
1723 const Position& last_position_to_select, | 1723 const Position& last_position_to_select, |
1724 EditingState* editing_state) { | 1724 EditingState* editing_state) { |
1725 Position start = PositionAtStartOfInsertedContent().DeepEquivalent(); | 1725 Position start = PositionAtStartOfInsertedContent().DeepEquivalent(); |
1726 Position end = PositionAtEndOfInsertedContent().DeepEquivalent(); | 1726 Position end = PositionAtEndOfInsertedContent().DeepEquivalent(); |
1727 | 1727 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2009 visitor->Trace(start_of_inserted_content_); | 2009 visitor->Trace(start_of_inserted_content_); |
2010 visitor->Trace(end_of_inserted_content_); | 2010 visitor->Trace(end_of_inserted_content_); |
2011 visitor->Trace(insertion_style_); | 2011 visitor->Trace(insertion_style_); |
2012 visitor->Trace(document_fragment_); | 2012 visitor->Trace(document_fragment_); |
2013 visitor->Trace(start_of_inserted_range_); | 2013 visitor->Trace(start_of_inserted_range_); |
2014 visitor->Trace(end_of_inserted_range_); | 2014 visitor->Trace(end_of_inserted_range_); |
2015 CompositeEditCommand::Trace(visitor); | 2015 CompositeEditCommand::Trace(visitor); |
2016 } | 2016 } |
2017 | 2017 |
2018 } // namespace blink | 2018 } // namespace blink |
OLD | NEW |