Bug 110732 - Web Inspector: Selector's raw start position in its line is considered to be 0 when computing UILocation
Summary: Web Inspector: Selector's raw start position in its line is considered to be ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (Deprecated) (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Alexander Pavlov (apavlov)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-25 00:53 PST by Alexander Pavlov (apavlov)
Modified: 2013-03-01 02:35 PST (History)
13 users (show)

See Also:


Attachments
Patch (24.14 KB, patch)
2013-02-25 06:28 PST, Alexander Pavlov (apavlov)
no flags Details | Formatted Diff | Diff
Patch (62.05 KB, patch)
2013-02-25 23:04 PST, Alexander Pavlov (apavlov)
no flags Details | Formatted Diff | Diff
Patch (61.49 KB, patch)
2013-02-28 03:02 PST, Alexander Pavlov (apavlov)
no flags Details | Formatted Diff | Diff
Patch (61.50 KB, patch)
2013-02-28 07:57 PST, Alexander Pavlov (apavlov)
vsevik: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Pavlov (apavlov) 2013-02-25 00:53:58 PST
Upstreaming https://code.google.com/p/chromium/issues/detail?id=177976
Comment 1 Alexander Pavlov (apavlov) 2013-02-25 06:28:37 PST
Created attachment 190046 [details]
Patch
Comment 2 Pavel Feldman 2013-02-25 06:43:03 PST
Comment on attachment 190046 [details]
Patch

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

> Source/WebCore/inspector/InspectorStyleSheet.cpp:149
> +    ASSERT(m_hasText);

Could you reuse the code in getRegularExpressionMatchesByLines?

> Source/WebCore/inspector/InspectorStyleSheet.cpp:176
> +struct LineColumn {

wtf/text/TextPosition.h

> Source/WebCore/inspector/InspectorStyleSheet.cpp:191
> +    const size_t vectorSize = lineEndings.size();

Move to ContentSearchUtil
Comment 3 Alexander Pavlov (apavlov) 2013-02-25 23:04:43 PST
Created attachment 190212 [details]
Patch
Comment 4 Vsevolod Vlasov 2013-02-27 03:22:50 PST
Comment on attachment 190212 [details]
Patch

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

> Source/WebCore/inspector/ContentSearchUtils.cpp:74
> +    if (!vectorSize)

This check should not be needed, see my comment to lineEndings below.

> Source/WebCore/inspector/ContentSearchUtils.cpp:79
> +    size_t previousLineEndingOffset;

const size_t* foundLineEnding = approximateBinarySearch<size_t, size_t>(lineEndings, vectorSize, offset, sizetExtractor);
    size_t lineIndex = foundLineEnding - &lineEndings.at(0);
    if (offset > *foundLineEnding)
        ++lineIndex;
    size_t previousLineEndingOffset = lineIndex >= 0 ? lineEndings.at(lineIndex-1) : 0;
    size_t column = offset - previousLineEndingOffset;
    return TextPosition(OrdinalNumber::fromZeroBasedInt(lineIndex), OrdinalNumber::fromZeroBasedInt(column));

Seems to be a shorter way to do the same.

> Source/WebCore/inspector/ContentSearchUtils.cpp:128
> +    while (start < text.length()) {

I would do as follows instead to make sure we lways have at least one line (even for an empty file). That would be consistent with what we do in front-end (see utilities.js)
   while (start < text.length()) {
        size_t lineEnd = text.find('\n', start);
        if (lineEnd == notFound)
            break;
        result->append(lineEnd);
        start = lineEnd + 1;
    }
    result->append(text.length());
Comment 5 Vsevolod Vlasov 2013-02-28 01:44:21 PST
Comment on attachment 190212 [details]
Patch

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

> Source/WebCore/inspector/InspectorStyleSheet.cpp:527
> +    OwnPtr<Vector<size_t> > lineEndings(m_parentStyleSheet ? m_parentStyleSheet->lineEndings() : PassOwnPtr<Vector<size_t> >());

Could you please explain what is the expected value of SourceRange in case m_parentStyleSheet is null and hence lineEndings are not available?

> Source/WebCore/inspector/front-end/CSSStyleModel.js:882
> +            if (resource && resource.type === WebInspector.resourceTypes.Stylesheet) {

Why is the resource type important here?
Comment 6 Vsevolod Vlasov 2013-02-28 01:45:16 PST
Comment on attachment 190212 [details]
Patch

r- per my comment about complexity of lineColumnFromOffset implementation.
Comment 7 Alexander Pavlov (apavlov) 2013-02-28 03:02:42 PST
Created attachment 190690 [details]
Patch
Comment 8 Timothy Hatcher 2013-02-28 07:42:30 PST
Comment on attachment 190690 [details]
Patch

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

> Source/WebCore/inspector/ContentSearchUtils.cpp:71
> +TextPosition lineColumnFromOffset(size_t offset, const Vector<size_t>& lineEndings)

textPositionFromOffset?
Comment 9 Alexander Pavlov (apavlov) 2013-02-28 07:45:00 PST
Comment on attachment 190690 [details]
Patch

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

>> Source/WebCore/inspector/ContentSearchUtils.cpp:71
>> +TextPosition lineColumnFromOffset(size_t offset, const Vector<size_t>& lineEndings)
> 
> textPositionFromOffset?

Makes sense, as long as it represents the line:column pair. Thanks.
Comment 10 Alexander Pavlov (apavlov) 2013-02-28 07:57:32 PST
Created attachment 190729 [details]
Patch
Comment 11 Vsevolod Vlasov 2013-03-01 02:24:23 PST
Comment on attachment 190729 [details]
Patch

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

> Source/WebCore/inspector/InspectorStyleSheet.cpp:64
> +#include <wtf/StdLibExtras.h>

This include should go to ContentSearchUtils
Comment 12 Alexander Pavlov (apavlov) 2013-03-01 02:35:48 PST
Committed r144434: <http://trac.webkit.org/changeset/144434>