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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "core/editing/VisibleUnits.h" | 44 #include "core/editing/VisibleUnits.h" |
45 #include "core/html/HTMLBRElement.h" | 45 #include "core/html/HTMLBRElement.h" |
46 #include "core/html/HTMLDivElement.h" | 46 #include "core/html/HTMLDivElement.h" |
47 #include "core/html/HTMLLIElement.h" | 47 #include "core/html/HTMLLIElement.h" |
48 #include "core/html/HTMLOListElement.h" | 48 #include "core/html/HTMLOListElement.h" |
49 #include "core/html/HTMLParagraphElement.h" | 49 #include "core/html/HTMLParagraphElement.h" |
50 #include "core/html/HTMLTableElement.h" | 50 #include "core/html/HTMLTableElement.h" |
51 #include "core/html/HTMLUListElement.h" | 51 #include "core/html/HTMLUListElement.h" |
52 #include "core/page/Frame.h" | 52 #include "core/page/Frame.h" |
53 #include "core/rendering/RenderObject.h" | 53 #include "core/rendering/RenderObject.h" |
| 54 #include "core/rendering/RenderText.h" |
54 #include "wtf/Assertions.h" | 55 #include "wtf/Assertions.h" |
55 #include "wtf/StdLibExtras.h" | 56 #include "wtf/StdLibExtras.h" |
56 #include "wtf/text/StringBuilder.h" | 57 #include "wtf/text/StringBuilder.h" |
57 #include "wtf/unicode/CharacterNames.h" | 58 #include "wtf/unicode/CharacterNames.h" |
58 | 59 |
59 using namespace std; | 60 using namespace std; |
60 | 61 |
61 namespace WebCore { | 62 namespace WebCore { |
62 | 63 |
63 using namespace HTMLNames; | 64 using namespace HTMLNames; |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 if (result.isNull() || result.deprecatedNode()->rootEditableElement() != pos
.deprecatedNode()->rootEditableElement()) | 481 if (result.isNull() || result.deprecatedNode()->rootEditableElement() != pos
.deprecatedNode()->rootEditableElement()) |
481 return pos; | 482 return pos; |
482 if (containingSpecialElement) | 483 if (containingSpecialElement) |
483 *containingSpecialElement = n; | 484 *containingSpecialElement = n; |
484 return result; | 485 return result; |
485 } | 486 } |
486 | 487 |
487 Node* isFirstPositionAfterTable(const VisiblePosition& visiblePosition) | 488 Node* isFirstPositionAfterTable(const VisiblePosition& visiblePosition) |
488 { | 489 { |
489 Position upstream(visiblePosition.deepEquivalent().upstream()); | 490 Position upstream(visiblePosition.deepEquivalent().upstream()); |
490 if (upstream.deprecatedNode() && upstream.deprecatedNode()->renderer() && up
stream.deprecatedNode()->renderer()->isTable() && upstream.atLastEditingPosition
ForNode()) | 491 if (upstream.deprecatedNode() && upstream.renderer() && upstream.renderer()-
>isTable() && upstream.atLastEditingPositionForNode()) |
491 return upstream.deprecatedNode(); | 492 return upstream.deprecatedNode(); |
492 | 493 |
493 return 0; | 494 return 0; |
494 } | 495 } |
495 | 496 |
496 Node* isLastPositionBeforeTable(const VisiblePosition& visiblePosition) | 497 Node* isLastPositionBeforeTable(const VisiblePosition& visiblePosition) |
497 { | 498 { |
498 Position downstream(visiblePosition.deepEquivalent().downstream()); | 499 Position downstream(visiblePosition.deepEquivalent().downstream()); |
499 if (downstream.deprecatedNode() && downstream.deprecatedNode()->renderer() &
& downstream.deprecatedNode()->renderer()->isTable() && downstream.atFirstEditin
gPositionForNode()) | 500 if (downstream.deprecatedNode() && downstream.renderer() && downstream.rende
rer()->isTable() && downstream.atFirstEditingPositionForNode()) |
500 return downstream.deprecatedNode(); | 501 return downstream.deprecatedNode(); |
501 | 502 |
502 return 0; | 503 return 0; |
503 } | 504 } |
504 | 505 |
505 // Returns the visible position at the beginning of a node | 506 // Returns the visible position at the beginning of a node |
506 VisiblePosition visiblePositionBeforeNode(Node* node) | 507 VisiblePosition visiblePositionBeforeNode(Node* node) |
507 { | 508 { |
508 ASSERT(node); | 509 ASSERT(node); |
509 if (node->childNodeCount()) | 510 if (node->childNodeCount()) |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 if (!node || !node->hasTagName(blockquoteTag)) | 972 if (!node || !node->hasTagName(blockquoteTag)) |
972 return false; | 973 return false; |
973 | 974 |
974 return toElement(node)->getAttribute("type") == "cite"; | 975 return toElement(node)->getAttribute("type") == "cite"; |
975 } | 976 } |
976 | 977 |
977 int caretMinOffset(const Node* n) | 978 int caretMinOffset(const Node* n) |
978 { | 979 { |
979 RenderObject* r = n->renderer(); | 980 RenderObject* r = n->renderer(); |
980 ASSERT(!n->isCharacterDataNode() || !r || r->isText()); // FIXME: This was a
runtime check that seemingly couldn't fail; changed it to an assertion for now. | 981 ASSERT(!n->isCharacterDataNode() || !r || r->isText()); // FIXME: This was a
runtime check that seemingly couldn't fail; changed it to an assertion for now. |
981 return r ? r->caretMinOffset() : 0; | 982 if (!r) |
| 983 return 0; |
| 984 if (r->isText()) |
| 985 return r->caretMinOffset() + toRenderText(r)->textStartOffset(); |
| 986 return r->caretMinOffset(); |
982 } | 987 } |
983 | 988 |
984 // If a node can contain candidates for VisiblePositions, return the offset of t
he last candidate, otherwise | 989 // If a node can contain candidates for VisiblePositions, return the offset of t
he last candidate, otherwise |
985 // return the number of children for container nodes and the length for unrender
ed text nodes. | 990 // return the number of children for container nodes and the length for unrender
ed text nodes. |
986 int caretMaxOffset(const Node* n) | 991 int caretMaxOffset(const Node* n) |
987 { | 992 { |
988 // For rendered text nodes, return the last position that a caret could occu
py. | 993 // For rendered text nodes, return the last position that a caret could occu
py. |
989 if (n->isTextNode() && n->renderer()) | 994 RenderObject* renderer = n->renderer(); |
990 return n->renderer()->caretMaxOffset(); | 995 if (renderer && renderer->isText()) |
| 996 return renderer->caretMaxOffset() + toRenderText(renderer)->textStartOff
set(); |
991 // For containers return the number of children. For others do the same as a
bove. | 997 // For containers return the number of children. For others do the same as a
bove. |
992 return lastOffsetForEditing(n); | 998 return lastOffsetForEditing(n); |
993 } | 999 } |
994 | 1000 |
995 bool lineBreakExistsAtVisiblePosition(const VisiblePosition& visiblePosition) | 1001 bool lineBreakExistsAtVisiblePosition(const VisiblePosition& visiblePosition) |
996 { | 1002 { |
997 return lineBreakExistsAtPosition(visiblePosition.deepEquivalent().downstream
()); | 1003 return lineBreakExistsAtPosition(visiblePosition.deepEquivalent().downstream
()); |
998 } | 1004 } |
999 | 1005 |
1000 bool lineBreakExistsAtPosition(const Position& position) | 1006 bool lineBreakExistsAtPosition(const Position& position) |
1001 { | 1007 { |
1002 if (position.isNull()) | 1008 if (position.isNull()) |
1003 return false; | 1009 return false; |
1004 | 1010 |
1005 if (position.anchorNode()->hasTagName(brTag) && position.atFirstEditingPosit
ionForNode()) | 1011 if (position.anchorNode()->hasTagName(brTag) && position.atFirstEditingPosit
ionForNode()) |
1006 return true; | 1012 return true; |
1007 | 1013 |
1008 if (!position.anchorNode()->renderer()) | 1014 if (!position.renderer()) |
1009 return false; | 1015 return false; |
1010 | 1016 |
1011 if (!position.anchorNode()->isTextNode() || !position.anchorNode()->renderer
()->style()->preserveNewline()) | 1017 if (!position.anchorNode()->isTextNode() || !position.renderer()->style()->p
reserveNewline()) |
1012 return false; | 1018 return false; |
1013 | 1019 |
1014 Text* textNode = toText(position.anchorNode()); | 1020 Text* textNode = toText(position.anchorNode()); |
1015 unsigned offset = position.offsetInContainerNode(); | 1021 unsigned offset = position.offsetInContainerNode(); |
1016 return offset < textNode->length() && textNode->data()[offset] == '\n'; | 1022 return offset < textNode->length() && textNode->data()[offset] == '\n'; |
1017 } | 1023 } |
1018 | 1024 |
1019 // Modifies selections that have an end point at the edge of a table | 1025 // Modifies selections that have an end point at the edge of a table |
1020 // that contains the other endpoint so that they don't confuse | 1026 // that contains the other endpoint so that they don't confuse |
1021 // code that iterates over selected paragraphs. | 1027 // code that iterates over selected paragraphs. |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 // if the selection starts just before a paragraph break, skip over it | 1168 // if the selection starts just before a paragraph break, skip over it |
1163 if (isEndOfParagraph(visiblePosition)) | 1169 if (isEndOfParagraph(visiblePosition)) |
1164 return visiblePosition.next().deepEquivalent().downstream(); | 1170 return visiblePosition.next().deepEquivalent().downstream(); |
1165 | 1171 |
1166 // otherwise, make sure to be at the start of the first selected node, | 1172 // otherwise, make sure to be at the start of the first selected node, |
1167 // instead of possibly at the end of the last node before the selection | 1173 // instead of possibly at the end of the last node before the selection |
1168 return visiblePosition.deepEquivalent().downstream(); | 1174 return visiblePosition.deepEquivalent().downstream(); |
1169 } | 1175 } |
1170 | 1176 |
1171 } // namespace WebCore | 1177 } // namespace WebCore |
OLD | NEW |