Bug 233259 - InlineIterator::TextBox::offsetForPosition and positionForOffset should be layout path independent
Summary: InlineIterator::TextBox::offsetForPosition and positionForOffset should be la...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Antti Koivisto
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-11-17 09:48 PST by Antti Koivisto
Modified: 2021-11-17 14:11 PST (History)
17 users (show)

See Also:


Attachments
Patch (17.64 KB, patch)
2021-11-17 10:00 PST, Antti Koivisto
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Antti Koivisto 2021-11-17 09:48:13 PST
Fewer bugs by reducing duplication.
Comment 1 Antti Koivisto 2021-11-17 10:00:03 PST
Created attachment 444530 [details]
Patch
Comment 2 zalan 2021-11-17 10:12:08 PST
Comment on attachment 444530 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=444530&action=review

> Source/WebCore/rendering/LegacyInlineTextBox.cpp:-494
> -int LegacyInlineTextBox::offsetForPosition(float lineOffset, bool includePartialGlyphs) const
> -{
> -    if (isLineBreak())
> -        return 0;
> -    if (lineOffset - logicalLeft() > logicalWidth())
> -        return isLeftToRightDirection() ? len() : 0;
> -    if (lineOffset - logicalLeft() < 0)
> -        return isLeftToRightDirection() ? 0 : len();
> -    bool ignoreCombinedText = true;
> -    bool ignoreHyphen = true;
> -    return lineFont().offsetForPosition(createTextRun(ignoreCombinedText, ignoreHyphen), lineOffset - logicalLeft(), includePartialGlyphs);
> -}
> -
> -float LegacyInlineTextBox::positionForOffset(unsigned offset) const
> -{
> -    ASSERT(offset >= m_start);
> -    ASSERT(offset <= m_start + len());
> -
> -    if (isLineBreak())
> -        return logicalLeft();
> -
> -    unsigned startOffset;
> -    unsigned endOffset;
> -    if (isLeftToRightDirection()) {
> -        startOffset = 0;
> -        endOffset = selectableRange().clamp(offset);
> -    } else {
> -        startOffset = selectableRange().clamp(offset);
> -        endOffset = m_len;
> -    }
> -
> -    // FIXME: Do we need to add rightBearing here?
> -    LayoutRect selectionRect = LayoutRect(logicalLeft(), 0, 0, 0);
> -    bool ignoreCombinedText = true;
> -    bool ignoreHyphen = true;
> -    TextRun textRun = createTextRun(ignoreCombinedText, ignoreHyphen);
> -    lineFont().adjustSelectionRectForText(textRun, selectionRect, startOffset, endOffset);
> -    return snapRectToDevicePixelsWithWritingDirection(selectionRect, renderer().document().deviceScaleFactor(), textRun.ltr()).maxX();
> -}
> -

nice.
Comment 3 EWS 2021-11-17 10:51:24 PST
Committed r285938 (244347@main): <https://commits.webkit.org/244347@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 444530 [details].
Comment 4 Radar WebKit Bug Importer 2021-11-17 10:58:59 PST
<rdar://problem/85511787>