OLD | NEW |
1 /* | 1 /* |
2 * This file is part of the select element renderer in WebCore. | 2 * This file is part of the select element renderer in WebCore. |
3 * | 3 * |
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). | 4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
5 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. | 5 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. |
6 * 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 6 * 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 RenderMenuList::RenderMenuList(Element* element) | 55 RenderMenuList::RenderMenuList(Element* element) |
56 : RenderFlexibleBox(element) | 56 : RenderFlexibleBox(element) |
57 , m_buttonText(0) | 57 , m_buttonText(0) |
58 , m_innerBlock(0) | 58 , m_innerBlock(0) |
59 , m_optionsChanged(true) | 59 , m_optionsChanged(true) |
60 , m_optionsWidth(0) | 60 , m_optionsWidth(0) |
61 , m_lastActiveIndex(-1) | 61 , m_lastActiveIndex(-1) |
62 , m_popupIsVisible(false) | 62 , m_popupIsVisible(false) |
63 { | 63 { |
64 ASSERT(element); | 64 ASSERT(isHTMLSelectElement(element)); |
65 ASSERT(element->isHTMLElement()); | |
66 ASSERT(element->hasTagName(HTMLNames::selectTag)); | |
67 } | 65 } |
68 | 66 |
69 RenderMenuList::~RenderMenuList() | 67 RenderMenuList::~RenderMenuList() |
70 { | 68 { |
71 if (m_popup) | 69 if (m_popup) |
72 m_popup->disconnectClient(); | 70 m_popup->disconnectClient(); |
73 m_popup = nullptr; | 71 m_popup = nullptr; |
74 } | 72 } |
75 | 73 |
76 // FIXME: Instead of this hack we should add a ShadowRoot to <select> with no in
sertion point | 74 // FIXME: Instead of this hack we should add a ShadowRoot to <select> with no in
sertion point |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 161 |
164 void RenderMenuList::updateOptionsWidth() | 162 void RenderMenuList::updateOptionsWidth() |
165 { | 163 { |
166 float maxOptionWidth = 0; | 164 float maxOptionWidth = 0; |
167 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 165 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); |
168 int size = listItems.size(); | 166 int size = listItems.size(); |
169 FontCachePurgePreventer fontCachePurgePreventer; | 167 FontCachePurgePreventer fontCachePurgePreventer; |
170 | 168 |
171 for (int i = 0; i < size; ++i) { | 169 for (int i = 0; i < size; ++i) { |
172 HTMLElement* element = listItems[i]; | 170 HTMLElement* element = listItems[i]; |
173 if (!element->hasTagName(optionTag)) | 171 if (!isHTMLOptionElement(*element)) |
174 continue; | 172 continue; |
175 | 173 |
176 String text = toHTMLOptionElement(element)->textIndentedToRespectGroupLa
bel(); | 174 String text = toHTMLOptionElement(element)->textIndentedToRespectGroupLa
bel(); |
177 applyTextTransform(style(), text, ' '); | 175 applyTextTransform(style(), text, ' '); |
178 if (RenderTheme::theme().popupOptionSupportsTextIndent()) { | 176 if (RenderTheme::theme().popupOptionSupportsTextIndent()) { |
179 // Add in the option's text indent. We can't calculate percentage v
alues for now. | 177 // Add in the option's text indent. We can't calculate percentage v
alues for now. |
180 float optionWidth = 0; | 178 float optionWidth = 0; |
181 if (RenderStyle* optionStyle = element->renderStyle()) | 179 if (RenderStyle* optionStyle = element->renderStyle()) |
182 optionWidth += minimumValueForLength(optionStyle->textIndent(),
0); | 180 optionWidth += minimumValueForLength(optionStyle->textIndent(),
0); |
183 if (!text.isEmpty()) | 181 if (!text.isEmpty()) |
(...skipping 28 matching lines...) Expand all Loading... |
212 void RenderMenuList::setTextFromOption(int optionIndex) | 210 void RenderMenuList::setTextFromOption(int optionIndex) |
213 { | 211 { |
214 HTMLSelectElement* select = selectElement(); | 212 HTMLSelectElement* select = selectElement(); |
215 const Vector<HTMLElement*>& listItems = select->listItems(); | 213 const Vector<HTMLElement*>& listItems = select->listItems(); |
216 int size = listItems.size(); | 214 int size = listItems.size(); |
217 | 215 |
218 int i = select->optionToListIndex(optionIndex); | 216 int i = select->optionToListIndex(optionIndex); |
219 String text = emptyString(); | 217 String text = emptyString(); |
220 if (i >= 0 && i < size) { | 218 if (i >= 0 && i < size) { |
221 Element* element = listItems[i]; | 219 Element* element = listItems[i]; |
222 if (element->hasTagName(optionTag)) { | 220 if (isHTMLOptionElement(*element)) { |
223 text = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel
(); | 221 text = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel
(); |
224 m_optionStyle = element->renderStyle(); | 222 m_optionStyle = element->renderStyle(); |
225 } | 223 } |
226 } | 224 } |
227 | 225 |
228 setText(text.stripWhiteSpace()); | 226 setText(text.stripWhiteSpace()); |
229 didUpdateActiveOption(optionIndex); | 227 didUpdateActiveOption(optionIndex); |
230 } | 228 } |
231 | 229 |
232 void RenderMenuList::setText(const String& s) | 230 void RenderMenuList::setText(const String& s) |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 386 |
389 String RenderMenuList::itemText(unsigned listIndex) const | 387 String RenderMenuList::itemText(unsigned listIndex) const |
390 { | 388 { |
391 HTMLSelectElement* select = selectElement(); | 389 HTMLSelectElement* select = selectElement(); |
392 const Vector<HTMLElement*>& listItems = select->listItems(); | 390 const Vector<HTMLElement*>& listItems = select->listItems(); |
393 if (listIndex >= listItems.size()) | 391 if (listIndex >= listItems.size()) |
394 return String(); | 392 return String(); |
395 | 393 |
396 String itemString; | 394 String itemString; |
397 Element* element = listItems[listIndex]; | 395 Element* element = listItems[listIndex]; |
398 if (element->hasTagName(optgroupTag)) | 396 if (isHTMLOptGroupElement(*element)) |
399 itemString = toHTMLOptGroupElement(element)->groupLabelText(); | 397 itemString = toHTMLOptGroupElement(*element).groupLabelText(); |
400 else if (element->hasTagName(optionTag)) | 398 else if (isHTMLOptionElement(*element)) |
401 itemString = toHTMLOptionElement(element)->textIndentedToRespectGroupLab
el(); | 399 itemString = toHTMLOptionElement(*element).textIndentedToRespectGroupLab
el(); |
402 | 400 |
403 applyTextTransform(style(), itemString, ' '); | 401 applyTextTransform(style(), itemString, ' '); |
404 return itemString; | 402 return itemString; |
405 } | 403 } |
406 | 404 |
407 String RenderMenuList::itemAccessibilityText(unsigned listIndex) const | 405 String RenderMenuList::itemAccessibilityText(unsigned listIndex) const |
408 { | 406 { |
409 // Allow the accessible name be changed if necessary. | 407 // Allow the accessible name be changed if necessary. |
410 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 408 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); |
411 if (listIndex >= listItems.size()) | 409 if (listIndex >= listItems.size()) |
412 return String(); | 410 return String(); |
413 return listItems[listIndex]->fastGetAttribute(aria_labelAttr); | 411 return listItems[listIndex]->fastGetAttribute(aria_labelAttr); |
414 } | 412 } |
415 | 413 |
416 String RenderMenuList::itemToolTip(unsigned listIndex) const | 414 String RenderMenuList::itemToolTip(unsigned listIndex) const |
417 { | 415 { |
418 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 416 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); |
419 if (listIndex >= listItems.size()) | 417 if (listIndex >= listItems.size()) |
420 return String(); | 418 return String(); |
421 return listItems[listIndex]->title(); | 419 return listItems[listIndex]->title(); |
422 } | 420 } |
423 | 421 |
424 bool RenderMenuList::itemIsEnabled(unsigned listIndex) const | 422 bool RenderMenuList::itemIsEnabled(unsigned listIndex) const |
425 { | 423 { |
426 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 424 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); |
427 if (listIndex >= listItems.size()) | 425 if (listIndex >= listItems.size()) |
428 return false; | 426 return false; |
429 HTMLElement* element = listItems[listIndex]; | 427 HTMLElement* element = listItems[listIndex]; |
430 if (!element->hasTagName(optionTag)) | 428 if (!isHTMLOptionElement(*element)) |
431 return false; | 429 return false; |
432 | 430 |
433 bool groupEnabled = true; | 431 bool groupEnabled = true; |
434 if (Element* parentElement = element->parentElement()) { | 432 if (Element* parentElement = element->parentElement()) { |
435 if (parentElement->hasTagName(optgroupTag)) | 433 if (isHTMLOptGroupElement(*parentElement)) |
436 groupEnabled = !parentElement->isDisabledFormControl(); | 434 groupEnabled = !parentElement->isDisabledFormControl(); |
437 } | 435 } |
438 if (!groupEnabled) | 436 if (!groupEnabled) |
439 return false; | 437 return false; |
440 | 438 |
441 return !element->isDisabledFormControl(); | 439 return !element->isDisabledFormControl(); |
442 } | 440 } |
443 | 441 |
444 PopupMenuStyle RenderMenuList::itemStyle(unsigned listIndex) const | 442 PopupMenuStyle RenderMenuList::itemStyle(unsigned listIndex) const |
445 { | 443 { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 } | 536 } |
539 | 537 |
540 void RenderMenuList::popupDidHide() | 538 void RenderMenuList::popupDidHide() |
541 { | 539 { |
542 m_popupIsVisible = false; | 540 m_popupIsVisible = false; |
543 } | 541 } |
544 | 542 |
545 bool RenderMenuList::itemIsSeparator(unsigned listIndex) const | 543 bool RenderMenuList::itemIsSeparator(unsigned listIndex) const |
546 { | 544 { |
547 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 545 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); |
548 return listIndex < listItems.size() && listItems[listIndex]->hasTagName(hrTa
g); | 546 return listIndex < listItems.size() && isHTMLHRElement(*listItems[listIndex]
); |
549 } | 547 } |
550 | 548 |
551 bool RenderMenuList::itemIsLabel(unsigned listIndex) const | 549 bool RenderMenuList::itemIsLabel(unsigned listIndex) const |
552 { | 550 { |
553 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 551 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); |
554 return listIndex < listItems.size() && listItems[listIndex]->hasTagName(optg
roupTag); | 552 return listIndex < listItems.size() && isHTMLOptGroupElement(*listItems[list
Index]); |
555 } | 553 } |
556 | 554 |
557 bool RenderMenuList::itemIsSelected(unsigned listIndex) const | 555 bool RenderMenuList::itemIsSelected(unsigned listIndex) const |
558 { | 556 { |
559 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 557 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); |
560 if (listIndex >= listItems.size()) | 558 if (listIndex >= listItems.size()) |
561 return false; | 559 return false; |
562 HTMLElement* element = listItems[listIndex]; | 560 HTMLElement* element = listItems[listIndex]; |
563 return element->hasTagName(optionTag) && toHTMLOptionElement(element)->selec
ted(); | 561 return isHTMLOptionElement(*element) && toHTMLOptionElement(*element).select
ed(); |
564 } | 562 } |
565 | 563 |
566 void RenderMenuList::setTextFromItem(unsigned listIndex) | 564 void RenderMenuList::setTextFromItem(unsigned listIndex) |
567 { | 565 { |
568 setTextFromOption(selectElement()->listToOptionIndex(listIndex)); | 566 setTextFromOption(selectElement()->listToOptionIndex(listIndex)); |
569 } | 567 } |
570 | 568 |
571 } | 569 } |
OLD | NEW |