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

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

Issue 922423002: Move rendering/RenderTextControl* to layout/LayoutTextControl* (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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.
11 * 11 *
12 * This library is distributed in the hope that it will be useful, 12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details. 15 * Library General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU Library General Public License 17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to 18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA. 20 * Boston, MA 02110-1301, USA.
21 * 21 *
22 */ 22 */
23 23
24 #include "config.h" 24 #include "config.h"
25 #include "core/rendering/RenderTextControlSingleLine.h" 25 #include "core/layout/LayoutTextControlSingleLine.h"
26 26
27 #include "core/CSSValueKeywords.h" 27 #include "core/CSSValueKeywords.h"
28 #include "core/InputTypeNames.h" 28 #include "core/InputTypeNames.h"
29 #include "core/dom/shadow/ShadowRoot.h" 29 #include "core/dom/shadow/ShadowRoot.h"
30 #include "core/editing/FrameSelection.h" 30 #include "core/editing/FrameSelection.h"
31 #include "core/frame/LocalFrame.h" 31 #include "core/frame/LocalFrame.h"
32 #include "core/html/shadow/ShadowElementNames.h" 32 #include "core/html/shadow/ShadowElementNames.h"
33 #include "core/layout/HitTestResult.h" 33 #include "core/layout/HitTestResult.h"
34 #include "core/layout/Layer.h" 34 #include "core/layout/Layer.h"
35 #include "core/layout/LayoutTheme.h" 35 #include "core/layout/LayoutTheme.h"
36 #include "platform/PlatformKeyboardEvent.h" 36 #include "platform/PlatformKeyboardEvent.h"
37 #include "platform/fonts/SimpleFontData.h" 37 #include "platform/fonts/SimpleFontData.h"
38 38
39 namespace blink { 39 namespace blink {
40 40
41 using namespace HTMLNames; 41 using namespace HTMLNames;
42 42
43 RenderTextControlSingleLine::RenderTextControlSingleLine(HTMLInputElement* eleme nt) 43 LayoutTextControlSingleLine::LayoutTextControlSingleLine(HTMLInputElement* eleme nt)
44 : RenderTextControl(element) 44 : LayoutTextControl(element)
45 , m_shouldDrawCapsLockIndicator(false) 45 , m_shouldDrawCapsLockIndicator(false)
46 , m_desiredInnerEditorLogicalHeight(-1) 46 , m_desiredInnerEditorLogicalHeight(-1)
47 { 47 {
48 } 48 }
49 49
50 RenderTextControlSingleLine::~RenderTextControlSingleLine() 50 LayoutTextControlSingleLine::~LayoutTextControlSingleLine()
51 { 51 {
52 } 52 }
53 53
54 inline Element* RenderTextControlSingleLine::containerElement() const 54 inline Element* LayoutTextControlSingleLine::containerElement() const
55 { 55 {
56 return inputElement()->userAgentShadowRoot()->getElementById(ShadowElementNa mes::textFieldContainer()); 56 return inputElement()->userAgentShadowRoot()->getElementById(ShadowElementNa mes::textFieldContainer());
57 } 57 }
58 58
59 inline Element* RenderTextControlSingleLine::editingViewPortElement() const 59 inline Element* LayoutTextControlSingleLine::editingViewPortElement() const
60 { 60 {
61 return inputElement()->userAgentShadowRoot()->getElementById(ShadowElementNa mes::editingViewPort()); 61 return inputElement()->userAgentShadowRoot()->getElementById(ShadowElementNa mes::editingViewPort());
62 } 62 }
63 63
64 inline HTMLElement* RenderTextControlSingleLine::innerSpinButtonElement() const 64 inline HTMLElement* LayoutTextControlSingleLine::innerSpinButtonElement() const
65 { 65 {
66 return toHTMLElement(inputElement()->userAgentShadowRoot()->getElementById(S hadowElementNames::spinButton())); 66 return toHTMLElement(inputElement()->userAgentShadowRoot()->getElementById(S hadowElementNames::spinButton()));
67 } 67 }
68 68
69 void RenderTextControlSingleLine::paint(const PaintInfo& paintInfo, const Layout Point& paintOffset) 69 void LayoutTextControlSingleLine::paint(const PaintInfo& paintInfo, const Layout Point& paintOffset)
70 { 70 {
71 RenderTextControl::paint(paintInfo, paintOffset); 71 LayoutTextControl::paint(paintInfo, paintOffset);
72 72
73 if (paintInfo.phase == PaintPhaseBlockBackground && m_shouldDrawCapsLockIndi cator) { 73 if (paintInfo.phase == PaintPhaseBlockBackground && m_shouldDrawCapsLockIndi cator) {
74 LayoutRect contentsRect = contentBoxRect(); 74 LayoutRect contentsRect = contentBoxRect();
75 75
76 // Center in the block progression direction. 76 // Center in the block progression direction.
77 if (isHorizontalWritingMode()) 77 if (isHorizontalWritingMode())
78 contentsRect.setY((size().height() - contentsRect.height()) / 2); 78 contentsRect.setY((size().height() - contentsRect.height()) / 2);
79 else 79 else
80 contentsRect.setX((size().width() - contentsRect.width()) / 2); 80 contentsRect.setX((size().width() - contentsRect.width()) / 2);
81 81
82 // Convert the rect into the coords used for painting the content 82 // Convert the rect into the coords used for painting the content
83 contentsRect.moveBy(paintOffset + location()); 83 contentsRect.moveBy(paintOffset + location());
84 LayoutTheme::theme().paintCapsLockIndicator(this, paintInfo, pixelSnappe dIntRect(contentsRect)); 84 LayoutTheme::theme().paintCapsLockIndicator(this, paintInfo, pixelSnappe dIntRect(contentsRect));
85 } 85 }
86 } 86 }
87 87
88 LayoutUnit RenderTextControlSingleLine::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 RenderTextControlSingleLine::layout() 93 void LayoutTextControlSingleLine::layout()
94 { 94 {
95 SubtreeLayoutScope layoutScope(*this); 95 SubtreeLayoutScope layoutScope(*this);
96 96
97 // FIXME: We should remove the height-related hacks in layout() and 97 // FIXME: We should remove the height-related hacks in layout() and
98 // styleDidChange(). We need them because 98 // styleDidChange(). We need them because
99 // - Center the inner elements vertically if the input height is taller than 99 // - Center the inner elements vertically if the input height is taller than
100 // the intrinsic height of the inner elements. 100 // the intrinsic height of the inner elements.
101 // - Shrink the inner elment heights if the input height is samller than the 101 // - Shrink the inner elment heights if the input height is samller than the
102 // intrinsic heights of the inner elements. 102 // intrinsic heights of the inner elements.
103 103
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->style()->setLogicalHeight(Length(logicalHeightLim it, 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->style()->setLogicalHeight(Length(contentLogicalHe ight(), Fixed));
154 layoutScope.setNeedsLayout(this); 154 layoutScope.setNeedsLayout(this);
155 } else 155 } else {
156 containerRenderer->style()->setLogicalHeight(Length(containerLogical Height, Fixed)); 156 containerRenderer->style()->setLogicalHeight(Length(containerLogical Height, Fixed));
157 }
157 } 158 }
158 159
159 // 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.
160 if (needsLayout()) 161 if (needsLayout())
161 RenderBlockFlow::layoutBlock(true); 162 RenderBlockFlow::layoutBlock(true);
162 163
163 // 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).
164 if (!container && innerEditorRenderer && innerEditorRenderer->size().height( ) != contentLogicalHeight()) { 165 if (!container && innerEditorRenderer && innerEditorRenderer->size().height( ) != contentLogicalHeight()) {
165 LayoutUnit logicalHeightDiff = innerEditorRenderer->logicalHeight() - co ntentLogicalHeight(); 166 LayoutUnit logicalHeightDiff = innerEditorRenderer->logicalHeight() - co ntentLogicalHeight();
166 innerEditorRenderer->setLogicalTop(innerEditorRenderer->logicalTop() - ( logicalHeightDiff / 2 + layoutMod(logicalHeightDiff, 2))); 167 innerEditorRenderer->setLogicalTop(innerEditorRenderer->logicalTop() - ( logicalHeightDiff / 2 + layoutMod(logicalHeightDiff, 2)));
167 } else 168 } else {
168 centerContainerIfNeeded(containerRenderer); 169 centerContainerIfNeeded(containerRenderer);
170 }
169 171
170 HTMLElement* placeholderElement = inputElement()->placeholderElement(); 172 HTMLElement* placeholderElement = inputElement()->placeholderElement();
171 if (RenderBox* placeholderBox = placeholderElement ? placeholderElement->ren derBox() : 0) { 173 if (RenderBox* placeholderBox = placeholderElement ? placeholderElement->ren derBox() : 0) {
172 LayoutSize innerEditorSize; 174 LayoutSize innerEditorSize;
173 175
174 if (innerEditorRenderer) 176 if (innerEditorRenderer)
175 innerEditorSize = innerEditorRenderer->size(); 177 innerEditorSize = innerEditorRenderer->size();
176 placeholderBox->style()->setWidth(Length(innerEditorSize.width() - place holderBox->borderAndPaddingWidth(), Fixed)); 178 placeholderBox->style()->setWidth(Length(innerEditorSize.width() - place holderBox->borderAndPaddingWidth(), Fixed));
177 placeholderBox->style()->setHeight(Length(innerEditorSize.height() - pla ceholderBox->borderAndPaddingHeight(), Fixed)); 179 placeholderBox->style()->setHeight(Length(innerEditorSize.height() - pla ceholderBox->borderAndPaddingHeight(), Fixed));
178 bool neededLayout = placeholderBox->needsLayout(); 180 bool neededLayout = placeholderBox->needsLayout();
179 placeholderBox->layoutIfNeeded(); 181 placeholderBox->layoutIfNeeded();
180 LayoutPoint textOffset; 182 LayoutPoint textOffset;
181 if (innerEditorRenderer) 183 if (innerEditorRenderer)
182 textOffset = innerEditorRenderer->location(); 184 textOffset = innerEditorRenderer->location();
183 if (editingViewPortElement() && editingViewPortElement()->renderBox()) 185 if (editingViewPortElement() && editingViewPortElement()->renderBox())
184 textOffset += toLayoutSize(editingViewPortElement()->renderBox()->lo cation()); 186 textOffset += toLayoutSize(editingViewPortElement()->renderBox()->lo cation());
185 if (containerRenderer) 187 if (containerRenderer)
186 textOffset += toLayoutSize(containerRenderer->location()); 188 textOffset += toLayoutSize(containerRenderer->location());
187 placeholderBox->setLocation(textOffset); 189 placeholderBox->setLocation(textOffset);
188 190
189 // The placeholder gets layout last, after the parent text control and i ts other children, 191 // The placeholder gets layout last, after the parent text control and i ts other children,
190 // so in order to get the correct overflow from the placeholder we need to recompute it now. 192 // so in order to get the correct overflow from the placeholder we need to recompute it now.
191 if (neededLayout) 193 if (neededLayout)
192 computeOverflow(clientLogicalBottom()); 194 computeOverflow(clientLogicalBottom());
193 } 195 }
194 } 196 }
195 197
196 bool RenderTextControlSingleLine::nodeAtPoint(const HitTestRequest& request, Hit TestResult& result, const HitTestLocation& locationInContainer, const LayoutPoin t& accumulatedOffset, HitTestAction hitTestAction) 198 bool LayoutTextControlSingleLine::nodeAtPoint(const HitTestRequest& request, Hit TestResult& result, const HitTestLocation& locationInContainer, const LayoutPoin t& accumulatedOffset, HitTestAction hitTestAction)
197 { 199 {
198 if (!RenderTextControl::nodeAtPoint(request, result, locationInContainer, ac cumulatedOffset, hitTestAction)) 200 if (!LayoutTextControl::nodeAtPoint(request, result, locationInContainer, ac cumulatedOffset, hitTestAction))
199 return false; 201 return false;
200 202
201 // Say that we hit the inner text element if 203 // Say that we hit the inner text element if
202 // - we hit a node inside the inner text element, 204 // - we hit a node inside the inner text element,
203 // - we hit the <input> element (e.g. we're over the border or padding), or 205 // - we hit the <input> element (e.g. we're over the border or padding), or
204 // - we hit regions not in any decoration buttons. 206 // - we hit regions not in any decoration buttons.
205 Element* container = containerElement(); 207 Element* container = containerElement();
206 if (result.innerNode()->isDescendantOf(innerEditorElement()) || result.inner Node() == node() || (container && container == result.innerNode())) { 208 if (result.innerNode()->isDescendantOf(innerEditorElement()) || result.inner Node() == node() || (container && container == result.innerNode())) {
207 LayoutPoint pointInParent = locationInContainer.point(); 209 LayoutPoint pointInParent = locationInContainer.point();
208 if (container && editingViewPortElement()) { 210 if (container && editingViewPortElement()) {
209 if (editingViewPortElement()->renderBox()) 211 if (editingViewPortElement()->renderBox())
210 pointInParent -= toLayoutSize(editingViewPortElement()->renderBo x()->location()); 212 pointInParent -= toLayoutSize(editingViewPortElement()->renderBo x()->location());
211 if (container->renderBox()) 213 if (container->renderBox())
212 pointInParent -= toLayoutSize(container->renderBox()->location() ); 214 pointInParent -= toLayoutSize(container->renderBox()->location() );
213 } 215 }
214 hitInnerEditorElement(result, pointInParent, accumulatedOffset); 216 hitInnerEditorElement(result, pointInParent, accumulatedOffset);
215 } 217 }
216 return true; 218 return true;
217 } 219 }
218 220
219 void RenderTextControlSingleLine::styleDidChange(StyleDifference diff, const Lay outStyle* oldStyle) 221 void LayoutTextControlSingleLine::styleDidChange(StyleDifference diff, const Lay outStyle* oldStyle)
220 { 222 {
221 m_desiredInnerEditorLogicalHeight = -1; 223 m_desiredInnerEditorLogicalHeight = -1;
222 RenderTextControl::styleDidChange(diff, oldStyle); 224 LayoutTextControl::styleDidChange(diff, oldStyle);
223 225
224 // 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().
225 // Reset them now to avoid getting a spurious layout hint. 227 // Reset them now to avoid getting a spurious layout hint.
226 Element* viewPort = editingViewPortElement(); 228 Element* viewPort = editingViewPortElement();
227 if (LayoutObject* viewPortRenderer = viewPort ? viewPort->renderer() : 0) { 229 if (LayoutObject* viewPortRenderer = viewPort ? viewPort->renderer() : 0) {
228 viewPortRenderer->style()->setHeight(Length()); 230 viewPortRenderer->style()->setHeight(Length());
229 viewPortRenderer->style()->setWidth(Length()); 231 viewPortRenderer->style()->setWidth(Length());
230 } 232 }
231 Element* container = containerElement(); 233 Element* container = containerElement();
232 if (LayoutObject* containerRenderer = container ? container->renderer() : 0) { 234 if (LayoutObject* containerRenderer = container ? container->renderer() : 0) {
233 containerRenderer->style()->setHeight(Length()); 235 containerRenderer->style()->setHeight(Length());
234 containerRenderer->style()->setWidth(Length()); 236 containerRenderer->style()->setWidth(Length());
235 } 237 }
236 LayoutObject* innerEditorRenderer = innerEditorElement()->renderer(); 238 LayoutObject* innerEditorRenderer = innerEditorElement()->renderer();
237 if (innerEditorRenderer && diff.needsFullLayout()) 239 if (innerEditorRenderer && diff.needsFullLayout())
238 innerEditorRenderer->setNeedsLayoutAndFullPaintInvalidation(); 240 innerEditorRenderer->setNeedsLayoutAndFullPaintInvalidation();
239 if (HTMLElement* placeholder = inputElement()->placeholderElement()) 241 if (HTMLElement* placeholder = inputElement()->placeholderElement())
240 placeholder->setInlineStyleProperty(CSSPropertyTextOverflow, textShouldB eTruncated() ? CSSValueEllipsis : CSSValueClip); 242 placeholder->setInlineStyleProperty(CSSPropertyTextOverflow, textShouldB eTruncated() ? CSSValueEllipsis : CSSValueClip);
241 setHasOverflowClip(false); 243 setHasOverflowClip(false);
242 } 244 }
243 245
244 void RenderTextControlSingleLine::capsLockStateMayHaveChanged() 246 void LayoutTextControlSingleLine::capsLockStateMayHaveChanged()
245 { 247 {
246 if (!node()) 248 if (!node())
247 return; 249 return;
248 250
249 // Only draw the caps lock indicator if these things are true: 251 // Only draw the caps lock indicator if these things are true:
250 // 1) The field is a password field 252 // 1) The field is a password field
251 // 2) The frame is active 253 // 2) The frame is active
252 // 3) The element is focused 254 // 3) The element is focused
253 // 4) The caps lock is on 255 // 4) The caps lock is on
254 bool shouldDrawCapsLockIndicator = false; 256 bool shouldDrawCapsLockIndicator = false;
255 257
256 if (LocalFrame* frame = document().frame()) 258 if (LocalFrame* frame = document().frame())
257 shouldDrawCapsLockIndicator = inputElement()->type() == InputTypeNames:: password && frame->selection().isFocusedAndActive() && document().focusedElement () == node() && PlatformKeyboardEvent::currentCapsLockState(); 259 shouldDrawCapsLockIndicator = inputElement()->type() == InputTypeNames:: password && frame->selection().isFocusedAndActive() && document().focusedElement () == node() && PlatformKeyboardEvent::currentCapsLockState();
258 260
259 if (shouldDrawCapsLockIndicator != m_shouldDrawCapsLockIndicator) { 261 if (shouldDrawCapsLockIndicator != m_shouldDrawCapsLockIndicator) {
260 m_shouldDrawCapsLockIndicator = shouldDrawCapsLockIndicator; 262 m_shouldDrawCapsLockIndicator = shouldDrawCapsLockIndicator;
261 setShouldDoFullPaintInvalidation(); 263 setShouldDoFullPaintInvalidation();
262 } 264 }
263 } 265 }
264 266
265 bool RenderTextControlSingleLine::hasControlClip() const 267 bool LayoutTextControlSingleLine::hasControlClip() const
266 { 268 {
267 // Apply control clip for text fields with decorations. 269 // Apply control clip for text fields with decorations.
268 return !!containerElement(); 270 return !!containerElement();
269 } 271 }
270 272
271 LayoutRect RenderTextControlSingleLine::controlClipRect(const LayoutPoint& addit ionalOffset) const 273 LayoutRect LayoutTextControlSingleLine::controlClipRect(const LayoutPoint& addit ionalOffset) const
272 { 274 {
273 ASSERT(hasControlClip()); 275 ASSERT(hasControlClip());
274 LayoutRect clipRect = contentBoxRect(); 276 LayoutRect clipRect = contentBoxRect();
275 if (containerElement()->renderBox()) 277 if (containerElement()->renderBox())
276 clipRect = unionRect(clipRect, containerElement()->renderBox()->frameRec t()); 278 clipRect = unionRect(clipRect, containerElement()->renderBox()->frameRec t());
277 clipRect.moveBy(additionalOffset); 279 clipRect.moveBy(additionalOffset);
278 return clipRect; 280 return clipRect;
279 } 281 }
280 282
281 float RenderTextControlSingleLine::getAvgCharWidth(AtomicString family) 283 float LayoutTextControlSingleLine::getAvgCharWidth(AtomicString family)
282 { 284 {
283 // Since Lucida Grande is the default font, we want this to match the width 285 // Since Lucida Grande is the default font, we want this to match the width
284 // of MS Shell Dlg, the default font for textareas in Firefox, Safari Win an d 286 // of MS Shell Dlg, the default font for textareas in Firefox, Safari Win an d
285 // IE for some encodings (in IE, the default font is encoding specific). 287 // IE for some encodings (in IE, the default font is encoding specific).
286 // 901 is the avgCharWidth value in the OS/2 table for MS Shell Dlg. 288 // 901 is the avgCharWidth value in the OS/2 table for MS Shell Dlg.
287 if (family == "Lucida Grande") 289 if (family == "Lucida Grande")
288 return scaleEmToUnits(901); 290 return scaleEmToUnits(901);
289 291
290 return RenderTextControl::getAvgCharWidth(family); 292 return LayoutTextControl::getAvgCharWidth(family);
291 } 293 }
292 294
293 LayoutUnit RenderTextControlSingleLine::preferredContentLogicalWidth(float charW idth) const 295 LayoutUnit LayoutTextControlSingleLine::preferredContentLogicalWidth(float charW idth) const
294 { 296 {
295 int factor; 297 int factor;
296 bool includesDecoration = inputElement()->sizeShouldIncludeDecoration(factor ); 298 bool includesDecoration = inputElement()->sizeShouldIncludeDecoration(factor );
297 if (factor <= 0) 299 if (factor <= 0)
298 factor = 20; 300 factor = 20;
299 301
300 LayoutUnit result = LayoutUnit::fromFloatCeil(charWidth * factor); 302 LayoutUnit result = LayoutUnit::fromFloatCeil(charWidth * factor);
301 303
302 float maxCharWidth = 0.f; 304 float maxCharWidth = 0.f;
303 AtomicString family = style()->font().fontDescription().family().family(); 305 AtomicString family = style()->font().fontDescription().family().family();
(...skipping 16 matching lines...) Expand all
320 result += spinRenderer->borderAndPaddingLogicalWidth(); 322 result += spinRenderer->borderAndPaddingLogicalWidth();
321 // Since the width of spinRenderer is not calculated yet, spinRender er->logicalWidth() returns 0. 323 // Since the width of spinRenderer is not calculated yet, spinRender er->logicalWidth() returns 0.
322 // So computedStyle()->logicalWidth() is used instead. 324 // So computedStyle()->logicalWidth() is used instead.
323 result += spinButton->computedStyle()->logicalWidth().value(); 325 result += spinButton->computedStyle()->logicalWidth().value();
324 } 326 }
325 } 327 }
326 328
327 return result; 329 return result;
328 } 330 }
329 331
330 LayoutUnit RenderTextControlSingleLine::computeControlLogicalHeight(LayoutUnit l ineHeight, LayoutUnit nonContentHeight) const 332 LayoutUnit LayoutTextControlSingleLine::computeControlLogicalHeight(LayoutUnit l ineHeight, LayoutUnit nonContentHeight) const
331 { 333 {
332 return lineHeight + nonContentHeight; 334 return lineHeight + nonContentHeight;
333 } 335 }
334 336
335 PassRefPtr<LayoutStyle> RenderTextControlSingleLine::createInnerEditorStyle(cons t LayoutStyle& startStyle) const 337 PassRefPtr<LayoutStyle> LayoutTextControlSingleLine::createInnerEditorStyle(cons t LayoutStyle& startStyle) const
336 { 338 {
337 RefPtr<LayoutStyle> textBlockStyle = LayoutStyle::create(); 339 RefPtr<LayoutStyle> textBlockStyle = LayoutStyle::create();
338 textBlockStyle->inheritFrom(startStyle); 340 textBlockStyle->inheritFrom(startStyle);
339 adjustInnerEditorStyle(*textBlockStyle); 341 adjustInnerEditorStyle(*textBlockStyle);
340 342
341 textBlockStyle->setWhiteSpace(PRE); 343 textBlockStyle->setWhiteSpace(PRE);
342 textBlockStyle->setOverflowWrap(NormalOverflowWrap); 344 textBlockStyle->setOverflowWrap(NormalOverflowWrap);
343 textBlockStyle->setOverflowX(OHIDDEN); 345 textBlockStyle->setOverflowX(OHIDDEN);
344 textBlockStyle->setOverflowY(OHIDDEN); 346 textBlockStyle->setOverflowY(OHIDDEN);
345 textBlockStyle->setTextOverflow(textShouldBeTruncated() ? TextOverflowEllips is : TextOverflowClip); 347 textBlockStyle->setTextOverflow(textShouldBeTruncated() ? TextOverflowEllips is : TextOverflowClip);
346 348
347 if (m_desiredInnerEditorLogicalHeight >= 0) 349 if (m_desiredInnerEditorLogicalHeight >= 0)
348 textBlockStyle->setLogicalHeight(Length(m_desiredInnerEditorLogicalHeigh t, Fixed)); 350 textBlockStyle->setLogicalHeight(Length(m_desiredInnerEditorLogicalHeigh t, Fixed));
349 // Do not allow line-height to be smaller than our default. 351 // Do not allow line-height to be smaller than our default.
350 if (textBlockStyle->fontMetrics().lineSpacing() > lineHeight(true, Horizonta lLine, PositionOfInteriorLineBoxes)) 352 if (textBlockStyle->fontMetrics().lineSpacing() > lineHeight(true, Horizonta lLine, PositionOfInteriorLineBoxes))
351 textBlockStyle->setLineHeight(LayoutStyle::initialLineHeight()); 353 textBlockStyle->setLineHeight(LayoutStyle::initialLineHeight());
352 354
353 textBlockStyle->setDisplay(BLOCK); 355 textBlockStyle->setDisplay(BLOCK);
354 textBlockStyle->setUnique(); 356 textBlockStyle->setUnique();
355 357
356 if (inputElement()->shouldRevealPassword()) 358 if (inputElement()->shouldRevealPassword())
357 textBlockStyle->setTextSecurity(TSNONE); 359 textBlockStyle->setTextSecurity(TSNONE);
358 360
359 return textBlockStyle.release(); 361 return textBlockStyle.release();
360 } 362 }
361 363
362 bool RenderTextControlSingleLine::textShouldBeTruncated() const 364 bool LayoutTextControlSingleLine::textShouldBeTruncated() const
363 { 365 {
364 return document().focusedElement() != node() && style()->textOverflow() == T extOverflowEllipsis; 366 return document().focusedElement() != node() && style()->textOverflow() == T extOverflowEllipsis;
365 } 367 }
366 368
367 void RenderTextControlSingleLine::autoscroll(const IntPoint& position) 369 void LayoutTextControlSingleLine::autoscroll(const IntPoint& position)
368 { 370 {
369 RenderBox* renderer = innerEditorElement()->renderBox(); 371 RenderBox* renderer = innerEditorElement()->renderBox();
370 if (!renderer) 372 if (!renderer)
371 return; 373 return;
372 374
373 renderer->autoscroll(position); 375 renderer->autoscroll(position);
374 } 376 }
375 377
376 LayoutUnit RenderTextControlSingleLine::scrollWidth() const 378 LayoutUnit LayoutTextControlSingleLine::scrollWidth() const
377 { 379 {
378 if (RenderBox* inner = innerEditorElement() ? innerEditorElement()->renderBo x() : 0) { 380 if (RenderBox* inner = innerEditorElement() ? innerEditorElement()->renderBo x() : 0) {
379 // Adjust scrollWidth to inculde input element horizontal paddings and 381 // Adjust scrollWidth to inculde input element horizontal paddings and
380 // decoration width 382 // decoration width
381 LayoutUnit adjustment = clientWidth() - inner->clientWidth(); 383 LayoutUnit adjustment = clientWidth() - inner->clientWidth();
382 return innerEditorElement()->scrollWidth() + adjustment; 384 return innerEditorElement()->scrollWidth() + adjustment;
383 } 385 }
384 return RenderBlockFlow::scrollWidth(); 386 return RenderBlockFlow::scrollWidth();
385 } 387 }
386 388
387 LayoutUnit RenderTextControlSingleLine::scrollHeight() const 389 LayoutUnit LayoutTextControlSingleLine::scrollHeight() const
388 { 390 {
389 if (RenderBox* inner = innerEditorElement() ? innerEditorElement()->renderBo x() : 0) { 391 if (RenderBox* inner = innerEditorElement() ? innerEditorElement()->renderBo x() : 0) {
390 // Adjust scrollHeight to include input element vertical paddings and 392 // Adjust scrollHeight to include input element vertical paddings and
391 // decoration height 393 // decoration height
392 LayoutUnit adjustment = clientHeight() - inner->clientHeight(); 394 LayoutUnit adjustment = clientHeight() - inner->clientHeight();
393 return innerEditorElement()->scrollHeight() + adjustment; 395 return innerEditorElement()->scrollHeight() + adjustment;
394 } 396 }
395 return RenderBlockFlow::scrollHeight(); 397 return RenderBlockFlow::scrollHeight();
396 } 398 }
397 399
398 LayoutUnit RenderTextControlSingleLine::scrollLeft() const 400 LayoutUnit LayoutTextControlSingleLine::scrollLeft() const
399 { 401 {
400 if (innerEditorElement()) 402 if (innerEditorElement())
401 return innerEditorElement()->scrollLeft(); 403 return innerEditorElement()->scrollLeft();
402 return RenderBlockFlow::scrollLeft(); 404 return RenderBlockFlow::scrollLeft();
403 } 405 }
404 406
405 LayoutUnit RenderTextControlSingleLine::scrollTop() const 407 LayoutUnit LayoutTextControlSingleLine::scrollTop() const
406 { 408 {
407 if (innerEditorElement()) 409 if (innerEditorElement())
408 return innerEditorElement()->scrollTop(); 410 return innerEditorElement()->scrollTop();
409 return RenderBlockFlow::scrollTop(); 411 return RenderBlockFlow::scrollTop();
410 } 412 }
411 413
412 void RenderTextControlSingleLine::setScrollLeft(LayoutUnit newLeft) 414 void LayoutTextControlSingleLine::setScrollLeft(LayoutUnit newLeft)
413 { 415 {
414 if (innerEditorElement()) 416 if (innerEditorElement())
415 innerEditorElement()->setScrollLeft(newLeft); 417 innerEditorElement()->setScrollLeft(newLeft);
416 } 418 }
417 419
418 void RenderTextControlSingleLine::setScrollTop(LayoutUnit newTop) 420 void LayoutTextControlSingleLine::setScrollTop(LayoutUnit newTop)
419 { 421 {
420 if (innerEditorElement()) 422 if (innerEditorElement())
421 innerEditorElement()->setScrollTop(newTop); 423 innerEditorElement()->setScrollTop(newTop);
422 } 424 }
423 425
424 HTMLInputElement* RenderTextControlSingleLine::inputElement() const 426 HTMLInputElement* LayoutTextControlSingleLine::inputElement() const
425 { 427 {
426 return toHTMLInputElement(node()); 428 return toHTMLInputElement(node());
427 } 429 }
428 430
429 } 431 }
OLDNEW
« no previous file with comments | « Source/core/layout/LayoutTextControlSingleLine.h ('k') | Source/core/layout/compositing/CompositingRequirementsUpdater.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698