| 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 "bindings/core/v8/ExceptionStatePlaceholder.h" | 7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/Element.h" | 9 #include "core/dom/Element.h" |
| 10 #include "core/dom/Text.h" | 10 #include "core/dom/Text.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 document().body()->setContentEditable("true", ASSERT_NO_EXCEPTION); | 135 document().body()->setContentEditable("true", ASSERT_NO_EXCEPTION); |
| 136 document().body()->focus(); | 136 document().body()->focus(); |
| 137 EXPECT_TRUE(document().body()->focused()); | 137 EXPECT_TRUE(document().body()->focused()); |
| 138 | 138 |
| 139 selection().setCaretVisible(true); | 139 selection().setCaretVisible(true); |
| 140 EXPECT_TRUE(selection().isCaret()); | 140 EXPECT_TRUE(selection().isCaret()); |
| 141 EXPECT_TRUE(shouldPaintCaretForTesting()); | 141 EXPECT_TRUE(shouldPaintCaretForTesting()); |
| 142 | 142 |
| 143 // Simulate to type "Hello, World!". | 143 // Simulate to type "Hello, World!". |
| 144 DisableCompositingQueryAsserts disabler; | 144 DisableCompositingQueryAsserts disabler; |
| 145 selection().moveTo(createVisiblePosition(selection().end(), selection().affi
nity()), NotUserTriggered); | 145 selection().moveTo(createVisiblePositionDeprecated(selection().end(), select
ion().affinity()), NotUserTriggered); |
| 146 selection().setCaretRectNeedsUpdate(); | 146 selection().setCaretRectNeedsUpdate(); |
| 147 EXPECT_TRUE(selection().isCaretBoundsDirty()); | 147 EXPECT_TRUE(selection().isCaretBoundsDirty()); |
| 148 EXPECT_FALSE(isPreviousCaretDirtyForTesting()); | 148 EXPECT_FALSE(isPreviousCaretDirtyForTesting()); |
| 149 selection().invalidateCaretRect(); | 149 selection().invalidateCaretRect(); |
| 150 EXPECT_FALSE(selection().isCaretBoundsDirty()); | 150 EXPECT_FALSE(selection().isCaretBoundsDirty()); |
| 151 EXPECT_TRUE(isPreviousCaretDirtyForTesting()); | 151 EXPECT_TRUE(isPreviousCaretDirtyForTesting()); |
| 152 | 152 |
| 153 // Simulate to remove all except for "H". | 153 // Simulate to remove all except for "H". |
| 154 text->replaceWholeText("H"); | 154 text->replaceWholeText("H"); |
| 155 selection().moveTo(createVisiblePosition(selection().end(), selection().affi
nity()), NotUserTriggered); | 155 selection().moveTo(createVisiblePositionDeprecated(selection().end(), select
ion().affinity()), NotUserTriggered); |
| 156 selection().setCaretRectNeedsUpdate(); | 156 selection().setCaretRectNeedsUpdate(); |
| 157 EXPECT_TRUE(selection().isCaretBoundsDirty()); | 157 EXPECT_TRUE(selection().isCaretBoundsDirty()); |
| 158 // "H" remains so early previousCaret invalidation isn't needed. | 158 // "H" remains so early previousCaret invalidation isn't needed. |
| 159 EXPECT_TRUE(isPreviousCaretDirtyForTesting()); | 159 EXPECT_TRUE(isPreviousCaretDirtyForTesting()); |
| 160 selection().invalidateCaretRect(); | 160 selection().invalidateCaretRect(); |
| 161 EXPECT_FALSE(selection().isCaretBoundsDirty()); | 161 EXPECT_FALSE(selection().isCaretBoundsDirty()); |
| 162 EXPECT_TRUE(isPreviousCaretDirtyForTesting()); | 162 EXPECT_TRUE(isPreviousCaretDirtyForTesting()); |
| 163 | 163 |
| 164 // Simulate to remove the last character. | 164 // Simulate to remove the last character. |
| 165 document().body()->removeChild(text); | 165 document().body()->removeChild(text); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 176 } | 176 } |
| 177 | 177 |
| 178 #define EXPECT_EQ_SELECTED_TEXT(text) \ | 178 #define EXPECT_EQ_SELECTED_TEXT(text) \ |
| 179 EXPECT_EQ(text, WebString(selection().selectedText()).utf8()) | 179 EXPECT_EQ(text, WebString(selection().selectedText()).utf8()) |
| 180 | 180 |
| 181 TEST_F(FrameSelectionTest, SelectWordAroundPosition) | 181 TEST_F(FrameSelectionTest, SelectWordAroundPosition) |
| 182 { | 182 { |
| 183 // "Foo Bar Baz," | 183 // "Foo Bar Baz," |
| 184 Text* text = appendTextNode("Foo Bar Baz,"); | 184 Text* text = appendTextNode("Foo Bar Baz,"); |
| 185 // "Fo|o Bar Baz," | 185 // "Fo|o Bar Baz," |
| 186 EXPECT_TRUE(selection().selectWordAroundPosition(createVisiblePosition(Posit
ion(text, 2)))); | 186 EXPECT_TRUE(selection().selectWordAroundPosition(createVisiblePositionDeprec
ated(Position(text, 2)))); |
| 187 EXPECT_EQ_SELECTED_TEXT("Foo"); | 187 EXPECT_EQ_SELECTED_TEXT("Foo"); |
| 188 // "Foo| Bar Baz," | 188 // "Foo| Bar Baz," |
| 189 EXPECT_TRUE(selection().selectWordAroundPosition(createVisiblePosition(Posit
ion(text, 3)))); | 189 EXPECT_TRUE(selection().selectWordAroundPosition(createVisiblePositionDeprec
ated(Position(text, 3)))); |
| 190 EXPECT_EQ_SELECTED_TEXT("Foo"); | 190 EXPECT_EQ_SELECTED_TEXT("Foo"); |
| 191 // "Foo Bar | Baz," | 191 // "Foo Bar | Baz," |
| 192 EXPECT_FALSE(selection().selectWordAroundPosition(createVisiblePosition(Posi
tion(text, 13)))); | 192 EXPECT_FALSE(selection().selectWordAroundPosition(createVisiblePositionDepre
cated(Position(text, 13)))); |
| 193 // "Foo Bar Baz|," | 193 // "Foo Bar Baz|," |
| 194 EXPECT_TRUE(selection().selectWordAroundPosition(createVisiblePosition(Posit
ion(text, 22)))); | 194 EXPECT_TRUE(selection().selectWordAroundPosition(createVisiblePositionDeprec
ated(Position(text, 22)))); |
| 195 EXPECT_EQ_SELECTED_TEXT("Baz"); | 195 EXPECT_EQ_SELECTED_TEXT("Baz"); |
| 196 } | 196 } |
| 197 | 197 |
| 198 TEST_F(FrameSelectionTest, ModifyExtendWithFlatTree) | 198 TEST_F(FrameSelectionTest, ModifyExtendWithFlatTree) |
| 199 { | 199 { |
| 200 setBodyContent("<span id=host></span>one"); | 200 setBodyContent("<span id=host></span>one"); |
| 201 setShadowContent("two<content></content>", "host"); | 201 setShadowContent("two<content></content>", "host"); |
| 202 Element* host = document().getElementById("host"); | 202 Element* host = document().getElementById("host"); |
| 203 Node* const two = FlatTreeTraversal::firstChild(*host); | 203 Node* const two = FlatTreeTraversal::firstChild(*host); |
| 204 // Select "two" for selection in DOM tree | 204 // Select "two" for selection in DOM tree |
| (...skipping 26 matching lines...) Expand all Loading... |
| 231 | 231 |
| 232 TEST_F(FrameSelectionTest, MoveRangeSelectionTest) | 232 TEST_F(FrameSelectionTest, MoveRangeSelectionTest) |
| 233 { | 233 { |
| 234 // "Foo Bar Baz," | 234 // "Foo Bar Baz," |
| 235 Text* text = appendTextNode("Foo Bar Baz,"); | 235 Text* text = appendTextNode("Foo Bar Baz,"); |
| 236 // Itinitializes with "Foo B|a>r Baz," (| means start and > means end). | 236 // Itinitializes with "Foo B|a>r Baz," (| means start and > means end). |
| 237 selection().setSelection(VisibleSelection(Position(text, 5), Position(text,
6))); | 237 selection().setSelection(VisibleSelection(Position(text, 5), Position(text,
6))); |
| 238 EXPECT_EQ_SELECTED_TEXT("a"); | 238 EXPECT_EQ_SELECTED_TEXT("a"); |
| 239 | 239 |
| 240 // "Foo B|ar B>az," with the Character granularity. | 240 // "Foo B|ar B>az," with the Character granularity. |
| 241 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre
ateVisiblePosition(Position(text, 9)), CharacterGranularity); | 241 selection().moveRangeSelection(createVisiblePositionDeprecated(Position(text
, 5)), createVisiblePositionDeprecated(Position(text, 9)), CharacterGranularity)
; |
| 242 EXPECT_EQ_SELECTED_TEXT("ar B"); | 242 EXPECT_EQ_SELECTED_TEXT("ar B"); |
| 243 // "Foo B|ar B>az," with the Word granularity. | 243 // "Foo B|ar B>az," with the Word granularity. |
| 244 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre
ateVisiblePosition(Position(text, 9)), WordGranularity); | 244 selection().moveRangeSelection(createVisiblePositionDeprecated(Position(text
, 5)), createVisiblePositionDeprecated(Position(text, 9)), WordGranularity); |
| 245 EXPECT_EQ_SELECTED_TEXT("Bar Baz"); | 245 EXPECT_EQ_SELECTED_TEXT("Bar Baz"); |
| 246 // "Fo<o B|ar Baz," with the Character granularity. | 246 // "Fo<o B|ar Baz," with the Character granularity. |
| 247 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre
ateVisiblePosition(Position(text, 2)), CharacterGranularity); | 247 selection().moveRangeSelection(createVisiblePositionDeprecated(Position(text
, 5)), createVisiblePositionDeprecated(Position(text, 2)), CharacterGranularity)
; |
| 248 EXPECT_EQ_SELECTED_TEXT("o B"); | 248 EXPECT_EQ_SELECTED_TEXT("o B"); |
| 249 // "Fo<o B|ar Baz," with the Word granularity. | 249 // "Fo<o B|ar Baz," with the Word granularity. |
| 250 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre
ateVisiblePosition(Position(text, 2)), WordGranularity); | 250 selection().moveRangeSelection(createVisiblePositionDeprecated(Position(text
, 5)), createVisiblePositionDeprecated(Position(text, 2)), WordGranularity); |
| 251 EXPECT_EQ_SELECTED_TEXT("Foo Bar"); | 251 EXPECT_EQ_SELECTED_TEXT("Foo Bar"); |
| 252 } | 252 } |
| 253 | 253 |
| 254 TEST_F(FrameSelectionTest, setNonDirectionalSelectionIfNeeded) | 254 TEST_F(FrameSelectionTest, setNonDirectionalSelectionIfNeeded) |
| 255 { | 255 { |
| 256 const char* bodyContent = "<span id=top>top</span><span id=host></span>"; | 256 const char* bodyContent = "<span id=top>top</span><span id=host></span>"; |
| 257 const char* shadowContent = "<span id=bottom>bottom</span>"; | 257 const char* shadowContent = "<span id=bottom>bottom</span>"; |
| 258 setBodyContent(bodyContent); | 258 setBodyContent(bodyContent); |
| 259 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 259 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
| 260 | 260 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 selection().updateIfNeeded(); | 311 selection().updateIfNeeded(); |
| 312 | 312 |
| 313 // TODO(yosin): Once lazy canonicalization implemented, selection.start | 313 // TODO(yosin): Once lazy canonicalization implemented, selection.start |
| 314 // should be Position(HTML, 0). | 314 // should be Position(HTML, 0). |
| 315 EXPECT_EQ(Position(), selection().start()) | 315 EXPECT_EQ(Position(), selection().start()) |
| 316 << "updateIfNeeded() makes selection to null."; | 316 << "updateIfNeeded() makes selection to null."; |
| 317 EXPECT_EQ(selection().start(), caretPosition().position()); | 317 EXPECT_EQ(selection().start(), caretPosition().position()); |
| 318 } | 318 } |
| 319 | 319 |
| 320 } // namespace blink | 320 } // namespace blink |
| OLD | NEW |