Show
Ignore:
Timestamp:
01/22/07 09:28:57 (2 years ago)
Author:
darin
Message:

LayoutTests:

Test by Andrew Wellington <proton@wiretapped.net>.
Reviewed by Darin.


  • fast/css/beforeSelectorOnCodeElement-expected.checksum: Added.
  • fast/css/beforeSelectorOnCodeElement-expected.png: Added.
  • fast/css/beforeSelectorOnCodeElement-expected.txt: Added.
  • fast/css/beforeSelectorOnCodeElement.html: Added.

Test by Mitz.
Reviewed by Darin.

  • test for monospace problem mentioned in the above bug


  • fast/text/monospace-width-cache-expected.checksum: Added.
  • fast/text/monospace-width-cache-expected.png: Added.
  • fast/text/monospace-width-cache-expected.txt: Added.
  • fast/text/monospace-width-cache.html: Added.

WebCore:

Reviewed by Mitz.

Inspired by a much simpler patch by Andrew Wellington <proton@wiretapped.net>.

Test: fast/css/beforeSelectorOnCodeElement.html

  • fix regression I recently introduced where the monospace cache could be used for text that was not ASCII, if text was changed after the style was set

Test: fast/text/monospace-width-cache.html

  • streamline RenderText.h -- remove unneeded functions, make some needlessly virtual functions non-virtual, remove unneeded header includes, replace use of Font* with Font& for consistency with RenderStyle, use "text" consistently instead of "string"
  • rendering/RenderText.h: Removed unneeded include of "Text.h", declarations of SOFT_HYPHEN, DocumentMarker, InlineBox, Position, String. Got rid of friend declaration for InlineTextBox. Changed constructor to take a PassRefPtr since we do take owership of the passed-in text. Made deleteTextBoxes() private. Removed unneeded data(). Made override of length() private so people will use the faster textLength() instead. Renamed string() to text() so it matches up better with setText(). Same for stringLength(), originalString(), and setInternalString(), which are now textLength(), originalText(), and setTextInternal(). Renamed the old text() function to characters(), since it returns a pointer as StringImpl::characters does. Changed Font* to Font& everywhere. Renamed the internal calcMinMaxWidth() function to calcMinMaxWidthInternal() and made it non-virtual since it's not overriden anywhere. Also made the trimmedMinMaxWidth() function non-virtual. Made containsOnlyWhitespace() private. Removed both font() functions (one was needlessly virtual) and element(). Renamed cacheWidths() to updateMonospaceCharacterWidth() and removed the shouldUseMonospaceCache() function. Renamed allAscii() to isAllASCII() and made it an inline function. Removed the m_allAsciiChecked flag and renamed the m_allAscii flag to m_isAllASCII.
  • rendering/RenderText.cpp: (WebCore::RenderText::RenderText): Removed initialization of m_allAsciiChecked. Initialize m_isAllASCII. Changed all occurrences of m_str->length() and m_str->characters () to use the stringLength() and characters() inline functions instead. (WebCore::RenderText::setStyle): Replaced the unconditional call to cacheWidths with a conditional call to updateMonospaceCharacterWidth. This speeds up the common case where style is changed without changing the font. (WebCore::RenderText::originalText): Changed code to not depend on overridden element() function with casts to a Text node -- this was one of only two call sites. Also renamed. (WebCore::RenderText::positionForCoordinates): Name change. (WebCore::RenderText::caretRect): Ditto. (WebCore::RenderText::updateMonospaceCharacterWidth): Renamed from cacheWidths and incorporate the check that was formerly in a separate shouldUseMonospaceCache function. (WebCore::RenderText::widthFromCache): Changed to take a Font& instead of Font*. Changed to take advantage of the fact that the string is known to be all ASCII in the m_monospaceCharacterWidth code path. (WebCore::RenderText::trimmedMinMaxWidth): Ditto. Also use style()->font() instead of font(false). (WebCore::RenderText::calcMinMaxWidth): Ditto. Also changed to use softHyphen instead of SOFT_HYPHEN. (WebCore::RenderText::containsOnlyWhitespace): More of the same. (WebCore::RenderText::setSelectionState): Ditto. (WebCore::RenderText::setTextWithOffset): Ditto. (WebCore::isInlineFlowOrEmptyText): Ditto. (WebCore::RenderText::setTextInternal): Updated for name changes. Also changed to set the m_isAllASCII flag every time, in the more-efficient way we use elsewhere (or'ing all the characters together), and to call updateMonospaceCharacterWidth if the "all ASCII"-ness of the text changes. (WebCore::RenderText::setText): Updated for name changes. (WebCore::RenderText::width): More like above. (WebCore::RenderText::selectionRect): Ditto. (WebCore::RenderText::caretMaxOffset): Ditto. (WebCore::RenderText::previousOffset): Ditto. (WebCore::RenderText::nextOffset): Ditto.
  • dom/Position.cpp:
  • dom/Range.cpp:
  • editing/CompositeEditCommand.cpp:
  • editing/DeleteSelectionCommand.cpp:
  • editing/VisiblePosition.cpp:
  • html/HTMLElement.cpp: Added now-needed include of "Text.h" which is no longer included by "RenderText.h".
  • editing/SelectionController.cpp: (WebCore::SelectionController::debugRenderer):
  • editing/TextIterator.cpp: (WebCore::TextIterator::handleTextNode): (WebCore::TextIterator::handleTextBox): (WebCore::SimplifiedBackwardsTextIterator::handleTextNode): Update for name changes of stringLength(), string(), and originalString() to textLength(), text(), and originalText(), and to always use textLength() instead of length() when we have a RenderText* rather than a RenderObject*.
  • editing/visible_units.cpp: (WebCore::startOfParagraph): Ditto. (WebCore::endOfParagraph): Ditto.
  • rendering/InlineFlowBox.cpp: (WebCore::InlineFlowBox::placeBoxesHorizontally): Ditto. Also removed use of the RenderObject::font() function and replaced it with explicit access to the style. (WebCore::InlineFlowBox::placeBoxesVertically): Ditto.
  • rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::selectionRect): Ditto. (WebCore::InlineTextBox::isLineBreak): Ditto. (WebCore::InlineTextBox::paint): Ditto. (WebCore::InlineTextBox::selectionStartEnd): Ditto. (WebCore::InlineTextBox::paintSelection): Ditto. (WebCore::InlineTextBox::paintMarkedTextBackground): Ditto. (WebCore::InlineTextBox::paintSpellingOrGrammarMarker): Ditto. (WebCore::InlineTextBox::paintTextMatchMarker): Ditto. (WebCore::InlineTextBox::offsetForPosition): Ditto. (WebCore::InlineTextBox::positionForOffset): Ditto.
  • rendering/RenderContainer.cpp: (WebCore::RenderContainer::addChild): Ditto.
  • rendering/RenderCounter.cpp: (WebCore::RenderCounter::originalText): Ditto. (WebCore::RenderCounter::calcMinMaxWidth): Ditto.
  • rendering/RenderCounter.h: Ditto.
  • rendering/RenderTextFragment.cpp: (WebCore::RenderTextFragment::originalText): Ditto.
  • rendering/RenderTextFragment.h: Ditto.
  • rendering/SVGInlineFlowBox.cpp: (WebCore::placePositionedBoxesHorizontally): Ditto. (WebCore::placeBoxesVerticallyWithAbsBaseline): Ditto.
  • rendering/bidi.cpp: (WebCore::BidiIterator::increment): Ditto. (WebCore::BidiIterator::current): Ditto. (WebCore::BidiIterator::direction): Ditto. (WebCore::addRun): Ditto. (WebCore::checkMidpoints): Ditto. (WebCore::RenderBlock::computeHorizontalPositionsForLine): Ditto. (WebCore::RenderBlock::skipWhitespace): Ditto. (WebCore::RenderBlock::findNextLineBreak): Ditto.
  • rendering/RenderBR.h: Updated signature of width function which now takes a Font& instead of a Font*.
  • rendering/RenderBlock.cpp: (WebCore::stripTrailingSpace): Updated to no longer use the RenderObject::font() function, and added a comment about first-line, which is not handled properly here.
  • rendering/RenderMenuList.cpp: (WebCore::RenderMenuList::text):
  • rendering/RenderTreeAsText.cpp: (WebCore::writeTextRun): Eliminated use of RenderText::data().
  • rendering/RenderObject.h: Removed RenderObject::font(). This had the bad effect of having everyone pass in a boolean rather than using the cleaner style() and firstLineStyle() functions in cases where there's no a firstLineStyle boolean.
  • rendering/RenderObject.cpp: (WebCore::RenderObject::getVerticalPosition): Replaced use of RenderObject::font() with direct use of the style instead, which is arguably easier to understand anyway. (WebCore::RenderObject::baselinePosition): Ditto.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/rendering/RenderText.h

    r18724 r19027  
    2525 
    2626#include "RenderObject.h" 
    27 #include "Text.h" 
    2827 
    2928namespace WebCore { 
    3029 
    31 // Define a constant for soft hyphen's unicode value. 
    32 const unsigned short SOFT_HYPHEN = 173; 
    33  
    34 class DocumentMarker; 
    35 class InlineBox; 
    3630class InlineTextBox; 
    37 class Position; 
    38 class String; 
    3931class StringImpl; 
    4032 
    4133class RenderText : public RenderObject { 
    42     friend class InlineTextBox; 
    4334public: 
    44     RenderText(Node*, StringImpl*); 
     35    RenderText(Node*, PassRefPtr<StringImpl>); 
    4536 
    4637    virtual const char* renderName() const { return "RenderText"; } 
     
    4839    virtual bool isTextFragment() const { return false; } 
    4940 
    50     virtual PassRefPtr<StringImpl> originalString() const; 
     41    virtual PassRefPtr<StringImpl> originalText() const; 
    5142 
    5243    virtual void setStyle(RenderStyle*); 
     
    5546    void attachTextBox(InlineTextBox*); 
    5647    void removeTextBox(InlineTextBox*); 
    57     void deleteTextBoxes(); 
     48 
    5849    virtual void destroy(); 
    5950 
    60     String data() const { return m_str.get(); } 
    61     StringImpl* string() const { return m_str.get(); } 
     51    StringImpl* text() const { return m_text.get(); } 
    6252 
    63     virtual InlineBox* createInlineBox(bool,bool, bool isOnlyRun = false); 
     53    virtual InlineBox* createInlineBox(bool makePlaceHolderBox, bool isRootLineBox, bool isOnlyRun = false); 
    6454    virtual void dirtyLineBoxes(bool fullLayout, bool isRootInlineBox = false); 
    6555 
     
    7464    virtual VisiblePosition positionForCoordinates(int x, int y); 
    7565 
    76     virtual unsigned length() const { return m_str->length(); } 
    77     const UChar* text() const { return m_str->characters(); } 
    78     unsigned stringLength() const { return m_str->length(); } // non virtual implementation of length() 
     66    const UChar* characters() const { return m_text->characters(); } 
     67    unsigned textLength() const { return m_text->length(); } // non virtual implementation of length() 
    7968    virtual void position(InlineBox*); 
    8069 
    81     virtual unsigned width(unsigned from, unsigned len, const Font*, int xPos) const; 
     70    virtual unsigned width(unsigned from, unsigned len, const Font&, int xPos) const; 
    8271    virtual unsigned width(unsigned from, unsigned len, int xPos, bool firstLine = false) const; 
    8372    virtual int width() const; 
     
    8675    virtual short lineHeight(bool firstLine, bool isRootLineBox = false) const; 
    8776 
    88     // overrides 
    8977    virtual void calcMinMaxWidth(); 
    9078    virtual int minWidth() const { return m_minWidth; } 
    9179    virtual int maxWidth() const { return m_maxWidth; } 
    9280 
    93     // widths 
    94     void calcMinMaxWidth(int leadWidth); 
    95     virtual void trimmedMinMaxWidth(int leadWidth, 
    96                                     int& beginMinW, bool& beginWS, 
    97                                     int& endMinW, bool& endWS, 
    98                                     bool& hasBreakableChar, bool& hasBreak, 
    99                                     int& beginMaxW, int& endMaxW, 
    100                                     int& minW, int& maxW, bool& stripFrontSpaces); 
    101  
    102     bool containsOnlyWhitespace(unsigned from, unsigned len) const; 
     81    void trimmedMinMaxWidth(int leadWidth, 
     82                            int& beginMinW, bool& beginWS, 
     83                            int& endMinW, bool& endWS, 
     84                            bool& hasBreakableChar, bool& hasBreak, 
     85                            int& beginMaxW, int& endMaxW, 
     86                            int& minW, int& maxW, bool& stripFrontSpaces); 
    10387 
    10488    // returns the minimum x position of all runs relative to the parent. 
     
    10993    virtual int yPos() const; 
    11094 
    111     virtual const Font& font(); 
    11295    virtual short verticalPositionHint(bool firstLine) const; 
    11396 
     
    125108 
    126109    virtual IntRect getAbsoluteRepaintRect(); 
    127  
    128     const Font* font(bool firstLine) const; 
    129  
    130     Text* element() const { return static_cast<Text*>(RenderObject::element()); } 
    131110 
    132111    InlineTextBox* firstTextBox() const { return m_firstTextBox; } 
     
    147126 
    148127protected: 
    149     void setInternalString(PassRefPtr<StringImpl>); 
     128    void setTextInternal(PassRefPtr<StringImpl>); 
    150129 
    151130private: 
    152     void cacheWidths(); 
    153     int widthFromCache(const Font*, int start, int len, int tabWidth, int xPos) const; 
    154     bool shouldUseMonospaceCache(const Font*) const; 
    155     bool allAscii() const; 
     131    // Make length() private so that callers that have a RenderText* 
     132    // will use the more efficient textLength() instead, while 
     133    // callers with a RenderObject* can continue to use length(). 
     134    virtual unsigned length() const { return textLength(); } 
    156135 
    157     // members 
    158     RefPtr<StringImpl> m_str; 
     136    void deleteTextBoxes(); 
     137    bool containsOnlyWhitespace(unsigned from, unsigned len) const; 
     138    void calcMinMaxWidthInternal(int leadWidth); 
     139 
     140    void updateMonospaceCharacterWidth(); 
     141    int widthFromCache(const Font&, int start, int len, int tabWidth, int xPos) const; 
     142    bool isAllASCII() const { return m_isAllASCII; } 
     143 
     144    RefPtr<StringImpl> m_text; 
    159145 
    160146    InlineTextBox* m_firstTextBox; 
     
    172158    bool m_hasBeginWS : 1; // Whether or not we begin with WS (only true if we aren't pre) 
    173159    bool m_hasEndWS : 1; // Whether or not we end with WS (only true if we aren't pre) 
    174  
    175160    bool m_linesDirty : 1; // This bit indicates that the text run has already dirtied specific 
    176161                           // line boxes, and this hint will enable layoutInlineChildren to avoid 
     
    178163                           // or removed). 
    179164    bool m_containsReversedText : 1; 
     165    bool m_isAllASCII : 1; 
    180166 
    181     // 22 bits left 
    182     mutable bool m_allAsciiChecked:1; 
    183     mutable bool m_allAscii:1; 
    184167    int m_monospaceCharacterWidth; 
    185168};