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