 Chromium Code Reviews
 Chromium Code Reviews Issue 651303003:
  Splitting text can leave |start| and |end| Positions without renderers  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk
    
  
    Issue 651303003:
  Splitting text can leave |start| and |end| Positions without renderers  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk| OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 * Copyright (C) 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. | 
| 3 * | 3 * | 
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without | 
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions | 
| 6 * are met: | 6 * are met: | 
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright | 
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. | 
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright | 
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the | 
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 | 576 | 
| 577 // split the start node and containing element if the selection starts insid e of it | 577 // split the start node and containing element if the selection starts insid e of it | 
| 578 bool splitStart = isValidCaretPositionInTextNode(start); | 578 bool splitStart = isValidCaretPositionInTextNode(start); | 
| 579 if (splitStart) { | 579 if (splitStart) { | 
| 580 if (shouldSplitTextElement(start.deprecatedNode()->parentElement(), styl e)) | 580 if (shouldSplitTextElement(start.deprecatedNode()->parentElement(), styl e)) | 
| 581 splitTextElementAtStart(start, end); | 581 splitTextElementAtStart(start, end); | 
| 582 else | 582 else | 
| 583 splitTextAtStart(start, end); | 583 splitTextAtStart(start, end); | 
| 584 start = startPosition(); | 584 start = startPosition(); | 
| 585 end = endPosition(); | 585 end = endPosition(); | 
| 586 if (start.isNull() || end.isNull()) | |
| 587 return; | |
| 586 startDummySpanAncestor = dummySpanAncestorForNode(start.deprecatedNode() ); | 588 startDummySpanAncestor = dummySpanAncestorForNode(start.deprecatedNode() ); | 
| 587 } | 589 } | 
| 588 | 590 | 
| 589 // split the end node and containing element if the selection ends inside of it | 591 // split the end node and containing element if the selection ends inside of it | 
| 590 bool splitEnd = isValidCaretPositionInTextNode(end); | 592 bool splitEnd = isValidCaretPositionInTextNode(end); | 
| 591 if (splitEnd) { | 593 if (splitEnd) { | 
| 592 if (shouldSplitTextElement(end.deprecatedNode()->parentElement(), style) ) | 594 if (shouldSplitTextElement(end.deprecatedNode()->parentElement(), style) ) | 
| 593 splitTextElementAtEnd(start, end); | 595 splitTextElementAtEnd(start, end); | 
| 594 else | 596 else | 
| 595 splitTextAtEnd(start, end); | 597 splitTextAtEnd(start, end); | 
| 596 start = startPosition(); | 598 start = startPosition(); | 
| 597 end = endPosition(); | 599 end = endPosition(); | 
| 600 if (start.isNull() || end.isNull()) | |
| 601 return; | |
| 598 endDummySpanAncestor = dummySpanAncestorForNode(end.deprecatedNode()); | 602 endDummySpanAncestor = dummySpanAncestorForNode(end.deprecatedNode()); | 
| 599 } | 603 } | 
| 600 | 604 | 
| 601 // Remove style from the selection. | 605 // Remove style from the selection. | 
| 602 // Use the upstream position of the start for removing style. | 606 // Use the upstream position of the start for removing style. | 
| 603 // This will ensure we remove all traces of the relevant styles from the sel ection | 607 // This will ensure we remove all traces of the relevant styles from the sel ection | 
| 604 // and prevent us from adding redundant ones, as described in: | 608 // and prevent us from adding redundant ones, as described in: | 
| 605 // <rdar://problem/3724344> Bolding and unbolding creates extraneous tags | 609 // <rdar://problem/3724344> Bolding and unbolding creates extraneous tags | 
| 606 Position removeStart = start.upstream(); | 610 Position removeStart = start.upstream(); | 
| 607 WritingDirection textDirection = NaturalWritingDirection; | 611 WritingDirection textDirection = NaturalWritingDirection; | 
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1258 bool ApplyStyleCommand::shouldSplitTextElement(Element* element, EditingStyle* s tyle) | 1262 bool ApplyStyleCommand::shouldSplitTextElement(Element* element, EditingStyle* s tyle) | 
| 1259 { | 1263 { | 
| 1260 if (!element || !element->isHTMLElement()) | 1264 if (!element || !element->isHTMLElement()) | 
| 1261 return false; | 1265 return false; | 
| 1262 | 1266 | 
| 1263 return shouldRemoveInlineStyleFromElement(style, toHTMLElement(element)); | 1267 return shouldRemoveInlineStyleFromElement(style, toHTMLElement(element)); | 
| 1264 } | 1268 } | 
| 1265 | 1269 | 
| 1266 bool ApplyStyleCommand::isValidCaretPositionInTextNode(const Position& position) | 1270 bool ApplyStyleCommand::isValidCaretPositionInTextNode(const Position& position) | 
| 1267 { | 1271 { | 
| 1272 ASSERT(position.containerNode()); | |
| 
yosin_UTC9
2014/10/15 01:26:41
nit: It is better to use |ASSERT(position.isNotNul
 
rhogan
2014/10/15 20:20:30
Done.
 | |
| 1273 | |
| 1268 Node* node = position.containerNode(); | 1274 Node* node = position.containerNode(); | 
| 1269 if (position.anchorType() != Position::PositionIsOffsetInAnchor || !node->is TextNode()) | 1275 if (position.anchorType() != Position::PositionIsOffsetInAnchor || !node->is TextNode()) | 
| 1270 return false; | 1276 return false; | 
| 1271 int offsetInText = position.offsetInContainerNode(); | 1277 int offsetInText = position.offsetInContainerNode(); | 
| 1272 return offsetInText > caretMinOffset(node) && offsetInText < caretMaxOffset( node); | 1278 return offsetInText > caretMinOffset(node) && offsetInText < caretMaxOffset( node); | 
| 1273 } | 1279 } | 
| 1274 | 1280 | 
| 1275 bool ApplyStyleCommand::mergeStartWithPreviousIfIdentical(const Position& start, const Position& end) | 1281 bool ApplyStyleCommand::mergeStartWithPreviousIfIdentical(const Position& start, const Position& end) | 
| 1276 { | 1282 { | 
| 1277 Node* startNode = start.containerNode(); | 1283 Node* startNode = start.containerNode(); | 
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1572 void ApplyStyleCommand::trace(Visitor* visitor) | 1578 void ApplyStyleCommand::trace(Visitor* visitor) | 
| 1573 { | 1579 { | 
| 1574 visitor->trace(m_style); | 1580 visitor->trace(m_style); | 
| 1575 visitor->trace(m_start); | 1581 visitor->trace(m_start); | 
| 1576 visitor->trace(m_end); | 1582 visitor->trace(m_end); | 
| 1577 visitor->trace(m_styledInlineElement); | 1583 visitor->trace(m_styledInlineElement); | 
| 1578 CompositeEditCommand::trace(visitor); | 1584 CompositeEditCommand::trace(visitor); | 
| 1579 } | 1585 } | 
| 1580 | 1586 | 
| 1581 } | 1587 } | 
| OLD | NEW |