OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011, Google Inc. All rights reserved. | 2 * Copyright (c) 2011, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 | 720 |
721 layout(); | 721 layout(); |
722 } | 722 } |
723 | 723 |
724 void PopupListBox::setMaxWidthAndLayout(int maxWidth) | 724 void PopupListBox::setMaxWidthAndLayout(int maxWidth) |
725 { | 725 { |
726 m_maxWindowWidth = maxWidth; | 726 m_maxWindowWidth = maxWidth; |
727 layout(); | 727 layout(); |
728 } | 728 } |
729 | 729 |
| 730 int PopupListBox::getRowBaseWidth(int index) |
| 731 { |
| 732 Font font = getRowFont(index); |
| 733 PopupMenuStyle style = m_popupClient->itemStyle(index); |
| 734 String text = m_popupClient->itemText(index); |
| 735 if (text.isEmpty()) |
| 736 return 0; |
| 737 TextRun textRun(text, 0, 0, TextRun::AllowTrailingExpansion, style.textDirec
tion(), style.hasTextDirectionOverride()); |
| 738 return font.width(textRun); |
| 739 } |
| 740 |
730 void PopupListBox::layout() | 741 void PopupListBox::layout() |
731 { | 742 { |
732 bool isRightAligned = m_popupClient->menuStyle().textDirection() == RTL; | 743 bool isRightAligned = m_popupClient->menuStyle().textDirection() == RTL; |
733 | 744 |
734 // Size our child items. | 745 // Size our child items. |
735 int baseWidth = 0; | 746 int baseWidth = 0; |
736 int paddingWidth = 0; | 747 int paddingWidth = 0; |
737 int lineEndPaddingWidth = 0; | 748 int lineEndPaddingWidth = 0; |
738 int y = 0; | 749 int y = 0; |
739 for (int i = 0; i < numItems(); ++i) { | 750 for (int i = 0; i < numItems(); ++i) { |
740 // Place the item vertically. | 751 // Place the item vertically. |
741 m_items[i]->yOffset = y; | 752 m_items[i]->yOffset = y; |
742 if (m_popupClient->itemStyle(i).isDisplayNone()) | 753 if (m_popupClient->itemStyle(i).isDisplayNone()) |
743 continue; | 754 continue; |
744 y += getRowHeight(i); | 755 y += getRowHeight(i); |
745 | 756 |
746 // Ensure the popup is wide enough to fit this item. | 757 // Ensure the popup is wide enough to fit this item. |
747 Font itemFont = getRowFont(i); | 758 baseWidth = max(baseWidth, getRowBaseWidth(i)); |
748 String text = m_popupClient->itemText(i); | |
749 int width = 0; | |
750 if (!text.isEmpty()) | |
751 width = itemFont.width(TextRun(text)); | |
752 | |
753 baseWidth = max(baseWidth, width); | |
754 // FIXME: http://b/1210481 We should get the padding of individual | 759 // FIXME: http://b/1210481 We should get the padding of individual |
755 // option elements. | 760 // option elements. |
756 paddingWidth = max<int>(paddingWidth, | 761 paddingWidth = max<int>(paddingWidth, |
757 m_popupClient->clientPaddingLeft() + m_popupClient->clientPaddingRig
ht()); | 762 m_popupClient->clientPaddingLeft() + m_popupClient->clientPaddingRig
ht()); |
758 lineEndPaddingWidth = max<int>(lineEndPaddingWidth, | 763 lineEndPaddingWidth = max<int>(lineEndPaddingWidth, |
759 isRightAligned ? m_popupClient->clientPaddingLeft() : m_popupClient-
>clientPaddingRight()); | 764 isRightAligned ? m_popupClient->clientPaddingLeft() : m_popupClient-
>clientPaddingRight()); |
760 } | 765 } |
761 | 766 |
762 // Calculate scroll bar width. | 767 // Calculate scroll bar width. |
763 int windowHeight = 0; | 768 int windowHeight = 0; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 { | 829 { |
825 return numItems() && IntRect(0, 0, width(), height()).contains(point); | 830 return numItems() && IntRect(0, 0, width(), height()).contains(point); |
826 } | 831 } |
827 | 832 |
828 int PopupListBox::popupContentHeight() const | 833 int PopupListBox::popupContentHeight() const |
829 { | 834 { |
830 return height(); | 835 return height(); |
831 } | 836 } |
832 | 837 |
833 } // namespace blink | 838 } // namespace blink |
OLD | NEW |