| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // Select "two" for selection in DOM tree | 166 // Select "two" for selection in DOM tree |
| 167 // Select "twoone" for selection in Flat tree | 167 // Select "twoone" for selection in Flat tree |
| 168 Selection().SetSelection( | 168 Selection().SetSelection( |
| 169 SelectionInFlatTree::Builder() | 169 SelectionInFlatTree::Builder() |
| 170 .Collapse(PositionInFlatTree(host, 0)) | 170 .Collapse(PositionInFlatTree(host, 0)) |
| 171 .Extend(PositionInFlatTree(GetDocument().body(), 2)) | 171 .Extend(PositionInFlatTree(GetDocument().body(), 2)) |
| 172 .Build()); | 172 .Build()); |
| 173 Selection().Modify(FrameSelection::kAlterationExtend, kDirectionForward, | 173 Selection().Modify(FrameSelection::kAlterationExtend, kDirectionForward, |
| 174 kWordGranularity); | 174 kWordGranularity); |
| 175 EXPECT_EQ(Position(two, 0), VisibleSelectionInDOMTree().Start()); | 175 EXPECT_EQ(Position(two, 0), VisibleSelectionInDOMTree().Start()); |
| 176 EXPECT_EQ(Position(two, 3), VisibleSelectionInDOMTree().end()); | 176 EXPECT_EQ(Position(two, 3), VisibleSelectionInDOMTree().End()); |
| 177 EXPECT_EQ(PositionInFlatTree(two, 0), | 177 EXPECT_EQ(PositionInFlatTree(two, 0), |
| 178 GetVisibleSelectionInFlatTree().Start()); | 178 GetVisibleSelectionInFlatTree().Start()); |
| 179 EXPECT_EQ(PositionInFlatTree(two, 3), GetVisibleSelectionInFlatTree().end()); | 179 EXPECT_EQ(PositionInFlatTree(two, 3), GetVisibleSelectionInFlatTree().End()); |
| 180 } | 180 } |
| 181 | 181 |
| 182 TEST_F(FrameSelectionTest, ModifyWithUserTriggered) { | 182 TEST_F(FrameSelectionTest, ModifyWithUserTriggered) { |
| 183 SetBodyContent("<div id=sample>abc</div>"); | 183 SetBodyContent("<div id=sample>abc</div>"); |
| 184 Element* sample = GetDocument().getElementById("sample"); | 184 Element* sample = GetDocument().getElementById("sample"); |
| 185 const Position end_of_text(sample->firstChild(), 3); | 185 const Position end_of_text(sample->firstChild(), 3); |
| 186 Selection().SetSelection( | 186 Selection().SetSelection( |
| 187 SelectionInDOMTree::Builder().Collapse(end_of_text).Build()); | 187 SelectionInDOMTree::Builder().Collapse(end_of_text).Build()); |
| 188 | 188 |
| 189 EXPECT_FALSE(Selection().Modify(FrameSelection::kAlterationMove, | 189 EXPECT_FALSE(Selection().Modify(FrameSelection::kAlterationMove, |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 EXPECT_FALSE(Selection().IsHidden()); | 957 EXPECT_FALSE(Selection().IsHidden()); |
| 958 | 958 |
| 959 Element* const alink = GetDocument().getElementById("alink"); | 959 Element* const alink = GetDocument().getElementById("alink"); |
| 960 alink->focus(); | 960 alink->focus(); |
| 961 EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsRange()); | 961 EXPECT_TRUE(Selection().GetSelectionInDOMTree().IsRange()); |
| 962 EXPECT_FALSE(Selection().SelectionHasFocus()); | 962 EXPECT_FALSE(Selection().SelectionHasFocus()); |
| 963 EXPECT_FALSE(Selection().IsHidden()); // Range still visible. | 963 EXPECT_FALSE(Selection().IsHidden()); // Range still visible. |
| 964 } | 964 } |
| 965 | 965 |
| 966 } // namespace blink | 966 } // namespace blink |
| OLD | NEW |