Changeset 63179 in webkit


Ignore:
Timestamp:
Jul 12, 2010 11:41:09 PM (14 years ago)
Author:
jcivelli@chromium.org
Message:

2010-07-12 Jay Civelli <jcivelli@chromium.org>

Reviewed by Kent Tamura.

Adding right aligned text called labels to PopupMenus.
https://bugs.webkit.org/show_bug.cgi?id=41964

  • platform/PopupMenuClient.h:
  • platform/chromium/PopupMenuChromium.cpp: (WebCore::PopupListBox::paintRow):
  • rendering/RenderMenuList.cpp: (WebCore::RenderMenuList::itemLabel):
  • rendering/RenderMenuList.h:
  • rendering/RenderTextControlSingleLine.cpp: (WebCore::RenderTextControlSingleLine::itemLabel):
  • rendering/RenderTextControlSingleLine.h:

2010-07-12 Jay Civelli <jcivelli@chromium.org>

Reviewed by Kent Tamura.

Making the autofill popup use labels to show the label
associated with an item.
https://bugs.webkit.org/show_bug.cgi?id=41964

  • src/AutoFillPopupMenuClient.cpp: (WebKit::AutoFillPopupMenuClient::getSuggestion): (WebKit::AutoFillPopupMenuClient::getLabel): (WebKit::AutoFillPopupMenuClient::itemLabel): (WebKit::AutoFillPopupMenuClient::setSuggestions): (WebKit::AutoFillPopupMenuClient::convertListIndexToInternalIndex):
  • src/AutoFillPopupMenuClient.h:
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r63176 r63179  
     12010-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
    1182010-07-12  Mihnea Ovidenea  <mihnea@adobe.com>
    219
  • trunk/WebCore/platform/PopupMenuClient.h

    r60514 r63179  
    4343
    4444    virtual String itemText(unsigned listIndex) const = 0;
     45    virtual String itemLabel(unsigned listIndex) const = 0;
    4546    virtual String itemToolTip(unsigned listIndex) const = 0;
    4647    virtual String itemAccessibilityText(unsigned listIndex) const = 0;
  • trunk/WebCore/platform/chromium/PopupMenuChromium.cpp

    r61941 r63179  
    7171static const int kMaxHeight = 500;
    7272static const int kBorderSize = 1;
     73static const int kTextToLabelPadding = 10;
    7374static const TimeStamp kTypeAheadTimeoutMs = 1000;
    7475
     
    918919    // Prepare text to be drawn.
    919920    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
    924938    // Prepare the directionality to draw text.
    925939    bool rtl = false;
     
    929943             PopupContainerSettings::FirstStrongDirectionalCharacterDirection)
    930944        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);
    932946    // If the text is right-to-left, make it right-aligned by adjusting its
    933947    // beginning position.
    934948    if (rightAligned)
    935949        textX += maxWidth - itemFont.width(textRun);
     950
    936951    // Draw the item text.
    937952    int textY = rowRect.y() + itemFont.ascent() + (rowRect.height() - itemFont.height()) / 2;
    938953    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));
    939972}
    940973
  • trunk/WebCore/rendering/RenderMenuList.cpp

    r61487 r63179  
    351351}
    352352
     353String RenderMenuList::itemLabel(unsigned) const
     354{
     355    return String();
     356}
     357
    353358String RenderMenuList::itemAccessibilityText(unsigned listIndex) const
    354359{
  • trunk/WebCore/rendering/RenderMenuList.h

    r60514 r63179  
    8383    // PopupMenuClient methods
    8484    virtual String itemText(unsigned listIndex) const;
     85    virtual String itemLabel(unsigned listIndex) const;
    8586    virtual String itemToolTip(unsigned listIndex) const;
    8687    virtual String itemAccessibilityText(unsigned listIndex) const;
  • trunk/WebCore/rendering/RenderTextControlSingleLine.cpp

    r62249 r63179  
    877877}
    878878
     879String RenderTextControlSingleLine::itemLabel(unsigned) const
     880{
     881    return String();
     882}
     883
    879884bool RenderTextControlSingleLine::itemIsEnabled(unsigned listIndex) const
    880885{
  • trunk/WebCore/rendering/RenderTextControlSingleLine.h

    r61752 r63179  
    116116    virtual void selectionCleared() {}
    117117    virtual String itemText(unsigned listIndex) const;
     118    virtual String itemLabel(unsigned listIndex) const;
    118119    virtual String itemToolTip(unsigned) const { return String(); }
    119120    virtual String itemAccessibilityText(unsigned) const { return String(); }
  • trunk/WebKit/chromium/ChangeLog

    r63173 r63179  
     12010-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
    1172010-07-12  Sheriff Bot  <webkit.review.bot@gmail.com>
    218
  • trunk/WebKit/chromium/src/AutoFillPopupMenuClient.cpp

    r62272 r63179  
    6767WebString AutoFillPopupMenuClient::getSuggestion(unsigned listIndex) const
    6868{
    69     if (listIndex == static_cast<unsigned>(m_separatorIndex))
     69    int index = convertListIndexToInternalIndex(listIndex);
     70    if (index == -1)
    7071        return WebString();
    7172
    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
     77WebString 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];
    8385}
    8486
     
    151153}
    152154
     155String AutoFillPopupMenuClient::itemLabel(unsigned listIndex) const
     156{
     157    return getLabel(listIndex);
     158}
     159
    153160PopupMenuStyle AutoFillPopupMenuClient::itemStyle(unsigned listIndex) const
    154161{
     
    269276    if (getSelectedIndex() >= static_cast<int>(names.size()))
    270277        setSelectedIndex(-1);
     278}
     279
     280int 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;
    271288}
    272289
  • trunk/WebKit/chromium/src/AutoFillPopupMenuClient.h

    r62272 r63179  
    5858    virtual WebString getSuggestion(unsigned listIndex) const;
    5959
     60    // Returns the label at |listIndex|.
     61    virtual WebString getLabel(unsigned listIndex) const;
     62   
    6063    // Removes the suggestion at |listIndex| from the list of suggestions.
    6164    virtual void removeSuggestionAtIndex(unsigned listIndex);
     
    6669    virtual void selectionCleared();
    6770    virtual WebCore::String itemText(unsigned listIndex) const;
     71    virtual WebCore::String itemLabel(unsigned listIndex) const;
    6872    virtual WebCore::String itemToolTip(unsigned lastIndex) const { return WebCore::String(); }
    6973    virtual WebCore::String itemAccessibilityText(unsigned lastIndex) const { return WebCore::String(); }
     
    105109
    106110private:
     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;
    107115    WebViewImpl* getWebView() const;
    108116    WebCore::HTMLInputElement* getTextField() const { return m_textField.get(); }
Note: See TracChangeset for help on using the changeset viewer.