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/FrameSelection.h" | 5 #include "core/editing/FrameSelection.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/dom/Element.h" | 10 #include "core/dom/Element.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 Text* FrameSelectionTest::AppendTextNode(const String& data) { | 53 Text* FrameSelectionTest::AppendTextNode(const String& data) { |
54 Text* text = GetDocument().createTextNode(data); | 54 Text* text = GetDocument().createTextNode(data); |
55 GetDocument().body()->AppendChild(text); | 55 GetDocument().body()->AppendChild(text); |
56 return text; | 56 return text; |
57 } | 57 } |
58 | 58 |
59 TEST_F(FrameSelectionTest, FirstEphemeralRangeOf) { | 59 TEST_F(FrameSelectionTest, FirstEphemeralRangeOf) { |
60 SetBodyContent("<div id=sample>0123456789</div>abc"); | 60 SetBodyContent("<div id=sample>0123456789</div>abc"); |
61 Element* const sample = GetDocument().getElementById("sample"); | 61 Element* const sample = GetDocument().getElementById("sample"); |
62 Node* const text = sample->firstChild(); | 62 Node* const text = sample->firstChild(); |
63 Selection().SetSelectedRange( | 63 Selection().SetSelection(SelectionInDOMTree::Builder() |
64 EphemeralRange(Position(text, 3), Position(text, 6)), VP_DEFAULT_AFFINITY, | 64 .SetBaseAndExtent(EphemeralRange( |
65 SelectionDirectionalMode::kNonDirectional, 0); | 65 Position(text, 3), Position(text, 6))) |
| 66 .Build(), |
| 67 0); |
66 sample->setAttribute(HTMLNames::styleAttr, "display:none"); | 68 sample->setAttribute(HTMLNames::styleAttr, "display:none"); |
67 // Move |VisibleSelection| before "abc". | 69 // Move |VisibleSelection| before "abc". |
68 UpdateAllLifecyclePhases(); | 70 UpdateAllLifecyclePhases(); |
69 const EphemeralRange& range = | 71 const EphemeralRange& range = |
70 FirstEphemeralRangeOf(Selection().ComputeVisibleSelectionInDOMTree()); | 72 FirstEphemeralRangeOf(Selection().ComputeVisibleSelectionInDOMTree()); |
71 EXPECT_EQ(Position(sample->nextSibling(), 0), range.StartPosition()) | 73 EXPECT_EQ(Position(sample->nextSibling(), 0), range.StartPosition()) |
72 << "firstRagne() should return current selection value"; | 74 << "firstRagne() should return current selection value"; |
73 EXPECT_EQ(Position(sample->nextSibling(), 0), range.EndPosition()); | 75 EXPECT_EQ(Position(sample->nextSibling(), 0), range.EndPosition()); |
74 } | 76 } |
75 | 77 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 .SetIsHandleVisible(true) | 291 .SetIsHandleVisible(true) |
290 .Build()); | 292 .Build()); |
291 EXPECT_TRUE(Selection().IsHandleVisible()); | 293 EXPECT_TRUE(Selection().IsHandleVisible()); |
292 Selection().SelectAll(); | 294 Selection().SelectAll(); |
293 EXPECT_TRUE(Selection().IsHandleVisible()) | 295 EXPECT_TRUE(Selection().IsHandleVisible()) |
294 << "If handles were present before" | 296 << "If handles were present before" |
295 "selectAll. Then they should be present" | 297 "selectAll. Then they should be present" |
296 "after it."; | 298 "after it."; |
297 } | 299 } |
298 | 300 |
299 TEST_F(FrameSelectionTest, SetSelectedRangeHidesHandle) { | 301 TEST_F(FrameSelectionTest, SelectionOnRangeHidesHandles) { |
300 Text* text = AppendTextNode("Hello, World!"); | 302 Text* text = AppendTextNode("Hello, World!"); |
301 GetDocument().View()->UpdateAllLifecyclePhases(); | 303 GetDocument().View()->UpdateAllLifecyclePhases(); |
302 Selection().SetSelection( | 304 Selection().SetSelection( |
303 SelectionInDOMTree::Builder() | 305 SelectionInDOMTree::Builder() |
304 .SetBaseAndExtent(Position(text, 0), Position(text, 5)) | 306 .SetBaseAndExtent(Position(text, 0), Position(text, 5)) |
305 .SetIsHandleVisible(false) | 307 .SetIsHandleVisible(false) |
306 .Build()); | 308 .Build()); |
307 | 309 |
308 Selection().SetSelectedRange( | 310 Selection().SetSelection(SelectionInDOMTree::Builder() |
309 EphemeralRange(Position(text, 0), Position(text, 12)), | 311 .SetBaseAndExtent(EphemeralRange( |
310 VP_DEFAULT_AFFINITY, SelectionDirectionalMode::kNonDirectional, 0); | 312 Position(text, 0), Position(text, 12))) |
| 313 .Build(), |
| 314 0); |
311 | 315 |
312 EXPECT_FALSE(Selection().IsHandleVisible()) | 316 EXPECT_FALSE(Selection().IsHandleVisible()) |
313 << "After SetSelectedRange handles shouldn't be present."; | 317 << "After SetSelection on Range, handles shouldn't be present."; |
314 | 318 |
315 Selection().SetSelection( | 319 Selection().SetSelection( |
316 SelectionInDOMTree::Builder() | 320 SelectionInDOMTree::Builder() |
317 .SetBaseAndExtent(Position(text, 0), Position(text, 5)) | 321 .SetBaseAndExtent(Position(text, 0), Position(text, 5)) |
318 .SetIsHandleVisible(true) | 322 .SetIsHandleVisible(true) |
319 .Build()); | 323 .Build()); |
320 | 324 |
321 Selection().SetSelectedRange( | 325 Selection().SetSelection(SelectionInDOMTree::Builder() |
322 EphemeralRange(Position(text, 0), Position(text, 12)), | 326 .SetBaseAndExtent(EphemeralRange( |
323 VP_DEFAULT_AFFINITY, SelectionDirectionalMode::kNonDirectional, 0); | 327 Position(text, 0), Position(text, 12))) |
| 328 .Build(), |
| 329 0); |
324 | 330 |
325 EXPECT_FALSE(Selection().IsHandleVisible()) | 331 EXPECT_FALSE(Selection().IsHandleVisible()) |
326 << "After SetSelectedRange handles shouldn't be present."; | 332 << "After SetSelection on Range, handles shouldn't be present."; |
327 } | 333 } |
328 | 334 |
329 // Regression test for crbug.com/702756 | 335 // Regression test for crbug.com/702756 |
330 // Test case excerpted from editing/undo/redo_correct_selection.html | 336 // Test case excerpted from editing/undo/redo_correct_selection.html |
331 TEST_F(FrameSelectionTest, SelectInvalidPositionInFlatTreeDoesntCrash) { | 337 TEST_F(FrameSelectionTest, SelectInvalidPositionInFlatTreeDoesntCrash) { |
332 SetBodyContent("foo<option><select></select></option>"); | 338 SetBodyContent("foo<option><select></select></option>"); |
333 Element* body = GetDocument().body(); | 339 Element* body = GetDocument().body(); |
334 Element* select = GetDocument().QuerySelector("select"); | 340 Element* select = GetDocument().QuerySelector("select"); |
335 Node* foo = body->firstChild(); | 341 Node* foo = body->firstChild(); |
336 Selection().SetSelection(SelectionInDOMTree::Builder() | 342 Selection().SetSelection(SelectionInDOMTree::Builder() |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 EXPECT_FALSE(Selection().IsHidden()); | 928 EXPECT_FALSE(Selection().IsHidden()); |
923 | 929 |
924 Element* const alink = GetDocument().getElementById("alink"); | 930 Element* const alink = GetDocument().getElementById("alink"); |
925 alink->focus(); | 931 alink->focus(); |
926 EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsRange()); | 932 EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsRange()); |
927 EXPECT_FALSE(Selection().SelectionHasFocus()); | 933 EXPECT_FALSE(Selection().SelectionHasFocus()); |
928 EXPECT_FALSE(Selection().IsHidden()); // Range still visible. | 934 EXPECT_FALSE(Selection().IsHidden()); // Range still visible. |
929 } | 935 } |
930 | 936 |
931 } // namespace blink | 937 } // namespace blink |
OLD | NEW |