Changeset 57940 in webkit


Ignore:
Timestamp:
Apr 20, 2010 4:51:45 PM (14 years ago)
Author:
hamaji@chromium.org
Message:

2010-04-20 Shinichiro Hamaji <hamaji@chromium.org>

Reviewed by Darin Adler and Alexey Proskuryakov.

A backslash in EUC-JP becomes to a yen sign when it is copied
https://bugs.webkit.org/show_bug.cgi?id=36419

  • editing/execCommand/transpose-backslash-with-euc-expected.txt: Added.
  • editing/execCommand/transpose-backslash-with-euc.html: Added.
  • editing/pasteboard/copy-backslash-with-euc-expected.txt: Added.
  • editing/pasteboard/copy-backslash-with-euc.html: Added.
  • editing/pasteboard/resources/copy-backslash-euc.html: Added.

2010-04-20 Shinichiro Hamaji <hamaji@chromium.org>

Reviewed by Darin Adler and Alexey Proskuryakov.

A backslash in EUC-JP becomes to a yen sign when it is copied
https://bugs.webkit.org/show_bug.cgi?id=36419

Tests: editing/execCommand/transpose-backslash-with-euc.html

editing/pasteboard/copy-backslash-with-euc.html

  • editing/Editor.cpp: Remove an unnecessary displayStringModifiedByEncoding calls. (WebCore::Editor::addToKillRing):
  • editing/TextIterator.cpp: TextIterator can use RenderText::textWithoutTranscoding and now plainText() uses this version (WebCore::TextIterator::TextIterator): (WebCore::TextIterator::init): (WebCore::TextIterator::emitText): (WebCore::plainTextToMallocAllocatedBuffer):
  • editing/TextIterator.h: (WebCore::):
  • platform/mac/PasteboardMac.mm: Remove an unnecessary displayStringModifiedByEncoding call. (WebCore::Pasteboard::writeSelection):
  • platform/text/TextEncoding.h: Make backslashAsCurrencySymbol public.
  • rendering/RenderText.cpp: Add RenderText::textWithoutTranscoding (WebCore::RenderText::RenderText): (WebCore::RenderText::updateNeedsTranscoding): (WebCore::RenderText::styleDidChange): (WebCore::isInlineFlowOrEmptyText): (WebCore::RenderText::previousCharacter): (WebCore::RenderText::setTextInternal): (WebCore::RenderText::textWithoutTranscoding): (WebCore::RenderText::transformText):
  • rendering/RenderText.h:
  • rendering/RenderTextControl.cpp: Remove an unnecessary displayStringModifiedByEncoding call. (WebCore::RenderTextControl::setInnerTextValue): (WebCore::RenderTextControl::finishText):
  • rendering/RenderTextFragment.cpp: (WebCore::RenderTextFragment::previousCharacter):
  • rendering/RenderTextFragment.h:
