Changeset 85551 in webkit


Ignore:
Timestamp:
May 2, 2011 4:43:37 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-05-02 Jia Pu <jpu@apple.com>

Reviewed by Alexey Proskuryakov.

[Mac] Need to truncate the string sent to "Look Up … " menu item, if it's too long.
https://bugs.webkit.org/show_bug.cgi?id=59836
<rdar://problem/9275983>

  • platform/DefaultLocalizationStrategy.cpp: (WebCore::truncatedStringForLookupMenuItem): (WebCore::DefaultLocalizationStrategy::contextMenuItemTagLookUpInDictionary):
Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r85549 r85551  
     12011-05-02  Jia Pu  <jpu@apple.com>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        [Mac] Need to truncate the string sent to "Look Up … " menu item, if it's too long.
     6        https://bugs.webkit.org/show_bug.cgi?id=59836
     7        <rdar://problem/9275983>
     8
     9        * platform/DefaultLocalizationStrategy.cpp:
     10        (WebCore::truncatedStringForLookupMenuItem):
     11        (WebCore::DefaultLocalizationStrategy::contextMenuItemTagLookUpInDictionary):
     12
    1132011-05-02  Brady Eidson  <beidson@apple.com>
    214
  • trunk/Source/WebCore/platform/DefaultLocalizationStrategy.cpp

    r85036 r85551  
    3232#include "LocalizedStrings.h"
    3333#include "NotImplemented.h"
     34#include "PlatformString.h"
    3435#include <wtf/MathExtras.h>
    3536#include <wtf/text/CString.h>
     37#include <wtf/unicode/CharacterNames.h>
    3638#include <wtf/UnusedParam.h>
    3739
     
    6971}
    7072
     73#if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
     74static String truncatedStringForLookupMenuItem(const String& original)
     75{
     76    if (original.isEmpty())
     77        return original;
     78   
     79    // Truncate the string if it's too long. This is in consistency with AppKit.
     80    unsigned maxNumberOfGraphemeClustersInLookupMenuItem = 24;
     81    DEFINE_STATIC_LOCAL(String, ellipsis, (&horizontalEllipsis, 1));
     82   
     83    String trimmed = original.stripWhiteSpace();
     84    unsigned numberOfCharacters = numCharactersInGraphemeClusters(trimmed, maxNumberOfGraphemeClustersInLookupMenuItem);
     85    return numberOfCharacters == trimmed.length() ? trimmed : trimmed.left(numberOfCharacters) + ellipsis;
     86}
     87#endif
     88
    7189DefaultLocalizationStrategy::DefaultLocalizationStrategy()
    7290{
     
    304322#else
    305323#if USE(CF)
    306     RetainPtr<CFStringRef> selectedCFString(AdoptCF, selectedString.createCFString());
     324    RetainPtr<CFStringRef> selectedCFString(AdoptCF, truncatedStringForLookupMenuItem(selectedString).createCFString());
    307325    return formatLocalizedString(WEB_UI_STRING("Look Up “%@”", "Look Up context menu item with selected word"), selectedCFString.get());
    308326#else
    309     return WEB_UI_STRING("Look Up “<selection>”", "Look Up context menu item with selected word").replace("<selection>", selectedString);
     327    return WEB_UI_STRING("Look Up “<selection>”", "Look Up context menu item with selected word").replace("<selection>", truncatedStringForLookupMenuItem(selectedString));
    310328#endif
    311329#endif
Note: See TracChangeset for help on using the changeset viewer.