diff options
Diffstat (limited to 'WebCore/rendering/InlineTextBox.cpp')
-rw-r--r-- | WebCore/rendering/InlineTextBox.cpp | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/WebCore/rendering/InlineTextBox.cpp b/WebCore/rendering/InlineTextBox.cpp index 2fc5823..09825b6 100644 --- a/WebCore/rendering/InlineTextBox.cpp +++ b/WebCore/rendering/InlineTextBox.cpp @@ -1,7 +1,7 @@ /* * (C) 1999 Lars Knoll (knoll@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -103,6 +103,18 @@ RenderObject::SelectionState InlineTextBox::selectionState() return state; } +typedef Vector<UChar, 256> BufferForAppendingHyphen; + +static void adjustCharactersAndLengthForHyphen(BufferForAppendingHyphen& charactersWithHyphen, RenderStyle* style, const UChar*& characters, int& length) +{ + const AtomicString& hyphenString = style->hyphenString(); + charactersWithHyphen.reserveCapacity(length + hyphenString.length()); + charactersWithHyphen.append(characters, length); + charactersWithHyphen.append(hyphenString.characters(), hyphenString.length()); + characters = charactersWithHyphen.data(); + length += hyphenString.length(); +} + IntRect InlineTextBox::selectionRect(int tx, int ty, int startPos, int endPos) { int sPos = max(startPos - m_start, 0); @@ -114,9 +126,18 @@ IntRect InlineTextBox::selectionRect(int tx, int ty, int startPos, int endPos) RenderText* textObj = textRenderer(); int selTop = selectionTop(); int selHeight = selectionHeight(); - const Font& f = textObj->style(m_firstLine)->font(); + RenderStyle* styleToUse = textObj->style(m_firstLine); + const Font& f = styleToUse->font(); + + const UChar* characters = textObj->text()->characters() + m_start; + int len = m_len; + BufferForAppendingHyphen charactersWithHyphen; + if (ePos == len && hasHyphen()) { + adjustCharactersAndLengthForHyphen(charactersWithHyphen, styleToUse, characters, len); + ePos = len; + } - IntRect r = enclosingIntRect(f.selectionRectForText(TextRun(textObj->text()->characters() + m_start, m_len, textObj->allowTabs(), textPos(), m_toAdd, direction() == RTL, m_dirOverride), + IntRect r = enclosingIntRect(f.selectionRectForText(TextRun(characters, len, textObj->allowTabs(), textPos(), m_toAdd, direction() == RTL, m_dirOverride), IntPoint(tx + m_x, ty + selTop), selHeight, sPos, ePos)); if (r.x() > tx + m_x + m_width) r.setWidth(0); @@ -476,16 +497,21 @@ void InlineTextBox::paint(RenderObject::PaintInfo& paintInfo, int tx, int ty) } } + const UChar* characters = textRenderer()->text()->characters() + m_start; + int length = m_len; + BufferForAppendingHyphen charactersWithHyphen; + if (hasHyphen()) + adjustCharactersAndLengthForHyphen(charactersWithHyphen, styleToUse, characters, length); + int baseline = renderer()->style(m_firstLine)->font().ascent(); IntPoint textOrigin(m_x + tx, m_y + ty + baseline); - TextRun textRun(textRenderer()->text()->characters() + m_start, m_len, textRenderer()->allowTabs(), textPos(), m_toAdd, direction() == RTL, m_dirOverride || styleToUse->visuallyOrdered()); + TextRun textRun(characters, length, textRenderer()->allowTabs(), textPos(), m_toAdd, direction() == RTL, m_dirOverride || styleToUse->visuallyOrdered()); int sPos = 0; int ePos = 0; if (paintSelectedTextOnly || paintSelectedTextSeparately) selectionStartEnd(sPos, ePos); - int length = m_len; if (m_truncation != cNoTruncation) { sPos = min<int>(sPos, m_truncation); ePos = min<int>(ePos, m_truncation); @@ -600,8 +626,16 @@ void InlineTextBox::paintSelection(GraphicsContext* context, int tx, int ty, Ren // If the text is truncated, let the thing being painted in the truncation // draw its own highlight. int length = m_truncation != cNoTruncation ? m_truncation : m_len; + const UChar* characters = textRenderer()->text()->characters() + m_start; + + BufferForAppendingHyphen charactersWithHyphen; + if (ePos == length && hasHyphen()) { + adjustCharactersAndLengthForHyphen(charactersWithHyphen, style, characters, length); + ePos = length; + } + context->clip(IntRect(m_x + tx, y + ty, m_width, h)); - context->drawHighlightForText(font, TextRun(textRenderer()->text()->characters() + m_start, length, textRenderer()->allowTabs(), textPos(), m_toAdd, + context->drawHighlightForText(font, TextRun(characters, length, textRenderer()->allowTabs(), textPos(), m_toAdd, direction() == RTL, m_dirOverride || style->visuallyOrdered()), IntPoint(m_x + tx, y + ty), h, c, style->colorSpace(), sPos, ePos); context->restore(); |