diff options
author | Ben Murdoch <benm@google.com> | 2010-07-22 15:37:06 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-07-27 10:20:25 +0100 |
commit | 967717af5423377c967781471ee106e2bb4e11c8 (patch) | |
tree | 1e701dc0a12f7f07cce1df4a7681717de77a211b /WebCore/platform/chromium/PopupMenuChromium.cpp | |
parent | dcc30a9fca45f634b1d3a12b276d3a0ccce99fc3 (diff) | |
download | external_webkit-967717af5423377c967781471ee106e2bb4e11c8.zip external_webkit-967717af5423377c967781471ee106e2bb4e11c8.tar.gz external_webkit-967717af5423377c967781471ee106e2bb4e11c8.tar.bz2 |
Merge WebKit at r63859 : Initial merge by git.
Change-Id: Ie8096c63ec7c991c9a9cba8bdd9c3b74a3b8ed62
Diffstat (limited to 'WebCore/platform/chromium/PopupMenuChromium.cpp')
-rw-r--r-- | WebCore/platform/chromium/PopupMenuChromium.cpp | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/WebCore/platform/chromium/PopupMenuChromium.cpp b/WebCore/platform/chromium/PopupMenuChromium.cpp index 7e3a2a0..4701a75 100644 --- a/WebCore/platform/chromium/PopupMenuChromium.cpp +++ b/WebCore/platform/chromium/PopupMenuChromium.cpp @@ -70,6 +70,7 @@ typedef unsigned long long TimeStamp; static const int kMaxVisibleRows = 20; static const int kMaxHeight = 500; static const int kBorderSize = 1; +static const int kTextToLabelPadding = 10; static const TimeStamp kTypeAheadTimeoutMs = 1000; // The settings used for the drop down menu. @@ -751,8 +752,11 @@ bool PopupListBox::handleKeyEvent(const PlatformKeyboardEvent& event) if (event.windowsVirtualKeyCode() == VKEY_TAB) { // TAB is a special case as it should select the current item if any and // advance focus. - if (m_selectedIndex >= 0) - m_popupClient->setTextFromItem(m_selectedIndex); + if (m_selectedIndex >= 0) { + acceptIndex(m_selectedIndex); // May delete us. + // Return false so the TAB key event is propagated to the page. + return false; + } // Call abandon() so we honor m_acceptedIndexOnAbandon if set. abandon(); // Return false so the TAB key event is propagated to the page. @@ -873,13 +877,17 @@ void PopupListBox::paintRow(GraphicsContext* gc, const IntRect& rect, int rowInd PopupMenuStyle style = m_popupClient->itemStyle(rowIndex); // Paint background - Color backColor, textColor; + Color backColor, textColor, labelColor; if (rowIndex == m_selectedIndex) { backColor = RenderTheme::defaultTheme()->activeListBoxSelectionBackgroundColor(); textColor = RenderTheme::defaultTheme()->activeListBoxSelectionForegroundColor(); + labelColor = textColor; } else { backColor = style.backgroundColor(); textColor = style.foregroundColor(); + // FIXME: for now the label color is hard-coded. It should be added to + // the PopupMenuStyle. + labelColor = Color(115, 115, 115); } // If we have a transparent background, make sure it has a color to blend @@ -917,10 +925,23 @@ void PopupListBox::paintRow(GraphicsContext* gc, const IntRect& rect, int rowInd } // Prepare text to be drawn. String itemText = m_popupClient->itemText(rowIndex); - if (m_settings.restrictWidthOfListBox) // truncate string to fit in. - itemText = StringTruncator::rightTruncate(itemText, maxWidth, itemFont); - unsigned length = itemText.length(); - const UChar* str = itemText.characters(); + String itemLabel = m_popupClient->itemLabel(rowIndex); + if (m_settings.restrictWidthOfListBox) { // Truncate strings to fit in. + // FIXME: We should leftTruncate for the rtl case. + // StringTruncator::leftTruncate would have to be implemented. + String str = StringTruncator::rightTruncate(itemText, maxWidth, itemFont); + if (str != itemText) { + itemText = str; + // Don't display the label, we already don't have enough room for the + // item text. + itemLabel = ""; + } else if (!itemLabel.isEmpty()) { + int availableWidth = maxWidth - kTextToLabelPadding - + StringTruncator::width(itemText, itemFont); + itemLabel = StringTruncator::rightTruncate(itemLabel, availableWidth, itemFont); + } + } + // Prepare the directionality to draw text. bool rtl = false; if (m_settings.itemTextDirectionalityHint == PopupContainerSettings::DOMElementDirection) @@ -928,14 +949,31 @@ void PopupListBox::paintRow(GraphicsContext* gc, const IntRect& rect, int rowInd else if (m_settings.itemTextDirectionalityHint == PopupContainerSettings::FirstStrongDirectionalCharacterDirection) rtl = itemText.defaultWritingDirection() == WTF::Unicode::RightToLeft; - TextRun textRun(str, length, false, 0, 0, rtl); + TextRun textRun(itemText.characters(), itemText.length(), false, 0, 0, rtl); // If the text is right-to-left, make it right-aligned by adjusting its // beginning position. if (rightAligned) textX += maxWidth - itemFont.width(textRun); + // Draw the item text. int textY = rowRect.y() + itemFont.ascent() + (rowRect.height() - itemFont.height()) / 2; gc->drawBidiText(itemFont, textRun, IntPoint(textX, textY)); + + // Draw the the label if applicable. + if (itemLabel.isEmpty()) + return; + TextRun labelTextRun(itemLabel.characters(), itemLabel.length(), false, 0, 0, rtl); + if (rightAligned) + textX = max(0, m_popupClient->clientPaddingLeft() - m_popupClient->clientInsetLeft()); + else { + // We are using the left padding as the right padding includes room for the scroll-bar which + // does not show in this case. + int rightPadding = max(0, m_popupClient->clientPaddingLeft() - m_popupClient->clientInsetLeft()); + textX = rowRect.width() - rightPadding - itemFont.width(labelTextRun); + } + + gc->setFillColor(labelColor, DeviceColorSpace); + gc->drawBidiText(itemFont, labelTextRun, IntPoint(textX, textY)); } Font PopupListBox::getRowFont(int rowIndex) |