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

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

Issue 23819007: Have Node::document() return a reference instead of a pointer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 3 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
OLDNEW
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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 HTMLElement* element = listItems[i]; 121 HTMLElement* element = listItems[i];
122 String text; 122 String text;
123 Font itemFont = style()->font(); 123 Font itemFont = style()->font();
124 if (element->hasTagName(optionTag)) { 124 if (element->hasTagName(optionTag)) {
125 text = toHTMLOptionElement(element)->textIndentedToRespectGroupL abel(); 125 text = toHTMLOptionElement(element)->textIndentedToRespectGroupL abel();
126 } else if (isHTMLOptGroupElement(element)) { 126 } else if (isHTMLOptGroupElement(element)) {
127 text = toHTMLOptGroupElement(element)->groupLabelText(); 127 text = toHTMLOptGroupElement(element)->groupLabelText();
128 FontDescription d = itemFont.fontDescription(); 128 FontDescription d = itemFont.fontDescription();
129 d.setWeight(d.bolderWeight()); 129 d.setWeight(d.bolderWeight());
130 itemFont = Font(d, itemFont.letterSpacing(), itemFont.wordSpacin g()); 130 itemFont = Font(d, itemFont.letterSpacing(), itemFont.wordSpacin g());
131 itemFont.update(document()->styleResolver()->fontSelector()); 131 itemFont.update(document().styleResolver()->fontSelector());
132 } 132 }
133 133
134 if (!text.isEmpty()) { 134 if (!text.isEmpty()) {
135 applyTextTransform(style(), text, ' '); 135 applyTextTransform(style(), text, ' ');
136 // FIXME: Why is this always LTR? Can't text direction affect th e width? 136 // FIXME: Why is this always LTR? Can't text direction affect th e width?
137 TextRun textRun = constructTextRun(this, itemFont, text, style() , TextRun::AllowTrailingExpansion); 137 TextRun textRun = constructTextRun(this, itemFont, text, style() , TextRun::AllowTrailingExpansion);
138 textRun.disableRoundingHacks(); 138 textRun.disableRoundingHacks();
139 float textWidth = itemFont.width(textRun); 139 float textWidth = itemFont.width(textRun);
140 width = max(width, textWidth); 140 width = max(width, textWidth);
141 } 141 }
(...skipping 15 matching lines...) Expand all
157 void RenderListBox::selectionChanged() 157 void RenderListBox::selectionChanged()
158 { 158 {
159 repaint(); 159 repaint();
160 if (!m_inAutoscroll) { 160 if (!m_inAutoscroll) {
161 if (m_optionsChanged || needsLayout()) 161 if (m_optionsChanged || needsLayout())
162 m_scrollToRevealSelectionAfterLayout = true; 162 m_scrollToRevealSelectionAfterLayout = true;
163 else 163 else
164 scrollToRevealSelection(); 164 scrollToRevealSelection();
165 } 165 }
166 166
167 if (AXObjectCache* cache = document()->existingAXObjectCache()) 167 if (AXObjectCache* cache = document().existingAXObjectCache())
168 cache->selectedChildrenChanged(this); 168 cache->selectedChildrenChanged(this);
169 } 169 }
170 170
171 void RenderListBox::layout() 171 void RenderListBox::layout()
172 { 172 {
173 RenderBlock::layout(); 173 RenderBlock::layout();
174 174
175 if (m_vBar) { 175 if (m_vBar) {
176 bool enabled = numVisibleItems() < numItems(); 176 bool enabled = numVisibleItems() < numItems();
177 m_vBar->setEnabled(enabled); 177 m_vBar->setEnabled(enabled);
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 String itemText; 400 String itemText;
401 bool isOptionElement = element->hasTagName(optionTag); 401 bool isOptionElement = element->hasTagName(optionTag);
402 if (isOptionElement) 402 if (isOptionElement)
403 itemText = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel (); 403 itemText = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel ();
404 else if (isHTMLOptGroupElement(element)) 404 else if (isHTMLOptGroupElement(element))
405 itemText = toHTMLOptGroupElement(element)->groupLabelText(); 405 itemText = toHTMLOptGroupElement(element)->groupLabelText();
406 applyTextTransform(style(), itemText, ' '); 406 applyTextTransform(style(), itemText, ' ');
407 407
408 Color textColor = element->renderStyle() ? resolveColor(element->renderStyle (), CSSPropertyColor) : resolveColor(CSSPropertyColor); 408 Color textColor = element->renderStyle() ? resolveColor(element->renderStyle (), CSSPropertyColor) : resolveColor(CSSPropertyColor);
409 if (isOptionElement && toHTMLOptionElement(element)->selected()) { 409 if (isOptionElement && toHTMLOptionElement(element)->selected()) {
410 if (frame()->selection()->isFocusedAndActive() && document()->focusedEle ment() == node()) 410 if (frame()->selection()->isFocusedAndActive() && document().focusedElem ent() == node())
411 textColor = RenderTheme::theme().activeListBoxSelectionForegroundCol or(); 411 textColor = RenderTheme::theme().activeListBoxSelectionForegroundCol or();
412 // Honor the foreground color for disabled items 412 // Honor the foreground color for disabled items
413 else if (!element->isDisabledFormControl() && !select->isDisabledFormCon trol()) 413 else if (!element->isDisabledFormControl() && !select->isDisabledFormCon trol())
414 textColor = RenderTheme::theme().inactiveListBoxSelectionForegroundC olor(); 414 textColor = RenderTheme::theme().inactiveListBoxSelectionForegroundC olor();
415 } 415 }
416 416
417 paintInfo.context->setFillColor(textColor); 417 paintInfo.context->setFillColor(textColor);
418 418
419 TextRun textRun(itemText, 0, 0, TextRun::AllowTrailingExpansion, itemStyle-> direction(), isOverride(itemStyle->unicodeBidi()), true, TextRun::NoRounding); 419 TextRun textRun(itemText, 0, 0, TextRun::AllowTrailingExpansion, itemStyle-> direction(), isOverride(itemStyle->unicodeBidi()), true, TextRun::NoRounding);
420 Font itemFont = style()->font(); 420 Font itemFont = style()->font();
421 LayoutRect r = itemBoundingBoxRect(paintOffset, listIndex); 421 LayoutRect r = itemBoundingBoxRect(paintOffset, listIndex);
422 r.move(itemOffsetForAlignment(textRun, itemStyle, itemFont, r)); 422 r.move(itemOffsetForAlignment(textRun, itemStyle, itemFont, r));
423 423
424 if (isHTMLOptGroupElement(element)) { 424 if (isHTMLOptGroupElement(element)) {
425 FontDescription d = itemFont.fontDescription(); 425 FontDescription d = itemFont.fontDescription();
426 d.setWeight(d.bolderWeight()); 426 d.setWeight(d.bolderWeight());
427 itemFont = Font(d, itemFont.letterSpacing(), itemFont.wordSpacing()); 427 itemFont = Font(d, itemFont.letterSpacing(), itemFont.wordSpacing());
428 itemFont.update(document()->styleResolver()->fontSelector()); 428 itemFont.update(document().styleResolver()->fontSelector());
429 } 429 }
430 430
431 // Draw the item text 431 // Draw the item text
432 TextRunPaintInfo textRunPaintInfo(textRun); 432 TextRunPaintInfo textRunPaintInfo(textRun);
433 textRunPaintInfo.bounds = r; 433 textRunPaintInfo.bounds = r;
434 paintInfo.context->drawBidiText(itemFont, textRunPaintInfo, roundedIntPoint( r.location())); 434 paintInfo.context->drawBidiText(itemFont, textRunPaintInfo, roundedIntPoint( r.location()));
435 } 435 }
436 436
437 void RenderListBox::paintItemBackground(PaintInfo& paintInfo, const LayoutPoint& paintOffset, int listIndex) 437 void RenderListBox::paintItemBackground(PaintInfo& paintInfo, const LayoutPoint& paintOffset, int listIndex)
438 { 438 {
439 const Vector<HTMLElement*>& listItems = selectElement()->listItems(); 439 const Vector<HTMLElement*>& listItems = selectElement()->listItems();
440 HTMLElement* element = listItems[listIndex]; 440 HTMLElement* element = listItems[listIndex];
441 441
442 Color backColor; 442 Color backColor;
443 if (element->hasTagName(optionTag) && toHTMLOptionElement(element)->selected ()) { 443 if (element->hasTagName(optionTag) && toHTMLOptionElement(element)->selected ()) {
444 if (frame()->selection()->isFocusedAndActive() && document()->focusedEle ment() == node()) 444 if (frame()->selection()->isFocusedAndActive() && document().focusedElem ent() == node())
445 backColor = RenderTheme::theme().activeListBoxSelectionBackgroundCol or(); 445 backColor = RenderTheme::theme().activeListBoxSelectionBackgroundCol or();
446 else 446 else
447 backColor = RenderTheme::theme().inactiveListBoxSelectionBackgroundC olor(); 447 backColor = RenderTheme::theme().inactiveListBoxSelectionBackgroundC olor();
448 } else { 448 } else {
449 backColor = element->renderStyle() ? resolveColor(element->renderStyle() , CSSPropertyBackgroundColor) : resolveColor(CSSPropertyBackgroundColor); 449 backColor = element->renderStyle() ? resolveColor(element->renderStyle() , CSSPropertyBackgroundColor) : resolveColor(CSSPropertyBackgroundColor);
450 } 450 }
451 451
452 // Draw the background for this list box item 452 // Draw the background for this list box item
453 if (!element->renderStyle() || element->renderStyle()->visibility() != HIDDE N) { 453 if (!element->renderStyle() || element->renderStyle()->visibility() != HIDDE N) {
454 LayoutRect itemRect = itemBoundingBoxRect(paintOffset, listIndex); 454 LayoutRect itemRect = itemBoundingBoxRect(paintOffset, listIndex);
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 scrollTo(offset.y()); 631 scrollTo(offset.y());
632 } 632 }
633 633
634 void RenderListBox::scrollTo(int newOffset) 634 void RenderListBox::scrollTo(int newOffset)
635 { 635 {
636 if (newOffset == m_indexOffset) 636 if (newOffset == m_indexOffset)
637 return; 637 return;
638 638
639 m_indexOffset = newOffset; 639 m_indexOffset = newOffset;
640 repaint(); 640 repaint();
641 node()->document()->eventQueue()->enqueueOrDispatchScrollEvent(node(), Docum entEventQueue::ScrollEventElementTarget); 641 node()->document().eventQueue()->enqueueOrDispatchScrollEvent(node(), Docume ntEventQueue::ScrollEventElementTarget);
642 } 642 }
643 643
644 LayoutUnit RenderListBox::itemHeight() const 644 LayoutUnit RenderListBox::itemHeight() const
645 { 645 {
646 return style()->fontMetrics().height() + rowSpacing; 646 return style()->fontMetrics().height() + rowSpacing;
647 } 647 }
648 648
649 int RenderListBox::verticalScrollbarWidth() const 649 int RenderListBox::verticalScrollbarWidth() const
650 { 650 {
651 return m_vBar && !m_vBar->isOverlayScrollbar() ? m_vBar->width() : 0; 651 return m_vBar && !m_vBar->isOverlayScrollbar() ? m_vBar->width() : 0;
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 PassRefPtr<Scrollbar> RenderListBox::createScrollbar() 872 PassRefPtr<Scrollbar> RenderListBox::createScrollbar()
873 { 873 {
874 RefPtr<Scrollbar> widget; 874 RefPtr<Scrollbar> widget;
875 bool hasCustomScrollbarStyle = style()->hasPseudoStyle(SCROLLBAR); 875 bool hasCustomScrollbarStyle = style()->hasPseudoStyle(SCROLLBAR);
876 if (hasCustomScrollbarStyle) 876 if (hasCustomScrollbarStyle)
877 widget = RenderScrollbar::createCustomScrollbar(this, VerticalScrollbar, this->node()); 877 widget = RenderScrollbar::createCustomScrollbar(this, VerticalScrollbar, this->node());
878 else { 878 else {
879 widget = Scrollbar::createNativeScrollbar(this, VerticalScrollbar, Rende rTheme::theme().scrollbarControlSizeForPart(ListboxPart)); 879 widget = Scrollbar::createNativeScrollbar(this, VerticalScrollbar, Rende rTheme::theme().scrollbarControlSizeForPart(ListboxPart));
880 didAddVerticalScrollbar(widget.get()); 880 didAddVerticalScrollbar(widget.get());
881 } 881 }
882 document()->view()->addChild(widget.get()); 882 document().view()->addChild(widget.get());
883 return widget.release(); 883 return widget.release();
884 } 884 }
885 885
886 void RenderListBox::destroyScrollbar() 886 void RenderListBox::destroyScrollbar()
887 { 887 {
888 if (!m_vBar) 888 if (!m_vBar)
889 return; 889 return;
890 890
891 if (!m_vBar->isCustomScrollbar()) 891 if (!m_vBar->isCustomScrollbar())
892 ScrollableArea::willRemoveVerticalScrollbar(m_vBar.get()); 892 ScrollableArea::willRemoveVerticalScrollbar(m_vBar.get());
893 m_vBar->removeFromParent(); 893 m_vBar->removeFromParent();
894 m_vBar->disconnectFromScrollableArea(); 894 m_vBar->disconnectFromScrollableArea();
895 m_vBar = 0; 895 m_vBar = 0;
896 } 896 }
897 897
898 void RenderListBox::setHasVerticalScrollbar(bool hasScrollbar) 898 void RenderListBox::setHasVerticalScrollbar(bool hasScrollbar)
899 { 899 {
900 if (hasScrollbar == (m_vBar != 0)) 900 if (hasScrollbar == (m_vBar != 0))
901 return; 901 return;
902 902
903 if (hasScrollbar) 903 if (hasScrollbar)
904 m_vBar = createScrollbar(); 904 m_vBar = createScrollbar();
905 else 905 else
906 destroyScrollbar(); 906 destroyScrollbar();
907 907
908 if (m_vBar) 908 if (m_vBar)
909 m_vBar->styleChanged(); 909 m_vBar->styleChanged();
910 910
911 // Force an update since we know the scrollbars have changed things. 911 // Force an update since we know the scrollbars have changed things.
912 if (document()->hasAnnotatedRegions()) 912 if (document().hasAnnotatedRegions())
913 document()->setAnnotatedRegionsDirty(true); 913 document().setAnnotatedRegionsDirty(true);
914 } 914 }
915 915
916 } // namespace WebCore 916 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderLayerFilterInfo.cpp ('k') | Source/core/rendering/RenderListItem.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698