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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #include "core/rendering/RenderScrollbar.h" | 51 #include "core/rendering/RenderScrollbar.h" |
52 #include "core/rendering/RenderText.h" | 52 #include "core/rendering/RenderText.h" |
53 #include "core/rendering/RenderTheme.h" | 53 #include "core/rendering/RenderTheme.h" |
54 #include "core/rendering/RenderView.h" | 54 #include "core/rendering/RenderView.h" |
55 #include "platform/fonts/FontCache.h" | 55 #include "platform/fonts/FontCache.h" |
56 #include "platform/graphics/GraphicsContext.h" | 56 #include "platform/graphics/GraphicsContext.h" |
57 #include "platform/scroll/Scrollbar.h" | 57 #include "platform/scroll/Scrollbar.h" |
58 #include "platform/text/BidiTextRun.h" | 58 #include "platform/text/BidiTextRun.h" |
59 #include <math.h> | 59 #include <math.h> |
60 | 60 |
61 using namespace std; | |
62 | |
63 namespace WebCore { | 61 namespace WebCore { |
64 | 62 |
65 using namespace HTMLNames; | 63 using namespace HTMLNames; |
66 | 64 |
67 const int rowSpacing = 1; | 65 const int rowSpacing = 1; |
68 | 66 |
69 const int optionsSpacingHorizontal = 2; | 67 const int optionsSpacingHorizontal = 2; |
70 | 68 |
71 // The minSize constant was originally defined to render scrollbars correctly. | 69 // The minSize constant was originally defined to render scrollbars correctly. |
72 // This might vary for different platforms. | 70 // This might vary for different platforms. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 if (!text.isEmpty()) { | 152 if (!text.isEmpty()) { |
155 applyTextTransform(style(), text, ' '); | 153 applyTextTransform(style(), text, ' '); |
156 | 154 |
157 bool hasStrongDirectionality; | 155 bool hasStrongDirectionality; |
158 TextDirection direction = determineDirectionality(text, hasStron
gDirectionality); | 156 TextDirection direction = determineDirectionality(text, hasStron
gDirectionality); |
159 TextRun textRun = constructTextRun(this, itemFont, text, style()
, TextRun::AllowTrailingExpansion); | 157 TextRun textRun = constructTextRun(this, itemFont, text, style()
, TextRun::AllowTrailingExpansion); |
160 if (hasStrongDirectionality) | 158 if (hasStrongDirectionality) |
161 textRun.setDirection(direction); | 159 textRun.setDirection(direction); |
162 textRun.disableRoundingHacks(); | 160 textRun.disableRoundingHacks(); |
163 float textWidth = itemFont.width(textRun); | 161 float textWidth = itemFont.width(textRun); |
164 width = max(width, textWidth); | 162 width = std::max(width, textWidth); |
165 } | 163 } |
166 } | 164 } |
167 m_optionsWidth = static_cast<int>(ceilf(width)); | 165 m_optionsWidth = static_cast<int>(ceilf(width)); |
168 m_optionsChanged = false; | 166 m_optionsChanged = false; |
169 | 167 |
170 setHasVerticalScrollbar(true); | 168 setHasVerticalScrollbar(true); |
171 | 169 |
172 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(); | 170 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(); |
173 } | 171 } |
174 } | 172 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 m_minPreferredLogicalWidth = 0; | 237 m_minPreferredLogicalWidth = 0; |
240 m_maxPreferredLogicalWidth = 0; | 238 m_maxPreferredLogicalWidth = 0; |
241 RenderStyle* styleToUse = style(); | 239 RenderStyle* styleToUse = style(); |
242 | 240 |
243 if (styleToUse->width().isFixed() && styleToUse->width().value() > 0) | 241 if (styleToUse->width().isFixed() && styleToUse->width().value() > 0) |
244 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentB
oxLogicalWidthForBoxSizing(styleToUse->width().value()); | 242 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentB
oxLogicalWidthForBoxSizing(styleToUse->width().value()); |
245 else | 243 else |
246 computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferred
LogicalWidth); | 244 computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferred
LogicalWidth); |
247 | 245 |
248 if (styleToUse->minWidth().isFixed() && styleToUse->minWidth().value() > 0)
{ | 246 if (styleToUse->minWidth().isFixed() && styleToUse->minWidth().value() > 0)
{ |
249 m_maxPreferredLogicalWidth = max(m_maxPreferredLogicalWidth, adjustConte
ntBoxLogicalWidthForBoxSizing(styleToUse->minWidth().value())); | 247 m_maxPreferredLogicalWidth = std::max(m_maxPreferredLogicalWidth, adjust
ContentBoxLogicalWidthForBoxSizing(styleToUse->minWidth().value())); |
250 m_minPreferredLogicalWidth = max(m_minPreferredLogicalWidth, adjustConte
ntBoxLogicalWidthForBoxSizing(styleToUse->minWidth().value())); | 248 m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, adjust
ContentBoxLogicalWidthForBoxSizing(styleToUse->minWidth().value())); |
251 } | 249 } |
252 | 250 |
253 if (styleToUse->maxWidth().isFixed()) { | 251 if (styleToUse->maxWidth().isFixed()) { |
254 m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, adjustConte
ntBoxLogicalWidthForBoxSizing(styleToUse->maxWidth().value())); | 252 m_maxPreferredLogicalWidth = std::min(m_maxPreferredLogicalWidth, adjust
ContentBoxLogicalWidthForBoxSizing(styleToUse->maxWidth().value())); |
255 m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, adjustConte
ntBoxLogicalWidthForBoxSizing(styleToUse->maxWidth().value())); | 253 m_minPreferredLogicalWidth = std::min(m_minPreferredLogicalWidth, adjust
ContentBoxLogicalWidthForBoxSizing(styleToUse->maxWidth().value())); |
256 } | 254 } |
257 | 255 |
258 LayoutUnit toAdd = borderAndPaddingWidth(); | 256 LayoutUnit toAdd = borderAndPaddingWidth(); |
259 m_minPreferredLogicalWidth += toAdd; | 257 m_minPreferredLogicalWidth += toAdd; |
260 m_maxPreferredLogicalWidth += toAdd; | 258 m_maxPreferredLogicalWidth += toAdd; |
261 | 259 |
262 clearPreferredLogicalWidthsDirty(); | 260 clearPreferredLogicalWidthsDirty(); |
263 } | 261 } |
264 | 262 |
265 int RenderListBox::size() const | 263 int RenderListBox::size() const |
266 { | 264 { |
267 int specifiedSize = selectElement()->size(); | 265 int specifiedSize = selectElement()->size(); |
268 if (specifiedSize > 1) | 266 if (specifiedSize > 1) |
269 return max(minSize, specifiedSize); | 267 return std::max(minSize, specifiedSize); |
270 | 268 |
271 return defaultSize; | 269 return defaultSize; |
272 } | 270 } |
273 | 271 |
274 int RenderListBox::numVisibleItems() const | 272 int RenderListBox::numVisibleItems() const |
275 { | 273 { |
276 // Only count fully visible rows. But don't return 0 even if only part of a
row shows. | 274 // Only count fully visible rows. But don't return 0 even if only part of a
row shows. |
277 return max<int>(1, (contentHeight() + rowSpacing) / itemHeight()); | 275 return std::max<int>(1, (contentHeight() + rowSpacing) / itemHeight()); |
278 } | 276 } |
279 | 277 |
280 int RenderListBox::numItems() const | 278 int RenderListBox::numItems() const |
281 { | 279 { |
282 return m_listItemCount; | 280 return m_listItemCount; |
283 } | 281 } |
284 | 282 |
285 LayoutUnit RenderListBox::listHeight() const | 283 LayoutUnit RenderListBox::listHeight() const |
286 { | 284 { |
287 return itemHeight() * numItems() - rowSpacing; | 285 return itemHeight() * numItems() - rowSpacing; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 // We need to check if the last known mouse position is out of the window. W
hen the mouse is out of the window, the position is incoherent | 546 // We need to check if the last known mouse position is out of the window. W
hen the mouse is out of the window, the position is incoherent |
549 static IntPoint previousMousePosition; | 547 static IntPoint previousMousePosition; |
550 if (lastKnownMousePosition.y() < 0) | 548 if (lastKnownMousePosition.y() < 0) |
551 lastKnownMousePosition = previousMousePosition; | 549 lastKnownMousePosition = previousMousePosition; |
552 else | 550 else |
553 previousMousePosition = lastKnownMousePosition; | 551 previousMousePosition = lastKnownMousePosition; |
554 | 552 |
555 int yDelta = lastKnownMousePosition.y() - panStartMousePosition.y(); | 553 int yDelta = lastKnownMousePosition.y() - panStartMousePosition.y(); |
556 | 554 |
557 // If the point is too far from the center we limit the speed | 555 // If the point is too far from the center we limit the speed |
558 yDelta = max<int>(min<int>(yDelta, maxSpeed), -maxSpeed); | 556 yDelta = std::max<int>(std::min<int>(yDelta, maxSpeed), -maxSpeed); |
559 | 557 |
560 if (abs(yDelta) < iconRadius) // at the center we let the space for the icon | 558 if (abs(yDelta) < iconRadius) // at the center we let the space for the icon |
561 return; | 559 return; |
562 | 560 |
563 if (yDelta > 0) | 561 if (yDelta > 0) |
564 absOffset.move(0, listHeight().toFloat()); | 562 absOffset.move(0, listHeight().toFloat()); |
565 else if (yDelta < 0) | 563 else if (yDelta < 0) |
566 yDelta--; | 564 yDelta--; |
567 | 565 |
568 // Let's attenuate the speed | 566 // Let's attenuate the speed |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 // FIXME: We ignore padding in the vertical direction as far as these values are
concerned, since that's | 694 // FIXME: We ignore padding in the vertical direction as far as these values are
concerned, since that's |
697 // how the control currently paints. | 695 // how the control currently paints. |
698 LayoutUnit RenderListBox::scrollWidth() const | 696 LayoutUnit RenderListBox::scrollWidth() const |
699 { | 697 { |
700 // There is no horizontal scrolling allowed. | 698 // There is no horizontal scrolling allowed. |
701 return clientWidth(); | 699 return clientWidth(); |
702 } | 700 } |
703 | 701 |
704 LayoutUnit RenderListBox::scrollHeight() const | 702 LayoutUnit RenderListBox::scrollHeight() const |
705 { | 703 { |
706 return max(clientHeight(), listHeight()); | 704 return std::max(clientHeight(), listHeight()); |
707 } | 705 } |
708 | 706 |
709 LayoutUnit RenderListBox::scrollLeft() const | 707 LayoutUnit RenderListBox::scrollLeft() const |
710 { | 708 { |
711 return 0; | 709 return 0; |
712 } | 710 } |
713 | 711 |
714 void RenderListBox::setScrollLeft(LayoutUnit) | 712 void RenderListBox::setScrollLeft(LayoutUnit) |
715 { | 713 { |
716 } | 714 } |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 return false; | 905 return false; |
908 } | 906 } |
909 | 907 |
910 int RenderListBox::lineStep(ScrollbarOrientation) const | 908 int RenderListBox::lineStep(ScrollbarOrientation) const |
911 { | 909 { |
912 return 1; | 910 return 1; |
913 } | 911 } |
914 | 912 |
915 int RenderListBox::pageStep(ScrollbarOrientation orientation) const | 913 int RenderListBox::pageStep(ScrollbarOrientation orientation) const |
916 { | 914 { |
917 return max(1, numVisibleItems() - 1); | 915 return std::max(1, numVisibleItems() - 1); |
918 } | 916 } |
919 | 917 |
920 float RenderListBox::pixelStep(ScrollbarOrientation) const | 918 float RenderListBox::pixelStep(ScrollbarOrientation) const |
921 { | 919 { |
922 return 1.0f / itemHeight(); | 920 return 1.0f / itemHeight(); |
923 } | 921 } |
924 | 922 |
925 IntRect RenderListBox::scrollableAreaBoundingBox() const | 923 IntRect RenderListBox::scrollableAreaBoundingBox() const |
926 { | 924 { |
927 return absoluteBoundingBoxRect(); | 925 return absoluteBoundingBoxRect(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 { | 1018 { |
1021 return itemBoundingBoxRectInternal(point, listIndexToRenderListBoxIndex(inde
x)); | 1019 return itemBoundingBoxRectInternal(point, listIndexToRenderListBoxIndex(inde
x)); |
1022 } | 1020 } |
1023 | 1021 |
1024 bool RenderListBox::scrollToRevealElementAtListIndex(int index) | 1022 bool RenderListBox::scrollToRevealElementAtListIndex(int index) |
1025 { | 1023 { |
1026 return scrollToRevealElementAtListIndexInternal(listIndexToRenderListBoxInde
x(index)); | 1024 return scrollToRevealElementAtListIndexInternal(listIndexToRenderListBoxInde
x(index)); |
1027 } | 1025 } |
1028 | 1026 |
1029 } // namespace WebCore | 1027 } // namespace WebCore |
OLD | NEW |