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 28 matching lines...) Expand all Loading... |
39 #include "platform/PlatformKeyboardEvent.h" | 39 #include "platform/PlatformKeyboardEvent.h" |
40 #include "platform/fonts/SimpleFontData.h" | 40 #include "platform/fonts/SimpleFontData.h" |
41 | 41 |
42 namespace blink { | 42 namespace blink { |
43 | 43 |
44 using namespace HTMLNames; | 44 using namespace HTMLNames; |
45 | 45 |
46 LayoutTextControlSingleLine::LayoutTextControlSingleLine(HTMLInputElement* eleme
nt) | 46 LayoutTextControlSingleLine::LayoutTextControlSingleLine(HTMLInputElement* eleme
nt) |
47 : LayoutTextControl(element) | 47 : LayoutTextControl(element) |
48 , m_shouldDrawCapsLockIndicator(false) | 48 , m_shouldDrawCapsLockIndicator(false) |
49 , m_desiredInnerEditorLogicalHeight(-1) | |
50 { | 49 { |
51 } | 50 } |
52 | 51 |
53 LayoutTextControlSingleLine::~LayoutTextControlSingleLine() | 52 LayoutTextControlSingleLine::~LayoutTextControlSingleLine() |
54 { | 53 { |
55 } | 54 } |
56 | 55 |
57 inline Element* LayoutTextControlSingleLine::containerElement() const | 56 inline Element* LayoutTextControlSingleLine::containerElement() const |
58 { | 57 { |
59 return inputElement()->userAgentShadowRoot()->getElementById(ShadowElementNa
mes::textFieldContainer()); | 58 return inputElement()->userAgentShadowRoot()->getElementById(ShadowElementNa
mes::textFieldContainer()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 LayoutAnalyzer::Scope analyzer(*this); | 102 LayoutAnalyzer::Scope analyzer(*this); |
104 SubtreeLayoutScope layoutScope(*this); | 103 SubtreeLayoutScope layoutScope(*this); |
105 | 104 |
106 // FIXME: This code is madness (https://crbug.com/461117) | 105 // FIXME: This code is madness (https://crbug.com/461117) |
107 // FIXME: We should remove the height-related hacks in layout() and | 106 // FIXME: We should remove the height-related hacks in layout() and |
108 // styleDidChange(). We need them because | 107 // styleDidChange(). We need them because |
109 // - Center the inner elements vertically if the input height is taller than | 108 // - Center the inner elements vertically if the input height is taller than |
110 // the intrinsic height of the inner elements. | 109 // the intrinsic height of the inner elements. |
111 // - Shrink the inner elment heights if the input height is samller than the | 110 // - Shrink the inner elment heights if the input height is samller than the |
112 // intrinsic heights of the inner elements. | 111 // intrinsic heights of the inner elements. |
| 112 // The hack was removed for the inner-editor element. We should remove it |
| 113 // for containerElement() too. |
113 | 114 |
114 // We don't honor paddings and borders for textfields without decorations | 115 // We don't honor paddings and borders for type=search if the text height is |
115 // and type=search if the text height is taller than the contentHeight() | 116 // taller than the contentHeight() because of compatibility. |
116 // because of compability. | |
117 | 117 |
118 LayoutBox* innerEditorLayoutObject = innerEditorElement()->layoutBox(); | 118 LayoutBox* innerEditorLayoutObject = innerEditorElement()->layoutBox(); |
119 bool innerEditorLayoutObjectHadLayout = innerEditorLayoutObject && innerEdit
orLayoutObject->needsLayout(); | 119 bool innerEditorLayoutObjectHadLayout = innerEditorLayoutObject && innerEdit
orLayoutObject->needsLayout(); |
120 LayoutBox* viewPortLayoutObject = editingViewPortElement() ? editingViewPort
Element()->layoutBox() : 0; | |
121 | |
122 // To ensure consistency between layouts, we need to reset any conditionally
overriden height. | |
123 if (innerEditorLayoutObject) { | |
124 innerEditorLayoutObject->clearOverrideLogicalContentHeight(); | |
125 // TODO(jchaffraix): We could probably skip some of these due to | |
126 // forcing children relayout below but keeping them for safety for now. | |
127 layoutScope.setNeedsLayout(innerEditorLayoutObject, LayoutInvalidationRe
ason::TextControlChanged); | |
128 HTMLElement* placeholderElement = inputElement()->placeholderElement(); | |
129 if (LayoutBox* placeholderBox = placeholderElement ? placeholderElement-
>layoutBox() : 0) | |
130 layoutScope.setNeedsLayout(placeholderBox, LayoutInvalidationReason:
:TextControlChanged); | |
131 } | |
132 // TODO(jchaffraix): This logic is not correct and will yield to bugs such | |
133 // as crbug.com/529252. The fix is similar to what is done with | |
134 // innerEditorLayoutObject above. | |
135 if (viewPortLayoutObject && !viewPortLayoutObject->styleRef().logicalHeight(
).isAuto()) { | |
136 viewPortLayoutObject->mutableStyleRef().setLogicalHeight(Length(Auto)); | |
137 layoutScope.setNeedsLayout(viewPortLayoutObject, LayoutInvalidationReaso
n::TextControlChanged); | |
138 } | |
139 | 120 |
140 // This is the measuring phase. Thus we force children to be relayout so | 121 // This is the measuring phase. Thus we force children to be relayout so |
141 // that the checks below are executed consistently. | 122 // that the checks below are executed consistently. |
142 LayoutBlockFlow::layoutBlock(true); | 123 LayoutBlockFlow::layoutBlock(true); |
143 | 124 |
144 Element* container = containerElement(); | 125 Element* container = containerElement(); |
145 LayoutBox* containerLayoutObject = container ? container->layoutBox() : 0; | 126 LayoutBox* containerLayoutObject = container ? container->layoutBox() : 0; |
146 | 127 |
147 // Set the text block height | |
148 LayoutUnit desiredLogicalHeight = textBlockLogicalHeight(); | |
149 LayoutUnit logicalHeightLimit = computeLogicalHeightLimit(); | 128 LayoutUnit logicalHeightLimit = computeLogicalHeightLimit(); |
150 if (innerEditorLayoutObject && innerEditorLayoutObject->logicalHeight() > lo
gicalHeightLimit) { | |
151 if (desiredLogicalHeight != innerEditorLayoutObject->logicalHeight()) | |
152 layoutScope.setNeedsLayout(this, LayoutInvalidationReason::TextContr
olChanged); | |
153 | |
154 m_desiredInnerEditorLogicalHeight = desiredLogicalHeight; | |
155 | |
156 innerEditorLayoutObject->setOverrideLogicalContentHeight(desiredLogicalH
eight); | |
157 layoutScope.setNeedsLayout(innerEditorLayoutObject, LayoutInvalidationRe
ason::TextControlChanged); | |
158 if (viewPortLayoutObject) { | |
159 viewPortLayoutObject->mutableStyleRef().setLogicalHeight(Length(desi
redLogicalHeight, Fixed)); | |
160 layoutScope.setNeedsLayout(viewPortLayoutObject, LayoutInvalidationR
eason::TextControlChanged); | |
161 } | |
162 } | |
163 // The container might be taller because of decoration elements. | 129 // The container might be taller because of decoration elements. |
164 if (containerLayoutObject) { | 130 if (containerLayoutObject) { |
165 containerLayoutObject->layoutIfNeeded(); | 131 containerLayoutObject->layoutIfNeeded(); |
166 LayoutUnit containerLogicalHeight = containerLayoutObject->logicalHeight
(); | 132 LayoutUnit containerLogicalHeight = containerLayoutObject->logicalHeight
(); |
167 if (containerLogicalHeight > logicalHeightLimit) { | 133 if (containerLogicalHeight > logicalHeightLimit) { |
168 containerLayoutObject->mutableStyleRef().setLogicalHeight(Length(log
icalHeightLimit, Fixed)); | 134 containerLayoutObject->mutableStyleRef().setLogicalHeight(Length(log
icalHeightLimit, Fixed)); |
169 layoutScope.setNeedsLayout(this, LayoutInvalidationReason::TextContr
olChanged); | 135 layoutScope.setNeedsLayout(this, LayoutInvalidationReason::TextContr
olChanged); |
170 } else if (containerLayoutObject->logicalHeight() < contentLogicalHeight
()) { | 136 } else if (containerLayoutObject->logicalHeight() < contentLogicalHeight
()) { |
171 containerLayoutObject->mutableStyleRef().setLogicalHeight(Length(con
tentLogicalHeight(), Fixed)); | 137 containerLayoutObject->mutableStyleRef().setLogicalHeight(Length(con
tentLogicalHeight(), Fixed)); |
172 layoutScope.setNeedsLayout(this, LayoutInvalidationReason::TextContr
olChanged); | 138 layoutScope.setNeedsLayout(this, LayoutInvalidationReason::TextContr
olChanged); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 if (container->layoutBox()) | 202 if (container->layoutBox()) |
237 pointInParent -= toLayoutSize(container->layoutBox()->location()
); | 203 pointInParent -= toLayoutSize(container->layoutBox()->location()
); |
238 } | 204 } |
239 hitInnerEditorElement(result, pointInParent, accumulatedOffset); | 205 hitInnerEditorElement(result, pointInParent, accumulatedOffset); |
240 } | 206 } |
241 return true; | 207 return true; |
242 } | 208 } |
243 | 209 |
244 void LayoutTextControlSingleLine::styleDidChange(StyleDifference diff, const Com
putedStyle* oldStyle) | 210 void LayoutTextControlSingleLine::styleDidChange(StyleDifference diff, const Com
putedStyle* oldStyle) |
245 { | 211 { |
246 m_desiredInnerEditorLogicalHeight = -1; | |
247 LayoutTextControl::styleDidChange(diff, oldStyle); | 212 LayoutTextControl::styleDidChange(diff, oldStyle); |
248 | 213 |
249 // We may have set the width and the height in the old style in layout(). | 214 // We may have set the width and the height in the old style in layout(). |
250 // Reset them now to avoid getting a spurious layout hint. | 215 // Reset them now to avoid getting a spurious layout hint. |
251 Element* viewPort = editingViewPortElement(); | |
252 if (LayoutObject* viewPortLayoutObject = viewPort ? viewPort->layoutObject()
: 0) { | |
253 viewPortLayoutObject->mutableStyleRef().setHeight(Length()); | |
254 viewPortLayoutObject->mutableStyleRef().setWidth(Length()); | |
255 } | |
256 Element* container = containerElement(); | 216 Element* container = containerElement(); |
257 if (LayoutObject* containerLayoutObject = container ? container->layoutObjec
t() : 0) { | 217 if (LayoutObject* containerLayoutObject = container ? container->layoutObjec
t() : 0) { |
258 containerLayoutObject->mutableStyleRef().setHeight(Length()); | 218 containerLayoutObject->mutableStyleRef().setHeight(Length()); |
259 containerLayoutObject->mutableStyleRef().setWidth(Length()); | 219 containerLayoutObject->mutableStyleRef().setWidth(Length()); |
260 } | 220 } |
261 if (HTMLElement* placeholder = inputElement()->placeholderElement()) | 221 if (HTMLElement* placeholder = inputElement()->placeholderElement()) |
262 placeholder->setInlineStyleProperty(CSSPropertyTextOverflow, textShouldB
eTruncated() ? CSSValueEllipsis : CSSValueClip); | 222 placeholder->setInlineStyleProperty(CSSPropertyTextOverflow, textShouldB
eTruncated() ? CSSValueEllipsis : CSSValueClip); |
263 setHasOverflowClip(false); | 223 setHasOverflowClip(false); |
264 } | 224 } |
265 | 225 |
(...skipping 13 matching lines...) Expand all Loading... |
279 shouldDrawCapsLockIndicator = inputElement()->type() == InputTypeNames::
password && frame->selection().isFocusedAndActive() && document().focusedElement
() == node() && PlatformKeyboardEvent::currentCapsLockState(); | 239 shouldDrawCapsLockIndicator = inputElement()->type() == InputTypeNames::
password && frame->selection().isFocusedAndActive() && document().focusedElement
() == node() && PlatformKeyboardEvent::currentCapsLockState(); |
280 | 240 |
281 if (shouldDrawCapsLockIndicator != m_shouldDrawCapsLockIndicator) { | 241 if (shouldDrawCapsLockIndicator != m_shouldDrawCapsLockIndicator) { |
282 m_shouldDrawCapsLockIndicator = shouldDrawCapsLockIndicator; | 242 m_shouldDrawCapsLockIndicator = shouldDrawCapsLockIndicator; |
283 setShouldDoFullPaintInvalidation(); | 243 setShouldDoFullPaintInvalidation(); |
284 } | 244 } |
285 } | 245 } |
286 | 246 |
287 bool LayoutTextControlSingleLine::hasControlClip() const | 247 bool LayoutTextControlSingleLine::hasControlClip() const |
288 { | 248 { |
289 // Apply control clip for text fields with decorations. | 249 return true; |
290 return !!containerElement(); | |
291 } | 250 } |
292 | 251 |
293 LayoutRect LayoutTextControlSingleLine::controlClipRect(const LayoutPoint& addit
ionalOffset) const | 252 LayoutRect LayoutTextControlSingleLine::controlClipRect(const LayoutPoint& addit
ionalOffset) const |
294 { | 253 { |
295 ASSERT(hasControlClip()); | |
296 LayoutRect clipRect = contentBoxRect(); | 254 LayoutRect clipRect = contentBoxRect(); |
297 if (containerElement()->layoutBox()) | 255 if (containerElement() && containerElement()->layoutBox()) |
298 clipRect = unionRect(clipRect, containerElement()->layoutBox()->frameRec
t()); | 256 clipRect = unionRect(clipRect, containerElement()->layoutBox()->frameRec
t()); |
299 clipRect.moveBy(additionalOffset); | 257 clipRect.moveBy(additionalOffset); |
300 return clipRect; | 258 return clipRect; |
301 } | 259 } |
302 | 260 |
303 float LayoutTextControlSingleLine::getAvgCharWidth(const AtomicString& family) c
onst | 261 float LayoutTextControlSingleLine::getAvgCharWidth(const AtomicString& family) c
onst |
304 { | 262 { |
305 // Match the default system font to the width of MS Shell Dlg, the default | 263 // Match the default system font to the width of MS Shell Dlg, the default |
306 // font for textareas in Firefox, Safari Win and IE for some encodings (in | 264 // font for textareas in Firefox, Safari Win and IE for some encodings (in |
307 // IE, the default font is encoding specific). 901 is the avgCharWidth value | 265 // IE, the default font is encoding specific). 901 is the avgCharWidth value |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 PassRefPtr<ComputedStyle> LayoutTextControlSingleLine::createInnerEditorStyle(co
nst ComputedStyle& startStyle) const | 315 PassRefPtr<ComputedStyle> LayoutTextControlSingleLine::createInnerEditorStyle(co
nst ComputedStyle& startStyle) const |
358 { | 316 { |
359 RefPtr<ComputedStyle> textBlockStyle = ComputedStyle::create(); | 317 RefPtr<ComputedStyle> textBlockStyle = ComputedStyle::create(); |
360 textBlockStyle->inheritFrom(startStyle); | 318 textBlockStyle->inheritFrom(startStyle); |
361 adjustInnerEditorStyle(*textBlockStyle); | 319 adjustInnerEditorStyle(*textBlockStyle); |
362 | 320 |
363 textBlockStyle->setWhiteSpace(PRE); | 321 textBlockStyle->setWhiteSpace(PRE); |
364 textBlockStyle->setOverflowWrap(NormalOverflowWrap); | 322 textBlockStyle->setOverflowWrap(NormalOverflowWrap); |
365 textBlockStyle->setTextOverflow(textShouldBeTruncated() ? TextOverflowEllips
is : TextOverflowClip); | 323 textBlockStyle->setTextOverflow(textShouldBeTruncated() ? TextOverflowEllips
is : TextOverflowClip); |
366 | 324 |
367 if (m_desiredInnerEditorLogicalHeight >= 0) | |
368 textBlockStyle->setLogicalHeight(Length(m_desiredInnerEditorLogicalHeigh
t, Fixed)); | |
369 // Do not allow line-height to be smaller than our default. | 325 // Do not allow line-height to be smaller than our default. |
370 if (textBlockStyle->fontSize() >= lineHeight(true, HorizontalLine, PositionO
fInteriorLineBoxes)) | 326 if (textBlockStyle->fontSize() >= lineHeight(true, HorizontalLine, PositionO
fInteriorLineBoxes) || !startStyle.logicalHeight().isIntrinsicOrAuto()) |
371 textBlockStyle->setLineHeight(ComputedStyle::initialLineHeight()); | 327 textBlockStyle->setLineHeight(ComputedStyle::initialLineHeight()); |
372 | 328 |
373 textBlockStyle->setDisplay(BLOCK); | 329 textBlockStyle->setDisplay(BLOCK); |
374 textBlockStyle->setUnique(); | 330 textBlockStyle->setUnique(); |
375 | 331 |
376 if (inputElement()->shouldRevealPassword()) | 332 if (inputElement()->shouldRevealPassword()) |
377 textBlockStyle->setTextSecurity(TSNONE); | 333 textBlockStyle->setTextSecurity(TSNONE); |
378 | 334 |
379 textBlockStyle->setOverflowX(OSCROLL); | 335 textBlockStyle->setOverflowX(OSCROLL); |
380 textBlockStyle->setOverflowY(OSCROLL); | 336 textBlockStyle->setOverflowY(OSCROLL); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 if (innerEditorElement()) | 404 if (innerEditorElement()) |
449 innerEditorElement()->setScrollTop(newTop); | 405 innerEditorElement()->setScrollTop(newTop); |
450 } | 406 } |
451 | 407 |
452 HTMLInputElement* LayoutTextControlSingleLine::inputElement() const | 408 HTMLInputElement* LayoutTextControlSingleLine::inputElement() const |
453 { | 409 { |
454 return toHTMLInputElement(node()); | 410 return toHTMLInputElement(node()); |
455 } | 411 } |
456 | 412 |
457 } | 413 } |
OLD | NEW |