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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 .SetBaseAndExtent(EphemeralRange( | 64 .SetBaseAndExtent(EphemeralRange( |
65 Position(text, 3), Position(text, 6))) | 65 Position(text, 3), Position(text, 6))) |
66 .Build(), | 66 .Build(), |
67 0); | 67 0); |
68 sample->setAttribute(HTMLNames::styleAttr, "display:none"); | 68 sample->setAttribute(HTMLNames::styleAttr, "display:none"); |
69 // Move |VisibleSelection| before "abc". | 69 // Move |VisibleSelection| before "abc". |
70 UpdateAllLifecyclePhases(); | 70 UpdateAllLifecyclePhases(); |
71 const EphemeralRange& range = | 71 const EphemeralRange& range = |
72 FirstEphemeralRangeOf(Selection().ComputeVisibleSelectionInDOMTree()); | 72 FirstEphemeralRangeOf(Selection().ComputeVisibleSelectionInDOMTree()); |
73 EXPECT_EQ(Position(sample->nextSibling(), 0), range.StartPosition()) | 73 EXPECT_EQ(Position(sample->nextSibling(), 0), range.StartPosition()) |
74 << "firstRagne() should return current selection value"; | 74 << "firstRange() should return current selection value"; |
75 EXPECT_EQ(Position(sample->nextSibling(), 0), range.EndPosition()); | 75 EXPECT_EQ(Position(sample->nextSibling(), 0), range.EndPosition()); |
76 } | 76 } |
77 | 77 |
78 TEST_F(FrameSelectionTest, SetValidSelection) { | 78 TEST_F(FrameSelectionTest, SetValidSelection) { |
79 Text* text = AppendTextNode("Hello, World!"); | 79 Text* text = AppendTextNode("Hello, World!"); |
80 GetDocument().View()->UpdateAllLifecyclePhases(); | 80 GetDocument().View()->UpdateAllLifecyclePhases(); |
81 Selection().SetSelection( | 81 Selection().SetSelection( |
82 SelectionInDOMTree::Builder() | 82 SelectionInDOMTree::Builder() |
83 .SetBaseAndExtent(Position(text, 0), Position(text, 5)) | 83 .SetBaseAndExtent(Position(text, 0), Position(text, 5)) |
84 .Build()); | 84 .Build()); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 SetBodyContent("<div id=sample>abc</div>"); | 275 SetBodyContent("<div id=sample>abc</div>"); |
276 Element* sample = GetDocument().getElementById("sample"); | 276 Element* sample = GetDocument().getElementById("sample"); |
277 const Position end_of_text(sample->firstChild(), 3); | 277 const Position end_of_text(sample->firstChild(), 3); |
278 Selection().SetSelection(SelectionInDOMTree::Builder() | 278 Selection().SetSelection(SelectionInDOMTree::Builder() |
279 .Collapse(end_of_text) | 279 .Collapse(end_of_text) |
280 .SetIsHandleVisible(false) | 280 .SetIsHandleVisible(false) |
281 .Build()); | 281 .Build()); |
282 EXPECT_FALSE(Selection().IsHandleVisible()); | 282 EXPECT_FALSE(Selection().IsHandleVisible()); |
283 Selection().SelectAll(); | 283 Selection().SelectAll(); |
284 EXPECT_FALSE(Selection().IsHandleVisible()) | 284 EXPECT_FALSE(Selection().IsHandleVisible()) |
285 << "If handles weren't present before" | 285 << "If handles weren't present before " |
286 "selectAll. Then they shouldn't be present" | 286 "selectAll. Then they shouldn't be present " |
287 "after it."; | 287 "after it."; |
288 | 288 |
289 Selection().SetSelection(SelectionInDOMTree::Builder() | 289 Selection().SetSelection(SelectionInDOMTree::Builder() |
290 .Collapse(end_of_text) | 290 .Collapse(end_of_text) |
291 .SetIsHandleVisible(true) | 291 .SetIsHandleVisible(true) |
292 .Build()); | 292 .Build()); |
293 EXPECT_TRUE(Selection().IsHandleVisible()); | 293 EXPECT_TRUE(Selection().IsHandleVisible()); |
294 Selection().SelectAll(); | 294 Selection().SelectAll(); |
295 EXPECT_TRUE(Selection().IsHandleVisible()) | 295 EXPECT_TRUE(Selection().IsHandleVisible()) |
296 << "If handles were present before" | 296 << "If handles were present before " |
297 "selectAll. Then they should be present" | 297 "selectAll. Then they should be present " |
298 "after it."; | 298 "after it."; |
299 } | 299 } |
300 | 300 |
| 301 TEST_F(FrameSelectionTest, BoldCommandPreservesHandle) { |
| 302 SetBodyContent("<div id=sample>abc</div>"); |
| 303 Element* sample = GetDocument().getElementById("sample"); |
| 304 const Position end_of_text(sample->firstChild(), 3); |
| 305 Selection().SetSelection(SelectionInDOMTree::Builder() |
| 306 .Collapse(end_of_text) |
| 307 .SetIsHandleVisible(false) |
| 308 .Build()); |
| 309 EXPECT_FALSE(Selection().IsHandleVisible()); |
| 310 Selection().SelectAll(); |
| 311 GetDocument().execCommand("bold", false, "", ASSERT_NO_EXCEPTION); |
| 312 EXPECT_FALSE(Selection().IsHandleVisible()) |
| 313 << "If handles weren't present before " |
| 314 "bold command. Then they shouldn't " |
| 315 "be present after it."; |
| 316 |
| 317 Selection().SetSelection(SelectionInDOMTree::Builder() |
| 318 .Collapse(end_of_text) |
| 319 .SetIsHandleVisible(true) |
| 320 .Build()); |
| 321 EXPECT_TRUE(Selection().IsHandleVisible()); |
| 322 Selection().SelectAll(); |
| 323 GetDocument().execCommand("bold", false, "", ASSERT_NO_EXCEPTION); |
| 324 EXPECT_TRUE(Selection().IsHandleVisible()) |
| 325 << "If handles were present before " |
| 326 "bold command. Then they should " |
| 327 "be present after it."; |
| 328 } |
| 329 |
301 TEST_F(FrameSelectionTest, SelectionOnRangeHidesHandles) { | 330 TEST_F(FrameSelectionTest, SelectionOnRangeHidesHandles) { |
302 Text* text = AppendTextNode("Hello, World!"); | 331 Text* text = AppendTextNode("Hello, World!"); |
303 GetDocument().View()->UpdateAllLifecyclePhases(); | 332 GetDocument().View()->UpdateAllLifecyclePhases(); |
304 Selection().SetSelection( | 333 Selection().SetSelection( |
305 SelectionInDOMTree::Builder() | 334 SelectionInDOMTree::Builder() |
306 .SetBaseAndExtent(Position(text, 0), Position(text, 5)) | 335 .SetBaseAndExtent(Position(text, 0), Position(text, 5)) |
307 .SetIsHandleVisible(false) | 336 .SetIsHandleVisible(false) |
308 .Build()); | 337 .Build()); |
309 | 338 |
310 Selection().SetSelection(SelectionInDOMTree::Builder() | 339 Selection().SetSelection(SelectionInDOMTree::Builder() |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 EXPECT_FALSE(Selection().IsHidden()); | 957 EXPECT_FALSE(Selection().IsHidden()); |
929 | 958 |
930 Element* const alink = GetDocument().getElementById("alink"); | 959 Element* const alink = GetDocument().getElementById("alink"); |
931 alink->focus(); | 960 alink->focus(); |
932 EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsRange()); | 961 EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsRange()); |
933 EXPECT_FALSE(Selection().SelectionHasFocus()); | 962 EXPECT_FALSE(Selection().SelectionHasFocus()); |
934 EXPECT_FALSE(Selection().IsHidden()); // Range still visible. | 963 EXPECT_FALSE(Selection().IsHidden()); // Range still visible. |
935 } | 964 } |
936 | 965 |
937 } // namespace blink | 966 } // namespace blink |
OLD | NEW |