OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/editing/VisibleUnits.h" | 5 #include "core/editing/VisibleUnits.h" |
6 | 6 |
7 #include "core/dom/Text.h" | 7 #include "core/dom/Text.h" |
8 #include "core/editing/EditingTestBase.h" | 8 #include "core/editing/EditingTestBase.h" |
9 #include "core/editing/VisiblePosition.h" | 9 #include "core/editing/VisiblePosition.h" |
10 #include "core/html/HTMLTextFormControlElement.h" | 10 #include "core/html/HTMLTextFormControlElement.h" |
11 #include "core/layout/LayoutTextFragment.h" | 11 #include "core/layout/LayoutTextFragment.h" |
12 #include "core/layout/line/InlineTextBox.h" | 12 #include "core/layout/line/InlineTextBox.h" |
13 #include <ostream> // NOLINT | 13 #include <ostream> // NOLINT |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 PositionWithAffinity positionWithAffinityInDOMTree(Node& anchor, int offset, Tex
tAffinity affinity = TextAffinity::Downstream) | 19 PositionWithAffinity positionWithAffinityInDOMTree(Node& anchor, int offset, Tex
tAffinity affinity = TextAffinity::Downstream) |
20 { | 20 { |
21 return PositionWithAffinity(canonicalPositionOf(Position(&anchor, offset)),
affinity); | 21 return PositionWithAffinity(canonicalPositionOf(Position(&anchor, offset)),
affinity); |
22 } | 22 } |
23 | 23 |
24 VisiblePosition createVisiblePositionInDOMTree(Node& anchor, int offset, TextAff
inity affinity = TextAffinity::Downstream) | 24 VisiblePosition createVisiblePositionInDOMTree(Node& anchor, int offset, TextAff
inity affinity = TextAffinity::Downstream) |
25 { | 25 { |
26 return createVisiblePositionDeprecated(Position(&anchor, offset), affinity); | 26 return createVisiblePosition(Position(&anchor, offset), affinity); |
27 } | 27 } |
28 | 28 |
29 PositionInFlatTreeWithAffinity positionWithAffinityInFlatTree(Node& anchor, int
offset, TextAffinity affinity = TextAffinity::Downstream) | 29 PositionInFlatTreeWithAffinity positionWithAffinityInFlatTree(Node& anchor, int
offset, TextAffinity affinity = TextAffinity::Downstream) |
30 { | 30 { |
31 return PositionInFlatTreeWithAffinity(canonicalPositionOf(PositionInFlatTree
(&anchor, offset)), affinity); | 31 return PositionInFlatTreeWithAffinity(canonicalPositionOf(PositionInFlatTree
(&anchor, offset)), affinity); |
32 } | 32 } |
33 | 33 |
34 VisiblePositionInFlatTree createVisiblePositionInFlatTree(Node& anchor, int offs
et, TextAffinity affinity = TextAffinity::Downstream) | 34 VisiblePositionInFlatTree createVisiblePositionInFlatTree(Node& anchor, int offs
et, TextAffinity affinity = TextAffinity::Downstream) |
35 { | 35 { |
36 return createVisiblePositionDeprecated(PositionInFlatTree(&anchor, offset),
affinity); | 36 return createVisiblePosition(PositionInFlatTree(&anchor, offset), affinity); |
37 } | 37 } |
38 | 38 |
39 } // namespace | 39 } // namespace |
40 | 40 |
41 std::ostream& operator<<(std::ostream& ostream, const InlineBoxPosition& inlineB
oxPosition) | 41 std::ostream& operator<<(std::ostream& ostream, const InlineBoxPosition& inlineB
oxPosition) |
42 { | 42 { |
43 if (!inlineBoxPosition.inlineBox) | 43 if (!inlineBoxPosition.inlineBox) |
44 return ostream << "null"; | 44 return ostream << "null"; |
45 return ostream << inlineBoxPosition.inlineBox->getLineLayoutItem().node() <<
"@" << inlineBoxPosition.offsetInBox; | 45 return ostream << inlineBoxPosition.inlineBox->getLineLayoutItem().node() <<
"@" << inlineBoxPosition.offsetInBox; |
46 } | 46 } |
47 | 47 |
48 class VisibleUnitsTest : public EditingTestBase { | 48 class VisibleUnitsTest : public EditingTestBase { |
49 }; | 49 }; |
50 | 50 |
51 TEST_F(VisibleUnitsTest, absoluteCaretBoundsOf) | 51 TEST_F(VisibleUnitsTest, absoluteCaretBoundsOf) |
52 { | 52 { |
53 const char* bodyContent = "<p id='host'><b id='one'>11</b><b id='two'>22</b>
</p>"; | 53 const char* bodyContent = "<p id='host'><b id='one'>11</b><b id='two'>22</b>
</p>"; |
54 const char* shadowContent = "<div><content select=#two></content><content se
lect=#one></content></div>"; | 54 const char* shadowContent = "<div><content select=#two></content><content se
lect=#one></content></div>"; |
55 setBodyContent(bodyContent); | 55 setBodyContent(bodyContent); |
56 setShadowContent(shadowContent, "host"); | 56 setShadowContent(shadowContent, "host"); |
57 | 57 |
58 Element* body = document().body(); | 58 Element* body = document().body(); |
59 Element* one = body->querySelector("#one"); | 59 Element* one = body->querySelector("#one"); |
60 | 60 |
61 IntRect boundsInDOMTree = absoluteCaretBoundsOf(createVisiblePositionDepreca
ted(Position(one, 0))); | 61 IntRect boundsInDOMTree = absoluteCaretBoundsOf(createVisiblePosition(Positi
on(one, 0))); |
62 IntRect boundsInFlatTree = absoluteCaretBoundsOf(createVisiblePositionDeprec
ated(PositionInFlatTree(one, 0))); | 62 IntRect boundsInFlatTree = absoluteCaretBoundsOf(createVisiblePosition(Posit
ionInFlatTree(one, 0))); |
63 | 63 |
64 EXPECT_FALSE(boundsInDOMTree.isEmpty()); | 64 EXPECT_FALSE(boundsInDOMTree.isEmpty()); |
65 EXPECT_EQ(boundsInDOMTree, boundsInFlatTree); | 65 EXPECT_EQ(boundsInDOMTree, boundsInFlatTree); |
66 } | 66 } |
67 | 67 |
68 TEST_F(VisibleUnitsTest, associatedLayoutObjectOfFirstLetterPunctuations) | 68 TEST_F(VisibleUnitsTest, associatedLayoutObjectOfFirstLetterPunctuations) |
69 { | 69 { |
70 const char* bodyContent = "<style>p:first-letter {color:red;}</style><p id=s
ample>(a)bc</p>"; | 70 const char* bodyContent = "<style>p:first-letter {color:red;}</style><p id=s
ample>(a)bc</p>"; |
71 setBodyContent(bodyContent); | 71 setBodyContent(bodyContent); |
72 | 72 |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 const char* shadowContent = "<b id=four>4444</b><content select=#two></conte
nt><content select=#one></content><b id=five>55555</b>"; | 758 const char* shadowContent = "<b id=four>4444</b><content select=#two></conte
nt><content select=#one></content><b id=five>55555</b>"; |
759 setBodyContent(bodyContent); | 759 setBodyContent(bodyContent); |
760 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 760 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
761 | 761 |
762 Element* one = document().getElementById("one"); | 762 Element* one = document().getElementById("one"); |
763 Element* two = document().getElementById("two"); | 763 Element* two = document().getElementById("two"); |
764 Element* three = document().getElementById("three"); | 764 Element* three = document().getElementById("three"); |
765 Element* four = shadowRoot->getElementById("four"); | 765 Element* four = shadowRoot->getElementById("four"); |
766 Element* five = shadowRoot->getElementById("five"); | 766 Element* five = shadowRoot->getElementById("five"); |
767 | 767 |
768 EXPECT_EQ(Position(two->firstChild(), 1), leftPositionOf(createVisiblePositi
onDeprecated(Position(one, 0))).deepEquivalent()); | 768 EXPECT_EQ(Position(two->firstChild(), 1), leftPositionOf(createVisiblePositi
on(Position(one, 0))).deepEquivalent()); |
769 EXPECT_EQ(PositionInFlatTree(two->firstChild(), 1), leftPositionOf(createVis
iblePositionDeprecated(PositionInFlatTree(one, 0))).deepEquivalent()); | 769 EXPECT_EQ(PositionInFlatTree(two->firstChild(), 1), leftPositionOf(createVis
iblePosition(PositionInFlatTree(one, 0))).deepEquivalent()); |
770 | 770 |
771 EXPECT_EQ(Position(one->firstChild(), 0), leftPositionOf(createVisiblePositi
onDeprecated(Position(two, 0))).deepEquivalent()); | 771 EXPECT_EQ(Position(one->firstChild(), 0), leftPositionOf(createVisiblePositi
on(Position(two, 0))).deepEquivalent()); |
772 EXPECT_EQ(PositionInFlatTree(four->firstChild(), 3), leftPositionOf(createVi
siblePositionDeprecated(PositionInFlatTree(two, 0))).deepEquivalent()); | 772 EXPECT_EQ(PositionInFlatTree(four->firstChild(), 3), leftPositionOf(createVi
siblePosition(PositionInFlatTree(two, 0))).deepEquivalent()); |
773 | 773 |
774 EXPECT_EQ(Position(two->firstChild(), 2), leftPositionOf(createVisiblePositi
onDeprecated(Position(three, 0))).deepEquivalent()); | 774 EXPECT_EQ(Position(two->firstChild(), 2), leftPositionOf(createVisiblePositi
on(Position(three, 0))).deepEquivalent()); |
775 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 5), leftPositionOf(createVi
siblePositionDeprecated(PositionInFlatTree(three, 0))).deepEquivalent()); | 775 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 5), leftPositionOf(createVi
siblePosition(PositionInFlatTree(three, 0))).deepEquivalent()); |
776 } | 776 } |
777 | 777 |
778 TEST_F(VisibleUnitsTest, localCaretRectOfPosition) | 778 TEST_F(VisibleUnitsTest, localCaretRectOfPosition) |
779 { | 779 { |
780 const char* bodyContent = "<p id='host'><b id='one'>1</b></p><b id='two'>22<
/b>"; | 780 const char* bodyContent = "<p id='host'><b id='one'>1</b></p><b id='two'>22<
/b>"; |
781 const char* shadowContent = "<b id='two'>22</b><content select=#one></conten
t><b id='three'>333</b>"; | 781 const char* shadowContent = "<b id='two'>22</b><content select=#one></conten
t><b id='three'>333</b>"; |
782 setBodyContent(bodyContent); | 782 setBodyContent(bodyContent); |
783 setShadowContent(shadowContent, "host"); | 783 setShadowContent(shadowContent, "host"); |
784 | 784 |
785 Element* one = document().getElementById("one"); | 785 Element* one = document().getElementById("one"); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 setBodyContent(bodyContent); | 984 setBodyContent(bodyContent); |
985 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 985 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
986 | 986 |
987 Element* zero = document().getElementById("zero"); | 987 Element* zero = document().getElementById("zero"); |
988 Element* one = document().getElementById("one"); | 988 Element* one = document().getElementById("one"); |
989 Element* two = document().getElementById("two"); | 989 Element* two = document().getElementById("two"); |
990 Element* three = document().getElementById("three"); | 990 Element* three = document().getElementById("three"); |
991 Element* four = shadowRoot->getElementById("four"); | 991 Element* four = shadowRoot->getElementById("four"); |
992 Element* five = shadowRoot->getElementById("five"); | 992 Element* five = shadowRoot->getElementById("five"); |
993 | 993 |
994 EXPECT_EQ(Position(one->firstChild(), 0), nextPositionOf(createVisiblePositi
onDeprecated(Position(zero, 1))).deepEquivalent()); | 994 EXPECT_EQ(Position(one->firstChild(), 0), nextPositionOf(createVisiblePositi
on(Position(zero, 1))).deepEquivalent()); |
995 EXPECT_EQ(PositionInFlatTree(four->firstChild(), 0), nextPositionOf(createVi
siblePositionDeprecated(PositionInFlatTree(zero, 1))).deepEquivalent()); | 995 EXPECT_EQ(PositionInFlatTree(four->firstChild(), 0), nextPositionOf(createVi
siblePosition(PositionInFlatTree(zero, 1))).deepEquivalent()); |
996 | 996 |
997 EXPECT_EQ(Position(one->firstChild(), 1), nextPositionOf(createVisiblePositi
onDeprecated(Position(one, 0))).deepEquivalent()); | 997 EXPECT_EQ(Position(one->firstChild(), 1), nextPositionOf(createVisiblePositi
on(Position(one, 0))).deepEquivalent()); |
998 EXPECT_EQ(PositionInFlatTree(one->firstChild(), 1), nextPositionOf(createVis
iblePositionDeprecated(PositionInFlatTree(one, 0))).deepEquivalent()); | 998 EXPECT_EQ(PositionInFlatTree(one->firstChild(), 1), nextPositionOf(createVis
iblePosition(PositionInFlatTree(one, 0))).deepEquivalent()); |
999 | 999 |
1000 EXPECT_EQ(Position(two->firstChild(), 1), nextPositionOf(createVisiblePositi
onDeprecated(Position(one, 1))).deepEquivalent()); | 1000 EXPECT_EQ(Position(two->firstChild(), 1), nextPositionOf(createVisiblePositi
on(Position(one, 1))).deepEquivalent()); |
1001 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 1), nextPositionOf(createVi
siblePositionDeprecated(PositionInFlatTree(one, 1))).deepEquivalent()); | 1001 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 1), nextPositionOf(createVi
siblePosition(PositionInFlatTree(one, 1))).deepEquivalent()); |
1002 | 1002 |
1003 EXPECT_EQ(Position(three->firstChild(), 0), nextPositionOf(createVisiblePosi
tionDeprecated(Position(two, 2))).deepEquivalent()); | 1003 EXPECT_EQ(Position(three->firstChild(), 0), nextPositionOf(createVisiblePosi
tion(Position(two, 2))).deepEquivalent()); |
1004 EXPECT_EQ(PositionInFlatTree(one->firstChild(), 1), nextPositionOf(createVis
iblePositionDeprecated(PositionInFlatTree(two, 2))).deepEquivalent()); | 1004 EXPECT_EQ(PositionInFlatTree(one->firstChild(), 1), nextPositionOf(createVis
iblePosition(PositionInFlatTree(two, 2))).deepEquivalent()); |
1005 } | 1005 } |
1006 | 1006 |
1007 TEST_F(VisibleUnitsTest, previousPositionOf) | 1007 TEST_F(VisibleUnitsTest, previousPositionOf) |
1008 { | 1008 { |
1009 const char* bodyContent = "<b id=zero>0</b><p id=host><b id=one>1</b><b id=t
wo>22</b></p><b id=three>333</b>"; | 1009 const char* bodyContent = "<b id=zero>0</b><p id=host><b id=one>1</b><b id=t
wo>22</b></p><b id=three>333</b>"; |
1010 const char* shadowContent = "<b id=four>4444</b><content select=#two></conte
nt><content select=#one></content><b id=five>55555</b>"; | 1010 const char* shadowContent = "<b id=four>4444</b><content select=#two></conte
nt><content select=#one></content><b id=five>55555</b>"; |
1011 setBodyContent(bodyContent); | 1011 setBodyContent(bodyContent); |
1012 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 1012 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
1013 | 1013 |
1014 Node* zero = document().getElementById("zero")->firstChild(); | 1014 Node* zero = document().getElementById("zero")->firstChild(); |
1015 Node* one = document().getElementById("one")->firstChild(); | 1015 Node* one = document().getElementById("one")->firstChild(); |
1016 Node* two = document().getElementById("two")->firstChild(); | 1016 Node* two = document().getElementById("two")->firstChild(); |
1017 Node* three = document().getElementById("three")->firstChild(); | 1017 Node* three = document().getElementById("three")->firstChild(); |
1018 Node* four = shadowRoot->getElementById("four")->firstChild(); | 1018 Node* four = shadowRoot->getElementById("four")->firstChild(); |
1019 Node* five = shadowRoot->getElementById("five")->firstChild(); | 1019 Node* five = shadowRoot->getElementById("five")->firstChild(); |
1020 | 1020 |
1021 EXPECT_EQ(Position(zero, 0), previousPositionOf(createVisiblePositionDepreca
ted(Position(zero, 1))).deepEquivalent()); | 1021 EXPECT_EQ(Position(zero, 0), previousPositionOf(createVisiblePosition(Positi
on(zero, 1))).deepEquivalent()); |
1022 EXPECT_EQ(PositionInFlatTree(zero, 0), previousPositionOf(createVisiblePosit
ionDeprecated(PositionInFlatTree(zero, 1))).deepEquivalent()); | 1022 EXPECT_EQ(PositionInFlatTree(zero, 0), previousPositionOf(createVisiblePosit
ion(PositionInFlatTree(zero, 1))).deepEquivalent()); |
1023 | 1023 |
1024 EXPECT_EQ(Position(zero, 1), previousPositionOf(createVisiblePositionDepreca
ted(Position(one, 0))).deepEquivalent()); | 1024 EXPECT_EQ(Position(zero, 1), previousPositionOf(createVisiblePosition(Positi
on(one, 0))).deepEquivalent()); |
1025 EXPECT_EQ(PositionInFlatTree(two, 1), previousPositionOf(createVisiblePositi
onDeprecated(PositionInFlatTree(one, 0))).deepEquivalent()); | 1025 EXPECT_EQ(PositionInFlatTree(two, 1), previousPositionOf(createVisiblePositi
on(PositionInFlatTree(one, 0))).deepEquivalent()); |
1026 | 1026 |
1027 EXPECT_EQ(Position(one, 0), previousPositionOf(createVisiblePositionDeprecat
ed(Position(one, 1))).deepEquivalent()); | 1027 EXPECT_EQ(Position(one, 0), previousPositionOf(createVisiblePosition(Positio
n(one, 1))).deepEquivalent()); |
1028 EXPECT_EQ(PositionInFlatTree(two, 2), previousPositionOf(createVisiblePositi
onDeprecated(PositionInFlatTree(one, 1))).deepEquivalent()); | 1028 EXPECT_EQ(PositionInFlatTree(two, 2), previousPositionOf(createVisiblePositi
on(PositionInFlatTree(one, 1))).deepEquivalent()); |
1029 | 1029 |
1030 EXPECT_EQ(Position(one, 0), previousPositionOf(createVisiblePositionDeprecat
ed(Position(two, 0))).deepEquivalent()); | 1030 EXPECT_EQ(Position(one, 0), previousPositionOf(createVisiblePosition(Positio
n(two, 0))).deepEquivalent()); |
1031 EXPECT_EQ(PositionInFlatTree(four, 3), previousPositionOf(createVisiblePosit
ionDeprecated(PositionInFlatTree(two, 0))).deepEquivalent()); | 1031 EXPECT_EQ(PositionInFlatTree(four, 3), previousPositionOf(createVisiblePosit
ion(PositionInFlatTree(two, 0))).deepEquivalent()); |
1032 | 1032 |
1033 // DOM tree to shadow tree | 1033 // DOM tree to shadow tree |
1034 EXPECT_EQ(Position(two, 2), previousPositionOf(createVisiblePositionDeprecat
ed(Position(three, 0))).deepEquivalent()); | 1034 EXPECT_EQ(Position(two, 2), previousPositionOf(createVisiblePosition(Positio
n(three, 0))).deepEquivalent()); |
1035 EXPECT_EQ(PositionInFlatTree(five, 5), previousPositionOf(createVisiblePosit
ionDeprecated(PositionInFlatTree(three, 0))).deepEquivalent()); | 1035 EXPECT_EQ(PositionInFlatTree(five, 5), previousPositionOf(createVisiblePosit
ion(PositionInFlatTree(three, 0))).deepEquivalent()); |
1036 | 1036 |
1037 // Shadow tree to DOM tree | 1037 // Shadow tree to DOM tree |
1038 EXPECT_EQ(Position(), previousPositionOf(createVisiblePositionDeprecated(Pos
ition(four, 0))).deepEquivalent()); | 1038 EXPECT_EQ(Position(), previousPositionOf(createVisiblePosition(Position(four
, 0))).deepEquivalent()); |
1039 EXPECT_EQ(PositionInFlatTree(zero, 1), previousPositionOf(createVisiblePosit
ionDeprecated(PositionInFlatTree(four, 0))).deepEquivalent()); | 1039 EXPECT_EQ(PositionInFlatTree(zero, 1), previousPositionOf(createVisiblePosit
ion(PositionInFlatTree(four, 0))).deepEquivalent()); |
1040 | 1040 |
1041 // Note: Canonicalization maps (five, 0) to (four, 4) in DOM tree and | 1041 // Note: Canonicalization maps (five, 0) to (four, 4) in DOM tree and |
1042 // (one, 1) in flat tree. | 1042 // (one, 1) in flat tree. |
1043 EXPECT_EQ(Position(four, 4), previousPositionOf(createVisiblePositionDepreca
ted(Position(five, 1))).deepEquivalent()); | 1043 EXPECT_EQ(Position(four, 4), previousPositionOf(createVisiblePosition(Positi
on(five, 1))).deepEquivalent()); |
1044 EXPECT_EQ(PositionInFlatTree(one, 1), previousPositionOf(createVisiblePositi
onDeprecated(PositionInFlatTree(five, 1))).deepEquivalent()); | 1044 EXPECT_EQ(PositionInFlatTree(one, 1), previousPositionOf(createVisiblePositi
on(PositionInFlatTree(five, 1))).deepEquivalent()); |
1045 } | 1045 } |
1046 | 1046 |
1047 TEST_F(VisibleUnitsTest, previousPositionOfOneCharPerLine) | 1047 TEST_F(VisibleUnitsTest, previousPositionOfOneCharPerLine) |
1048 { | 1048 { |
1049 const char* bodyContent = "<div id=sample style='font-size: 500px'>A煊
逸</div>"; | 1049 const char* bodyContent = "<div id=sample style='font-size: 500px'>A煊
逸</div>"; |
1050 setBodyContent(bodyContent); | 1050 setBodyContent(bodyContent); |
1051 | 1051 |
1052 Node* sample = document().getElementById("sample")->firstChild(); | 1052 Node* sample = document().getElementById("sample")->firstChild(); |
1053 | 1053 |
1054 // In case of each line has one character, VisiblePosition are: | 1054 // In case of each line has one character, VisiblePosition are: |
1055 // [C,Dn] [C,Up] [B, Dn] [B, Up] | 1055 // [C,Dn] [C,Up] [B, Dn] [B, Up] |
1056 // A A A A| | 1056 // A A A A| |
1057 // B B| |B B | 1057 // B B| |B B |
1058 // |C C C C | 1058 // |C C C C |
1059 EXPECT_EQ(PositionWithAffinity(Position(sample, 1)), previousPositionOf(crea
teVisiblePositionDeprecated(Position(sample, 2))).toPositionWithAffinity()); | 1059 EXPECT_EQ(PositionWithAffinity(Position(sample, 1)), previousPositionOf(crea
teVisiblePosition(Position(sample, 2))).toPositionWithAffinity()); |
1060 EXPECT_EQ(PositionWithAffinity(Position(sample, 1)), previousPositionOf(crea
teVisiblePositionDeprecated(Position(sample, 2), TextAffinity::Upstream)).toPosi
tionWithAffinity()); | 1060 EXPECT_EQ(PositionWithAffinity(Position(sample, 1)), previousPositionOf(crea
teVisiblePosition(Position(sample, 2), TextAffinity::Upstream)).toPositionWithAf
finity()); |
1061 } | 1061 } |
1062 | 1062 |
1063 TEST_F(VisibleUnitsTest, previousPositionOfNoPreviousPosition) | 1063 TEST_F(VisibleUnitsTest, previousPositionOfNoPreviousPosition) |
1064 { | 1064 { |
1065 setBodyContent( | 1065 setBodyContent( |
1066 "<span contenteditable='true'>" | 1066 "<span contenteditable='true'>" |
1067 "<span> </span>" | 1067 "<span> </span>" |
1068 " " // This whitespace causes no previous position. | 1068 " " // This whitespace causes no previous position. |
1069 "<div id='anchor'> bar</div>" | 1069 "<div id='anchor'> bar</div>" |
1070 "</span>"); | 1070 "</span>"); |
1071 const Position position(document().getElementById("anchor")->firstChild(), 1
); | 1071 const Position position(document().getElementById("anchor")->firstChild(), 1
); |
1072 EXPECT_EQ(Position(), previousPositionOf(createVisiblePositionDeprecated(pos
ition)).deepEquivalent()); | 1072 EXPECT_EQ(Position(), previousPositionOf(createVisiblePosition(position)).de
epEquivalent()); |
1073 } | 1073 } |
1074 | 1074 |
1075 TEST_F(VisibleUnitsTest, rendersInDifferentPositionAfterAnchor) | 1075 TEST_F(VisibleUnitsTest, rendersInDifferentPositionAfterAnchor) |
1076 { | 1076 { |
1077 const char* bodyContent = "<p id='sample'>00</p>"; | 1077 const char* bodyContent = "<p id='sample'>00</p>"; |
1078 setBodyContent(bodyContent); | 1078 setBodyContent(bodyContent); |
1079 Element* sample = document().getElementById("sample"); | 1079 Element* sample = document().getElementById("sample"); |
1080 | 1080 |
1081 EXPECT_FALSE(rendersInDifferentPosition(Position(), Position())); | 1081 EXPECT_FALSE(rendersInDifferentPosition(Position(), Position())); |
1082 EXPECT_FALSE(rendersInDifferentPosition(Position(), Position::afterNode(samp
le))) | 1082 EXPECT_FALSE(rendersInDifferentPosition(Position(), Position::afterNode(samp
le))) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 const char* shadowContent = "<p id=four>4444</p><content select=#two></conte
nt><content select=#one></content><p id=five>55555</p>"; | 1125 const char* shadowContent = "<p id=four>4444</p><content select=#two></conte
nt><content select=#one></content><p id=five>55555</p>"; |
1126 setBodyContent(bodyContent); | 1126 setBodyContent(bodyContent); |
1127 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 1127 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
1128 | 1128 |
1129 Node* one = document().getElementById("one")->firstChild(); | 1129 Node* one = document().getElementById("one")->firstChild(); |
1130 Node* two = document().getElementById("two")->firstChild(); | 1130 Node* two = document().getElementById("two")->firstChild(); |
1131 Node* three = document().getElementById("three")->firstChild(); | 1131 Node* three = document().getElementById("three")->firstChild(); |
1132 Node* four = shadowRoot->getElementById("four")->firstChild(); | 1132 Node* four = shadowRoot->getElementById("four")->firstChild(); |
1133 Node* five = shadowRoot->getElementById("five")->firstChild(); | 1133 Node* five = shadowRoot->getElementById("five")->firstChild(); |
1134 | 1134 |
1135 EXPECT_EQ(Position(), rightPositionOf(createVisiblePositionDeprecated(Positi
on(one, 1))).deepEquivalent()); | 1135 EXPECT_EQ(Position(), rightPositionOf(createVisiblePosition(Position(one, 1)
)).deepEquivalent()); |
1136 EXPECT_EQ(PositionInFlatTree(five, 0), rightPositionOf(createVisiblePosition
Deprecated(PositionInFlatTree(one, 1))).deepEquivalent()); | 1136 EXPECT_EQ(PositionInFlatTree(five, 0), rightPositionOf(createVisiblePosition
(PositionInFlatTree(one, 1))).deepEquivalent()); |
1137 | 1137 |
1138 EXPECT_EQ(Position(one, 1), rightPositionOf(createVisiblePositionDeprecated(
Position(two, 2))).deepEquivalent()); | 1138 EXPECT_EQ(Position(one, 1), rightPositionOf(createVisiblePosition(Position(t
wo, 2))).deepEquivalent()); |
1139 EXPECT_EQ(PositionInFlatTree(one, 1), rightPositionOf(createVisiblePositionD
eprecated(PositionInFlatTree(two, 2))).deepEquivalent()); | 1139 EXPECT_EQ(PositionInFlatTree(one, 1), rightPositionOf(createVisiblePosition(
PositionInFlatTree(two, 2))).deepEquivalent()); |
1140 | 1140 |
1141 EXPECT_EQ(Position(five, 0), rightPositionOf(createVisiblePositionDeprecated
(Position(four, 4))).deepEquivalent()); | 1141 EXPECT_EQ(Position(five, 0), rightPositionOf(createVisiblePosition(Position(
four, 4))).deepEquivalent()); |
1142 EXPECT_EQ(PositionInFlatTree(two, 0), rightPositionOf(createVisiblePositionD
eprecated(PositionInFlatTree(four, 4))).deepEquivalent()); | 1142 EXPECT_EQ(PositionInFlatTree(two, 0), rightPositionOf(createVisiblePosition(
PositionInFlatTree(four, 4))).deepEquivalent()); |
1143 | 1143 |
1144 EXPECT_EQ(Position(), rightPositionOf(createVisiblePositionDeprecated(Positi
on(five, 5))).deepEquivalent()); | 1144 EXPECT_EQ(Position(), rightPositionOf(createVisiblePosition(Position(five, 5
))).deepEquivalent()); |
1145 EXPECT_EQ(PositionInFlatTree(three, 0), rightPositionOf(createVisiblePositio
nDeprecated(PositionInFlatTree(five, 5))).deepEquivalent()); | 1145 EXPECT_EQ(PositionInFlatTree(three, 0), rightPositionOf(createVisiblePositio
n(PositionInFlatTree(five, 5))).deepEquivalent()); |
1146 } | 1146 } |
1147 | 1147 |
1148 TEST_F(VisibleUnitsTest, startOfDocument) | 1148 TEST_F(VisibleUnitsTest, startOfDocument) |
1149 { | 1149 { |
1150 const char* bodyContent = "<a id=host><b id=one>1</b><b id=two>22</b></a>"; | 1150 const char* bodyContent = "<a id=host><b id=one>1</b><b id=two>22</b></a>"; |
1151 const char* shadowContent = "<p><content select=#two></content></p><p><conte
nt select=#one></content></p>"; | 1151 const char* shadowContent = "<p><content select=#two></content></p><p><conte
nt select=#one></content></p>"; |
1152 setBodyContent(bodyContent); | 1152 setBodyContent(bodyContent); |
1153 setShadowContent(shadowContent, "host"); | 1153 setShadowContent(shadowContent, "host"); |
1154 | 1154 |
1155 Node* one = document().getElementById("one")->firstChild(); | 1155 Node* one = document().getElementById("one")->firstChild(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1236 root->setInnerHTML("<style>* { display:inline-table; }</style><body contente
ditable=true><svg><svg><foreignObject>abc<svg></svg></foreignObject></svg></svg>
</body>", ASSERT_NO_EXCEPTION); | 1236 root->setInnerHTML("<style>* { display:inline-table; }</style><body contente
ditable=true><svg><svg><foreignObject>abc<svg></svg></foreignObject></svg></svg>
</body>", ASSERT_NO_EXCEPTION); |
1237 Element* oldBody = document().body(); | 1237 Element* oldBody = document().body(); |
1238 root->setInnerHTML("<body contenteditable=true><svg><foreignObject><style>de
f</style>", ASSERT_NO_EXCEPTION); | 1238 root->setInnerHTML("<body contenteditable=true><svg><foreignObject><style>de
f</style>", ASSERT_NO_EXCEPTION); |
1239 DCHECK_NE(oldBody, document().body()); | 1239 DCHECK_NE(oldBody, document().body()); |
1240 Node* foreignObject = document().body()->firstChild()->firstChild(); | 1240 Node* foreignObject = document().body()->firstChild()->firstChild(); |
1241 foreignObject->insertBefore(oldBody, foreignObject->firstChild()); | 1241 foreignObject->insertBefore(oldBody, foreignObject->firstChild()); |
1242 Node* styleText = foreignObject->lastChild()->firstChild(); | 1242 Node* styleText = foreignObject->lastChild()->firstChild(); |
1243 DCHECK(styleText->isTextNode()) << styleText; | 1243 DCHECK(styleText->isTextNode()) << styleText; |
1244 updateAllLifecyclePhases(); | 1244 updateAllLifecyclePhases(); |
1245 | 1245 |
1246 EXPECT_FALSE(startOfParagraph(createVisiblePositionDeprecated(Position(style
Text, 0))).isNull()); | 1246 EXPECT_FALSE(startOfParagraph(createVisiblePosition(Position(styleText, 0)))
.isNull()); |
1247 } | 1247 } |
1248 | 1248 |
1249 TEST_F(VisibleUnitsTest, startOfSentence) | 1249 TEST_F(VisibleUnitsTest, startOfSentence) |
1250 { | 1250 { |
1251 const char* bodyContent = "<a id=host><b id=one>1</b><b id=two>22</b></a>"; | 1251 const char* bodyContent = "<a id=host><b id=one>1</b><b id=two>22</b></a>"; |
1252 const char* shadowContent = "<p><i id=three>333</i> <content select=#two></c
ontent> <content select=#one></content> <i id=four>4444</i></p>"; | 1252 const char* shadowContent = "<p><i id=three>333</i> <content select=#two></c
ontent> <content select=#one></content> <i id=four>4444</i></p>"; |
1253 setBodyContent(bodyContent); | 1253 setBodyContent(bodyContent); |
1254 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 1254 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
1255 | 1255 |
1256 Node* one = document().getElementById("one")->firstChild(); | 1256 Node* one = document().getElementById("one")->firstChild(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1327 { | 1327 { |
1328 // Repro case of crbug.com/584030 | 1328 // Repro case of crbug.com/584030 |
1329 const char* bodyContent = "<button><rt><script>document.designMode = 'on'</s
cript></rt></button>"; | 1329 const char* bodyContent = "<button><rt><script>document.designMode = 'on'</s
cript></rt></button>"; |
1330 setBodyContent(bodyContent); | 1330 setBodyContent(bodyContent); |
1331 | 1331 |
1332 Node* button = document().querySelector("button"); | 1332 Node* button = document().querySelector("button"); |
1333 EXPECT_TRUE(endsOfNodeAreVisuallyDistinctPositions(button)); | 1333 EXPECT_TRUE(endsOfNodeAreVisuallyDistinctPositions(button)); |
1334 } | 1334 } |
1335 | 1335 |
1336 } // namespace blink | 1336 } // namespace blink |
OLD | NEW |