Chromium Code Reviews| 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" |
| 11 #include "core/editing/EditingTestBase.h" | 11 #include "core/editing/EditingTestBase.h" |
| 12 #include "core/editing/FrameCaret.h" | |
| 12 #include "core/frame/FrameView.h" | 13 #include "core/frame/FrameView.h" |
| 13 #include "core/html/HTMLBodyElement.h" | 14 #include "core/html/HTMLBodyElement.h" |
| 14 #include "core/html/HTMLDocument.h" | 15 #include "core/html/HTMLDocument.h" |
| 15 #include "core/layout/LayoutView.h" | 16 #include "core/layout/LayoutView.h" |
| 16 #include "core/paint/PaintInfo.h" | 17 #include "core/paint/PaintInfo.h" |
| 17 #include "core/paint/PaintLayer.h" | 18 #include "core/paint/PaintLayer.h" |
| 18 #include "core/testing/DummyPageHolder.h" | 19 #include "core/testing/DummyPageHolder.h" |
| 19 #include "platform/graphics/paint/DrawingRecorder.h" | 20 #include "platform/graphics/paint/DrawingRecorder.h" |
| 20 #include "platform/graphics/paint/PaintController.h" | 21 #include "platform/graphics/paint/PaintController.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 32 FrameSelection& selection() const; | 33 FrameSelection& selection() const; |
| 33 const VisibleSelection& visibleSelectionInDOMTree() const { return selection ().selection(); } | 34 const VisibleSelection& visibleSelectionInDOMTree() const { return selection ().selection(); } |
| 34 const VisibleSelectionInFlatTree& visibleSelectionInFlatTree() const { retur n selection().selectionInFlatTree(); } | 35 const VisibleSelectionInFlatTree& visibleSelectionInFlatTree() const { retur n selection().selectionInFlatTree(); } |
| 35 | 36 |
| 36 Text* appendTextNode(const String& data); | 37 Text* appendTextNode(const String& data); |
| 37 int layoutCount() const { return dummyPageHolder().frameView().layoutCount() ; } | 38 int layoutCount() const { return dummyPageHolder().frameView().layoutCount() ; } |
| 38 | 39 |
| 39 bool shouldPaintCaretForTesting() const { return selection().shouldPaintCare tForTesting(); } | 40 bool shouldPaintCaretForTesting() const { return selection().shouldPaintCare tForTesting(); } |
| 40 bool isPreviousCaretDirtyForTesting() const { return selection().isPreviousC aretDirtyForTesting(); } | 41 bool isPreviousCaretDirtyForTesting() const { return selection().isPreviousC aretDirtyForTesting(); } |
| 41 | 42 |
| 43 PositionWithAffinity caretPosition() const | |
| 44 { | |
| 45 return selection().m_frameCaret->caretPosition(); | |
| 46 } | |
| 47 | |
| 42 private: | 48 private: |
| 43 Persistent<Text> m_textNode; | 49 Persistent<Text> m_textNode; |
| 44 }; | 50 }; |
| 45 | 51 |
| 46 void FrameSelectionTest::setSelection(const VisibleSelection& newSelection) | 52 void FrameSelectionTest::setSelection(const VisibleSelection& newSelection) |
| 47 { | 53 { |
| 48 dummyPageHolder().frame().selection().setSelection(newSelection); | 54 dummyPageHolder().frame().selection().setSelection(newSelection); |
| 49 } | 55 } |
| 50 | 56 |
| 51 FrameSelection& FrameSelectionTest::selection() const | 57 FrameSelection& FrameSelectionTest::selection() const |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 } | 272 } |
| 267 | 273 |
| 268 TEST_F(FrameSelectionTest, SelectAllWithUnselectableRoot) | 274 TEST_F(FrameSelectionTest, SelectAllWithUnselectableRoot) |
| 269 { | 275 { |
| 270 Element* select = document().createElement("select", ASSERT_NO_EXCEPTION); | 276 Element* select = document().createElement("select", ASSERT_NO_EXCEPTION); |
| 271 document().replaceChild(select, document().documentElement()); | 277 document().replaceChild(select, document().documentElement()); |
| 272 selection().selectAll(); | 278 selection().selectAll(); |
| 273 EXPECT_TRUE(selection().isNone()) << "Nothing should be selected if the cont ent of the documentElement is not selctable."; | 279 EXPECT_TRUE(selection().isNone()) << "Nothing should be selected if the cont ent of the documentElement is not selctable."; |
| 274 } | 280 } |
| 275 | 281 |
| 282 TEST_F(FrameSelectionTest, updateIfNeededAndFrameCaret) | |
| 283 { | |
| 284 setBodyContent("<style id=sample></style>"); | |
| 285 document().setDesignMode("on"); | |
| 286 Element* sample = document().getElementById("sample"); | |
| 287 setSelection(VisibleSelection(Position(sample, 0))); | |
|
yoichio
2016/07/20 09:10:06
Confirm selection().start() and caretPosition().po
yosin_UTC9
2016/07/20 09:27:33
Done.
| |
| 288 document().body()->remove(); | |
| 289 selection().updateIfNeeded(); | |
| 290 | |
| 291 // TODO(yosin): Once lazy canonicalization implemented, selection.start | |
| 292 // should be Position(HTML, 0). | |
| 293 EXPECT_EQ(Position(), selection().start()) | |
| 294 << "updateIfNeeded() makes selection to null."; | |
| 295 EXPECT_EQ(Position(), caretPosition().position()) | |
| 296 << "caret position and selection.start should be same."; | |
| 297 } | |
| 298 | |
| 276 } // namespace blink | 299 } // namespace blink |
| OLD | NEW |