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

Side by Side Diff: Source/core/layout/LayoutTextControlSingleLine.cpp

Issue 952663002: Text inside input field gets misaligned when relaying out (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Better change. Created 5 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « LayoutTests/fast/forms/relayout-shifts-inner-editor-expected.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * Copyright (C) 2006, 2007, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2010 Apple Inc. All rights reserved.
3 * (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 3 * (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
4 * Copyright (C) 2010 Google Inc. All rights reserved. 4 * Copyright (C) 2010 Google Inc. All rights reserved.
5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 LayoutUnit LayoutTextControlSingleLine::computeLogicalHeightLimit() const 88 LayoutUnit LayoutTextControlSingleLine::computeLogicalHeightLimit() const
89 { 89 {
90 return containerElement() ? contentLogicalHeight() : logicalHeight(); 90 return containerElement() ? contentLogicalHeight() : logicalHeight();
91 } 91 }
92 92
93 void LayoutTextControlSingleLine::layout() 93 void LayoutTextControlSingleLine::layout()
94 { 94 {
95 SubtreeLayoutScope layoutScope(*this); 95 SubtreeLayoutScope layoutScope(*this);
96 96
97 // FIXME: This code is madness (https://crbug.com/461117)
leviw_travelin_and_unemployed 2015/02/24 18:38:25 Well said, sir!
97 // FIXME: We should remove the height-related hacks in layout() and 98 // FIXME: We should remove the height-related hacks in layout() and
98 // styleDidChange(). We need them because 99 // styleDidChange(). We need them because
99 // - Center the inner elements vertically if the input height is taller than 100 // - Center the inner elements vertically if the input height is taller than
100 // the intrinsic height of the inner elements. 101 // the intrinsic height of the inner elements.
101 // - Shrink the inner elment heights if the input height is samller than the 102 // - Shrink the inner elment heights if the input height is samller than the
102 // intrinsic heights of the inner elements. 103 // intrinsic heights of the inner elements.
103 104
104 // We don't honor paddings and borders for textfields without decorations 105 // We don't honor paddings and borders for textfields without decorations
105 // and type=search if the text height is taller than the contentHeight() 106 // and type=search if the text height is taller than the contentHeight()
106 // because of compability. 107 // because of compability.
107 108
108 RenderBox* innerEditorRenderer = innerEditorElement()->renderBox(); 109 RenderBox* innerEditorRenderer = innerEditorElement()->renderBox();
110 bool innerEditorRendererHadLayout = innerEditorRenderer && innerEditorRender er->needsLayout();
leviw_travelin_and_unemployed 2015/02/24 18:38:25 innerEditorRendererHadNeedsLayout?
Julien - ping for review 2015/02/24 18:48:01 I prefer HadLayout as it corresponds to what's hap
109 RenderBox* viewPortRenderer = editingViewPortElement() ? editingViewPortElem ent()->renderBox() : 0; 111 RenderBox* viewPortRenderer = editingViewPortElement() ? editingViewPortElem ent()->renderBox() : 0;
110 112
111 // To ensure consistency between layouts, we need to reset any conditionally overriden height. 113 // To ensure consistency between layouts, we need to reset any conditionally overriden height.
112 if (innerEditorRenderer && !innerEditorRenderer->style()->logicalHeight().is Auto()) { 114 if (innerEditorRenderer && !innerEditorRenderer->style()->logicalHeight().is Auto()) {
113 innerEditorRenderer->style()->setLogicalHeight(Length(Auto)); 115 innerEditorRenderer->style()->setLogicalHeight(Length(Auto));
114 layoutScope.setNeedsLayout(innerEditorRenderer); 116 layoutScope.setNeedsLayout(innerEditorRenderer);
115 HTMLElement* placeholderElement = inputElement()->placeholderElement(); 117 HTMLElement* placeholderElement = inputElement()->placeholderElement();
116 if (RenderBox* placeholderBox = placeholderElement ? placeholderElement- >renderBox() : 0) 118 if (RenderBox* placeholderBox = placeholderElement ? placeholderElement- >renderBox() : 0)
117 layoutScope.setNeedsLayout(placeholderBox); 119 layoutScope.setNeedsLayout(placeholderBox);
118 } 120 }
(...skipping 10 matching lines...) Expand all
129 // Set the text block height 131 // Set the text block height
130 LayoutUnit desiredLogicalHeight = textBlockLogicalHeight(); 132 LayoutUnit desiredLogicalHeight = textBlockLogicalHeight();
131 LayoutUnit logicalHeightLimit = computeLogicalHeightLimit(); 133 LayoutUnit logicalHeightLimit = computeLogicalHeightLimit();
132 if (innerEditorRenderer && innerEditorRenderer->logicalHeight() > logicalHei ghtLimit) { 134 if (innerEditorRenderer && innerEditorRenderer->logicalHeight() > logicalHei ghtLimit) {
133 if (desiredLogicalHeight != innerEditorRenderer->logicalHeight()) 135 if (desiredLogicalHeight != innerEditorRenderer->logicalHeight())
134 layoutScope.setNeedsLayout(this); 136 layoutScope.setNeedsLayout(this);
135 137
136 m_desiredInnerEditorLogicalHeight = desiredLogicalHeight; 138 m_desiredInnerEditorLogicalHeight = desiredLogicalHeight;
137 139
138 innerEditorRenderer->style()->setLogicalHeight(Length(desiredLogicalHeig ht, Fixed)); 140 innerEditorRenderer->style()->setLogicalHeight(Length(desiredLogicalHeig ht, Fixed));
139 layoutScope.setNeedsLayout(innerEditorRenderer); 141 layoutScope.setNeedsLayout(innerEditorRenderer);
leviw_travelin_and_unemployed 2015/02/24 18:38:25 Do we still need this?
Julien - ping for review 2015/02/24 18:48:02 Yes. We won't force a relayout if you had a layout
140 if (viewPortRenderer) { 142 if (viewPortRenderer) {
141 viewPortRenderer->style()->setLogicalHeight(Length(desiredLogicalHei ght, Fixed)); 143 viewPortRenderer->style()->setLogicalHeight(Length(desiredLogicalHei ght, Fixed));
142 layoutScope.setNeedsLayout(viewPortRenderer); 144 layoutScope.setNeedsLayout(viewPortRenderer);
143 } 145 }
144 } 146 }
145 // The container might be taller because of decoration elements. 147 // The container might be taller because of decoration elements.
146 if (containerRenderer) { 148 if (containerRenderer) {
147 containerRenderer->layoutIfNeeded(); 149 containerRenderer->layoutIfNeeded();
148 LayoutUnit containerLogicalHeight = containerRenderer->logicalHeight(); 150 LayoutUnit containerLogicalHeight = containerRenderer->logicalHeight();
149 if (containerLogicalHeight > logicalHeightLimit) { 151 if (containerLogicalHeight > logicalHeightLimit) {
150 containerRenderer->style()->setLogicalHeight(Length(logicalHeightLim it, Fixed)); 152 containerRenderer->style()->setLogicalHeight(Length(logicalHeightLim it, Fixed));
151 layoutScope.setNeedsLayout(this); 153 layoutScope.setNeedsLayout(this);
152 } else if (containerRenderer->logicalHeight() < contentLogicalHeight()) { 154 } else if (containerRenderer->logicalHeight() < contentLogicalHeight()) {
153 containerRenderer->style()->setLogicalHeight(Length(contentLogicalHe ight(), Fixed)); 155 containerRenderer->style()->setLogicalHeight(Length(contentLogicalHe ight(), Fixed));
154 layoutScope.setNeedsLayout(this); 156 layoutScope.setNeedsLayout(this);
155 } else { 157 } else {
156 containerRenderer->style()->setLogicalHeight(Length(containerLogical Height, Fixed)); 158 containerRenderer->style()->setLogicalHeight(Length(containerLogical Height, Fixed));
157 } 159 }
158 } 160 }
159 161
162 // We ensure that the inner editor renderer is laid out at least once. This is
163 // required as the logic below assumes that we don't carry over previous lay out values.
164 if (innerEditorRenderer && !innerEditorRendererHadLayout)
165 layoutScope.setNeedsLayout(innerEditorRenderer);
166
160 // If we need another layout pass, we have changed one of children's height so we need to relayout them. 167 // If we need another layout pass, we have changed one of children's height so we need to relayout them.
161 if (needsLayout()) 168 if (needsLayout())
162 RenderBlockFlow::layoutBlock(true); 169 RenderBlockFlow::layoutBlock(true);
163 170
164 // Center the child block in the block progression direction (vertical cente ring for horizontal text fields). 171 // Center the child block in the block progression direction (vertical cente ring for horizontal text fields).
165 if (!container && innerEditorRenderer && innerEditorRenderer->size().height( ) != contentLogicalHeight()) { 172 if (!container && innerEditorRenderer && innerEditorRenderer->size().height( ) != contentLogicalHeight()) {
166 LayoutUnit logicalHeightDiff = innerEditorRenderer->logicalHeight() - co ntentLogicalHeight(); 173 LayoutUnit logicalHeightDiff = innerEditorRenderer->logicalHeight() - co ntentLogicalHeight();
167 innerEditorRenderer->setLogicalTop(innerEditorRenderer->logicalTop() - ( logicalHeightDiff / 2 + layoutMod(logicalHeightDiff, 2))); 174 innerEditorRenderer->setLogicalTop(innerEditorRenderer->logicalTop() - ( logicalHeightDiff / 2 + layoutMod(logicalHeightDiff, 2)));
168 } else { 175 } else {
169 centerContainerIfNeeded(containerRenderer); 176 centerContainerIfNeeded(containerRenderer);
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 if (innerEditorElement()) 429 if (innerEditorElement())
423 innerEditorElement()->setScrollTop(newTop); 430 innerEditorElement()->setScrollTop(newTop);
424 } 431 }
425 432
426 HTMLInputElement* LayoutTextControlSingleLine::inputElement() const 433 HTMLInputElement* LayoutTextControlSingleLine::inputElement() const
427 { 434 {
428 return toHTMLInputElement(node()); 435 return toHTMLInputElement(node());
429 } 436 }
430 437
431 } 438 }
OLDNEW
« no previous file with comments | « LayoutTests/fast/forms/relayout-shifts-inner-editor-expected.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698