OLD | NEW |
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
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 LayoutBox* innerEditorRenderer = innerEditorElement()->layoutBox(); |
109 RenderBox* viewPortRenderer = editingViewPortElement() ? editingViewPortElem
ent()->renderBox() : 0; | 109 LayoutBox* viewPortRenderer = editingViewPortElement() ? editingViewPortElem
ent()->layoutBox() : 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->style()->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 (LayoutBox* placeholderBox = placeholderElement ? placeholderElement-
>layoutBox() : 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->style()->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 LayoutBox* containerRenderer = container ? container->layoutBox() : 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 |
(...skipping 25 matching lines...) Expand all Loading... |
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 (LayoutBox* placeholderBox = placeholderElement ? placeholderElement->lay
outBox() : 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->style()->setWidth(Length(innerEditorSize.width() - place
holderBox->borderAndPaddingWidth(), Fixed)); |
179 placeholderBox->style()->setHeight(Length(innerEditorSize.height() - pla
ceholderBox->borderAndPaddingHeight(), Fixed)); | 179 placeholderBox->style()->setHeight(Length(innerEditorSize.height() - pla
ceholderBox->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()->layoutBox()) |
186 textOffset += toLayoutSize(editingViewPortElement()->renderBox()->lo
cation()); | 186 textOffset += toLayoutSize(editingViewPortElement()->layoutBox()->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); |
190 | 190 |
191 // 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, |
192 // 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. |
193 if (neededLayout) | 193 if (neededLayout) |
194 computeOverflow(clientLogicalBottom()); | 194 computeOverflow(clientLogicalBottom()); |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 bool LayoutTextControlSingleLine::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) |
199 { | 199 { |
200 if (!LayoutTextControl::nodeAtPoint(request, result, locationInContainer, ac
cumulatedOffset, hitTestAction)) | 200 if (!LayoutTextControl::nodeAtPoint(request, result, locationInContainer, ac
cumulatedOffset, hitTestAction)) |
201 return false; | 201 return false; |
202 | 202 |
203 // Say that we hit the inner text element if | 203 // Say that we hit the inner text element if |
204 // - we hit a node inside the inner text element, | 204 // - we hit a node inside the inner text element, |
205 // - 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 |
206 // - we hit regions not in any decoration buttons. | 206 // - we hit regions not in any decoration buttons. |
207 Element* container = containerElement(); | 207 Element* container = containerElement(); |
208 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())) { |
209 LayoutPoint pointInParent = locationInContainer.point(); | 209 LayoutPoint pointInParent = locationInContainer.point(); |
210 if (container && editingViewPortElement()) { | 210 if (container && editingViewPortElement()) { |
211 if (editingViewPortElement()->renderBox()) | 211 if (editingViewPortElement()->layoutBox()) |
212 pointInParent -= toLayoutSize(editingViewPortElement()->renderBo
x()->location()); | 212 pointInParent -= toLayoutSize(editingViewPortElement()->layoutBo
x()->location()); |
213 if (container->renderBox()) | 213 if (container->layoutBox()) |
214 pointInParent -= toLayoutSize(container->renderBox()->location()
); | 214 pointInParent -= toLayoutSize(container->layoutBox()->location()
); |
215 } | 215 } |
216 hitInnerEditorElement(result, pointInParent, accumulatedOffset); | 216 hitInnerEditorElement(result, pointInParent, accumulatedOffset); |
217 } | 217 } |
218 return true; | 218 return true; |
219 } | 219 } |
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); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 bool LayoutTextControlSingleLine::hasControlClip() const | 267 bool LayoutTextControlSingleLine::hasControlClip() const |
268 { | 268 { |
269 // Apply control clip for text fields with decorations. | 269 // Apply control clip for text fields with decorations. |
270 return !!containerElement(); | 270 return !!containerElement(); |
271 } | 271 } |
272 | 272 |
273 LayoutRect LayoutTextControlSingleLine::controlClipRect(const LayoutPoint& addit
ionalOffset) const | 273 LayoutRect LayoutTextControlSingleLine::controlClipRect(const LayoutPoint& addit
ionalOffset) const |
274 { | 274 { |
275 ASSERT(hasControlClip()); | 275 ASSERT(hasControlClip()); |
276 LayoutRect clipRect = contentBoxRect(); | 276 LayoutRect clipRect = contentBoxRect(); |
277 if (containerElement()->renderBox()) | 277 if (containerElement()->layoutBox()) |
278 clipRect = unionRect(clipRect, containerElement()->renderBox()->frameRec
t()); | 278 clipRect = unionRect(clipRect, containerElement()->layoutBox()->frameRec
t()); |
279 clipRect.moveBy(additionalOffset); | 279 clipRect.moveBy(additionalOffset); |
280 return clipRect; | 280 return clipRect; |
281 } | 281 } |
282 | 282 |
283 float LayoutTextControlSingleLine::getAvgCharWidth(AtomicString family) | 283 float LayoutTextControlSingleLine::getAvgCharWidth(AtomicString family) |
284 { | 284 { |
285 // 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 |
286 // 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 |
287 // 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). |
288 // 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. |
(...skipping 22 matching lines...) Expand all Loading... |
311 maxCharWidth = scaleEmToUnits(4027); | 311 maxCharWidth = scaleEmToUnits(4027); |
312 else if (hasValidAvgCharWidth(family)) | 312 else if (hasValidAvgCharWidth(family)) |
313 maxCharWidth = roundf(style()->font().primaryFont()->maxCharWidth()); | 313 maxCharWidth = roundf(style()->font().primaryFont()->maxCharWidth()); |
314 | 314 |
315 // For text inputs, IE adds some extra width. | 315 // For text inputs, IE adds some extra width. |
316 if (maxCharWidth > 0.f) | 316 if (maxCharWidth > 0.f) |
317 result += maxCharWidth - charWidth; | 317 result += maxCharWidth - charWidth; |
318 | 318 |
319 if (includesDecoration) { | 319 if (includesDecoration) { |
320 HTMLElement* spinButton = innerSpinButtonElement(); | 320 HTMLElement* spinButton = innerSpinButtonElement(); |
321 if (RenderBox* spinRenderer = spinButton ? spinButton->renderBox() : 0)
{ | 321 if (LayoutBox* spinRenderer = spinButton ? spinButton->layoutBox() : 0)
{ |
322 result += spinRenderer->borderAndPaddingLogicalWidth(); | 322 result += spinRenderer->borderAndPaddingLogicalWidth(); |
323 // 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. |
324 // So computedStyle()->logicalWidth() is used instead. | 324 // So computedStyle()->logicalWidth() is used instead. |
325 result += spinButton->computedStyle()->logicalWidth().value(); | 325 result += spinButton->computedStyle()->logicalWidth().value(); |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
329 return result; | 329 return result; |
330 } | 330 } |
331 | 331 |
(...skipping 29 matching lines...) Expand all Loading... |
361 return textBlockStyle.release(); | 361 return textBlockStyle.release(); |
362 } | 362 } |
363 | 363 |
364 bool LayoutTextControlSingleLine::textShouldBeTruncated() const | 364 bool LayoutTextControlSingleLine::textShouldBeTruncated() const |
365 { | 365 { |
366 return document().focusedElement() != node() && style()->textOverflow() == T
extOverflowEllipsis; | 366 return document().focusedElement() != node() && style()->textOverflow() == T
extOverflowEllipsis; |
367 } | 367 } |
368 | 368 |
369 void LayoutTextControlSingleLine::autoscroll(const IntPoint& position) | 369 void LayoutTextControlSingleLine::autoscroll(const IntPoint& position) |
370 { | 370 { |
371 RenderBox* renderer = innerEditorElement()->renderBox(); | 371 LayoutBox* renderer = innerEditorElement()->layoutBox(); |
372 if (!renderer) | 372 if (!renderer) |
373 return; | 373 return; |
374 | 374 |
375 renderer->autoscroll(position); | 375 renderer->autoscroll(position); |
376 } | 376 } |
377 | 377 |
378 LayoutUnit LayoutTextControlSingleLine::scrollWidth() const | 378 LayoutUnit LayoutTextControlSingleLine::scrollWidth() const |
379 { | 379 { |
380 if (RenderBox* inner = innerEditorElement() ? innerEditorElement()->renderBo
x() : 0) { | 380 if (LayoutBox* inner = innerEditorElement() ? innerEditorElement()->layoutBo
x() : 0) { |
381 // Adjust scrollWidth to inculde input element horizontal paddings and | 381 // Adjust scrollWidth to inculde input element horizontal paddings and |
382 // decoration width | 382 // decoration width |
383 LayoutUnit adjustment = clientWidth() - inner->clientWidth(); | 383 LayoutUnit adjustment = clientWidth() - inner->clientWidth(); |
384 return innerEditorElement()->scrollWidth() + adjustment; | 384 return innerEditorElement()->scrollWidth() + adjustment; |
385 } | 385 } |
386 return RenderBlockFlow::scrollWidth(); | 386 return RenderBlockFlow::scrollWidth(); |
387 } | 387 } |
388 | 388 |
389 LayoutUnit LayoutTextControlSingleLine::scrollHeight() const | 389 LayoutUnit LayoutTextControlSingleLine::scrollHeight() const |
390 { | 390 { |
391 if (RenderBox* inner = innerEditorElement() ? innerEditorElement()->renderBo
x() : 0) { | 391 if (LayoutBox* inner = innerEditorElement() ? innerEditorElement()->layoutBo
x() : 0) { |
392 // Adjust scrollHeight to include input element vertical paddings and | 392 // Adjust scrollHeight to include input element vertical paddings and |
393 // decoration height | 393 // decoration height |
394 LayoutUnit adjustment = clientHeight() - inner->clientHeight(); | 394 LayoutUnit adjustment = clientHeight() - inner->clientHeight(); |
395 return innerEditorElement()->scrollHeight() + adjustment; | 395 return innerEditorElement()->scrollHeight() + adjustment; |
396 } | 396 } |
397 return RenderBlockFlow::scrollHeight(); | 397 return RenderBlockFlow::scrollHeight(); |
398 } | 398 } |
399 | 399 |
400 LayoutUnit LayoutTextControlSingleLine::scrollLeft() const | 400 LayoutUnit LayoutTextControlSingleLine::scrollLeft() const |
401 { | 401 { |
(...skipping 20 matching lines...) Expand all Loading... |
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 } |
OLD | NEW |