summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/chromium/PopupMenuChromium.cpp
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2010-07-30 10:46:49 +0100
committerKristian Monsen <kristianm@google.com>2010-08-04 13:01:34 +0100
commit0617145a89917ae7735fe1c9538688ab9a577df5 (patch)
tree56206078694427c37ed7bdf27eb5221398b833c0 /WebCore/platform/chromium/PopupMenuChromium.cpp
parentef1adcdfc805d4d13103f6f15cc5b4d96828a60f (diff)
downloadexternal_webkit-0617145a89917ae7735fe1c9538688ab9a577df5.zip
external_webkit-0617145a89917ae7735fe1c9538688ab9a577df5.tar.gz
external_webkit-0617145a89917ae7735fe1c9538688ab9a577df5.tar.bz2
Merge WebKit at r64264 : Initial merge by git.
Change-Id: Ic42bef02efef8217a0f84c47176a9c617c28d1f1
Diffstat (limited to 'WebCore/platform/chromium/PopupMenuChromium.cpp')
-rw-r--r--WebCore/platform/chromium/PopupMenuChromium.cpp37
1 files changed, 28 insertions, 9 deletions
diff --git a/WebCore/platform/chromium/PopupMenuChromium.cpp b/WebCore/platform/chromium/PopupMenuChromium.cpp
index 4701a75..d07ba2e 100644
--- a/WebCore/platform/chromium/PopupMenuChromium.cpp
+++ b/WebCore/platform/chromium/PopupMenuChromium.cpp
@@ -71,6 +71,7 @@ static const int kMaxVisibleRows = 20;
static const int kMaxHeight = 500;
static const int kBorderSize = 1;
static const int kTextToLabelPadding = 10;
+static const int kLabelToIconPadding = 5;
static const TimeStamp kTypeAheadTimeoutMs = 1000;
// The settings used for the drop down menu.
@@ -959,18 +960,30 @@ void PopupListBox::paintRow(GraphicsContext* gc, const IntRect& rect, int rowInd
int textY = rowRect.y() + itemFont.ascent() + (rowRect.height() - itemFont.height()) / 2;
gc->drawBidiText(itemFont, textRun, IntPoint(textX, textY));
+ // 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());
+ int remainingWidth = rowRect.width() - rightPadding;
+
+ // Draw the icon if applicable.
+ String itemIcon = m_popupClient->itemIcon(rowIndex);
+ RefPtr<Image> image(Image::loadPlatformResource(itemIcon.utf8().data()));
+ if (image && !image->isNull()) {
+ IntRect imageRect = image->rect();
+ remainingWidth -= (imageRect.width() + kLabelToIconPadding);
+ imageRect.setX(rowRect.width() - rightPadding - imageRect.width());
+ imageRect.setY(rowRect.y() + (rowRect.height() - imageRect.height()) / 2);
+ gc->drawImage(image.get(), DeviceColorSpace, imageRect);
+ }
+
// 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);
- }
+ else
+ textX = remainingWidth - itemFont.width(labelTextRun);
gc->setFillColor(labelColor, DeviceColorSpace);
gc->drawBidiText(itemFont, labelTextRun, IntPoint(textX, textY));
@@ -1243,10 +1256,16 @@ void PopupListBox::layout()
// Ensure the popup is wide enough to fit this item.
String text = m_popupClient->itemText(i);
- if (!text.isEmpty()) {
- int width = itemFont.width(TextRun(text));
- baseWidth = max(baseWidth, width);
+ String label = m_popupClient->itemLabel(i);
+ int width = 0;
+ if (!text.isEmpty())
+ width = itemFont.width(TextRun(text));
+ if (!label.isEmpty()) {
+ if (width > 0)
+ width += kTextToLabelPadding;
+ width += itemFont.width(TextRun(label));
}
+ baseWidth = max(baseWidth, width);
// FIXME: http://b/1210481 We should get the padding of individual option elements.
paddingWidth = max(paddingWidth,
m_popupClient->clientPaddingLeft() + m_popupClient->clientPaddingRight());