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

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: Rebaselined Created 5 years, 9 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)
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 LayoutBox* innerEditorRenderer = innerEditorElement()->layoutBox(); 109 LayoutBox* innerEditorRenderer = innerEditorElement()->layoutBox();
110 bool innerEditorRendererHadLayout = innerEditorRenderer && innerEditorRender er->needsLayout();
109 LayoutBox* viewPortRenderer = editingViewPortElement() ? editingViewPortElem ent()->layoutBox() : 0; 111 LayoutBox* viewPortRenderer = editingViewPortElement() ? editingViewPortElem ent()->layoutBox() : 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 (LayoutBox* placeholderBox = placeholderElement ? placeholderElement- >layoutBox() : 0) 118 if (LayoutBox* placeholderBox = placeholderElement ? placeholderElement- >layoutBox() : 0)
117 layoutScope.setNeedsLayout(placeholderBox); 119 layoutScope.setNeedsLayout(placeholderBox);
118 } 120 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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