Location:
trunk
Files:
5 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r57939 r57940  
     12010-04-20  Shinichiro Hamaji  <hamaji@chromium.org>
     2
     3        Reviewed by Darin Adler and Alexey Proskuryakov.
     4
     5        A backslash in EUC-JP becomes to a yen sign when it is copied
     6        https://bugs.webkit.org/show_bug.cgi?id=36419
     7
     8        * editing/execCommand/transpose-backslash-with-euc-expected.txt: Added.
     9        * editing/execCommand/transpose-backslash-with-euc.html: Added.
     10        * editing/pasteboard/copy-backslash-with-euc-expected.txt: Added.
     11        * editing/pasteboard/copy-backslash-with-euc.html: Added.
     12        * editing/pasteboard/resources/copy-backslash-euc.html: Added.
     13
    1142010-04-20  Andrew Scherkus  <scherkus@chromium.org>
    215
  • trunk/WebCore/ChangeLog

    r57936 r57940  
     12010-04-20  Shinichiro Hamaji  <hamaji@chromium.org>
     2
     3        Reviewed by Darin Adler and Alexey Proskuryakov.
     4
     5        A backslash in EUC-JP becomes to a yen sign when it is copied
     6        https://bugs.webkit.org/show_bug.cgi?id=36419
     7
     8        Tests: editing/execCommand/transpose-backslash-with-euc.html
     9               editing/pasteboard/copy-backslash-with-euc.html
     10
     11        * editing/Editor.cpp: Remove an unnecessary displayStringModifiedByEncoding calls.
     12        (WebCore::Editor::addToKillRing):
     13        * editing/TextIterator.cpp: TextIterator can use RenderText::textWithoutTranscoding and now plainText() uses this version
     14        (WebCore::TextIterator::TextIterator):
     15        (WebCore::TextIterator::init):
     16        (WebCore::TextIterator::emitText):
     17        (WebCore::plainTextToMallocAllocatedBuffer):
     18        * editing/TextIterator.h:
     19        (WebCore::):
     20        * platform/mac/PasteboardMac.mm: Remove an unnecessary displayStringModifiedByEncoding call.
     21        (WebCore::Pasteboard::writeSelection):
     22        * platform/text/TextEncoding.h: Make backslashAsCurrencySymbol public.
     23        * rendering/RenderText.cpp: Add RenderText::textWithoutTranscoding
     24        (WebCore::RenderText::RenderText):
     25        (WebCore::RenderText::updateNeedsTranscoding):
     26        (WebCore::RenderText::styleDidChange):
     27        (WebCore::isInlineFlowOrEmptyText):
     28        (WebCore::RenderText::previousCharacter):
     29        (WebCore::RenderText::setTextInternal):
     30        (WebCore::RenderText::textWithoutTranscoding):
     31        (WebCore::RenderText::transformText):
     32        * rendering/RenderText.h:
     33        * rendering/RenderTextControl.cpp: Remove an unnecessary displayStringModifiedByEncoding call.
     34        (WebCore::RenderTextControl::setInnerTextValue):
     35        (WebCore::RenderTextControl::finishText):
     36        * rendering/RenderTextFragment.cpp:
     37        (WebCore::RenderTextFragment::previousCharacter):
     38        * rendering/RenderTextFragment.h:
     39
    1402010-04-20  Nate Chapin  <japhet@chromium.org>
    241
  • trunk/WebCore/editing/Editor.cpp

    r57895 r57940  
    27042704        startNewKillRingSequence();
    27052705
    2706     String text = m_frame->displayStringModifiedByEncoding(plainText(range));
     2706    String text = plainText(range);
    27072707    if (prepend)
    27082708        prependToKillRing(text);
  • trunk/WebCore/editing/TextIterator.cpp

    r55705 r57940  
    257257    , m_emitCharactersBetweenAllVisiblePositions(false)
    258258    , m_enterTextControls(false)
    259 {
    260 }
    261 
    262 TextIterator::TextIterator(const Range* r, bool emitCharactersBetweenAllVisiblePositions, bool enterTextControls)
     259    , m_emitsTextWithoutTranscoding(false)
     260{
     261}
     262
     263TextIterator::TextIterator(const Range* r, bool emitCharactersBetweenAllVisiblePositions, bool enterTextControls)
    263264    : m_startContainer(0)
    264265    , m_startOffset(0)
     
    270271    , m_emitCharactersBetweenAllVisiblePositions(emitCharactersBetweenAllVisiblePositions)
    271272    , m_enterTextControls(enterTextControls)
     273    , m_emitsTextWithoutTranscoding(false)
     274{
     275    init(r);
     276}
     277
     278TextIterator::TextIterator(const Range* r, TextIteratorBehavior behavior)
     279    : m_startContainer(0)
     280    , m_startOffset(0)
     281    , m_endContainer(0)
     282    , m_endOffset(0)
     283    , m_positionNode(0)
     284    , m_textCharacters(0)
     285    , m_textLength(0)
     286    , m_emitCharactersBetweenAllVisiblePositions(behavior & TextIteratorBehaviorEmitCharactersBetweenAllVisiblePositions)
     287    , m_enterTextControls(behavior & TextIteratorBehaviorEnterTextControls)
     288    , m_emitsTextWithoutTranscoding(behavior & TextIteratorBehaviorEmitsTextsWithoutTranscoding)
     289{
     290    init(r);
     291}
     292
     293void TextIterator::init(const Range* r)
    272294{
    273295    if (!r)
     
    890912{
    891913    RenderText* renderer = toRenderText(m_node->renderer());
    892     String str = renderer->text();
     914    String str = m_emitsTextWithoutTranscoding ? renderer->textWithoutTranscoding() : renderer->text();
    893915    ASSERT(str.characters());
    894916
     
    21052127// --------
    21062128   
    2107 UChar* plainTextToMallocAllocatedBuffer(const Range* r, unsigned& bufferLength, bool isDisplayString) 
     2129UChar* plainTextToMallocAllocatedBuffer(const Range* r, unsigned& bufferLength, bool isDisplayString)
    21082130{
    21092131    UChar* result = 0;
     
    21172139    Vector<UChar> textBuffer;
    21182140    textBuffer.reserveInitialCapacity(cMaxSegmentSize);
    2119     for (TextIterator it(r); !it.atEnd(); it.advance()) {
     2141    for (TextIterator it(r, isDisplayString ? TextIteratorBehaviorDefault : TextIteratorBehaviorEmitsTextsWithoutTranscoding); !it.atEnd(); it.advance()) {
    21202142        if (textBuffer.size() && textBuffer.size() + it.length() > cMaxSegmentSize) {
    21212143            UChar* newSegmentBuffer = static_cast<UChar*>(malloc(textBuffer.size() * sizeof(UChar)));
  • trunk/WebCore/editing/TextIterator.h

    r44674 r57940  
    6969// chunks so as to optimize for performance of the iteration.
    7070
     71enum TextIteratorBehavior {
     72    TextIteratorBehaviorDefault = 0,
     73    TextIteratorBehaviorEmitCharactersBetweenAllVisiblePositions = 1 << 0,
     74    TextIteratorBehaviorEnterTextControls = 1 << 1,
     75    TextIteratorBehaviorEmitsTextsWithoutTranscoding = 1 << 2,
     76};
     77
    7178class TextIterator {
    7279public:
    7380    TextIterator();
    7481    explicit TextIterator(const Range*, bool emitCharactersBetweenAllVisiblePositions = false, bool enterTextControls = false);
    75    
     82    TextIterator(const Range*, TextIteratorBehavior);
     83
    7684    bool atEnd() const { return !m_positionNode; }
    7785    void advance();
     
    8896   
    8997private:
     98    void init(const Range*);
    9099    void exitNode();
    91100    bool shouldRepresentNodeOffsetZero();
     
    148157    bool m_emitCharactersBetweenAllVisiblePositions;
    149158    bool m_enterTextControls;
     159
     160    // Used when we want texts for copying, pasting, and transposing.
     161    bool m_emitsTextWithoutTranscoding;
    150162};
    151163
  • trunk/WebCore/platform/mac/PasteboardMac.mm

    r55029 r57940  
    185185        // Map &nbsp; to a plain old space because this is better for source code, other browsers do it,
    186186        // and because HTML forces you to do this any time you want two spaces in a row.
    187         String text = frame->displayStringModifiedByEncoding(selectedRange->text());
     187        String text = selectedRange->text();
    188188        NSMutableString *s = [[[(NSString*)text copy] autorelease] mutableCopy];
    189189       
  • trunk/WebCore/platform/text/TextEncoding.h

    r56825 r57940  
    7878        WTF::CString encode(const UChar*, size_t length, UnencodableHandling) const;
    7979
     80        UChar backslashAsCurrencySymbol() const;
     81
    8082    private:
    81         UChar backslashAsCurrencySymbol() const;
    8283        bool isNonByteBasedEncoding() const;
    8384        bool isUTF7Encoding() const;
  • trunk/WebCore/rendering/RenderText.cpp

    r57215 r57940  
    4040#include "Text.h"
    4141#include "TextBreakIterator.h"
     42#include "TextResourceDecoder.h"
    4243#include "VisiblePosition.h"
    4344#include "break_lines.h"
     
    8990     : RenderObject(node)
    9091     , m_minWidth(-1)
    91      , m_text(document()->displayStringModifiedByEncoding(str))
     92     , m_text(str)
    9293     , m_firstTextBox(0)
    9394     , m_lastTextBox(0)
     
    100101     , m_isAllASCII(m_text.containsOnlyASCII())
    101102     , m_knownToHaveNoOverflowAndNoFallbackFonts(false)
     103     , m_needsTranscoding(false)
    102104{
    103105    ASSERT(m_text);
     
    134136{
    135137    return false;
     138}
     139
     140void RenderText::updateNeedsTranscoding()
     141{
     142    m_needsTranscoding = document()->decoder() && document()->decoder()->encoding().backslashAsCurrencySymbol() != '\\';
    136143}
    137144
     
    147154    }
    148155
     156    bool needsResetText = false;
     157    if (!oldStyle) {
     158        updateNeedsTranscoding();
     159        needsResetText = m_needsTranscoding;
     160    }
     161
    149162    ETextTransform oldTransform = oldStyle ? oldStyle->textTransform() : TTNONE;
    150163    ETextSecurity oldSecurity = oldStyle ? oldStyle->textSecurity() : TSNONE;
    151 
    152     if (oldTransform != style()->textTransform() || oldSecurity != style()->textSecurity()) {
     164    if (needsResetText || oldTransform != style()->textTransform() || oldSecurity != style()->textSecurity()) {
    153165        if (RefPtr<StringImpl> textToTransform = originalText())
    154166            setText(textToTransform.release(), true);
     
    961973}
    962974
    963 static inline bool isInlineFlowOrEmptyText(RenderObject* o)
     975static inline bool isInlineFlowOrEmptyText(const RenderObject* o)
    964976{
    965977    if (o->isRenderInline())
     
    973985}
    974986
    975 UChar RenderText::previousCharacter()
     987UChar RenderText::previousCharacter() const
    976988{
    977989    // find previous text renderer if one exists
    978     RenderObject* previousText = this;
     990    const RenderObject* previousText = this;
    979991    while ((previousText = previousText->previousInPreOrder()))
    980992        if (!isInlineFlowOrEmptyText(previousText))
     
    987999}
    9881000
     1001void RenderText::transformText(String& text) const
     1002{
     1003    ASSERT(style());
     1004    switch (style()->textTransform()) {
     1005    case TTNONE:
     1006        break;
     1007    case CAPITALIZE:
     1008        makeCapitalized(&text, previousCharacter());
     1009        break;
     1010    case UPPERCASE:
     1011        text.makeUpper();
     1012        break;
     1013    case LOWERCASE:
     1014        text.makeLower();
     1015        break;
     1016    }
     1017}
     1018
    9891019void RenderText::setTextInternal(PassRefPtr<StringImpl> text)
    9901020{
    9911021    ASSERT(text);
    992     m_text = document()->displayStringModifiedByEncoding(text);
     1022    if (m_needsTranscoding)
     1023        m_text = document()->displayStringModifiedByEncoding(text);
     1024    else
     1025        m_text = text;
    9931026    ASSERT(m_text);
    9941027
     
    10231056
    10241057    if (style()) {
    1025         switch (style()->textTransform()) {
    1026             case TTNONE:
    1027                 break;
    1028             case CAPITALIZE:
    1029                 makeCapitalized(&m_text, previousCharacter());
    1030                 break;
    1031             case UPPERCASE:
    1032                 m_text.makeUpper();
    1033                 break;
    1034             case LOWERCASE:
    1035                 m_text.makeLower();
    1036                 break;
    1037         }
     1058        transformText(m_text);
    10381059
    10391060        // We use the same characters here as for list markers.
    10401061        // See the listMarkerText function in RenderListMarker.cpp.
    10411062        switch (style()->textSecurity()) {
    1042             case TSNONE:
    1043                 break;
    1044             case TSCIRCLE:
    1045                 m_text.makeSecure(whiteBullet);
    1046                 break;
    1047             case TSDISC:
    1048                 m_text.makeSecure(bullet);
    1049                 break;
    1050             case TSSQUARE:
    1051                 m_text.makeSecure(blackSquare);
     1063        case TSNONE:
     1064            break;
     1065        case TSCIRCLE:
     1066            m_text.makeSecure(whiteBullet);
     1067            break;
     1068        case TSDISC:
     1069            m_text.makeSecure(bullet);
     1070            break;
     1071        case TSSQUARE:
     1072            m_text.makeSecure(blackSquare);
    10521073        }
    10531074    }
     
    10731094    if (axObjectCache->accessibilityEnabled())
    10741095        axObjectCache->contentChanged(this);
     1096}
     1097
     1098String RenderText::textWithoutTranscoding() const
     1099{
     1100    // If m_text isn't transcoded or is secure, we can just return the modified text.
     1101    if (!m_needsTranscoding || style()->textSecurity() != TSNONE)
     1102        return text();
     1103
     1104    // Otherwise, we should use original text. If text-transform is
     1105    // specified, we should transform the text on the fly.
     1106    String text = originalText();
     1107    if (style())
     1108        transformText(text);
     1109    return text;
    10751110}
    10761111
  • trunk/WebCore/rendering/RenderText.h

    r57215 r57940  
    5252
    5353    StringImpl* text() const { return m_text.impl(); }
     54    String textWithoutTranscoding() const;
    5455
    5556    InlineTextBox* createInlineTextBox();
     
    129130
    130131    virtual void setTextInternal(PassRefPtr<StringImpl>);
    131     virtual UChar previousCharacter();
     132    virtual UChar previousCharacter() const;
    132133   
    133134    virtual InlineTextBox* createTextBox(); // Subclassed by SVG.
     
    149150    int widthFromCache(const Font&, int start, int len, int xPos, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow*) const;
    150151    bool isAllASCII() const { return m_isAllASCII; }
     152    void updateNeedsTranscoding();
     153
     154    inline void transformText(String&) const;
    151155
    152156    int m_minWidth; // here to minimize padding in 64-bit.
     
    173177    bool m_isAllASCII : 1;
    174178    mutable bool m_knownToHaveNoOverflowAndNoFallbackFonts : 1;
     179    bool m_needsTranscoding : 1;
    175180};
    176181
  • trunk/WebCore/rendering/RenderTextControl.cpp

    r56885 r57940  
    168168void RenderTextControl::setInnerTextValue(const String& innerTextValue)
    169169{
    170     String value;
    171 
    172     if (innerTextValue.isNull())
    173         value = "";
    174     else {
    175         value = innerTextValue;
    176         value = document()->displayStringModifiedByEncoding(value);
    177     }
    178 
     170    String value = innerTextValue;
    179171    if (value != text() || !m_innerText->hasChildNodes()) {
    180172        if (value != text()) {
     
    319311        result.shrink(--size);
    320312
    321     // Convert backslash to currency symbol.
    322     document()->displayBufferModifiedByEncoding(result.data(), result.size());
    323    
    324313    return String::adopt(result);
    325314}
  • trunk/WebCore/rendering/RenderTextFragment.cpp

    r55196 r57940  
    7777}
    7878
    79 UChar RenderTextFragment::previousCharacter()
     79UChar RenderTextFragment::previousCharacter() const
    8080{
    8181    if (start()) {
  • trunk/WebCore/rendering/RenderTextFragment.h

    r25754 r57940  
    5252private:
    5353    virtual void setTextInternal(PassRefPtr<StringImpl>);
    54     virtual UChar previousCharacter();
     54    virtual UChar previousCharacter() const;
    5555
    5656    unsigned m_start;
Note: See TracChangeset for help on using the changeset viewer.