| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. |
| 3 * 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 3 * 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 RenderListBox::RenderListBox(Element* element) | 83 RenderListBox::RenderListBox(Element* element) |
| 84 : RenderBlockFlow(element) | 84 : RenderBlockFlow(element) |
| 85 , m_optionsChanged(true) | 85 , m_optionsChanged(true) |
| 86 , m_scrollToRevealSelectionAfterLayout(true) | 86 , m_scrollToRevealSelectionAfterLayout(true) |
| 87 , m_inAutoscroll(false) | 87 , m_inAutoscroll(false) |
| 88 , m_optionsWidth(0) | 88 , m_optionsWidth(0) |
| 89 , m_indexOffset(0) | 89 , m_indexOffset(0) |
| 90 { | 90 { |
| 91 ASSERT(element); | 91 ASSERT(element); |
| 92 ASSERT(element->isHTMLElement()); | 92 ASSERT(element->isHTMLElement()); |
| 93 ASSERT(element->hasTagName(HTMLNames::selectTag)); | 93 ASSERT(isHTMLSelectElement(element)); |
| 94 | 94 |
| 95 if (FrameView* frameView = frame()->view()) | 95 if (FrameView* frameView = frame()->view()) |
| 96 frameView->addScrollableArea(this); | 96 frameView->addScrollableArea(this); |
| 97 } | 97 } |
| 98 | 98 |
| 99 RenderListBox::~RenderListBox() | 99 RenderListBox::~RenderListBox() |
| 100 { | 100 { |
| 101 setHasVerticalScrollbar(false); | 101 setHasVerticalScrollbar(false); |
| 102 | 102 |
| 103 if (FrameView* frameView = frame()->view()) | 103 if (FrameView* frameView = frame()->view()) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 122 | 122 |
| 123 if (m_optionsChanged) { | 123 if (m_optionsChanged) { |
| 124 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 124 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); |
| 125 int size = numItems(); | 125 int size = numItems(); |
| 126 | 126 |
| 127 float width = 0; | 127 float width = 0; |
| 128 for (int i = 0; i < size; ++i) { | 128 for (int i = 0; i < size; ++i) { |
| 129 HTMLElement* element = listItems[i]; | 129 HTMLElement* element = listItems[i]; |
| 130 String text; | 130 String text; |
| 131 Font itemFont = style()->font(); | 131 Font itemFont = style()->font(); |
| 132 if (element->hasTagName(optionTag)) { | 132 if (isHTMLOptionElement(*element)) { |
| 133 text = toHTMLOptionElement(element)->textIndentedToRespectGroupL
abel(); | 133 text = toHTMLOptionElement(*element).textIndentedToRespectGroupL
abel(); |
| 134 } else if (element->hasTagName(optgroupTag)) { | 134 } else if (isHTMLOptGroupElement(*element)) { |
| 135 text = toHTMLOptGroupElement(element)->groupLabelText(); | 135 text = toHTMLOptGroupElement(*element).groupLabelText(); |
| 136 FontDescription d = itemFont.fontDescription(); | 136 FontDescription d = itemFont.fontDescription(); |
| 137 d.setWeight(d.bolderWeight()); | 137 d.setWeight(d.bolderWeight()); |
| 138 itemFont = Font(d); | 138 itemFont = Font(d); |
| 139 itemFont.update(document().styleEngine()->fontSelector()); | 139 itemFont.update(document().styleEngine()->fontSelector()); |
| 140 } | 140 } |
| 141 | 141 |
| 142 if (!text.isEmpty()) { | 142 if (!text.isEmpty()) { |
| 143 applyTextTransform(style(), text, ' '); | 143 applyTextTransform(style(), text, ' '); |
| 144 | 144 |
| 145 bool hasStrongDirectionality; | 145 bool hasStrongDirectionality; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 if (selectedItem >= 0) { | 345 if (selectedItem >= 0) { |
| 346 rects.append(pixelSnappedIntRect(itemBoundingBoxRect(additionalOffset, s
electedItem))); | 346 rects.append(pixelSnappedIntRect(itemBoundingBoxRect(additionalOffset, s
electedItem))); |
| 347 return; | 347 return; |
| 348 } | 348 } |
| 349 | 349 |
| 350 // No selected items, find the first non-disabled item. | 350 // No selected items, find the first non-disabled item. |
| 351 int size = numItems(); | 351 int size = numItems(); |
| 352 const Vector<HTMLElement*>& listItems = select->listItems(); | 352 const Vector<HTMLElement*>& listItems = select->listItems(); |
| 353 for (int i = 0; i < size; ++i) { | 353 for (int i = 0; i < size; ++i) { |
| 354 HTMLElement* element = listItems[i]; | 354 HTMLElement* element = listItems[i]; |
| 355 if (element->hasTagName(optionTag) && !element->isDisabledFormControl())
{ | 355 if (isHTMLOptionElement(*element) && !element->isDisabledFormControl())
{ |
| 356 rects.append(pixelSnappedIntRect(itemBoundingBoxRect(additionalOffse
t, i))); | 356 rects.append(pixelSnappedIntRect(itemBoundingBoxRect(additionalOffse
t, i))); |
| 357 return; | 357 return; |
| 358 } | 358 } |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 | 361 |
| 362 int RenderListBox::scrollbarLeft() const | 362 int RenderListBox::scrollbarLeft() const |
| 363 { | 363 { |
| 364 int scrollbarLeft = 0; | 364 int scrollbarLeft = 0; |
| 365 if (style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft()) | 365 if (style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft()) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 HTMLElement* element = listItems[listIndex]; | 411 HTMLElement* element = listItems[listIndex]; |
| 412 | 412 |
| 413 RenderStyle* itemStyle = element->renderStyle(); | 413 RenderStyle* itemStyle = element->renderStyle(); |
| 414 if (!itemStyle) | 414 if (!itemStyle) |
| 415 itemStyle = style(); | 415 itemStyle = style(); |
| 416 | 416 |
| 417 if (itemStyle->visibility() == HIDDEN) | 417 if (itemStyle->visibility() == HIDDEN) |
| 418 return; | 418 return; |
| 419 | 419 |
| 420 String itemText; | 420 String itemText; |
| 421 bool isOptionElement = element->hasTagName(optionTag); | 421 bool isOptionElement = isHTMLOptionElement(*element); |
| 422 if (isOptionElement) | 422 if (isOptionElement) |
| 423 itemText = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel
(); | 423 itemText = toHTMLOptionElement(*element).textIndentedToRespectGroupLabel
(); |
| 424 else if (element->hasTagName(optgroupTag)) | 424 else if (isHTMLOptGroupElement(*element)) |
| 425 itemText = toHTMLOptGroupElement(element)->groupLabelText(); | 425 itemText = toHTMLOptGroupElement(*element).groupLabelText(); |
| 426 applyTextTransform(style(), itemText, ' '); | 426 applyTextTransform(style(), itemText, ' '); |
| 427 | 427 |
| 428 Color textColor = element->renderStyle() ? resolveColor(element->renderStyle
(), CSSPropertyColor) : resolveColor(CSSPropertyColor); | 428 Color textColor = element->renderStyle() ? resolveColor(element->renderStyle
(), CSSPropertyColor) : resolveColor(CSSPropertyColor); |
| 429 if (isOptionElement && toHTMLOptionElement(element)->selected()) { | 429 if (isOptionElement && toHTMLOptionElement(*element).selected()) { |
| 430 if (frame()->selection().isFocusedAndActive() && document().focusedEleme
nt() == node()) | 430 if (frame()->selection().isFocusedAndActive() && document().focusedEleme
nt() == node()) |
| 431 textColor = RenderTheme::theme().activeListBoxSelectionForegroundCol
or(); | 431 textColor = RenderTheme::theme().activeListBoxSelectionForegroundCol
or(); |
| 432 // Honor the foreground color for disabled items | 432 // Honor the foreground color for disabled items |
| 433 else if (!element->isDisabledFormControl() && !select->isDisabledFormCon
trol()) | 433 else if (!element->isDisabledFormControl() && !select->isDisabledFormCon
trol()) |
| 434 textColor = RenderTheme::theme().inactiveListBoxSelectionForegroundC
olor(); | 434 textColor = RenderTheme::theme().inactiveListBoxSelectionForegroundC
olor(); |
| 435 } | 435 } |
| 436 | 436 |
| 437 paintInfo.context->setFillColor(textColor); | 437 paintInfo.context->setFillColor(textColor); |
| 438 | 438 |
| 439 TextRun textRun(itemText, 0, 0, TextRun::AllowTrailingExpansion, itemStyle->
direction(), isOverride(itemStyle->unicodeBidi()), true, TextRun::NoRounding); | 439 TextRun textRun(itemText, 0, 0, TextRun::AllowTrailingExpansion, itemStyle->
direction(), isOverride(itemStyle->unicodeBidi()), true, TextRun::NoRounding); |
| 440 Font itemFont = style()->font(); | 440 Font itemFont = style()->font(); |
| 441 LayoutRect r = itemBoundingBoxRect(paintOffset, listIndex); | 441 LayoutRect r = itemBoundingBoxRect(paintOffset, listIndex); |
| 442 r.move(itemOffsetForAlignment(textRun, itemStyle, itemFont, r)); | 442 r.move(itemOffsetForAlignment(textRun, itemStyle, itemFont, r)); |
| 443 | 443 |
| 444 if (element->hasTagName(optgroupTag)) { | 444 if (isHTMLOptGroupElement(*element)) { |
| 445 FontDescription d = itemFont.fontDescription(); | 445 FontDescription d = itemFont.fontDescription(); |
| 446 d.setWeight(d.bolderWeight()); | 446 d.setWeight(d.bolderWeight()); |
| 447 itemFont = Font(d); | 447 itemFont = Font(d); |
| 448 itemFont.update(document().styleEngine()->fontSelector()); | 448 itemFont.update(document().styleEngine()->fontSelector()); |
| 449 } | 449 } |
| 450 | 450 |
| 451 // Draw the item text | 451 // Draw the item text |
| 452 TextRunPaintInfo textRunPaintInfo(textRun); | 452 TextRunPaintInfo textRunPaintInfo(textRun); |
| 453 textRunPaintInfo.bounds = r; | 453 textRunPaintInfo.bounds = r; |
| 454 paintInfo.context->drawBidiText(itemFont, textRunPaintInfo, roundedIntPoint(
r.location())); | 454 paintInfo.context->drawBidiText(itemFont, textRunPaintInfo, roundedIntPoint(
r.location())); |
| 455 } | 455 } |
| 456 | 456 |
| 457 void RenderListBox::paintItemBackground(PaintInfo& paintInfo, const LayoutPoint&
paintOffset, int listIndex) | 457 void RenderListBox::paintItemBackground(PaintInfo& paintInfo, const LayoutPoint&
paintOffset, int listIndex) |
| 458 { | 458 { |
| 459 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 459 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); |
| 460 HTMLElement* element = listItems[listIndex]; | 460 HTMLElement* element = listItems[listIndex]; |
| 461 | 461 |
| 462 Color backColor; | 462 Color backColor; |
| 463 if (element->hasTagName(optionTag) && toHTMLOptionElement(element)->selected
()) { | 463 if (isHTMLOptionElement(*element) && toHTMLOptionElement(*element).selected(
)) { |
| 464 if (frame()->selection().isFocusedAndActive() && document().focusedEleme
nt() == node()) | 464 if (frame()->selection().isFocusedAndActive() && document().focusedEleme
nt() == node()) |
| 465 backColor = RenderTheme::theme().activeListBoxSelectionBackgroundCol
or(); | 465 backColor = RenderTheme::theme().activeListBoxSelectionBackgroundCol
or(); |
| 466 else | 466 else |
| 467 backColor = RenderTheme::theme().inactiveListBoxSelectionBackgroundC
olor(); | 467 backColor = RenderTheme::theme().inactiveListBoxSelectionBackgroundC
olor(); |
| 468 } else { | 468 } else { |
| 469 backColor = element->renderStyle() ? resolveColor(element->renderStyle()
, CSSPropertyBackgroundColor) : resolveColor(CSSPropertyBackgroundColor); | 469 backColor = element->renderStyle() ? resolveColor(element->renderStyle()
, CSSPropertyBackgroundColor) : resolveColor(CSSPropertyBackgroundColor); |
| 470 } | 470 } |
| 471 | 471 |
| 472 // Draw the background for this list box item | 472 // Draw the background for this list box item |
| 473 if (!element->renderStyle() || element->renderStyle()->visibility() != HIDDE
N) { | 473 if (!element->renderStyle() || element->renderStyle()->visibility() != HIDDE
N) { |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 | 950 |
| 951 if (m_vBar) | 951 if (m_vBar) |
| 952 m_vBar->styleChanged(); | 952 m_vBar->styleChanged(); |
| 953 | 953 |
| 954 // Force an update since we know the scrollbars have changed things. | 954 // Force an update since we know the scrollbars have changed things. |
| 955 if (document().hasAnnotatedRegions()) | 955 if (document().hasAnnotatedRegions()) |
| 956 document().setAnnotatedRegionsDirty(true); | 956 document().setAnnotatedRegionsDirty(true); |
| 957 } | 957 } |
| 958 | 958 |
| 959 } // namespace WebCore | 959 } // namespace WebCore |
| OLD | NEW |