| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 EXPECT_FALSE(selection().isCaretBoundsDirty()); | 87 EXPECT_FALSE(selection().isCaretBoundsDirty()); |
| 88 | 88 |
| 89 document().body()->removeChild(text); | 89 document().body()->removeChild(text); |
| 90 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 90 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 91 selection().setCaretRectNeedsUpdate(); | 91 selection().setCaretRectNeedsUpdate(); |
| 92 EXPECT_TRUE(selection().isCaretBoundsDirty()); | 92 EXPECT_TRUE(selection().isCaretBoundsDirty()); |
| 93 selection().invalidateCaretRect(); | 93 selection().invalidateCaretRect(); |
| 94 EXPECT_FALSE(selection().isCaretBoundsDirty()); | 94 EXPECT_FALSE(selection().isCaretBoundsDirty()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 TEST_F(FrameSelectionTest, PaintCaretShouldNotLayout) |
| 98 { |
| 99 Text* text = appendTextNode("Hello, World!"); |
| 100 document().view()->updateAllLifecyclePhases(); |
| 101 |
| 102 document().body()->setContentEditable("true", ASSERT_NO_EXCEPTION); |
| 103 document().body()->focus(); |
| 104 EXPECT_TRUE(document().body()->focused()); |
| 105 |
| 106 VisibleSelection validSelection(Position(text, 0), Position(text, 0)); |
| 107 selection().setCaretVisible(true); |
| 108 setSelection(validSelection); |
| 109 EXPECT_TRUE(selection().isCaret()); |
| 110 EXPECT_TRUE(shouldPaintCaretForTesting()); |
| 111 |
| 112 int startCount = layoutCount(); |
| 113 { |
| 114 // To force layout in next updateLayout calling, widen view. |
| 115 FrameView& frameView = dummyPageHolder().frameView(); |
| 116 IntRect frameRect = frameView.frameRect(); |
| 117 frameRect.setWidth(frameRect.width() + 1); |
| 118 frameRect.setHeight(frameRect.height() + 1); |
| 119 dummyPageHolder().frameView().setFrameRect(frameRect); |
| 120 } |
| 121 std::unique_ptr<PaintController> paintController = PaintController::create()
; |
| 122 { |
| 123 GraphicsContext context(*paintController); |
| 124 DrawingRecorder drawingRecorder(context, *dummyPageHolder().frameView().
layoutView(), DisplayItem::Caret, LayoutRect::infiniteIntRect()); |
| 125 selection().paintCaret(context, LayoutPoint()); |
| 126 } |
| 127 paintController->commitNewDisplayItems(); |
| 128 EXPECT_EQ(startCount, layoutCount()); |
| 129 } |
| 130 |
| 97 TEST_F(FrameSelectionTest, InvalidatePreviousCaretAfterRemovingLastCharacter) | 131 TEST_F(FrameSelectionTest, InvalidatePreviousCaretAfterRemovingLastCharacter) |
| 98 { | 132 { |
| 99 Text* text = appendTextNode("Hello, World!"); | 133 Text* text = appendTextNode("Hello, World!"); |
| 100 document().view()->updateAllLifecyclePhases(); | 134 document().view()->updateAllLifecyclePhases(); |
| 101 | 135 |
| 102 document().body()->setContentEditable("true", ASSERT_NO_EXCEPTION); | 136 document().body()->setContentEditable("true", ASSERT_NO_EXCEPTION); |
| 103 document().body()->focus(); | 137 document().body()->focus(); |
| 104 EXPECT_TRUE(document().body()->focused()); | 138 EXPECT_TRUE(document().body()->focused()); |
| 105 | 139 |
| 106 selection().setCaretVisible(true); | 140 selection().setCaretVisible(true); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 selection().updateIfNeeded(); | 312 selection().updateIfNeeded(); |
| 279 | 313 |
| 280 // TODO(yosin): Once lazy canonicalization implemented, selection.start | 314 // TODO(yosin): Once lazy canonicalization implemented, selection.start |
| 281 // should be Position(HTML, 0). | 315 // should be Position(HTML, 0). |
| 282 EXPECT_EQ(Position(), selection().start()) | 316 EXPECT_EQ(Position(), selection().start()) |
| 283 << "updateIfNeeded() makes selection to null."; | 317 << "updateIfNeeded() makes selection to null."; |
| 284 EXPECT_EQ(selection().start(), caretPosition().position()); | 318 EXPECT_EQ(selection().start(), caretPosition().position()); |
| 285 } | 319 } |
| 286 | 320 |
| 287 } // namespace blink | 321 } // namespace blink |
| OLD | NEW |