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 "config.h" | 5 #include "config.h" |
6 #include "core/editing/VisibleUnits.h" | 6 #include "core/editing/VisibleUnits.h" |
7 | 7 |
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 | 10 |
11 namespace blink { | 11 namespace blink { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 PositionWithAffinity positionWithAffinityInDOMTree(Node& anchor, int offset, Tex
tAffinity affinity = TextAffinity::Downstream) | 15 PositionWithAffinity positionWithAffinityInDOMTree(Node& anchor, int offset, Tex
tAffinity affinity = TextAffinity::Downstream) |
16 { | 16 { |
17 return PositionWithAffinity(canonicalPositionOf(Position(&anchor, offset)),
affinity); | 17 return PositionWithAffinity(canonicalPositionOf(Position(&anchor, offset)),
affinity); |
18 } | 18 } |
19 | 19 |
20 PositionInComposedTreeWithAffinity positionWithAffinityInComposedTree(Node& anch
or, int offset, TextAffinity affinity = TextAffinity::Downstream) | 20 PositionInComposedTreeWithAffinity positionWithAffinityInComposedTree(Node& anch
or, int offset, TextAffinity affinity = TextAffinity::Downstream) |
21 { | 21 { |
22 return PositionInComposedTreeWithAffinity(canonicalPositionOf(PositionInComp
osedTree(&anchor, offset)), affinity); | 22 return PositionInComposedTreeWithAffinity(canonicalPositionOf(PositionInComp
osedTree(&anchor, offset)), affinity); |
23 } | 23 } |
24 | 24 |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 class VisibleUnitsTest : public EditingTestBase { | 27 class VisibleUnitsTest : public EditingTestBase { |
28 }; | 28 }; |
29 | 29 |
| 30 TEST_F(VisibleUnitsTest, absoluteCaretBoundsOf) |
| 31 { |
| 32 const char* bodyContent = "<p id='host'><b id='one'>11</b><b id='two'>22</b>
</p>"; |
| 33 const char* shadowContent = "<div><content select=#two></content><content se
lect=#one></content></div>"; |
| 34 setBodyContent(bodyContent); |
| 35 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
| 36 updateLayoutAndStyleForPainting(); |
| 37 |
| 38 RefPtrWillBeRawPtr<Element> body = document().body(); |
| 39 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); |
| 40 |
| 41 IntRect boundsInDOMTree = absoluteCaretBoundsOf(createVisiblePosition(Positi
on(one.get(), 0))); |
| 42 IntRect boundsInComposedTree = absoluteCaretBoundsOf(createVisiblePosition(P
ositionInComposedTree(one.get(), 0))); |
| 43 |
| 44 EXPECT_FALSE(boundsInDOMTree.isEmpty()); |
| 45 EXPECT_EQ(boundsInDOMTree, boundsInComposedTree); |
| 46 } |
| 47 |
30 TEST_F(VisibleUnitsTest, inSameLine) | 48 TEST_F(VisibleUnitsTest, inSameLine) |
31 { | 49 { |
32 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; | 50 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; |
33 const char* shadowContent = "<div><span id='s4'>44</span><content select=#tw
o></content><br><span id='s5'>55</span><br><content select=#one></content><span
id='s6'>66</span></div>"; | 51 const char* shadowContent = "<div><span id='s4'>44</span><content select=#tw
o></content><br><span id='s5'>55</span><br><content select=#one></content><span
id='s6'>66</span></div>"; |
34 setBodyContent(bodyContent); | 52 setBodyContent(bodyContent); |
35 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); | 53 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
36 updateLayoutAndStyleForPainting(); | 54 updateLayoutAndStyleForPainting(); |
37 | 55 |
38 RefPtrWillBeRawPtr<Element> body = document().body(); | 56 RefPtrWillBeRawPtr<Element> body = document().body(); |
39 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); | 57 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 setBodyContent(bodyContent); | 139 setBodyContent(bodyContent); |
122 updateLayoutAndStyleForPainting(); | 140 updateLayoutAndStyleForPainting(); |
123 RefPtrWillBeRawPtr<Element> sample1 = document().getElementById("sample1"); | 141 RefPtrWillBeRawPtr<Element> sample1 = document().getElementById("sample1"); |
124 RefPtrWillBeRawPtr<Element> sample2 = document().getElementById("sample2"); | 142 RefPtrWillBeRawPtr<Element> sample2 = document().getElementById("sample2"); |
125 | 143 |
126 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample1->firstCh
ild()), Position(sample2->firstChild(), 0))); | 144 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample1->firstCh
ild()), Position(sample2->firstChild(), 0))); |
127 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample1
->firstChild()), Position(sample2->firstChild(), 0))); | 145 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample1
->firstChild()), Position(sample2->firstChild(), 0))); |
128 } | 146 } |
129 | 147 |
130 } // namespace blink | 148 } // namespace blink |
OLD | NEW |