#include "config.h"
#include "InlineTextBox.h"
#include "Document.h"
#include "Editor.h"
#include "Frame.h"
#include "GraphicsContext.h"
#include "HitTestResult.h"
#include "RenderArena.h"
#include "RenderBlock.h"
#include "RenderTheme.h"
#include "Text.h"
#include "break_lines.h"
#include <wtf/AlwaysInline.h>
using namespace std;
namespace WebCore {
int InlineTextBox::selectionTop()
{
return root()->selectionTop();
}
int InlineTextBox::selectionHeight()
{
return root()->selectionHeight();
}
bool InlineTextBox::isSelected(int startPos, int endPos) const
{
int sPos = max(startPos - m_start, 0);
int ePos = min(endPos - m_start, (int)m_len);
return (sPos < ePos);
}
RenderObject::SelectionState InlineTextBox::selectionState()
{
RenderObject::SelectionState state = object()->selectionState();
if (state == RenderObject::SelectionStart || state == RenderObject::SelectionEnd || state == RenderObject::SelectionBoth) {
int startPos, endPos;
object()->selectionStartEnd(startPos, endPos);
int lastSelectable = start() + len() - (isLineBreak() ? 1 : 0);
bool start = (state != RenderObject::SelectionEnd && startPos >= m_start && startPos < m_start + m_len);
bool end = (state != RenderObject::SelectionStart && endPos > m_start && endPos <= lastSelectable);
if (start && end)
state = RenderObject::SelectionBoth;
else if (start)
state = RenderObject::SelectionStart;
else if (end)
state = RenderObject::SelectionEnd;
else if ((state == RenderObject::SelectionEnd || startPos < m_start) &&
(state == RenderObject::SelectionStart || endPos > lastSelectable))
state = RenderObject::SelectionInside;
else if (state == RenderObject::SelectionBoth)
state = RenderObject::SelectionNone;
}
return state;
}
IntRect InlineTextBox::selectionRect(int tx, int ty, int startPos, int endPos)
{
int sPos = max(startPos - m_start, 0);
int ePos = min(endPos - m_start, (int)m_len);
if (sPos >= ePos)
return IntRect();
RenderText* textObj = textObject();
int selTop = selectionTop();
int selHeight = selectionHeight();
const Font& f = textObj->style(m_firstLine)->font();
IntRect r = enclosingIntRect(f.selectionRectForText(TextRun(textObj->text()->characters() + m_start, m_len, textObj->allowTabs(), textPos(), m_toAdd, m_reversed, m_dirOverride),
IntPoint(tx + m_x, ty + selTop), selHeight, sPos, ePos));
if (r.x() > tx + m_x + m_width)
r.setWidth(0);
else if (r.right() - 1 > tx + m_x + m_width)
r.setWidth(tx + m_x + m_width - r.x());
return r;
}
void InlineTextBox::deleteLine(RenderArena* arena)
{
static_cast<RenderText*>(m_object)->removeTextBox(this);
destroy(arena);
}
void InlineTextBox::extractLine()
{
if (m_extracted)
return;
static_cast<RenderText*>(m_object)->extractTextBox(this);
}
void InlineTextBox::attachLine()
{
if (!m_extracted)
return;
static_cast<RenderText*>(m_object)->attachTextBox(this);
}
int InlineTextBox::placeEllipsisBox(bool ltr, int blockEdge, int ellipsisWidth, bool& foundBox)
{
if (foundBox) {
m_truncation = cFullTruncation;
return -1;
}
int ellipsisX = ltr ? blockEdge - ellipsisWidth : blockEdge + ellipsisWidth;
if (ltr) {
if (ellipsisX <= m_x) {
m_truncation = cFullTruncation;
foundBox = true;
return -1;
}
if (ellipsisX < m_x + m_width) {
if (m_reversed)
return -1;
foundBox = true;
int offset = offsetForPosition(ellipsisX, false);
if (offset == 0) {
m_truncation = cFullTruncation;
return min(ellipsisX, m_x);
}
m_truncation = offset;
return m_x + static_cast<RenderText*>(m_object)->width(m_start, offset, textPos(), m_firstLine);
}
}
else {
}
return -1;
}
Color correctedTextColor(Color textColor, Color backgroundColor)
{
int d = differenceSquared(textColor, backgroundColor);
if (d > 65025) {
return textColor;
}
int distanceFromWhite = differenceSquared(textColor, Color::white);
int distanceFromBlack = differenceSquared(textColor, Color::black);
if (distanceFromWhite < distanceFromBlack) {
return textColor.dark();
}
return textColor.light();
}
void updateGraphicsContext(GraphicsContext* context, const Color& fillColor, const Color& strokeColor, float strokeThickness)
{
int mode = context->textDrawingMode();
if (strokeThickness > 0) {
int newMode = mode | cTextStroke;
if (mode != newMode) {
context->setTextDrawingMode(newMode);
mode = newMode;
}
}
if (mode & cTextFill && fillColor != context->fillColor())
context->setFillColor(fillColor);
if (mode & cTextStroke) {
if (strokeColor != context->strokeColor())
context->setStrokeColor(strokeColor);
if (strokeThickness != context->strokeThickness())
context->setStrokeThickness(strokeThickness);
}
}
bool InlineTextBox::isLineBreak() const
{
return object()->isBR() || (object()->style()->preserveNewline() && len() == 1 && (*textObject()->text())[start()] == '\n');
}
bool InlineTextBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, int x, int y, int tx, int ty)
{
if (isLineBreak())
return false;
IntRect rect(tx + m_x, ty + m_y, m_width, m_height);
if (m_truncation != cFullTruncation && object()->style()->visibility() == VISIBLE && rect.contains(x, y)) {
object()->updateHitTestResult(result, IntPoint(x - tx, y - ty));
return true;
}
return false;
}
void InlineTextBox::paint(RenderObject::PaintInfo& paintInfo, int tx, int ty)
{
if (isLineBreak() || !object()->shouldPaintWithinRoot(paintInfo) || object()->style()->visibility() != VISIBLE ||
m_truncation == cFullTruncation || paintInfo.phase == PaintPhaseOutline)
return;
ASSERT(paintInfo.phase != PaintPhaseSelfOutline && paintInfo.phase != PaintPhaseChildOutlines);
int xPos = tx + m_x - parent()->maxHorizontalVisualOverflow();
int w = width() + 2 * parent()->maxHorizontalVisualOverflow();
if (xPos >= paintInfo.rect.right() || xPos + w <= paintInfo.rect.x())
return;
bool isPrinting = textObject()->document()->printing();
bool haveSelection = !isPrinting && selectionState() != RenderObject::SelectionNone;
if (!haveSelection && paintInfo.phase == PaintPhaseSelection)
return;
bool containsComposition = object()->document()->frame()->editor()->compositionNode() == object()->node();
bool useCustomUnderlines = containsComposition && object()->document()->frame()->editor()->compositionUsesCustomUnderlines();
RenderStyle* styleToUse = object()->style(m_firstLine);
int d = styleToUse->textDecorationsInEffect();
const Font* font = &styleToUse->font();
if (*font != paintInfo.context->font())
paintInfo.context->setFont(*font);
if (paintInfo.phase != PaintPhaseSelection && !isPrinting) {
#if PLATFORM(MAC)
if (styleToUse->highlight() != nullAtom && !paintInfo.context->paintingDisabled())
paintCustomHighlight(tx, ty, styleToUse->highlight());
#endif
if (containsComposition && !useCustomUnderlines)
paintCompositionBackground(paintInfo.context, tx, ty, styleToUse, font,
object()->document()->frame()->editor()->compositionStart(),
object()->document()->frame()->editor()->compositionEnd());
paintDocumentMarkers(paintInfo.context, tx, ty, styleToUse, font, true);
if (haveSelection && !useCustomUnderlines)
paintSelection(paintInfo.context, tx, ty, styleToUse, font);
}
if (m_len <= 0)
return;
Color textFillColor;
Color textStrokeColor;
float textStrokeWidth = styleToUse->textStrokeWidth();
if (paintInfo.forceBlackText) {
textFillColor = Color::black;
textStrokeColor = Color::black;
} else {
textFillColor = styleToUse->textFillColor();
if (!textFillColor.isValid())
textFillColor = styleToUse->color();
if (styleToUse->forceBackgroundsToWhite())
textFillColor = correctedTextColor(textFillColor, Color::white);
textStrokeColor = styleToUse->textStrokeColor();
if (!textStrokeColor.isValid())
textStrokeColor = styleToUse->color();
if (styleToUse->forceBackgroundsToWhite())
textStrokeColor = correctedTextColor(textStrokeColor, Color::white);
}
if (textStrokeWidth > 0)
paintInfo.context->save();
updateGraphicsContext(paintInfo.context, textFillColor, textStrokeColor, textStrokeWidth);
bool setShadow = false;
if (styleToUse->textShadow()) {
paintInfo.context->setShadow(IntSize(styleToUse->textShadow()->x, styleToUse->textShadow()->y),
styleToUse->textShadow()->blur, styleToUse->textShadow()->color);
setShadow = true;
}
bool paintSelectedTextOnly = (paintInfo.phase == PaintPhaseSelection);
bool paintSelectedTextSeparately = false; Color selectionFillColor = textFillColor;
Color selectionStrokeColor = textStrokeColor;
float selectionStrokeWidth = textStrokeWidth;
ShadowData* selectionTextShadow = 0;
if (haveSelection) {
Color foreground = object()->selectionForegroundColor();
if (foreground.isValid() && foreground != selectionFillColor) {
if (!paintSelectedTextOnly)
paintSelectedTextSeparately = true;
selectionFillColor = foreground;
}
RenderStyle* pseudoStyle = object()->getPseudoStyle(RenderStyle::SELECTION);
if (pseudoStyle) {
if (pseudoStyle->textShadow()) {
if (!paintSelectedTextOnly)
paintSelectedTextSeparately = true;
if (pseudoStyle->textShadow())
selectionTextShadow = pseudoStyle->textShadow();
}
float strokeWidth = pseudoStyle->textStrokeWidth();
if (strokeWidth != selectionStrokeWidth) {
if (!paintSelectedTextOnly)
paintSelectedTextSeparately = true;
selectionStrokeWidth = strokeWidth;
}
Color stroke = pseudoStyle->textStrokeColor();
if (!stroke.isValid())
stroke = pseudoStyle->color();
if (stroke != selectionStrokeColor) {
if (!paintSelectedTextOnly)
paintSelectedTextSeparately = true;
selectionStrokeColor = stroke;
}
}
}
StringImpl* textStr = textObject()->text();
if (!paintSelectedTextOnly && !paintSelectedTextSeparately) {
int endPoint = m_len;
if (m_truncation != cNoTruncation)
endPoint = m_truncation;
paintInfo.context->drawText(TextRun(textStr->characters() + m_start, endPoint, textObject()->allowTabs(), textPos(), m_toAdd, m_reversed, m_dirOverride || styleToUse->visuallyOrdered()),
IntPoint(m_x + tx, m_y + ty + m_baseline));
} else {
int sPos, ePos;
selectionStartEnd(sPos, ePos);
if (paintSelectedTextSeparately) {
if (sPos >= ePos)
paintInfo.context->drawText(TextRun(textStr->characters() + m_start, m_len, textObject()->allowTabs(), textPos(), m_toAdd, m_reversed, m_dirOverride || styleToUse->visuallyOrdered()),
IntPoint(m_x + tx, m_y + ty + m_baseline));
else {
if (sPos - 1 >= 0)
paintInfo.context->drawText(TextRun(textStr->characters() + m_start, m_len, textObject()->allowTabs(), textPos(), m_toAdd, m_reversed, m_dirOverride || styleToUse->visuallyOrdered()),
IntPoint(m_x + tx, m_y + ty + m_baseline), 0, sPos);
if (ePos < m_start + m_len)
paintInfo.context->drawText(TextRun(textStr->characters() + m_start, m_len, textObject()->allowTabs(), textPos(), m_toAdd, m_reversed, m_dirOverride || styleToUse->visuallyOrdered()),
IntPoint(m_x + tx, m_y + ty + m_baseline), ePos);
}
}
if (sPos < ePos) {
if (selectionStrokeWidth > 0)
paintInfo.context->save();
updateGraphicsContext(paintInfo.context, selectionFillColor, selectionStrokeColor, selectionStrokeWidth);
if (selectionTextShadow)
paintInfo.context->setShadow(IntSize(selectionTextShadow->x, selectionTextShadow->y),
selectionTextShadow->blur, selectionTextShadow->color);
paintInfo.context->drawText(TextRun(textStr->characters() + m_start, m_len, textObject()->allowTabs(), textPos(), m_toAdd, m_reversed, m_dirOverride || styleToUse->visuallyOrdered()),
IntPoint(m_x + tx, m_y + ty + m_baseline), sPos, ePos);
if (selectionTextShadow)
paintInfo.context->clearShadow();
if (selectionStrokeWidth > 0)
paintInfo.context->restore();
}
}
if (d != TDNONE && paintInfo.phase != PaintPhaseSelection && styleToUse->htmlHacks()) {
paintInfo.context->setStrokeColor(styleToUse->color());
paintDecoration(paintInfo.context, tx, ty, d);
}
if (paintInfo.phase != PaintPhaseSelection) {
paintDocumentMarkers(paintInfo.context, tx, ty, styleToUse, font, false);
if (useCustomUnderlines) {
const Vector<CompositionUnderline>& underlines = object()->document()->frame()->editor()->customCompositionUnderlines();
size_t numUnderlines = underlines.size();
for (size_t index = 0; index < numUnderlines; ++index) {
const CompositionUnderline& underline = underlines[index];
if (underline.endOffset <= start())
continue;
if (underline.startOffset <= end()) {
paintCompositionUnderline(paintInfo.context, tx, ty, underline);
if (underline.endOffset > end() + 1)
break;
} else
break;
}
}
}
if (setShadow)
paintInfo.context->clearShadow();
if (textStrokeWidth > 0)
paintInfo.context->restore();
}
void InlineTextBox::selectionStartEnd(int& sPos, int& ePos)
{
int startPos, endPos;
if (object()->selectionState() == RenderObject::SelectionInside) {
startPos = 0;
endPos = textObject()->textLength();
} else {
textObject()->selectionStartEnd(startPos, endPos);
if (object()->selectionState() == RenderObject::SelectionStart)
endPos = textObject()->textLength();
else if (object()->selectionState() == RenderObject::SelectionEnd)
startPos = 0;
}
sPos = max(startPos - m_start, 0);
ePos = min(endPos - m_start, (int)m_len);
}
void InlineTextBox::paintSelection(GraphicsContext* p, int tx, int ty, RenderStyle* style, const Font* f)
{
int sPos, ePos;
selectionStartEnd(sPos, ePos);
if (sPos >= ePos)
return;
Color textColor = style->color();
Color c = object()->selectionBackgroundColor();
if (!c.isValid() || c.alpha() == 0)
return;
if (textColor == c)
c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue());
p->save();
updateGraphicsContext(p, c, c, 0); int y = selectionTop();
int h = selectionHeight();
p->clip(IntRect(m_x + tx, y + ty, m_width, h));
p->drawHighlightForText(TextRun(textObject()->text()->characters() + m_start, m_len, textObject()->allowTabs(), textPos(), m_toAdd, m_reversed, m_dirOverride || style->visuallyOrdered()),
IntPoint(m_x + tx, y + ty), h, c, sPos, ePos);
p->restore();
}
void InlineTextBox::paintCompositionBackground(GraphicsContext* p, int tx, int ty, RenderStyle* style, const Font* f, int startPos, int endPos)
{
int offset = m_start;
int sPos = max(startPos - offset, 0);
int ePos = min(endPos - offset, (int)m_len);
if (sPos >= ePos)
return;
p->save();
Color c = Color(225, 221, 85);
updateGraphicsContext(p, c, c, 0);
int y = selectionTop();
int h = selectionHeight();
p->drawHighlightForText(TextRun(textObject()->text()->characters() + m_start, m_len, textObject()->allowTabs(), textPos(), m_toAdd, m_reversed, m_dirOverride || style->visuallyOrdered()),
IntPoint(m_x + tx, y + ty), h, c, sPos, ePos);
p->restore();
}
#if PLATFORM(MAC)
void InlineTextBox::paintCustomHighlight(int tx, int ty, const AtomicString& type)
{
RootInlineBox* r = root();
FloatRect rootRect(tx + r->xPos(), ty + selectionTop(), r->width(), selectionHeight());
FloatRect textRect(tx + xPos(), rootRect.y(), width(), rootRect.height());
object()->document()->frame()->paintCustomHighlight(type, textRect, rootRect, true, false, object()->node());
}
#endif
void InlineTextBox::paintDecoration(GraphicsContext* context, int tx, int ty, int deco)
{
tx += m_x;
ty += m_y;
if (m_truncation == cFullTruncation)
return;
int width = (m_truncation == cNoTruncation) ? m_width
: static_cast<RenderText*>(m_object)->width(m_start, m_truncation, textPos(), m_firstLine);
Color underline, overline, linethrough;
object()->getTextDecorationColors(deco, underline, overline, linethrough, true);
bool isPrinting = textObject()->document()->printing();
context->setStrokeThickness(1.0f); if (deco & UNDERLINE) {
context->setStrokeColor(underline);
context->drawLineForText(IntPoint(tx, ty + m_baseline + 1), width, isPrinting);
}
if (deco & OVERLINE) {
context->setStrokeColor(overline);
context->drawLineForText(IntPoint(tx, ty), width, isPrinting);
}
if (deco & LINE_THROUGH) {
context->setStrokeColor(linethrough);
context->drawLineForText(IntPoint(tx, ty + 2 * m_baseline / 3), width, isPrinting);
}
}
void InlineTextBox::paintSpellingOrGrammarMarker(GraphicsContext* pt, int tx, int ty, DocumentMarker marker, RenderStyle* style, const Font* f, bool grammar)
{
if (textObject()->document()->printing())
return;
if (m_truncation == cFullTruncation)
return;
tx += m_x;
ty += m_y;
int start = 0; int width = m_width; bool useWholeWidth = true;
unsigned paintStart = m_start;
unsigned paintEnd = end()+1; if (paintStart <= marker.startOffset) {
paintStart = marker.startOffset;
useWholeWidth = false;
start = static_cast<RenderText*>(m_object)->width(m_start, paintStart - m_start, textPos(), m_firstLine);
}
if (paintEnd != marker.endOffset) { paintEnd = min(paintEnd, marker.endOffset);
useWholeWidth = false;
}
if (m_truncation != cNoTruncation) {
paintEnd = min(paintEnd, (unsigned)m_start + m_truncation);
useWholeWidth = false;
}
if (!useWholeWidth) {
width = static_cast<RenderText*>(m_object)->width(paintStart, paintEnd - paintStart, textPos() + start, m_firstLine);
}
if (grammar) {
int y = selectionTop();
IntPoint startPoint = IntPoint(m_x + tx, y + ty);
int startPosition = max(marker.startOffset - m_start, (unsigned)0);
int endPosition = min(marker.endOffset - m_start, (unsigned)m_len);
TextRun run(textObject()->text()->characters() + m_start, m_len, textObject()->allowTabs(), textPos(), m_toAdd, m_reversed, m_dirOverride || style->visuallyOrdered());
IntRect markerRect = enclosingIntRect(f->selectionRectForText(run, startPoint, selectionHeight(), startPosition, endPosition));
object()->document()->setRenderedRectForMarker(object()->node(), marker, markerRect);
}
int lineThickness = cMisspellingLineThickness;
int descent = m_height - m_baseline;
int underlineOffset;
if (descent <= (2 + lineThickness)) {
underlineOffset = m_height - lineThickness;
} else {
underlineOffset = m_baseline + 2;
}
pt->drawLineForMisspellingOrBadGrammar(IntPoint(tx + start, ty + underlineOffset), width, grammar);
}
void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, int tx, int ty, DocumentMarker marker, RenderStyle* style, const Font* f)
{
int y = selectionTop();
int h = selectionHeight();
int sPos = max(marker.startOffset - m_start, (unsigned)0);
int ePos = min(marker.endOffset - m_start, (unsigned)m_len);
TextRun run(textObject()->text()->characters() + m_start, m_len, textObject()->allowTabs(), textPos(), m_toAdd, m_reversed, m_dirOverride || style->visuallyOrdered());
IntPoint startPoint = IntPoint(m_x + tx, y + ty);
IntRect markerRect = enclosingIntRect(f->selectionRectForText(run, startPoint, h, sPos, ePos));
object()->document()->setRenderedRectForMarker(object()->node(), marker, markerRect);
if (object()->document()->frame()->markedTextMatchesAreHighlighted()) {
Color color = theme()->platformTextSearchHighlightColor();
pt->save();
updateGraphicsContext(pt, color, color, 0); pt->clip(IntRect(tx + m_x, ty + y, m_width, h));
pt->drawHighlightForText(run, startPoint, h, color, sPos, ePos);
pt->restore();
}
}
void InlineTextBox::paintDocumentMarkers(GraphicsContext* pt, int tx, int ty, RenderStyle* style, const Font* f, bool background)
{
Vector<DocumentMarker> markers = object()->document()->markersForNode(object()->node());
Vector<DocumentMarker>::iterator markerIt = markers.begin();
for ( ; markerIt != markers.end(); markerIt++) {
DocumentMarker marker = *markerIt;
switch (marker.type) {
case DocumentMarker::Grammar:
case DocumentMarker::Spelling:
if (background)
continue;
break;
case DocumentMarker::TextMatch:
if (!background)
continue;
break;
default:
ASSERT_NOT_REACHED();
}
if (marker.endOffset <= start())
continue;
if (marker.startOffset > end())
break;
switch (marker.type) {
case DocumentMarker::Spelling:
paintSpellingOrGrammarMarker(pt, tx, ty, marker, style, f, false);
break;
case DocumentMarker::Grammar:
paintSpellingOrGrammarMarker(pt, tx, ty, marker, style, f, true);
break;
case DocumentMarker::TextMatch:
paintTextMatchMarker(pt, tx, ty, marker, style, f);
break;
default:
ASSERT_NOT_REACHED();
}
if (marker.endOffset > end() + 1)
break;
}
}
void InlineTextBox::paintCompositionUnderline(GraphicsContext* ctx, int tx, int ty, const CompositionUnderline& underline)
{
tx += m_x;
ty += m_y;
if (m_truncation == cFullTruncation)
return;
int start = 0; int width = m_width; bool useWholeWidth = true;
unsigned paintStart = m_start;
unsigned paintEnd = end() + 1; if (paintStart <= underline.startOffset) {
paintStart = underline.startOffset;
useWholeWidth = false;
start = static_cast<RenderText*>(m_object)->width(m_start, paintStart - m_start, textPos(), m_firstLine);
}
if (paintEnd != underline.endOffset) { paintEnd = min(paintEnd, (unsigned)underline.endOffset);
useWholeWidth = false;
}
if (m_truncation != cNoTruncation) {
paintEnd = min(paintEnd, (unsigned)m_start + m_truncation);
useWholeWidth = false;
}
if (!useWholeWidth) {
width = static_cast<RenderText*>(m_object)->width(paintStart, paintEnd - paintStart, textPos() + start, m_firstLine);
}
int lineThickness = 1;
if (underline.thick && m_height - m_baseline >= 2)
lineThickness = 2;
start += 1;
width -= 2;
ctx->setStrokeColor(underline.color);
ctx->setStrokeThickness(lineThickness);
ctx->drawLineForText(IntPoint(tx + start, ty + m_height - lineThickness), width, textObject()->document()->printing());
}
int InlineTextBox::caretMinOffset() const
{
return m_start;
}
int InlineTextBox::caretMaxOffset() const
{
return m_start + m_len;
}
unsigned InlineTextBox::caretMaxRenderedOffset() const
{
return m_start + m_len;
}
int InlineTextBox::textPos() const
{
if (xPos() == 0)
return 0;
RenderBlock *blockElement = object()->containingBlock();
return m_reversed ? xPos() - blockElement->borderRight() - blockElement->paddingRight()
: xPos() - blockElement->borderLeft() - blockElement->paddingLeft();
}
int InlineTextBox::offsetForPosition(int _x, bool includePartialGlyphs) const
{
if (isLineBreak())
return 0;
RenderText* text = static_cast<RenderText*>(m_object);
RenderStyle *style = text->style(m_firstLine);
const Font* f = &style->font();
return f->offsetForPosition(TextRun(textObject()->text()->characters() + m_start, m_len, textObject()->allowTabs(), textPos(), m_toAdd, m_reversed, m_dirOverride || style->visuallyOrdered()),
_x - m_x, includePartialGlyphs);
}
int InlineTextBox::positionForOffset(int offset) const
{
if (isLineBreak())
return m_x;
RenderText* text = static_cast<RenderText*>(m_object);
const Font& f = text->style(m_firstLine)->font();
int from = m_reversed ? offset - m_start : 0;
int to = m_reversed ? m_len : offset - m_start;
return enclosingIntRect(f.selectionRectForText(TextRun(text->text()->characters() + m_start, m_len, textObject()->allowTabs(), textPos(), m_toAdd, m_reversed, m_dirOverride),
IntPoint(m_x, 0), 0, from, to)).right();
}
bool InlineTextBox::containsCaretOffset(int offset) const
{
if (offset < m_start)
return false;
int pastEnd = m_start + m_len;
if (offset < pastEnd)
return true;
if (offset > pastEnd)
return false;
if (isLineBreak())
return false;
return true;
}
}