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

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

Powered by Google App Engine
This is Rietveld 408576698