Chromium Code Reviews| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 #include "wtf/text/CString.h" | 48 #include "wtf/text/CString.h" |
| 49 #include "wtf/unicode/CharacterNames.h" | 49 #include "wtf/unicode/CharacterNames.h" |
| 50 | 50 |
| 51 namespace WebCore { | 51 namespace WebCore { |
| 52 | 52 |
| 53 using namespace HTMLNames; | 53 using namespace HTMLNames; |
| 54 | 54 |
| 55 static Node* nextRenderedEditable(Node* node) | 55 static Node* nextRenderedEditable(Node* node) |
| 56 { | 56 { |
| 57 while ((node = node->nextLeafNode())) { | 57 while ((node = node->nextLeafNode())) { |
| 58 if (!node->rendererIsEditable()) | |
| 59 continue; | |
| 60 RenderObject* renderer = node->renderer(); | 58 RenderObject* renderer = node->renderer(); |
| 61 if (!renderer) | 59 if (!renderer) |
| 62 continue; | 60 continue; |
| 61 if (!node->rendererIsEditable()) | |
| 62 continue; | |
| 63 if ((renderer->isBox() && toRenderBox(renderer)->inlineBoxWrapper()) || (renderer->isText() && toRenderText(renderer)->firstTextBox())) | 63 if ((renderer->isBox() && toRenderBox(renderer)->inlineBoxWrapper()) || (renderer->isText() && toRenderText(renderer)->firstTextBox())) |
| 64 return node; | 64 return node; |
| 65 } | 65 } |
| 66 return 0; | 66 return 0; |
| 67 } | 67 } |
| 68 | 68 |
| 69 static Node* previousRenderedEditable(Node* node) | 69 static Node* previousRenderedEditable(Node* node) |
| 70 { | 70 { |
| 71 while ((node = node->previousLeafNode())) { | 71 while ((node = node->previousLeafNode())) { |
| 72 if (!node->rendererIsEditable()) | |
| 73 continue; | |
| 74 RenderObject* renderer = node->renderer(); | 72 RenderObject* renderer = node->renderer(); |
| 75 if (!renderer) | 73 if (!renderer) |
| 76 continue; | 74 continue; |
| 75 if (!node->rendererIsEditable()) | |
| 76 continue; | |
| 77 if ((renderer->isBox() && toRenderBox(renderer)->inlineBoxWrapper()) || (renderer->isText() && toRenderText(renderer)->firstTextBox())) | 77 if ((renderer->isBox() && toRenderBox(renderer)->inlineBoxWrapper()) || (renderer->isText() && toRenderText(renderer)->firstTextBox())) |
| 78 return node; | 78 return node; |
| 79 } | 79 } |
| 80 return 0; | 80 return 0; |
| 81 } | 81 } |
| 82 | 82 |
| 83 Position::Position(PassRefPtr<Node> anchorNode, LegacyEditingOffset offset) | 83 Position::Position(PassRefPtr<Node> anchorNode, LegacyEditingOffset offset) |
| 84 : m_anchorNode(anchorNode) | 84 : m_anchorNode(anchorNode) |
| 85 , m_offset(offset.value()) | 85 , m_offset(offset.value()) |
| 86 , m_anchorType(anchorTypeForLegacyEditingPosition(m_anchorNode.get(), m_offs et)) | 86 , m_anchorType(anchorTypeForLegacyEditingPosition(m_anchorNode.get(), m_offs et)) |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 Node* boundary = enclosingVisualBoundary(startNode); | 590 Node* boundary = enclosingVisualBoundary(startNode); |
| 591 // FIXME: PositionIterator should respect Before and After positions. | 591 // FIXME: PositionIterator should respect Before and After positions. |
| 592 PositionIterator lastVisible = m_anchorType == PositionIsAfterAnchor ? creat eLegacyEditingPosition(m_anchorNode.get(), caretMaxOffset(m_anchorNode.get())) : *this; | 592 PositionIterator lastVisible = m_anchorType == PositionIsAfterAnchor ? creat eLegacyEditingPosition(m_anchorNode.get(), caretMaxOffset(m_anchorNode.get())) : *this; |
| 593 PositionIterator currentPos = lastVisible; | 593 PositionIterator currentPos = lastVisible; |
| 594 bool startEditable = startNode->rendererIsEditable(); | 594 bool startEditable = startNode->rendererIsEditable(); |
| 595 Node* lastNode = startNode; | 595 Node* lastNode = startNode; |
| 596 bool boundaryCrossed = false; | 596 bool boundaryCrossed = false; |
| 597 for (; !currentPos.atStart(); currentPos.decrement()) { | 597 for (; !currentPos.atStart(); currentPos.decrement()) { |
| 598 Node* currentNode = currentPos.node(); | 598 Node* currentNode = currentPos.node(); |
| 599 | 599 |
| 600 // skip position in unrendered or invisible node | |
| 601 RenderObject* renderer = currentNode->renderer(); | |
|
ojan
2013/10/01 19:21:39
Doesn't this change behavior because you've now mo
| |
| 602 if (!renderer || renderer->style()->visibility() != VISIBLE) | |
| 603 continue; | |
| 604 | |
| 600 // Don't check for an editability change if we haven't moved to a differ ent node, | 605 // Don't check for an editability change if we haven't moved to a differ ent node, |
| 601 // to avoid the expense of computing rendererIsEditable(). | 606 // to avoid the expense of computing rendererIsEditable(). |
| 602 if (currentNode != lastNode) { | 607 if (currentNode != lastNode) { |
| 603 // Don't change editability. | 608 // Don't change editability. |
| 604 bool currentEditable = currentNode->rendererIsEditable(); | 609 bool currentEditable = currentNode->rendererIsEditable(); |
| 605 if (startEditable != currentEditable) { | 610 if (startEditable != currentEditable) { |
| 606 if (rule == CannotCrossEditingBoundary) | 611 if (rule == CannotCrossEditingBoundary) |
| 607 break; | 612 break; |
| 608 boundaryCrossed = true; | 613 boundaryCrossed = true; |
| 609 } | 614 } |
| 610 lastNode = currentNode; | 615 lastNode = currentNode; |
| 611 } | 616 } |
| 612 | 617 |
| 613 // If we've moved to a position that is visually distinct, return the la st saved position. There | 618 // If we've moved to a position that is visually distinct, return the la st saved position. There |
| 614 // is code below that terminates early if we're *about* to move to a vis ually distinct position. | 619 // is code below that terminates early if we're *about* to move to a vis ually distinct position. |
| 615 if (endsOfNodeAreVisuallyDistinctPositions(currentNode) && currentNode ! = boundary) | 620 if (endsOfNodeAreVisuallyDistinctPositions(currentNode) && currentNode ! = boundary) |
| 616 return lastVisible; | 621 return lastVisible; |
| 617 | 622 |
| 618 // skip position in unrendered or invisible node | |
| 619 RenderObject* renderer = currentNode->renderer(); | |
| 620 if (!renderer || renderer->style()->visibility() != VISIBLE) | |
| 621 continue; | |
| 622 | |
| 623 if (rule == CanCrossEditingBoundary && boundaryCrossed) { | 623 if (rule == CanCrossEditingBoundary && boundaryCrossed) { |
| 624 lastVisible = currentPos; | 624 lastVisible = currentPos; |
| 625 break; | 625 break; |
| 626 } | 626 } |
| 627 | 627 |
| 628 // track last visible streamer position | 628 // track last visible streamer position |
| 629 if (isStreamer(currentPos)) | 629 if (isStreamer(currentPos)) |
| 630 lastVisible = currentPos; | 630 lastVisible = currentPos; |
| 631 | 631 |
| 632 // Don't move past a position that is visually distinct. We could rely on code above to terminate and | 632 // Don't move past a position that is visually distinct. We could rely on code above to terminate and |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 713 Node* boundary = enclosingVisualBoundary(startNode); | 713 Node* boundary = enclosingVisualBoundary(startNode); |
| 714 // FIXME: PositionIterator should respect Before and After positions. | 714 // FIXME: PositionIterator should respect Before and After positions. |
| 715 PositionIterator lastVisible = m_anchorType == PositionIsAfterAnchor ? creat eLegacyEditingPosition(m_anchorNode.get(), caretMaxOffset(m_anchorNode.get())) : *this; | 715 PositionIterator lastVisible = m_anchorType == PositionIsAfterAnchor ? creat eLegacyEditingPosition(m_anchorNode.get(), caretMaxOffset(m_anchorNode.get())) : *this; |
| 716 PositionIterator currentPos = lastVisible; | 716 PositionIterator currentPos = lastVisible; |
| 717 bool startEditable = startNode->rendererIsEditable(); | 717 bool startEditable = startNode->rendererIsEditable(); |
| 718 Node* lastNode = startNode; | 718 Node* lastNode = startNode; |
| 719 bool boundaryCrossed = false; | 719 bool boundaryCrossed = false; |
| 720 for (; !currentPos.atEnd(); currentPos.increment()) { | 720 for (; !currentPos.atEnd(); currentPos.increment()) { |
| 721 Node* currentNode = currentPos.node(); | 721 Node* currentNode = currentPos.node(); |
| 722 | 722 |
| 723 // skip position in unrendered or invisible node | |
| 724 RenderObject* renderer = currentNode->renderer(); | |
|
ojan
2013/10/01 19:21:39
Ditto.
| |
| 725 if (!renderer || renderer->style()->visibility() != VISIBLE) | |
| 726 continue; | |
| 727 | |
| 723 // Don't check for an editability change if we haven't moved to a differ ent node, | 728 // Don't check for an editability change if we haven't moved to a differ ent node, |
| 724 // to avoid the expense of computing rendererIsEditable(). | 729 // to avoid the expense of computing rendererIsEditable(). |
| 725 if (currentNode != lastNode) { | 730 if (currentNode != lastNode) { |
| 726 // Don't change editability. | 731 // Don't change editability. |
| 727 bool currentEditable = currentNode->rendererIsEditable(); | 732 bool currentEditable = currentNode->rendererIsEditable(); |
| 728 if (startEditable != currentEditable) { | 733 if (startEditable != currentEditable) { |
| 729 if (rule == CannotCrossEditingBoundary) | 734 if (rule == CannotCrossEditingBoundary) |
| 730 break; | 735 break; |
| 731 boundaryCrossed = true; | 736 boundaryCrossed = true; |
| 732 } | 737 } |
| 733 | 738 |
| 734 lastNode = currentNode; | 739 lastNode = currentNode; |
| 735 } | 740 } |
| 736 | 741 |
| 737 // stop before going above the body, up into the head | 742 // stop before going above the body, up into the head |
| 738 // return the last visible streamer position | 743 // return the last visible streamer position |
| 739 if (currentNode->hasTagName(bodyTag) && currentPos.atEndOfNode()) | 744 if (currentNode->hasTagName(bodyTag) && currentPos.atEndOfNode()) |
| 740 break; | 745 break; |
| 741 | 746 |
| 742 // Do not move to a visually distinct position. | 747 // Do not move to a visually distinct position. |
| 743 if (endsOfNodeAreVisuallyDistinctPositions(currentNode) && currentNode ! = boundary) | 748 if (endsOfNodeAreVisuallyDistinctPositions(currentNode) && currentNode ! = boundary) |
| 744 return lastVisible; | 749 return lastVisible; |
| 745 // Do not move past a visually disinct position. | 750 // Do not move past a visually disinct position. |
| 746 // Note: The first position after the last in a node whose ends are visu ally distinct | 751 // Note: The first position after the last in a node whose ends are visu ally distinct |
| 747 // positions will be [boundary->parentNode(), originalBlock->nodeIndex() + 1]. | 752 // positions will be [boundary->parentNode(), originalBlock->nodeIndex() + 1]. |
| 748 if (boundary && boundary->parentNode() == currentNode) | 753 if (boundary && boundary->parentNode() == currentNode) |
| 749 return lastVisible; | 754 return lastVisible; |
| 750 | 755 |
| 751 // skip position in unrendered or invisible node | |
| 752 RenderObject* renderer = currentNode->renderer(); | |
| 753 if (!renderer || renderer->style()->visibility() != VISIBLE) | |
| 754 continue; | |
| 755 | |
| 756 if (rule == CanCrossEditingBoundary && boundaryCrossed) { | 756 if (rule == CanCrossEditingBoundary && boundaryCrossed) { |
| 757 lastVisible = currentPos; | 757 lastVisible = currentPos; |
| 758 break; | 758 break; |
| 759 } | 759 } |
| 760 | 760 |
| 761 // track last visible streamer position | 761 // track last visible streamer position |
| 762 if (isStreamer(currentPos)) | 762 if (isStreamer(currentPos)) |
| 763 lastVisible = currentPos; | 763 lastVisible = currentPos; |
| 764 | 764 |
| 765 // Return position before tables and nodes which have content that can b e ignored. | 765 // Return position before tables and nodes which have content that can b e ignored. |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1384 pos.showTreeForThis(); | 1384 pos.showTreeForThis(); |
| 1385 } | 1385 } |
| 1386 | 1386 |
| 1387 void showTree(const WebCore::Position* pos) | 1387 void showTree(const WebCore::Position* pos) |
| 1388 { | 1388 { |
| 1389 if (pos) | 1389 if (pos) |
| 1390 pos->showTreeForThis(); | 1390 pos->showTreeForThis(); |
| 1391 } | 1391 } |
| 1392 | 1392 |
| 1393 #endif | 1393 #endif |
| OLD | NEW |