Changeset 204400 in webkit


Ignore:
Timestamp:
Aug 11, 2016 6:22:55 PM (8 years ago)
Author:
mmaxfield@apple.com
Message:

Migrate from ints to unsigneds when referring to indices into strings
https://bugs.webkit.org/show_bug.cgi?id=160735

Reviewed by Simon Fraser.

There are a few cases where we use ints to refer to indices into strings:

  • A simple historical accident. These were migrated to unsigneds directly.
  • Where we use -1 as a sentinal value. These were migrated to Optional<unsigned>.

This patch only modifies rendering code (rather than DOM code). There are a few
places in DOM code (such as Position and Node::maxCharacterOffset()) which also
erroneously use ints; however, I didn't want this change to be observable from
script and I wanted to keep this patch to a reasonable size.

No new tests because there is no behavior change.

  • editing/FrameSelection.cpp:

(WebCore::FrameSelection::updateAppearance):
(WebCore::FrameSelection::setCaretVisibility):

  • platform/DragImage.cpp:

(WebCore::createDragImageForRange):

  • platform/graphics/FontCascade.cpp:

(WebCore::FontCascade::glyphBufferForTextRun):
(WebCore::FontCascade::drawText):
(WebCore::FontCascade::drawEmphasisMarks):
(WebCore::FontCascade::adjustSelectionRectForText):
(WebCore::computeUnderlineType):
(WebCore::FontCascade::getGlyphsAndAdvancesForSimpleText):
(WebCore::FontCascade::drawEmphasisMarksForSimpleText):
(WebCore::FontCascade::drawGlyphBuffer):
(WebCore::offsetToMiddleOfGlyphAtIndex):
(WebCore::FontCascade::adjustSelectionRectForSimpleText):

  • platform/graphics/FontCascade.h:
  • platform/graphics/GlyphBuffer.h:

(WebCore::GlyphBuffer::size):
(WebCore::GlyphBuffer::glyphs):
(WebCore::GlyphBuffer::advances):
(WebCore::GlyphBuffer::fontAt):
(WebCore::GlyphBuffer::glyphAt):
(WebCore::GlyphBuffer::advanceAt):
(WebCore::GlyphBuffer::offsetAt):
(WebCore::GlyphBuffer::reverse):
(WebCore::GlyphBuffer::offsetInString):
(WebCore::GlyphBuffer::shrink):
(WebCore::GlyphBuffer::swap):

  • platform/graphics/GraphicsContext.cpp:

(WebCore::GraphicsContext::drawText):
(WebCore::GraphicsContext::drawGlyphs):
(WebCore::GraphicsContext::drawEmphasisMarks):

  • platform/graphics/GraphicsContext.h:
  • platform/graphics/Latin1TextIterator.h:

(WebCore::Latin1TextIterator::Latin1TextIterator):
(WebCore::Latin1TextIterator::currentCharacter):

  • platform/graphics/SurrogatePairAwareTextIterator.cpp:

(WebCore::SurrogatePairAwareTextIterator::SurrogatePairAwareTextIterator):

  • platform/graphics/SurrogatePairAwareTextIterator.h:

(WebCore::SurrogatePairAwareTextIterator::currentCharacter):

  • platform/graphics/WidthIterator.cpp:

(WebCore::WidthIterator::applyFontTransforms):
(WebCore::WidthIterator::advanceInternal):
(WebCore::WidthIterator::advance):
(WebCore::WidthIterator::advanceOneCharacter):

  • platform/graphics/WidthIterator.h:
  • platform/graphics/cairo/FontCairo.cpp:

(WebCore::drawGlyphsToContext):
(WebCore::drawGlyphsShadow):
(WebCore::FontCascade::drawGlyphs):

  • platform/graphics/cairo/FontCairoHarfbuzzNG.cpp:

(WebCore::FontCascade::getGlyphsAndAdvancesForComplexText):
(WebCore::FontCascade::drawEmphasisMarksForComplexText):
(WebCore::FontCascade::adjustSelectionRectForComplexText):

  • platform/graphics/cocoa/FontCascadeCocoa.mm:

(WebCore::fillVectorWithHorizontalGlyphPositions):
(WebCore::showLetterpressedGlyphsWithAdvances):
(WebCore::showGlyphsWithAdvances):
(WebCore::FontCascade::drawGlyphs):
(WebCore::FontCascade::dashesForIntersectionsWithRect):
(WebCore::FontCascade::adjustSelectionRectForComplexText):
(WebCore::FontCascade::getGlyphsAndAdvancesForComplexText):
(WebCore::FontCascade::drawEmphasisMarksForComplexText):

  • platform/graphics/displaylists/DisplayListRecorder.cpp:

(WebCore::DisplayList::Recorder::drawGlyphs):

  • platform/graphics/displaylists/DisplayListRecorder.h:
  • platform/graphics/harfbuzz/HarfBuzzShaper.cpp:

(WebCore::HarfBuzzShaper::selectionRect):

  • platform/graphics/harfbuzz/HarfBuzzShaper.h:
  • platform/graphics/mac/ComplexTextController.h:
  • platform/graphics/win/FontCGWin.cpp:

(WebCore::FontCascade::drawGlyphs):

  • platform/graphics/win/FontWin.cpp:

(WebCore::FontCascade::adjustSelectionRectForComplexText):
(WebCore::FontCascade::getGlyphsAndAdvancesForComplexText):
(WebCore::FontCascade::drawEmphasisMarksForComplexText):

  • rendering/EllipsisBox.cpp:

(WebCore::EllipsisBox::paintSelection):

  • rendering/InlineTextBox.cpp:

(WebCore::InlineTextBox::isSelected):
(WebCore::InlineTextBox::selectionState):
(WebCore::InlineTextBox::localSelectionRect):
(WebCore::InlineTextBox::paint):
(WebCore::InlineTextBox::clampedOffset):
(WebCore::InlineTextBox::selectionStartEnd):
(WebCore::InlineTextBox::paintSelection):
(WebCore::InlineTextBox::paintCompositionBackground):
(WebCore::InlineTextBox::paintDocumentMarker):
(WebCore::InlineTextBox::paintTextMatchMarker):
(WebCore::InlineTextBox::positionForOffset):

  • rendering/InlineTextBox.h:

(WebCore::InlineTextBox::offsetRun):
(WebCore::InlineTextBox::InlineTextBox): Deleted.

  • rendering/RenderBlock.cpp:

(WebCore::RenderBlock::localCaretRect):

  • rendering/RenderBlock.h:
  • rendering/RenderBox.cpp:

(WebCore::RenderBox::localCaretRect):

  • rendering/RenderBox.h:
  • rendering/RenderInline.cpp:

(WebCore::RenderInline::localCaretRect):

  • rendering/RenderInline.h:
  • rendering/RenderLineBreak.cpp:

(WebCore::RenderLineBreak::localCaretRect):

  • rendering/RenderLineBreak.h:
  • rendering/RenderObject.cpp:

(WebCore::RenderObject::selectionStartEnd):
(WebCore::RenderObject::localCaretRect):

  • rendering/RenderObject.h:
  • rendering/RenderReplaced.cpp:

(WebCore::RenderReplaced::isSelected):

  • rendering/RenderText.cpp:

(WebCore::RenderText::localCaretRect):
(WebCore::RenderText::collectSelectionRectsForLineBoxes):

  • rendering/RenderText.h:
  • rendering/RenderTextLineBoxes.cpp:

(WebCore::RenderTextLineBoxes::setSelectionState):

  • rendering/RenderView.cpp:

(WebCore::RenderView::subtreeSelectionBounds):
(WebCore::RenderView::repaintSubtreeSelection):
(WebCore::RenderView::setSelection):
(WebCore::RenderView::splitSelectionBetweenSubtrees):
(WebCore::RenderView::clearSubtreeSelection):
(WebCore::RenderView::applySubtreeSelection):
(WebCore::RenderView::getSelection):
(WebCore::RenderView::clearSelection):
(WebCore::RenderView::RenderView): Deleted.

  • rendering/RenderView.h:
  • rendering/SelectionSubtreeRoot.cpp:

(WebCore::SelectionSubtreeRoot::adjustForVisibleSelection):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeRoot): Deleted.

  • rendering/SelectionSubtreeRoot.h:

(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::SelectionSubtreeData):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionStartPos):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionEndPos):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionClear):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionStartEndPositions):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::setSelectionStartPos):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::setSelectionEndPos):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::clearSelection):
(WebCore::SelectionSubtreeRoot::OldSelectionData::OldSelectionData): Deleted.

  • rendering/TextPainter.cpp:

(WebCore::TextPainter::drawTextOrEmphasisMarks):
(WebCore::TextPainter::paintTextWithShadows):
(WebCore::TextPainter::paintTextAndEmphasisMarksIfNeeded):
(WebCore::TextPainter::paintText):

  • rendering/TextPainter.h:

(WebCore::TextPainter::addEmphasis):

  • rendering/svg/RenderSVGInlineText.cpp:

(WebCore::RenderSVGInlineText::localCaretRect):

  • rendering/svg/RenderSVGInlineText.h:
  • rendering/svg/SVGInlineTextBox.cpp:

(WebCore::SVGInlineTextBox::positionForOffset):
(WebCore::SVGInlineTextBox::selectionRectForTextFragment):
(WebCore::SVGInlineTextBox::localSelectionRect):
(WebCore::SVGInlineTextBox::paintSelectionBackground):
(WebCore::SVGInlineTextBox::mapStartEndPositionsIntoFragmentCoordinates):
(WebCore::SVGInlineTextBox::paintTextWithShadows):
(WebCore::SVGInlineTextBox::paintText):

  • rendering/svg/SVGInlineTextBox.h:
  • rendering/svg/SVGTextQuery.cpp:

(WebCore::SVGTextQuery::mapStartEndPositionsIntoFragmentCoordinates):
(WebCore::SVGTextQuery::modifyStartEndPositionsRespectingLigatures):
(WebCore::SVGTextQuery::subStringLengthCallback):
(WebCore::SVGTextQuery::startPositionOfCharacterCallback):
(WebCore::SVGTextQuery::endPositionOfCharacterCallback):
(WebCore::SVGTextQuery::rotationOfCharacterCallback):
(WebCore::calculateGlyphBoundaries):
(WebCore::SVGTextQuery::extentOfCharacterCallback):
(WebCore::SVGTextQuery::characterNumberAtPositionCallback):

  • rendering/svg/SVGTextQuery.h:
