| OLD | NEW |
| 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 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 VisiblePosition previousLinePosition(const VisiblePosition &visiblePosition, Lay
outUnit lineDirectionPoint, EditableType editableType) | 917 VisiblePosition previousLinePosition(const VisiblePosition &visiblePosition, Lay
outUnit lineDirectionPoint, EditableType editableType) |
| 918 { | 918 { |
| 919 Position p = visiblePosition.deepEquivalent(); | 919 Position p = visiblePosition.deepEquivalent(); |
| 920 Node* node = p.deprecatedNode(); | 920 Node* node = p.deprecatedNode(); |
| 921 | 921 |
| 922 if (!node) | 922 if (!node) |
| 923 return VisiblePosition(); | 923 return VisiblePosition(); |
| 924 | 924 |
| 925 node->document().updateLayoutIgnorePendingStylesheets(); | 925 node->document().updateLayoutIgnorePendingStylesheets(); |
| 926 | 926 |
| 927 LayoutObject* renderer = node->layoutObject(); | 927 LayoutObject* layoutObject = node->layoutObject(); |
| 928 if (!renderer) | 928 if (!layoutObject) |
| 929 return VisiblePosition(); | 929 return VisiblePosition(); |
| 930 | 930 |
| 931 RootInlineBox* root = 0; | 931 RootInlineBox* root = 0; |
| 932 InlineBox* box; | 932 InlineBox* box; |
| 933 int ignoredCaretOffset; | 933 int ignoredCaretOffset; |
| 934 visiblePosition.getInlineBoxAndOffset(box, ignoredCaretOffset); | 934 visiblePosition.getInlineBoxAndOffset(box, ignoredCaretOffset); |
| 935 if (box) { | 935 if (box) { |
| 936 root = box->root().prevRootBox(); | 936 root = box->root().prevRootBox(); |
| 937 // We want to skip zero height boxes. | 937 // We want to skip zero height boxes. |
| 938 // This could happen in case it is a TrailingFloatsRootInlineBox. | 938 // This could happen in case it is a TrailingFloatsRootInlineBox. |
| 939 if (!root || !root->logicalHeight() || !root->firstLeafChild()) | 939 if (!root || !root->logicalHeight() || !root->firstLeafChild()) |
| 940 root = 0; | 940 root = 0; |
| 941 } | 941 } |
| 942 | 942 |
| 943 if (!root) { | 943 if (!root) { |
| 944 Position position = previousRootInlineBoxCandidatePosition(node, visible
Position, editableType); | 944 Position position = previousRootInlineBoxCandidatePosition(node, visible
Position, editableType); |
| 945 if (position.isNotNull()) { | 945 if (position.isNotNull()) { |
| 946 RenderedPosition renderedPosition((VisiblePosition(position))); | 946 RenderedPosition renderedPosition((VisiblePosition(position))); |
| 947 root = renderedPosition.rootBox(); | 947 root = renderedPosition.rootBox(); |
| 948 if (!root) | 948 if (!root) |
| 949 return VisiblePosition(position); | 949 return VisiblePosition(position); |
| 950 } | 950 } |
| 951 } | 951 } |
| 952 | 952 |
| 953 if (root) { | 953 if (root) { |
| 954 // FIXME: Can be wrong for multi-column layout and with transforms. | 954 // FIXME: Can be wrong for multi-column layout and with transforms. |
| 955 LayoutPoint pointInLine = absoluteLineDirectionPointToLocalPointInBlock(
root, lineDirectionPoint); | 955 LayoutPoint pointInLine = absoluteLineDirectionPointToLocalPointInBlock(
root, lineDirectionPoint); |
| 956 LayoutObject& renderer = root->closestLeafChildForPoint(pointInLine, isE
ditablePosition(p))->layoutObject(); | 956 LayoutObject& layoutObject = root->closestLeafChildForPoint(pointInLine,
isEditablePosition(p))->layoutObject(); |
| 957 Node* node = renderer.node(); | 957 Node* node = layoutObject.node(); |
| 958 if (node && editingIgnoresContent(node)) | 958 if (node && editingIgnoresContent(node)) |
| 959 return VisiblePosition(positionInParentBeforeNode(*node)); | 959 return VisiblePosition(positionInParentBeforeNode(*node)); |
| 960 return VisiblePosition(renderer.positionForPoint(pointInLine)); | 960 return VisiblePosition(layoutObject.positionForPoint(pointInLine)); |
| 961 } | 961 } |
| 962 | 962 |
| 963 // Could not find a previous line. This means we must already be on the firs
t line. | 963 // Could not find a previous line. This means we must already be on the firs
t line. |
| 964 // Move to the start of the content in this block, which effectively moves u
s | 964 // Move to the start of the content in this block, which effectively moves u
s |
| 965 // to the start of the line we're on. | 965 // to the start of the line we're on. |
| 966 Element* rootElement = node->hasEditableStyle(editableType) ? node->rootEdit
ableElement(editableType) : node->document().documentElement(); | 966 Element* rootElement = node->hasEditableStyle(editableType) ? node->rootEdit
ableElement(editableType) : node->document().documentElement(); |
| 967 if (!rootElement) | 967 if (!rootElement) |
| 968 return VisiblePosition(); | 968 return VisiblePosition(); |
| 969 return VisiblePosition(firstPositionInNode(rootElement), DOWNSTREAM); | 969 return VisiblePosition(firstPositionInNode(rootElement), DOWNSTREAM); |
| 970 } | 970 } |
| 971 | 971 |
| 972 VisiblePosition nextLinePosition(const VisiblePosition &visiblePosition, LayoutU
nit lineDirectionPoint, EditableType editableType) | 972 VisiblePosition nextLinePosition(const VisiblePosition &visiblePosition, LayoutU
nit lineDirectionPoint, EditableType editableType) |
| 973 { | 973 { |
| 974 Position p = visiblePosition.deepEquivalent(); | 974 Position p = visiblePosition.deepEquivalent(); |
| 975 Node* node = p.deprecatedNode(); | 975 Node* node = p.deprecatedNode(); |
| 976 | 976 |
| 977 if (!node) | 977 if (!node) |
| 978 return VisiblePosition(); | 978 return VisiblePosition(); |
| 979 | 979 |
| 980 node->document().updateLayoutIgnorePendingStylesheets(); | 980 node->document().updateLayoutIgnorePendingStylesheets(); |
| 981 | 981 |
| 982 LayoutObject* renderer = node->layoutObject(); | 982 LayoutObject* layoutObject = node->layoutObject(); |
| 983 if (!renderer) | 983 if (!layoutObject) |
| 984 return VisiblePosition(); | 984 return VisiblePosition(); |
| 985 | 985 |
| 986 RootInlineBox* root = 0; | 986 RootInlineBox* root = 0; |
| 987 InlineBox* box; | 987 InlineBox* box; |
| 988 int ignoredCaretOffset; | 988 int ignoredCaretOffset; |
| 989 visiblePosition.getInlineBoxAndOffset(box, ignoredCaretOffset); | 989 visiblePosition.getInlineBoxAndOffset(box, ignoredCaretOffset); |
| 990 if (box) { | 990 if (box) { |
| 991 root = box->root().nextRootBox(); | 991 root = box->root().nextRootBox(); |
| 992 // We want to skip zero height boxes. | 992 // We want to skip zero height boxes. |
| 993 // This could happen in case it is a TrailingFloatsRootInlineBox. | 993 // This could happen in case it is a TrailingFloatsRootInlineBox. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1004 RenderedPosition renderedPosition((VisiblePosition(position))); | 1004 RenderedPosition renderedPosition((VisiblePosition(position))); |
| 1005 root = renderedPosition.rootBox(); | 1005 root = renderedPosition.rootBox(); |
| 1006 if (!root) | 1006 if (!root) |
| 1007 return VisiblePosition(position); | 1007 return VisiblePosition(position); |
| 1008 } | 1008 } |
| 1009 } | 1009 } |
| 1010 | 1010 |
| 1011 if (root) { | 1011 if (root) { |
| 1012 // FIXME: Can be wrong for multi-column layout and with transforms. | 1012 // FIXME: Can be wrong for multi-column layout and with transforms. |
| 1013 LayoutPoint pointInLine = absoluteLineDirectionPointToLocalPointInBlock(
root, lineDirectionPoint); | 1013 LayoutPoint pointInLine = absoluteLineDirectionPointToLocalPointInBlock(
root, lineDirectionPoint); |
| 1014 LayoutObject& renderer = root->closestLeafChildForPoint(pointInLine, isE
ditablePosition(p))->layoutObject(); | 1014 LayoutObject& layoutObject = root->closestLeafChildForPoint(pointInLine,
isEditablePosition(p))->layoutObject(); |
| 1015 Node* node = renderer.node(); | 1015 Node* node = layoutObject.node(); |
| 1016 if (node && editingIgnoresContent(node)) | 1016 if (node && editingIgnoresContent(node)) |
| 1017 return VisiblePosition(positionInParentBeforeNode(*node)); | 1017 return VisiblePosition(positionInParentBeforeNode(*node)); |
| 1018 return VisiblePosition(renderer.positionForPoint(pointInLine)); | 1018 return VisiblePosition(layoutObject.positionForPoint(pointInLine)); |
| 1019 } | 1019 } |
| 1020 | 1020 |
| 1021 // Could not find a next line. This means we must already be on the last lin
e. | 1021 // Could not find a next line. This means we must already be on the last lin
e. |
| 1022 // Move to the end of the content in this block, which effectively moves us | 1022 // Move to the end of the content in this block, which effectively moves us |
| 1023 // to the end of the line we're on. | 1023 // to the end of the line we're on. |
| 1024 Element* rootElement = node->hasEditableStyle(editableType) ? node->rootEdit
ableElement(editableType) : node->document().documentElement(); | 1024 Element* rootElement = node->hasEditableStyle(editableType) ? node->rootEdit
ableElement(editableType) : node->document().documentElement(); |
| 1025 if (!rootElement) | 1025 if (!rootElement) |
| 1026 return VisiblePosition(); | 1026 return VisiblePosition(); |
| 1027 return VisiblePosition(lastPositionInNode(rootElement), DOWNSTREAM); | 1027 return VisiblePosition(lastPositionInNode(rootElement), DOWNSTREAM); |
| 1028 } | 1028 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 } | 1196 } |
| 1197 const ComputedStyle& style = r->styleRef(); | 1197 const ComputedStyle& style = r->styleRef(); |
| 1198 if (style.visibility() != VISIBLE) { | 1198 if (style.visibility() != VISIBLE) { |
| 1199 n = NodeTraversal::next(*n, stayInsideBlock); | 1199 n = NodeTraversal::next(*n, stayInsideBlock); |
| 1200 continue; | 1200 continue; |
| 1201 } | 1201 } |
| 1202 | 1202 |
| 1203 if (r->isBR() || isBlock(n)) | 1203 if (r->isBR() || isBlock(n)) |
| 1204 break; | 1204 break; |
| 1205 | 1205 |
| 1206 // FIXME: We avoid returning a position where the renderer can't accept
the caret. | 1206 // FIXME: We avoid returning a position where the layoutObject can't acc
ept the caret. |
| 1207 if (r->isText() && toLayoutText(r)->resolvedTextLength()) { | 1207 if (r->isText() && toLayoutText(r)->resolvedTextLength()) { |
| 1208 ASSERT_WITH_SECURITY_IMPLICATION(n->isTextNode()); | 1208 ASSERT_WITH_SECURITY_IMPLICATION(n->isTextNode()); |
| 1209 int length = toLayoutText(r)->textLength(); | 1209 int length = toLayoutText(r)->textLength(); |
| 1210 type = Position::PositionIsOffsetInAnchor; | 1210 type = Position::PositionIsOffsetInAnchor; |
| 1211 if (style.preserveNewline()) { | 1211 if (style.preserveNewline()) { |
| 1212 LayoutText* text = toLayoutText(r); | 1212 LayoutText* text = toLayoutText(r); |
| 1213 int o = n == startNode ? offset : 0; | 1213 int o = n == startNode ? offset : 0; |
| 1214 for (int i = o; i < length; ++i) { | 1214 for (int i = o; i < length; ++i) { |
| 1215 if ((*text)[i] == '\n') | 1215 if ((*text)[i] == '\n') |
| 1216 return VisiblePosition(Position(toText(n), i), DOWNSTREA
M); | 1216 return VisiblePosition(Position(toText(n), i), DOWNSTREA
M); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1383 VisiblePosition leftBoundaryOfLine(const VisiblePosition& c, TextDirection direc
tion) | 1383 VisiblePosition leftBoundaryOfLine(const VisiblePosition& c, TextDirection direc
tion) |
| 1384 { | 1384 { |
| 1385 return direction == LTR ? logicalStartOfLine(c) : logicalEndOfLine(c); | 1385 return direction == LTR ? logicalStartOfLine(c) : logicalEndOfLine(c); |
| 1386 } | 1386 } |
| 1387 | 1387 |
| 1388 VisiblePosition rightBoundaryOfLine(const VisiblePosition& c, TextDirection dire
ction) | 1388 VisiblePosition rightBoundaryOfLine(const VisiblePosition& c, TextDirection dire
ction) |
| 1389 { | 1389 { |
| 1390 return direction == LTR ? logicalEndOfLine(c) : logicalStartOfLine(c); | 1390 return direction == LTR ? logicalEndOfLine(c) : logicalStartOfLine(c); |
| 1391 } | 1391 } |
| 1392 | 1392 |
| 1393 LayoutRect localCaretRectOfPosition(const PositionWithAffinity& position, Layout
Object*& renderer) | 1393 LayoutRect localCaretRectOfPosition(const PositionWithAffinity& position, Layout
Object*& layoutObject) |
| 1394 { | 1394 { |
| 1395 if (position.position().isNull()) { | 1395 if (position.position().isNull()) { |
| 1396 renderer = nullptr; | 1396 layoutObject = nullptr; |
| 1397 return LayoutRect(); | 1397 return LayoutRect(); |
| 1398 } | 1398 } |
| 1399 Node* node = position.position().anchorNode(); | 1399 Node* node = position.position().anchorNode(); |
| 1400 | 1400 |
| 1401 renderer = node->layoutObject(); | 1401 layoutObject = node->layoutObject(); |
| 1402 if (!renderer) | 1402 if (!layoutObject) |
| 1403 return LayoutRect(); | 1403 return LayoutRect(); |
| 1404 | 1404 |
| 1405 InlineBox* inlineBox; | 1405 InlineBox* inlineBox; |
| 1406 int caretOffset; | 1406 int caretOffset; |
| 1407 position.position().getInlineBoxAndOffset(position.affinity(), inlineBox, ca
retOffset); | 1407 position.position().getInlineBoxAndOffset(position.affinity(), inlineBox, ca
retOffset); |
| 1408 | 1408 |
| 1409 if (inlineBox) | 1409 if (inlineBox) |
| 1410 renderer = &inlineBox->layoutObject(); | 1410 layoutObject = &inlineBox->layoutObject(); |
| 1411 | 1411 |
| 1412 return renderer->localCaretRect(inlineBox, caretOffset); | 1412 return layoutObject->localCaretRect(inlineBox, caretOffset); |
| 1413 } | 1413 } |
| 1414 | 1414 |
| 1415 } | 1415 } |
| OLD | NEW |