| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 "<input type=checkbox>" | 77 "<input type=checkbox>" |
| 78 "<div style='user-select:none'>abc</div>"); | 78 "<div style='user-select:none'>abc</div>"); |
| 79 Element* const input = GetDocument().QuerySelector("input"); | 79 Element* const input = GetDocument().QuerySelector("input"); |
| 80 | 80 |
| 81 // Simulate double-clicking "abc". | 81 // Simulate double-clicking "abc". |
| 82 // TODO(editing-dev): We should remove above comment once we fix [1]. | 82 // TODO(editing-dev): We should remove above comment once we fix [1]. |
| 83 // [1] http://crbug.com/701657 double-click on user-select:none should not | 83 // [1] http://crbug.com/701657 double-click on user-select:none should not |
| 84 // compute selection. | 84 // compute selection. |
| 85 VisibleSelection selection = | 85 VisibleSelection selection = |
| 86 CreateVisibleSelection(SelectionInDOMTree::Builder() | 86 CreateVisibleSelection(SelectionInDOMTree::Builder() |
| 87 .Collapse(Position::BeforeNode(input)) | 87 .Collapse(Position::BeforeNode(*input)) |
| 88 .Extend(Position::AfterNode(input)) | 88 .Extend(Position::AfterNode(input)) |
| 89 .SetGranularity(kWordGranularity) | 89 .SetGranularity(kWordGranularity) |
| 90 .Build()); | 90 .Build()); |
| 91 selection.AppendTrailingWhitespace(); | 91 selection.AppendTrailingWhitespace(); |
| 92 | 92 |
| 93 EXPECT_EQ(Position::BeforeNode(input), selection.Start()); | 93 EXPECT_EQ(Position::BeforeNode(*input), selection.Start()); |
| 94 EXPECT_EQ(Position::AfterNode(input), selection.End()); | 94 EXPECT_EQ(Position::AfterNode(input), selection.End()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 TEST_F(VisibleSelectionTest, expandUsingGranularity) { | 97 TEST_F(VisibleSelectionTest, expandUsingGranularity) { |
| 98 const char* body_content = | 98 const char* body_content = |
| 99 "<span id=host><a id=one>1</a><a id=two>22</a></span>"; | 99 "<span id=host><a id=one>1</a><a id=two>22</a></span>"; |
| 100 const char* shadow_content = | 100 const char* shadow_content = |
| 101 "<p><b id=three>333</b><content select=#two></content><b " | 101 "<p><b id=three>333</b><content select=#two></content><b " |
| 102 "id=four>4444</b><span id=space> </span><content " | 102 "id=four>4444</b><span id=space> </span><content " |
| 103 "select=#one></content><b id=five>55555</b></p>"; | 103 "select=#one></content><b id=five>55555</b></p>"; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 Element* const html_element = GetDocument().documentElement(); | 250 Element* const html_element = GetDocument().documentElement(); |
| 251 Element* const input = GetDocument().QuerySelector("input"); | 251 Element* const input = GetDocument().QuerySelector("input"); |
| 252 Node* const last_child = GetDocument().body()->lastChild(); | 252 Node* const last_child = GetDocument().body()->lastChild(); |
| 253 | 253 |
| 254 const VisibleSelection& visible_selectin_in_dom_tree = CreateVisibleSelection( | 254 const VisibleSelection& visible_selectin_in_dom_tree = CreateVisibleSelection( |
| 255 SelectionInDOMTree::Builder() | 255 SelectionInDOMTree::Builder() |
| 256 .Collapse(Position::FirstPositionInNode(html_element)) | 256 .Collapse(Position::FirstPositionInNode(html_element)) |
| 257 .Extend(Position::LastPositionInNode(html_element)) | 257 .Extend(Position::LastPositionInNode(html_element)) |
| 258 .Build()); | 258 .Build()); |
| 259 EXPECT_EQ(SelectionInDOMTree::Builder() | 259 EXPECT_EQ(SelectionInDOMTree::Builder() |
| 260 .Collapse(Position::BeforeNode(input)) | 260 .Collapse(Position::BeforeNode(*input)) |
| 261 .Extend(Position(last_child, 3)) | 261 .Extend(Position(last_child, 3)) |
| 262 .Build(), | 262 .Build(), |
| 263 visible_selectin_in_dom_tree.AsSelection()); | 263 visible_selectin_in_dom_tree.AsSelection()); |
| 264 | 264 |
| 265 const VisibleSelectionInFlatTree& visible_selectin_in_flat_tree = | 265 const VisibleSelectionInFlatTree& visible_selectin_in_flat_tree = |
| 266 CreateVisibleSelection( | 266 CreateVisibleSelection( |
| 267 SelectionInFlatTree::Builder() | 267 SelectionInFlatTree::Builder() |
| 268 .Collapse(PositionInFlatTree::FirstPositionInNode(html_element)) | 268 .Collapse(PositionInFlatTree::FirstPositionInNode(html_element)) |
| 269 .Extend(PositionInFlatTree::LastPositionInNode(html_element)) | 269 .Extend(PositionInFlatTree::LastPositionInNode(html_element)) |
| 270 .Build()); | 270 .Build()); |
| 271 EXPECT_EQ(SelectionInFlatTree::Builder() | 271 EXPECT_EQ(SelectionInFlatTree::Builder() |
| 272 .Collapse(PositionInFlatTree::BeforeNode(input)) | 272 .Collapse(PositionInFlatTree::BeforeNode(*input)) |
| 273 .Extend(PositionInFlatTree(last_child, 3)) | 273 .Extend(PositionInFlatTree(last_child, 3)) |
| 274 .Build(), | 274 .Build(), |
| 275 visible_selectin_in_flat_tree.AsSelection()); | 275 visible_selectin_in_flat_tree.AsSelection()); |
| 276 } | 276 } |
| 277 | 277 |
| 278 TEST_F(VisibleSelectionTest, ShadowCrossing) { | 278 TEST_F(VisibleSelectionTest, ShadowCrossing) { |
| 279 const char* body_content = | 279 const char* body_content = |
| 280 "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>"; | 280 "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>"; |
| 281 const char* shadow_content = | 281 const char* shadow_content = |
| 282 "<a><span id='s4'>44</span><content select=#two></content><span " | 282 "<a><span id='s4'>44</span><content select=#two></content><span " |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 Element* host = GetDocument().getElementById("host"); | 532 Element* host = GetDocument().getElementById("host"); |
| 533 host->AppendChild(sample); | 533 host->AppendChild(sample); |
| 534 GetDocument().UpdateStyleAndLayout(); | 534 GetDocument().UpdateStyleAndLayout(); |
| 535 | 535 |
| 536 // Simulates to restore selection from undo stack. | 536 // Simulates to restore selection from undo stack. |
| 537 selection = CreateVisibleSelection(selection.AsSelection()); | 537 selection = CreateVisibleSelection(selection.AsSelection()); |
| 538 EXPECT_EQ(Position(sample->firstChild(), 0), selection.Start()); | 538 EXPECT_EQ(Position(sample->firstChild(), 0), selection.Start()); |
| 539 } | 539 } |
| 540 | 540 |
| 541 } // namespace blink | 541 } // namespace blink |
| OLD | NEW |