| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2009 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } | 197 } |
| 198 | 198 |
| 199 template <typename Strategy> | 199 template <typename Strategy> |
| 200 int PositionAlgorithm<Strategy>::computeEditingOffset() const | 200 int PositionAlgorithm<Strategy>::computeEditingOffset() const |
| 201 { | 201 { |
| 202 if (isAfterAnchorOrAfterChildren()) | 202 if (isAfterAnchorOrAfterChildren()) |
| 203 return Strategy::lastOffsetForEditing(m_anchorNode.get()); | 203 return Strategy::lastOffsetForEditing(m_anchorNode.get()); |
| 204 return m_offset; | 204 return m_offset; |
| 205 } | 205 } |
| 206 | 206 |
| 207 // TODO(yosin) We should replace all usage of |deprecatedEditingOffset()| by | |
| 208 // |computeEditingOffset()|. | |
| 209 template <typename Strategy> | |
| 210 int PositionAlgorithm<Strategy>::deprecatedEditingOffset() const | |
| 211 { | |
| 212 return computeEditingOffset(); | |
| 213 } | |
| 214 | |
| 215 template <typename Strategy> | 207 template <typename Strategy> |
| 216 Node* PositionAlgorithm<Strategy>::computeNodeBeforePosition() const | 208 Node* PositionAlgorithm<Strategy>::computeNodeBeforePosition() const |
| 217 { | 209 { |
| 218 if (!m_anchorNode) | 210 if (!m_anchorNode) |
| 219 return 0; | 211 return 0; |
| 220 switch (anchorType()) { | 212 switch (anchorType()) { |
| 221 case PositionAnchorType::BeforeChildren: | 213 case PositionAnchorType::BeforeChildren: |
| 222 return 0; | 214 return 0; |
| 223 case PositionAnchorType::AfterChildren: | 215 case PositionAnchorType::AfterChildren: |
| 224 return Strategy::lastChild(*m_anchorNode); | 216 return Strategy::lastChild(*m_anchorNode); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 return comparePositions(*this, other); | 313 return comparePositions(*this, other); |
| 322 } | 314 } |
| 323 | 315 |
| 324 template <typename Strategy> | 316 template <typename Strategy> |
| 325 PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::previous(PositionMoveTy
pe moveType) const | 317 PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::previous(PositionMoveTy
pe moveType) const |
| 326 { | 318 { |
| 327 Node* node = anchorNode(); | 319 Node* node = anchorNode(); |
| 328 if (!node) | 320 if (!node) |
| 329 return PositionAlgorithm<Strategy>(*this); | 321 return PositionAlgorithm<Strategy>(*this); |
| 330 | 322 |
| 331 int offset = deprecatedEditingOffset(); | 323 int offset = computeEditingOffset(); |
| 332 | 324 |
| 333 if (offset > 0) { | 325 if (offset > 0) { |
| 334 if (editingIgnoresContent(node)) | 326 if (editingIgnoresContent(node)) |
| 335 return beforeNode(node); | 327 return beforeNode(node); |
| 336 if (Node* child = Strategy::childAt(*node, offset - 1)) | 328 if (Node* child = Strategy::childAt(*node, offset - 1)) |
| 337 return lastPositionInOrAfterNode(child); | 329 return lastPositionInOrAfterNode(child); |
| 338 | 330 |
| 339 // There are two reasons child might be 0: | 331 // There are two reasons child might be 0: |
| 340 // 1) The node is node like a text node that is not an element, and th
erefore has no children. | 332 // 1) The node is node like a text node that is not an element, and th
erefore has no children. |
| 341 // Going backward one character at a time is correct. | 333 // Going backward one character at a time is correct. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 363 | 355 |
| 364 template <typename Strategy> | 356 template <typename Strategy> |
| 365 PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::next(PositionMoveType m
oveType) const | 357 PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::next(PositionMoveType m
oveType) const |
| 366 { | 358 { |
| 367 ASSERT(moveType != BackwardDeletion); | 359 ASSERT(moveType != BackwardDeletion); |
| 368 | 360 |
| 369 Node* node = anchorNode(); | 361 Node* node = anchorNode(); |
| 370 if (!node) | 362 if (!node) |
| 371 return PositionAlgorithm<Strategy>(*this); | 363 return PositionAlgorithm<Strategy>(*this); |
| 372 | 364 |
| 373 int offset = deprecatedEditingOffset(); | 365 int offset = computeEditingOffset(); |
| 374 | 366 |
| 375 if (Node* child = Strategy::childAt(*node, offset)) | 367 if (Node* child = Strategy::childAt(*node, offset)) |
| 376 return firstPositionInOrBeforeNode(child); | 368 return firstPositionInOrBeforeNode(child); |
| 377 | 369 |
| 378 // TODO(yosin) We should use |Strategy::lastOffsetForEditing()| instead of | 370 // TODO(yosin) We should use |Strategy::lastOffsetForEditing()| instead of |
| 379 // DOM tree version. | 371 // DOM tree version. |
| 380 if (!Strategy::hasChildren(*node) && offset < EditingStrategy::lastOffsetFor
Editing(node)) { | 372 if (!Strategy::hasChildren(*node) && offset < EditingStrategy::lastOffsetFor
Editing(node)) { |
| 381 // There are two reasons child might be 0: | 373 // There are two reasons child might be 0: |
| 382 // 1) The node is node like a text node that is not an element, and th
erefore has no children. | 374 // 1) The node is node like a text node that is not an element, and th
erefore has no children. |
| 383 // Going forward one character at a time is correct. | 375 // Going forward one character at a time is correct. |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 lastPosition = position; | 1008 lastPosition = position; |
| 1017 position = position.upstream(CanCrossEditingBoundary); | 1009 position = position.upstream(CanCrossEditingBoundary); |
| 1018 } | 1010 } |
| 1019 return position; | 1011 return position; |
| 1020 } | 1012 } |
| 1021 | 1013 |
| 1022 template <typename Strategy> | 1014 template <typename Strategy> |
| 1023 InlineBoxPosition PositionAlgorithm<Strategy>::computeInlineBoxPosition(EAffinit
y affinity, TextDirection primaryDirection) const | 1015 InlineBoxPosition PositionAlgorithm<Strategy>::computeInlineBoxPosition(EAffinit
y affinity, TextDirection primaryDirection) const |
| 1024 { | 1016 { |
| 1025 InlineBox* inlineBox = nullptr; | 1017 InlineBox* inlineBox = nullptr; |
| 1026 int caretOffset = deprecatedEditingOffset(); | 1018 int caretOffset = computeEditingOffset(); |
| 1027 LayoutObject* layoutObject = m_anchorNode->isShadowRoot() ? toShadowRoot(m_a
nchorNode)->host()->layoutObject() : m_anchorNode->layoutObject(); | 1019 LayoutObject* layoutObject = m_anchorNode->isShadowRoot() ? toShadowRoot(m_a
nchorNode)->host()->layoutObject() : m_anchorNode->layoutObject(); |
| 1028 | 1020 |
| 1029 if (!layoutObject->isText()) { | 1021 if (!layoutObject->isText()) { |
| 1030 inlineBox = 0; | 1022 inlineBox = 0; |
| 1031 if (canHaveChildrenForEditing(anchorNode()) && layoutObject->isLayoutBlo
ckFlow() && hasRenderedNonAnonymousDescendantsWithHeight(layoutObject)) { | 1023 if (canHaveChildrenForEditing(anchorNode()) && layoutObject->isLayoutBlo
ckFlow() && hasRenderedNonAnonymousDescendantsWithHeight(layoutObject)) { |
| 1032 // Try a visually equivalent position with possibly opposite | 1024 // Try a visually equivalent position with possibly opposite |
| 1033 // editability. This helps in case |this| is in an editable block | 1025 // editability. This helps in case |this| is in an editable block |
| 1034 // but surrounded by non-editable positions. It acts to negate the | 1026 // but surrounded by non-editable positions. It acts to negate the |
| 1035 // logic at the beginning of LayoutObject::createVisiblePosition(). | 1027 // logic at the beginning of LayoutObject::createVisiblePosition(). |
| 1036 PositionAlgorithm<Strategy> thisPosition = PositionAlgorithm<Strateg
y>(*this); | 1028 PositionAlgorithm<Strategy> thisPosition = PositionAlgorithm<Strateg
y>(*this); |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 | 1353 |
| 1362 void showTree(const blink::Position* pos) | 1354 void showTree(const blink::Position* pos) |
| 1363 { | 1355 { |
| 1364 if (pos) | 1356 if (pos) |
| 1365 pos->showTreeForThis(); | 1357 pos->showTreeForThis(); |
| 1366 else | 1358 else |
| 1367 fprintf(stderr, "Cannot showTree for (nil)\n"); | 1359 fprintf(stderr, "Cannot showTree for (nil)\n"); |
| 1368 } | 1360 } |
| 1369 | 1361 |
| 1370 #endif | 1362 #endif |
| OLD | NEW |