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

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: Move localCaretRect to VisibleUnits 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; }
37 38
39 int layoutCount() const { return page().frameView().layoutCount(); }
40 void forceLayoutFlag();
38 private: 41 private:
tkent 2014/07/29 09:30:20 nit: We put one blank line before private:.
yoichio 2014/07/29 10:32:46 Done.
39 OwnPtr<SpellCheckerClient> m_spellCheckerClient; 42 OwnPtr<SpellCheckerClient> m_spellCheckerClient;
40 OwnPtr<DummyPageHolder> m_dummyPageHolder; 43 OwnPtr<DummyPageHolder> m_dummyPageHolder;
41 44
42 RefPtrWillBePersistent<HTMLDocument> m_document; 45 RefPtrWillBePersistent<HTMLDocument> m_document;
43 RefPtrWillBePersistent<HTMLTextFormControlElement> m_textControl; 46 RefPtrWillBePersistent<HTMLTextFormControlElement> m_textControl;
47 RefPtrWillBePersistent<HTMLInputElement> m_input;
44 }; 48 };
45 49
46 class DummyTextCheckerClient : public EmptyTextCheckerClient { 50 class DummyTextCheckerClient : public EmptyTextCheckerClient {
47 public: 51 public:
48 ~DummyTextCheckerClient() { } 52 ~DummyTextCheckerClient() { }
49 53
50 virtual bool shouldEraseMarkersAfterChangeSelection(TextCheckingType) const OVERRIDE { return false; } 54 virtual bool shouldEraseMarkersAfterChangeSelection(TextCheckingType) const OVERRIDE { return false; }
51 }; 55 };
52 56
53 class DummySpellCheckerClient : public EmptySpellCheckerClient { 57 class DummySpellCheckerClient : public EmptySpellCheckerClient {
(...skipping 15 matching lines...) Expand all
69 fillWithEmptyClients(pageClients); 73 fillWithEmptyClients(pageClients);
70 m_spellCheckerClient = adoptPtr(new DummySpellCheckerClient); 74 m_spellCheckerClient = adoptPtr(new DummySpellCheckerClient);
71 pageClients.spellCheckerClient = m_spellCheckerClient.get(); 75 pageClients.spellCheckerClient = m_spellCheckerClient.get();
72 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients) ; 76 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients) ;
73 77
74 m_document = toHTMLDocument(&m_dummyPageHolder->document()); 78 m_document = toHTMLDocument(&m_dummyPageHolder->document());
75 m_document->documentElement()->setInnerHTML("<body><textarea id=textarea></t extarea><input id=input /></body>", ASSERT_NO_EXCEPTION); 79 m_document->documentElement()->setInnerHTML("<body><textarea id=textarea></t extarea><input id=input /></body>", ASSERT_NO_EXCEPTION);
76 m_document->view()->updateLayoutAndStyleIfNeededRecursive(); 80 m_document->view()->updateLayoutAndStyleIfNeededRecursive();
77 m_textControl = toHTMLTextFormControlElement(m_document->getElementById("tex tarea")); 81 m_textControl = toHTMLTextFormControlElement(m_document->getElementById("tex tarea"));
78 m_textControl->focus(); 82 m_textControl->focus();
83 m_input = toHTMLInputElement(m_document->getElementById("input"));
84 }
85
86 void HTMLTextFormControlElementTest::forceLayoutFlag()
87 {
88 FrameView& frameView = page().frameView();
89 IntRect frameRect = frameView.frameRect();
90 frameRect.setWidth(frameRect.width() + 1);
91 frameRect.setHeight(frameRect.height() + 1);
92 page().frameView().setFrameRect(frameRect);
79 } 93 }
80 94
81 TEST_F(HTMLTextFormControlElementTest, SetSelectionRange) 95 TEST_F(HTMLTextFormControlElementTest, SetSelectionRange)
82 { 96 {
83 EXPECT_EQ(0, textControl().selectionStart()); 97 EXPECT_EQ(0, textControl().selectionStart());
84 EXPECT_EQ(0, textControl().selectionEnd()); 98 EXPECT_EQ(0, textControl().selectionEnd());
85 99
86 textControl().setInnerEditorValue("Hello, text form."); 100 textControl().setInnerEditorValue("Hello, text form.");
87 EXPECT_EQ(0, textControl().selectionStart()); 101 EXPECT_EQ(0, textControl().selectionStart());
88 EXPECT_EQ(0, textControl().selectionEnd()); 102 EXPECT_EQ(0, textControl().selectionEnd());
89 103
90 textControl().setSelectionRange(1, 3); 104 textControl().setSelectionRange(1, 3);
91 EXPECT_EQ(1, textControl().selectionStart()); 105 EXPECT_EQ(1, textControl().selectionStart());
92 EXPECT_EQ(3, textControl().selectionEnd()); 106 EXPECT_EQ(3, textControl().selectionEnd());
93 } 107 }
94 108
109 TEST_F(HTMLTextFormControlElementTest, FrameSelectionLocalCaretRectDoesNotCauseL ayout)
110 {
111 input().focus();
112 input().setValue("Hello, input form.");
113 FrameSelection& frameSelection = document().frame()->selection();
114 frameSelection.setCaretRectNeedsUpdate();
115
116 forceLayoutFlag();
117 int startLayoutCount = layoutCount();
118 frameSelection.localCaretRect();
119 EXPECT_EQ(startLayoutCount, layoutCount());
120 }
121
95 typedef Position (*PositionFunction)(const Position&); 122 typedef Position (*PositionFunction)(const Position&);
96 typedef VisiblePosition(*VisblePositionFunction)(const VisiblePosition&); 123 typedef VisiblePosition(*VisblePositionFunction)(const VisiblePosition&);
97 124
98 void testFunctionEquivalence(const Position& position, PositionFunction position Function, VisblePositionFunction visibleFunction) 125 void testFunctionEquivalence(const Position& position, PositionFunction position Function, VisblePositionFunction visibleFunction)
99 { 126 {
100 VisiblePosition visiblePosition(position); 127 VisiblePosition visiblePosition(position);
101 VisiblePosition expected = visibleFunction(visiblePosition); 128 VisiblePosition expected = visibleFunction(visiblePosition);
102 VisiblePosition actual = VisiblePosition(positionFunction(position)); 129 VisiblePosition actual = VisiblePosition(positionFunction(position));
103 EXPECT_EQ(expected, actual); 130 EXPECT_EQ(expected, actual);
104 } 131 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 input->focus(); 198 input->focus();
172 input->setValue("Hello, input field"); 199 input->setValue("Hello, input field");
173 VisibleSelection oldSelection = document().frame()->selection().selection(); 200 VisibleSelection oldSelection = document().frame()->selection().selection();
174 201
175 Position newPosition(input->innerEditorElement()->firstChild(), 3, Position: :PositionIsOffsetInAnchor); 202 Position newPosition(input->innerEditorElement()->firstChild(), 3, Position: :PositionIsOffsetInAnchor);
176 VisibleSelection newSelection(newPosition, DOWNSTREAM); 203 VisibleSelection newSelection(newPosition, DOWNSTREAM);
177 document().frame()->selection().setSelection(newSelection, FrameSelection::C loseTyping | FrameSelection::ClearTypingStyle | FrameSelection::DoNotUpdateAppea rance); 204 document().frame()->selection().setSelection(newSelection, FrameSelection::C loseTyping | FrameSelection::ClearTypingStyle | FrameSelection::DoNotUpdateAppea rance);
178 ASSERT_EQ(3, input->selectionStart()); 205 ASSERT_EQ(3, input->selectionStart());
179 206
180 OwnPtr<SpellChecker> spellChecker(SpellChecker::create(page().frame())); 207 OwnPtr<SpellChecker> spellChecker(SpellChecker::create(page().frame()));
181 page().frameView().setFrameRect(IntRect(0, 0, 801, 601)); 208 forceLayoutFlag();
182 int startCount = page().frameView().layoutCount(); 209 int startCount = layoutCount();
183 spellChecker->respondToChangedSelection(oldSelection, FrameSelection::CloseT yping | FrameSelection::ClearTypingStyle); 210 spellChecker->respondToChangedSelection(oldSelection, FrameSelection::CloseT yping | FrameSelection::ClearTypingStyle);
184 EXPECT_EQ(startCount, page().frameView().layoutCount()); 211 EXPECT_EQ(startCount, layoutCount());
185 } 212 }
186 213
187 } 214 }
OLDNEW
« Source/core/editing/VisibleUnits.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