| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 adjustInnerStyle(); | 155 adjustInnerStyle(); |
| 156 | 156 |
| 157 bool fontChanged = !oldStyle || oldStyle->font() != style()->font(); | 157 bool fontChanged = !oldStyle || oldStyle->font() != style()->font(); |
| 158 if (fontChanged) | 158 if (fontChanged) |
| 159 updateOptionsWidth(); | 159 updateOptionsWidth(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void RenderMenuList::updateOptionsWidth() | 162 void RenderMenuList::updateOptionsWidth() |
| 163 { | 163 { |
| 164 float maxOptionWidth = 0; | 164 float maxOptionWidth = 0; |
| 165 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 165 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select
Element()->listItems(); |
| 166 int size = listItems.size(); | 166 int size = listItems.size(); |
| 167 FontCachePurgePreventer fontCachePurgePreventer; | 167 FontCachePurgePreventer fontCachePurgePreventer; |
| 168 | 168 |
| 169 for (int i = 0; i < size; ++i) { | 169 for (int i = 0; i < size; ++i) { |
| 170 HTMLElement* element = listItems[i]; | 170 HTMLElement* element = listItems[i]; |
| 171 if (!isHTMLOptionElement(*element)) | 171 if (!isHTMLOptionElement(*element)) |
| 172 continue; | 172 continue; |
| 173 | 173 |
| 174 String text = toHTMLOptionElement(element)->textIndentedToRespectGroupLa
bel(); | 174 String text = toHTMLOptionElement(element)->textIndentedToRespectGroupLa
bel(); |
| 175 applyTextTransform(style(), text, ' '); | 175 applyTextTransform(style(), text, ' '); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 if (selectElement()->suggestedIndex() >= 0) | 207 if (selectElement()->suggestedIndex() >= 0) |
| 208 setTextFromOption(selectElement()->suggestedIndex()); | 208 setTextFromOption(selectElement()->suggestedIndex()); |
| 209 else | 209 else |
| 210 setTextFromOption(selectElement()->selectedIndex()); | 210 setTextFromOption(selectElement()->selectedIndex()); |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 | 213 |
| 214 void RenderMenuList::setTextFromOption(int optionIndex) | 214 void RenderMenuList::setTextFromOption(int optionIndex) |
| 215 { | 215 { |
| 216 HTMLSelectElement* select = selectElement(); | 216 HTMLSelectElement* select = selectElement(); |
| 217 const Vector<HTMLElement*>& listItems = select->listItems(); | 217 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select
->listItems(); |
| 218 int size = listItems.size(); | 218 int size = listItems.size(); |
| 219 | 219 |
| 220 int i = select->optionToListIndex(optionIndex); | 220 int i = select->optionToListIndex(optionIndex); |
| 221 String text = emptyString(); | 221 String text = emptyString(); |
| 222 if (i >= 0 && i < size) { | 222 if (i >= 0 && i < size) { |
| 223 Element* element = listItems[i]; | 223 Element* element = listItems[i]; |
| 224 if (isHTMLOptionElement(*element)) { | 224 if (isHTMLOptionElement(*element)) { |
| 225 text = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel
(); | 225 text = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel
(); |
| 226 m_optionStyle = element->renderStyle(); | 226 m_optionStyle = element->renderStyle(); |
| 227 } | 227 } |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 int listIndex = select->optionToListIndex(optionIndex); | 385 int listIndex = select->optionToListIndex(optionIndex); |
| 386 if (listIndex < 0 || listIndex >= static_cast<int>(select->listItems().size(
))) | 386 if (listIndex < 0 || listIndex >= static_cast<int>(select->listItems().size(
))) |
| 387 return; | 387 return; |
| 388 if (AXMenuList* menuList = toAXMenuList(document().axObjectCache()->get(this
))) | 388 if (AXMenuList* menuList = toAXMenuList(document().axObjectCache()->get(this
))) |
| 389 menuList->didUpdateActiveOption(optionIndex); | 389 menuList->didUpdateActiveOption(optionIndex); |
| 390 } | 390 } |
| 391 | 391 |
| 392 String RenderMenuList::itemText(unsigned listIndex) const | 392 String RenderMenuList::itemText(unsigned listIndex) const |
| 393 { | 393 { |
| 394 HTMLSelectElement* select = selectElement(); | 394 HTMLSelectElement* select = selectElement(); |
| 395 const Vector<HTMLElement*>& listItems = select->listItems(); | 395 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select
->listItems(); |
| 396 if (listIndex >= listItems.size()) | 396 if (listIndex >= listItems.size()) |
| 397 return String(); | 397 return String(); |
| 398 | 398 |
| 399 String itemString; | 399 String itemString; |
| 400 Element* element = listItems[listIndex]; | 400 Element* element = listItems[listIndex]; |
| 401 if (isHTMLOptGroupElement(*element)) | 401 if (isHTMLOptGroupElement(*element)) |
| 402 itemString = toHTMLOptGroupElement(*element).groupLabelText(); | 402 itemString = toHTMLOptGroupElement(*element).groupLabelText(); |
| 403 else if (isHTMLOptionElement(*element)) | 403 else if (isHTMLOptionElement(*element)) |
| 404 itemString = toHTMLOptionElement(*element).textIndentedToRespectGroupLab
el(); | 404 itemString = toHTMLOptionElement(*element).textIndentedToRespectGroupLab
el(); |
| 405 | 405 |
| 406 applyTextTransform(style(), itemString, ' '); | 406 applyTextTransform(style(), itemString, ' '); |
| 407 return itemString; | 407 return itemString; |
| 408 } | 408 } |
| 409 | 409 |
| 410 String RenderMenuList::itemAccessibilityText(unsigned listIndex) const | 410 String RenderMenuList::itemAccessibilityText(unsigned listIndex) const |
| 411 { | 411 { |
| 412 // Allow the accessible name be changed if necessary. | 412 // Allow the accessible name be changed if necessary. |
| 413 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 413 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select
Element()->listItems(); |
| 414 if (listIndex >= listItems.size()) | 414 if (listIndex >= listItems.size()) |
| 415 return String(); | 415 return String(); |
| 416 return listItems[listIndex]->fastGetAttribute(aria_labelAttr); | 416 return listItems[listIndex]->fastGetAttribute(aria_labelAttr); |
| 417 } | 417 } |
| 418 | 418 |
| 419 String RenderMenuList::itemToolTip(unsigned listIndex) const | 419 String RenderMenuList::itemToolTip(unsigned listIndex) const |
| 420 { | 420 { |
| 421 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 421 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select
Element()->listItems(); |
| 422 if (listIndex >= listItems.size()) | 422 if (listIndex >= listItems.size()) |
| 423 return String(); | 423 return String(); |
| 424 return listItems[listIndex]->title(); | 424 return listItems[listIndex]->title(); |
| 425 } | 425 } |
| 426 | 426 |
| 427 bool RenderMenuList::itemIsEnabled(unsigned listIndex) const | 427 bool RenderMenuList::itemIsEnabled(unsigned listIndex) const |
| 428 { | 428 { |
| 429 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 429 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select
Element()->listItems(); |
| 430 if (listIndex >= listItems.size()) | 430 if (listIndex >= listItems.size()) |
| 431 return false; | 431 return false; |
| 432 HTMLElement* element = listItems[listIndex]; | 432 HTMLElement* element = listItems[listIndex]; |
| 433 if (!isHTMLOptionElement(*element)) | 433 if (!isHTMLOptionElement(*element)) |
| 434 return false; | 434 return false; |
| 435 | 435 |
| 436 bool groupEnabled = true; | 436 bool groupEnabled = true; |
| 437 if (Element* parentElement = element->parentElement()) { | 437 if (Element* parentElement = element->parentElement()) { |
| 438 if (isHTMLOptGroupElement(*parentElement)) | 438 if (isHTMLOptGroupElement(*parentElement)) |
| 439 groupEnabled = !parentElement->isDisabledFormControl(); | 439 groupEnabled = !parentElement->isDisabledFormControl(); |
| 440 } | 440 } |
| 441 if (!groupEnabled) | 441 if (!groupEnabled) |
| 442 return false; | 442 return false; |
| 443 | 443 |
| 444 return !element->isDisabledFormControl(); | 444 return !element->isDisabledFormControl(); |
| 445 } | 445 } |
| 446 | 446 |
| 447 PopupMenuStyle RenderMenuList::itemStyle(unsigned listIndex) const | 447 PopupMenuStyle RenderMenuList::itemStyle(unsigned listIndex) const |
| 448 { | 448 { |
| 449 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 449 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select
Element()->listItems(); |
| 450 if (listIndex >= listItems.size()) { | 450 if (listIndex >= listItems.size()) { |
| 451 // If we are making an out of bounds access, then we want to use the sty
le | 451 // If we are making an out of bounds access, then we want to use the sty
le |
| 452 // of a different option element (index 0). However, if there isn't an o
ption element | 452 // of a different option element (index 0). However, if there isn't an o
ption element |
| 453 // before at index 0, we fall back to the menu's style. | 453 // before at index 0, we fall back to the menu's style. |
| 454 if (!listIndex) | 454 if (!listIndex) |
| 455 return menuStyle(); | 455 return menuStyle(); |
| 456 | 456 |
| 457 // Try to retrieve the style of an option element we know exists (index
0). | 457 // Try to retrieve the style of an option element we know exists (index
0). |
| 458 listIndex = 0; | 458 listIndex = 0; |
| 459 } | 459 } |
| 460 HTMLElement* element = listItems[listIndex]; | 460 HTMLElement* element = listItems[listIndex]; |
| 461 | 461 |
| 462 Color itemBackgroundColor; | 462 Color itemBackgroundColor; |
| 463 bool itemHasCustomBackgroundColor; | 463 bool itemHasCustomBackgroundColor; |
| 464 getItemBackgroundColor(listIndex, itemBackgroundColor, itemHasCustomBackgrou
ndColor); | 464 getItemBackgroundColor(listIndex, itemBackgroundColor, itemHasCustomBackgrou
ndColor); |
| 465 | 465 |
| 466 RenderStyle* style = element->renderStyle() ? element->renderStyle() : eleme
nt->computedStyle(); | 466 RenderStyle* style = element->renderStyle() ? element->renderStyle() : eleme
nt->computedStyle(); |
| 467 return style ? PopupMenuStyle(resolveColor(style, CSSPropertyColor), itemBac
kgroundColor, style->font(), style->visibility() == VISIBLE, | 467 return style ? PopupMenuStyle(resolveColor(style, CSSPropertyColor), itemBac
kgroundColor, style->font(), style->visibility() == VISIBLE, |
| 468 style->display() == NONE, style->textIndent(), style->direction(), isOve
rride(style->unicodeBidi()), | 468 style->display() == NONE, style->textIndent(), style->direction(), isOve
rride(style->unicodeBidi()), |
| 469 itemHasCustomBackgroundColor ? PopupMenuStyle::CustomBackgroundColor : P
opupMenuStyle::DefaultBackgroundColor) : menuStyle(); | 469 itemHasCustomBackgroundColor ? PopupMenuStyle::CustomBackgroundColor : P
opupMenuStyle::DefaultBackgroundColor) : menuStyle(); |
| 470 } | 470 } |
| 471 | 471 |
| 472 void RenderMenuList::getItemBackgroundColor(unsigned listIndex, Color& itemBackg
roundColor, bool& itemHasCustomBackgroundColor) const | 472 void RenderMenuList::getItemBackgroundColor(unsigned listIndex, Color& itemBackg
roundColor, bool& itemHasCustomBackgroundColor) const |
| 473 { | 473 { |
| 474 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 474 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select
Element()->listItems(); |
| 475 if (listIndex >= listItems.size()) { | 475 if (listIndex >= listItems.size()) { |
| 476 itemBackgroundColor = resolveColor(CSSPropertyBackgroundColor); | 476 itemBackgroundColor = resolveColor(CSSPropertyBackgroundColor); |
| 477 itemHasCustomBackgroundColor = false; | 477 itemHasCustomBackgroundColor = false; |
| 478 return; | 478 return; |
| 479 } | 479 } |
| 480 HTMLElement* element = listItems[listIndex]; | 480 HTMLElement* element = listItems[listIndex]; |
| 481 | 481 |
| 482 Color backgroundColor; | 482 Color backgroundColor; |
| 483 if (element->renderStyle()) | 483 if (element->renderStyle()) |
| 484 backgroundColor = resolveColor(element->renderStyle(), CSSPropertyBackgr
oundColor); | 484 backgroundColor = resolveColor(element->renderStyle(), CSSPropertyBackgr
oundColor); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 return select->optionToListIndex(select->selectedIndex()); | 540 return select->optionToListIndex(select->selectedIndex()); |
| 541 } | 541 } |
| 542 | 542 |
| 543 void RenderMenuList::popupDidHide() | 543 void RenderMenuList::popupDidHide() |
| 544 { | 544 { |
| 545 m_popupIsVisible = false; | 545 m_popupIsVisible = false; |
| 546 } | 546 } |
| 547 | 547 |
| 548 bool RenderMenuList::itemIsSeparator(unsigned listIndex) const | 548 bool RenderMenuList::itemIsSeparator(unsigned listIndex) const |
| 549 { | 549 { |
| 550 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 550 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select
Element()->listItems(); |
| 551 return listIndex < listItems.size() && isHTMLHRElement(*listItems[listIndex]
); | 551 return listIndex < listItems.size() && isHTMLHRElement(*listItems[listIndex]
); |
| 552 } | 552 } |
| 553 | 553 |
| 554 bool RenderMenuList::itemIsLabel(unsigned listIndex) const | 554 bool RenderMenuList::itemIsLabel(unsigned listIndex) const |
| 555 { | 555 { |
| 556 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 556 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select
Element()->listItems(); |
| 557 return listIndex < listItems.size() && isHTMLOptGroupElement(*listItems[list
Index]); | 557 return listIndex < listItems.size() && isHTMLOptGroupElement(*listItems[list
Index]); |
| 558 } | 558 } |
| 559 | 559 |
| 560 bool RenderMenuList::itemIsSelected(unsigned listIndex) const | 560 bool RenderMenuList::itemIsSelected(unsigned listIndex) const |
| 561 { | 561 { |
| 562 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 562 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select
Element()->listItems(); |
| 563 if (listIndex >= listItems.size()) | 563 if (listIndex >= listItems.size()) |
| 564 return false; | 564 return false; |
| 565 HTMLElement* element = listItems[listIndex]; | 565 HTMLElement* element = listItems[listIndex]; |
| 566 return isHTMLOptionElement(*element) && toHTMLOptionElement(*element).select
ed(); | 566 return isHTMLOptionElement(*element) && toHTMLOptionElement(*element).select
ed(); |
| 567 } | 567 } |
| 568 | 568 |
| 569 void RenderMenuList::setTextFromItem(unsigned listIndex) | 569 void RenderMenuList::setTextFromItem(unsigned listIndex) |
| 570 { | 570 { |
| 571 setTextFromOption(selectElement()->listToOptionIndex(listIndex)); | 571 setTextFromOption(selectElement()->listToOptionIndex(listIndex)); |
| 572 } | 572 } |
| 573 | 573 |
| 574 } | 574 } |
| OLD | NEW |