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

Side by Side Diff: Source/core/rendering/RenderTextControl.cpp

Issue 340273003: Rename innerTextElement/Value used in <input> and <textarea> to innerEditor. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007 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 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 29 matching lines...) Expand all
40 40
41 RenderTextControl::~RenderTextControl() 41 RenderTextControl::~RenderTextControl()
42 { 42 {
43 } 43 }
44 44
45 HTMLTextFormControlElement* RenderTextControl::textFormControlElement() const 45 HTMLTextFormControlElement* RenderTextControl::textFormControlElement() const
46 { 46 {
47 return toHTMLTextFormControlElement(node()); 47 return toHTMLTextFormControlElement(node());
48 } 48 }
49 49
50 HTMLElement* RenderTextControl::innerTextElement() const 50 HTMLElement* RenderTextControl::innerEditorElement() const
51 { 51 {
52 return textFormControlElement()->innerTextElement(); 52 return textFormControlElement()->innerEditorElement();
53 } 53 }
54 54
55 void RenderTextControl::addChild(RenderObject* newChild, RenderObject* beforeChi ld) 55 void RenderTextControl::addChild(RenderObject* newChild, RenderObject* beforeChi ld)
56 { 56 {
57 // FIXME: This is a terrible hack to get the caret over the placeholder text since it'll 57 // FIXME: This is a terrible hack to get the caret over the placeholder text since it'll
58 // make us paint the placeholder first. (See https://trac.webkit.org/changes et/118733) 58 // make us paint the placeholder first. (See https://trac.webkit.org/changes et/118733)
59 Node* node = newChild->node(); 59 Node* node = newChild->node();
60 if (node && node->isElementNode() && toElement(node)->shadowPseudoId() == "- webkit-input-placeholder") 60 if (node && node->isElementNode() && toElement(node)->shadowPseudoId() == "- webkit-input-placeholder")
61 RenderBlockFlow::addChild(newChild, firstChild()); 61 RenderBlockFlow::addChild(newChild, firstChild());
62 else 62 else
63 RenderBlockFlow::addChild(newChild, beforeChild); 63 RenderBlockFlow::addChild(newChild, beforeChild);
64 } 64 }
65 65
66 void RenderTextControl::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) 66 void RenderTextControl::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
67 { 67 {
68 RenderBlockFlow::styleDidChange(diff, oldStyle); 68 RenderBlockFlow::styleDidChange(diff, oldStyle);
69 Element* innerText = innerTextElement(); 69 Element* innerEditor = innerEditorElement();
70 if (!innerText) 70 if (!innerEditor)
71 return; 71 return;
72 RenderBlock* innerTextRenderer = toRenderBlock(innerText->renderer()); 72 RenderBlock* innerEditorRenderer = toRenderBlock(innerEditor->renderer());
73 if (innerTextRenderer) { 73 if (innerEditorRenderer) {
74 // We may have set the width and the height in the old style in layout() . 74 // We may have set the width and the height in the old style in layout() .
75 // Reset them now to avoid getting a spurious layout hint. 75 // Reset them now to avoid getting a spurious layout hint.
76 innerTextRenderer->style()->setHeight(Length()); 76 innerEditorRenderer->style()->setHeight(Length());
77 innerTextRenderer->style()->setWidth(Length()); 77 innerEditorRenderer->style()->setWidth(Length());
78 innerTextRenderer->setStyle(createInnerTextStyle(style())); 78 innerEditorRenderer->setStyle(createInnerEditorStyle(style()));
79 innerText->setNeedsStyleRecalc(SubtreeStyleChange); 79 innerEditor->setNeedsStyleRecalc(SubtreeStyleChange);
80 } 80 }
81 textFormControlElement()->updatePlaceholderVisibility(false); 81 textFormControlElement()->updatePlaceholderVisibility(false);
82 } 82 }
83 83
84 static inline void updateUserModifyProperty(HTMLTextFormControlElement* node, Re nderStyle* style) 84 static inline void updateUserModifyProperty(HTMLTextFormControlElement* node, Re nderStyle* style)
85 { 85 {
86 style->setUserModify(node->isDisabledOrReadOnly() ? READ_ONLY : READ_WRITE_P LAINTEXT_ONLY); 86 style->setUserModify(node->isDisabledOrReadOnly() ? READ_ONLY : READ_WRITE_P LAINTEXT_ONLY);
87 } 87 }
88 88
89 void RenderTextControl::adjustInnerTextStyle(RenderStyle* textBlockStyle) const 89 void RenderTextControl::adjustInnerEditorStyle(RenderStyle* textBlockStyle) cons t
90 { 90 {
91 // The inner block, if present, always has its direction set to LTR, 91 // The inner block, if present, always has its direction set to LTR,
92 // so we need to inherit the direction and unicode-bidi style from the eleme nt. 92 // so we need to inherit the direction and unicode-bidi style from the eleme nt.
93 textBlockStyle->setDirection(style()->direction()); 93 textBlockStyle->setDirection(style()->direction());
94 textBlockStyle->setUnicodeBidi(style()->unicodeBidi()); 94 textBlockStyle->setUnicodeBidi(style()->unicodeBidi());
95 95
96 updateUserModifyProperty(textFormControlElement(), textBlockStyle); 96 updateUserModifyProperty(textFormControlElement(), textBlockStyle);
97 } 97 }
98 98
99 int RenderTextControl::textBlockLogicalHeight() const 99 int RenderTextControl::textBlockLogicalHeight() const
100 { 100 {
101 return logicalHeight() - borderAndPaddingLogicalHeight(); 101 return logicalHeight() - borderAndPaddingLogicalHeight();
102 } 102 }
103 103
104 int RenderTextControl::textBlockLogicalWidth() const 104 int RenderTextControl::textBlockLogicalWidth() const
105 { 105 {
106 Element* innerText = innerTextElement(); 106 Element* innerEditor = innerEditorElement();
107 ASSERT(innerText); 107 ASSERT(innerEditor);
108 108
109 LayoutUnit unitWidth = logicalWidth() - borderAndPaddingLogicalWidth(); 109 LayoutUnit unitWidth = logicalWidth() - borderAndPaddingLogicalWidth();
110 if (innerText->renderer()) 110 if (innerEditor->renderer())
111 unitWidth -= innerText->renderBox()->paddingStart() + innerText->renderB ox()->paddingEnd(); 111 unitWidth -= innerEditor->renderBox()->paddingStart() + innerEditor->ren derBox()->paddingEnd();
112 112
113 return unitWidth; 113 return unitWidth;
114 } 114 }
115 115
116 void RenderTextControl::updateFromElement() 116 void RenderTextControl::updateFromElement()
117 { 117 {
118 Element* innerText = innerTextElement(); 118 Element* innerEditor = innerEditorElement();
119 if (innerText && innerText->renderer()) 119 if (innerEditor && innerEditor->renderer())
120 updateUserModifyProperty(textFormControlElement(), innerText->renderer() ->style()); 120 updateUserModifyProperty(textFormControlElement(), innerEditor->renderer ()->style());
121 } 121 }
122 122
123 int RenderTextControl::scrollbarThickness() const 123 int RenderTextControl::scrollbarThickness() const
124 { 124 {
125 // FIXME: We should get the size of the scrollbar from the RenderTheme inste ad. 125 // FIXME: We should get the size of the scrollbar from the RenderTheme inste ad.
126 return ScrollbarTheme::theme()->scrollbarThickness(); 126 return ScrollbarTheme::theme()->scrollbarThickness();
127 } 127 }
128 128
129 void RenderTextControl::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUni t logicalTop, LogicalExtentComputedValues& computedValues) const 129 void RenderTextControl::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUni t logicalTop, LogicalExtentComputedValues& computedValues) const
130 { 130 {
131 HTMLElement* innerText = innerTextElement(); 131 HTMLElement* innerEditor = innerEditorElement();
132 ASSERT(innerText); 132 ASSERT(innerEditor);
133 if (RenderBox* innerTextBox = innerText->renderBox()) { 133 if (RenderBox* innerEditorBox = innerEditor->renderBox()) {
134 LayoutUnit nonContentHeight = innerTextBox->borderAndPaddingHeight() + i nnerTextBox->marginHeight(); 134 LayoutUnit nonContentHeight = innerEditorBox->borderAndPaddingHeight() + innerEditorBox->marginHeight();
135 logicalHeight = computeControlLogicalHeight(innerTextBox->lineHeight(tru e, HorizontalLine, PositionOfInteriorLineBoxes), nonContentHeight); 135 logicalHeight = computeControlLogicalHeight(innerEditorBox->lineHeight(t rue, HorizontalLine, PositionOfInteriorLineBoxes), nonContentHeight);
136 136
137 // We are able to have a horizontal scrollbar if the overflow style is s croll, or if its auto and there's no word wrap. 137 // We are able to have a horizontal scrollbar if the overflow style is s croll, or if its auto and there's no word wrap.
138 if ((isHorizontalWritingMode() && (style()->overflowX() == OSCROLL || ( style()->overflowX() == OAUTO && innerText->renderer()->style()->overflowWrap() == NormalOverflowWrap))) 138 if ((isHorizontalWritingMode() && (style()->overflowX() == OSCROLL || ( style()->overflowX() == OAUTO && innerEditor->renderer()->style()->overflowWrap( ) == NormalOverflowWrap)))
139 || (!isHorizontalWritingMode() && (style()->overflowY() == OSCROLL | | (style()->overflowY() == OAUTO && innerText->renderer()->style()->overflowWra p() == NormalOverflowWrap)))) 139 || (!isHorizontalWritingMode() && (style()->overflowY() == OSCROLL | | (style()->overflowY() == OAUTO && innerEditor->renderer()->style()->overflowW rap() == NormalOverflowWrap))))
140 logicalHeight += scrollbarThickness(); 140 logicalHeight += scrollbarThickness();
141 141
142 // FIXME: The logical height of the inner text box should have been adde d before calling computeLogicalHeight to 142 // FIXME: The logical height of the inner text box should have been adde d before calling computeLogicalHeight to
143 // avoid this hack. 143 // avoid this hack.
144 updateIntrinsicContentLogicalHeight(logicalHeight); 144 updateIntrinsicContentLogicalHeight(logicalHeight);
145 145
146 logicalHeight += borderAndPaddingHeight(); 146 logicalHeight += borderAndPaddingHeight();
147 } 147 }
148 148
149 RenderBox::computeLogicalHeight(logicalHeight, logicalTop, computedValues); 149 RenderBox::computeLogicalHeight(logicalHeight, logicalTop, computedValues);
150 } 150 }
151 151
152 void RenderTextControl::hitInnerTextElement(HitTestResult& result, const LayoutP oint& pointInContainer, const LayoutPoint& accumulatedOffset) 152 void RenderTextControl::hitInnerEditorElement(HitTestResult& result, const Layou tPoint& pointInContainer, const LayoutPoint& accumulatedOffset)
153 { 153 {
154 HTMLElement* innerText = innerTextElement(); 154 HTMLElement* innerEditor = innerEditorElement();
155 if (!innerText->renderer()) 155 if (!innerEditor->renderer())
156 return; 156 return;
157 157
158 LayoutPoint adjustedLocation = accumulatedOffset + location(); 158 LayoutPoint adjustedLocation = accumulatedOffset + location();
159 LayoutPoint localPoint = pointInContainer - toLayoutSize(adjustedLocation + innerText->renderBox()->location()); 159 LayoutPoint localPoint = pointInContainer - toLayoutSize(adjustedLocation + innerEditor->renderBox()->location());
160 if (hasOverflowClip()) 160 if (hasOverflowClip())
161 localPoint += scrolledContentOffset(); 161 localPoint += scrolledContentOffset();
162 result.setInnerNode(innerText); 162 result.setInnerNode(innerEditor);
163 result.setInnerNonSharedNode(innerText); 163 result.setInnerNonSharedNode(innerEditor);
164 result.setLocalPoint(localPoint); 164 result.setLocalPoint(localPoint);
165 } 165 }
166 166
167 static const char* const fontFamiliesWithInvalidCharWidth[] = { 167 static const char* const fontFamiliesWithInvalidCharWidth[] = {
168 "American Typewriter", 168 "American Typewriter",
169 "Arial Hebrew", 169 "Arial Hebrew",
170 "Chalkboard", 170 "Chalkboard",
171 "Cochin", 171 "Cochin",
172 "Corsiva Hebrew", 172 "Corsiva Hebrew",
173 "Courier", 173 "Courier",
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // This matches the unitsPerEm value for MS Shell Dlg and Courier New from t he "head" font table. 241 // This matches the unitsPerEm value for MS Shell Dlg and Courier New from t he "head" font table.
242 float unitsPerEm = 2048.0f; 242 float unitsPerEm = 2048.0f;
243 return roundf(style()->font().fontDescription().computedSize() * x / unitsPe rEm); 243 return roundf(style()->font().fontDescription().computedSize() * x / unitsPe rEm);
244 } 244 }
245 245
246 void RenderTextControl::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidt h, LayoutUnit& maxLogicalWidth) const 246 void RenderTextControl::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidt h, LayoutUnit& maxLogicalWidth) const
247 { 247 {
248 // Use average character width. Matches IE. 248 // Use average character width. Matches IE.
249 AtomicString family = style()->font().fontDescription().family().family(); 249 AtomicString family = style()->font().fontDescription().family().family();
250 maxLogicalWidth = preferredContentLogicalWidth(const_cast<RenderTextControl* >(this)->getAvgCharWidth(family)); 250 maxLogicalWidth = preferredContentLogicalWidth(const_cast<RenderTextControl* >(this)->getAvgCharWidth(family));
251 if (RenderBox* innerTextRenderBox = innerTextElement()->renderBox()) 251 if (RenderBox* innerEditorRenderBox = innerEditorElement()->renderBox())
252 maxLogicalWidth += innerTextRenderBox->paddingStart() + innerTextRenderB ox->paddingEnd(); 252 maxLogicalWidth += innerEditorRenderBox->paddingStart() + innerEditorRen derBox->paddingEnd();
253 if (!style()->logicalWidth().isPercent()) 253 if (!style()->logicalWidth().isPercent())
254 minLogicalWidth = maxLogicalWidth; 254 minLogicalWidth = maxLogicalWidth;
255 } 255 }
256 256
257 void RenderTextControl::computePreferredLogicalWidths() 257 void RenderTextControl::computePreferredLogicalWidths()
258 { 258 {
259 ASSERT(preferredLogicalWidthsDirty()); 259 ASSERT(preferredLogicalWidthsDirty());
260 260
261 m_minPreferredLogicalWidth = 0; 261 m_minPreferredLogicalWidth = 0;
262 m_maxPreferredLogicalWidth = 0; 262 m_maxPreferredLogicalWidth = 0;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 HTMLElement* placeholder = toHTMLTextFormControlElement(node())->placeholder Element(); 296 HTMLElement* placeholder = toHTMLTextFormControlElement(node())->placeholder Element();
297 RenderObject* placeholderRenderer = placeholder ? placeholder->renderer() : 0; 297 RenderObject* placeholderRenderer = placeholder ? placeholder->renderer() : 0;
298 if (!placeholderRenderer) 298 if (!placeholderRenderer)
299 return 0; 299 return 0;
300 if (relayoutChildren) 300 if (relayoutChildren)
301 layoutScope.setChildNeedsLayout(placeholderRenderer); 301 layoutScope.setChildNeedsLayout(placeholderRenderer);
302 return placeholderRenderer; 302 return placeholderRenderer;
303 } 303 }
304 304
305 } // namespace WebCore 305 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderTextControl.h ('k') | Source/core/rendering/RenderTextControlMultiLine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698