Location:
trunk/Source/WebCore
Files:
52 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r204395 r204400  
     12016-08-11  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Migrate from ints to unsigneds when referring to indices into strings
     4        https://bugs.webkit.org/show_bug.cgi?id=160735
     5
     6        Reviewed by Simon Fraser.
     7
     8        There are a few cases where we use ints to refer to indices into strings:
     9        - A simple historical accident. These were migrated to unsigneds directly.
     10        - Where we use -1 as a sentinal value. These were migrated to Optional<unsigned>.
     11
     12        This patch only modifies rendering code (rather than DOM code). There are a few
     13        places in DOM code (such as Position and Node::maxCharacterOffset()) which also
     14        erroneously use ints; however, I didn't want this change to be observable from
     15        script and I wanted to keep this patch to a reasonable size.
     16
     17        No new tests because there is no behavior change.
     18
     19        * editing/FrameSelection.cpp:
     20        (WebCore::FrameSelection::updateAppearance):
     21        (WebCore::FrameSelection::setCaretVisibility):
     22        * platform/DragImage.cpp:
     23        (WebCore::createDragImageForRange):
     24        * platform/graphics/FontCascade.cpp:
     25        (WebCore::FontCascade::glyphBufferForTextRun):
     26        (WebCore::FontCascade::drawText):
     27        (WebCore::FontCascade::drawEmphasisMarks):
     28        (WebCore::FontCascade::adjustSelectionRectForText):
     29        (WebCore::computeUnderlineType):
     30        (WebCore::FontCascade::getGlyphsAndAdvancesForSimpleText):
     31        (WebCore::FontCascade::drawEmphasisMarksForSimpleText):
     32        (WebCore::FontCascade::drawGlyphBuffer):
     33        (WebCore::offsetToMiddleOfGlyphAtIndex):
     34        (WebCore::FontCascade::adjustSelectionRectForSimpleText):
     35        * platform/graphics/FontCascade.h:
     36        * platform/graphics/GlyphBuffer.h:
     37        (WebCore::GlyphBuffer::size):
     38        (WebCore::GlyphBuffer::glyphs):
     39        (WebCore::GlyphBuffer::advances):
     40        (WebCore::GlyphBuffer::fontAt):
     41        (WebCore::GlyphBuffer::glyphAt):
     42        (WebCore::GlyphBuffer::advanceAt):
     43        (WebCore::GlyphBuffer::offsetAt):
     44        (WebCore::GlyphBuffer::reverse):
     45        (WebCore::GlyphBuffer::offsetInString):
     46        (WebCore::GlyphBuffer::shrink):
     47        (WebCore::GlyphBuffer::swap):
     48        * platform/graphics/GraphicsContext.cpp:
     49        (WebCore::GraphicsContext::drawText):
     50        (WebCore::GraphicsContext::drawGlyphs):
     51        (WebCore::GraphicsContext::drawEmphasisMarks):
     52        * platform/graphics/GraphicsContext.h:
     53        * platform/graphics/Latin1TextIterator.h:
     54        (WebCore::Latin1TextIterator::Latin1TextIterator):
     55        (WebCore::Latin1TextIterator::currentCharacter):
     56        * platform/graphics/SurrogatePairAwareTextIterator.cpp:
     57        (WebCore::SurrogatePairAwareTextIterator::SurrogatePairAwareTextIterator):
     58        * platform/graphics/SurrogatePairAwareTextIterator.h:
     59        (WebCore::SurrogatePairAwareTextIterator::currentCharacter):
     60        * platform/graphics/WidthIterator.cpp:
     61        (WebCore::WidthIterator::applyFontTransforms):
     62        (WebCore::WidthIterator::advanceInternal):
     63        (WebCore::WidthIterator::advance):
     64        (WebCore::WidthIterator::advanceOneCharacter):
     65        * platform/graphics/WidthIterator.h:
     66        * platform/graphics/cairo/FontCairo.cpp:
     67        (WebCore::drawGlyphsToContext):
     68        (WebCore::drawGlyphsShadow):
     69        (WebCore::FontCascade::drawGlyphs):
     70        * platform/graphics/cairo/FontCairoHarfbuzzNG.cpp:
     71        (WebCore::FontCascade::getGlyphsAndAdvancesForComplexText):
     72        (WebCore::FontCascade::drawEmphasisMarksForComplexText):
     73        (WebCore::FontCascade::adjustSelectionRectForComplexText):
     74        * platform/graphics/cocoa/FontCascadeCocoa.mm:
     75        (WebCore::fillVectorWithHorizontalGlyphPositions):
     76        (WebCore::showLetterpressedGlyphsWithAdvances):
     77        (WebCore::showGlyphsWithAdvances):
     78        (WebCore::FontCascade::drawGlyphs):
     79        (WebCore::FontCascade::dashesForIntersectionsWithRect):
     80        (WebCore::FontCascade::adjustSelectionRectForComplexText):
     81        (WebCore::FontCascade::getGlyphsAndAdvancesForComplexText):
     82        (WebCore::FontCascade::drawEmphasisMarksForComplexText):
     83        * platform/graphics/displaylists/DisplayListRecorder.cpp:
     84        (WebCore::DisplayList::Recorder::drawGlyphs):
     85        * platform/graphics/displaylists/DisplayListRecorder.h:
     86        * platform/graphics/harfbuzz/HarfBuzzShaper.cpp:
     87        (WebCore::HarfBuzzShaper::selectionRect):
     88        * platform/graphics/harfbuzz/HarfBuzzShaper.h:
     89        * platform/graphics/mac/ComplexTextController.h:
     90        * platform/graphics/win/FontCGWin.cpp:
     91        (WebCore::FontCascade::drawGlyphs):
     92        * platform/graphics/win/FontWin.cpp:
     93        (WebCore::FontCascade::adjustSelectionRectForComplexText):
     94        (WebCore::FontCascade::getGlyphsAndAdvancesForComplexText):
     95        (WebCore::FontCascade::drawEmphasisMarksForComplexText):
     96        * rendering/EllipsisBox.cpp:
     97        (WebCore::EllipsisBox::paintSelection):
     98        * rendering/InlineTextBox.cpp:
     99        (WebCore::InlineTextBox::isSelected):
     100        (WebCore::InlineTextBox::selectionState):
     101        (WebCore::InlineTextBox::localSelectionRect):
     102        (WebCore::InlineTextBox::paint):
     103        (WebCore::InlineTextBox::clampedOffset):
     104        (WebCore::InlineTextBox::selectionStartEnd):
     105        (WebCore::InlineTextBox::paintSelection):
     106        (WebCore::InlineTextBox::paintCompositionBackground):
     107        (WebCore::InlineTextBox::paintDocumentMarker):
     108        (WebCore::InlineTextBox::paintTextMatchMarker):
     109        (WebCore::InlineTextBox::positionForOffset):
     110        * rendering/InlineTextBox.h:
     111        (WebCore::InlineTextBox::offsetRun):
     112        (WebCore::InlineTextBox::InlineTextBox): Deleted.
     113        * rendering/RenderBlock.cpp:
     114        (WebCore::RenderBlock::localCaretRect):
     115        * rendering/RenderBlock.h:
     116        * rendering/RenderBox.cpp:
     117        (WebCore::RenderBox::localCaretRect):
     118        * rendering/RenderBox.h:
     119        * rendering/RenderInline.cpp:
     120        (WebCore::RenderInline::localCaretRect):
     121        * rendering/RenderInline.h:
     122        * rendering/RenderLineBreak.cpp:
     123        (WebCore::RenderLineBreak::localCaretRect):
     124        * rendering/RenderLineBreak.h:
     125        * rendering/RenderObject.cpp:
     126        (WebCore::RenderObject::selectionStartEnd):
     127        (WebCore::RenderObject::localCaretRect):
     128        * rendering/RenderObject.h:
     129        * rendering/RenderReplaced.cpp:
     130        (WebCore::RenderReplaced::isSelected):
     131        * rendering/RenderText.cpp:
     132        (WebCore::RenderText::localCaretRect):
     133        (WebCore::RenderText::collectSelectionRectsForLineBoxes):
     134        * rendering/RenderText.h:
     135        * rendering/RenderTextLineBoxes.cpp:
     136        (WebCore::RenderTextLineBoxes::setSelectionState):
     137        * rendering/RenderView.cpp:
     138        (WebCore::RenderView::subtreeSelectionBounds):
     139        (WebCore::RenderView::repaintSubtreeSelection):
     140        (WebCore::RenderView::setSelection):
     141        (WebCore::RenderView::splitSelectionBetweenSubtrees):
     142        (WebCore::RenderView::clearSubtreeSelection):
     143        (WebCore::RenderView::applySubtreeSelection):
     144        (WebCore::RenderView::getSelection):
     145        (WebCore::RenderView::clearSelection):
     146        (WebCore::RenderView::RenderView): Deleted.
     147        * rendering/RenderView.h:
     148        * rendering/SelectionSubtreeRoot.cpp:
     149        (WebCore::SelectionSubtreeRoot::adjustForVisibleSelection):
     150        (WebCore::SelectionSubtreeRoot::SelectionSubtreeRoot): Deleted.
     151        * rendering/SelectionSubtreeRoot.h:
     152        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::SelectionSubtreeData):
     153        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionStartPos):
     154        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionEndPos):
     155        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionClear):
     156        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionStartEndPositions):
     157        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::setSelectionStartPos):
     158        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::setSelectionEndPos):
     159        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::clearSelection):
     160        (WebCore::SelectionSubtreeRoot::OldSelectionData::OldSelectionData): Deleted.
     161        * rendering/TextPainter.cpp:
     162        (WebCore::TextPainter::drawTextOrEmphasisMarks):
     163        (WebCore::TextPainter::paintTextWithShadows):
     164        (WebCore::TextPainter::paintTextAndEmphasisMarksIfNeeded):
     165        (WebCore::TextPainter::paintText):
     166        * rendering/TextPainter.h:
     167        (WebCore::TextPainter::addEmphasis):
     168        * rendering/svg/RenderSVGInlineText.cpp:
     169        (WebCore::RenderSVGInlineText::localCaretRect):
     170        * rendering/svg/RenderSVGInlineText.h:
     171        * rendering/svg/SVGInlineTextBox.cpp:
     172        (WebCore::SVGInlineTextBox::positionForOffset):
     173        (WebCore::SVGInlineTextBox::selectionRectForTextFragment):
     174        (WebCore::SVGInlineTextBox::localSelectionRect):
     175        (WebCore::SVGInlineTextBox::paintSelectionBackground):
     176        (WebCore::SVGInlineTextBox::mapStartEndPositionsIntoFragmentCoordinates):
     177        (WebCore::SVGInlineTextBox::paintTextWithShadows):
     178        (WebCore::SVGInlineTextBox::paintText):
     179        * rendering/svg/SVGInlineTextBox.h:
     180        * rendering/svg/SVGTextQuery.cpp:
     181        (WebCore::SVGTextQuery::mapStartEndPositionsIntoFragmentCoordinates):
     182        (WebCore::SVGTextQuery::modifyStartEndPositionsRespectingLigatures):
     183        (WebCore::SVGTextQuery::subStringLengthCallback):
     184        (WebCore::SVGTextQuery::startPositionOfCharacterCallback):
     185        (WebCore::SVGTextQuery::endPositionOfCharacterCallback):
     186        (WebCore::SVGTextQuery::rotationOfCharacterCallback):
     187        (WebCore::calculateGlyphBoundaries):
     188        (WebCore::SVGTextQuery::extentOfCharacterCallback):
     189        (WebCore::SVGTextQuery::characterNumberAtPositionCallback):
     190        * rendering/svg/SVGTextQuery.h:
     191
    11922016-08-11  Alex Christensen  <achristensen@webkit.org>
    2193
  • trunk/Source/WebCore/editing/FrameSelection.cpp

    r202292 r204400  
    20892089    if (startPos.isNotNull() && endPos.isNotNull() && selection.visibleStart() != selection.visibleEnd()) {
    20902090        RenderObject* startRenderer = startPos.deprecatedNode()->renderer();
     2091        int startOffset = startPos.deprecatedEditingOffset();
    20912092        RenderObject* endRenderer = endPos.deprecatedNode()->renderer();
    2092         view->setSelection(startRenderer, startPos.deprecatedEditingOffset(), endRenderer, endPos.deprecatedEditingOffset());
     2093        int endOffset = endPos.deprecatedEditingOffset();
     2094        ASSERT(startOffset >= 0 && endOffset >= 0);
     2095        view->setSelection(startRenderer, startOffset, endRenderer, endOffset);
    20932096    }
    20942097}
     
    20992102        return;
    21002103
    2101     // FIXME: We shouldn't trigger a synchrnously layout here.
     2104    // FIXME: We shouldn't trigger a synchronous layout here.
    21022105    if (m_frame)
    21032106        updateSelectionByUpdatingLayoutOrStyle(*m_frame);
  • trunk/Source/WebCore/platform/DragImage.cpp

    r194496 r204400  
    142142    RenderObject* startRenderer;
    143143    RenderObject* endRenderer;
    144     int startOffset;
    145     int endOffset;
     144    Optional<unsigned> startOffset;
     145    Optional<unsigned> endOffset;
    146146};
    147147
     
    175175
    176176    SnapshotOptions options = SnapshotOptionsPaintSelectionOnly | (forceBlackText ? SnapshotOptionsForceBlackText : SnapshotOptionsNone);
    177     view->setSelection(startRenderer, start.deprecatedEditingOffset(), endRenderer, end.deprecatedEditingOffset(), RenderView::RepaintNothing);
     177    int startOffset = start.deprecatedEditingOffset();
     178    int endOffset = end.deprecatedEditingOffset();
     179    ASSERT(startOffset >= 0 && endOffset >= 0);
     180    view->setSelection(startRenderer, startOffset, endRenderer, endOffset, RenderView::RepaintNothing);
    178181    // We capture using snapshotFrameRect() because we fake up the selection using
    179182    // FrameView but snapshotSelection() uses the selection from the Frame itself.
  • trunk/Source/WebCore/platform/graphics/FontCascade.cpp

    r203330 r204400  
    295295}
    296296
    297 float FontCascade::glyphBufferForTextRun(CodePath codePathToUse, const TextRun& run, int from, int to, GlyphBuffer& glyphBuffer) const
     297float FontCascade::glyphBufferForTextRun(CodePath codePathToUse, const TextRun& run, unsigned from, unsigned to, GlyphBuffer& glyphBuffer) const
    298298{
    299299    if (codePathToUse != Complex)
     
    302302}
    303303
    304 float FontCascade::drawText(GraphicsContext& context, const TextRun& run, const FloatPoint& point, int from, int to, CustomFontNotReadyAction customFontNotReadyAction) const
     304float FontCascade::drawText(GraphicsContext& context, const TextRun& run, const FloatPoint& point, unsigned from, Optional<unsigned> to, CustomFontNotReadyAction customFontNotReadyAction) const
    305305{
    306306    // Don't draw anything while we are using custom fonts that are in the process of loading,
     
    310310        return 0;
    311311
    312     to = (to == -1 ? run.length() : to);
     312    unsigned destination = to.valueOr(run.length());
    313313
    314314    CodePath codePathToUse = codePath(run);
    315315    // FIXME: Use the fast code path once it handles partial runs with kerning and ligatures. See http://webkit.org/b/100050
    316     if (codePathToUse != Complex && (enableKerning() || requiresShaping()) && (from || static_cast<unsigned>(to) != run.length()))
     316    if (codePathToUse != Complex && (enableKerning() || requiresShaping()) && (from || destination != run.length()))
    317317        codePathToUse = Complex;
    318318
    319319    GlyphBuffer glyphBuffer;
    320     float startX = point.x() + glyphBufferForTextRun(codePathToUse, run, from, to, glyphBuffer);
     320    float startX = point.x() + glyphBufferForTextRun(codePathToUse, run, from, destination, glyphBuffer);
    321321    // We couldn't generate any glyphs for the run. Give up.
    322322    if (glyphBuffer.isEmpty())
     
    328328}
    329329
    330 void FontCascade::drawEmphasisMarks(GraphicsContext& context, const TextRun& run, const AtomicString& mark, const FloatPoint& point, int from, int to) const
     330void FontCascade::drawEmphasisMarks(GraphicsContext& context, const TextRun& run, const AtomicString& mark, const FloatPoint& point, unsigned from, Optional<unsigned> to) const
    331331{
    332332    if (isLoadingCustomFonts())
    333333        return;
    334334
    335     if (to < 0)
    336         to = run.length();
     335    unsigned destination = to.valueOr(run.length());
    337336
    338337    CodePath codePathToUse = codePath(run);
    339338    // FIXME: Use the fast code path once it handles partial runs with kerning and ligatures. See http://webkit.org/b/100050
    340     if (codePathToUse != Complex && (enableKerning() || requiresShaping()) && (from || static_cast<unsigned>(to) != run.length()))
     339    if (codePathToUse != Complex && (enableKerning() || requiresShaping()) && (from || destination != run.length()))
    341340        codePathToUse = Complex;
    342341
    343342    if (codePathToUse != Complex)
    344         drawEmphasisMarksForSimpleText(context, run, mark, point, from, to);
     343        drawEmphasisMarksForSimpleText(context, run, mark, point, from, destination);
    345344    else
    346         drawEmphasisMarksForComplexText(context, run, mark, point, from, to);
     345        drawEmphasisMarksForComplexText(context, run, mark, point, from, destination);
    347346}
    348347
     
    492491}
    493492
    494 void FontCascade::adjustSelectionRectForText(const TextRun& run, LayoutRect& selectionRect, int from, int to) const
    495 {
    496     to = (to == -1 ? run.length() : to);
     493void FontCascade::adjustSelectionRectForText(const TextRun& run, LayoutRect& selectionRect, unsigned from, Optional<unsigned> to) const
     494{
     495    unsigned destination = to.valueOr(run.length());
    497496
    498497    CodePath codePathToUse = codePath(run);
    499498    // FIXME: Use the fast code path once it handles partial runs with kerning and ligatures. See http://webkit.org/b/100050
    500     if (codePathToUse != Complex && (enableKerning() || requiresShaping()) && (from || static_cast<unsigned>(to) != run.length()))
     499    if (codePathToUse != Complex && (enableKerning() || requiresShaping()) && (from || destination != run.length()))
    501500        codePathToUse = Complex;
    502501
    503502    if (codePathToUse != Complex)
    504         return adjustSelectionRectForSimpleText(run, selectionRect, from, to);
    505 
    506     return adjustSelectionRectForComplexText(run, selectionRect, from, to);
     503        return adjustSelectionRectForSimpleText(run, selectionRect, from, destination);
     504
     505    return adjustSelectionRectForComplexText(run, selectionRect, from, destination);
    507506}
    508507
     
    11241123}
    11251124   
    1126 GlyphToPathTranslator::GlyphUnderlineType computeUnderlineType(const TextRun& textRun, const GlyphBuffer& glyphBuffer, int index)
     1125GlyphToPathTranslator::GlyphUnderlineType computeUnderlineType(const TextRun& textRun, const GlyphBuffer& glyphBuffer, unsigned index)
    11271126{
    11281127    // In general, we want to skip descenders. However, skipping descenders on CJK characters leads to undesirable renderings,
     
    12391238}
    12401239
    1241 float FontCascade::getGlyphsAndAdvancesForSimpleText(const TextRun& run, int from, int to, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot forTextEmphasis) const
     1240float FontCascade::getGlyphsAndAdvancesForSimpleText(const TextRun& run, unsigned from, unsigned to, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot forTextEmphasis) const
    12421241{
    12431242    float initialAdvance;
     
    12691268}
    12701269
    1271 void FontCascade::drawEmphasisMarksForSimpleText(GraphicsContext& context, const TextRun& run, const AtomicString& mark, const FloatPoint& point, int from, int to) const
     1270void FontCascade::drawEmphasisMarksForSimpleText(GraphicsContext& context, const TextRun& run, const AtomicString& mark, const FloatPoint& point, unsigned from, unsigned to) const
    12721271{
    12731272    GlyphBuffer glyphBuffer;
     
    12881287    float nextX = startPoint.x() + glyphBuffer.advanceAt(0).width();
    12891288    float nextY = startPoint.y() + glyphBuffer.advanceAt(0).height();
    1290     int lastFrom = 0;
    1291     int nextGlyph = 1;
     1289    unsigned lastFrom = 0;
     1290    unsigned nextGlyph = 1;
    12921291    while (nextGlyph < glyphBuffer.size()) {
    12931292        const Font* nextFontData = glyphBuffer.fontAt(nextGlyph);
     
    13221321}
    13231322
    1324 inline static float offsetToMiddleOfGlyphAtIndex(const GlyphBuffer& glyphBuffer, size_t i)
     1323inline static float offsetToMiddleOfGlyphAtIndex(const GlyphBuffer& glyphBuffer, unsigned i)
    13251324{
    13261325    return offsetToMiddleOfGlyph(glyphBuffer.fontAt(i), glyphBuffer.glyphAt(i));
     
    13451344
    13461345    GlyphBuffer markBuffer;
    1347     for (int i = 0; i + 1 < glyphBuffer.size(); ++i) {
     1346    for (unsigned i = 0; i + 1 < glyphBuffer.size(); ++i) {
    13481347        float middleOfNextGlyph = offsetToMiddleOfGlyphAtIndex(glyphBuffer, i + 1);
    13491348        float advance = glyphBuffer.advanceAt(i).width() - middleOfLastGlyph + middleOfNextGlyph;
     
    13721371}
    13731372
    1374 void FontCascade::adjustSelectionRectForSimpleText(const TextRun& run, LayoutRect& selectionRect, int from, int to) const
     1373void FontCascade::adjustSelectionRectForSimpleText(const TextRun& run, LayoutRect& selectionRect, unsigned from, unsigned to) const
    13751374{
    13761375    GlyphBuffer glyphBuffer;
  • trunk/Source/WebCore/platform/graphics/FontCascade.h

    r198074 r204400  
    106106    virtual ~GlyphToPathTranslator() { }
    107107};
    108 GlyphToPathTranslator::GlyphUnderlineType computeUnderlineType(const TextRun&, const GlyphBuffer&, int index);
     108GlyphToPathTranslator::GlyphUnderlineType computeUnderlineType(const TextRun&, const GlyphBuffer&, unsigned index);
    109109
    110110class TextLayoutDeleter {
     
    134134
    135135    enum CustomFontNotReadyAction { DoNotPaintIfFontNotReady, UseFallbackIfFontNotReady };
    136     WEBCORE_EXPORT float drawText(GraphicsContext&, const TextRun&, const FloatPoint&, int from = 0, int to = -1, CustomFontNotReadyAction = DoNotPaintIfFontNotReady) const;
    137     static void drawGlyphs(GraphicsContext&, const Font&, const GlyphBuffer&, int from, int numGlyphs, const FloatPoint&, FontSmoothingMode);
    138     void drawEmphasisMarks(GraphicsContext&, const TextRun&, const AtomicString& mark, const FloatPoint&, int from = 0, int to = -1) const;
     136    WEBCORE_EXPORT float drawText(GraphicsContext&, const TextRun&, const FloatPoint&, unsigned from = 0, Optional<unsigned> to = Nullopt, CustomFontNotReadyAction = DoNotPaintIfFontNotReady) const;
     137    static void drawGlyphs(GraphicsContext&, const Font&, const GlyphBuffer&, unsigned from, unsigned numGlyphs, const FloatPoint&, FontSmoothingMode);
     138    void drawEmphasisMarks(GraphicsContext&, const TextRun&, const AtomicString& mark, const FloatPoint&, unsigned from = 0, Optional<unsigned> to = Nullopt) const;
    139139
    140140    DashArray dashesForIntersectionsWithRect(const TextRun&, const FloatPoint& textOrigin, const FloatRect& lineExtents) const;
     
    146146
    147147    int offsetForPosition(const TextRun&, float position, bool includePartialGlyphs) const;
    148     void adjustSelectionRectForText(const TextRun&, LayoutRect& selectionRect, int from = 0, int to = -1) const;
     148    void adjustSelectionRectForText(const TextRun&, LayoutRect& selectionRect, unsigned from = 0, Optional<unsigned> to = Nullopt) const;
    149149
    150150    bool isSmallCaps() const { return m_fontDescription.variantCaps() == FontVariantCaps::Small; }
     
    219219    enum ForTextEmphasisOrNot { NotForTextEmphasis, ForTextEmphasis };
    220220
    221     float glyphBufferForTextRun(CodePath, const TextRun&, int from, int to, GlyphBuffer&) const;
     221    float glyphBufferForTextRun(CodePath, const TextRun&, unsigned from, unsigned to, GlyphBuffer&) const;
    222222    // Returns the initial in-stream advance.
    223     float getGlyphsAndAdvancesForSimpleText(const TextRun&, int from, int to, GlyphBuffer&, ForTextEmphasisOrNot = NotForTextEmphasis) const;
    224     void drawEmphasisMarksForSimpleText(GraphicsContext&, const TextRun&, const AtomicString& mark, const FloatPoint&, int from, int to) const;
     223    float getGlyphsAndAdvancesForSimpleText(const TextRun&, unsigned from, unsigned to, GlyphBuffer&, ForTextEmphasisOrNot = NotForTextEmphasis) const;
     224    void drawEmphasisMarksForSimpleText(GraphicsContext&, const TextRun&, const AtomicString& mark, const FloatPoint&, unsigned from, unsigned to) const;
    225225    void drawGlyphBuffer(GraphicsContext&, const GlyphBuffer&, FloatPoint&) const;
    226226    void drawEmphasisMarks(GraphicsContext&, const GlyphBuffer&, const AtomicString&, const FloatPoint&) const;
    227227    float floatWidthForSimpleText(const TextRun&, HashSet<const Font*>* fallbackFonts = 0, GlyphOverflow* = 0) const;
    228228    int offsetForPositionForSimpleText(const TextRun&, float position, bool includePartialGlyphs) const;
    229     void adjustSelectionRectForSimpleText(const TextRun&, LayoutRect& selectionRect, int from, int to) const;
     229    void adjustSelectionRectForSimpleText(const TextRun&, LayoutRect& selectionRect, unsigned from, unsigned to) const;
    230230
    231231    Optional<GlyphData> getEmphasisMarkGlyphData(const AtomicString&) const;
     
    235235
    236236    // Returns the initial in-stream advance.
    237     float getGlyphsAndAdvancesForComplexText(const TextRun&, int from, int to, GlyphBuffer&, ForTextEmphasisOrNot = NotForTextEmphasis) const;
    238     void drawEmphasisMarksForComplexText(GraphicsContext&, const TextRun&, const AtomicString& mark, const FloatPoint&, int from, int to) const;
     237    float getGlyphsAndAdvancesForComplexText(const TextRun&, unsigned from, unsigned to, GlyphBuffer&, ForTextEmphasisOrNot = NotForTextEmphasis) const;
     238    void drawEmphasisMarksForComplexText(GraphicsContext&, const TextRun&, const AtomicString& mark, const FloatPoint&, unsigned from, unsigned to) const;
    239239    float floatWidthForComplexText(const TextRun&, HashSet<const Font*>* fallbackFonts = 0, GlyphOverflow* = 0) const;
    240240    int offsetForPositionForComplexText(const TextRun&, float position, bool includePartialGlyphs) const;
    241     void adjustSelectionRectForComplexText(const TextRun&, LayoutRect& selectionRect, int from, int to) const;
     241    void adjustSelectionRectForComplexText(const TextRun&, LayoutRect& selectionRect, unsigned from, unsigned to) const;
    242242
    243243    static std::pair<unsigned, bool> expansionOpportunityCountInternal(const LChar*, size_t length, TextDirection, ExpansionBehavior);
  • trunk/Source/WebCore/platform/graphics/GlyphBuffer.h

    r182236 r204400  
    7878public:
    7979    bool isEmpty() const { return m_font.isEmpty(); }
    80     int size() const { return m_font.size(); }
     80    unsigned size() const { return m_font.size(); }
    8181   
    8282    void clear()
     
    9292    }
    9393
    94     GlyphBufferGlyph* glyphs(int from) { return m_glyphs.data() + from; }
    95     GlyphBufferAdvance* advances(int from) { return m_advances.data() + from; }
    96     const GlyphBufferGlyph* glyphs(int from) const { return m_glyphs.data() + from; }
    97     const GlyphBufferAdvance* advances(int from) const { return m_advances.data() + from; }
    98 
    99     const Font* fontAt(int index) const { return m_font[index]; }
     94    GlyphBufferGlyph* glyphs(unsigned from) { return m_glyphs.data() + from; }
     95    GlyphBufferAdvance* advances(unsigned from) { return m_advances.data() + from; }
     96    const GlyphBufferGlyph* glyphs(unsigned from) const { return m_glyphs.data() + from; }
     97    const GlyphBufferAdvance* advances(unsigned from) const { return m_advances.data() + from; }
     98
     99    const Font* fontAt(unsigned index) const { return m_font[index]; }
    100100
    101101    void setInitialAdvance(GlyphBufferAdvance initialAdvance) { m_initialAdvance = initialAdvance; }
     
    105105    float leadingExpansion() const { return m_leadingExpansion; }
    106106   
    107     Glyph glyphAt(int index) const
     107    Glyph glyphAt(unsigned index) const
    108108    {
    109109#if USE(CAIRO)
     
    114114    }
    115115
    116     GlyphBufferAdvance advanceAt(int index) const
     116    GlyphBufferAdvance advanceAt(unsigned index) const
    117117    {
    118118        return m_advances[index];
    119119    }
    120120
    121     FloatSize offsetAt(int index) const
     121    FloatSize offsetAt(unsigned index) const
    122122    {
    123123#if PLATFORM(WIN)
     
    181181#endif
    182182
    183     void reverse(int from, int length)
    184     {
    185         for (int i = from, end = from + length - 1; i < end; ++i, --end)
     183    void reverse(unsigned from, unsigned length)
     184    {
     185        for (unsigned i = from, end = from + length - 1; i < end; ++i, --end)
    186186            swap(i, end);
    187187    }
     
    199199    }
    200200
    201     // FIXME: This converts from an unsigned to an int
    202     int offsetInString(int index) const
     201    int offsetInString(unsigned index) const
    203202    {
    204203        ASSERT(m_offsetsInString);
     
    206205    }
    207206
    208     void shrink(int truncationPoint)
     207    void shrink(unsigned truncationPoint)
    209208    {
    210209        m_font.shrink(truncationPoint);
     
    219218
    220219private:
    221     void swap(int index1, int index2)
     220    void swap(unsigned index1, unsigned index2)
    222221    {
    223222        const Font* f = m_font[index1];
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp

    r201629 r204400  
    637637}
    638638
    639 float GraphicsContext::drawText(const FontCascade& font, const TextRun& run, const FloatPoint& point, int from, int to)
     639float GraphicsContext::drawText(const FontCascade& font, const TextRun& run, const FloatPoint& point, unsigned from, Optional<unsigned> to)
    640640{
    641641    if (paintingDisabled())
     
    646646}
    647647
    648 void GraphicsContext::drawGlyphs(const FontCascade& fontCascade, const Font& font, const GlyphBuffer& buffer, int from, int numGlyphs, const FloatPoint& point)
     648void GraphicsContext::drawGlyphs(const FontCascade& fontCascade, const Font& font, const GlyphBuffer& buffer, unsigned from, unsigned numGlyphs, const FloatPoint& point)
    649649{
    650650    if (paintingDisabled())
     
    659659}
    660660
    661 void GraphicsContext::drawEmphasisMarks(const FontCascade& font, const TextRun& run, const AtomicString& mark, const FloatPoint& point, int from, int to)
     661void GraphicsContext::drawEmphasisMarks(const FontCascade& font, const TextRun& run, const AtomicString& mark, const FloatPoint& point, unsigned from, Optional<unsigned> to)
    662662{
    663663    if (paintingDisabled())
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.h

    r201777 r204400  
    382382    TextDrawingModeFlags textDrawingMode() const { return m_state.textDrawingMode; }
    383383
    384     float drawText(const FontCascade&, const TextRun&, const FloatPoint&, int from = 0, int to = -1);
    385     void drawGlyphs(const FontCascade&, const Font&, const GlyphBuffer&, int from, int numGlyphs, const FloatPoint&);
    386     void drawEmphasisMarks(const FontCascade&, const TextRun&, const AtomicString& mark, const FloatPoint&, int from = 0, int to = -1);
     384    float drawText(const FontCascade&, const TextRun&, const FloatPoint&, unsigned from = 0, Optional<unsigned> to = Nullopt);
     385    void drawGlyphs(const FontCascade&, const Font&, const GlyphBuffer&, unsigned from, unsigned numGlyphs, const FloatPoint&);
     386    void drawEmphasisMarks(const FontCascade&, const TextRun&, const AtomicString& mark, const FloatPoint&, unsigned from = 0, Optional<unsigned> to = Nullopt);
    387387    void drawBidiText(const FontCascade&, const TextRun&, const FloatPoint&, FontCascade::CustomFontNotReadyAction = FontCascade::DoNotPaintIfFontNotReady);
    388388
  • trunk/Source/WebCore/platform/graphics/Latin1TextIterator.h

    r170947 r204400  
    2929class Latin1TextIterator {
    3030public:
    31     // The passed in LChar pointer starts at 'currentCharacter'. The iterator operates on the range [currentCharacter, lastCharacter].
    32     // 'endCharacter' denotes the maximum length of the UChar array, which might exceed 'lastCharacter'.
    33     Latin1TextIterator(const LChar* characters, int currentCharacter, int lastCharacter, int /*endCharacter*/)
     31    // The passed in LChar pointer starts at 'currentIndex'. The iterator operates on the range [currentIndex, lastIndex].
     32    // 'endCharacter' denotes the maximum length of the UChar array, which might exceed 'lastIndex'.
     33    Latin1TextIterator(const LChar* characters, unsigned currentIndex, unsigned lastIndex, unsigned /*endCharacter*/)
    3434        : m_characters(characters)
    35         , m_currentCharacter(currentCharacter)
    36         , m_lastCharacter(lastCharacter)
     35        , m_currentIndex(currentIndex)
     36        , m_lastIndex(lastIndex)
    3737    {
    3838    }
     
    4040    bool consume(UChar32& character, unsigned& clusterLength)
    4141    {
    42         if (m_currentCharacter >= m_lastCharacter)
     42        if (m_currentIndex >= m_lastIndex)
    4343            return false;
    4444
     
    5151    {
    5252        m_characters += advanceLength;
    53         m_currentCharacter += advanceLength;
     53        m_currentIndex += advanceLength;
    5454    }
    5555
    56     int currentCharacter() const { return m_currentCharacter; }
     56    unsigned currentIndex() const { return m_currentIndex; }
    5757    const LChar* characters() const { return m_characters; }
    5858
    5959private:
    6060    const LChar* m_characters;
    61     int m_currentCharacter;
    62     int m_lastCharacter;
     61    unsigned m_currentIndex;
     62    unsigned m_lastIndex;
    6363};
    6464
  • trunk/Source/WebCore/platform/graphics/SurrogatePairAwareTextIterator.cpp

    r170947 r204400  
    2828namespace WebCore {
    2929
    30 SurrogatePairAwareTextIterator::SurrogatePairAwareTextIterator(const UChar* characters, int currentCharacter, int lastCharacter, int endCharacter)
     30SurrogatePairAwareTextIterator::SurrogatePairAwareTextIterator(const UChar* characters, unsigned currentIndex, unsigned lastIndex, unsigned endIndex)
    3131    : m_characters(characters)
    32     , m_currentCharacter(currentCharacter)
    33     , m_lastCharacter(lastCharacter)
    34     , m_endCharacter(endCharacter)
     32    , m_currentIndex(currentIndex)
     33    , m_lastIndex(lastIndex)
     34    , m_endIndex(endIndex)
    3535{
    3636}
     
    5858    // Do we have a surrogate pair? If so, determine the full Unicode (32 bit) code point before glyph lookup.
    5959    // Make sure we have another character and it's a low surrogate.
    60     if (m_currentCharacter + 1 >= m_endCharacter)
     60    if (m_currentIndex + 1 >= m_endIndex)
    6161        return false;
    6262
     
    7575    static const uint8_t hiraganaKatakanaVoicingMarksCombiningClass = 8;
    7676
    77     if (m_currentCharacter + 1 >= m_endCharacter)
     77    if (m_currentIndex + 1 >= m_endIndex)
    7878        return 0;
    7979
  • trunk/Source/WebCore/platform/graphics/SurrogatePairAwareTextIterator.h

    r170947 r204400  
    2929class SurrogatePairAwareTextIterator {
    3030public:
    31     // The passed in UChar pointer starts at 'currentCharacter'. The iterator operatoes on the range [currentCharacter, lastCharacter].
    32     // 'endCharacter' denotes the maximum length of the UChar array, which might exceed 'lastCharacter'.
    33     SurrogatePairAwareTextIterator(const UChar*, int currentCharacter, int lastCharacter, int endCharacter);
     31    // The passed in UChar pointer starts at 'currentIndex'. The iterator operatoes on the range [currentIndex, lastIndex].
     32    // 'endIndex' denotes the maximum length of the UChar array, which might exceed 'lastIndex'.
     33    SurrogatePairAwareTextIterator(const UChar*, unsigned currentIndex, unsigned lastIndex, unsigned endIndex);
    3434
    3535    inline bool consume(UChar32& character, unsigned& clusterLength)
    3636    {
    37         if (m_currentCharacter >= m_lastCharacter)
     37        if (m_currentIndex >= m_lastIndex)
    3838            return false;
    3939
     
    5050    {
    5151        m_characters += advanceLength;
    52         m_currentCharacter += advanceLength;
     52        m_currentIndex += advanceLength;
    5353    }
    5454
    55     int currentCharacter() const { return m_currentCharacter; }
     55    unsigned currentIndex() const { return m_currentIndex; }
    5656    const UChar* characters() const { return m_characters; }
    5757
     
    6161
    6262    const UChar* m_characters;
    63     int m_currentCharacter;
    64     int m_lastCharacter;
    65     int m_endCharacter;
     63    unsigned m_currentIndex;
     64    unsigned m_lastIndex;
     65    unsigned m_endIndex;
    6666};
    6767
  • trunk/Source/WebCore/platform/graphics/WidthIterator.cpp

    r198074 r204400  
    8282}
    8383
    84 inline auto WidthIterator::shouldApplyFontTransforms(const GlyphBuffer* glyphBuffer, int lastGlyphCount, UChar32 previousCharacter) const -> TransformsType
     84inline auto WidthIterator::shouldApplyFontTransforms(const GlyphBuffer* glyphBuffer, unsigned lastGlyphCount, UChar32 previousCharacter) const -> TransformsType
    8585{
    8686    if (glyphBuffer && glyphBuffer->size() == (lastGlyphCount + 1) && isSoftBankEmoji(previousCharacter))
     
    9191}
    9292
    93 inline float WidthIterator::applyFontTransforms(GlyphBuffer* glyphBuffer, bool ltr, int& lastGlyphCount, const Font* font, UChar32 previousCharacter, bool force, CharactersTreatedAsSpace& charactersTreatedAsSpace)
     93inline float WidthIterator::applyFontTransforms(GlyphBuffer* glyphBuffer, bool ltr, unsigned& lastGlyphCount, const Font* font, UChar32 previousCharacter, bool force, CharactersTreatedAsSpace& charactersTreatedAsSpace)
    9494{
    9595    ASSERT_UNUSED(previousCharacter, shouldApplyFontTransforms(glyphBuffer, lastGlyphCount, previousCharacter) != WidthIterator::TransformsType::None);
     
    9898        return 0;
    9999
    100     int glyphBufferSize = glyphBuffer->size();
     100    unsigned glyphBufferSize = glyphBuffer->size();
    101101    if (!force && glyphBufferSize <= lastGlyphCount + 1) {
    102102        lastGlyphCount = glyphBufferSize;
     
    106106    GlyphBufferAdvance* advances = glyphBuffer->advances(0);
    107107    float widthDifference = 0;
    108     for (int i = lastGlyphCount; i < glyphBufferSize; ++i)
     108    for (unsigned i = lastGlyphCount; i < glyphBufferSize; ++i)
    109109        widthDifference -= advances[i].width();
    110110
     111    ASSERT(lastGlyphCount <= glyphBufferSize);
    111112    if (!ltr)
    112113        glyphBuffer->reverse(lastGlyphCount, glyphBufferSize - lastGlyphCount);
     
    126127    charactersTreatedAsSpace.clear();
    127128
    128     for (int i = lastGlyphCount; i < glyphBufferSize; ++i)
     129    for (unsigned i = lastGlyphCount; i < glyphBufferSize; ++i)
    129130        widthDifference += advances[i].width();
    130131
     
    182183    const Font& primaryFont = m_font->primaryFont();
    183184    const Font* lastFontData = &primaryFont;
    184     int lastGlyphCount = glyphBuffer ? glyphBuffer->size() : 0;
     185    unsigned lastGlyphCount = glyphBuffer ? glyphBuffer->size() : 0;
    185186
    186187    UChar32 character = 0;
     
    192193    while (textIterator.consume(character, clusterLength)) {
    193194        unsigned advanceLength = clusterLength;
    194         int currentCharacter = textIterator.currentCharacter();
     195        int currentCharacter = textIterator.currentIndex();
    195196        const GlyphData& glyphData = m_font->glyphDataForCharacter(character, rtl);
    196197        Glyph glyph = glyphData.glyph;
     
    350351    }
    351352
    352     unsigned consumedCharacters = textIterator.currentCharacter() - m_currentCharacter;
    353     m_currentCharacter = textIterator.currentCharacter();
     353    unsigned consumedCharacters = textIterator.currentIndex() - m_currentCharacter;
     354    m_currentCharacter = textIterator.currentIndex();
    354355    m_runWidthSoFar += widthSinceLastRounding;
    355356    m_finalRoundingWidth = lastRoundingWidth;
     
    357358}
    358359
    359 unsigned WidthIterator::advance(int offset, GlyphBuffer* glyphBuffer)
    360 {
    361     int length = m_run.length();
     360unsigned WidthIterator::advance(unsigned offset, GlyphBuffer* glyphBuffer)
     361{
     362    unsigned length = m_run.length();
    362363
    363364    if (offset > length)
    364365        offset = length;
    365366
    366     if (m_currentCharacter >= static_cast<unsigned>(offset))
     367    if (m_currentCharacter >= offset)
    367368        return 0;
    368369
     
    378379bool WidthIterator::advanceOneCharacter(float& width, GlyphBuffer& glyphBuffer)
    379380{
    380     int oldSize = glyphBuffer.size();
     381    unsigned oldSize = glyphBuffer.size();
    381382    advance(m_currentCharacter + 1, &glyphBuffer);
    382383    float w = 0;
    383     for (int i = oldSize; i < glyphBuffer.size(); ++i)
     384    for (unsigned i = oldSize; i < glyphBuffer.size(); ++i)
    384385        w += glyphBuffer.advanceAt(i).width();
    385386    width = w;
  • trunk/Source/WebCore/platform/graphics/WidthIterator.h

    r198074 r204400  
    4343    WidthIterator(const FontCascade*, const TextRun&, HashSet<const Font*>* fallbackFonts = 0, bool accountForGlyphBounds = false, bool forTextEmphasis = false);
    4444
    45     unsigned advance(int to, GlyphBuffer*);
     45    unsigned advance(unsigned to, GlyphBuffer*);
    4646    bool advanceOneCharacter(float& width, GlyphBuffer&);
    4747
     
    7171
    7272    enum class TransformsType { None, Forced, NotForced };
    73     TransformsType shouldApplyFontTransforms(const GlyphBuffer*, int lastGlyphCount, UChar32 previousCharacter) const;
    74     float applyFontTransforms(GlyphBuffer*, bool ltr, int& lastGlyphCount, const Font*, UChar32 previousCharacter, bool force, CharactersTreatedAsSpace&);
     73    TransformsType shouldApplyFontTransforms(const GlyphBuffer*, unsigned lastGlyphCount, UChar32 previousCharacter) const;
     74    float applyFontTransforms(GlyphBuffer*, bool ltr, unsigned& lastGlyphCount, const Font*, UChar32 previousCharacter, bool force, CharactersTreatedAsSpace&);
    7575
    7676    HashSet<const Font*>* m_fallbackFonts { nullptr };
  • trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp

    r200919 r204400  
    4848namespace WebCore {
    4949
    50 static void drawGlyphsToContext(cairo_t* context, const Font& font, GlyphBufferGlyph* glyphs, int numGlyphs)
     50static void drawGlyphsToContext(cairo_t* context, const Font& font, GlyphBufferGlyph* glyphs, unsigned numGlyphs)
    5151{
    5252    cairo_matrix_t originalTransform;
     
    6767}
    6868
    69 static void drawGlyphsShadow(GraphicsContext& graphicsContext, const FloatPoint& point, const Font& font, GlyphBufferGlyph* glyphs, int numGlyphs)
     69static void drawGlyphsShadow(GraphicsContext& graphicsContext, const FloatPoint& point, const Font& font, GlyphBufferGlyph* glyphs, unsigned numGlyphs)
    7070{
    7171    ShadowBlur& shadow = graphicsContext.platformContext()->shadowBlur();
     
    9999
    100100void FontCascade::drawGlyphs(GraphicsContext& context, const Font& font, const GlyphBuffer& glyphBuffer,
    101     int from, int numGlyphs, const FloatPoint& point, FontSmoothingMode)
     101    unsigned from, unsigned numGlyphs, const FloatPoint& point, FontSmoothingMode)
    102102{
    103103    if (!font.platformData().size())
     
    107107
    108108    float offset = point.x();
    109     for (int i = 0; i < numGlyphs; i++) {
     109    for (unsigned i = 0; i < numGlyphs; i++) {
    110110        glyphs[i].x = offset;
    111111        glyphs[i].y = point.y();
     
    230230
    231231private:
    232     int m_index;
     232    unsigned m_index;
    233233    const TextRun& m_textRun;
    234234    const GlyphBuffer& m_glyphBuffer;
  • trunk/Source/WebCore/platform/graphics/cairo/FontCairoHarfbuzzNG.cpp

    r194132 r204400  
    4141namespace WebCore {
    4242
    43 float FontCascade::getGlyphsAndAdvancesForComplexText(const TextRun& run, int, int, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot /* forTextEmphasis */) const
     43float FontCascade::getGlyphsAndAdvancesForComplexText(const TextRun& run, unsigned, unsigned, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot /* forTextEmphasis */) const
    4444{
    4545    HarfBuzzShaper shaper(this, run);
     
    5353}
    5454
    55 void FontCascade::drawEmphasisMarksForComplexText(GraphicsContext& /* context */, const TextRun& /* run */, const AtomicString& /* mark */, const FloatPoint& /* point */, int /* from */, int /* to */) const
     55void FontCascade::drawEmphasisMarksForComplexText(GraphicsContext& /* context */, const TextRun& /* run */, const AtomicString& /* mark */, const FloatPoint& /* point */, unsigned /* from */, unsigned /* to */) const
    5656{
    5757    notImplemented();
     
    8686}
    8787
    88 void FontCascade::adjustSelectionRectForComplexText(const TextRun& run, LayoutRect& selectionRect, int from, int to) const
     88void FontCascade::adjustSelectionRectForComplexText(const TextRun& run, LayoutRect& selectionRect, unsigned from, unsigned to) const
    8989{
    9090    HarfBuzzShaper shaper(this, run);
  • trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm

    r200919 r204400  
    7171}
    7272
    73 static inline void fillVectorWithHorizontalGlyphPositions(Vector<CGPoint, 256>& positions, CGContextRef context, const CGSize* advances, size_t count)
     73static inline void fillVectorWithHorizontalGlyphPositions(Vector<CGPoint, 256>& positions, CGContextRef context, const CGSize* advances, unsigned count)
    7474{
    7575    CGAffineTransform matrix = CGAffineTransformInvert(CGContextGetTextMatrix(context));
    7676    positions[0] = CGPointZero;
    77     for (size_t i = 1; i < count; ++i) {
     77    for (unsigned i = 1; i < count; ++i) {
    7878        CGSize advance = CGSizeApplyAffineTransform(advances[i - 1], matrix);
    7979        positions[i].x = positions[i - 1].x + advance.width;
     
    9292}
    9393
    94 static void showLetterpressedGlyphsWithAdvances(const FloatPoint& point, const Font& font, CGContextRef context, const CGGlyph* glyphs, const CGSize* advances, size_t count)
     94static void showLetterpressedGlyphsWithAdvances(const FloatPoint& point, const Font& font, CGContextRef context, const CGGlyph* glyphs, const CGSize* advances, unsigned count)
    9595{
    9696#if ENABLE(LETTERPRESS)
     
    159159};
    160160
    161 static void showGlyphsWithAdvances(const FloatPoint& point, const Font& font, CGContextRef context, const CGGlyph* glyphs, const CGSize* advances, size_t count)
     161static void showGlyphsWithAdvances(const FloatPoint& point, const Font& font, CGContextRef context, const CGGlyph* glyphs, const CGSize* advances, unsigned count)
    162162{
    163163    if (!count)
     
    183183
    184184        CGPoint position = FloatPoint(point.x(), point.y() + font.fontMetrics().floatAscent(IdeographicBaseline) - font.fontMetrics().floatAscent());
    185         for (size_t i = 0; i < count; ++i) {
     185        for (unsigned i = 0; i < count; ++i) {
    186186            CGSize translation = CGSizeApplyAffineTransform(translations[i], rotateLeftTransform);
    187187            positions[i] = CGPointApplyAffineTransform(CGPointMake(position.x - translation.width, position.y + translation.height), transform);
     
    221221}
    222222
    223 void FontCascade::drawGlyphs(GraphicsContext& context, const Font& font, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& anchorPoint, FontSmoothingMode smoothingMode)
     223void FontCascade::drawGlyphs(GraphicsContext& context, const Font& font, const GlyphBuffer& glyphBuffer, unsigned from, unsigned numGlyphs, const FloatPoint& anchorPoint, FontSmoothingMode smoothingMode)
    224224{
    225225    const FontPlatformData& platformData = font.platformData();
     
    435435
    436436private:
    437     int m_index;
     437    unsigned m_index;
    438438    const TextRun& m_textRun;
    439439    const GlyphBuffer& m_glyphBuffer;
     
    489489    MacGlyphToPathTranslator translator(run, glyphBuffer, origin);
    490490    DashArray result;
    491     for (int index = 0; translator.containsMorePaths(); ++index, translator.advance()) {
     491    for (unsigned index = 0; translator.containsMorePaths(); ++index, translator.advance()) {
    492492        GlyphIterationState info = GlyphIterationState(CGPointMake(0, 0), CGPointMake(0, 0), lineExtents.y(), lineExtents.y() + lineExtents.height(), lineExtents.x() + lineExtents.width(), lineExtents.x());
    493493        const Font* localFont = glyphBuffer.fontAt(index);
     
    528528}
    529529
    530 void FontCascade::adjustSelectionRectForComplexText(const TextRun& run, LayoutRect& selectionRect, int from, int to) const
     530void FontCascade::adjustSelectionRectForComplexText(const TextRun& run, LayoutRect& selectionRect, unsigned from, unsigned to) const
    531531{
    532532    ComplexTextController controller(*this, run);
     
    543543}
    544544
    545 float FontCascade::getGlyphsAndAdvancesForComplexText(const TextRun& run, int from, int to, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot forTextEmphasis) const
     545float FontCascade::getGlyphsAndAdvancesForComplexText(const TextRun& run, unsigned from, unsigned to, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot forTextEmphasis) const
    546546{
    547547    float initialAdvance;
     
    566566}
    567567
    568 void FontCascade::drawEmphasisMarksForComplexText(GraphicsContext& context, const TextRun& run, const AtomicString& mark, const FloatPoint& point, int from, int to) const
     568void FontCascade::drawEmphasisMarksForComplexText(GraphicsContext& context, const TextRun& run, const AtomicString& mark, const FloatPoint& point, unsigned from, unsigned to) const
    569569{
    570570    GlyphBuffer glyphBuffer;
  • trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp

    r198655 r204400  
    101101}
    102102
    103 void Recorder::drawGlyphs(const Font& font, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& startPoint, FontSmoothingMode smoothingMode)
     103void Recorder::drawGlyphs(const Font& font, const GlyphBuffer& glyphBuffer, unsigned from, unsigned numGlyphs, const FloatPoint& startPoint, FontSmoothingMode smoothingMode)
    104104{
    105105    DrawingItem& newItem = downcast<DrawingItem>(appendItem(DrawGlyphs::create(font, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs, FloatPoint(), toFloatSize(startPoint), smoothingMode)));
  • trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h

    r198655 r204400  
    8181#endif
    8282
    83     void drawGlyphs(const Font&, const GlyphBuffer&, int from, int numGlyphs, const FloatPoint& anchorPoint, FontSmoothingMode);
     83    void drawGlyphs(const Font&, const GlyphBuffer&, unsigned from, unsigned numGlyphs, const FloatPoint& anchorPoint, FontSmoothingMode);
    8484
    8585    void drawImage(Image&, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions&);
  • trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp

    r198074 r204400  
    9898}
    9999
    100 int HarfBuzzShaper::HarfBuzzRun::characterIndexForXPosition(float targetX)
     100unsigned HarfBuzzShaper::HarfBuzzRun::characterIndexForXPosition(float targetX)
    101101{
    102102    ASSERT(targetX <= m_width);
     
    157157}
    158158
    159 static void normalizeCharacters(const TextRun& run, UChar* destination, int length)
    160 {
    161     int position = 0;
     159static void normalizeCharacters(const TextRun& run, UChar* destination, unsigned length)
     160{
     161    unsigned position = 0;
    162162    bool error = false;
    163163    const UChar* source;
     
    171171    while (position < length) {
    172172        UChar32 character;
    173         int nextPosition = position;
     173        unsigned nextPosition = position;
    174174        U16_NEXT(source, nextPosition, length, character);
    175175        // Don't normalize tabs as they are not treated as spaces for word-end.
     
    205205}
    206206
    207 static void normalizeSpacesAndMirrorChars(const UChar* source, UChar* destination, int length, HarfBuzzShaper::NormalizeMode normalizeMode)
    208 {
    209     int position = 0;
     207static void normalizeSpacesAndMirrorChars(const UChar* source, UChar* destination, unsigned length, HarfBuzzShaper::NormalizeMode normalizeMode)
     208{
     209    unsigned position = 0;
    210210    bool error = false;
    211211    // Iterate characters in source and mirror character if needed.
    212212    while (position < length) {
    213213        UChar32 character;
    214         int nextPosition = position;
     214        unsigned nextPosition = position;
    215215        U16_NEXT(source, nextPosition, length, character);
    216216        // Don't normalize tabs as they are not treated as spaces for word-end
     
    418418
    419419            if (U_GET_GC_MASK(character) & U_GC_M_MASK) {
    420                 int markLength = clusterLength;
     420                unsigned markLength = clusterLength;
    421421                const UChar* markCharactersEnd = iterator.characters() + clusterLength;
    422422                while (markCharactersEnd < normalizedBufferEnd) {
    423423                    UChar32 nextCharacter;
    424                     int nextCharacterLength = 0;
     424                    unsigned nextCharacterLength = 0;
    425425                    U16_NEXT(markCharactersEnd, nextCharacterLength, normalizedBufferEnd - markCharactersEnd, nextCharacter);
    426426                    if (!(U_GET_GC_MASK(nextCharacter) & U_GC_M_MASK))
     
    447447            currentCharacterPosition = iterator.characters();
    448448        }
    449         unsigned numCharactersOfCurrentRun = iterator.currentCharacter() - startIndexOfCurrentRun;
     449        unsigned numCharactersOfCurrentRun = iterator.currentIndex() - startIndexOfCurrentRun;
    450450        hb_script_t script = hb_icu_script_to_script(currentScript);
    451451        m_harfBuzzRuns.append(std::make_unique<HarfBuzzRun>(currentFontData, startIndexOfCurrentRun, numCharactersOfCurrentRun, m_run.direction(), script));
    452452        currentFontData = nextFontData;
    453         startIndexOfCurrentRun = iterator.currentCharacter();
     453        startIndexOfCurrentRun = iterator.currentIndex();
    454454    } while (iterator.consume(character, clusterLength));
    455455
     
    641641}
    642642
    643 FloatRect HarfBuzzShaper::selectionRect(const FloatPoint& point, int height, int from, int to)
     643FloatRect HarfBuzzShaper::selectionRect(const FloatPoint& point, int height, unsigned from, unsigned to)
    644644{
    645645    float currentX = 0;
     
    654654        if (m_run.rtl())
    655655            currentX -= m_harfBuzzRuns[i]->width();
    656         int numCharacters = m_harfBuzzRuns[i]->numCharacters();
    657         if (!foundFromX && from >= 0 && from < numCharacters) {
     656        unsigned numCharacters = m_harfBuzzRuns[i]->numCharacters();
     657        if (!foundFromX && from < numCharacters) {
    658658            fromX = m_harfBuzzRuns[i]->xPositionForOffset(from) + currentX;
    659659            foundFromX = true;
    660         } else
     660        } else {
     661            ASSERT(from >= numCharacters);
    661662            from -= numCharacters;
    662 
    663         if (!foundToX && to >= 0 && to < numCharacters) {
     663        }
     664
     665        if (!foundToX && to < numCharacters) {
    664666            toX = m_harfBuzzRuns[i]->xPositionForOffset(to) + currentX;
    665667            foundToX = true;
    666         } else
     668        } else {
     669            ASSERT(to >= numCharacters);
    667670            to -= numCharacters;
     671        }
    668672
    669673        if (foundFromX && foundToX)
  • trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.h

    r183234 r204400  
    6060    float totalWidth() { return m_totalWidth; }
    6161    int offsetForPosition(float targetX);
    62     FloatRect selectionRect(const FloatPoint&, int height, int from, int to);
     62    FloatRect selectionRect(const FloatPoint&, int height, unsigned from, unsigned to);
    6363
    6464private:
     
    7171        void setWidth(float width) { m_width = width; }
    7272
    73         int characterIndexForXPosition(float targetX);
     73        unsigned characterIndexForXPosition(float targetX);
    7474        float xPositionForOffset(unsigned offset);
    7575
     
    8989        const Font* m_fontData;
    9090        unsigned m_startIndex;
    91         size_t m_numCharacters;
     91        unsigned m_numCharacters;
    9292        unsigned m_numGlyphs;
    9393        TextDirection m_direction;
  • trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.h

    r199735 r204400  
    5555
    5656    // Advance and emit glyphs up to the specified character.
    57     void advance(unsigned to, GlyphBuffer* = 0, GlyphIterationStyle = IncludePartialGlyphs, HashSet<const Font*>* fallbackFonts = 0);
     57    void advance(unsigned to, GlyphBuffer* = nullptr, GlyphIterationStyle = IncludePartialGlyphs, HashSet<const Font*>* fallbackFonts = nullptr);
    5858
    5959    // Compute the character offset for a given x coordinate.
  • trunk/Source/WebCore/platform/graphics/win/FontCGWin.cpp

    r194966 r204400  
    129129
    130130void FontCascade::drawGlyphs(GraphicsContext& graphicsContext, const Font& font, const GlyphBuffer& glyphBuffer,
    131     int from, int numGlyphs, const FloatPoint& point, FontSmoothingMode smoothingMode)
     131    unsigned from, unsigned numGlyphs, const FloatPoint& point, FontSmoothingMode smoothingMode)
    132132{
    133133    CGContextRef cgContext = graphicsContext.platformContext();
  • trunk/Source/WebCore/platform/graphics/win/FontWin.cpp

    r198074 r204400  
    5151}
    5252
    53 void FontCascade::adjustSelectionRectForComplexText(const TextRun& run, LayoutRect& selectionRect, int from, int to) const
     53void FontCascade::adjustSelectionRectForComplexText(const TextRun& run, LayoutRect& selectionRect, unsigned from, unsigned to) const
    5454{
    5555    UniscribeController it(this, run);
     
    6767}
    6868
    69 float FontCascade::getGlyphsAndAdvancesForComplexText(const TextRun& run, int from, int to, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot forTextEmphasis) const
     69float FontCascade::getGlyphsAndAdvancesForComplexText(const TextRun& run, unsigned from, unsigned to, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot forTextEmphasis) const
    7070{
    7171    if (forTextEmphasis) {
     
    9292}
    9393
    94 void FontCascade::drawEmphasisMarksForComplexText(GraphicsContext& context, const TextRun& run, const AtomicString& mark, const FloatPoint& point, int from, int to) const
     94void FontCascade::drawEmphasisMarksForComplexText(GraphicsContext& context, const TextRun& run, const AtomicString& mark, const FloatPoint& point, unsigned from, unsigned to) const
    9595{
    9696    GlyphBuffer glyphBuffer;
  • trunk/Source/WebCore/rendering/EllipsisBox.cpp

    r203681 r204400  
    137137    LayoutRect selectionRect = LayoutRect(x() + paintOffset.x(), y() + paintOffset.y() + rootBox.selectionTop(), 0, rootBox.selectionHeight());
    138138    TextRun run = RenderBlock::constructTextRun(m_str, style, AllowTrailingExpansion);
    139     font.adjustSelectionRectForText(run, selectionRect, 0, -1);
     139    font.adjustSelectionRectForText(run, selectionRect);
    140140    context.fillRect(snapRectToDevicePixelsWithWritingDirection(selectionRect, renderer().document().deviceScaleFactor(), run.ltr()), c);
    141141}
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r204276 r204400  
    131131}
    132132
    133 bool InlineTextBox::isSelected(int startPos, int endPos) const
    134 {
    135     int sPos = std::max(startPos - m_start, 0);
    136     int ePos = std::min(endPos - m_start, static_cast<int>(m_len));
    137     return (sPos < ePos);
     133bool InlineTextBox::isSelected(unsigned startPos, unsigned endPos) const
     134{
     135    int sPos = clampedOffset(startPos);
     136    int ePos = clampedOffset(endPos);
     137    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=160786
     138    // We should only be checking if sPos >= ePos here, because those are the
     139    // indices used to actually generate the selection rect. Allowing us past this guard
     140    // on any other condition creates zero-width selection rects.
     141    return sPos < ePos || (startPos == endPos && startPos >= start() && startPos <= (start() + len()));
    138142}
    139143
     
    142146    RenderObject::SelectionState state = renderer().selectionState();
    143147    if (state == RenderObject::SelectionStart || state == RenderObject::SelectionEnd || state == RenderObject::SelectionBoth) {
    144         int startPos, endPos;
     148        unsigned startPos, endPos;
    145149        renderer().selectionStartEnd(startPos, endPos);
    146150        // The position after a hard line break is considered to be past its end.
    147         int lastSelectable = start() + len() - (isLineBreak() ? 1 : 0);
     151        ASSERT(start() + len() >= (isLineBreak() ? 1 : 0));
     152        unsigned lastSelectable = start() + len() - (isLineBreak() ? 1 : 0);
    148153
    149154        bool start = (state != RenderObject::SelectionEnd && startPos >= m_start && startPos < m_start + m_len);
     
    166171        EllipsisBox* ellipsis = root().ellipsisBox();
    167172        if (state != RenderObject::SelectionNone) {
    168             int selectionStart;
    169             int selectionEnd;
     173            unsigned selectionStart;
     174            unsigned selectionEnd;
    170175            std::tie(selectionStart, selectionEnd) = selectionStartEnd();
    171176            // The ellipsis should be considered to be selected if the end of
     
    192197}
    193198
    194 LayoutRect InlineTextBox::localSelectionRect(int startPos, int endPos) const
    195 {
    196     int sPos = std::max(startPos - m_start, 0);
    197     int ePos = std::min(endPos - m_start, (int)m_len);
    198    
    199     if (sPos > ePos)
     199LayoutRect InlineTextBox::localSelectionRect(unsigned startPos, unsigned endPos) const
     200{
     201    unsigned sPos = clampedOffset(startPos);
     202    unsigned ePos = clampedOffset(endPos);
     203
     204    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=160786
     205    // We should only be checking if sPos >= ePos here, because those are the
     206    // indices used to actually generate the selection rect. Allowing us past this guard
     207    // on any other condition creates zero-width selection rects.
     208    if (sPos >= ePos && !(startPos == endPos && startPos >= start() && startPos <= (start() + len())))
    200209        return LayoutRect();
    201210
     
    213222    LayoutRect selectionRect = LayoutRect(LayoutPoint(logicalLeft(), selectionTop), LayoutSize(m_logicalWidth, selectionHeight));
    214223    // Avoid computing the font width when the entire line box is selected as an optimization.
    215     if (sPos || ePos != static_cast<int>(m_len))
     224    if (sPos || ePos != m_len)
    216225        font.adjustSelectionRectForText(textRun, selectionRect, sPos, ePos);
    217226    IntRect snappedSelectionRect = enclosingIntRect(selectionRect);
     
    509518    unsigned length = textRun.length();
    510519
    511     int selectionStart = 0;
    512     int selectionEnd = 0;
     520    unsigned selectionStart = 0;
     521    unsigned selectionEnd = 0;
    513522    if (haveSelection && (paintSelectedTextOnly || paintSelectedTextSeparately))
    514523        std::tie(selectionStart, selectionEnd) = selectionStartEnd();
    515524
    516525    if (m_truncation != cNoTruncation) {
    517         selectionStart = std::min<int>(selectionStart, m_truncation);
    518         selectionEnd = std::min<int>(selectionEnd, m_truncation);
     526        selectionStart = std::min(selectionStart, static_cast<unsigned>(m_truncation));
     527        selectionEnd = std::min(selectionEnd, static_cast<unsigned>(m_truncation));
    519528        length = m_truncation;
    520529    }
    521530
    522     int emphasisMarkOffset = 0;
     531    float emphasisMarkOffset = 0;
    523532    bool emphasisMarkAbove;
    524533    bool hasTextEmphasis = emphasisMarkExistsAndIsAbove(lineStyle, emphasisMarkAbove);
     
    588597}
    589598
    590 std::pair<int, int> InlineTextBox::selectionStartEnd() const
     599unsigned InlineTextBox::clampedOffset(unsigned x) const
     600{
     601    return std::max(std::min(x, start() + len()), start()) - start();
     602}
     603
     604std::pair<unsigned, unsigned> InlineTextBox::selectionStartEnd() const
    591605{
    592606    auto selectionState = renderer().selectionState();
     
    594608        return { 0, m_len };
    595609   
    596     int start;
    597     int end;
     610    unsigned start;
     611    unsigned end;
    598612    renderer().selectionStartEnd(start, end);
    599613    if (selectionState == RenderObject::SelectionStart)
     
    601615    else if (selectionState == RenderObject::SelectionEnd)
    602616        start = 0;
    603     return { std::max(start - m_start, 0), std::min<int>(end - m_start, m_len) };
     617    return { clampedOffset(start), clampedOffset(end) };
    604618}
    605619
     
    611625
    612626    // See if we have a selection to paint at all.
    613     int selectionStart;
    614     int selectionEnd;
     627    unsigned selectionStart;
     628    unsigned selectionEnd;
    615629    std::tie(selectionStart, selectionEnd) = selectionStartEnd();
    616630    if (selectionStart >= selectionEnd)
     
    635649
    636650    String hyphenatedString;
    637     bool respectHyphen = selectionEnd == static_cast<int>(length) && hasHyphen();
     651    bool respectHyphen = selectionEnd == length && hasHyphen();
    638652    if (respectHyphen)
    639653        hyphenatedString = hyphenatedStringForTextRun(style, length);
     
    661675}
    662676
    663 void InlineTextBox::paintCompositionBackground(GraphicsContext& context, const FloatPoint& boxOrigin, const RenderStyle& style, const FontCascade& font, int startPos, int endPos)
    664 {
    665     int offset = m_start;
    666     int selectionStart = std::max(startPos - offset, 0);
    667     int selectionEnd = std::min<int>(endPos - offset, m_len);
     677void InlineTextBox::paintCompositionBackground(GraphicsContext& context, const FloatPoint& boxOrigin, const RenderStyle& style, const FontCascade& font, unsigned startPos, unsigned endPos)
     678{
     679    unsigned selectionStart = clampedOffset(startPos);
     680    unsigned selectionEnd = clampedOffset(endPos);
    668681    if (selectionStart >= selectionEnd)
    669682        return;
     
    757770    // Determine whether we need to measure text
    758771    bool markerSpansWholeBox = true;
    759     if (m_start <= (int)marker.startOffset())
     772    if (m_start <= marker.startOffset())
    760773        markerSpansWholeBox = false;
    761774    if ((end() + 1) != marker.endOffset()) // end points at the last char, not past it
     
    766779    bool isDictationMarker = marker.type() == DocumentMarker::DictationAlternatives;
    767780    if (!markerSpansWholeBox || grammar || isDictationMarker) {
    768         int startPosition = std::max<int>(marker.startOffset() - m_start, 0);
    769         int endPosition = std::min<int>(marker.endOffset() - m_start, m_len);
     781        unsigned startPosition = clampedOffset(marker.startOffset());
     782        unsigned endPosition = clampedOffset(marker.endOffset());
    770783       
    771784        if (m_truncation != cNoTruncation)
    772             endPosition = std::min<int>(endPosition, m_truncation);
     785            endPosition = std::min(endPosition, static_cast<unsigned>(m_truncation));
    773786
    774787        // Calculate start & width
     
    819832    LayoutRect selectionRect = LayoutRect(boxOrigin.x(), boxOrigin.y() - deltaY, 0, this->selectionHeight());
    820833
    821     int sPos = std::max<int>(marker.startOffset() - m_start, 0);
    822     int ePos = std::min<int>(marker.endOffset() - m_start, m_len);
     834    unsigned sPos = clampedOffset(marker.startOffset());
     835    unsigned ePos = clampedOffset(marker.endOffset());
    823836    TextRun run = constructTextRun(style);
    824837    font.adjustSelectionRectForText(run, selectionRect, sPos, ePos);
     
    986999}
    9871000
    988 float InlineTextBox::positionForOffset(int offset) const
     1001float InlineTextBox::positionForOffset(unsigned offset) const
    9891002{
    9901003    ASSERT(offset >= m_start);
    991     ASSERT(offset <= m_start + m_len);
     1004    ASSERT(offset <= m_start + len());
    9921005
    9931006    if (isLineBreak())
     
    9961009    const RenderStyle& lineStyle = this->lineStyle();
    9971010    const FontCascade& font = fontToUse(lineStyle, renderer());
    998     int from = !isLeftToRightDirection() ? offset - m_start : 0;
    999     int to = !isLeftToRightDirection() ? m_len : offset - m_start;
     1011    unsigned from = !isLeftToRightDirection() ? clampedOffset(offset) : 0;
     1012    unsigned to = !isLeftToRightDirection() ? m_len : clampedOffset(offset);
    10001013    // FIXME: Do we need to add rightBearing here?
    10011014    LayoutRect selectionRect = LayoutRect(logicalLeft(), 0, 0, 0);
  • trunk/Source/WebCore/rendering/InlineTextBox.h

    r204276 r204400  
    4343    explicit InlineTextBox(RenderText& renderer)
    4444        : InlineBox(renderer)
    45         , m_prevTextBox(nullptr)
    46         , m_nextTextBox(nullptr)
    47         , m_start(0)
    48         , m_len(0)
    49         , m_truncation(cNoTruncation)
    5045    {
    5146        setBehavesLikeText(true);
     
    7065    void setLen(unsigned len) { m_len = len; }
    7166
    72     void offsetRun(int d) { ASSERT(!isDirty()); m_start += d; }
     67    void offsetRun(int d) { ASSERT(!isDirty()); ASSERT(d > 0 || m_start >= static_cast<unsigned>(-d)); m_start += d; }
    7368
    7469    unsigned short truncation() const { return m_truncation; }
     
    121116    FloatRect calculateBoundaries() const override { return FloatRect(x(), y(), width(), height()); }
    122117
    123     virtual LayoutRect localSelectionRect(int startPos, int endPos) const;
    124     bool isSelected(int startPos, int endPos) const;
    125     std::pair<int, int> selectionStartEnd() const;
     118    virtual LayoutRect localSelectionRect(unsigned startPos, unsigned endPos) const;
     119    bool isSelected(unsigned startPos, unsigned endPos) const;
     120    std::pair<unsigned, unsigned> selectionStartEnd() const;
    126121
    127122protected:
     
    156151public:
    157152    virtual int offsetForPosition(float x, bool includePartialGlyphs = true) const;
    158     virtual float positionForOffset(int offset) const;
     153    virtual float positionForOffset(unsigned offset) const;
    159154
    160155protected:
    161     void paintCompositionBackground(GraphicsContext&, const FloatPoint& boxOrigin, const RenderStyle&, const FontCascade&, int startPos, int endPos);
     156    void paintCompositionBackground(GraphicsContext&, const FloatPoint& boxOrigin, const RenderStyle&, const FontCascade&, unsigned startPos, unsigned endPos);
    162157    void paintDocumentMarkers(GraphicsContext&, const FloatPoint& boxOrigin, const RenderStyle&, const FontCascade&, bool background);
    163158    void paintCompositionUnderline(GraphicsContext&, const FloatPoint& boxOrigin, const CompositionUnderline&);
     159    unsigned clampedOffset(unsigned) const;
    164160
    165161private:
     
    174170    void behavesLikeText() const = delete;
    175171
    176     InlineTextBox* m_prevTextBox; // The previous box that also uses our RenderObject
    177     InlineTextBox* m_nextTextBox; // The next box that also uses our RenderObject
     172    InlineTextBox* m_prevTextBox { nullptr }; // The previous box that also uses our RenderObject
     173    InlineTextBox* m_nextTextBox { nullptr }; // The next box that also uses our RenderObject
    178174
    179     int m_start;
    180     unsigned short m_len;
     175    unsigned m_start { 0 };
     176    unsigned short m_len { 0 };
    181177
    182178    // Where to truncate when text overflow is applied. We use special constants to
    183179    // denote no truncation (the whole run paints) and full truncation (nothing paints at all).
    184     unsigned short m_truncation;
     180    unsigned short m_truncation { cNoTruncation };
    185181};
    186182
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r203708 r204400  
    34903490}
    34913491
    3492 LayoutRect RenderBlock::localCaretRect(InlineBox* inlineBox, int caretOffset, LayoutUnit* extraWidthToEndOfLine)
     3492LayoutRect RenderBlock::localCaretRect(InlineBox* inlineBox, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine)
    34933493{
    34943494    // Do the normal calculation in most cases.
  • trunk/Source/WebCore/rendering/RenderBlock.h

    r203708 r204400  
    477477    void paintContinuationOutlines(PaintInfo&, const LayoutPoint&);
    478478
    479     LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) final;
     479    LayoutRect localCaretRect(InlineBox*, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) final;
    480480   
    481481    // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
  • trunk/Source/WebCore/rendering/RenderBox.cpp

    r203738 r204400  
    43844384}
    43854385
    4386 LayoutRect RenderBox::localCaretRect(InlineBox* box, int caretOffset, LayoutUnit* extraWidthToEndOfLine)
     4386LayoutRect RenderBox::localCaretRect(InlineBox* box, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine)
    43874387{
    43884388    // VisiblePositions at offsets inside containers either a) refer to the positions before/after
  • trunk/Source/WebCore/rendering/RenderBox.h

    r203708 r204400  
    482482    bool isUnsplittableForPagination() const;
    483483
    484     LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = nullptr) override;
     484    LayoutRect localCaretRect(InlineBox*, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine = nullptr) override;
    485485
    486486    virtual LayoutRect overflowClipRect(const LayoutPoint& location, RenderRegion*, OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize, PaintPhase = PaintPhaseBlockBackground);
  • trunk/Source/WebCore/rendering/RenderInline.cpp

    r203708 r204400  
    250250}
    251251
    252 LayoutRect RenderInline::localCaretRect(InlineBox* inlineBox, int, LayoutUnit* extraWidthToEndOfLine)
     252LayoutRect RenderInline::localCaretRect(InlineBox* inlineBox, unsigned, LayoutUnit* extraWidthToEndOfLine)
    253253{
    254254    if (firstChild()) {
  • trunk/Source/WebCore/rendering/RenderInline.h

    r201704 r204400  
    9797    void updateAlwaysCreateLineBoxes(bool fullLayout);
    9898
    99     LayoutRect localCaretRect(InlineBox*, int, LayoutUnit* extraWidthToEndOfLine) final;
     99    LayoutRect localCaretRect(InlineBox*, unsigned, LayoutUnit* extraWidthToEndOfLine) final;
    100100
    101101    bool hitTestCulledInline(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset);
  • trunk/Source/WebCore/rendering/RenderLineBreak.cpp

    r200953 r204400  
    167167}
    168168
    169 LayoutRect RenderLineBreak::localCaretRect(InlineBox* inlineBox, int caretOffset, LayoutUnit* extraWidthToEndOfLine)
     169LayoutRect RenderLineBreak::localCaretRect(InlineBox* inlineBox, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine)
    170170{
    171171    ASSERT_UNUSED(caretOffset, !caretOffset);
  • trunk/Source/WebCore/rendering/RenderLineBreak.h

    r200041 r204400  
    6767    int caretMaxOffset() const override;
    6868    bool canBeSelectionLeaf() const override;
    69     LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine) override;
     69    LayoutRect localCaretRect(InlineBox*, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine) override;
    7070    void setSelectionState(SelectionState) override;
    7171
  • trunk/Source/WebCore/rendering/RenderObject.cpp

    r203091 r204400  
    12071207}
    12081208
    1209 void RenderObject::selectionStartEnd(int& spos, int& epos) const
     1209void RenderObject::selectionStartEnd(unsigned& spos, unsigned& epos) const
    12101210{
    12111211    selectionRoot().selectionData().selectionStartEndPositions(spos, epos);
     
    13781378}
    13791379
    1380 LayoutRect RenderObject::localCaretRect(InlineBox*, int, LayoutUnit* extraWidthToEndOfLine)
     1380LayoutRect RenderObject::localCaretRect(InlineBox*, unsigned, LayoutUnit* extraWidthToEndOfLine)
    13811381{
    13821382    if (extraWidthToEndOfLine)
  • trunk/Source/WebCore/rendering/RenderObject.h

    r203973 r204400  
    750750     * useful for character range rect computations
    751751     */
    752     virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = nullptr);
     752    virtual LayoutRect localCaretRect(InlineBox*, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine = nullptr);
    753753
    754754    // When performing a global document tear-down, the renderer of the document is cleared.  We use this
     
    783783
    784784    SelectionSubtreeRoot& selectionRoot() const;
    785     void selectionStartEnd(int& spos, int& epos) const;
     785    void selectionStartEnd(unsigned& spos, unsigned& epos) const;
    786786   
    787787    void removeFromParent();
  • trunk/Source/WebCore/rendering/RenderReplaced.cpp

    r201889 r204400  
    617617        return true;
    618618
    619     int selectionStart, selectionEnd;
     619    unsigned selectionStart, selectionEnd;
    620620    selectionStartEnd(selectionStart, selectionEnd);
    621621    if (s == SelectionStart)
    622622        return selectionStart == 0;
    623623       
    624     int end = element()->hasChildNodes() ? element()->countChildNodes() : 1;
     624    unsigned end = element()->hasChildNodes() ? element()->countChildNodes() : 1;
    625625    if (s == SelectionEnd)
    626626        return selectionEnd == end;
     
    628628        return selectionStart == 0 && selectionEnd == end;
    629629       
    630     ASSERT(0);
     630    ASSERT_NOT_REACHED();
    631631    return false;
    632632}
  • trunk/Source/WebCore/rendering/RenderText.cpp

    r203042 r204400  
    443443}
    444444
    445 LayoutRect RenderText::localCaretRect(InlineBox* inlineBox, int caretOffset, LayoutUnit* extraWidthToEndOfLine)
     445LayoutRect RenderText::localCaretRect(InlineBox* inlineBox, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine)
    446446{
    447447    if (!inlineBox)
     
    13731373    if (selectionState() == SelectionNone)
    13741374        return LayoutRect();
    1375     RenderBlock* cb = containingBlock();
    1376     if (!cb)
     1375    if (!containingBlock())
    13771376        return LayoutRect();
    13781377
    13791378    // Now calculate startPos and endPos for painting selection.
    13801379    // We include a selection while endPos > 0
    1381     int startPos, endPos;
     1380    unsigned startPos, endPos;
    13821381    if (selectionState() == SelectionInside) {
    13831382        // We are fully selected.
  • trunk/Source/WebCore/rendering/RenderText.h

    r203038 r204400  
    120120    void setSelectionState(SelectionState) final;
    121121    LayoutRect selectionRectForRepaint(const RenderLayerModelObject* repaintContainer, bool clipToVisibleContent = true) override;
    122     LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) override;
     122    LayoutRect localCaretRect(InlineBox*, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) override;
    123123
    124124    LayoutRect collectSelectionRectsForLineBoxes(const RenderLayerModelObject* repaintContainer, bool clipToVisibleContent, Vector<LayoutRect>& rects);
  • trunk/Source/WebCore/rendering/RenderTextLineBoxes.cpp

    r191002 r204400  
    446446    }
    447447
    448     int start, end;
     448    unsigned start, end;
    449449    renderer.selectionStartEnd(start, end);
    450450    if (state == RenderObject::SelectionStart) {
  • trunk/Source/WebCore/rendering/RenderView.cpp

    r203751 r204400  
    119119    : RenderBlockFlow(document, WTFMove(style))
    120120    , m_frameView(*document.view())
    121     , m_selectionUnsplitStart(nullptr)
    122     , m_selectionUnsplitEnd(nullptr)
    123     , m_selectionUnsplitStartPos(-1)
    124     , m_selectionUnsplitEndPos(-1)
    125121    , m_lazyRepaintTimer(*this, &RenderView::lazyRepaintTimerFired)
    126     , m_pageLogicalHeight(0)
    127     , m_pageLogicalHeightChanged(false)
    128     , m_layoutState(nullptr)
    129     , m_layoutStateDisableCount(0)
    130     , m_renderQuoteHead(nullptr)
    131     , m_renderCounterCount(0)
    132     , m_selectionWasCaret(false)
    133     , m_hasSoftwareFilters(false)
    134122#if ENABLE(SERVICE_CONTROLS)
    135123    , m_selectionRectGatherer(*this)
     
    773761
    774762    RenderObject* os = root.selectionData().selectionStart();
    775     RenderObject* stop = rendererAfterPosition(root.selectionData().selectionEnd(), root.selectionData().selectionEndPos());
     763    auto* selectionEnd = root.selectionData().selectionEnd();
     764    RenderObject* stop = nullptr;
     765    if (selectionEnd)
     766        stop = rendererAfterPosition(selectionEnd, root.selectionData().selectionEndPos().value());
    776767    SelectionIterator selectionIterator(os);
    777768    while (os && os != stop) {
     
    822813    HashSet<RenderBlock*> processedBlocks;
    823814
    824     RenderObject* end = rendererAfterPosition(root.selectionData().selectionEnd(), root.selectionData().selectionEndPos());
     815    auto* selectionEnd = root.selectionData().selectionEnd();
     816    RenderObject* end = nullptr;
     817    if (selectionEnd)
     818        end = rendererAfterPosition(selectionEnd, root.selectionData().selectionEndPos().value());
    825819    SelectionIterator selectionIterator(root.selectionData().selectionStart());
    826820    for (RenderObject* o = selectionIterator.current(); o && o != end; o = selectionIterator.next()) {
     
    841835}
    842836
    843 void RenderView::setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode blockRepaintMode)
     837void RenderView::setSelection(RenderObject* start, Optional<unsigned> startPos, RenderObject* end, Optional<unsigned> endPos, SelectionRepaintMode blockRepaintMode)
    844838{
    845839    // Make sure both our start and end objects are defined.
     
    878872}
    879873
    880 void RenderView::splitSelectionBetweenSubtrees(const RenderObject* start, int startPos, const RenderObject* end, int endPos, SelectionRepaintMode blockRepaintMode)
     874void RenderView::splitSelectionBetweenSubtrees(const RenderObject* start, Optional<unsigned> startPos, const RenderObject* end, Optional<unsigned> endPos, SelectionRepaintMode blockRepaintMode)
    881875{
    882876    // Compute the visible selection end points for each of the subtrees.
     
    903897            if (selectionData.selectionClear()) {
    904898                selectionData.setSelectionStart(node->renderer());
    905                 selectionData.setSelectionStartPos(node == startNode ? startPos : 0);
     899                selectionData.setSelectionStartPos(node == startNode ? startPos : Optional<unsigned>(0));
    906900            }
    907901
     
    909903            if (node == endNode)
    910904                selectionData.setSelectionEndPos(endPos);
    911             else
    912                 selectionData.setSelectionEndPos(node->offsetInCharacters() ? node->maxCharacterOffset() : node->countChildNodes());
     905            else {
     906                unsigned newEndPos = node->offsetInCharacters() ? node->maxCharacterOffset() : node->countChildNodes();
     907                selectionData.setSelectionEndPos(newEndPos);
     908            }
    913909
    914910            renderSubtreesMap.set(&root, selectionData);
     
    961957
    962958    RenderObject* os = root.selectionData().selectionStart();
    963     RenderObject* stop = rendererAfterPosition(root.selectionData().selectionEnd(), root.selectionData().selectionEndPos());
     959    auto* selectionEnd = root.selectionData().selectionEnd();
     960    RenderObject* stop = nullptr;
     961    if (selectionEnd)
     962        stop = rendererAfterPosition(selectionEnd, root.selectionData().selectionEndPos().value());
    964963    SelectionIterator selectionIterator(os);
    965964    while (os && os != stop) {
     
    999998
    1000999    RenderObject* selectionStart = root.selectionData().selectionStart();
    1001     RenderObject* selectionEnd = rendererAfterPosition(root.selectionData().selectionEnd(), root.selectionData().selectionEndPos());
     1000    auto* selectionDataEnd = root.selectionData().selectionEnd();
     1001    RenderObject* selectionEnd = nullptr;
     1002    if (selectionDataEnd)
     1003        selectionEnd = rendererAfterPosition(selectionDataEnd, root.selectionData().selectionEndPos().value());
    10021004    SelectionIterator selectionIterator(selectionStart);
    10031005    for (RenderObject* currentRenderer = selectionStart; currentRenderer && currentRenderer != selectionEnd; currentRenderer = selectionIterator.next()) {
     
    10901092}
    10911093
    1092 void RenderView::getSelection(RenderObject*& startRenderer, int& startOffset, RenderObject*& endRenderer, int& endOffset) const
     1094void RenderView::getSelection(RenderObject*& startRenderer, Optional<unsigned>& startOffset, RenderObject*& endRenderer, Optional<unsigned>& endOffset) const
    10931095{
    10941096    startRenderer = m_selectionUnsplitStart;
     
    11011103{
    11021104    layer()->repaintBlockSelectionGaps();
    1103     setSelection(nullptr, -1, nullptr, -1, RepaintNewMinusOld);
     1105    setSelection(nullptr, Nullopt, nullptr, Nullopt, RepaintNewMinusOld);
    11041106}
    11051107
  • trunk/Source/WebCore/rendering/RenderView.h

    r203751 r204400  
    8686
    8787    enum SelectionRepaintMode { RepaintNewXOROld, RepaintNewMinusOld, RepaintNothing };
    88     void setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode = RepaintNewXOROld);
    89     void getSelection(RenderObject*& startRenderer, int& startOffset, RenderObject*& endRenderer, int& endOffset) const;
     88    void setSelection(RenderObject* start, Optional<unsigned> startPos, RenderObject* endObject, Optional<unsigned> endPos, SelectionRepaintMode = RepaintNewXOROld);
     89    void getSelection(RenderObject*& startRenderer, Optional<unsigned>& startOffset, RenderObject*& endRenderer, Optional<unsigned>& endOffset) const;
    9090    void clearSelection();
    9191    RenderObject* selectionUnsplitStart() const { return m_selectionUnsplitStart; }
     
    308308    bool isScrollableOrRubberbandableBox() const override;
    309309
    310     void splitSelectionBetweenSubtrees(const RenderObject* startRenderer, int startPos, const RenderObject* endRenderer, int endPos, SelectionRepaintMode blockRepaintMode);
     310    void splitSelectionBetweenSubtrees(const RenderObject* startRenderer, Optional<unsigned> startPos, const RenderObject* endRenderer, Optional<unsigned> endPos, SelectionRepaintMode blockRepaintMode);
    311311    void clearSubtreeSelection(const SelectionSubtreeRoot&, SelectionRepaintMode, OldSelectionData&) const;
    312312    void updateSelectionForSubtrees(RenderSubtreesMap&, SelectionRepaintMode);
     
    318318    FrameView& m_frameView;
    319319
    320     RenderObject* m_selectionUnsplitStart;
    321     RenderObject* m_selectionUnsplitEnd;
    322     int m_selectionUnsplitStartPos;
    323     int m_selectionUnsplitEndPos;
     320    RenderObject* m_selectionUnsplitStart { nullptr };
     321    RenderObject* m_selectionUnsplitEnd { nullptr };
     322    Optional<unsigned> m_selectionUnsplitStartPos;
     323    Optional<unsigned> m_selectionUnsplitEndPos;
    324324
    325325    // Include this RenderView.
     
    330330    // FIXME: Only used by embedded WebViews inside AppKit NSViews.  Find a way to remove.
    331331    struct LegacyPrinting {
    332         LegacyPrinting()
    333             : m_bestTruncatedAt(0)
    334             , m_truncatedAt(0)
    335             , m_truncatorWidth(0)
    336             , m_forcedPageBreak(false)
    337         { }
    338 
    339         int m_bestTruncatedAt;
    340         int m_truncatedAt;
    341         int m_truncatorWidth;
     332        int m_bestTruncatedAt { 0 };
     333        int m_truncatedAt { 0 };
     334        int m_truncatorWidth { 0 };
    342335        IntRect m_printRect;
    343         bool m_forcedPageBreak;
     336        bool m_forcedPageBreak { false };
    344337    };
    345338    LegacyPrinting m_legacyPrinting;
     
    355348    std::unique_ptr<ImageQualityController> m_imageQualityController;
    356349    LayoutUnit m_pageLogicalHeight;
    357     bool m_pageLogicalHeightChanged;
     350    bool m_pageLogicalHeightChanged { false };
    358351    std::unique_ptr<LayoutState> m_layoutState;
    359     unsigned m_layoutStateDisableCount;
     352    unsigned m_layoutStateDisableCount { 0 };
    360353    std::unique_ptr<RenderLayerCompositor> m_compositor;
    361354    std::unique_ptr<FlowThreadController> m_flowThreadController;
    362355
    363     RenderQuote* m_renderQuoteHead;
    364     unsigned m_renderCounterCount;
    365 
    366     bool m_selectionWasCaret;
    367     bool m_hasSoftwareFilters;
     356    RenderQuote* m_renderQuoteHead { nullptr };
     357    unsigned m_renderCounterCount { 0 };
     358
     359    bool m_selectionWasCaret { false };
     360    bool m_hasSoftwareFilters { false };
    368361    bool m_usesFirstLineRules { false };
    369362    bool m_usesFirstLetterRules { false };
  • trunk/Source/WebCore/rendering/SelectionSubtreeRoot.cpp

    r185838 r204400  
    4343}
    4444
    45 SelectionSubtreeRoot::SelectionSubtreeRoot(RenderObject* selectionStart, int selectionStartPos, RenderObject* selectionEnd, int selectionEndPos)
    46     : m_selectionSubtreeData(selectionStart, selectionStartPos, selectionEnd, selectionEndPos)
    47 {
    48 }
    49 
    5045void SelectionSubtreeRoot::adjustForVisibleSelection(Document& document)
    5146{
     
    5449
    5550    // Create a range based on the cached end points
    56     Position startPosition = createLegacyEditingPosition(m_selectionSubtreeData.selectionStart()->node(), m_selectionSubtreeData.selectionStartPos());
    57     Position endPosition = createLegacyEditingPosition(m_selectionSubtreeData.selectionEnd()->node(), m_selectionSubtreeData.selectionEndPos());
     51    auto selectionStart = m_selectionSubtreeData.selectionStartPos().value();
     52    auto selectionEnd = m_selectionSubtreeData.selectionEndPos().value();
     53    Position startPosition = createLegacyEditingPosition(m_selectionSubtreeData.selectionStart()->node(), selectionStart);
     54    Position endPosition = createLegacyEditingPosition(m_selectionSubtreeData.selectionEnd()->node(), selectionEnd);
    5855
    5956    RefPtr<Range> range = Range::create(document, startPosition.parentAnchoredEquivalent(), endPosition.parentAnchoredEquivalent());
     
    8380        return;
    8481
     82    auto newStartPos = startPos.deprecatedEditingOffset();
     83    auto newEndPos = endPos.deprecatedEditingOffset();
     84    ASSERT(newStartPos >= 0 && newEndPos >= 0);
    8585    m_selectionSubtreeData.setSelectionStart(startPos.deprecatedNode()->renderer());
    86     m_selectionSubtreeData.setSelectionStartPos(startPos.deprecatedEditingOffset());
     86    m_selectionSubtreeData.setSelectionStartPos(newStartPos);
    8787    m_selectionSubtreeData.setSelectionEnd(endPos.deprecatedNode()->renderer());
    88     m_selectionSubtreeData.setSelectionEndPos(endPos.deprecatedEditingOffset());
     88    m_selectionSubtreeData.setSelectionEndPos(newEndPos);
    8989}
    9090
  • trunk/Source/WebCore/rendering/SelectionSubtreeRoot.h

    r175252 r204400  
    4646    struct OldSelectionData {
    4747        OldSelectionData()
    48             : selectionStartPos(-1)
    49             , selectionEndPos(-1)
    5048        {
    5149        }
    5250
    53         int selectionStartPos;
    54         int selectionEndPos;
     51        Optional<unsigned> selectionStartPos;
     52        Optional<unsigned> selectionEndPos;
    5553        SelectedObjectMap selectedObjects;
    5654        SelectedBlockMap selectedBlocks;
     
    5957    class SelectionSubtreeData {
    6058    public:
    61         SelectionSubtreeData()
    62             : m_selectionStart(nullptr)
    63             , m_selectionStartPos(-1)
    64             , m_selectionEnd(nullptr)
    65             , m_selectionEndPos(-1)
    66         {
    67         }
     59        SelectionSubtreeData() = default;
    6860
    69         SelectionSubtreeData(RenderObject* selectionStart, int selectionStartPos, RenderObject* selectionEnd, int selectionEndPos)
     61        SelectionSubtreeData(RenderObject* selectionStart, Optional<unsigned> selectionStartPos, RenderObject* selectionEnd, Optional<unsigned> selectionEndPos)
    7062            : m_selectionStart(selectionStart)
    7163            , m_selectionStartPos(selectionStartPos)
     
    7668
    7769        RenderObject* selectionStart() const { return m_selectionStart; }
    78         int selectionStartPos() const { return m_selectionStartPos; }
     70        Optional<unsigned> selectionStartPos() const { return m_selectionStartPos; }
    7971        RenderObject* selectionEnd() const { return m_selectionEnd; }
    80         int selectionEndPos() const { return m_selectionEndPos; }
     72        Optional<unsigned> selectionEndPos() const { return m_selectionEndPos; }
    8173        bool selectionClear() const
    8274        {
    8375            return !m_selectionStart
    84             && (m_selectionStartPos == -1)
     76            && (!m_selectionStartPos)
    8577            && !m_selectionEnd
    86             && (m_selectionEndPos == -1);
     78            && (!m_selectionEndPos);
    8779        }
    8880
    89         void selectionStartEndPositions(int& startPos, int& endPos) const
     81        void selectionStartEndPositions(unsigned& startPos, unsigned& endPos) const
    9082        {
    91             startPos = m_selectionStartPos;
    92             endPos = m_selectionEndPos;
     83            startPos = m_selectionStartPos.value();
     84            endPos = m_selectionEndPos.value();
    9385        }
    9486        void setSelectionStart(RenderObject* selectionStart) { m_selectionStart = selectionStart; }
    95         void setSelectionStartPos(int selectionStartPos) { m_selectionStartPos = selectionStartPos; }
     87        void setSelectionStartPos(Optional<unsigned> selectionStartPos) { m_selectionStartPos = selectionStartPos;}
    9688        void setSelectionEnd(RenderObject* selectionEnd) { m_selectionEnd = selectionEnd; }
    97         void setSelectionEndPos(int selectionEndPos) { m_selectionEndPos = selectionEndPos; }
     89        void setSelectionEndPos(Optional<unsigned> selectionEndPos) { m_selectionEndPos = selectionEndPos;}
    9890        void clearSelection()
    9991        {
    10092            m_selectionStart = nullptr;
    101             m_selectionStartPos = -1;
     93            m_selectionStartPos = Nullopt;
    10294            m_selectionEnd = nullptr;
    103             m_selectionEndPos = -1;
     95            m_selectionEndPos = Nullopt;
    10496        }
    10597
    10698    private:
    107         RenderObject* m_selectionStart;
    108         int m_selectionStartPos;
    109         RenderObject* m_selectionEnd;
    110         int m_selectionEndPos;
     99        RenderObject* m_selectionStart { nullptr };
     100        Optional<unsigned> m_selectionStartPos;
     101        RenderObject* m_selectionEnd { nullptr };
     102        Optional<unsigned> m_selectionEndPos;
    111103    };
    112104
     
    115107
    116108    SelectionSubtreeRoot();
    117     SelectionSubtreeRoot(RenderObject* selectionStart, int selectionStartPos, RenderObject* selectionEnd, int selectionEndPos);
    118109
    119110    SelectionSubtreeData& selectionData() { return m_selectionSubtreeData; }
  • trunk/Source/WebCore/rendering/TextPainter.cpp

    r200807 r204400  
    8585
    8686void TextPainter::drawTextOrEmphasisMarks(const FontCascade& font, const TextRun& textRun, const AtomicString& emphasisMark,
    87     int emphasisMarkOffset, const FloatPoint& textOrigin, int startOffset, int endOffset)
     87    float emphasisMarkOffset, const FloatPoint& textOrigin, unsigned startOffset, unsigned endOffset)
    8888{
    8989    ASSERT(startOffset < endOffset);
     
    9191        m_context.drawText(font, textRun, textOrigin, startOffset, endOffset);
    9292    else
    93         m_context.drawEmphasisMarks(font, textRun, emphasisMark, textOrigin + IntSize(0, emphasisMarkOffset), startOffset, endOffset);
     93        m_context.drawEmphasisMarks(font, textRun, emphasisMark, textOrigin + FloatSize(0, emphasisMarkOffset), startOffset, endOffset);
    9494}
    9595
    9696void TextPainter::paintTextWithShadows(const ShadowData* shadow, const FontCascade& font, const TextRun& textRun, const FloatRect& boxRect, const FloatPoint& textOrigin,
    97     int startOffset, int endOffset, const AtomicString& emphasisMark, int emphasisMarkOffset, bool stroked)
     97    unsigned startOffset, unsigned endOffset, const AtomicString& emphasisMark, float emphasisMarkOffset, bool stroked)
    9898{
    9999    if (!shadow) {
     
    121121}
    122122
    123 void TextPainter::paintTextAndEmphasisMarksIfNeeded(const TextRun& textRun, const FloatRect& boxRect, const FloatPoint& textOrigin, int startOffset, int endOffset,
     123void TextPainter::paintTextAndEmphasisMarksIfNeeded(const TextRun& textRun, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned startOffset, unsigned endOffset,
    124124    const TextPaintStyle& paintStyle, const ShadowData* shadow)
    125125{
     
    146146}
    147147   
    148 void TextPainter::paintText(const TextRun& textRun, int length, const FloatRect& boxRect, const FloatPoint& textOrigin, int selectionStart, int selectionEnd,
     148void TextPainter::paintText(const TextRun& textRun, unsigned length, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned selectionStart, unsigned selectionEnd,
    149149    bool paintSelectedTextOnly, bool paintSelectedTextSeparately)
    150150{
  • trunk/Source/WebCore/rendering/TextPainter.h

    r202167 r204400  
    5555    void setIsHorizontal(bool isHorizontal) { m_textBoxIsHorizontal = isHorizontal; }
    5656    void setFont(const FontCascade& font) { m_font = &font; }
    57     void addEmphasis(const AtomicString& emphasisMark, int emphasisMarkOffset, RenderCombineText*);
     57    void addEmphasis(const AtomicString& emphasisMark, float emphasisMarkOffset, RenderCombineText*);
    5858    void addTextShadow(const ShadowData* textShadow, const ShadowData* selectionShadow);
    5959
    60     void paintText(const TextRun&, int length, const FloatRect& boxRect, const FloatPoint& textOrigin,
    61         int selectionStart = 0, int selectionEnd = 0, bool paintSelectedTextOnly = false, bool paintSelectedTextSeparately = false);
     60    void paintText(const TextRun&, unsigned length, const FloatRect& boxRect, const FloatPoint& textOrigin,
     61        unsigned selectionStart = 0, unsigned selectionEnd = 0, bool paintSelectedTextOnly = false, bool paintSelectedTextSeparately = false);
    6262
    6363private:
    64     void drawTextOrEmphasisMarks(const FontCascade&, const TextRun&, const AtomicString& emphasisMark, int emphasisMarkOffset,
    65         const FloatPoint& textOrigin, int startOffset, int endOffset);
     64    void drawTextOrEmphasisMarks(const FontCascade&, const TextRun&, const AtomicString& emphasisMark, float emphasisMarkOffset,
     65        const FloatPoint& textOrigin, unsigned startOffset, unsigned endOffset);
    6666    void paintTextWithShadows(const ShadowData*, const FontCascade&, const TextRun&, const FloatRect& boxRect, const FloatPoint& textOrigin,
    67         int startOffset, int endOffset, const AtomicString& emphasisMark, int emphasisMarkOffset, bool stroked);
    68     void paintTextAndEmphasisMarksIfNeeded(const TextRun&, const FloatRect& boxRect, const FloatPoint& textOrigin, int startOffset, int endOffset,
     67        unsigned startOffset, unsigned endOffset, const AtomicString& emphasisMark, float emphasisMarkOffset, bool stroked);
     68    void paintTextAndEmphasisMarksIfNeeded(const TextRun&, const FloatRect& boxRect, const FloatPoint& textOrigin, unsigned startOffset, unsigned endOffset,
    6969        const TextPaintStyle&, const ShadowData*);
    7070
     
    7777    AtomicString m_emphasisMark;
    7878    RenderCombineText* m_combinedText { nullptr };
    79     int m_emphasisMarkOffset { 0 };
     79    float m_emphasisMarkOffset { 0 };
    8080    bool m_textBoxIsHorizontal { true };
    8181};
    8282
    83 inline void TextPainter::addEmphasis(const AtomicString& emphasisMark, int emphasisMarkOffset, RenderCombineText* combinedText)
     83inline void TextPainter::addEmphasis(const AtomicString& emphasisMark, float emphasisMarkOffset, RenderCombineText* combinedText)
    8484{
    8585    m_emphasisMark = emphasisMark;
  • trunk/Source/WebCore/rendering/svg/RenderSVGInlineText.cpp

    r194496 r204400  
    117117}
    118118
    119 LayoutRect RenderSVGInlineText::localCaretRect(InlineBox* box, int caretOffset, LayoutUnit*)
     119LayoutRect RenderSVGInlineText::localCaretRect(InlineBox* box, unsigned caretOffset, LayoutUnit*)
    120120{
    121121    if (!is<InlineTextBox>(box))
     
    123123
    124124    auto& textBox = downcast<InlineTextBox>(*box);
    125     if (static_cast<unsigned>(caretOffset) < textBox.start() || static_cast<unsigned>(caretOffset) > textBox.start() + textBox.len())
     125    if (caretOffset < textBox.start() || caretOffset > textBox.start() + textBox.len())
    126126        return LayoutRect();
    127127
    128128    // Use the edge of the selection rect to determine the caret rect.
    129     if (static_cast<unsigned>(caretOffset) < textBox.start() + textBox.len()) {
     129    if (caretOffset < textBox.start() + textBox.len()) {
    130130        LayoutRect rect = textBox.localSelectionRect(caretOffset, caretOffset + 1);
    131131        LayoutUnit x = textBox.isLeftToRightDirection() ? rect.x() : rect.maxX();
  • trunk/Source/WebCore/rendering/svg/RenderSVGInlineText.h

    r197563 r204400  
    6161
    6262    VisiblePosition positionForPoint(const LayoutPoint&, const RenderRegion*) override;
    63     LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) override;
     63    LayoutRect localCaretRect(InlineBox*, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) override;
    6464    IntRect linesBoundingBox() const override;
    6565    std::unique_ptr<InlineTextBox> createTextBox() override;
  • trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp

    r203910 r204400  
    101101}
    102102
    103 float SVGInlineTextBox::positionForOffset(int) const
     103float SVGInlineTextBox::positionForOffset(unsigned) const
    104104{
    105105    // SVG doesn't use the offset <-> position selection system.
     
    108108}
    109109
    110 FloatRect SVGInlineTextBox::selectionRectForTextFragment(const SVGTextFragment& fragment, int startPosition, int endPosition, const RenderStyle* style) const
     110FloatRect SVGInlineTextBox::selectionRectForTextFragment(const SVGTextFragment& fragment, unsigned startPosition, unsigned endPosition, const RenderStyle* style) const
    111111{
    112112    ASSERT_WITH_SECURITY_IMPLICATION(startPosition < endPosition);
     
    135135}
    136136
    137 LayoutRect SVGInlineTextBox::localSelectionRect(int startPosition, int endPosition) const
    138 {
    139     int boxStart = start();
    140     startPosition = std::max(startPosition - boxStart, 0);
    141     endPosition = std::min(endPosition - boxStart, static_cast<int>(len()));
     137LayoutRect SVGInlineTextBox::localSelectionRect(unsigned startPosition, unsigned endPosition) const
     138{
     139    startPosition = clampedOffset(startPosition);
     140    endPosition = clampedOffset(endPosition);
    142141    if (startPosition >= endPosition)
    143142        return LayoutRect();
     
    147146    AffineTransform fragmentTransform;
    148147    FloatRect selectionRect;
    149     int fragmentStartPosition = 0;
    150     int fragmentEndPosition = 0;
     148    unsigned fragmentStartPosition = 0;
     149    unsigned fragmentEndPosition = 0;
    151150
    152151    unsigned textFragmentsSize = m_textFragments.size();
     
    204203    auto& style = parentRenderer.style();
    205204
    206     int startPosition;
    207     int endPosition;
     205    unsigned startPosition;
     206    unsigned endPosition;
    208207    std::tie(startPosition, endPosition) = selectionStartEnd();
    209208
    210     int fragmentStartPosition = 0;
    211     int fragmentEndPosition = 0;
     209    unsigned fragmentStartPosition = 0;
     210    unsigned fragmentEndPosition = 0;
    212211    AffineTransform fragmentTransform;
    213212    unsigned textFragmentsSize = m_textFragments.size();
     
    408407}
    409408
    410 bool SVGInlineTextBox::mapStartEndPositionsIntoFragmentCoordinates(const SVGTextFragment& fragment, int& startPosition, int& endPosition) const
     409bool SVGInlineTextBox::mapStartEndPositionsIntoFragmentCoordinates(const SVGTextFragment& fragment, unsigned& startPosition, unsigned& endPosition) const
    411410{
    412411    if (startPosition >= endPosition)
    413412        return false;
    414413
    415     int offset = static_cast<int>(fragment.characterOffset) - start();
    416     int length = static_cast<int>(fragment.length);
     414    ASSERT(fragment.characterOffset >= start());
     415    unsigned offset = fragment.characterOffset - start();
     416    unsigned length = fragment.length;
    417417
    418418    if (startPosition >= offset + length || endPosition <= offset)
     
    421421    if (startPosition < offset)
    422422        startPosition = 0;
    423     else
     423    else {
     424        ASSERT(startPosition >= offset);
    424425        startPosition -= offset;
     426    }
    425427
    426428    if (endPosition > offset + length)
     
    541543}
    542544
    543 void SVGInlineTextBox::paintTextWithShadows(GraphicsContext& context, const RenderStyle* style, TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int endPosition)
     545void SVGInlineTextBox::paintTextWithShadows(GraphicsContext& context, const RenderStyle* style, TextRun& textRun, const SVGTextFragment& fragment, unsigned startPosition, unsigned endPosition)
    544546{
    545547    float scalingFactor = renderer().scalingFactor();
     
    591593    ASSERT(selectionStyle);
    592594
    593     int startPosition = 0;
    594     int endPosition = 0;
     595    unsigned startPosition = 0;
     596    unsigned endPosition = 0;
    595597    if (hasSelection) {
    596598        std::tie(startPosition, endPosition) = selectionStartEnd();
     
    619621
    620622    // Eventually draw text using regular style from the end position of the selection to the end of the current chunk part
    621     if (endPosition < static_cast<int>(fragment.length) && !paintSelectedTextOnly)
     623    if (endPosition < fragment.length && !paintSelectedTextOnly)
    622624        paintTextWithShadows(context, style, textRun, fragment, endPosition, fragment.length);
    623625}
  • trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.h

    r200098 r204400  
    4444    int selectionHeight() { return static_cast<int>(ceilf(m_logicalHeight)); }
    4545    int offsetForPosition(float x, bool includePartialGlyphs = true) const override;
    46     float positionForOffset(int offset) const override;
     46    float positionForOffset(unsigned offset) const override;
    4747
    4848    void paintSelectionBackground(PaintInfo&);
    4949    void paint(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom) override;
    50     LayoutRect localSelectionRect(int startPosition, int endPosition) const override;
     50    LayoutRect localSelectionRect(unsigned startPosition, unsigned endPosition) const override;
    5151
    52     bool mapStartEndPositionsIntoFragmentCoordinates(const SVGTextFragment&, int& startPosition, int& endPosition) const;
     52    bool mapStartEndPositionsIntoFragmentCoordinates(const SVGTextFragment&, unsigned& startPosition, unsigned& endPosition) const;
    5353
    5454    FloatRect calculateBoundaries() const override;
     
    6565
    6666    int offsetForPositionInFragment(const SVGTextFragment&, float position, bool includePartialGlyphs) const;
    67     FloatRect selectionRectForTextFragment(const SVGTextFragment&, int fragmentStartPosition, int fragmentEndPosition, const RenderStyle*) const;
     67    FloatRect selectionRectForTextFragment(const SVGTextFragment&, unsigned fragmentStartPosition, unsigned fragmentEndPosition, const RenderStyle*) const;
    6868
    6969private:
     
    8080    void paintDecoration(GraphicsContext&, TextDecoration, const SVGTextFragment&);
    8181    void paintDecorationWithStyle(GraphicsContext&, TextDecoration, const SVGTextFragment&, RenderBoxModelObject& decorationRenderer);
    82     void paintTextWithShadows(GraphicsContext&, const RenderStyle*, TextRun&, const SVGTextFragment&, int startPosition, int endPosition);
     82    void paintTextWithShadows(GraphicsContext&, const RenderStyle*, TextRun&, const SVGTextFragment&, unsigned startPosition, unsigned endPosition);
    8383    void paintText(GraphicsContext&, const RenderStyle*, const RenderStyle* selectionStyle, const SVGTextFragment&, bool hasSelection, bool paintSelectedTextOnly);
    8484
  • trunk/Source/WebCore/rendering/svg/SVGTextQuery.cpp

    r185593 r204400  
    135135}
    136136
    137 bool SVGTextQuery::mapStartEndPositionsIntoFragmentCoordinates(Data* queryData, const SVGTextFragment& fragment, int& startPosition, int& endPosition) const
     137bool SVGTextQuery::mapStartEndPositionsIntoFragmentCoordinates(Data* queryData, const SVGTextFragment& fragment, unsigned& startPosition, unsigned& endPosition) const
    138138{
    139139    // Reuse the same logic used for text selection & painting, to map our query start/length into start/endPositions of the current text fragment.
     140    ASSERT(startPosition >= queryData->processedCharacters);
     141    ASSERT(endPosition >= queryData->processedCharacters);
    140142    startPosition -= queryData->processedCharacters;
    141143    endPosition -= queryData->processedCharacters;
    142144
    143     if (startPosition >= endPosition || startPosition < 0 || endPosition < 0)
     145    if (startPosition >= endPosition)
    144146        return false;
    145147
     
    152154}
    153155
    154 void SVGTextQuery::modifyStartEndPositionsRespectingLigatures(Data* queryData, int& startPosition, int& endPosition) const
     156void SVGTextQuery::modifyStartEndPositionsRespectingLigatures(Data* queryData, unsigned& startPosition, unsigned& endPosition) const
    155157{
    156158    SVGTextLayoutAttributes* layoutAttributes = queryData->textRenderer->layoutAttributes();
     
    168170    bool alterEndPosition = true;
    169171
    170     int lastPositionOffset = -1;
     172    Optional<unsigned> lastPositionOffset;
    171173    for (; textMetricsOffset < textMetricsSize && positionOffset < positionSize; ++textMetricsOffset) {
    172174        SVGTextMetrics& metrics = textMetricsValues[textMetricsOffset];
     
    183185
    184186        // If the start position maps to a character in the metrics list, we don't need to modify it.
    185         if (startPosition == static_cast<int>(positionOffset))
     187        if (startPosition == positionOffset)
    186188            alterStartPosition = false;
    187189
    188190        // If the start position maps to a character in the metrics list, we don't need to modify it.
    189         if (endPosition == static_cast<int>(positionOffset))
     191        if (endPosition == positionOffset)
    190192            alterEndPosition = false;
    191193
    192194        // Detect ligatures.
    193         if (lastPositionOffset != -1 && lastPositionOffset - positionOffset > 1) {
    194             if (alterStartPosition && startPosition > lastPositionOffset && startPosition < static_cast<int>(positionOffset)) {
    195                 startPosition = lastPositionOffset;
     195        if (lastPositionOffset && lastPositionOffset.value() - positionOffset > 1) {
     196            if (alterStartPosition && startPosition > lastPositionOffset.value() && startPosition < positionOffset) {
     197                startPosition = lastPositionOffset.value();
    196198                alterStartPosition = false;
    197199            }
    198200
    199             if (alterEndPosition && endPosition > lastPositionOffset && endPosition < static_cast<int>(positionOffset)) {
     201            if (alterEndPosition && endPosition > lastPositionOffset.value() && endPosition < positionOffset) {
    200202                endPosition = positionOffset;
    201203                alterEndPosition = false;
     
    213215        return;
    214216
    215     if (lastPositionOffset != -1 && lastPositionOffset - positionOffset > 1) {
    216         if (alterStartPosition && startPosition > lastPositionOffset && startPosition < static_cast<int>(positionOffset))
    217             startPosition = lastPositionOffset;
    218 
    219         if (alterEndPosition && endPosition > lastPositionOffset && endPosition < static_cast<int>(positionOffset))
     217    if (lastPositionOffset && lastPositionOffset.value() - positionOffset > 1) {
     218        if (alterStartPosition && startPosition > lastPositionOffset.value() && startPosition < positionOffset)
     219            startPosition = lastPositionOffset.value();
     220
     221        if (alterEndPosition && endPosition > lastPositionOffset.value() && endPosition < positionOffset)
    220222            endPosition = positionOffset;
    221223    }
     
    285287    SubStringLengthData* data = static_cast<SubStringLengthData*>(queryData);
    286288
    287     int startPosition = data->startPosition;
    288     int endPosition = startPosition + data->length;
     289    unsigned startPosition = data->startPosition;
     290    unsigned endPosition = startPosition + data->length;
    289291    if (!mapStartEndPositionsIntoFragmentCoordinates(queryData, fragment, startPosition, endPosition))
    290292        return false;
     
    320322    StartPositionOfCharacterData* data = static_cast<StartPositionOfCharacterData*>(queryData);
    321323
    322     int startPosition = data->position;
    323     int endPosition = startPosition + 1;
     324    unsigned startPosition = data->position;
     325    unsigned endPosition = startPosition + 1;
    324326    if (!mapStartEndPositionsIntoFragmentCoordinates(queryData, fragment, startPosition, endPosition))
    325327        return false;
     
    369371    EndPositionOfCharacterData* data = static_cast<EndPositionOfCharacterData*>(queryData);
    370372
    371     int startPosition = data->position;
    372     int endPosition = startPosition + 1;
     373    unsigned startPosition = data->position;
     374    unsigned endPosition = startPosition + 1;
    373375    if (!mapStartEndPositionsIntoFragmentCoordinates(queryData, fragment, startPosition, endPosition))
    374376        return false;
     
    417419    RotationOfCharacterData* data = static_cast<RotationOfCharacterData*>(queryData);
    418420
    419     int startPosition = data->position;
    420     int endPosition = startPosition + 1;
     421    unsigned startPosition = data->position;
     422    unsigned endPosition = startPosition + 1;
    421423    if (!mapStartEndPositionsIntoFragmentCoordinates(queryData, fragment, startPosition, endPosition))
    422424        return false;
     
    455457};
    456458
    457 static inline void calculateGlyphBoundaries(SVGTextQuery::Data* queryData, const SVGTextFragment& fragment, int startPosition, FloatRect& extent)
     459static inline void calculateGlyphBoundaries(SVGTextQuery::Data* queryData, const SVGTextFragment& fragment, unsigned startPosition, FloatRect& extent)
    458460{
    459461    float scalingFactor = queryData->textRenderer->scalingFactor();
     
    485487    ExtentOfCharacterData* data = static_cast<ExtentOfCharacterData*>(queryData);
    486488
    487     int startPosition = data->position;
    488     int endPosition = startPosition + 1;
     489    unsigned startPosition = data->position;
     490    unsigned endPosition = startPosition + 1;
    489491    if (!mapStartEndPositionsIntoFragmentCoordinates(queryData, fragment, startPosition, endPosition))
    490492        return false;
     
    520522    FloatRect extent;
    521523    for (unsigned i = 0; i < fragment.length; ++i) {
    522         int startPosition = data->processedCharacters + i;
    523         int endPosition = startPosition + 1;
     524        unsigned startPosition = data->processedCharacters + i;
     525        unsigned endPosition = startPosition + 1;
    524526        if (!mapStartEndPositionsIntoFragmentCoordinates(queryData, fragment, startPosition, endPosition))
    525527            continue;
  • trunk/Source/WebCore/rendering/svg/SVGTextQuery.h

    r170947 r204400  
    5353
    5454    void collectTextBoxesInFlowBox(InlineFlowBox*);
    55     bool mapStartEndPositionsIntoFragmentCoordinates(Data*, const SVGTextFragment&, int& startPosition, int& endPosition) const;
    56     void modifyStartEndPositionsRespectingLigatures(Data*, int& startPosition, int& endPosition) const;
     55    bool mapStartEndPositionsIntoFragmentCoordinates(Data*, const SVGTextFragment&, unsigned& startPosition, unsigned& endPosition) const;
     56    void modifyStartEndPositionsRespectingLigatures(Data*, unsigned& startPosition, unsigned& endPosition) const;
    5757
    5858private:
Note: See TracChangeset for help on using the changeset viewer.