| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/VisibleSelection.h" | 5 #include "core/editing/VisibleSelection.h" |
| 6 | 6 |
| 7 #include "core/dom/Range.h" | 7 #include "core/dom/Range.h" |
| 8 #include "core/editing/EditingTestBase.h" | 8 #include "core/editing/EditingTestBase.h" |
| 9 #include "core/editing/SelectionAdjuster.h" | 9 #include "core/editing/SelectionAdjuster.h" |
| 10 | 10 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 "id='s5'>55</span><content select=#one></content><span " | 205 "id='s5'>55</span><content select=#one></content><span " |
| 206 "id='s6'>66</span></a>"; | 206 "id='s6'>66</span></a>"; |
| 207 setBodyContent(bodyContent); | 207 setBodyContent(bodyContent); |
| 208 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 208 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
| 209 | 209 |
| 210 Element* body = document().body(); | 210 Element* body = document().body(); |
| 211 Element* host = body->querySelector("#host"); | 211 Element* host = body->querySelector("#host"); |
| 212 Element* one = body->querySelector("#one"); | 212 Element* one = body->querySelector("#one"); |
| 213 Element* six = shadowRoot->querySelector("#s6"); | 213 Element* six = shadowRoot->querySelector("#s6"); |
| 214 | 214 |
| 215 VisibleSelection selection = | 215 VisibleSelection selection = createVisibleSelection( |
| 216 createVisibleSelection(Position::firstPositionInNode(one), | 216 SelectionInDOMTree::Builder() |
| 217 Position::lastPositionInNode(shadowRoot)); | 217 .collapse(Position::firstPositionInNode(one)) |
| 218 .extend(Position::lastPositionInNode(shadowRoot)) |
| 219 .build()); |
| 218 VisibleSelectionInFlatTree selectionInFlatTree = createVisibleSelection( | 220 VisibleSelectionInFlatTree selectionInFlatTree = createVisibleSelection( |
| 219 SelectionInFlatTree::Builder() | 221 SelectionInFlatTree::Builder() |
| 220 .collapse(PositionInFlatTree::firstPositionInNode(one)) | 222 .collapse(PositionInFlatTree::firstPositionInNode(one)) |
| 221 .extend(PositionInFlatTree::lastPositionInNode(host)) | 223 .extend(PositionInFlatTree::lastPositionInNode(host)) |
| 222 .build()); | 224 .build()); |
| 223 | 225 |
| 224 EXPECT_EQ(Position(host, PositionAnchorType::BeforeAnchor), | 226 EXPECT_EQ(Position(host, PositionAnchorType::BeforeAnchor), |
| 225 selection.start()); | 227 selection.start()); |
| 226 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); | 228 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); |
| 227 EXPECT_EQ(PositionInFlatTree(one->firstChild(), 0), | 229 EXPECT_EQ(PositionInFlatTree(one->firstChild(), 0), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 238 "id='s5'>55</span><content select=#one></content><span " | 240 "id='s5'>55</span><content select=#one></content><span " |
| 239 "id='s6'>66</span></a>"; | 241 "id='s6'>66</span></a>"; |
| 240 setBodyContent(bodyContent); | 242 setBodyContent(bodyContent); |
| 241 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 243 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
| 242 | 244 |
| 243 Element* body = document().body(); | 245 Element* body = document().body(); |
| 244 Element* one = body->querySelector("#one"); | 246 Element* one = body->querySelector("#one"); |
| 245 Element* two = body->querySelector("#two"); | 247 Element* two = body->querySelector("#two"); |
| 246 Element* five = shadowRoot->querySelector("#s5"); | 248 Element* five = shadowRoot->querySelector("#s5"); |
| 247 | 249 |
| 248 VisibleSelection selection = createVisibleSelection( | 250 VisibleSelection selection = |
| 249 Position::firstPositionInNode(one), Position::lastPositionInNode(two)); | 251 createVisibleSelection(SelectionInDOMTree::Builder() |
| 252 .collapse(Position::firstPositionInNode(one)) |
| 253 .extend(Position::lastPositionInNode(two)) |
| 254 .build()); |
| 250 VisibleSelectionInFlatTree selectionInFlatTree = createVisibleSelection( | 255 VisibleSelectionInFlatTree selectionInFlatTree = createVisibleSelection( |
| 251 SelectionInFlatTree::Builder() | 256 SelectionInFlatTree::Builder() |
| 252 .collapse(PositionInFlatTree::firstPositionInNode(one)) | 257 .collapse(PositionInFlatTree::firstPositionInNode(one)) |
| 253 .extend(PositionInFlatTree::lastPositionInNode(two)) | 258 .extend(PositionInFlatTree::lastPositionInNode(two)) |
| 254 .build()); | 259 .build()); |
| 255 | 260 |
| 256 EXPECT_EQ(Position(one->firstChild(), 0), selection.start()); | 261 EXPECT_EQ(Position(one->firstChild(), 0), selection.start()); |
| 257 EXPECT_EQ(Position(two->firstChild(), 2), selection.end()); | 262 EXPECT_EQ(Position(two->firstChild(), 2), selection.end()); |
| 258 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 0), | 263 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 0), |
| 259 selectionInFlatTree.start()); | 264 selectionInFlatTree.start()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 281 // <b id="two">22</b> | 286 // <b id="two">22</b> |
| 282 // <span id="s5"><span id="s7">77>55</span id="s8">88</span> | 287 // <span id="s5"><span id="s7">77>55</span id="s8">88</span> |
| 283 // <b id="one">11</b> | 288 // <b id="one">11</b> |
| 284 // <span id="s6">66</span> | 289 // <span id="s6">66</span> |
| 285 // </p> | 290 // </p> |
| 286 Element* body = document().body(); | 291 Element* body = document().body(); |
| 287 Element* host = body->querySelector("#host"); | 292 Element* host = body->querySelector("#host"); |
| 288 Element* one = body->querySelector("#one"); | 293 Element* one = body->querySelector("#one"); |
| 289 Element* eight = shadowRoot2->querySelector("#s8"); | 294 Element* eight = shadowRoot2->querySelector("#s8"); |
| 290 | 295 |
| 291 VisibleSelection selection = | 296 VisibleSelection selection = createVisibleSelection( |
| 292 createVisibleSelection(Position::firstPositionInNode(one), | 297 SelectionInDOMTree::Builder() |
| 293 Position::lastPositionInNode(shadowRoot2)); | 298 .collapse(Position::firstPositionInNode(one)) |
| 299 .extend(Position::lastPositionInNode(shadowRoot2)) |
| 300 .build()); |
| 294 VisibleSelectionInFlatTree selectionInFlatTree = createVisibleSelection( | 301 VisibleSelectionInFlatTree selectionInFlatTree = createVisibleSelection( |
| 295 SelectionInFlatTree::Builder() | 302 SelectionInFlatTree::Builder() |
| 296 .collapse(PositionInFlatTree::firstPositionInNode(one)) | 303 .collapse(PositionInFlatTree::firstPositionInNode(one)) |
| 297 .extend(PositionInFlatTree::afterNode(eight)) | 304 .extend(PositionInFlatTree::afterNode(eight)) |
| 298 .build()); | 305 .build()); |
| 299 | 306 |
| 300 EXPECT_EQ(Position(host, PositionAnchorType::BeforeAnchor), | 307 EXPECT_EQ(Position(host, PositionAnchorType::BeforeAnchor), |
| 301 selection.start()); | 308 selection.start()); |
| 302 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); | 309 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); |
| 303 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), | 310 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 selection.updateIfNeeded(); | 452 selection.updateIfNeeded(); |
| 446 EXPECT_EQ(Position(sample->firstChild(), 0), selection.start()); | 453 EXPECT_EQ(Position(sample->firstChild(), 0), selection.start()); |
| 447 | 454 |
| 448 VisibleSelectionInFlatTree selectionInFlatTree; | 455 VisibleSelectionInFlatTree selectionInFlatTree; |
| 449 SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection); | 456 SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection); |
| 450 EXPECT_EQ(PositionInFlatTree(sample->firstChild(), 0), | 457 EXPECT_EQ(PositionInFlatTree(sample->firstChild(), 0), |
| 451 selectionInFlatTree.start()); | 458 selectionInFlatTree.start()); |
| 452 } | 459 } |
| 453 | 460 |
| 454 } // namespace blink | 461 } // namespace blink |
| OLD | NEW |