Changeset 63179 in webkit
- Timestamp:
- Jul 12, 2010 11:41:09 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r63176 r63179 1 2010-07-12 Jay Civelli <jcivelli@chromium.org> 2 3 Reviewed by Kent Tamura. 4 5 Adding right aligned text called labels to PopupMenus. 6 https://bugs.webkit.org/show_bug.cgi?id=41964 7 8 * platform/PopupMenuClient.h: 9 * platform/chromium/PopupMenuChromium.cpp: 10 (WebCore::PopupListBox::paintRow): 11 * rendering/RenderMenuList.cpp: 12 (WebCore::RenderMenuList::itemLabel): 13 * rendering/RenderMenuList.h: 14 * rendering/RenderTextControlSingleLine.cpp: 15 (WebCore::RenderTextControlSingleLine::itemLabel): 16 * rendering/RenderTextControlSingleLine.h: 17 1 18 2010-07-12 Mihnea Ovidenea <mihnea@adobe.com> 2 19 -
trunk/WebCore/platform/PopupMenuClient.h
r60514 r63179 43 43 44 44 virtual String itemText(unsigned listIndex) const = 0; 45 virtual String itemLabel(unsigned listIndex) const = 0; 45 46 virtual String itemToolTip(unsigned listIndex) const = 0; 46 47 virtual String itemAccessibilityText(unsigned listIndex) const = 0; -
trunk/WebCore/platform/chromium/PopupMenuChromium.cpp
r61941 r63179 71 71 static const int kMaxHeight = 500; 72 72 static const int kBorderSize = 1; 73 static const int kTextToLabelPadding = 10; 73 74 static const TimeStamp kTypeAheadTimeoutMs = 1000; 74 75 … … 918 919 // Prepare text to be drawn. 919 920 String itemText = m_popupClient->itemText(rowIndex); 920 if (m_settings.restrictWidthOfListBox) // truncate string to fit in. 921 itemText = StringTruncator::rightTruncate(itemText, maxWidth, itemFont); 922 unsigned length = itemText.length(); 923 const UChar* str = itemText.characters(); 921 String itemLabel = m_popupClient->itemLabel(rowIndex); 922 if (m_settings.restrictWidthOfListBox) { // Truncate strings to fit in. 923 // FIXME: We should leftTruncate for the rtl case. 924 // StringTruncator::leftTruncate would have to be implemented. 925 String str = StringTruncator::rightTruncate(itemText, maxWidth, itemFont); 926 if (str != itemText) { 927 itemText = str; 928 // Don't display the label, we already don't have enough room for the 929 // item text. 930 itemLabel = ""; 931 } else if (!itemLabel.isEmpty()) { 932 int availableWidth = maxWidth - kTextToLabelPadding - 933 StringTruncator::width(itemText, itemFont); 934 itemLabel = StringTruncator::rightTruncate(itemLabel, availableWidth, itemFont); 935 } 936 } 937 924 938 // Prepare the directionality to draw text. 925 939 bool rtl = false; … … 929 943 PopupContainerSettings::FirstStrongDirectionalCharacterDirection) 930 944 rtl = itemText.defaultWritingDirection() == WTF::Unicode::RightToLeft; 931 TextRun textRun( str, length, false, 0, 0, rtl);945 TextRun textRun(itemText.characters(), itemText.length(), false, 0, 0, rtl); 932 946 // If the text is right-to-left, make it right-aligned by adjusting its 933 947 // beginning position. 934 948 if (rightAligned) 935 949 textX += maxWidth - itemFont.width(textRun); 950 936 951 // Draw the item text. 937 952 int textY = rowRect.y() + itemFont.ascent() + (rowRect.height() - itemFont.height()) / 2; 938 953 gc->drawBidiText(itemFont, textRun, IntPoint(textX, textY)); 954 955 // Draw the the label if applicable. 956 if (itemLabel.isEmpty()) 957 return; 958 TextRun labelTextRun(itemLabel.characters(), itemLabel.length(), false, 0, 0, rtl); 959 if (rightAligned) 960 textX = max(0, m_popupClient->clientPaddingLeft() - m_popupClient->clientInsetLeft()); 961 else { 962 // We are using the left padding as the right padding includes room for the scroll-bar which 963 // does not show in this case. 964 int rightPadding = max(0, m_popupClient->clientPaddingLeft() - m_popupClient->clientInsetLeft()); 965 textX = rowRect.width() - rightPadding - itemFont.width(labelTextRun); 966 } 967 968 // FIXME: for now the label color is hard-coded. It should be added to the 969 // PopupMenuStyle. 970 gc->setFillColor(Color(115, 115, 115), DeviceColorSpace); 971 gc->drawBidiText(itemFont, labelTextRun, IntPoint(textX, textY)); 939 972 } 940 973 -
trunk/WebCore/rendering/RenderMenuList.cpp
r61487 r63179 351 351 } 352 352 353 String RenderMenuList::itemLabel(unsigned) const 354 { 355 return String(); 356 } 357 353 358 String RenderMenuList::itemAccessibilityText(unsigned listIndex) const 354 359 { -
trunk/WebCore/rendering/RenderMenuList.h
r60514 r63179 83 83 // PopupMenuClient methods 84 84 virtual String itemText(unsigned listIndex) const; 85 virtual String itemLabel(unsigned listIndex) const; 85 86 virtual String itemToolTip(unsigned listIndex) const; 86 87 virtual String itemAccessibilityText(unsigned listIndex) const; -
trunk/WebCore/rendering/RenderTextControlSingleLine.cpp
r62249 r63179 877 877 } 878 878 879 String RenderTextControlSingleLine::itemLabel(unsigned) const 880 { 881 return String(); 882 } 883 879 884 bool RenderTextControlSingleLine::itemIsEnabled(unsigned listIndex) const 880 885 { -
trunk/WebCore/rendering/RenderTextControlSingleLine.h
r61752 r63179 116 116 virtual void selectionCleared() {} 117 117 virtual String itemText(unsigned listIndex) const; 118 virtual String itemLabel(unsigned listIndex) const; 118 119 virtual String itemToolTip(unsigned) const { return String(); } 119 120 virtual String itemAccessibilityText(unsigned) const { return String(); } -
trunk/WebKit/chromium/ChangeLog
r63173 r63179 1 2010-07-12 Jay Civelli <jcivelli@chromium.org> 2 3 Reviewed by Kent Tamura. 4 5 Making the autofill popup use labels to show the label 6 associated with an item. 7 https://bugs.webkit.org/show_bug.cgi?id=41964 8 9 * src/AutoFillPopupMenuClient.cpp: 10 (WebKit::AutoFillPopupMenuClient::getSuggestion): 11 (WebKit::AutoFillPopupMenuClient::getLabel): 12 (WebKit::AutoFillPopupMenuClient::itemLabel): 13 (WebKit::AutoFillPopupMenuClient::setSuggestions): 14 (WebKit::AutoFillPopupMenuClient::convertListIndexToInternalIndex): 15 * src/AutoFillPopupMenuClient.h: 16 1 17 2010-07-12 Sheriff Bot <webkit.review.bot@gmail.com> 2 18 -
trunk/WebKit/chromium/src/AutoFillPopupMenuClient.cpp
r62272 r63179 67 67 WebString AutoFillPopupMenuClient::getSuggestion(unsigned listIndex) const 68 68 { 69 if (listIndex == static_cast<unsigned>(m_separatorIndex)) 69 int index = convertListIndexToInternalIndex(listIndex); 70 if (index == -1) 70 71 return WebString(); 71 72 72 if (m_separatorIndex != -1 && listIndex > static_cast<unsigned>(m_separatorIndex)) 73 --listIndex; 74 75 // FIXME: Modify the PopupMenu to add the label in gray right-justified. 76 ASSERT(listIndex < m_names.size()); 77 78 WebString suggestion = m_names[listIndex]; 79 if (m_labels[listIndex].isEmpty()) 80 return suggestion; 81 82 return suggestion + String(" (") + m_labels[listIndex] + String(")"); 73 ASSERT(index < m_names.size()); 74 return m_names[index]; 75 } 76 77 WebString AutoFillPopupMenuClient::getLabel(unsigned listIndex) const 78 { 79 int index = convertListIndexToInternalIndex(listIndex); 80 if (index == -1) 81 return WebString(); 82 83 ASSERT(index < m_labels.size()); 84 return m_labels[index]; 83 85 } 84 86 … … 151 153 } 152 154 155 String AutoFillPopupMenuClient::itemLabel(unsigned listIndex) const 156 { 157 return getLabel(listIndex); 158 } 159 153 160 PopupMenuStyle AutoFillPopupMenuClient::itemStyle(unsigned listIndex) const 154 161 { … … 269 276 if (getSelectedIndex() >= static_cast<int>(names.size())) 270 277 setSelectedIndex(-1); 278 } 279 280 int AutoFillPopupMenuClient::convertListIndexToInternalIndex(unsigned listIndex) const 281 { 282 if (listIndex == static_cast<unsigned>(m_separatorIndex)) 283 return -1; 284 285 if (m_separatorIndex == -1 || listIndex < static_cast<unsigned>(m_separatorIndex)) 286 return listIndex; 287 return listIndex - 1; 271 288 } 272 289 -
trunk/WebKit/chromium/src/AutoFillPopupMenuClient.h
r62272 r63179 58 58 virtual WebString getSuggestion(unsigned listIndex) const; 59 59 60 // Returns the label at |listIndex|. 61 virtual WebString getLabel(unsigned listIndex) const; 62 60 63 // Removes the suggestion at |listIndex| from the list of suggestions. 61 64 virtual void removeSuggestionAtIndex(unsigned listIndex); … … 66 69 virtual void selectionCleared(); 67 70 virtual WebCore::String itemText(unsigned listIndex) const; 71 virtual WebCore::String itemLabel(unsigned listIndex) const; 68 72 virtual WebCore::String itemToolTip(unsigned lastIndex) const { return WebCore::String(); } 69 73 virtual WebCore::String itemAccessibilityText(unsigned lastIndex) const { return WebCore::String(); } … … 105 109 106 110 private: 111 // Convert the specified index from an index into the visible list (which might 112 // include a separator entry) to an index to |m_names| and |m_labels|. 113 // Returns -1 if the given index points to the separator. 114 int convertListIndexToInternalIndex(unsigned) const; 107 115 WebViewImpl* getWebView() const; 108 116 WebCore::HTMLInputElement* getTextField() const { return m_textField.get(); }
Note: See TracChangeset
for help on using the changeset viewer.