LayoutTests:
Test by Andrew Wellington <proton@wiretapped.net>.
Reviewed by Darin.
- test for fix to http://bugs.webkit.org/show_bug.cgi?id=11197
REGRESSION: Specifying a counter for a CODE tag's content style
property on before or after causes a crash.
* 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>.
- fix http://bugs.webkit.org/show_bug.cgi?id=11197
REGRESSION: Specifying a counter for a CODE tag's content style property
on before or after causes a crash.
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.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@19027 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/rendering/bidi.cpp b/WebCore/rendering/bidi.cpp
index 136e5be..1c0adee 100644
--- a/WebCore/rendering/bidi.cpp
+++ b/WebCore/rendering/bidi.cpp
@@ -372,7 +372,7 @@
return;
if (obj->isText()) {
pos++;
- if (pos >= static_cast<RenderText *>(obj)->stringLength()) {
+ if (pos >= static_cast<RenderText *>(obj)->textLength()) {
obj = bidiNext(block, obj, bidi);
pos = 0;
}
@@ -393,10 +393,10 @@
return 0;
RenderText* text = static_cast<RenderText*>(obj);
- if (!text->text())
+ if (!text->characters())
return 0;
- return text->text()[pos];
+ return text->characters()[pos];
}
ALWAYS_INLINE Direction BidiIterator::direction() const
@@ -408,9 +408,9 @@
if (!obj->isText())
return OtherNeutral;
RenderText* renderTxt = static_cast<RenderText*>(obj);
- if (pos >= renderTxt->stringLength())
+ if (pos >= renderTxt->textLength())
return OtherNeutral;
- return Unicode::direction(renderTxt->text()[pos]);
+ return Unicode::direction(renderTxt->characters()[pos]);
}
// -------------------------------------------------------------------------------------------------
@@ -429,9 +429,9 @@
// Compute the number of spaces in this run,
if (bidiRun->obj && bidiRun->obj->isText()) {
RenderText* text = static_cast<RenderText*>(bidiRun->obj);
- if (text->text()) {
+ if (text->characters()) {
for (int i = bidiRun->start; i < bidiRun->stop; i++) {
- UChar c = text->text()[i];
+ UChar c = text->characters()[i];
if (c == ' ' || c == '\n' || c == '\t')
numSpaces++;
}
@@ -521,12 +521,12 @@
if (endpoint.obj->isText()) {
// Don't shave a character off the endpoint if it was from a soft hyphen.
RenderText* textObj = static_cast<RenderText*>(endpoint.obj);
- if (endpoint.pos+1 < textObj->length()) {
- if (textObj->text()[endpoint.pos+1] == SOFT_HYPHEN)
+ if (endpoint.pos + 1 < textObj->textLength()) {
+ if (textObj->characters()[endpoint.pos+1] == softHyphen)
return;
} else if (startpoint.obj->isText()) {
RenderText *startText = static_cast<RenderText*>(startpoint.obj);
- if (startText->length() > 0 && startText->text()[0] == SOFT_HYPHEN)
+ if (startText->textLength() && startText->characters()[0] == softHyphen)
return;
}
}
@@ -875,11 +875,11 @@
RenderText* rt = static_cast<RenderText*>(r->obj);
int textWidth = rt->width(r->start, r->stop-r->start, totWidth, m_firstLine);
int effectiveWidth = textWidth;
- int rtLength = rt->length();
+ int rtLength = rt->textLength();
if (rtLength != 0) {
- if (r->start == 0 && needsWordSpacing && DeprecatedChar(rt->text()[r->start]).isSpace())
- effectiveWidth += rt->font(m_firstLine)->wordSpacing();
- needsWordSpacing = !DeprecatedChar(rt->text()[r->stop-1]).isSpace() && r->stop == rtLength;
+ if (r->start == 0 && needsWordSpacing && DeprecatedChar(rt->characters()[r->start]).isSpace())
+ effectiveWidth += rt->style(m_firstLine)->font().wordSpacing();
+ needsWordSpacing = !DeprecatedChar(rt->characters()[r->stop-1]).isSpace() && r->stop == rtLength;
}
r->box->setWidth(textWidth);
} else if (!r->obj->isInlineFlow()) {
@@ -950,7 +950,7 @@
// get the number of spaces in the run
int spaces = 0;
for ( int i = r->start; i < r->stop; i++ ) {
- UChar c = static_cast<RenderText*>(r->obj)->text()[i];
+ UChar c = static_cast<RenderText*>(r->obj)->characters()[i];
if (c == ' ' || c == '\n' || c == '\t')
spaces++;
}
@@ -1921,7 +1921,7 @@
int w = lineWidth(m_height);
while (!it.atEnd() && (it.obj->isInlineFlow() || (shouldCollapseWhiteSpace(it.obj->style()) && !it.obj->isBR() &&
(it.current() == ' ' || it.current() == '\t' || (!it.obj->style()->preserveNewline() && it.current() == '\n') ||
- it.current() == SOFT_HYPHEN || skipNonBreakingSpace(it) || it.obj->isFloatingOrPositioned())))) {
+ it.current() == softHyphen || skipNonBreakingSpace(it) || it.obj->isFloatingOrPositioned())))) {
if (it.obj->isFloatingOrPositioned()) {
RenderObject *o = it.obj;
// add to special objects...
@@ -2115,9 +2115,9 @@
// Optimize for a common case. If we can't find whitespace after the list
// item, then this is all moot. -dwh
RenderObject* next = bidiNext(start.block, o, bidi);
- if (style()->collapseWhiteSpace() && next && !next->isBR() && next->isText() && static_cast<RenderText*>(next)->stringLength() > 0) {
+ if (style()->collapseWhiteSpace() && next && !next->isBR() && next->isText() && static_cast<RenderText*>(next)->textLength() > 0) {
RenderText *nextText = static_cast<RenderText*>(next);
- UChar nextChar = nextText->text()[0];
+ UChar nextChar = nextText->characters()[0];
if (nextText->style()->isCollapsibleWhiteSpace(nextChar)) {
currentCharacterIsSpace = true;
currentCharacterIsWS = true;
@@ -2130,11 +2130,11 @@
tmpW += o->width() + o->marginLeft() + o->marginRight() + inlineWidth(o);
} else if (o->isText()) {
RenderText *t = static_cast<RenderText *>(o);
- int strlen = t->stringLength();
+ int strlen = t->textLength();
int len = strlen - pos;
- const UChar* str = t->text();
+ const UChar* str = t->characters();
- const Font *f = t->font(m_firstLine);
+ const Font& f = t->style(m_firstLine)->font();
// proportional font, needs a bit more work.
int lastSpace = pos;
int wordSpacing = o->style()->wordSpacing();
@@ -2155,14 +2155,14 @@
isLineEmpty = false;
// Check for soft hyphens. Go ahead and ignore them.
- if (c == SOFT_HYPHEN) {
+ if (c == softHyphen) {
if (!ignoringSpaces) {
// Ignore soft hyphens
BidiIterator endMid;
if (pos > 0)
endMid = BidiIterator(0, o, pos-1);
else
- endMid = BidiIterator(0, previous, previous->isText() ? static_cast<RenderText *>(previous)->stringLength() - 1 : 0);
+ endMid = BidiIterator(0, previous, previous->isText() ? static_cast<RenderText *>(previous)->textLength() - 1 : 0);
// Two consecutive soft hyphens. Avoid overlapping midpoints.
if (sNumMidpoints && smidpoints->at(sNumMidpoints - 1).obj == endMid.obj && smidpoints->at(sNumMidpoints - 1).pos > endMid.pos)
sNumMidpoints--;
@@ -2273,7 +2273,7 @@
}
}
if (lineWasTooWide || w + tmpW > width) {
- if (lBreak.obj && lBreak.obj->style()->preserveNewline() && lBreak.obj->isText() && static_cast<RenderText*>(lBreak.obj)->text()[lBreak.pos] == '\n') {
+ if (lBreak.obj && lBreak.obj->style()->preserveNewline() && lBreak.obj->isText() && static_cast<RenderText*>(lBreak.obj)->characters()[lBreak.pos] == '\n') {
if (!stoppedIgnoringSpaces && pos > 0) {
// We need to stop right before the newline and then start up again.
BidiIterator midpoint(0, o, pos);
@@ -2287,7 +2287,7 @@
} else {
if (midWordBreak)
tmpW -= additionalTmpW;
- if (pos > 0 && str[pos-1] == SOFT_HYPHEN)
+ if (pos > 0 && str[pos-1] == softHyphen)
// Subtract the width of the soft hyphen out since we fit on a line.
tmpW -= t->width(pos-1, 1, f, w+tmpW);
}
@@ -2388,8 +2388,8 @@
else {
checkForBreak = false;
RenderText* nextText = static_cast<RenderText*>(next);
- if (nextText->stringLength() != 0) {
- UChar c = nextText->text()[0];
+ if (nextText->textLength() != 0) {
+ UChar c = nextText->characters()[0];
if (c == ' ' || c == '\t' || (c == '\n' && !next->style()->preserveNewline()))
// If the next item on the line is text, and if we did not end with
// a space, then the next text run continues our word (and so it needs to
@@ -2510,7 +2510,8 @@
else if (lBreak.obj == 0 && trailingSpaceObject->isText()) {
// Add a new end midpoint that stops right at the very end.
RenderText* text = static_cast<RenderText *>(trailingSpaceObject);
- unsigned pos = text->length() >=2 ? text->length() - 2 : UINT_MAX;
+ unsigned length = text->textLength();
+ unsigned pos = length >= 2 ? length - 2 : UINT_MAX;
BidiIterator endMid(0, trailingSpaceObject, pos);
addMidpoint(endMid);
}
@@ -2528,8 +2529,8 @@
if (lBreak.obj && lBreak.pos >= 2 && lBreak.obj->isText()) {
// For soft hyphens on line breaks, we have to chop out the midpoints that made us
// ignore the hyphen so that it will render at the end of the line.
- UChar c = static_cast<RenderText*>(lBreak.obj)->text()[lBreak.pos-1];
- if (c == SOFT_HYPHEN)
+ UChar c = static_cast<RenderText*>(lBreak.obj)->characters()[lBreak.pos-1];
+ if (c == softHyphen)
chopMidpointsAt(lBreak.obj, lBreak.pos-2);
}