Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1060)

Side by Side Diff: Source/core/editing/VisibleUnits.cpp

Issue 20681004: Make first-letter style to work with editing Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 2013-08-08T13:29:08 Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 * 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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 479
480 searchRange->setStart(start.deprecatedNode(), start.deprecatedEditingOffset( ), es); 480 searchRange->setStart(start.deprecatedNode(), start.deprecatedEditingOffset( ), es);
481 searchRange->setEnd(end.deprecatedNode(), end.deprecatedEditingOffset(), es) ; 481 searchRange->setEnd(end.deprecatedNode(), end.deprecatedEditingOffset(), es) ;
482 482
483 ASSERT(!es.hadException()); 483 ASSERT(!es.hadException());
484 if (es.hadException()) 484 if (es.hadException())
485 return VisiblePosition(); 485 return VisiblePosition();
486 486
487 SimplifiedBackwardsTextIterator it(searchRange.get()); 487 SimplifiedBackwardsTextIterator it(searchRange.get());
488 unsigned next = 0; 488 unsigned next = 0;
489 bool inTextSecurityMode = start.deprecatedNode() && start.deprecatedNode()-> renderer() && start.deprecatedNode()->renderer()->style()->textSecurity() != TSN ONE; 489 bool inTextSecurityMode = start.deprecatedNode() && start.renderer() && star t.renderer()->style()->textSecurity() != TSNONE;
490 bool needMoreContext = false; 490 bool needMoreContext = false;
491 while (!it.atEnd()) { 491 while (!it.atEnd()) {
492 // iterate to get chunks until the searchFunction returns a non-zero val ue. 492 // iterate to get chunks until the searchFunction returns a non-zero val ue.
493 if (!inTextSecurityMode) 493 if (!inTextSecurityMode)
494 it.prependTextTo(string); 494 it.prependTextTo(string);
495 else { 495 else {
496 // Treat bullets used in the text security mode as regular character s when looking for boundaries 496 // Treat bullets used in the text security mode as regular character s when looking for boundaries
497 Vector<UChar, 1024> iteratorString; 497 Vector<UChar, 1024> iteratorString;
498 iteratorString.fill('x', it.length()); 498 iteratorString.fill('x', it.length());
499 string.prepend(iteratorString.data(), iteratorString.size()); 499 string.prepend(iteratorString.data(), iteratorString.size());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 if (i > 0) 553 if (i > 0)
554 break; 554 break;
555 backwardsIterator.advance(); 555 backwardsIterator.advance();
556 } 556 }
557 } 557 }
558 558
559 searchRange->selectNodeContents(boundary, IGNORE_EXCEPTION); 559 searchRange->selectNodeContents(boundary, IGNORE_EXCEPTION);
560 searchRange->setStart(start.deprecatedNode(), start.deprecatedEditingOffset( ), IGNORE_EXCEPTION); 560 searchRange->setStart(start.deprecatedNode(), start.deprecatedEditingOffset( ), IGNORE_EXCEPTION);
561 TextIterator it(searchRange.get(), TextIteratorEmitsCharactersBetweenAllVisi blePositions); 561 TextIterator it(searchRange.get(), TextIteratorEmitsCharactersBetweenAllVisi blePositions);
562 unsigned next = 0; 562 unsigned next = 0;
563 bool inTextSecurityMode = start.deprecatedNode() && start.deprecatedNode()-> renderer() && start.deprecatedNode()->renderer()->style()->textSecurity() != TSN ONE; 563 bool inTextSecurityMode = start.deprecatedNode() && start.renderer() && star t.renderer()->style()->textSecurity() != TSNONE;
564 bool needMoreContext = false; 564 bool needMoreContext = false;
565 while (!it.atEnd()) { 565 while (!it.atEnd()) {
566 // Keep asking the iterator for chunks until the search function 566 // Keep asking the iterator for chunks until the search function
567 // returns an end value not equal to the length of the string passed to it. 567 // returns an end value not equal to the length of the string passed to it.
568 if (!inTextSecurityMode) 568 if (!inTextSecurityMode)
569 it.appendTextTo(string); 569 it.appendTextTo(string);
570 else { 570 else {
571 // Treat bullets used in the text security mode as regular character s when looking for boundaries 571 // Treat bullets used in the text security mode as regular character s when looking for boundaries
572 Vector<UChar, 1024> iteratorString; 572 Vector<UChar, 1024> iteratorString;
573 iteratorString.fill('x', it.length()); 573 iteratorString.fill('x', it.length());
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 static VisiblePosition startPositionForLine(const VisiblePosition& c, LineEndpoi ntComputationMode mode) 713 static VisiblePosition startPositionForLine(const VisiblePosition& c, LineEndpoi ntComputationMode mode)
714 { 714 {
715 if (c.isNull()) 715 if (c.isNull())
716 return VisiblePosition(); 716 return VisiblePosition();
717 717
718 RootInlineBox* rootBox = RenderedPosition(c).rootBox(); 718 RootInlineBox* rootBox = RenderedPosition(c).rootBox();
719 if (!rootBox) { 719 if (!rootBox) {
720 // There are VisiblePositions at offset 0 in blocks without 720 // There are VisiblePositions at offset 0 in blocks without
721 // RootInlineBoxes, like empty editable blocks and bordered blocks. 721 // RootInlineBoxes, like empty editable blocks and bordered blocks.
722 Position p = c.deepEquivalent(); 722 Position p = c.deepEquivalent();
723 if (p.deprecatedNode()->renderer() && p.deprecatedNode()->renderer()->is RenderBlock() && !p.deprecatedEditingOffset()) 723 if (p.renderer() && p.renderer()->isRenderBlock() && !p.deprecatedEditin gOffset())
724 return c; 724 return c;
725 725
726 return VisiblePosition(); 726 return VisiblePosition();
727 } 727 }
728 728
729 Node* startNode; 729 Node* startNode;
730 InlineBox* startBox; 730 InlineBox* startBox;
731 if (mode == UseLogicalOrdering) { 731 if (mode == UseLogicalOrdering) {
732 startNode = rootBox->getLogicalStartBoxWithNode(startBox); 732 startNode = rootBox->getLogicalStartBoxWithNode(startBox);
733 if (!startNode) 733 if (!startNode)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 static VisiblePosition endPositionForLine(const VisiblePosition& c, LineEndpoint ComputationMode mode) 786 static VisiblePosition endPositionForLine(const VisiblePosition& c, LineEndpoint ComputationMode mode)
787 { 787 {
788 if (c.isNull()) 788 if (c.isNull())
789 return VisiblePosition(); 789 return VisiblePosition();
790 790
791 RootInlineBox* rootBox = RenderedPosition(c).rootBox(); 791 RootInlineBox* rootBox = RenderedPosition(c).rootBox();
792 if (!rootBox) { 792 if (!rootBox) {
793 // There are VisiblePositions at offset 0 in blocks without 793 // There are VisiblePositions at offset 0 in blocks without
794 // RootInlineBoxes, like empty editable blocks and bordered blocks. 794 // RootInlineBoxes, like empty editable blocks and bordered blocks.
795 Position p = c.deepEquivalent(); 795 Position p = c.deepEquivalent();
796 if (p.deprecatedNode()->renderer() && p.deprecatedNode()->renderer()->is RenderBlock() && !p.deprecatedEditingOffset()) 796 if (p.renderer() && p.renderer()->isRenderBlock() && !p.deprecatedEditin gOffset())
797 return c; 797 return c;
798 return VisiblePosition(); 798 return VisiblePosition();
799 } 799 }
800 800
801 Node* endNode; 801 Node* endNode;
802 InlineBox* endBox; 802 InlineBox* endBox;
803 if (mode == UseLogicalOrdering) { 803 if (mode == UseLogicalOrdering) {
804 endNode = rootBox->getLogicalEndBoxWithNode(endBox); 804 endNode = rootBox->getLogicalEndBoxWithNode(endBox);
805 if (!endNode) 805 if (!endNode)
806 return VisiblePosition(); 806 return VisiblePosition();
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 if (style->visibility() != VISIBLE) { 1130 if (style->visibility() != VISIBLE) {
1131 n = NodeTraversal::previousPostOrder(n, startBlock); 1131 n = NodeTraversal::previousPostOrder(n, startBlock);
1132 continue; 1132 continue;
1133 } 1133 }
1134 1134
1135 if (r->isBR() || isBlock(n)) 1135 if (r->isBR() || isBlock(n))
1136 break; 1136 break;
1137 1137
1138 if (r->isText() && toRenderText(r)->renderedTextLength()) { 1138 if (r->isText() && toRenderText(r)->renderedTextLength()) {
1139 ASSERT_WITH_SECURITY_IMPLICATION(n->isTextNode()); 1139 ASSERT_WITH_SECURITY_IMPLICATION(n->isTextNode());
1140 RenderText* text = toRenderText(r);
1140 type = Position::PositionIsOffsetInAnchor; 1141 type = Position::PositionIsOffsetInAnchor;
1141 if (style->preserveNewline()) { 1142 if (style->preserveNewline()) {
1142 RenderText* text = toRenderText(r);
1143 int i = text->textLength(); 1143 int i = text->textLength();
1144 int o = offset; 1144 int o = offset;
1145 if (n == startNode && o < i) 1145 if (n == startNode && o < i)
1146 i = max(0, o); 1146 i = max(0, o);
1147 while (--i >= 0) { 1147 while (--i >= 0) {
1148 if ((*text)[i] == '\n') 1148 if ((*text)[i] == '\n')
1149 return VisiblePosition(Position(toText(n), i + 1), DOWNS TREAM); 1149 return VisiblePosition(Position(toText(n), i + text->tex tStartOffset() + 1), DOWNSTREAM);
1150 } 1150 }
1151 } 1151 }
1152 node = n; 1152 node = n;
1153 offset = 0; 1153 offset = 0;
1154 n = NodeTraversal::previousPostOrder(n, startBlock); 1154 n = NodeTraversal::previousPostOrder(n, startBlock);
1155 } else if (editingIgnoresContent(n) || isTableElement(n)) { 1155 } else if (editingIgnoresContent(n) || isTableElement(n)) {
1156 node = n; 1156 node = n;
1157 type = Position::PositionIsBeforeAnchor; 1157 type = Position::PositionIsBeforeAnchor;
1158 n = n->previousSibling() ? n->previousSibling() : NodeTraversal::pre viousPostOrder(n, startBlock); 1158 n = n->previousSibling() ? n->previousSibling() : NodeTraversal::pre viousPostOrder(n, startBlock);
1159 } else 1159 } else
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 n = NodeTraversal::next(n, stayInsideBlock); 1212 n = NodeTraversal::next(n, stayInsideBlock);
1213 continue; 1213 continue;
1214 } 1214 }
1215 1215
1216 if (r->isBR() || isBlock(n)) 1216 if (r->isBR() || isBlock(n))
1217 break; 1217 break;
1218 1218
1219 // FIXME: We avoid returning a position where the renderer can't accept the caret. 1219 // FIXME: We avoid returning a position where the renderer can't accept the caret.
1220 if (r->isText() && toRenderText(r)->renderedTextLength()) { 1220 if (r->isText() && toRenderText(r)->renderedTextLength()) {
1221 ASSERT_WITH_SECURITY_IMPLICATION(n->isTextNode()); 1221 ASSERT_WITH_SECURITY_IMPLICATION(n->isTextNode());
1222 int length = toRenderText(r)->textLength(); 1222 RenderText* text = toRenderText(r);
1223 int length = text->textLength();
1223 type = Position::PositionIsOffsetInAnchor; 1224 type = Position::PositionIsOffsetInAnchor;
1224 if (style->preserveNewline()) { 1225 if (style->preserveNewline()) {
1225 RenderText* text = toRenderText(r);
1226 int o = n == startNode ? offset : 0; 1226 int o = n == startNode ? offset : 0;
1227 for (int i = o; i < length; ++i) { 1227 for (int i = o; i < length; ++i) {
1228 if ((*text)[i] == '\n') 1228 if ((*text)[i] == '\n')
1229 return VisiblePosition(Position(toText(n), i), DOWNSTREA M); 1229 return VisiblePosition(Position(toText(n), i + text->tex tStartOffset()), DOWNSTREAM);
1230 } 1230 }
1231 } 1231 }
1232 node = n; 1232 node = n;
1233 offset = r->caretMaxOffset(); 1233 offset = r->caretMaxOffset() + text->textStartOffset();
1234 n = NodeTraversal::next(n, stayInsideBlock); 1234 n = NodeTraversal::next(n, stayInsideBlock);
1235 } else if (editingIgnoresContent(n) || isTableElement(n)) { 1235 } else if (editingIgnoresContent(n) || isTableElement(n)) {
1236 node = n; 1236 node = n;
1237 type = Position::PositionIsAfterAnchor; 1237 type = Position::PositionIsAfterAnchor;
1238 n = NodeTraversal::nextSkippingChildren(n, stayInsideBlock); 1238 n = NodeTraversal::nextSkippingChildren(n, stayInsideBlock);
1239 } else 1239 } else
1240 n = NodeTraversal::next(n, stayInsideBlock); 1240 n = NodeTraversal::next(n, stayInsideBlock);
1241 } 1241 }
1242 1242
1243 if (type == Position::PositionIsOffsetInAnchor) 1243 if (type == Position::PositionIsOffsetInAnchor)
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 { 1414 {
1415 return direction == LTR ? logicalStartOfLine(c) : logicalEndOfLine(c); 1415 return direction == LTR ? logicalStartOfLine(c) : logicalEndOfLine(c);
1416 } 1416 }
1417 1417
1418 VisiblePosition rightBoundaryOfLine(const VisiblePosition& c, TextDirection dire ction) 1418 VisiblePosition rightBoundaryOfLine(const VisiblePosition& c, TextDirection dire ction)
1419 { 1419 {
1420 return direction == LTR ? logicalEndOfLine(c) : logicalStartOfLine(c); 1420 return direction == LTR ? logicalEndOfLine(c) : logicalStartOfLine(c);
1421 } 1421 }
1422 1422
1423 } 1423 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698