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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 98 } |
99 | 99 |
100 RenderListBox::~RenderListBox() | 100 RenderListBox::~RenderListBox() |
101 { | 101 { |
102 setHasVerticalScrollbar(false); | 102 setHasVerticalScrollbar(false); |
103 | 103 |
104 if (FrameView* frameView = frame()->view()) | 104 if (FrameView* frameView = frame()->view()) |
105 frameView->removeScrollableArea(this); | 105 frameView->removeScrollableArea(this); |
106 } | 106 } |
107 | 107 |
108 inline HTMLSelectElement* RenderListBox::selectElement() const | 108 inline Result<HTMLSelectElement> RenderListBox::selectElement() const |
109 { | 109 { |
110 return toHTMLSelectElement(node()); | 110 return toHTMLSelectElement(node()); |
111 } | 111 } |
112 | 112 |
113 void RenderListBox::updateFromElement() | 113 void RenderListBox::updateFromElement() |
114 { | 114 { |
115 FontCachePurgePreventer fontCachePurgePreventer; | 115 FontCachePurgePreventer fontCachePurgePreventer; |
116 | 116 |
117 if (m_optionsChanged) { | 117 if (m_optionsChanged) { |
118 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); | 118 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } | 187 } |
188 | 188 |
189 if (m_scrollToRevealSelectionAfterLayout) { | 189 if (m_scrollToRevealSelectionAfterLayout) { |
190 LayoutStateDisabler layoutStateDisabler(view()); | 190 LayoutStateDisabler layoutStateDisabler(view()); |
191 scrollToRevealSelection(); | 191 scrollToRevealSelection(); |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
195 void RenderListBox::scrollToRevealSelection() | 195 void RenderListBox::scrollToRevealSelection() |
196 { | 196 { |
197 HTMLSelectElement* select = selectElement(); | 197 Handle<HTMLSelectElement> select = selectElement(); |
198 | 198 |
199 m_scrollToRevealSelectionAfterLayout = false; | 199 m_scrollToRevealSelectionAfterLayout = false; |
200 | 200 |
201 int firstIndex = select->activeSelectionStartListIndex(); | 201 int firstIndex = select->activeSelectionStartListIndex(); |
202 if (firstIndex >= 0 && !listIndexIsVisible(select->activeSelectionEndListInd
ex())) | 202 if (firstIndex >= 0 && !listIndexIsVisible(select->activeSelectionEndListInd
ex())) |
203 scrollToRevealElementAtListIndex(firstIndex); | 203 scrollToRevealElementAtListIndex(firstIndex); |
204 } | 204 } |
205 | 205 |
206 void RenderListBox::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, L
ayoutUnit& maxLogicalWidth) const | 206 void RenderListBox::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, L
ayoutUnit& maxLogicalWidth) const |
207 { | 207 { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 default: | 325 default: |
326 break; | 326 break; |
327 } | 327 } |
328 } | 328 } |
329 | 329 |
330 void RenderListBox::addFocusRingRects(Vector<IntRect>& rects, const LayoutPoint&
additionalOffset, const RenderLayerModelObject* paintContainer) | 330 void RenderListBox::addFocusRingRects(Vector<IntRect>& rects, const LayoutPoint&
additionalOffset, const RenderLayerModelObject* paintContainer) |
331 { | 331 { |
332 if (!isSpatialNavigationEnabled(frame())) | 332 if (!isSpatialNavigationEnabled(frame())) |
333 return RenderBlock::addFocusRingRects(rects, additionalOffset, paintCont
ainer); | 333 return RenderBlock::addFocusRingRects(rects, additionalOffset, paintCont
ainer); |
334 | 334 |
335 HTMLSelectElement* select = selectElement(); | 335 Handle<HTMLSelectElement> select = selectElement(); |
336 | 336 |
337 // Focus the last selected item. | 337 // Focus the last selected item. |
338 int selectedItem = select->activeSelectionEndListIndex(); | 338 int selectedItem = select->activeSelectionEndListIndex(); |
339 if (selectedItem >= 0) { | 339 if (selectedItem >= 0) { |
340 rects.append(pixelSnappedIntRect(itemBoundingBoxRect(additionalOffset, s
electedItem))); | 340 rects.append(pixelSnappedIntRect(itemBoundingBoxRect(additionalOffset, s
electedItem))); |
341 return; | 341 return; |
342 } | 342 } |
343 | 343 |
344 // No selected items, find the first non-disabled item. | 344 // No selected items, find the first non-disabled item. |
345 int size = numItems(); | 345 int size = numItems(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 offset.setWidth((itemBoudingBox.width() - textWidth) / 2); | 382 offset.setWidth((itemBoudingBox.width() - textWidth) / 2); |
383 } else | 383 } else |
384 offset.setWidth(optionsSpacingHorizontal); | 384 offset.setWidth(optionsSpacingHorizontal); |
385 return offset; | 385 return offset; |
386 } | 386 } |
387 | 387 |
388 void RenderListBox::paintItemForeground(PaintInfo& paintInfo, const LayoutPoint&
paintOffset, int listIndex) | 388 void RenderListBox::paintItemForeground(PaintInfo& paintInfo, const LayoutPoint&
paintOffset, int listIndex) |
389 { | 389 { |
390 FontCachePurgePreventer fontCachePurgePreventer; | 390 FontCachePurgePreventer fontCachePurgePreventer; |
391 | 391 |
392 HTMLSelectElement* select = selectElement(); | 392 Handle<HTMLSelectElement> select = selectElement(); |
393 | 393 |
394 const Vector<HTMLElement*>& listItems = select->listItems(); | 394 const Vector<HTMLElement*>& listItems = select->listItems(); |
395 HTMLElement* element = listItems[listIndex]; | 395 HTMLElement* element = listItems[listIndex]; |
396 | 396 |
397 RenderStyle* itemStyle = element->renderStyle(); | 397 RenderStyle* itemStyle = element->renderStyle(); |
398 if (!itemStyle) | 398 if (!itemStyle) |
399 itemStyle = style(); | 399 itemStyle = style(); |
400 | 400 |
401 if (itemStyle->visibility() == HIDDEN) | 401 if (itemStyle->visibility() == HIDDEN) |
402 return; | 402 return; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 // Let's attenuate the speed | 527 // Let's attenuate the speed |
528 yDelta /= speedReducer; | 528 yDelta /= speedReducer; |
529 | 529 |
530 IntPoint scrollPoint(0, 0); | 530 IntPoint scrollPoint(0, 0); |
531 scrollPoint.setY(absOffset.y() + yDelta); | 531 scrollPoint.setY(absOffset.y() + yDelta); |
532 int newOffset = scrollToward(scrollPoint); | 532 int newOffset = scrollToward(scrollPoint); |
533 if (newOffset < 0) | 533 if (newOffset < 0) |
534 return; | 534 return; |
535 | 535 |
536 m_inAutoscroll = true; | 536 m_inAutoscroll = true; |
537 HTMLSelectElement* select = selectElement(); | 537 Handle<HTMLSelectElement> select = selectElement(); |
538 select->updateListBoxSelection(!select->multiple()); | 538 select->updateListBoxSelection(!select->multiple()); |
539 m_inAutoscroll = false; | 539 m_inAutoscroll = false; |
540 } | 540 } |
541 | 541 |
542 int RenderListBox::scrollToward(const IntPoint& destination) | 542 int RenderListBox::scrollToward(const IntPoint& destination) |
543 { | 543 { |
544 // FIXME: This doesn't work correctly with transforms. | 544 // FIXME: This doesn't work correctly with transforms. |
545 FloatPoint absPos = localToAbsolute(); | 545 FloatPoint absPos = localToAbsolute(); |
546 IntSize positionOffset = roundedIntSize(destination - absPos); | 546 IntSize positionOffset = roundedIntSize(destination - absPos); |
547 | 547 |
548 int rows = numVisibleItems(); | 548 int rows = numVisibleItems(); |
549 int offset = m_indexOffset; | 549 int offset = m_indexOffset; |
550 | 550 |
551 if (positionOffset.height() < borderTop() + paddingTop() && scrollToRevealEl
ementAtListIndex(offset - 1)) | 551 if (positionOffset.height() < borderTop() + paddingTop() && scrollToRevealEl
ementAtListIndex(offset - 1)) |
552 return offset - 1; | 552 return offset - 1; |
553 | 553 |
554 if (positionOffset.height() > height() - paddingBottom() - borderBottom() &&
scrollToRevealElementAtListIndex(offset + rows)) | 554 if (positionOffset.height() > height() - paddingBottom() - borderBottom() &&
scrollToRevealElementAtListIndex(offset + rows)) |
555 return offset + rows - 1; | 555 return offset + rows - 1; |
556 | 556 |
557 return listIndexAtOffset(positionOffset); | 557 return listIndexAtOffset(positionOffset); |
558 } | 558 } |
559 | 559 |
560 void RenderListBox::autoscroll(const IntPoint&) | 560 void RenderListBox::autoscroll(const IntPoint&) |
561 { | 561 { |
562 IntPoint pos = frame()->view()->windowToContents(frame()->eventHandler()->la
stKnownMousePosition()); | 562 IntPoint pos = frame()->view()->windowToContents(frame()->eventHandler()->la
stKnownMousePosition()); |
563 | 563 |
564 int endIndex = scrollToward(pos); | 564 int endIndex = scrollToward(pos); |
565 if (endIndex >= 0) { | 565 if (endIndex >= 0) { |
566 HTMLSelectElement* select = selectElement(); | 566 Handle<HTMLSelectElement> select = selectElement(); |
567 m_inAutoscroll = true; | 567 m_inAutoscroll = true; |
568 | 568 |
569 if (!select->multiple()) | 569 if (!select->multiple()) |
570 select->setActiveSelectionAnchorIndex(endIndex); | 570 select->setActiveSelectionAnchorIndex(endIndex); |
571 | 571 |
572 select->setActiveSelectionEndIndex(endIndex); | 572 select->setActiveSelectionEndIndex(endIndex); |
573 select->updateListBoxSelection(!select->multiple()); | 573 select->updateListBoxSelection(!select->multiple()); |
574 m_inAutoscroll = false; | 574 m_inAutoscroll = false; |
575 } | 575 } |
576 } | 576 } |
(...skipping 29 matching lines...) Expand all Loading... |
606 return ScrollableArea::scroll(direction, granularity, multiplier); | 606 return ScrollableArea::scroll(direction, granularity, multiplier); |
607 } | 607 } |
608 | 608 |
609 bool RenderListBox::logicalScroll(ScrollLogicalDirection direction, ScrollGranul
arity granularity, float multiplier, Node**) | 609 bool RenderListBox::logicalScroll(ScrollLogicalDirection direction, ScrollGranul
arity granularity, float multiplier, Node**) |
610 { | 610 { |
611 return ScrollableArea::scroll(logicalToPhysical(direction, style()->isHorizo
ntalWritingMode(), style()->isFlippedBlocksWritingMode()), granularity, multipli
er); | 611 return ScrollableArea::scroll(logicalToPhysical(direction, style()->isHorizo
ntalWritingMode(), style()->isFlippedBlocksWritingMode()), granularity, multipli
er); |
612 } | 612 } |
613 | 613 |
614 void RenderListBox::valueChanged(unsigned listIndex) | 614 void RenderListBox::valueChanged(unsigned listIndex) |
615 { | 615 { |
616 HTMLSelectElement* element = selectElement(); | 616 Handle<HTMLSelectElement> element = selectElement(); |
617 element->setSelectedIndex(element->listToOptionIndex(listIndex)); | 617 element->setSelectedIndex(element->listToOptionIndex(listIndex)); |
618 element->dispatchFormControlChangeEvent(); | 618 element->dispatchFormControlChangeEvent(); |
619 } | 619 } |
620 | 620 |
621 int RenderListBox::scrollSize(ScrollbarOrientation orientation) const | 621 int RenderListBox::scrollSize(ScrollbarOrientation orientation) const |
622 { | 622 { |
623 return ((orientation == VerticalScrollbar) && m_vBar) ? (m_vBar->totalSize()
- m_vBar->visibleSize()) : 0; | 623 return ((orientation == VerticalScrollbar) && m_vBar) ? (m_vBar->totalSize()
- m_vBar->visibleSize()) : 0; |
624 } | 624 } |
625 | 625 |
626 int RenderListBox::scrollPosition(Scrollbar*) const | 626 int RenderListBox::scrollPosition(Scrollbar*) const |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 | 879 |
880 if (m_vBar) | 880 if (m_vBar) |
881 m_vBar->styleChanged(); | 881 m_vBar->styleChanged(); |
882 | 882 |
883 // Force an update since we know the scrollbars have changed things. | 883 // Force an update since we know the scrollbars have changed things. |
884 if (document()->hasAnnotatedRegions()) | 884 if (document()->hasAnnotatedRegions()) |
885 document()->setAnnotatedRegionsDirty(true); | 885 document()->setAnnotatedRegionsDirty(true); |
886 } | 886 } |
887 | 887 |
888 } // namespace WebCore | 888 } // namespace WebCore |
OLD | NEW |