| 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()->focus(); | 135 document().body()->focus(); |
| 136 EXPECT_TRUE(document().body()->isFocused()); | 136 EXPECT_TRUE(document().body()->isFocused()); |
| 137 | 137 |
| 138 selection().setCaretVisible(true); | 138 selection().setCaretVisible(true); |
| 139 EXPECT_TRUE(selection().isCaret()); | 139 EXPECT_TRUE(selection().isCaret()); |
| 140 EXPECT_TRUE(shouldPaintCaretForTesting()); | 140 EXPECT_TRUE(shouldPaintCaretForTesting()); |
| 141 | 141 |
| 142 // Simulate to type "Hello, World!". | 142 // Simulate to type "Hello, World!". |
| 143 DisableCompositingQueryAsserts disabler; | 143 DisableCompositingQueryAsserts disabler; |
| 144 document().updateStyleAndLayout(); | 144 document().updateStyleAndLayout(); |
| 145 selection().moveTo( | 145 selection().setSelection( |
| 146 createVisiblePosition(selection().end(), selection().affinity()), | 146 SelectionInDOMTree::Builder().collapse(selection().end()).build()); |
| 147 NotUserTriggered); | |
| 148 selection().setCaretRectNeedsUpdate(); | 147 selection().setCaretRectNeedsUpdate(); |
| 149 EXPECT_TRUE(selection().isCaretBoundsDirty()); | 148 EXPECT_TRUE(selection().isCaretBoundsDirty()); |
| 150 EXPECT_FALSE(isPreviousCaretDirtyForTesting()); | 149 EXPECT_FALSE(isPreviousCaretDirtyForTesting()); |
| 151 selection().invalidateCaretRect(); | 150 selection().invalidateCaretRect(); |
| 152 EXPECT_FALSE(selection().isCaretBoundsDirty()); | 151 EXPECT_FALSE(selection().isCaretBoundsDirty()); |
| 153 EXPECT_TRUE(isPreviousCaretDirtyForTesting()); | 152 EXPECT_TRUE(isPreviousCaretDirtyForTesting()); |
| 154 | 153 |
| 155 // Simulate to remove all except for "H". | 154 // Simulate to remove all except for "H". |
| 156 text->replaceWholeText("H"); | 155 text->replaceWholeText("H"); |
| 157 document().updateStyleAndLayout(); | 156 document().updateStyleAndLayout(); |
| 158 selection().moveTo( | 157 selection().setSelection( |
| 159 createVisiblePosition(selection().end(), selection().affinity()), | 158 SelectionInDOMTree::Builder().collapse(selection().end()).build()); |
| 160 NotUserTriggered); | |
| 161 selection().setCaretRectNeedsUpdate(); | 159 selection().setCaretRectNeedsUpdate(); |
| 162 EXPECT_TRUE(selection().isCaretBoundsDirty()); | 160 EXPECT_TRUE(selection().isCaretBoundsDirty()); |
| 163 // "H" remains so early previousCaret invalidation isn't needed. | 161 // "H" remains so early previousCaret invalidation isn't needed. |
| 164 EXPECT_TRUE(isPreviousCaretDirtyForTesting()); | 162 EXPECT_TRUE(isPreviousCaretDirtyForTesting()); |
| 165 selection().invalidateCaretRect(); | 163 selection().invalidateCaretRect(); |
| 166 EXPECT_FALSE(selection().isCaretBoundsDirty()); | 164 EXPECT_FALSE(selection().isCaretBoundsDirty()); |
| 167 EXPECT_TRUE(isPreviousCaretDirtyForTesting()); | 165 EXPECT_TRUE(isPreviousCaretDirtyForTesting()); |
| 168 | 166 |
| 169 // Simulate to remove the last character. | 167 // Simulate to remove the last character. |
| 170 document().body()->removeChild(text); | 168 document().body()->removeChild(text); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 selection().updateIfNeeded(); | 348 selection().updateIfNeeded(); |
| 351 | 349 |
| 352 // TODO(yosin): Once lazy canonicalization implemented, selection.start | 350 // TODO(yosin): Once lazy canonicalization implemented, selection.start |
| 353 // should be Position(HTML, 0). | 351 // should be Position(HTML, 0). |
| 354 EXPECT_EQ(Position(), selection().start()) | 352 EXPECT_EQ(Position(), selection().start()) |
| 355 << "updateIfNeeded() makes selection to null."; | 353 << "updateIfNeeded() makes selection to null."; |
| 356 EXPECT_EQ(selection().start(), caretPosition().position()); | 354 EXPECT_EQ(selection().start(), caretPosition().position()); |
| 357 } | 355 } |
| 358 | 356 |
| 359 } // namespace blink | 357 } // namespace blink |
| OLD | NEW |