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 * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. | 3 * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 #include "config.h" | 27 #include "config.h" |
28 #include "core/editing/VisiblePosition.h" | 28 #include "core/editing/VisiblePosition.h" |
29 | 29 |
30 #include "bindings/core/v8/ExceptionState.h" | 30 #include "bindings/core/v8/ExceptionState.h" |
31 #include "core/HTMLNames.h" | 31 #include "core/HTMLNames.h" |
32 #include "core/dom/Document.h" | 32 #include "core/dom/Document.h" |
33 #include "core/dom/Range.h" | 33 #include "core/dom/Range.h" |
34 #include "core/dom/Text.h" | 34 #include "core/dom/Text.h" |
35 #include "core/editing/EditingUtilities.h" | 35 #include "core/editing/EditingUtilities.h" |
| 36 #include "core/editing/TextAffinity.h" |
36 #include "core/editing/VisibleUnits.h" | 37 #include "core/editing/VisibleUnits.h" |
37 #include "core/html/HTMLElement.h" | 38 #include "core/html/HTMLElement.h" |
38 #include "core/layout/LayoutBlock.h" | 39 #include "core/layout/LayoutBlock.h" |
39 #include "core/layout/line/RootInlineBox.h" | 40 #include "core/layout/line/RootInlineBox.h" |
40 #include "platform/geometry/FloatQuad.h" | 41 #include "platform/geometry/FloatQuad.h" |
41 #include "wtf/text/CString.h" | 42 #include "wtf/text/CString.h" |
42 | 43 |
43 #ifndef NDEBUG | 44 #ifndef NDEBUG |
44 #include <stdio.h> | 45 #include <stdio.h> |
45 #endif | 46 #endif |
46 | 47 |
47 namespace blink { | 48 namespace blink { |
48 | 49 |
49 using namespace HTMLNames; | 50 using namespace HTMLNames; |
50 | 51 |
51 VisiblePosition::VisiblePosition(const Position &pos, EAffinity affinity) | 52 VisiblePosition::VisiblePosition(const Position &pos, TextAffinity affinity) |
52 { | 53 { |
53 init(pos, affinity); | 54 init(pos, affinity); |
54 } | 55 } |
55 | 56 |
56 VisiblePosition::VisiblePosition(const PositionInComposedTree& pos, EAffinity af
finity) | 57 VisiblePosition::VisiblePosition(const PositionInComposedTree& pos, TextAffinity
affinity) |
57 { | 58 { |
58 init(pos, affinity); | 59 init(pos, affinity); |
59 } | 60 } |
60 | 61 |
61 VisiblePosition::VisiblePosition(const PositionWithAffinity& positionWithAffinit
y) | 62 VisiblePosition::VisiblePosition(const PositionWithAffinity& positionWithAffinit
y) |
62 { | 63 { |
63 init(positionWithAffinity.position(), positionWithAffinity.affinity()); | 64 init(positionWithAffinity.position(), positionWithAffinity.affinity()); |
64 } | 65 } |
65 | 66 |
66 VisiblePosition VisiblePosition::next(EditingBoundaryCrossingRule rule) const | 67 VisiblePosition VisiblePosition::next(EditingBoundaryCrossingRule rule) const |
(...skipping 17 matching lines...) Expand all Loading... |
84 Position pos = previousVisuallyDistinctCandidate(m_deepPosition); | 85 Position pos = previousVisuallyDistinctCandidate(m_deepPosition); |
85 | 86 |
86 // return null visible position if there is no previous visible position | 87 // return null visible position if there is no previous visible position |
87 if (pos.atStartOfTree()) | 88 if (pos.atStartOfTree()) |
88 return VisiblePosition(); | 89 return VisiblePosition(); |
89 | 90 |
90 VisiblePosition prev = VisiblePosition(pos); | 91 VisiblePosition prev = VisiblePosition(pos); |
91 ASSERT(prev.deepEquivalent() != m_deepPosition); | 92 ASSERT(prev.deepEquivalent() != m_deepPosition); |
92 | 93 |
93 #if ENABLE(ASSERT) | 94 #if ENABLE(ASSERT) |
94 // we should always be able to make the affinity DOWNSTREAM, because going p
revious from an | 95 // we should always be able to make the affinity |TextAffinity::Downstream|, |
95 // UPSTREAM position can never yield another UPSTREAM position (unless line
wrap length is 0!). | 96 // because going previous from an |TextAffinity::Upstream| position can |
96 if (prev.isNotNull() && m_affinity == UPSTREAM) { | 97 // never yield another |TextAffinity::Upstream position| (unless line wrap |
97 ASSERT(inSameLine(PositionWithAffinity(prev.deepEquivalent()), PositionW
ithAffinity(prev.deepEquivalent(), UPSTREAM))); | 98 // length is 0!). |
| 99 if (prev.isNotNull() && m_affinity == TextAffinity::Upstream) { |
| 100 ASSERT(inSameLine(PositionWithAffinity(prev.deepEquivalent()), PositionW
ithAffinity(prev.deepEquivalent(), TextAffinity::Upstream))); |
98 } | 101 } |
99 #endif | 102 #endif |
100 | 103 |
101 switch (rule) { | 104 switch (rule) { |
102 case CanCrossEditingBoundary: | 105 case CanCrossEditingBoundary: |
103 return prev; | 106 return prev; |
104 case CannotCrossEditingBoundary: | 107 case CannotCrossEditingBoundary: |
105 return honorEditingBoundaryAtOrBefore(prev); | 108 return honorEditingBoundaryAtOrBefore(prev); |
106 case CanSkipOverEditingBoundary: | 109 case CanSkipOverEditingBoundary: |
107 return skipToStartOfEditingBoundary(prev); | 110 return skipToStartOfEditingBoundary(prev); |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 { | 632 { |
630 return canonicalPosition(position); | 633 return canonicalPosition(position); |
631 } | 634 } |
632 | 635 |
633 PositionInComposedTree canonicalPositionOf(const PositionInComposedTree& positio
n) | 636 PositionInComposedTree canonicalPositionOf(const PositionInComposedTree& positio
n) |
634 { | 637 { |
635 return canonicalPosition(position); | 638 return canonicalPosition(position); |
636 } | 639 } |
637 | 640 |
638 template<typename Strategy> | 641 template<typename Strategy> |
639 void VisiblePosition::init(const PositionAlgorithm<Strategy>& position, EAffinit
y affinity) | 642 void VisiblePosition::init(const PositionAlgorithm<Strategy>& position, TextAffi
nity affinity) |
640 { | 643 { |
641 m_affinity = affinity; | 644 m_affinity = affinity; |
642 | 645 |
643 PositionAlgorithm<Strategy> deepPosition = canonicalPosition(position); | 646 PositionAlgorithm<Strategy> deepPosition = canonicalPosition(position); |
644 m_deepPosition = toPositionInDOMTree(deepPosition); | 647 m_deepPosition = toPositionInDOMTree(deepPosition); |
645 | 648 |
646 if (m_affinity != UPSTREAM) | 649 if (m_affinity != TextAffinity::Upstream) |
647 return; | 650 return; |
648 | 651 |
649 if (isNull()) { | 652 if (isNull()) { |
650 m_affinity = DOWNSTREAM; | 653 m_affinity = TextAffinity::Downstream; |
651 return; | 654 return; |
652 } | 655 } |
653 | 656 |
654 // When not at a line wrap, make sure to end up with DOWNSTREAM affinity. | 657 // When not at a line wrap, make sure to end up with |
655 if (!inSameLine(PositionWithAffinityTemplate<Strategy>(deepPosition), Positi
onWithAffinityTemplate<Strategy>(deepPosition, UPSTREAM))) | 658 // |TextAffinity::Downstream| affinity. |
| 659 if (!inSameLine(PositionWithAffinityTemplate<Strategy>(deepPosition), Positi
onWithAffinityTemplate<Strategy>(deepPosition, TextAffinity::Upstream))) |
656 return; | 660 return; |
657 m_affinity = DOWNSTREAM; | 661 m_affinity = TextAffinity::Downstream; |
658 } | 662 } |
659 | 663 |
660 UChar32 VisiblePosition::characterAfter() const | 664 UChar32 VisiblePosition::characterAfter() const |
661 { | 665 { |
662 // We canonicalize to the first of two equivalent candidates, but the second | 666 // We canonicalize to the first of two equivalent candidates, but the second |
663 // of the two candidates is the one that will be inside the text node | 667 // of the two candidates is the one that will be inside the text node |
664 // containing the character after this visible position. | 668 // containing the character after this visible position. |
665 Position pos = m_deepPosition.downstream(); | 669 Position pos = m_deepPosition.downstream(); |
666 if (!pos.isOffsetInAnchor()) | 670 if (!pos.isOffsetInAnchor()) |
667 return 0; | 671 return 0; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 else | 769 else |
766 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); | 770 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); |
767 } | 771 } |
768 | 772 |
769 void showTree(const blink::VisiblePosition& vpos) | 773 void showTree(const blink::VisiblePosition& vpos) |
770 { | 774 { |
771 vpos.showTreeForThis(); | 775 vpos.showTreeForThis(); |
772 } | 776 } |
773 | 777 |
774 #endif | 778 #endif |
OLD | NEW |