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

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

Issue 889563002: Make RenderObject::style() return a const object (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated change after Doug's review. 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
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 // We don't honor paddings and borders for textfields without decorations 104 // We don't honor paddings and borders for textfields without decorations
105 // and type=search if the text height is taller than the contentHeight() 105 // and type=search if the text height is taller than the contentHeight()
106 // because of compability. 106 // because of compability.
107 107
108 RenderBox* innerEditorRenderer = innerEditorElement()->renderBox(); 108 RenderBox* innerEditorRenderer = innerEditorElement()->renderBox();
109 RenderBox* viewPortRenderer = editingViewPortElement() ? editingViewPortElem ent()->renderBox() : 0; 109 RenderBox* viewPortRenderer = editingViewPortElement() ? editingViewPortElem ent()->renderBox() : 0;
110 110
111 // To ensure consistency between layouts, we need to reset any conditionally overriden height. 111 // To ensure consistency between layouts, we need to reset any conditionally overriden height.
112 if (innerEditorRenderer && !innerEditorRenderer->style()->logicalHeight().is Auto()) { 112 if (innerEditorRenderer && !innerEditorRenderer->style()->logicalHeight().is Auto()) {
113 innerEditorRenderer->style()->setLogicalHeight(Length(Auto)); 113 innerEditorRenderer->mutableStyleRef().setLogicalHeight(Length(Auto));
114 layoutScope.setNeedsLayout(innerEditorRenderer); 114 layoutScope.setNeedsLayout(innerEditorRenderer);
115 HTMLElement* placeholderElement = inputElement()->placeholderElement(); 115 HTMLElement* placeholderElement = inputElement()->placeholderElement();
116 if (RenderBox* placeholderBox = placeholderElement ? placeholderElement- >renderBox() : 0) 116 if (RenderBox* placeholderBox = placeholderElement ? placeholderElement- >renderBox() : 0)
117 layoutScope.setNeedsLayout(placeholderBox); 117 layoutScope.setNeedsLayout(placeholderBox);
118 } 118 }
119 if (viewPortRenderer && !viewPortRenderer->style()->logicalHeight().isAuto() ) { 119 if (viewPortRenderer && !viewPortRenderer->style()->logicalHeight().isAuto() ) {
120 viewPortRenderer->style()->setLogicalHeight(Length(Auto)); 120 viewPortRenderer->mutableStyleRef().setLogicalHeight(Length(Auto));
121 layoutScope.setNeedsLayout(viewPortRenderer); 121 layoutScope.setNeedsLayout(viewPortRenderer);
122 } 122 }
123 123
124 RenderBlockFlow::layoutBlock(false); 124 RenderBlockFlow::layoutBlock(false);
125 125
126 Element* container = containerElement(); 126 Element* container = containerElement();
127 RenderBox* containerRenderer = container ? container->renderBox() : 0; 127 RenderBox* containerRenderer = container ? container->renderBox() : 0;
128 128
129 // Set the text block height 129 // Set the text block height
130 LayoutUnit desiredLogicalHeight = textBlockLogicalHeight(); 130 LayoutUnit desiredLogicalHeight = textBlockLogicalHeight();
131 LayoutUnit logicalHeightLimit = computeLogicalHeightLimit(); 131 LayoutUnit logicalHeightLimit = computeLogicalHeightLimit();
132 if (innerEditorRenderer && innerEditorRenderer->logicalHeight() > logicalHei ghtLimit) { 132 if (innerEditorRenderer && innerEditorRenderer->logicalHeight() > logicalHei ghtLimit) {
133 if (desiredLogicalHeight != innerEditorRenderer->logicalHeight()) 133 if (desiredLogicalHeight != innerEditorRenderer->logicalHeight())
134 layoutScope.setNeedsLayout(this); 134 layoutScope.setNeedsLayout(this);
135 135
136 m_desiredInnerEditorLogicalHeight = desiredLogicalHeight; 136 m_desiredInnerEditorLogicalHeight = desiredLogicalHeight;
137 137
138 innerEditorRenderer->style()->setLogicalHeight(Length(desiredLogicalHeig ht, Fixed)); 138 innerEditorRenderer->mutableStyleRef().setLogicalHeight(Length(desiredLo gicalHeight, Fixed));
139 layoutScope.setNeedsLayout(innerEditorRenderer); 139 layoutScope.setNeedsLayout(innerEditorRenderer);
140 if (viewPortRenderer) { 140 if (viewPortRenderer) {
141 viewPortRenderer->style()->setLogicalHeight(Length(desiredLogicalHei ght, Fixed)); 141 viewPortRenderer->mutableStyleRef().setLogicalHeight(Length(desiredL ogicalHeight, Fixed));
142 layoutScope.setNeedsLayout(viewPortRenderer); 142 layoutScope.setNeedsLayout(viewPortRenderer);
143 } 143 }
144 } 144 }
145 // The container might be taller because of decoration elements. 145 // The container might be taller because of decoration elements.
146 if (containerRenderer) { 146 if (containerRenderer) {
147 containerRenderer->layoutIfNeeded(); 147 containerRenderer->layoutIfNeeded();
148 LayoutUnit containerLogicalHeight = containerRenderer->logicalHeight(); 148 LayoutUnit containerLogicalHeight = containerRenderer->logicalHeight();
149 if (containerLogicalHeight > logicalHeightLimit) { 149 if (containerLogicalHeight > logicalHeightLimit) {
150 containerRenderer->style()->setLogicalHeight(Length(logicalHeightLim it, Fixed)); 150 containerRenderer->mutableStyleRef().setLogicalHeight(Length(logical HeightLimit, Fixed));
151 layoutScope.setNeedsLayout(this); 151 layoutScope.setNeedsLayout(this);
152 } else if (containerRenderer->logicalHeight() < contentLogicalHeight()) { 152 } else if (containerRenderer->logicalHeight() < contentLogicalHeight()) {
153 containerRenderer->style()->setLogicalHeight(Length(contentLogicalHe ight(), Fixed)); 153 containerRenderer->mutableStyleRef().setLogicalHeight(Length(content LogicalHeight(), Fixed));
154 layoutScope.setNeedsLayout(this); 154 layoutScope.setNeedsLayout(this);
155 } else { 155 } else {
156 containerRenderer->style()->setLogicalHeight(Length(containerLogical Height, Fixed)); 156 containerRenderer->mutableStyleRef().setLogicalHeight(Length(contain erLogicalHeight, Fixed));
157 } 157 }
158 } 158 }
159 159
160 // If we need another layout pass, we have changed one of children's height so we need to relayout them. 160 // If we need another layout pass, we have changed one of children's height so we need to relayout them.
161 if (needsLayout()) 161 if (needsLayout())
162 RenderBlockFlow::layoutBlock(true); 162 RenderBlockFlow::layoutBlock(true);
163 163
164 // Center the child block in the block progression direction (vertical cente ring for horizontal text fields). 164 // Center the child block in the block progression direction (vertical cente ring for horizontal text fields).
165 if (!container && innerEditorRenderer && innerEditorRenderer->size().height( ) != contentLogicalHeight()) { 165 if (!container && innerEditorRenderer && innerEditorRenderer->size().height( ) != contentLogicalHeight()) {
166 LayoutUnit logicalHeightDiff = innerEditorRenderer->logicalHeight() - co ntentLogicalHeight(); 166 LayoutUnit logicalHeightDiff = innerEditorRenderer->logicalHeight() - co ntentLogicalHeight();
167 innerEditorRenderer->setLogicalTop(innerEditorRenderer->logicalTop() - ( logicalHeightDiff / 2 + layoutMod(logicalHeightDiff, 2))); 167 innerEditorRenderer->setLogicalTop(innerEditorRenderer->logicalTop() - ( logicalHeightDiff / 2 + layoutMod(logicalHeightDiff, 2)));
168 } else { 168 } else {
169 centerContainerIfNeeded(containerRenderer); 169 centerContainerIfNeeded(containerRenderer);
170 } 170 }
171 171
172 HTMLElement* placeholderElement = inputElement()->placeholderElement(); 172 HTMLElement* placeholderElement = inputElement()->placeholderElement();
173 if (RenderBox* placeholderBox = placeholderElement ? placeholderElement->ren derBox() : 0) { 173 if (RenderBox* placeholderBox = placeholderElement ? placeholderElement->ren derBox() : 0) {
174 LayoutSize innerEditorSize; 174 LayoutSize innerEditorSize;
175 175
176 if (innerEditorRenderer) 176 if (innerEditorRenderer)
177 innerEditorSize = innerEditorRenderer->size(); 177 innerEditorSize = innerEditorRenderer->size();
178 placeholderBox->style()->setWidth(Length(innerEditorSize.width() - place holderBox->borderAndPaddingWidth(), Fixed)); 178 placeholderBox->mutableStyleRef().setWidth(Length(innerEditorSize.width( ) - placeholderBox->borderAndPaddingWidth(), Fixed));
179 placeholderBox->style()->setHeight(Length(innerEditorSize.height() - pla ceholderBox->borderAndPaddingHeight(), Fixed)); 179 placeholderBox->mutableStyleRef().setHeight(Length(innerEditorSize.heigh t() - placeholderBox->borderAndPaddingHeight(), Fixed));
180 bool neededLayout = placeholderBox->needsLayout(); 180 bool neededLayout = placeholderBox->needsLayout();
181 placeholderBox->layoutIfNeeded(); 181 placeholderBox->layoutIfNeeded();
182 LayoutPoint textOffset; 182 LayoutPoint textOffset;
183 if (innerEditorRenderer) 183 if (innerEditorRenderer)
184 textOffset = innerEditorRenderer->location(); 184 textOffset = innerEditorRenderer->location();
185 if (editingViewPortElement() && editingViewPortElement()->renderBox()) 185 if (editingViewPortElement() && editingViewPortElement()->renderBox())
186 textOffset += toLayoutSize(editingViewPortElement()->renderBox()->lo cation()); 186 textOffset += toLayoutSize(editingViewPortElement()->renderBox()->lo cation());
187 if (containerRenderer) 187 if (containerRenderer)
188 textOffset += toLayoutSize(containerRenderer->location()); 188 textOffset += toLayoutSize(containerRenderer->location());
189 placeholderBox->setLocation(textOffset); 189 placeholderBox->setLocation(textOffset);
(...skipping 30 matching lines...) Expand all
220 220
221 void LayoutTextControlSingleLine::styleDidChange(StyleDifference diff, const Lay outStyle* oldStyle) 221 void LayoutTextControlSingleLine::styleDidChange(StyleDifference diff, const Lay outStyle* oldStyle)
222 { 222 {
223 m_desiredInnerEditorLogicalHeight = -1; 223 m_desiredInnerEditorLogicalHeight = -1;
224 LayoutTextControl::styleDidChange(diff, oldStyle); 224 LayoutTextControl::styleDidChange(diff, oldStyle);
225 225
226 // We may have set the width and the height in the old style in layout(). 226 // We may have set the width and the height in the old style in layout().
227 // Reset them now to avoid getting a spurious layout hint. 227 // Reset them now to avoid getting a spurious layout hint.
228 Element* viewPort = editingViewPortElement(); 228 Element* viewPort = editingViewPortElement();
229 if (LayoutObject* viewPortRenderer = viewPort ? viewPort->renderer() : 0) { 229 if (LayoutObject* viewPortRenderer = viewPort ? viewPort->renderer() : 0) {
230 viewPortRenderer->style()->setHeight(Length()); 230 viewPortRenderer->mutableStyle()->setHeight(Length());
231 viewPortRenderer->style()->setWidth(Length()); 231 viewPortRenderer->mutableStyle()->setWidth(Length());
232 } 232 }
233 Element* container = containerElement(); 233 Element* container = containerElement();
234 if (LayoutObject* containerRenderer = container ? container->renderer() : 0) { 234 if (LayoutObject* containerRenderer = container ? container->renderer() : 0) {
235 containerRenderer->style()->setHeight(Length()); 235 containerRenderer->mutableStyle()->setHeight(Length());
236 containerRenderer->style()->setWidth(Length()); 236 containerRenderer->mutableStyle()->setWidth(Length());
237 } 237 }
238 LayoutObject* innerEditorRenderer = innerEditorElement()->renderer(); 238 LayoutObject* innerEditorRenderer = innerEditorElement()->renderer();
239 if (innerEditorRenderer && diff.needsFullLayout()) 239 if (innerEditorRenderer && diff.needsFullLayout())
240 innerEditorRenderer->setNeedsLayoutAndFullPaintInvalidation(); 240 innerEditorRenderer->setNeedsLayoutAndFullPaintInvalidation();
241 if (HTMLElement* placeholder = inputElement()->placeholderElement()) 241 if (HTMLElement* placeholder = inputElement()->placeholderElement())
242 placeholder->setInlineStyleProperty(CSSPropertyTextOverflow, textShouldB eTruncated() ? CSSValueEllipsis : CSSValueClip); 242 placeholder->setInlineStyleProperty(CSSPropertyTextOverflow, textShouldB eTruncated() ? CSSValueEllipsis : CSSValueClip);
243 setHasOverflowClip(false); 243 setHasOverflowClip(false);
244 } 244 }
245 245
246 void LayoutTextControlSingleLine::capsLockStateMayHaveChanged() 246 void LayoutTextControlSingleLine::capsLockStateMayHaveChanged()
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 if (innerEditorElement()) 422 if (innerEditorElement())
423 innerEditorElement()->setScrollTop(newTop); 423 innerEditorElement()->setScrollTop(newTop);
424 } 424 }
425 425
426 HTMLInputElement* LayoutTextControlSingleLine::inputElement() const 426 HTMLInputElement* LayoutTextControlSingleLine::inputElement() const
427 { 427 {
428 return toHTMLInputElement(node()); 428 return toHTMLInputElement(node());
429 } 429 }
430 430
431 } 431 }
OLDNEW
« no previous file with comments | « Source/core/layout/LayoutTextControlMultiLine.cpp ('k') | Source/core/layout/MultiColumnFragmentainerGroup.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698