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 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 // The space must not be in another paragraph and it must be editable. | 957 // The space must not be in another paragraph and it must be editable. |
958 if (isSpace && !isEndOfParagraph(visiblePosition) && visiblePosition.next(Ca
nnotCrossEditingBoundary).isNotNull()) | 958 if (isSpace && !isEndOfParagraph(visiblePosition) && visiblePosition.next(Ca
nnotCrossEditingBoundary).isNotNull()) |
959 return position; | 959 return position; |
960 return Position(); | 960 return Position(); |
961 } | 961 } |
962 | 962 |
963 unsigned numEnclosingMailBlockquotes(const Position& p) | 963 unsigned numEnclosingMailBlockquotes(const Position& p) |
964 { | 964 { |
965 unsigned num = 0; | 965 unsigned num = 0; |
966 for (Node* n = p.deprecatedNode(); n; n = n->parentNode()) | 966 for (Node* n = p.deprecatedNode(); n; n = n->parentNode()) |
967 if (isMailBlockquote(n)) | 967 if (isMailHTMLBlockquoteElement(n)) |
968 num++; | 968 num++; |
969 | 969 |
970 return num; | 970 return num; |
971 } | 971 } |
972 | 972 |
973 void updatePositionForNodeRemoval(Position& position, Node& node) | 973 void updatePositionForNodeRemoval(Position& position, Node& node) |
974 { | 974 { |
975 if (position.isNull()) | 975 if (position.isNull()) |
976 return; | 976 return; |
977 switch (position.anchorType()) { | 977 switch (position.anchorType()) { |
(...skipping 15 matching lines...) Expand all Loading... |
993 if (node.containsIncludingShadowDOM(position.anchorNode())) | 993 if (node.containsIncludingShadowDOM(position.anchorNode())) |
994 position = positionInParentAfterNode(node); | 994 position = positionInParentAfterNode(node); |
995 break; | 995 break; |
996 case Position::PositionIsBeforeAnchor: | 996 case Position::PositionIsBeforeAnchor: |
997 if (node.containsIncludingShadowDOM(position.anchorNode())) | 997 if (node.containsIncludingShadowDOM(position.anchorNode())) |
998 position = positionInParentBeforeNode(node); | 998 position = positionInParentBeforeNode(node); |
999 break; | 999 break; |
1000 } | 1000 } |
1001 } | 1001 } |
1002 | 1002 |
1003 bool isMailBlockquote(const Node *node) | 1003 bool isMailHTMLBlockquoteElement(const Node* node) |
1004 { | 1004 { |
1005 if (!node || !node->hasTagName(blockquoteTag)) | 1005 if (!node || !node->isHTMLElement()) |
1006 return false; | 1006 return false; |
1007 | 1007 |
1008 return toElement(node)->getAttribute("type") == "cite"; | 1008 const HTMLElement& element = toHTMLElement(*node); |
| 1009 return element.hasTagName(blockquoteTag) && element.getAttribute("type") ==
"cite"; |
1009 } | 1010 } |
1010 | 1011 |
1011 int caretMinOffset(const Node* n) | 1012 int caretMinOffset(const Node* n) |
1012 { | 1013 { |
1013 RenderObject* r = n->renderer(); | 1014 RenderObject* r = n->renderer(); |
1014 ASSERT(!n->isCharacterDataNode() || !r || r->isText()); // FIXME: This was a
runtime check that seemingly couldn't fail; changed it to an assertion for now. | 1015 ASSERT(!n->isCharacterDataNode() || !r || r->isText()); // FIXME: This was a
runtime check that seemingly couldn't fail; changed it to an assertion for now. |
1015 return r ? r->caretMinOffset() : 0; | 1016 return r ? r->caretMinOffset() : 0; |
1016 } | 1017 } |
1017 | 1018 |
1018 // If a node can contain candidates for VisiblePositions, return the offset of t
he last candidate, otherwise | 1019 // If a node can contain candidates for VisiblePositions, return the offset of t
he last candidate, otherwise |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 const Element* firstElement = toElement(first); | 1158 const Element* firstElement = toElement(first); |
1158 const Element* secondElement = toElement(second); | 1159 const Element* secondElement = toElement(second); |
1159 if (!firstElement->hasTagName(secondElement->tagQName())) | 1160 if (!firstElement->hasTagName(secondElement->tagQName())) |
1160 return false; | 1161 return false; |
1161 | 1162 |
1162 return firstElement->hasEquivalentAttributes(secondElement); | 1163 return firstElement->hasEquivalentAttributes(secondElement); |
1163 } | 1164 } |
1164 | 1165 |
1165 bool isNonTableCellHTMLBlockElement(const Node* node) | 1166 bool isNonTableCellHTMLBlockElement(const Node* node) |
1166 { | 1167 { |
1167 return node->hasTagName(listingTag) | 1168 if (!node->isHTMLElement()) |
1168 || node->hasTagName(olTag) | 1169 return false; |
1169 || node->hasTagName(preTag) | 1170 |
1170 || node->hasTagName(tableTag) | 1171 const HTMLElement& element = toHTMLElement(*node); |
1171 || node->hasTagName(ulTag) | 1172 return element.hasTagName(listingTag) |
1172 || node->hasTagName(xmpTag) | 1173 || element.hasTagName(olTag) |
1173 || node->hasTagName(h1Tag) | 1174 || element.hasTagName(preTag) |
1174 || node->hasTagName(h2Tag) | 1175 || element.hasTagName(tableTag) |
1175 || node->hasTagName(h3Tag) | 1176 || element.hasTagName(ulTag) |
1176 || node->hasTagName(h4Tag) | 1177 || element.hasTagName(xmpTag) |
1177 || node->hasTagName(h5Tag); | 1178 || element.hasTagName(h1Tag) |
| 1179 || element.hasTagName(h2Tag) |
| 1180 || element.hasTagName(h3Tag) |
| 1181 || element.hasTagName(h4Tag) |
| 1182 || element.hasTagName(h5Tag); |
1178 } | 1183 } |
1179 | 1184 |
1180 Position adjustedSelectionStartForStyleComputation(const VisibleSelection& selec
tion) | 1185 Position adjustedSelectionStartForStyleComputation(const VisibleSelection& selec
tion) |
1181 { | 1186 { |
1182 // This function is used by range style computations to avoid bugs like: | 1187 // This function is used by range style computations to avoid bugs like: |
1183 // <rdar://problem/4017641> REGRESSION (Mail): you can only bold/unbold a se
lection starting from end of line once | 1188 // <rdar://problem/4017641> REGRESSION (Mail): you can only bold/unbold a se
lection starting from end of line once |
1184 // It is important to skip certain irrelevant content at the start of the se
lection, so we do not wind up | 1189 // It is important to skip certain irrelevant content at the start of the se
lection, so we do not wind up |
1185 // with a spurious "mixed" style. | 1190 // with a spurious "mixed" style. |
1186 | 1191 |
1187 VisiblePosition visiblePosition(selection.start()); | 1192 VisiblePosition visiblePosition(selection.start()); |
1188 if (visiblePosition.isNull()) | 1193 if (visiblePosition.isNull()) |
1189 return Position(); | 1194 return Position(); |
1190 | 1195 |
1191 // if the selection is a caret, just return the position, since the style | 1196 // if the selection is a caret, just return the position, since the style |
1192 // behind us is relevant | 1197 // behind us is relevant |
1193 if (selection.isCaret()) | 1198 if (selection.isCaret()) |
1194 return visiblePosition.deepEquivalent(); | 1199 return visiblePosition.deepEquivalent(); |
1195 | 1200 |
1196 // if the selection starts just before a paragraph break, skip over it | 1201 // if the selection starts just before a paragraph break, skip over it |
1197 if (isEndOfParagraph(visiblePosition)) | 1202 if (isEndOfParagraph(visiblePosition)) |
1198 return visiblePosition.next().deepEquivalent().downstream(); | 1203 return visiblePosition.next().deepEquivalent().downstream(); |
1199 | 1204 |
1200 // otherwise, make sure to be at the start of the first selected node, | 1205 // otherwise, make sure to be at the start of the first selected node, |
1201 // instead of possibly at the end of the last node before the selection | 1206 // instead of possibly at the end of the last node before the selection |
1202 return visiblePosition.deepEquivalent().downstream(); | 1207 return visiblePosition.deepEquivalent().downstream(); |
1203 } | 1208 } |
1204 | 1209 |
1205 } // namespace blink | 1210 } // namespace blink |
OLD | NEW |