OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "core/html/HTMLDivElement.h" | 45 #include "core/html/HTMLDivElement.h" |
46 #include "core/html/HTMLLIElement.h" | 46 #include "core/html/HTMLLIElement.h" |
47 #include "core/html/HTMLOListElement.h" | 47 #include "core/html/HTMLOListElement.h" |
48 #include "core/html/HTMLParagraphElement.h" | 48 #include "core/html/HTMLParagraphElement.h" |
49 #include "core/html/HTMLTableElement.h" | 49 #include "core/html/HTMLTableElement.h" |
50 #include "core/html/HTMLUListElement.h" | 50 #include "core/html/HTMLUListElement.h" |
51 #include "core/page/Frame.h" | 51 #include "core/page/Frame.h" |
52 #include "core/rendering/RenderObject.h" | 52 #include "core/rendering/RenderObject.h" |
53 #include "wtf/Assertions.h" | 53 #include "wtf/Assertions.h" |
54 #include "wtf/StdLibExtras.h" | 54 #include "wtf/StdLibExtras.h" |
| 55 #include "wtf/text/StringBuilder.h" |
55 #include "wtf/unicode/CharacterNames.h" | 56 #include "wtf/unicode/CharacterNames.h" |
56 | 57 |
57 using namespace std; | 58 using namespace std; |
58 | 59 |
59 namespace WebCore { | 60 namespace WebCore { |
60 | 61 |
61 using namespace HTMLNames; | 62 using namespace HTMLNames; |
62 | 63 |
63 // Atomic means that the node has no children, or has children which are ignored
for the | 64 // Atomic means that the node has no children, or has children which are ignored
for the |
64 // purposes of editing. | 65 // purposes of editing. |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 349 |
349 // NOTE: This should preempt the childNodeCount for, e.g., select nodes | 350 // NOTE: This should preempt the childNodeCount for, e.g., select nodes |
350 if (editingIgnoresContent(node)) | 351 if (editingIgnoresContent(node)) |
351 return 1; | 352 return 1; |
352 | 353 |
353 return 0; | 354 return 0; |
354 } | 355 } |
355 | 356 |
356 String stringWithRebalancedWhitespace(const String& string, bool startIsStartOfP
aragraph, bool endIsEndOfParagraph) | 357 String stringWithRebalancedWhitespace(const String& string, bool startIsStartOfP
aragraph, bool endIsEndOfParagraph) |
357 { | 358 { |
358 Vector<UChar> rebalancedString; | 359 unsigned length = string.length(); |
359 append(rebalancedString, string); | 360 |
| 361 StringBuilder rebalancedString; |
| 362 rebalancedString.reserveCapacity(length); |
360 | 363 |
361 bool previousCharacterWasSpace = false; | 364 bool previousCharacterWasSpace = false; |
362 for (size_t i = 0; i < rebalancedString.size(); i++) { | 365 for (size_t i = 0; i < length; i++) { |
363 if (!isWhitespace(rebalancedString[i])) { | 366 UChar c = string[i]; |
| 367 if (!isWhitespace(c)) { |
| 368 rebalancedString.append(c); |
364 previousCharacterWasSpace = false; | 369 previousCharacterWasSpace = false; |
365 continue; | 370 continue; |
366 } | 371 } |
367 | 372 |
368 if (previousCharacterWasSpace || (!i && startIsStartOfParagraph) || (i +
1 == rebalancedString.size() && endIsEndOfParagraph)) { | 373 if (previousCharacterWasSpace || (!i && startIsStartOfParagraph) || (i +
1 == length && endIsEndOfParagraph)) { |
369 rebalancedString[i] = noBreakSpace; | 374 rebalancedString.append(noBreakSpace); |
370 previousCharacterWasSpace = false; | 375 previousCharacterWasSpace = false; |
371 } else { | 376 } else { |
372 rebalancedString[i] = ' '; | 377 rebalancedString.append(' '); |
373 previousCharacterWasSpace = true; | 378 previousCharacterWasSpace = true; |
374 } | 379 } |
375 | |
376 } | 380 } |
377 | 381 |
378 return String::adopt(rebalancedString); | 382 ASSERT(rebalancedString.length() == length); |
| 383 |
| 384 return rebalancedString.toString(); |
379 } | 385 } |
380 | 386 |
381 bool isTableStructureNode(const Node *node) | 387 bool isTableStructureNode(const Node *node) |
382 { | 388 { |
383 RenderObject* renderer = node->renderer(); | 389 RenderObject* renderer = node->renderer(); |
384 return (renderer && (renderer->isTableCell() || renderer->isTableRow() || re
nderer->isTableSection() || renderer->isRenderTableCol())); | 390 return (renderer && (renderer->isTableCell() || renderer->isTableRow() || re
nderer->isTableSection() || renderer->isRenderTableCol())); |
385 } | 391 } |
386 | 392 |
387 const String& nonBreakingSpaceString() | 393 const String& nonBreakingSpaceString() |
388 { | 394 { |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 // if the selection starts just before a paragraph break, skip over it | 1159 // if the selection starts just before a paragraph break, skip over it |
1154 if (isEndOfParagraph(visiblePosition)) | 1160 if (isEndOfParagraph(visiblePosition)) |
1155 return visiblePosition.next().deepEquivalent().downstream(); | 1161 return visiblePosition.next().deepEquivalent().downstream(); |
1156 | 1162 |
1157 // otherwise, make sure to be at the start of the first selected node, | 1163 // otherwise, make sure to be at the start of the first selected node, |
1158 // instead of possibly at the end of the last node before the selection | 1164 // instead of possibly at the end of the last node before the selection |
1159 return visiblePosition.deepEquivalent().downstream(); | 1165 return visiblePosition.deepEquivalent().downstream(); |
1160 } | 1166 } |
1161 | 1167 |
1162 } // namespace WebCore | 1168 } // namespace WebCore |
OLD | NEW |