|
1 /** |
|
2 * Copyright (C) 2006, 2007, 2010 Apple Inc. All rights reserved. |
|
3 * (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) |
|
4 * Copyright (C) 2010 Google Inc. All rights reserved. |
|
5 * |
|
6 * This library is free software; you can redistribute it and/or |
|
7 * modify it under the terms of the GNU Library General Public |
|
8 * License as published by the Free Software Foundation; either |
|
9 * version 2 of the License, or (at your option) any later version. |
|
10 * |
|
11 * This library is distributed in the hope that it will be useful, |
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 * Library General Public License for more details. |
|
15 * |
|
16 * You should have received a copy of the GNU Library General Public License |
|
17 * along with this library; see the file COPYING.LIB. If not, write to |
|
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
19 * Boston, MA 02110-1301, USA. |
|
20 * |
|
21 */ |
|
22 |
|
23 #include "config.h" |
|
24 #include "RenderTextControlSingleLine.h" |
|
25 |
|
26 #include "CSSStyleSelector.h" |
|
27 #include "Event.h" |
|
28 #include "EventNames.h" |
|
29 #include "Frame.h" |
|
30 #include "FrameView.h" |
|
31 #include "HTMLInputElement.h" |
|
32 #include "HTMLNames.h" |
|
33 #include "HitTestResult.h" |
|
34 #include "InputElement.h" |
|
35 #include "LocalizedStrings.h" |
|
36 #include "MouseEvent.h" |
|
37 #include "PlatformKeyboardEvent.h" |
|
38 #include "RenderLayer.h" |
|
39 #include "RenderScrollbar.h" |
|
40 #include "RenderTheme.h" |
|
41 #include "SearchPopupMenu.h" |
|
42 #include "SelectionController.h" |
|
43 #include "Settings.h" |
|
44 #include "SimpleFontData.h" |
|
45 #include "TextControlInnerElements.h" |
|
46 |
|
47 using namespace std; |
|
48 |
|
49 namespace WebCore { |
|
50 |
|
51 using namespace HTMLNames; |
|
52 |
|
53 RenderTextControlSingleLine::RenderTextControlSingleLine(Node* node, bool placeholderVisible) |
|
54 : RenderTextControl(node, placeholderVisible) |
|
55 , m_searchPopupIsVisible(false) |
|
56 , m_shouldDrawCapsLockIndicator(false) |
|
57 , m_searchEventTimer(this, &RenderTextControlSingleLine::searchEventTimerFired) |
|
58 , m_searchPopup(0) |
|
59 { |
|
60 } |
|
61 |
|
62 RenderTextControlSingleLine::~RenderTextControlSingleLine() |
|
63 { |
|
64 if (m_searchPopup) { |
|
65 m_searchPopup->disconnectClient(); |
|
66 m_searchPopup = 0; |
|
67 } |
|
68 |
|
69 if (m_innerBlock) |
|
70 m_innerBlock->detach(); |
|
71 |
|
72 if (m_innerSpinButton) |
|
73 m_innerSpinButton->detach(); |
|
74 if (m_outerSpinButton) |
|
75 m_outerSpinButton->detach(); |
|
76 } |
|
77 |
|
78 RenderStyle* RenderTextControlSingleLine::textBaseStyle() const |
|
79 { |
|
80 return m_innerBlock ? m_innerBlock->renderer()->style() : style(); |
|
81 } |
|
82 |
|
83 void RenderTextControlSingleLine::addSearchResult() |
|
84 { |
|
85 ASSERT(node()->isHTMLElement()); |
|
86 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); |
|
87 if (input->maxResults() <= 0) |
|
88 return; |
|
89 |
|
90 String value = input->value(); |
|
91 if (value.isEmpty()) |
|
92 return; |
|
93 |
|
94 Settings* settings = document()->settings(); |
|
95 if (!settings || settings->privateBrowsingEnabled()) |
|
96 return; |
|
97 |
|
98 int size = static_cast<int>(m_recentSearches.size()); |
|
99 for (int i = size - 1; i >= 0; --i) { |
|
100 if (m_recentSearches[i] == value) |
|
101 m_recentSearches.remove(i); |
|
102 } |
|
103 |
|
104 m_recentSearches.insert(0, value); |
|
105 while (static_cast<int>(m_recentSearches.size()) > input->maxResults()) |
|
106 m_recentSearches.removeLast(); |
|
107 |
|
108 const AtomicString& name = autosaveName(); |
|
109 if (!m_searchPopup) |
|
110 m_searchPopup = SearchPopupMenu::create(this); |
|
111 |
|
112 m_searchPopup->saveRecentSearches(name, m_recentSearches); |
|
113 } |
|
114 |
|
115 void RenderTextControlSingleLine::stopSearchEventTimer() |
|
116 { |
|
117 ASSERT(node()->isHTMLElement()); |
|
118 m_searchEventTimer.stop(); |
|
119 } |
|
120 |
|
121 void RenderTextControlSingleLine::showPopup() |
|
122 { |
|
123 ASSERT(node()->isHTMLElement()); |
|
124 if (m_searchPopupIsVisible) |
|
125 return; |
|
126 |
|
127 if (!m_searchPopup) |
|
128 m_searchPopup = SearchPopupMenu::create(this); |
|
129 |
|
130 if (!m_searchPopup->enabled()) |
|
131 return; |
|
132 |
|
133 m_searchPopupIsVisible = true; |
|
134 |
|
135 const AtomicString& name = autosaveName(); |
|
136 m_searchPopup->loadRecentSearches(name, m_recentSearches); |
|
137 |
|
138 // Trim the recent searches list if the maximum size has changed since we last saved. |
|
139 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); |
|
140 if (static_cast<int>(m_recentSearches.size()) > input->maxResults()) { |
|
141 do { |
|
142 m_recentSearches.removeLast(); |
|
143 } while (static_cast<int>(m_recentSearches.size()) > input->maxResults()); |
|
144 |
|
145 m_searchPopup->saveRecentSearches(name, m_recentSearches); |
|
146 } |
|
147 |
|
148 m_searchPopup->show(absoluteBoundingBoxRect(true), document()->view(), -1); |
|
149 } |
|
150 |
|
151 void RenderTextControlSingleLine::hidePopup() |
|
152 { |
|
153 ASSERT(node()->isHTMLElement()); |
|
154 if (m_searchPopup) |
|
155 m_searchPopup->hide(); |
|
156 } |
|
157 |
|
158 void RenderTextControlSingleLine::subtreeHasChanged() |
|
159 { |
|
160 bool wasChanged = wasChangedSinceLastChangeEvent(); |
|
161 RenderTextControl::subtreeHasChanged(); |
|
162 |
|
163 InputElement* input = inputElement(); |
|
164 // We don't need to call sanitizeUserInputValue() function here because |
|
165 // InputElement::handleBeforeTextInsertedEvent() has already called |
|
166 // sanitizeUserInputValue(). |
|
167 // sanitizeValue() is needed because IME input doesn't dispatch BeforeTextInsertedEvent. |
|
168 input->setValueFromRenderer(input->sanitizeValue(text())); |
|
169 |
|
170 if (m_cancelButton) |
|
171 updateCancelButtonVisibility(); |
|
172 |
|
173 // If the incremental attribute is set, then dispatch the search event |
|
174 if (input->searchEventsShouldBeDispatched()) |
|
175 startSearchEventTimer(); |
|
176 |
|
177 if (!wasChanged && node()->focused()) { |
|
178 if (Frame* frame = this->frame()) |
|
179 frame->textFieldDidBeginEditing(static_cast<Element*>(node())); |
|
180 } |
|
181 |
|
182 if (node()->focused()) { |
|
183 if (Frame* frame = document()->frame()) |
|
184 frame->textDidChangeInTextField(static_cast<Element*>(node())); |
|
185 } |
|
186 } |
|
187 |
|
188 void RenderTextControlSingleLine::paint(PaintInfo& paintInfo, int tx, int ty) |
|
189 { |
|
190 RenderTextControl::paint(paintInfo, tx, ty); |
|
191 |
|
192 if (paintInfo.phase == PaintPhaseBlockBackground && m_shouldDrawCapsLockIndicator) { |
|
193 IntRect contentsRect = contentBoxRect(); |
|
194 |
|
195 // Center vertically like the text. |
|
196 contentsRect.setY((height() - contentsRect.height()) / 2); |
|
197 |
|
198 // Convert the rect into the coords used for painting the content |
|
199 contentsRect.move(tx + x(), ty + y()); |
|
200 theme()->paintCapsLockIndicator(this, paintInfo, contentsRect); |
|
201 } |
|
202 } |
|
203 |
|
204 void RenderTextControlSingleLine::paintBoxDecorations(PaintInfo& paintInfo, int tx, int ty) |
|
205 { |
|
206 paintBoxDecorationsWithSize(paintInfo, tx, ty, width() - decorationWidthRight(), height()); |
|
207 } |
|
208 |
|
209 void RenderTextControlSingleLine::addFocusRingRects(Vector<IntRect>& rects, int tx, int ty) |
|
210 { |
|
211 int w = width() - decorationWidthRight(); |
|
212 if (w && height()) |
|
213 rects.append(IntRect(tx, ty, w, height())); |
|
214 } |
|
215 |
|
216 void RenderTextControlSingleLine::layout() |
|
217 { |
|
218 int oldHeight = height(); |
|
219 calcHeight(); |
|
220 |
|
221 int oldWidth = width(); |
|
222 calcWidth(); |
|
223 |
|
224 bool relayoutChildren = oldHeight != height() || oldWidth != width(); |
|
225 |
|
226 RenderBox* innerTextRenderer = innerTextElement()->renderBox(); |
|
227 RenderBox* innerBlockRenderer = m_innerBlock ? m_innerBlock->renderBox() : 0; |
|
228 |
|
229 // Set the text block height |
|
230 int desiredHeight = textBlockHeight(); |
|
231 int currentHeight = innerTextRenderer->height(); |
|
232 |
|
233 if (currentHeight > height()) { |
|
234 if (desiredHeight != currentHeight) |
|
235 relayoutChildren = true; |
|
236 innerTextRenderer->style()->setHeight(Length(desiredHeight, Fixed)); |
|
237 if (m_innerBlock) |
|
238 innerBlockRenderer->style()->setHeight(Length(desiredHeight, Fixed)); |
|
239 } |
|
240 |
|
241 // Set the text block width |
|
242 int desiredWidth = textBlockWidth(); |
|
243 if (desiredWidth != innerTextRenderer->width()) |
|
244 relayoutChildren = true; |
|
245 innerTextRenderer->style()->setWidth(Length(desiredWidth, Fixed)); |
|
246 |
|
247 if (m_innerBlock) { |
|
248 int innerBlockWidth = width() - borderAndPaddingWidth(); |
|
249 if (innerBlockWidth != innerBlockRenderer->width()) |
|
250 relayoutChildren = true; |
|
251 innerBlockRenderer->style()->setWidth(Length(innerBlockWidth, Fixed)); |
|
252 } |
|
253 |
|
254 RenderBlock::layoutBlock(relayoutChildren); |
|
255 |
|
256 // Center the child block vertically |
|
257 RenderBox* childBlock = innerBlockRenderer ? innerBlockRenderer : innerTextRenderer; |
|
258 currentHeight = childBlock->height(); |
|
259 if (currentHeight < height()) |
|
260 childBlock->setY((height() - currentHeight) / 2); |
|
261 |
|
262 // Ignores the paddings for the inner spin button. |
|
263 if (RenderBox* spinBox = m_innerSpinButton ? m_innerSpinButton->renderBox() : 0) { |
|
264 spinBox->setLocation(spinBox->x() + paddingRight(), borderTop()); |
|
265 spinBox->setHeight(height() - borderTop() - borderBottom()); |
|
266 } |
|
267 |
|
268 // Center the spin button vertically, and move it to the right by |
|
269 // padding + border of the text fields. |
|
270 if (RenderBox* spinBox = m_outerSpinButton ? m_outerSpinButton->renderBox() : 0) { |
|
271 int diff = height() - spinBox->height(); |
|
272 // If the diff is odd, the top area over the spin button takes the |
|
273 // remaining one pixel. It's good for Mac NSStepper because it has |
|
274 // shadow at the bottom. |
|
275 int y = (diff / 2) + (diff % 2); |
|
276 int x = width() - borderRight() - paddingRight() - spinBox->width(); |
|
277 spinBox->setLocation(x, y); |
|
278 } |
|
279 } |
|
280 |
|
281 bool RenderTextControlSingleLine::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, int xPos, int yPos, int tx, int ty, HitTestAction hitTestAction) |
|
282 { |
|
283 // If we're within the text control, we want to act as if we've hit the inner text block element, in case the point |
|
284 // was on the control but not on the inner element (see Radar 4617841). |
|
285 |
|
286 // In a search field, we want to act as if we've hit the results block if we're to the left of the inner text block, |
|
287 // and act as if we've hit the close block if we're to the right of the inner text block. |
|
288 |
|
289 if (!RenderTextControl::nodeAtPoint(request, result, xPos, yPos, tx, ty, hitTestAction)) |
|
290 return false; |
|
291 |
|
292 // If we hit a node inside the inner text element, say that we hit that element, |
|
293 // and if we hit our node (e.g. we're over the border or padding), also say that we hit the |
|
294 // inner text element so that it gains focus. |
|
295 if (result.innerNode()->isDescendantOf(innerTextElement()) || result.innerNode() == node()) |
|
296 hitInnerTextElement(result, xPos, yPos, tx, ty); |
|
297 |
|
298 // If we found a spin button, we're done. |
|
299 if (m_innerSpinButton && result.innerNode() == m_innerSpinButton) |
|
300 return true; |
|
301 if (m_outerSpinButton && result.innerNode() == m_outerSpinButton) |
|
302 return true; |
|
303 // If we're not a search field, or we already found the speech, results or cancel buttons, we're done. |
|
304 if (!m_innerBlock || result.innerNode() == m_resultsButton || result.innerNode() == m_cancelButton) |
|
305 return true; |
|
306 #if ENABLE(INPUT_SPEECH) |
|
307 if (m_innerBlock && m_speechButton && result.innerNode() == m_speechButton) |
|
308 return true; |
|
309 #endif |
|
310 |
|
311 Node* innerNode = 0; |
|
312 RenderBox* innerBlockRenderer = m_innerBlock->renderBox(); |
|
313 RenderBox* innerTextRenderer = innerTextElement()->renderBox(); |
|
314 |
|
315 IntPoint localPoint = result.localPoint(); |
|
316 localPoint.move(-innerBlockRenderer->x(), -innerBlockRenderer->y()); |
|
317 |
|
318 int textLeft = tx + x() + innerBlockRenderer->x() + innerTextRenderer->x(); |
|
319 if (m_resultsButton && m_resultsButton->renderer() && xPos < textLeft) |
|
320 innerNode = m_resultsButton.get(); |
|
321 |
|
322 #if ENABLE(INPUT_SPEECH) |
|
323 if (!innerNode && m_speechButton && m_speechButton->renderer()) { |
|
324 int buttonLeft = textLeft + innerTextRenderer->width(); |
|
325 if (m_cancelButton) { |
|
326 RenderBox* cancelRenderer = m_cancelButton->renderBox(); |
|
327 cancelRenderer->calcWidth(); |
|
328 buttonLeft += cancelRenderer->width() + cancelRenderer->marginLeft() + cancelRenderer->marginRight(); |
|
329 } |
|
330 if (xPos > buttonLeft) |
|
331 innerNode = m_speechButton.get(); |
|
332 } |
|
333 #endif |
|
334 |
|
335 if (!innerNode) { |
|
336 int textRight = textLeft + innerTextRenderer->width(); |
|
337 if (m_cancelButton && m_cancelButton->renderer() && xPos > textRight) |
|
338 innerNode = m_cancelButton.get(); |
|
339 } |
|
340 |
|
341 if (innerNode) { |
|
342 result.setInnerNode(innerNode); |
|
343 localPoint.move(-innerNode->renderBox()->x(), -innerNode->renderBox()->y()); |
|
344 } |
|
345 |
|
346 result.setLocalPoint(localPoint); |
|
347 return true; |
|
348 } |
|
349 |
|
350 void RenderTextControlSingleLine::forwardEvent(Event* event) |
|
351 { |
|
352 RenderBox* innerTextRenderer = innerTextElement()->renderBox(); |
|
353 |
|
354 if (event->type() == eventNames().blurEvent) { |
|
355 if (innerTextRenderer) { |
|
356 if (RenderLayer* innerLayer = innerTextRenderer->layer()) |
|
357 innerLayer->scrollToOffset(style()->direction() == RTL ? innerLayer->scrollWidth() : 0, 0); |
|
358 } |
|
359 |
|
360 capsLockStateMayHaveChanged(); |
|
361 } else if (event->type() == eventNames().focusEvent) |
|
362 capsLockStateMayHaveChanged(); |
|
363 |
|
364 if (!event->isMouseEvent()) { |
|
365 RenderTextControl::forwardEvent(event); |
|
366 return; |
|
367 } |
|
368 |
|
369 FloatPoint localPoint = innerTextRenderer->absoluteToLocal(static_cast<MouseEvent*>(event)->absoluteLocation(), false, true); |
|
370 int textRight = innerTextRenderer->borderBoxRect().right(); |
|
371 |
|
372 #if ENABLE(INPUT_SPEECH) |
|
373 if (RenderBox* speechBox = m_speechButton ? m_speechButton->renderBox() : 0) { |
|
374 if (localPoint.x() >= speechBox->x() && localPoint.x() < speechBox->x() + speechBox->width()) { |
|
375 m_speechButton->defaultEventHandler(event); |
|
376 return; |
|
377 } |
|
378 } |
|
379 #endif |
|
380 |
|
381 if (m_resultsButton && localPoint.x() < innerTextRenderer->borderBoxRect().x()) |
|
382 m_resultsButton->defaultEventHandler(event); |
|
383 else if (m_cancelButton && localPoint.x() > textRight) |
|
384 m_cancelButton->defaultEventHandler(event); |
|
385 else if (m_innerSpinButton && localPoint.x() > textRight && localPoint.x() < textRight + m_innerSpinButton->renderBox()->width()) |
|
386 m_innerSpinButton->defaultEventHandler(event); |
|
387 else if (m_outerSpinButton && localPoint.x() > textRight) |
|
388 m_outerSpinButton->defaultEventHandler(event); |
|
389 else |
|
390 RenderTextControl::forwardEvent(event); |
|
391 } |
|
392 |
|
393 void RenderTextControlSingleLine::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) |
|
394 { |
|
395 RenderTextControl::styleDidChange(diff, oldStyle); |
|
396 |
|
397 if (RenderObject* innerBlockRenderer = m_innerBlock ? m_innerBlock->renderer() : 0) { |
|
398 // We may have set the width and the height in the old style in layout(). |
|
399 // Reset them now to avoid getting a spurious layout hint. |
|
400 innerBlockRenderer->style()->setHeight(Length()); |
|
401 innerBlockRenderer->style()->setWidth(Length()); |
|
402 innerBlockRenderer->setStyle(createInnerBlockStyle(style())); |
|
403 } |
|
404 |
|
405 if (RenderObject* resultsRenderer = m_resultsButton ? m_resultsButton->renderer() : 0) |
|
406 resultsRenderer->setStyle(createResultsButtonStyle(style())); |
|
407 |
|
408 if (RenderObject* cancelRenderer = m_cancelButton ? m_cancelButton->renderer() : 0) |
|
409 cancelRenderer->setStyle(createCancelButtonStyle(style())); |
|
410 |
|
411 if (RenderObject* spinRenderer = m_outerSpinButton ? m_outerSpinButton->renderer() : 0) |
|
412 spinRenderer->setStyle(createOuterSpinButtonStyle()); |
|
413 |
|
414 #if ENABLE(INPUT_SPEECH) |
|
415 if (RenderObject* speechRenderer = m_speechButton ? m_speechButton->renderer() : 0) |
|
416 speechRenderer->setStyle(createSpeechButtonStyle(style())); |
|
417 #endif |
|
418 |
|
419 setHasOverflowClip(false); |
|
420 } |
|
421 |
|
422 void RenderTextControlSingleLine::capsLockStateMayHaveChanged() |
|
423 { |
|
424 if (!node() || !document()) |
|
425 return; |
|
426 |
|
427 // Only draw the caps lock indicator if these things are true: |
|
428 // 1) The field is a password field |
|
429 // 2) The frame is active |
|
430 // 3) The element is focused |
|
431 // 4) The caps lock is on |
|
432 bool shouldDrawCapsLockIndicator = false; |
|
433 |
|
434 if (Frame* frame = document()->frame()) |
|
435 shouldDrawCapsLockIndicator = inputElement()->isPasswordField() |
|
436 && frame->selection()->isFocusedAndActive() |
|
437 && document()->focusedNode() == node() |
|
438 && PlatformKeyboardEvent::currentCapsLockState(); |
|
439 |
|
440 if (shouldDrawCapsLockIndicator != m_shouldDrawCapsLockIndicator) { |
|
441 m_shouldDrawCapsLockIndicator = shouldDrawCapsLockIndicator; |
|
442 repaint(); |
|
443 } |
|
444 } |
|
445 |
|
446 bool RenderTextControlSingleLine::hasControlClip() const |
|
447 { |
|
448 bool clip = m_cancelButton; |
|
449 #if ENABLE(INPUT_SPEECH) |
|
450 if (m_speechButton) |
|
451 clip = true; |
|
452 #endif |
|
453 return clip; |
|
454 } |
|
455 |
|
456 IntRect RenderTextControlSingleLine::controlClipRect(int tx, int ty) const |
|
457 { |
|
458 // This should only get called for search & speech inputs. |
|
459 ASSERT(hasControlClip()); |
|
460 |
|
461 IntRect clipRect = IntRect(m_innerBlock->renderBox()->frameRect()); |
|
462 clipRect.move(tx, ty); |
|
463 return clipRect; |
|
464 } |
|
465 |
|
466 int RenderTextControlSingleLine::textBlockWidth() const |
|
467 { |
|
468 int width = RenderTextControl::textBlockWidth(); |
|
469 |
|
470 if (RenderBox* resultsRenderer = m_resultsButton ? m_resultsButton->renderBox() : 0) { |
|
471 resultsRenderer->calcWidth(); |
|
472 width -= resultsRenderer->width() + resultsRenderer->marginLeft() + resultsRenderer->marginRight(); |
|
473 } |
|
474 |
|
475 if (RenderBox* cancelRenderer = m_cancelButton ? m_cancelButton->renderBox() : 0) { |
|
476 cancelRenderer->calcWidth(); |
|
477 width -= cancelRenderer->width() + cancelRenderer->marginLeft() + cancelRenderer->marginRight(); |
|
478 } |
|
479 |
|
480 if (RenderBox* spinRenderer = m_innerSpinButton ? m_innerSpinButton->renderBox() : 0) { |
|
481 spinRenderer->calcWidth(); |
|
482 width -= spinRenderer->width() + spinRenderer->marginLeft() + spinRenderer->marginRight(); |
|
483 } |
|
484 |
|
485 #if ENABLE(INPUT_SPEECH) |
|
486 if (RenderBox* speechRenderer = m_speechButton ? m_speechButton->renderBox() : 0) { |
|
487 speechRenderer->calcWidth(); |
|
488 width -= speechRenderer->width() + speechRenderer->marginLeft() + speechRenderer->marginRight(); |
|
489 } |
|
490 #endif |
|
491 |
|
492 return width - decorationWidthRight(); |
|
493 } |
|
494 |
|
495 int RenderTextControlSingleLine::decorationWidthRight() const |
|
496 { |
|
497 int width = 0; |
|
498 if (RenderBox* spinRenderer = m_outerSpinButton ? m_outerSpinButton->renderBox() : 0) { |
|
499 spinRenderer->calcWidth(); |
|
500 width += spinRenderer->width() + spinRenderer->marginLeft() + spinRenderer->marginRight(); |
|
501 } |
|
502 if (width > 0) |
|
503 width += paddingRight() + borderRight(); |
|
504 return width; |
|
505 } |
|
506 |
|
507 float RenderTextControlSingleLine::getAvgCharWidth(AtomicString family) |
|
508 { |
|
509 // Since Lucida Grande is the default font, we want this to match the width |
|
510 // of MS Shell Dlg, the default font for textareas in Firefox, Safari Win and |
|
511 // IE for some encodings (in IE, the default font is encoding specific). |
|
512 // 901 is the avgCharWidth value in the OS/2 table for MS Shell Dlg. |
|
513 if (family == AtomicString("Lucida Grande")) |
|
514 return scaleEmToUnits(901); |
|
515 |
|
516 return RenderTextControl::getAvgCharWidth(family); |
|
517 } |
|
518 |
|
519 int RenderTextControlSingleLine::preferredContentWidth(float charWidth) const |
|
520 { |
|
521 int factor = inputElement()->size(); |
|
522 if (factor <= 0) |
|
523 factor = 20; |
|
524 |
|
525 int result = static_cast<int>(ceilf(charWidth * factor)); |
|
526 |
|
527 float maxCharWidth = 0.f; |
|
528 AtomicString family = style()->font().family().family(); |
|
529 // Since Lucida Grande is the default font, we want this to match the width |
|
530 // of MS Shell Dlg, the default font for textareas in Firefox, Safari Win and |
|
531 // IE for some encodings (in IE, the default font is encoding specific). |
|
532 // 4027 is the (xMax - xMin) value in the "head" font table for MS Shell Dlg. |
|
533 if (family == AtomicString("Lucida Grande")) |
|
534 maxCharWidth = scaleEmToUnits(4027); |
|
535 else if (hasValidAvgCharWidth(family)) |
|
536 maxCharWidth = roundf(style()->font().primaryFont()->maxCharWidth()); |
|
537 |
|
538 // For text inputs, IE adds some extra width. |
|
539 if (maxCharWidth > 0.f) |
|
540 result += maxCharWidth - charWidth; |
|
541 |
|
542 if (RenderBox* resultsRenderer = m_resultsButton ? m_resultsButton->renderBox() : 0) |
|
543 result += resultsRenderer->borderLeft() + resultsRenderer->borderRight() + |
|
544 resultsRenderer->paddingLeft() + resultsRenderer->paddingRight(); |
|
545 |
|
546 if (RenderBox* cancelRenderer = m_cancelButton ? m_cancelButton->renderBox() : 0) |
|
547 result += cancelRenderer->borderLeft() + cancelRenderer->borderRight() + |
|
548 cancelRenderer->paddingLeft() + cancelRenderer->paddingRight(); |
|
549 |
|
550 if (RenderBox* spinRenderer = m_innerSpinButton ? m_innerSpinButton->renderBox() : 0) |
|
551 result += spinRenderer->minPrefWidth(); |
|
552 |
|
553 #if ENABLE(INPUT_SPEECH) |
|
554 if (RenderBox* speechRenderer = m_speechButton ? m_speechButton->renderBox() : 0) { |
|
555 result += speechRenderer->borderLeft() + speechRenderer->borderRight() + |
|
556 speechRenderer->paddingLeft() + speechRenderer->paddingRight(); |
|
557 } |
|
558 #endif |
|
559 return result; |
|
560 } |
|
561 |
|
562 int RenderTextControlSingleLine::preferredDecorationWidthRight() const |
|
563 { |
|
564 int width = 0; |
|
565 if (RenderBox* spinRenderer = m_outerSpinButton ? m_outerSpinButton->renderBox() : 0) { |
|
566 spinRenderer->calcWidth(); |
|
567 width += spinRenderer->minPrefWidth() + spinRenderer->marginLeft() + spinRenderer->marginRight(); |
|
568 } |
|
569 if (width > 0) |
|
570 width += paddingRight() + borderRight(); |
|
571 return width; |
|
572 } |
|
573 |
|
574 void RenderTextControlSingleLine::adjustControlHeightBasedOnLineHeight(int lineHeight) |
|
575 { |
|
576 if (RenderBox* resultsRenderer = m_resultsButton ? m_resultsButton->renderBox() : 0) { |
|
577 toRenderBlock(resultsRenderer)->calcHeight(); |
|
578 setHeight(max(height(), |
|
579 resultsRenderer->borderTop() + resultsRenderer->borderBottom() + |
|
580 resultsRenderer->paddingTop() + resultsRenderer->paddingBottom() + |
|
581 resultsRenderer->marginTop() + resultsRenderer->marginBottom())); |
|
582 lineHeight = max(lineHeight, resultsRenderer->height()); |
|
583 } |
|
584 |
|
585 if (RenderBox* cancelRenderer = m_cancelButton ? m_cancelButton->renderBox() : 0) { |
|
586 toRenderBlock(cancelRenderer)->calcHeight(); |
|
587 setHeight(max(height(), |
|
588 cancelRenderer->borderTop() + cancelRenderer->borderBottom() + |
|
589 cancelRenderer->paddingTop() + cancelRenderer->paddingBottom() + |
|
590 cancelRenderer->marginTop() + cancelRenderer->marginBottom())); |
|
591 lineHeight = max(lineHeight, cancelRenderer->height()); |
|
592 } |
|
593 |
|
594 #if ENABLE(INPUT_SPEECH) |
|
595 if (RenderBox* speechRenderer = m_speechButton ? m_speechButton->renderBox() : 0) { |
|
596 toRenderBlock(speechRenderer)->calcHeight(); |
|
597 setHeight(max(height(), |
|
598 speechRenderer->borderTop() + speechRenderer->borderBottom() + |
|
599 speechRenderer->paddingTop() + speechRenderer->paddingBottom() + |
|
600 speechRenderer->marginTop() + speechRenderer->marginBottom())); |
|
601 lineHeight = max(lineHeight, speechRenderer->height()); |
|
602 } |
|
603 #endif |
|
604 |
|
605 setHeight(height() + lineHeight); |
|
606 } |
|
607 |
|
608 void RenderTextControlSingleLine::createSubtreeIfNeeded() |
|
609 { |
|
610 bool createSubtree = inputElement()->isSearchField(); |
|
611 #if ENABLE(INPUT_SPEECH) |
|
612 if (inputElement()->isSpeechEnabled()) |
|
613 createSubtree = true; |
|
614 #endif |
|
615 if (!createSubtree) { |
|
616 RenderTextControl::createSubtreeIfNeeded(m_innerBlock.get()); |
|
617 bool hasSpinButton = inputElement()->hasSpinButton(); |
|
618 if (hasSpinButton && !m_innerSpinButton) { |
|
619 m_innerSpinButton = SpinButtonElement::create(node()); |
|
620 m_innerSpinButton->attachInnerElement(node(), createInnerSpinButtonStyle(), renderArena()); |
|
621 } |
|
622 if (hasSpinButton && !m_outerSpinButton) { |
|
623 m_outerSpinButton = SpinButtonElement::create(node()); |
|
624 m_outerSpinButton->attachInnerElement(node(), createOuterSpinButtonStyle(), renderArena()); |
|
625 } |
|
626 return; |
|
627 } |
|
628 |
|
629 if (!m_innerBlock) { |
|
630 // Create the inner block element |
|
631 m_innerBlock = TextControlInnerElement::create(node()); |
|
632 m_innerBlock->attachInnerElement(node(), createInnerBlockStyle(style()), renderArena()); |
|
633 } |
|
634 if (inputElement()->hasSpinButton() && !m_outerSpinButton) { |
|
635 m_outerSpinButton = SpinButtonElement::create(node()); |
|
636 m_outerSpinButton->attachInnerElement(node(), createOuterSpinButtonStyle(), renderArena()); |
|
637 } |
|
638 |
|
639 if (inputElement()->isSearchField()) { |
|
640 if (!m_resultsButton) { |
|
641 // Create the search results button element. |
|
642 m_resultsButton = SearchFieldResultsButtonElement::create(document()); |
|
643 m_resultsButton->attachInnerElement(m_innerBlock.get(), createResultsButtonStyle(m_innerBlock->renderer()->style()), renderArena()); |
|
644 } |
|
645 } |
|
646 |
|
647 // Create innerText element before adding the other buttons. |
|
648 RenderTextControl::createSubtreeIfNeeded(m_innerBlock.get()); |
|
649 |
|
650 if (inputElement()->isSearchField()) { |
|
651 if (!m_cancelButton) { |
|
652 // Create the cancel button element. |
|
653 m_cancelButton = SearchFieldCancelButtonElement::create(document()); |
|
654 m_cancelButton->attachInnerElement(m_innerBlock.get(), createCancelButtonStyle(m_innerBlock->renderer()->style()), renderArena()); |
|
655 } |
|
656 } |
|
657 #if ENABLE(INPUT_SPEECH) |
|
658 if (inputElement()->isSpeechEnabled() && !m_speechButton) { |
|
659 // Create the speech button element. |
|
660 m_speechButton = InputFieldSpeechButtonElement::create(document()); |
|
661 m_speechButton->attachInnerElement(m_innerBlock.get(), createSpeechButtonStyle(m_innerBlock->renderer()->style()), renderArena()); |
|
662 } |
|
663 #endif |
|
664 } |
|
665 |
|
666 void RenderTextControlSingleLine::updateFromElement() |
|
667 { |
|
668 createSubtreeIfNeeded(); |
|
669 RenderTextControl::updateFromElement(); |
|
670 |
|
671 if (m_cancelButton) |
|
672 updateCancelButtonVisibility(); |
|
673 |
|
674 if (m_placeholderVisible) { |
|
675 // node() must be an HTMLInputElement. WMLInputElement doesn't support placeholder. |
|
676 ASSERT(node()->isHTMLElement()); |
|
677 ExceptionCode ec = 0; |
|
678 innerTextElement()->setInnerText(static_cast<HTMLInputElement*>(node())->strippedPlaceholder(), ec); |
|
679 ASSERT(!ec); |
|
680 } else { |
|
681 if (!inputElement()->suggestedValue().isNull()) |
|
682 setInnerTextValue(inputElement()->suggestedValue()); |
|
683 else |
|
684 setInnerTextValue(inputElement()->value()); |
|
685 } |
|
686 |
|
687 if (m_searchPopupIsVisible) |
|
688 m_searchPopup->updateFromElement(); |
|
689 } |
|
690 |
|
691 void RenderTextControlSingleLine::cacheSelection(int start, int end) |
|
692 { |
|
693 inputElement()->cacheSelection(start, end); |
|
694 } |
|
695 |
|
696 PassRefPtr<RenderStyle> RenderTextControlSingleLine::createInnerTextStyle(const RenderStyle* startStyle) const |
|
697 { |
|
698 RefPtr<RenderStyle> textBlockStyle; |
|
699 if (m_placeholderVisible) { |
|
700 if (RenderStyle* pseudoStyle = getCachedPseudoStyle(INPUT_PLACEHOLDER)) |
|
701 textBlockStyle = RenderStyle::clone(pseudoStyle); |
|
702 } |
|
703 if (!textBlockStyle) { |
|
704 textBlockStyle = RenderStyle::create(); |
|
705 textBlockStyle->inheritFrom(startStyle); |
|
706 } |
|
707 |
|
708 adjustInnerTextStyle(startStyle, textBlockStyle.get()); |
|
709 |
|
710 textBlockStyle->setWhiteSpace(PRE); |
|
711 textBlockStyle->setWordWrap(NormalWordWrap); |
|
712 textBlockStyle->setOverflowX(OHIDDEN); |
|
713 textBlockStyle->setOverflowY(OHIDDEN); |
|
714 |
|
715 // Do not allow line-height to be smaller than our default. |
|
716 if (textBlockStyle->font().lineSpacing() > lineHeight(true, true)) |
|
717 textBlockStyle->setLineHeight(Length(-100.0f, Percent)); |
|
718 |
|
719 textBlockStyle->setDisplay(m_innerBlock || inputElement()->hasSpinButton() ? INLINE_BLOCK : BLOCK); |
|
720 |
|
721 // We're adding one extra pixel of padding to match WinIE. |
|
722 textBlockStyle->setPaddingLeft(Length(1, Fixed)); |
|
723 textBlockStyle->setPaddingRight(Length(1, Fixed)); |
|
724 |
|
725 // When the placeholder is going to be displayed, temporarily override the text security to be "none". |
|
726 // After this, updateFromElement will immediately update the text displayed. |
|
727 // When the placeholder is no longer visible, updatePlaceholderVisiblity will reset the style, |
|
728 // and the text security mode will be set back to the computed value correctly. |
|
729 if (m_placeholderVisible) |
|
730 textBlockStyle->setTextSecurity(TSNONE); |
|
731 |
|
732 return textBlockStyle.release(); |
|
733 } |
|
734 |
|
735 PassRefPtr<RenderStyle> RenderTextControlSingleLine::createInnerBlockStyle(const RenderStyle* startStyle) const |
|
736 { |
|
737 ASSERT(node()->isHTMLElement()); |
|
738 |
|
739 RefPtr<RenderStyle> innerBlockStyle = RenderStyle::create(); |
|
740 innerBlockStyle->inheritFrom(startStyle); |
|
741 |
|
742 innerBlockStyle->setDisplay(inputElement()->hasSpinButton() ? INLINE_BLOCK : BLOCK); |
|
743 innerBlockStyle->setDirection(LTR); |
|
744 |
|
745 // We don't want the shadow dom to be editable, so we set this block to read-only in case the input itself is editable. |
|
746 innerBlockStyle->setUserModify(READ_ONLY); |
|
747 |
|
748 return innerBlockStyle.release(); |
|
749 } |
|
750 |
|
751 PassRefPtr<RenderStyle> RenderTextControlSingleLine::createResultsButtonStyle(const RenderStyle* startStyle) const |
|
752 { |
|
753 ASSERT(node()->isHTMLElement()); |
|
754 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); |
|
755 |
|
756 RefPtr<RenderStyle> resultsBlockStyle; |
|
757 if (input->maxResults() < 0) |
|
758 resultsBlockStyle = getCachedPseudoStyle(SEARCH_DECORATION); |
|
759 else if (!input->maxResults()) |
|
760 resultsBlockStyle = getCachedPseudoStyle(SEARCH_RESULTS_DECORATION); |
|
761 else |
|
762 resultsBlockStyle = getCachedPseudoStyle(SEARCH_RESULTS_BUTTON); |
|
763 |
|
764 if (!resultsBlockStyle) |
|
765 resultsBlockStyle = RenderStyle::create(); |
|
766 |
|
767 if (startStyle) |
|
768 resultsBlockStyle->inheritFrom(startStyle); |
|
769 |
|
770 return resultsBlockStyle.release(); |
|
771 } |
|
772 |
|
773 PassRefPtr<RenderStyle> RenderTextControlSingleLine::createCancelButtonStyle(const RenderStyle* startStyle) const |
|
774 { |
|
775 ASSERT(node()->isHTMLElement()); |
|
776 RefPtr<RenderStyle> cancelBlockStyle; |
|
777 |
|
778 if (RefPtr<RenderStyle> pseudoStyle = getCachedPseudoStyle(SEARCH_CANCEL_BUTTON)) |
|
779 // We may be sharing style with another search field, but we must not share the cancel button style. |
|
780 cancelBlockStyle = RenderStyle::clone(pseudoStyle.get()); |
|
781 else |
|
782 cancelBlockStyle = RenderStyle::create(); |
|
783 |
|
784 if (startStyle) |
|
785 cancelBlockStyle->inheritFrom(startStyle); |
|
786 |
|
787 cancelBlockStyle->setVisibility(visibilityForCancelButton()); |
|
788 return cancelBlockStyle.release(); |
|
789 } |
|
790 |
|
791 PassRefPtr<RenderStyle> RenderTextControlSingleLine::createInnerSpinButtonStyle() const |
|
792 { |
|
793 ASSERT(node()->isHTMLElement()); |
|
794 RefPtr<RenderStyle> buttonStyle = getCachedPseudoStyle(INNER_SPIN_BUTTON); |
|
795 if (!buttonStyle) |
|
796 buttonStyle = RenderStyle::create(); |
|
797 buttonStyle->inheritFrom(style()); |
|
798 return buttonStyle.release(); |
|
799 } |
|
800 |
|
801 PassRefPtr<RenderStyle> RenderTextControlSingleLine::createOuterSpinButtonStyle() const |
|
802 { |
|
803 ASSERT(node()->isHTMLElement()); |
|
804 RefPtr<RenderStyle> buttonStyle = getCachedPseudoStyle(OUTER_SPIN_BUTTON); |
|
805 if (!buttonStyle) |
|
806 buttonStyle = RenderStyle::create(); |
|
807 buttonStyle->inheritFrom(style()); |
|
808 return buttonStyle.release(); |
|
809 } |
|
810 |
|
811 #if ENABLE(INPUT_SPEECH) |
|
812 PassRefPtr<RenderStyle> RenderTextControlSingleLine::createSpeechButtonStyle(const RenderStyle* startStyle) const |
|
813 { |
|
814 ASSERT(node()->isHTMLElement()); |
|
815 RefPtr<RenderStyle> buttonStyle = getCachedPseudoStyle(INPUT_SPEECH_BUTTON); |
|
816 if (!buttonStyle) |
|
817 buttonStyle = RenderStyle::create(); |
|
818 if (startStyle) |
|
819 buttonStyle->inheritFrom(startStyle); |
|
820 return buttonStyle.release(); |
|
821 } |
|
822 #endif |
|
823 |
|
824 void RenderTextControlSingleLine::updateCancelButtonVisibility() const |
|
825 { |
|
826 if (!m_cancelButton->renderer()) |
|
827 return; |
|
828 |
|
829 const RenderStyle* curStyle = m_cancelButton->renderer()->style(); |
|
830 EVisibility buttonVisibility = visibilityForCancelButton(); |
|
831 if (curStyle->visibility() == buttonVisibility) |
|
832 return; |
|
833 |
|
834 RefPtr<RenderStyle> cancelButtonStyle = RenderStyle::clone(curStyle); |
|
835 cancelButtonStyle->setVisibility(buttonVisibility); |
|
836 m_cancelButton->renderer()->setStyle(cancelButtonStyle); |
|
837 } |
|
838 |
|
839 EVisibility RenderTextControlSingleLine::visibilityForCancelButton() const |
|
840 { |
|
841 ASSERT(node()->isHTMLElement()); |
|
842 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); |
|
843 return input->value().isEmpty() ? HIDDEN : VISIBLE; |
|
844 } |
|
845 |
|
846 const AtomicString& RenderTextControlSingleLine::autosaveName() const |
|
847 { |
|
848 return static_cast<Element*>(node())->getAttribute(autosaveAttr); |
|
849 } |
|
850 |
|
851 void RenderTextControlSingleLine::startSearchEventTimer() |
|
852 { |
|
853 ASSERT(node()->isHTMLElement()); |
|
854 unsigned length = text().length(); |
|
855 |
|
856 // If there's no text, fire the event right away. |
|
857 if (!length) { |
|
858 stopSearchEventTimer(); |
|
859 static_cast<HTMLInputElement*>(node())->onSearch(); |
|
860 return; |
|
861 } |
|
862 |
|
863 // After typing the first key, we wait 0.5 seconds. |
|
864 // After the second key, 0.4 seconds, then 0.3, then 0.2 from then on. |
|
865 m_searchEventTimer.startOneShot(max(0.2, 0.6 - 0.1 * length)); |
|
866 } |
|
867 |
|
868 void RenderTextControlSingleLine::searchEventTimerFired(Timer<RenderTextControlSingleLine>*) |
|
869 { |
|
870 ASSERT(node()->isHTMLElement()); |
|
871 static_cast<HTMLInputElement*>(node())->onSearch(); |
|
872 } |
|
873 |
|
874 // PopupMenuClient methods |
|
875 void RenderTextControlSingleLine::valueChanged(unsigned listIndex, bool fireEvents) |
|
876 { |
|
877 ASSERT(node()->isHTMLElement()); |
|
878 ASSERT(static_cast<int>(listIndex) < listSize()); |
|
879 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); |
|
880 if (static_cast<int>(listIndex) == (listSize() - 1)) { |
|
881 if (fireEvents) { |
|
882 m_recentSearches.clear(); |
|
883 const AtomicString& name = autosaveName(); |
|
884 if (!name.isEmpty()) { |
|
885 if (!m_searchPopup) |
|
886 m_searchPopup = SearchPopupMenu::create(this); |
|
887 m_searchPopup->saveRecentSearches(name, m_recentSearches); |
|
888 } |
|
889 } |
|
890 } else { |
|
891 input->setValue(itemText(listIndex)); |
|
892 if (fireEvents) |
|
893 input->onSearch(); |
|
894 input->select(); |
|
895 } |
|
896 } |
|
897 |
|
898 String RenderTextControlSingleLine::itemText(unsigned listIndex) const |
|
899 { |
|
900 int size = listSize(); |
|
901 if (size == 1) { |
|
902 ASSERT(!listIndex); |
|
903 return searchMenuNoRecentSearchesText(); |
|
904 } |
|
905 if (!listIndex) |
|
906 return searchMenuRecentSearchesText(); |
|
907 if (itemIsSeparator(listIndex)) |
|
908 return String(); |
|
909 if (static_cast<int>(listIndex) == (size - 1)) |
|
910 return searchMenuClearRecentSearchesText(); |
|
911 return m_recentSearches[listIndex - 1]; |
|
912 } |
|
913 |
|
914 String RenderTextControlSingleLine::itemLabel(unsigned) const |
|
915 { |
|
916 return String(); |
|
917 } |
|
918 |
|
919 bool RenderTextControlSingleLine::itemIsEnabled(unsigned listIndex) const |
|
920 { |
|
921 if (!listIndex || itemIsSeparator(listIndex)) |
|
922 return false; |
|
923 return true; |
|
924 } |
|
925 |
|
926 PopupMenuStyle RenderTextControlSingleLine::itemStyle(unsigned) const |
|
927 { |
|
928 return menuStyle(); |
|
929 } |
|
930 |
|
931 PopupMenuStyle RenderTextControlSingleLine::menuStyle() const |
|
932 { |
|
933 return PopupMenuStyle(style()->visitedDependentColor(CSSPropertyColor), style()->visitedDependentColor(CSSPropertyBackgroundColor), style()->font(), style()->visibility() == VISIBLE, style()->textIndent(), style()->direction()); |
|
934 } |
|
935 |
|
936 int RenderTextControlSingleLine::clientInsetLeft() const |
|
937 { |
|
938 // Inset the menu by the radius of the cap on the left so that |
|
939 // it only runs along the straight part of the bezel. |
|
940 return height() / 2; |
|
941 } |
|
942 |
|
943 int RenderTextControlSingleLine::clientInsetRight() const |
|
944 { |
|
945 // Inset the menu by the radius of the cap on the right so that |
|
946 // it only runs along the straight part of the bezel (unless it needs |
|
947 // to be wider). |
|
948 return height() / 2; |
|
949 } |
|
950 |
|
951 int RenderTextControlSingleLine::clientPaddingLeft() const |
|
952 { |
|
953 int padding = paddingLeft(); |
|
954 |
|
955 if (RenderBox* resultsRenderer = m_resultsButton ? m_resultsButton->renderBox() : 0) |
|
956 padding += resultsRenderer->width(); |
|
957 |
|
958 return padding; |
|
959 } |
|
960 |
|
961 int RenderTextControlSingleLine::clientPaddingRight() const |
|
962 { |
|
963 int padding = paddingRight(); |
|
964 |
|
965 if (RenderBox* cancelRenderer = m_cancelButton ? m_cancelButton->renderBox() : 0) |
|
966 padding += cancelRenderer->width(); |
|
967 #if ENABLE(INPUT_SPEECH) |
|
968 if (RenderBox* speechRenderer = m_speechButton ? m_speechButton->renderBox() : 0) |
|
969 padding += speechRenderer->width(); |
|
970 #endif |
|
971 |
|
972 return padding; |
|
973 } |
|
974 |
|
975 int RenderTextControlSingleLine::listSize() const |
|
976 { |
|
977 // If there are no recent searches, then our menu will have 1 "No recent searches" item. |
|
978 if (!m_recentSearches.size()) |
|
979 return 1; |
|
980 // Otherwise, leave room in the menu for a header, a separator, and the "Clear recent searches" item. |
|
981 return m_recentSearches.size() + 3; |
|
982 } |
|
983 |
|
984 int RenderTextControlSingleLine::selectedIndex() const |
|
985 { |
|
986 return -1; |
|
987 } |
|
988 |
|
989 void RenderTextControlSingleLine::popupDidHide() |
|
990 { |
|
991 m_searchPopupIsVisible = false; |
|
992 } |
|
993 |
|
994 bool RenderTextControlSingleLine::itemIsSeparator(unsigned listIndex) const |
|
995 { |
|
996 // The separator will be the second to last item in our list. |
|
997 return static_cast<int>(listIndex) == (listSize() - 2); |
|
998 } |
|
999 |
|
1000 bool RenderTextControlSingleLine::itemIsLabel(unsigned listIndex) const |
|
1001 { |
|
1002 return listIndex == 0; |
|
1003 } |
|
1004 |
|
1005 bool RenderTextControlSingleLine::itemIsSelected(unsigned) const |
|
1006 { |
|
1007 return false; |
|
1008 } |
|
1009 |
|
1010 void RenderTextControlSingleLine::setTextFromItem(unsigned listIndex) |
|
1011 { |
|
1012 ASSERT(node()->isHTMLElement()); |
|
1013 static_cast<HTMLInputElement*>(node())->setValue(itemText(listIndex)); |
|
1014 } |
|
1015 |
|
1016 FontSelector* RenderTextControlSingleLine::fontSelector() const |
|
1017 { |
|
1018 return document()->styleSelector()->fontSelector(); |
|
1019 } |
|
1020 |
|
1021 HostWindow* RenderTextControlSingleLine::hostWindow() const |
|
1022 { |
|
1023 return document()->view()->hostWindow(); |
|
1024 } |
|
1025 |
|
1026 void RenderTextControlSingleLine::autoscroll() |
|
1027 { |
|
1028 RenderLayer* layer = innerTextElement()->renderBox()->layer(); |
|
1029 if (layer) |
|
1030 layer->autoscroll(); |
|
1031 } |
|
1032 |
|
1033 int RenderTextControlSingleLine::scrollWidth() const |
|
1034 { |
|
1035 if (innerTextElement()) |
|
1036 return innerTextElement()->scrollWidth(); |
|
1037 return RenderBlock::scrollWidth(); |
|
1038 } |
|
1039 |
|
1040 int RenderTextControlSingleLine::scrollHeight() const |
|
1041 { |
|
1042 if (innerTextElement()) |
|
1043 return innerTextElement()->scrollHeight(); |
|
1044 return RenderBlock::scrollHeight(); |
|
1045 } |
|
1046 |
|
1047 int RenderTextControlSingleLine::scrollLeft() const |
|
1048 { |
|
1049 if (innerTextElement()) |
|
1050 return innerTextElement()->scrollLeft(); |
|
1051 return RenderBlock::scrollLeft(); |
|
1052 } |
|
1053 |
|
1054 int RenderTextControlSingleLine::scrollTop() const |
|
1055 { |
|
1056 if (innerTextElement()) |
|
1057 return innerTextElement()->scrollTop(); |
|
1058 return RenderBlock::scrollTop(); |
|
1059 } |
|
1060 |
|
1061 void RenderTextControlSingleLine::setScrollLeft(int newLeft) |
|
1062 { |
|
1063 if (innerTextElement()) |
|
1064 innerTextElement()->setScrollLeft(newLeft); |
|
1065 } |
|
1066 |
|
1067 void RenderTextControlSingleLine::setScrollTop(int newTop) |
|
1068 { |
|
1069 if (innerTextElement()) |
|
1070 innerTextElement()->setScrollTop(newTop); |
|
1071 } |
|
1072 |
|
1073 bool RenderTextControlSingleLine::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier, Node** stopNode) |
|
1074 { |
|
1075 RenderLayer* layer = innerTextElement()->renderBox()->layer(); |
|
1076 if (layer && layer->scroll(direction, granularity, multiplier)) |
|
1077 return true; |
|
1078 return RenderBlock::scroll(direction, granularity, multiplier, stopNode); |
|
1079 } |
|
1080 |
|
1081 PassRefPtr<Scrollbar> RenderTextControlSingleLine::createScrollbar(ScrollbarClient* client, ScrollbarOrientation orientation, ScrollbarControlSize controlSize) |
|
1082 { |
|
1083 RefPtr<Scrollbar> widget; |
|
1084 bool hasCustomScrollbarStyle = style()->hasPseudoStyle(SCROLLBAR); |
|
1085 if (hasCustomScrollbarStyle) |
|
1086 widget = RenderScrollbar::createCustomScrollbar(client, orientation, this); |
|
1087 else |
|
1088 widget = Scrollbar::createNativeScrollbar(client, orientation, controlSize); |
|
1089 return widget.release(); |
|
1090 } |
|
1091 |
|
1092 InputElement* RenderTextControlSingleLine::inputElement() const |
|
1093 { |
|
1094 return toInputElement(static_cast<Element*>(node())); |
|
1095 } |
|
1096 |
|
1097 } |