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

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

Issue 275573003: Oilpan: Prepare to move select and option elements to Oilpan heap. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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
« no previous file with comments | « Source/core/rendering/RenderListBox.cpp ('k') | Source/web/WebSearchableFormData.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 int listIndex = select->optionToListIndex(optionIndex); 391 int listIndex = select->optionToListIndex(optionIndex);
392 if (listIndex < 0 || listIndex >= static_cast<int>(select->listItems().size( ))) 392 if (listIndex < 0 || listIndex >= static_cast<int>(select->listItems().size( )))
393 return; 393 return;
394 if (AXMenuList* menuList = toAXMenuList(document().axObjectCache()->get(this ))) 394 if (AXMenuList* menuList = toAXMenuList(document().axObjectCache()->get(this )))
395 menuList->didUpdateActiveOption(optionIndex); 395 menuList->didUpdateActiveOption(optionIndex);
396 } 396 }
397 397
398 String RenderMenuList::itemText(unsigned listIndex) const 398 String RenderMenuList::itemText(unsigned listIndex) const
399 { 399 {
400 HTMLSelectElement* select = selectElement(); 400 HTMLSelectElement* select = selectElement();
401 const Vector<HTMLElement*>& listItems = select->listItems(); 401 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select ->listItems();
402 if (listIndex >= listItems.size()) 402 if (listIndex >= listItems.size())
403 return String(); 403 return String();
404 404
405 String itemString; 405 String itemString;
406 Element* element = listItems[listIndex]; 406 Element* element = listItems[listIndex];
407 if (isHTMLOptGroupElement(*element)) 407 if (isHTMLOptGroupElement(*element))
408 itemString = toHTMLOptGroupElement(*element).groupLabelText(); 408 itemString = toHTMLOptGroupElement(*element).groupLabelText();
409 else if (isHTMLOptionElement(*element)) 409 else if (isHTMLOptionElement(*element))
410 itemString = toHTMLOptionElement(*element).textIndentedToRespectGroupLab el(); 410 itemString = toHTMLOptionElement(*element).textIndentedToRespectGroupLab el();
411 411
412 applyTextTransform(style(), itemString, ' '); 412 applyTextTransform(style(), itemString, ' ');
413 return itemString; 413 return itemString;
414 } 414 }
415 415
416 String RenderMenuList::itemAccessibilityText(unsigned listIndex) const 416 String RenderMenuList::itemAccessibilityText(unsigned listIndex) const
417 { 417 {
418 // Allow the accessible name be changed if necessary. 418 // Allow the accessible name be changed if necessary.
419 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); 419 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select Element()->listItems();
420 if (listIndex >= listItems.size()) 420 if (listIndex >= listItems.size())
421 return String(); 421 return String();
422 return listItems[listIndex]->fastGetAttribute(aria_labelAttr); 422 return listItems[listIndex]->fastGetAttribute(aria_labelAttr);
423 } 423 }
424 424
425 String RenderMenuList::itemToolTip(unsigned listIndex) const 425 String RenderMenuList::itemToolTip(unsigned listIndex) const
426 { 426 {
427 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); 427 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select Element()->listItems();
428 if (listIndex >= listItems.size()) 428 if (listIndex >= listItems.size())
429 return String(); 429 return String();
430 return listItems[listIndex]->title(); 430 return listItems[listIndex]->title();
431 } 431 }
432 432
433 bool RenderMenuList::itemIsEnabled(unsigned listIndex) const 433 bool RenderMenuList::itemIsEnabled(unsigned listIndex) const
434 { 434 {
435 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); 435 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select Element()->listItems();
436 if (listIndex >= listItems.size()) 436 if (listIndex >= listItems.size())
437 return false; 437 return false;
438 HTMLElement* element = listItems[listIndex]; 438 HTMLElement* element = listItems[listIndex];
439 if (!isHTMLOptionElement(*element)) 439 if (!isHTMLOptionElement(*element))
440 return false; 440 return false;
441 441
442 bool groupEnabled = true; 442 bool groupEnabled = true;
443 if (Element* parentElement = element->parentElement()) { 443 if (Element* parentElement = element->parentElement()) {
444 if (isHTMLOptGroupElement(*parentElement)) 444 if (isHTMLOptGroupElement(*parentElement))
445 groupEnabled = !parentElement->isDisabledFormControl(); 445 groupEnabled = !parentElement->isDisabledFormControl();
446 } 446 }
447 if (!groupEnabled) 447 if (!groupEnabled)
448 return false; 448 return false;
449 449
450 return !element->isDisabledFormControl(); 450 return !element->isDisabledFormControl();
451 } 451 }
452 452
453 PopupMenuStyle RenderMenuList::itemStyle(unsigned listIndex) const 453 PopupMenuStyle RenderMenuList::itemStyle(unsigned listIndex) const
454 { 454 {
455 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); 455 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select Element()->listItems();
456 if (listIndex >= listItems.size()) { 456 if (listIndex >= listItems.size()) {
457 // If we are making an out of bounds access, then we want to use the sty le 457 // If we are making an out of bounds access, then we want to use the sty le
458 // of a different option element (index 0). However, if there isn't an o ption element 458 // of a different option element (index 0). However, if there isn't an o ption element
459 // before at index 0, we fall back to the menu's style. 459 // before at index 0, we fall back to the menu's style.
460 if (!listIndex) 460 if (!listIndex)
461 return menuStyle(); 461 return menuStyle();
462 462
463 // Try to retrieve the style of an option element we know exists (index 0). 463 // Try to retrieve the style of an option element we know exists (index 0).
464 listIndex = 0; 464 listIndex = 0;
465 } 465 }
466 HTMLElement* element = listItems[listIndex]; 466 HTMLElement* element = listItems[listIndex];
467 467
468 Color itemBackgroundColor; 468 Color itemBackgroundColor;
469 bool itemHasCustomBackgroundColor; 469 bool itemHasCustomBackgroundColor;
470 getItemBackgroundColor(listIndex, itemBackgroundColor, itemHasCustomBackgrou ndColor); 470 getItemBackgroundColor(listIndex, itemBackgroundColor, itemHasCustomBackgrou ndColor);
471 471
472 RenderStyle* style = element->renderStyle() ? element->renderStyle() : eleme nt->computedStyle(); 472 RenderStyle* style = element->renderStyle() ? element->renderStyle() : eleme nt->computedStyle();
473 return style ? PopupMenuStyle(resolveColor(style, CSSPropertyColor), itemBac kgroundColor, style->font(), style->visibility() == VISIBLE, 473 return style ? PopupMenuStyle(resolveColor(style, CSSPropertyColor), itemBac kgroundColor, style->font(), style->visibility() == VISIBLE,
474 style->display() == NONE, style->textIndent(), style->direction(), isOve rride(style->unicodeBidi()), 474 style->display() == NONE, style->textIndent(), style->direction(), isOve rride(style->unicodeBidi()),
475 itemHasCustomBackgroundColor ? PopupMenuStyle::CustomBackgroundColor : P opupMenuStyle::DefaultBackgroundColor) : menuStyle(); 475 itemHasCustomBackgroundColor ? PopupMenuStyle::CustomBackgroundColor : P opupMenuStyle::DefaultBackgroundColor) : menuStyle();
476 } 476 }
477 477
478 void RenderMenuList::getItemBackgroundColor(unsigned listIndex, Color& itemBackg roundColor, bool& itemHasCustomBackgroundColor) const 478 void RenderMenuList::getItemBackgroundColor(unsigned listIndex, Color& itemBackg roundColor, bool& itemHasCustomBackgroundColor) const
479 { 479 {
480 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); 480 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select Element()->listItems();
481 if (listIndex >= listItems.size()) { 481 if (listIndex >= listItems.size()) {
482 itemBackgroundColor = resolveColor(CSSPropertyBackgroundColor); 482 itemBackgroundColor = resolveColor(CSSPropertyBackgroundColor);
483 itemHasCustomBackgroundColor = false; 483 itemHasCustomBackgroundColor = false;
484 return; 484 return;
485 } 485 }
486 HTMLElement* element = listItems[listIndex]; 486 HTMLElement* element = listItems[listIndex];
487 487
488 Color backgroundColor; 488 Color backgroundColor;
489 if (element->renderStyle()) 489 if (element->renderStyle())
490 backgroundColor = resolveColor(element->renderStyle(), CSSPropertyBackgr oundColor); 490 backgroundColor = resolveColor(element->renderStyle(), CSSPropertyBackgr oundColor);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 return select->optionToListIndex(select->selectedIndex()); 546 return select->optionToListIndex(select->selectedIndex());
547 } 547 }
548 548
549 void RenderMenuList::popupDidHide() 549 void RenderMenuList::popupDidHide()
550 { 550 {
551 m_popupIsVisible = false; 551 m_popupIsVisible = false;
552 } 552 }
553 553
554 bool RenderMenuList::itemIsSeparator(unsigned listIndex) const 554 bool RenderMenuList::itemIsSeparator(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() && isHTMLHRElement(*listItems[listIndex] ); 557 return listIndex < listItems.size() && isHTMLHRElement(*listItems[listIndex] );
558 } 558 }
559 559
560 bool RenderMenuList::itemIsLabel(unsigned listIndex) const 560 bool RenderMenuList::itemIsLabel(unsigned listIndex) const
561 { 561 {
562 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); 562 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select Element()->listItems();
563 return listIndex < listItems.size() && isHTMLOptGroupElement(*listItems[list Index]); 563 return listIndex < listItems.size() && isHTMLOptGroupElement(*listItems[list Index]);
564 } 564 }
565 565
566 bool RenderMenuList::itemIsSelected(unsigned listIndex) const 566 bool RenderMenuList::itemIsSelected(unsigned listIndex) const
567 { 567 {
568 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); 568 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select Element()->listItems();
569 if (listIndex >= listItems.size()) 569 if (listIndex >= listItems.size())
570 return false; 570 return false;
571 HTMLElement* element = listItems[listIndex]; 571 HTMLElement* element = listItems[listIndex];
572 return isHTMLOptionElement(*element) && toHTMLOptionElement(*element).select ed(); 572 return isHTMLOptionElement(*element) && toHTMLOptionElement(*element).select ed();
573 } 573 }
574 574
575 void RenderMenuList::setTextFromItem(unsigned listIndex) 575 void RenderMenuList::setTextFromItem(unsigned listIndex)
576 { 576 {
577 setTextFromOption(selectElement()->listToOptionIndex(listIndex)); 577 setTextFromOption(selectElement()->listToOptionIndex(listIndex));
578 } 578 }
579 579
580 } 580 }
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderListBox.cpp ('k') | Source/web/WebSearchableFormData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698