Chromium Code Reviews| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 // widget, but I'm not sure this is right for the new control. | 80 // widget, but I'm not sure this is right for the new control. |
| 81 const int baselineAdjustment = 7; | 81 const int baselineAdjustment = 7; |
| 82 | 82 |
| 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 , m_listItemCount(0) | |
| 90 { | 91 { |
| 91 ASSERT(element); | 92 ASSERT(element); |
| 92 ASSERT(element->isHTMLElement()); | 93 ASSERT(element->isHTMLElement()); |
| 93 ASSERT(isHTMLSelectElement(element)); | 94 ASSERT(isHTMLSelectElement(element)); |
| 94 | 95 |
| 95 if (FrameView* frameView = frame()->view()) | 96 if (FrameView* frameView = frame()->view()) |
| 96 frameView->addScrollableArea(this); | 97 frameView->addScrollableArea(this); |
| 97 } | 98 } |
| 98 | 99 |
| 99 RenderListBox::~RenderListBox() | 100 RenderListBox::~RenderListBox() |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 112 } | 113 } |
| 113 | 114 |
| 114 inline HTMLSelectElement* RenderListBox::selectElement() const | 115 inline HTMLSelectElement* RenderListBox::selectElement() const |
| 115 { | 116 { |
| 116 return toHTMLSelectElement(node()); | 117 return toHTMLSelectElement(node()); |
| 117 } | 118 } |
| 118 | 119 |
| 119 void RenderListBox::updateFromElement() | 120 void RenderListBox::updateFromElement() |
| 120 { | 121 { |
| 121 FontCachePurgePreventer fontCachePurgePreventer; | 122 FontCachePurgePreventer fontCachePurgePreventer; |
| 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 = static_cast<int>(listItems.size()); |
| 126 | 126 |
| 127 float width = 0; | 127 float width = 0; |
| 128 | |
| 129 m_listItemCount = 0; | |
| 128 for (int i = 0; i < size; ++i) { | 130 for (int i = 0; i < size; ++i) { |
| 129 HTMLElement* element = listItems[i]; | 131 HTMLElement* element = listItems[i]; |
| 132 RenderStyle* listItemStyle = element->renderStyle(); | |
| 133 if (listItemStyle && listItemStyle->display() == NONE) | |
| 134 continue; | |
| 135 | |
| 136 ++m_listItemCount; | |
| 130 String text; | 137 String text; |
| 131 Font itemFont = style()->font(); | 138 Font itemFont = style()->font(); |
| 132 if (isHTMLOptionElement(*element)) { | 139 if (isHTMLOptionElement(*element)) { |
| 133 text = toHTMLOptionElement(*element).textIndentedToRespectGroupL abel(); | 140 text = toHTMLOptionElement(*element).textIndentedToRespectGroupL abel(); |
| 134 } else if (isHTMLOptGroupElement(*element)) { | 141 } else if (isHTMLOptGroupElement(*element)) { |
| 135 text = toHTMLOptGroupElement(*element).groupLabelText(); | 142 text = toHTMLOptGroupElement(*element).groupLabelText(); |
| 136 FontDescription d = itemFont.fontDescription(); | 143 FontDescription d = itemFont.fontDescription(); |
| 137 d.setWeight(d.bolderWeight()); | 144 d.setWeight(d.bolderWeight()); |
| 138 itemFont = Font(d); | 145 itemFont = Font(d); |
| 139 itemFont.update(document().styleEngine()->fontSelector()); | 146 itemFont.update(document().styleEngine()->fontSelector()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 scrollToRevealSelection(); | 202 scrollToRevealSelection(); |
| 196 } | 203 } |
| 197 } | 204 } |
| 198 | 205 |
| 199 void RenderListBox::scrollToRevealSelection() | 206 void RenderListBox::scrollToRevealSelection() |
| 200 { | 207 { |
| 201 HTMLSelectElement* select = selectElement(); | 208 HTMLSelectElement* select = selectElement(); |
| 202 | 209 |
| 203 m_scrollToRevealSelectionAfterLayout = false; | 210 m_scrollToRevealSelectionAfterLayout = false; |
| 204 | 211 |
| 205 int firstIndex = select->activeSelectionStartListIndex(); | 212 int firstIndex = toRenderListBoxIndex(select->activeSelectionStartListIndex( )); |
| 206 if (firstIndex >= 0 && !listIndexIsVisible(select->activeSelectionEndListInd ex())) | 213 int lastIndex = toRenderListBoxIndex(select->activeSelectionEndListIndex()); |
| 214 if (firstIndex >= 0 && !listIndexIsVisible(lastIndex)) | |
| 207 scrollToRevealElementAtListIndex(firstIndex); | 215 scrollToRevealElementAtListIndex(firstIndex); |
| 208 } | 216 } |
| 209 | 217 |
| 210 void RenderListBox::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, L ayoutUnit& maxLogicalWidth) const | 218 void RenderListBox::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, L ayoutUnit& maxLogicalWidth) const |
| 211 { | 219 { |
| 212 maxLogicalWidth = m_optionsWidth + 2 * optionsSpacingHorizontal; | 220 maxLogicalWidth = m_optionsWidth + 2 * optionsSpacingHorizontal; |
| 213 if (m_vBar) | 221 if (m_vBar) |
| 214 maxLogicalWidth += verticalScrollbarWidth(); | 222 maxLogicalWidth += verticalScrollbarWidth(); |
| 215 if (!style()->width().isPercent()) | 223 if (!style()->width().isPercent()) |
| 216 minLogicalWidth = maxLogicalWidth; | 224 minLogicalWidth = maxLogicalWidth; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 } | 263 } |
| 256 | 264 |
| 257 int RenderListBox::numVisibleItems() const | 265 int RenderListBox::numVisibleItems() const |
| 258 { | 266 { |
| 259 // Only count fully visible rows. But don't return 0 even if only part of a row shows. | 267 // Only count fully visible rows. But don't return 0 even if only part of a row shows. |
| 260 return max<int>(1, (contentHeight() + rowSpacing) / itemHeight()); | 268 return max<int>(1, (contentHeight() + rowSpacing) / itemHeight()); |
| 261 } | 269 } |
| 262 | 270 |
| 263 int RenderListBox::numItems() const | 271 int RenderListBox::numItems() const |
| 264 { | 272 { |
| 265 return selectElement()->listItems().size(); | 273 return m_listItemCount; |
| 266 } | 274 } |
| 267 | 275 |
| 268 LayoutUnit RenderListBox::listHeight() const | 276 LayoutUnit RenderListBox::listHeight() const |
| 269 { | 277 { |
| 270 return itemHeight() * numItems() - rowSpacing; | 278 return itemHeight() * numItems() - rowSpacing; |
| 271 } | 279 } |
| 272 | 280 |
| 273 void RenderListBox::computeLogicalHeight(LayoutUnit, LayoutUnit logicalTop, Logi calExtentComputedValues& computedValues) const | 281 void RenderListBox::computeLogicalHeight(LayoutUnit, LayoutUnit logicalTop, Logi calExtentComputedValues& computedValues) const |
| 274 { | 282 { |
| 275 LayoutUnit height = itemHeight() * size() - rowSpacing + borderAndPaddingHei ght(); | 283 LayoutUnit height = itemHeight() * size() - rowSpacing + borderAndPaddingHei ght(); |
| 276 RenderBox::computeLogicalHeight(height, logicalTop, computedValues); | 284 RenderBox::computeLogicalHeight(height, logicalTop, computedValues); |
| 277 } | 285 } |
| 278 | 286 |
| 279 int RenderListBox::baselinePosition(FontBaseline baselineType, bool firstLine, L ineDirectionMode lineDirection, LinePositionMode linePositionMode) const | 287 int RenderListBox::baselinePosition(FontBaseline baselineType, bool firstLine, L ineDirectionMode lineDirection, LinePositionMode linePositionMode) const |
| 280 { | 288 { |
| 281 return RenderBox::baselinePosition(baselineType, firstLine, lineDirection, l inePositionMode) - baselineAdjustment; | 289 return RenderBox::baselinePosition(baselineType, firstLine, lineDirection, l inePositionMode) - baselineAdjustment; |
| 282 } | 290 } |
| 283 | 291 |
| 284 LayoutRect RenderListBox::itemBoundingBoxRect(const LayoutPoint& additionalOffse t, int index) | 292 LayoutRect RenderListBox::itemBoundingBoxRect(const LayoutPoint& additionalOffse t, int index) const |
| 285 { | 293 { |
| 286 // For RTL, items start after the left-side vertical scrollbar. | 294 // For RTL, items start after the left-side vertical scrollbar. |
| 287 int scrollbarOffset = style()->shouldPlaceBlockDirectionScrollbarOnLogicalLe ft() ? verticalScrollbarWidth() : 0; | 295 int scrollbarOffset = style()->shouldPlaceBlockDirectionScrollbarOnLogicalLe ft() ? verticalScrollbarWidth() : 0; |
| 288 return LayoutRect(additionalOffset.x() + borderLeft() + paddingLeft() + scro llbarOffset, | 296 return LayoutRect(additionalOffset.x() + borderLeft() + paddingLeft() + scro llbarOffset, |
| 289 additionalOffset.y() + borderTop() + paddingTop() + itemHeight() * (inde x - m_indexOffset), | 297 additionalOffset.y() + borderTop() + paddingTop() + itemHeight() * (inde x - m_indexOffset), |
| 290 contentWidth(), itemHeight()); | 298 contentWidth(), itemHeight()); |
| 291 } | 299 } |
| 292 | 300 |
| 293 void RenderListBox::paintObject(PaintInfo& paintInfo, const LayoutPoint& paintOf fset) | 301 void RenderListBox::paintObject(PaintInfo& paintInfo, const LayoutPoint& paintOf fset) |
| 294 { | 302 { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 int selectedItem = select->activeSelectionEndListIndex(); | 352 int selectedItem = select->activeSelectionEndListIndex(); |
| 345 if (selectedItem >= 0) { | 353 if (selectedItem >= 0) { |
| 346 rects.append(pixelSnappedIntRect(itemBoundingBoxRect(additionalOffset, s electedItem))); | 354 rects.append(pixelSnappedIntRect(itemBoundingBoxRect(additionalOffset, s electedItem))); |
| 347 return; | 355 return; |
| 348 } | 356 } |
| 349 | 357 |
| 350 // No selected items, find the first non-disabled item. | 358 // No selected items, find the first non-disabled item. |
| 351 int size = numItems(); | 359 int size = numItems(); |
| 352 const Vector<HTMLElement*>& listItems = select->listItems(); | 360 const Vector<HTMLElement*>& listItems = select->listItems(); |
| 353 for (int i = 0; i < size; ++i) { | 361 for (int i = 0; i < size; ++i) { |
| 354 HTMLElement* element = listItems[i]; | 362 HTMLElement* element = listItems[toOptionListIndex(i)]; |
| 355 if (isHTMLOptionElement(*element) && !element->isDisabledFormControl()) { | 363 if (isHTMLOptionElement(*element) && !element->isDisabledFormControl()) { |
| 356 rects.append(pixelSnappedIntRect(itemBoundingBoxRect(additionalOffse t, i))); | 364 rects.append(pixelSnappedIntRect(itemBoundingBoxRect(additionalOffse t, i))); |
| 357 return; | 365 return; |
| 358 } | 366 } |
| 359 } | 367 } |
| 360 } | 368 } |
| 361 | 369 |
| 362 int RenderListBox::scrollbarLeft() const | 370 int RenderListBox::scrollbarLeft() const |
| 363 { | 371 { |
| 364 int scrollbarLeft = 0; | 372 int scrollbarLeft = 0; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 return offset; | 409 return offset; |
| 402 } | 410 } |
| 403 | 411 |
| 404 void RenderListBox::paintItemForeground(PaintInfo& paintInfo, const LayoutPoint& paintOffset, int listIndex) | 412 void RenderListBox::paintItemForeground(PaintInfo& paintInfo, const LayoutPoint& paintOffset, int listIndex) |
| 405 { | 413 { |
| 406 FontCachePurgePreventer fontCachePurgePreventer; | 414 FontCachePurgePreventer fontCachePurgePreventer; |
| 407 | 415 |
| 408 HTMLSelectElement* select = selectElement(); | 416 HTMLSelectElement* select = selectElement(); |
| 409 | 417 |
| 410 const Vector<HTMLElement*>& listItems = select->listItems(); | 418 const Vector<HTMLElement*>& listItems = select->listItems(); |
| 411 HTMLElement* element = listItems[listIndex]; | 419 HTMLElement* element = listItems[toOptionListIndex(listIndex)]; |
| 412 | 420 |
| 413 RenderStyle* itemStyle = element->renderStyle(); | 421 RenderStyle* itemStyle = element->renderStyle(); |
| 414 if (!itemStyle) | 422 if (!itemStyle) |
| 415 itemStyle = style(); | 423 itemStyle = style(); |
| 416 | 424 |
| 417 if (itemStyle->visibility() == HIDDEN) | 425 if (itemStyle->visibility() == HIDDEN) |
| 418 return; | 426 return; |
| 419 | 427 |
| 420 String itemText; | 428 String itemText; |
| 421 bool isOptionElement = isHTMLOptionElement(*element); | 429 bool isOptionElement = isHTMLOptionElement(*element); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 450 | 458 |
| 451 // Draw the item text | 459 // Draw the item text |
| 452 TextRunPaintInfo textRunPaintInfo(textRun); | 460 TextRunPaintInfo textRunPaintInfo(textRun); |
| 453 textRunPaintInfo.bounds = r; | 461 textRunPaintInfo.bounds = r; |
| 454 paintInfo.context->drawBidiText(itemFont, textRunPaintInfo, roundedIntPoint( r.location())); | 462 paintInfo.context->drawBidiText(itemFont, textRunPaintInfo, roundedIntPoint( r.location())); |
| 455 } | 463 } |
| 456 | 464 |
| 457 void RenderListBox::paintItemBackground(PaintInfo& paintInfo, const LayoutPoint& paintOffset, int listIndex) | 465 void RenderListBox::paintItemBackground(PaintInfo& paintInfo, const LayoutPoint& paintOffset, int listIndex) |
| 458 { | 466 { |
| 459 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 467 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); |
| 460 HTMLElement* element = listItems[listIndex]; | 468 HTMLElement* element = listItems[toOptionListIndex(listIndex)]; |
| 461 | 469 |
| 462 Color backColor; | 470 Color backColor; |
| 463 if (isHTMLOptionElement(*element) && ((toHTMLOptionElement(*element).selecte d() && selectElement()->suggestedIndex() < 0) || listIndex == selectElement()->s uggestedIndex())) { | 471 if (isHTMLOptionElement(*element) && ((toHTMLOptionElement(*element).selecte d() && selectElement()->suggestedIndex() < 0) || listIndex == selectElement()->s uggestedIndex())) { |
| 464 if (frame()->selection().isFocusedAndActive() && document().focusedEleme nt() == node()) | 472 if (frame()->selection().isFocusedAndActive() && document().focusedEleme nt() == node()) |
| 465 backColor = RenderTheme::theme().activeListBoxSelectionBackgroundCol or(); | 473 backColor = RenderTheme::theme().activeListBoxSelectionBackgroundCol or(); |
| 466 else | 474 else |
| 467 backColor = RenderTheme::theme().inactiveListBoxSelectionBackgroundC olor(); | 475 backColor = RenderTheme::theme().inactiveListBoxSelectionBackgroundC olor(); |
| 468 } else { | 476 } else { |
| 469 backColor = element->renderStyle() ? resolveColor(element->renderStyle() , CSSPropertyBackgroundColor) : resolveColor(CSSPropertyBackgroundColor); | 477 backColor = element->renderStyle() ? resolveColor(element->renderStyle() , CSSPropertyBackgroundColor) : resolveColor(CSSPropertyBackgroundColor); |
| 470 } | 478 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 487 verticalScrollbarWidth(), | 495 verticalScrollbarWidth(), |
| 488 height() - borderTop() - borderBottom()); | 496 height() - borderTop() - borderBottom()); |
| 489 | 497 |
| 490 if (vertRect.contains(locationInContainer)) { | 498 if (vertRect.contains(locationInContainer)) { |
| 491 result.setScrollbar(m_vBar.get()); | 499 result.setScrollbar(m_vBar.get()); |
| 492 return true; | 500 return true; |
| 493 } | 501 } |
| 494 return false; | 502 return false; |
| 495 } | 503 } |
| 496 | 504 |
| 497 int RenderListBox::listIndexAtOffset(const LayoutSize& offset) | 505 int RenderListBox::listIndexAtOffset(const LayoutSize& offset) const |
| 498 { | 506 { |
| 499 if (!numItems()) | 507 if (!numItems()) |
| 500 return -1; | 508 return -1; |
| 501 | 509 |
| 502 if (offset.height() < borderTop() + paddingTop() || offset.height() > height () - paddingBottom() - borderBottom()) | 510 if (offset.height() < borderTop() + paddingTop() || offset.height() > height () - paddingBottom() - borderBottom()) |
| 503 return -1; | 511 return -1; |
| 504 | 512 |
| 505 int scrollbarWidth = verticalScrollbarWidth(); | 513 int scrollbarWidth = verticalScrollbarWidth(); |
| 506 int rightScrollbarOffset = style()->shouldPlaceBlockDirectionScrollbarOnLogi calLeft() ? scrollbarWidth : 0; | 514 int rightScrollbarOffset = style()->shouldPlaceBlockDirectionScrollbarOnLogi calLeft() ? scrollbarWidth : 0; |
| 507 int leftScrollbarOffset = style()->shouldPlaceBlockDirectionScrollbarOnLogic alLeft() ? 0 : scrollbarWidth; | 515 int leftScrollbarOffset = style()->shouldPlaceBlockDirectionScrollbarOnLogic alLeft() ? 0 : scrollbarWidth; |
| 508 if (offset.width() < borderLeft() + paddingLeft() + rightScrollbarOffset | 516 if (offset.width() < borderLeft() + paddingLeft() + rightScrollbarOffset |
| 509 || offset.width() > width() - borderRight() - paddingRight() - leftScrol lbarOffset) | 517 || offset.width() > width() - borderRight() - paddingRight() - leftScrol lbarOffset) |
| 510 return -1; | 518 return -1; |
| 511 | 519 |
| 512 int newOffset = (offset.height() - borderTop() - paddingTop()) / itemHeight( ) + m_indexOffset; | 520 int newOffset = (offset.height() - borderTop() - paddingTop()) / itemHeight( ) + m_indexOffset; |
| 513 return newOffset < numItems() ? newOffset : -1; | 521 return newOffset < numItems() ? toOptionListIndex(newOffset) : -1; |
| 514 } | 522 } |
| 515 | 523 |
| 516 void RenderListBox::panScroll(const IntPoint& panStartMousePosition) | 524 void RenderListBox::panScroll(const IntPoint& panStartMousePosition) |
| 517 { | 525 { |
| 518 const int maxSpeed = 20; | 526 const int maxSpeed = 20; |
| 519 const int iconRadius = 7; | 527 const int iconRadius = 7; |
| 520 const int speedReducer = 4; | 528 const int speedReducer = 4; |
| 521 | 529 |
| 522 // FIXME: This doesn't work correctly with transforms. | 530 // FIXME: This doesn't work correctly with transforms. |
| 523 FloatPoint absOffset = localToAbsolute(); | 531 FloatPoint absOffset = localToAbsolute(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 | 590 |
| 583 int endIndex = scrollToward(pos); | 591 int endIndex = scrollToward(pos); |
| 584 if (selectElement()->isDisabledFormControl()) | 592 if (selectElement()->isDisabledFormControl()) |
| 585 return; | 593 return; |
| 586 | 594 |
| 587 if (endIndex >= 0) { | 595 if (endIndex >= 0) { |
| 588 HTMLSelectElement* select = selectElement(); | 596 HTMLSelectElement* select = selectElement(); |
| 589 m_inAutoscroll = true; | 597 m_inAutoscroll = true; |
| 590 | 598 |
| 591 if (!select->multiple()) | 599 if (!select->multiple()) |
| 592 select->setActiveSelectionAnchorIndex(endIndex); | 600 select->setActiveSelectionAnchorIndex(toOptionListIndex(endIndex)); |
| 593 | 601 |
| 594 select->setActiveSelectionEndIndex(endIndex); | 602 select->setActiveSelectionEndIndex(toOptionListIndex(endIndex)); |
| 595 select->updateListBoxSelection(!select->multiple()); | 603 select->updateListBoxSelection(!select->multiple()); |
| 596 m_inAutoscroll = false; | 604 m_inAutoscroll = false; |
| 597 } | 605 } |
| 598 } | 606 } |
| 599 | 607 |
| 600 void RenderListBox::stopAutoscroll() | 608 void RenderListBox::stopAutoscroll() |
| 601 { | 609 { |
| 602 if (selectElement()->isDisabledFormControl()) | 610 if (selectElement()->isDisabledFormControl()) |
| 603 return; | 611 return; |
| 604 | 612 |
| 605 selectElement()->listBoxOnChange(); | 613 selectElement()->listBoxOnChange(); |
| 606 } | 614 } |
| 607 | 615 |
| 608 bool RenderListBox::scrollToRevealElementAtListIndex(int index) | 616 bool RenderListBox::scrollToRevealElementAtListIndex(int index) |
| 609 { | 617 { |
| 610 if (index < 0 || index >= numItems() || listIndexIsVisible(index)) | 618 if (index < 0 || index >= numItems() || listIndexIsVisible(index)) |
| 611 return false; | 619 return false; |
| 612 | 620 |
| 613 int newOffset; | 621 int newOffset; |
| 614 if (index < m_indexOffset) | 622 if (index < m_indexOffset) |
| 615 newOffset = index; | 623 newOffset = index; |
| 616 else | 624 else |
| 617 newOffset = index - numVisibleItems() + 1; | 625 newOffset = index - numVisibleItems() + 1; |
| 618 | 626 |
| 619 scrollToOffsetWithoutAnimation(VerticalScrollbar, newOffset); | 627 scrollToOffsetWithoutAnimation(VerticalScrollbar, newOffset); |
| 620 | 628 |
| 621 return true; | 629 return true; |
| 622 } | 630 } |
| 623 | 631 |
| 624 bool RenderListBox::listIndexIsVisible(int index) | 632 bool RenderListBox::listIndexIsVisible(int index) const |
| 625 { | 633 { |
| 626 return index >= m_indexOffset && index < m_indexOffset + numVisibleItems(); | 634 return index >= m_indexOffset && index < m_indexOffset + numVisibleItems(); |
| 627 } | 635 } |
| 628 | 636 |
| 629 bool RenderListBox::scroll(ScrollDirection direction, ScrollGranularity granular ity, float multiplier) | 637 bool RenderListBox::scroll(ScrollDirection direction, ScrollGranularity granular ity, float multiplier) |
| 630 { | 638 { |
| 631 return ScrollableArea::scroll(direction, granularity, multiplier); | 639 return ScrollableArea::scroll(direction, granularity, multiplier); |
| 632 } | 640 } |
| 633 | 641 |
| 634 int RenderListBox::scrollSize(ScrollbarOrientation orientation) const | 642 int RenderListBox::scrollSize(ScrollbarOrientation orientation) const |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 711 bool RenderListBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& re sult, const HitTestLocation& locationInContainer, const LayoutPoint& accumulated Offset, HitTestAction hitTestAction) | 719 bool RenderListBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& re sult, const HitTestLocation& locationInContainer, const LayoutPoint& accumulated Offset, HitTestAction hitTestAction) |
| 712 { | 720 { |
| 713 if (!RenderBlockFlow::nodeAtPoint(request, result, locationInContainer, accu mulatedOffset, hitTestAction)) | 721 if (!RenderBlockFlow::nodeAtPoint(request, result, locationInContainer, accu mulatedOffset, hitTestAction)) |
| 714 return false; | 722 return false; |
| 715 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 723 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); |
| 716 int size = numItems(); | 724 int size = numItems(); |
| 717 LayoutPoint adjustedLocation = accumulatedOffset + location(); | 725 LayoutPoint adjustedLocation = accumulatedOffset + location(); |
| 718 | 726 |
| 719 for (int i = 0; i < size; ++i) { | 727 for (int i = 0; i < size; ++i) { |
| 720 if (itemBoundingBoxRect(adjustedLocation, i).contains(locationInContaine r.point())) { | 728 if (itemBoundingBoxRect(adjustedLocation, i).contains(locationInContaine r.point())) { |
| 721 if (Element* node = listItems[i]) { | 729 if (Element* node = listItems[toOptionListIndex(i)]) { |
| 722 result.setInnerNode(node); | 730 result.setInnerNode(node); |
| 723 if (!result.innerNonSharedNode()) | 731 if (!result.innerNonSharedNode()) |
| 724 result.setInnerNonSharedNode(node); | 732 result.setInnerNonSharedNode(node); |
| 725 result.setLocalPoint(locationInContainer.point() - toLayoutSize( adjustedLocation)); | 733 result.setLocalPoint(locationInContainer.point() - toLayoutSize( adjustedLocation)); |
| 726 break; | 734 break; |
| 727 } | 735 } |
| 728 } | 736 } |
| 729 } | 737 } |
| 730 | 738 |
| 731 return true; | 739 return true; |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 942 destroyScrollbar(); | 950 destroyScrollbar(); |
| 943 | 951 |
| 944 if (m_vBar) | 952 if (m_vBar) |
| 945 m_vBar->styleChanged(); | 953 m_vBar->styleChanged(); |
| 946 | 954 |
| 947 // Force an update since we know the scrollbars have changed things. | 955 // Force an update since we know the scrollbars have changed things. |
| 948 if (document().hasAnnotatedRegions()) | 956 if (document().hasAnnotatedRegions()) |
| 949 document().setAnnotatedRegionsDirty(true); | 957 document().setAnnotatedRegionsDirty(true); |
| 950 } | 958 } |
| 951 | 959 |
| 960 int RenderListBox::toOptionListIndex(int index) const | |
|
keishi
2014/04/11 06:40:13
We have lots of indexes so it would be great if we
spartha
2014/04/11 11:19:45
Done.
| |
| 961 { | |
| 962 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | |
| 963 const int size = static_cast<int>(listItems.size()); | |
| 964 | |
| 965 if (size == numItems()) | |
| 966 return index; | |
| 967 | |
| 968 int rendererIndex = 0; | |
| 969 int i = 0; | |
| 970 for (; i < size; ++i) { | |
| 971 HTMLElement* element = listItems[i]; | |
| 972 RenderStyle* listItemStyle = element->renderStyle(); | |
| 973 if (listItemStyle && listItemStyle->display() == NONE) | |
| 974 continue; | |
| 975 if (index == rendererIndex) | |
| 976 break; | |
| 977 ++rendererIndex; | |
| 978 } | |
| 979 return i; | |
| 980 } | |
| 981 | |
| 982 int RenderListBox::toRenderListBoxIndex(int index) const | |
| 983 { | |
| 984 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | |
| 985 const int size = static_cast<int>(listItems.size()); | |
| 986 | |
| 987 if (size == numItems()) | |
| 988 return index; | |
| 989 | |
| 990 int realIndex = 0; | |
| 991 for (int i = 0; i < size; ++i) { | |
| 992 HTMLElement* element = listItems[i]; | |
| 993 RenderStyle* listItemStyle = element->renderStyle(); | |
| 994 if (listItemStyle && listItemStyle->display() == NONE) | |
| 995 continue; | |
| 996 if (index == i) | |
| 997 break; | |
| 998 ++realIndex; | |
| 999 } | |
| 1000 return realIndex; | |
| 1001 } | |
| 1002 | |
| 952 } // namespace WebCore | 1003 } // namespace WebCore |
| OLD | NEW |