| 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 gc->translate(static_cast<float>(tx), static_cast<float>(ty)); | 369 gc->translate(static_cast<float>(tx), static_cast<float>(ty)); |
| 370 gc->clip(r); | 370 gc->clip(r); |
| 371 | 371 |
| 372 // FIXME: Can we optimize scrolling to not require repainting the entire | 372 // FIXME: Can we optimize scrolling to not require repainting the entire |
| 373 // window? Should we? | 373 // window? Should we? |
| 374 for (int i = 0; i < numItems(); ++i) | 374 for (int i = 0; i < numItems(); ++i) |
| 375 paintRow(gc, r, i); | 375 paintRow(gc, r, i); |
| 376 | 376 |
| 377 // Special case for an empty popup. | 377 // Special case for an empty popup. |
| 378 if (!numItems()) | 378 if (!numItems()) |
| 379 gc->fillRect(r, Color::white, ColorSpaceDeviceRGB); | 379 gc->fillRect(r, Color::white); |
| 380 | 380 |
| 381 gc->restore(); | 381 gc->restore(); |
| 382 | 382 |
| 383 ScrollView::paint(gc, rect); | 383 ScrollView::paint(gc, rect); |
| 384 } | 384 } |
| 385 | 385 |
| 386 static const int separatorPadding = 4; | 386 static const int separatorPadding = 4; |
| 387 static const int separatorHeight = 1; | 387 static const int separatorHeight = 1; |
| 388 | 388 |
| 389 void PopupListBox::paintRow(GraphicsContext* gc, const IntRect& rect, int rowInd
ex) | 389 void PopupListBox::paintRow(GraphicsContext* gc, const IntRect& rect, int rowInd
ex) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 416 #endif | 416 #endif |
| 417 | 417 |
| 418 // FIXME: for now the label color is hard-coded. It should be added to | 418 // FIXME: for now the label color is hard-coded. It should be added to |
| 419 // the PopupMenuStyle. | 419 // the PopupMenuStyle. |
| 420 labelColor = Color(115, 115, 115); | 420 labelColor = Color(115, 115, 115); |
| 421 } | 421 } |
| 422 | 422 |
| 423 // If we have a transparent background, make sure it has a color to blend | 423 // If we have a transparent background, make sure it has a color to blend |
| 424 // against. | 424 // against. |
| 425 if (backColor.hasAlpha()) | 425 if (backColor.hasAlpha()) |
| 426 gc->fillRect(rowRect, Color::white, ColorSpaceDeviceRGB); | 426 gc->fillRect(rowRect, Color::white); |
| 427 | 427 |
| 428 gc->fillRect(rowRect, backColor, ColorSpaceDeviceRGB); | 428 gc->fillRect(rowRect, backColor); |
| 429 | 429 |
| 430 // It doesn't look good but Autofill requires special style for separator. | 430 // It doesn't look good but Autofill requires special style for separator. |
| 431 // Autofill doesn't have padding and #dcdcdc color. | 431 // Autofill doesn't have padding and #dcdcdc color. |
| 432 if (m_popupClient->itemIsSeparator(rowIndex)) { | 432 if (m_popupClient->itemIsSeparator(rowIndex)) { |
| 433 int padding = style.menuType() == PopupMenuStyle::AutofillPopup ? 0 : se
paratorPadding; | 433 int padding = style.menuType() == PopupMenuStyle::AutofillPopup ? 0 : se
paratorPadding; |
| 434 IntRect separatorRect( | 434 IntRect separatorRect( |
| 435 rowRect.x() + padding, | 435 rowRect.x() + padding, |
| 436 rowRect.y() + (rowRect.height() - separatorHeight) / 2, | 436 rowRect.y() + (rowRect.height() - separatorHeight) / 2, |
| 437 rowRect.width() - 2 * padding, separatorHeight); | 437 rowRect.width() - 2 * padding, separatorHeight); |
| 438 gc->fillRect(separatorRect, style.menuType() == PopupMenuStyle::Autofill
Popup ? Color(0xdc, 0xdc, 0xdc) : textColor, ColorSpaceDeviceRGB); | 438 gc->fillRect(separatorRect, style.menuType() == PopupMenuStyle::Autofill
Popup ? Color(0xdc, 0xdc, 0xdc) : textColor); |
| 439 return; | 439 return; |
| 440 } | 440 } |
| 441 | 441 |
| 442 if (!style.isVisible()) | 442 if (!style.isVisible()) |
| 443 return; | 443 return; |
| 444 | 444 |
| 445 gc->setFillColor(textColor, ColorSpaceDeviceRGB); | 445 gc->setFillColor(textColor); |
| 446 | 446 |
| 447 FontCachePurgePreventer fontCachePurgePreventer; | 447 FontCachePurgePreventer fontCachePurgePreventer; |
| 448 | 448 |
| 449 Font itemFont = getRowFont(rowIndex); | 449 Font itemFont = getRowFont(rowIndex); |
| 450 // FIXME: http://crbug.com/19872 We should get the padding of individual opt
ion | 450 // FIXME: http://crbug.com/19872 We should get the padding of individual opt
ion |
| 451 // elements. This probably implies changes to PopupMenuClient. | 451 // elements. This probably implies changes to PopupMenuClient. |
| 452 bool rightAligned = m_popupClient->menuStyle().textDirection() == RTL; | 452 bool rightAligned = m_popupClient->menuStyle().textDirection() == RTL; |
| 453 int textX = 0; | 453 int textX = 0; |
| 454 int maxWidth = 0; | 454 int maxWidth = 0; |
| 455 if (rightAligned) | 455 if (rightAligned) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 int rightPadding = max<int>(0, m_popupClient->clientPaddingLeft() - m_popupC
lient->clientInsetLeft()); | 496 int rightPadding = max<int>(0, m_popupClient->clientPaddingLeft() - m_popupC
lient->clientInsetLeft()); |
| 497 int remainingWidth = rowRect.width() - rightPadding; | 497 int remainingWidth = rowRect.width() - rightPadding; |
| 498 | 498 |
| 499 // Draw the icon if applicable. | 499 // Draw the icon if applicable. |
| 500 RefPtr<Image> image(Image::loadPlatformResource(itemIcon.utf8().data())); | 500 RefPtr<Image> image(Image::loadPlatformResource(itemIcon.utf8().data())); |
| 501 if (image && !image->isNull()) { | 501 if (image && !image->isNull()) { |
| 502 IntRect imageRect = image->rect(); | 502 IntRect imageRect = image->rect(); |
| 503 remainingWidth -= (imageRect.width() + labelToIconPadding); | 503 remainingWidth -= (imageRect.width() + labelToIconPadding); |
| 504 imageRect.setX(rowRect.width() - rightPadding - imageRect.width()); | 504 imageRect.setX(rowRect.width() - rightPadding - imageRect.width()); |
| 505 imageRect.setY(rowRect.y() + (rowRect.height() - imageRect.height()) / 2
); | 505 imageRect.setY(rowRect.y() + (rowRect.height() - imageRect.height()) / 2
); |
| 506 gc->drawImage(image.get(), ColorSpaceDeviceRGB, imageRect); | 506 gc->drawImage(image.get(), imageRect); |
| 507 } | 507 } |
| 508 | 508 |
| 509 // Draw the the label if applicable. | 509 // Draw the the label if applicable. |
| 510 if (itemLabel.isEmpty()) | 510 if (itemLabel.isEmpty()) |
| 511 return; | 511 return; |
| 512 | 512 |
| 513 // Autofill label is 0.9 smaller than regular font size. | 513 // Autofill label is 0.9 smaller than regular font size. |
| 514 if (style.menuType() == PopupMenuStyle::AutofillPopup) { | 514 if (style.menuType() == PopupMenuStyle::AutofillPopup) { |
| 515 itemFont = m_popupClient->itemStyle(rowIndex).font(); | 515 itemFont = m_popupClient->itemStyle(rowIndex).font(); |
| 516 FontDescription d = itemFont.fontDescription(); | 516 FontDescription d = itemFont.fontDescription(); |
| 517 d.setComputedSize(d.computedSize() * 0.9); | 517 d.setComputedSize(d.computedSize() * 0.9); |
| 518 itemFont = Font(d, itemFont.letterSpacing(), itemFont.wordSpacing()); | 518 itemFont = Font(d, itemFont.letterSpacing(), itemFont.wordSpacing()); |
| 519 itemFont.update(0); | 519 itemFont.update(0); |
| 520 } | 520 } |
| 521 | 521 |
| 522 TextRun labelTextRun(itemLabel, 0, 0, TextRun::AllowTrailingExpansion, style
.textDirection(), style.hasTextDirectionOverride()); | 522 TextRun labelTextRun(itemLabel, 0, 0, TextRun::AllowTrailingExpansion, style
.textDirection(), style.hasTextDirectionOverride()); |
| 523 if (rightAligned) | 523 if (rightAligned) |
| 524 textX = max<int>(0, m_popupClient->clientPaddingLeft() - m_popupClient->
clientInsetLeft()); | 524 textX = max<int>(0, m_popupClient->clientPaddingLeft() - m_popupClient->
clientInsetLeft()); |
| 525 else | 525 else |
| 526 textX = remainingWidth - itemFont.width(labelTextRun); | 526 textX = remainingWidth - itemFont.width(labelTextRun); |
| 527 TextRunPaintInfo labelTextRunPaintInfo(labelTextRun); | 527 TextRunPaintInfo labelTextRunPaintInfo(labelTextRun); |
| 528 labelTextRunPaintInfo.bounds = rowRect; | 528 labelTextRunPaintInfo.bounds = rowRect; |
| 529 | 529 |
| 530 gc->setFillColor(labelColor, ColorSpaceDeviceRGB); | 530 gc->setFillColor(labelColor); |
| 531 gc->drawBidiText(itemFont, labelTextRunPaintInfo, IntPoint(textX, textY)); | 531 gc->drawBidiText(itemFont, labelTextRunPaintInfo, IntPoint(textX, textY)); |
| 532 } | 532 } |
| 533 | 533 |
| 534 Font PopupListBox::getRowFont(int rowIndex) | 534 Font PopupListBox::getRowFont(int rowIndex) |
| 535 { | 535 { |
| 536 Font itemFont = m_popupClient->itemStyle(rowIndex).font(); | 536 Font itemFont = m_popupClient->itemStyle(rowIndex).font(); |
| 537 if (m_popupClient->itemIsLabel(rowIndex)) { | 537 if (m_popupClient->itemIsLabel(rowIndex)) { |
| 538 // Bold-ify labels (ie, an <optgroup> heading). | 538 // Bold-ify labels (ie, an <optgroup> heading). |
| 539 FontDescription d = itemFont.fontDescription(); | 539 FontDescription d = itemFont.fontDescription(); |
| 540 d.setWeight(FontWeightBold); | 540 d.setWeight(FontWeightBold); |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 { | 929 { |
| 930 return numItems() && IntRect(0, 0, width(), height()).contains(point); | 930 return numItems() && IntRect(0, 0, width(), height()).contains(point); |
| 931 } | 931 } |
| 932 | 932 |
| 933 int PopupListBox::popupContentHeight() const | 933 int PopupListBox::popupContentHeight() const |
| 934 { | 934 { |
| 935 return height(); | 935 return height(); |
| 936 } | 936 } |
| 937 | 937 |
| 938 } // namespace WebCore | 938 } // namespace WebCore |
| OLD | NEW |