Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: Source/core/html/HTMLTextFormControlElementTest.cpp

Issue 429453004: Let FrameSelection::localCaretRect on a text input field avoid synchronous layout. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Nits Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "config.h" 5 #include "config.h"
6 #include "core/html/HTMLTextFormControlElement.h" 6 #include "core/html/HTMLTextFormControlElement.h"
7 7
8 #include "core/dom/Position.h" 8 #include "core/dom/Position.h"
9 #include "core/dom/Text.h" 9 #include "core/dom/Text.h"
10 #include "core/editing/FrameSelection.h" 10 #include "core/editing/FrameSelection.h"
(...skipping 16 matching lines...) Expand all
27 27
28 namespace { 28 namespace {
29 29
30 class HTMLTextFormControlElementTest : public ::testing::Test { 30 class HTMLTextFormControlElementTest : public ::testing::Test {
31 protected: 31 protected:
32 virtual void SetUp() OVERRIDE; 32 virtual void SetUp() OVERRIDE;
33 33
34 DummyPageHolder& page() const { return *m_dummyPageHolder; } 34 DummyPageHolder& page() const { return *m_dummyPageHolder; }
35 HTMLDocument& document() const { return *m_document; } 35 HTMLDocument& document() const { return *m_document; }
36 HTMLTextFormControlElement& textControl() const { return *m_textControl; } 36 HTMLTextFormControlElement& textControl() const { return *m_textControl; }
37 HTMLInputElement& input() const { return *m_input; }
38
39 int layoutCount() const { return page().frameView().layoutCount(); }
40 void forceLayoutFlag();
37 41
38 private: 42 private:
39 OwnPtr<SpellCheckerClient> m_spellCheckerClient; 43 OwnPtr<SpellCheckerClient> m_spellCheckerClient;
40 OwnPtr<DummyPageHolder> m_dummyPageHolder; 44 OwnPtr<DummyPageHolder> m_dummyPageHolder;
41 45
42 RefPtrWillBePersistent<HTMLDocument> m_document; 46 RefPtrWillBePersistent<HTMLDocument> m_document;
43 RefPtrWillBePersistent<HTMLTextFormControlElement> m_textControl; 47 RefPtrWillBePersistent<HTMLTextFormControlElement> m_textControl;
48 RefPtrWillBePersistent<HTMLInputElement> m_input;
44 }; 49 };
45 50
46 class DummyTextCheckerClient : public EmptyTextCheckerClient { 51 class DummyTextCheckerClient : public EmptyTextCheckerClient {
47 public: 52 public:
48 ~DummyTextCheckerClient() { } 53 ~DummyTextCheckerClient() { }
49 54
50 virtual bool shouldEraseMarkersAfterChangeSelection(TextCheckingType) const OVERRIDE { return false; } 55 virtual bool shouldEraseMarkersAfterChangeSelection(TextCheckingType) const OVERRIDE { return false; }
51 }; 56 };
52 57
53 class DummySpellCheckerClient : public EmptySpellCheckerClient { 58 class DummySpellCheckerClient : public EmptySpellCheckerClient {
(...skipping 15 matching lines...) Expand all
69 fillWithEmptyClients(pageClients); 74 fillWithEmptyClients(pageClients);
70 m_spellCheckerClient = adoptPtr(new DummySpellCheckerClient); 75 m_spellCheckerClient = adoptPtr(new DummySpellCheckerClient);
71 pageClients.spellCheckerClient = m_spellCheckerClient.get(); 76 pageClients.spellCheckerClient = m_spellCheckerClient.get();
72 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients) ; 77 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients) ;
73 78
74 m_document = toHTMLDocument(&m_dummyPageHolder->document()); 79 m_document = toHTMLDocument(&m_dummyPageHolder->document());
75 m_document->documentElement()->setInnerHTML("<body><textarea id=textarea></t extarea><input id=input /></body>", ASSERT_NO_EXCEPTION); 80 m_document->documentElement()->setInnerHTML("<body><textarea id=textarea></t extarea><input id=input /></body>", ASSERT_NO_EXCEPTION);
76 m_document->view()->updateLayoutAndStyleIfNeededRecursive(); 81 m_document->view()->updateLayoutAndStyleIfNeededRecursive();
77 m_textControl = toHTMLTextFormControlElement(m_document->getElementById("tex tarea")); 82 m_textControl = toHTMLTextFormControlElement(m_document->getElementById("tex tarea"));
78 m_textControl->focus(); 83 m_textControl->focus();
84 m_input = toHTMLInputElement(m_document->getElementById("input"));
85 }
86
87 void HTMLTextFormControlElementTest::forceLayoutFlag()
88 {
89 FrameView& frameView = page().frameView();
90 IntRect frameRect = frameView.frameRect();
91 frameRect.setWidth(frameRect.width() + 1);
92 frameRect.setHeight(frameRect.height() + 1);
93 page().frameView().setFrameRect(frameRect);
79 } 94 }
80 95
81 TEST_F(HTMLTextFormControlElementTest, SetSelectionRange) 96 TEST_F(HTMLTextFormControlElementTest, SetSelectionRange)
82 { 97 {
83 EXPECT_EQ(0, textControl().selectionStart()); 98 EXPECT_EQ(0, textControl().selectionStart());
84 EXPECT_EQ(0, textControl().selectionEnd()); 99 EXPECT_EQ(0, textControl().selectionEnd());
85 100
86 textControl().setInnerEditorValue("Hello, text form."); 101 textControl().setInnerEditorValue("Hello, text form.");
87 EXPECT_EQ(0, textControl().selectionStart()); 102 EXPECT_EQ(0, textControl().selectionStart());
88 EXPECT_EQ(0, textControl().selectionEnd()); 103 EXPECT_EQ(0, textControl().selectionEnd());
89 104
90 textControl().setSelectionRange(1, 3); 105 textControl().setSelectionRange(1, 3);
91 EXPECT_EQ(1, textControl().selectionStart()); 106 EXPECT_EQ(1, textControl().selectionStart());
92 EXPECT_EQ(3, textControl().selectionEnd()); 107 EXPECT_EQ(3, textControl().selectionEnd());
93 } 108 }
94 109
110 TEST_F(HTMLTextFormControlElementTest, FrameSelectionLocalCaretRectDoesNotCauseL ayout)
111 {
112 input().focus();
113 input().setValue("Hello, input form.");
114 FrameSelection& frameSelection = document().frame()->selection();
115 frameSelection.setCaretRectNeedsUpdate();
116
117 forceLayoutFlag();
118 int startLayoutCount = layoutCount();
119 frameSelection.localCaretRect();
120 EXPECT_EQ(startLayoutCount, layoutCount());
121 }
122
95 typedef Position (*PositionFunction)(const Position&); 123 typedef Position (*PositionFunction)(const Position&);
96 typedef VisiblePosition(*VisblePositionFunction)(const VisiblePosition&); 124 typedef VisiblePosition(*VisblePositionFunction)(const VisiblePosition&);
97 125
98 void testFunctionEquivalence(const Position& position, PositionFunction position Function, VisblePositionFunction visibleFunction) 126 void testFunctionEquivalence(const Position& position, PositionFunction position Function, VisblePositionFunction visibleFunction)
99 { 127 {
100 VisiblePosition visiblePosition(position); 128 VisiblePosition visiblePosition(position);
101 VisiblePosition expected = visibleFunction(visiblePosition); 129 VisiblePosition expected = visibleFunction(visiblePosition);
102 VisiblePosition actual = VisiblePosition(positionFunction(position)); 130 VisiblePosition actual = VisiblePosition(positionFunction(position));
103 EXPECT_EQ(expected, actual); 131 EXPECT_EQ(expected, actual);
104 } 132 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 input->focus(); 199 input->focus();
172 input->setValue("Hello, input field"); 200 input->setValue("Hello, input field");
173 VisibleSelection oldSelection = document().frame()->selection().selection(); 201 VisibleSelection oldSelection = document().frame()->selection().selection();
174 202
175 Position newPosition(input->innerEditorElement()->firstChild(), 3, Position: :PositionIsOffsetInAnchor); 203 Position newPosition(input->innerEditorElement()->firstChild(), 3, Position: :PositionIsOffsetInAnchor);
176 VisibleSelection newSelection(newPosition, DOWNSTREAM); 204 VisibleSelection newSelection(newPosition, DOWNSTREAM);
177 document().frame()->selection().setSelection(newSelection, FrameSelection::C loseTyping | FrameSelection::ClearTypingStyle | FrameSelection::DoNotUpdateAppea rance); 205 document().frame()->selection().setSelection(newSelection, FrameSelection::C loseTyping | FrameSelection::ClearTypingStyle | FrameSelection::DoNotUpdateAppea rance);
178 ASSERT_EQ(3, input->selectionStart()); 206 ASSERT_EQ(3, input->selectionStart());
179 207
180 OwnPtr<SpellChecker> spellChecker(SpellChecker::create(page().frame())); 208 OwnPtr<SpellChecker> spellChecker(SpellChecker::create(page().frame()));
181 page().frameView().setFrameRect(IntRect(0, 0, 801, 601)); 209 forceLayoutFlag();
182 int startCount = page().frameView().layoutCount(); 210 int startCount = layoutCount();
183 spellChecker->respondToChangedSelection(oldSelection, FrameSelection::CloseT yping | FrameSelection::ClearTypingStyle); 211 spellChecker->respondToChangedSelection(oldSelection, FrameSelection::CloseT yping | FrameSelection::ClearTypingStyle);
184 EXPECT_EQ(startCount, page().frameView().layoutCount()); 212 EXPECT_EQ(startCount, layoutCount());
185 } 213 }
186 214
187 } 215 }
OLDNEW
« Source/core/editing/Caret.h ('K') | « Source/core/editing/VisibleUnits.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698