Simple line layout: Change FlowContents::segmentForPosition() to segmentForRun().
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Mar 2015 03:40:51 +0000 (03:40 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Mar 2015 03:40:51 +0000 (03:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142785

Reviewed by Antti Koivisto.

This is in transition to support <br>. A particular position could point to multiple
segments when <br> is directly followed by text.

No change in functionality.

* rendering/SimpleLineLayoutFlowContents.cpp:
(WebCore::SimpleLineLayout::FlowContents::segmentIndexForRunSlow):
(WebCore::SimpleLineLayout::FlowContents::segmentIndexForPositionSlow): Deleted.
* rendering/SimpleLineLayoutFlowContents.h:
(WebCore::SimpleLineLayout::FlowContents::segmentForRun):
(WebCore::SimpleLineLayout::FlowContents::segmentIndexForPosition): Deleted.
(WebCore::SimpleLineLayout::FlowContents::segmentForPosition): Deleted.
* rendering/SimpleLineLayoutResolver.cpp:
(WebCore::SimpleLineLayout::RunResolver::Run::text):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181682 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/SimpleLineLayoutFlowContents.cpp
Source/WebCore/rendering/SimpleLineLayoutFlowContents.h
Source/WebCore/rendering/SimpleLineLayoutResolver.cpp

index 362e942..f8c4213 100644 (file)
@@ -1,3 +1,25 @@
+2015-03-17  Zalan Bujtas  <zalan@apple.com>
+
+        Simple line layout: Change FlowContents::segmentForPosition() to segmentForRun().
+        https://bugs.webkit.org/show_bug.cgi?id=142785
+
+        Reviewed by Antti Koivisto.
+
+        This is in transition to support <br>. A particular position could point to multiple
+        segments when <br> is directly followed by text.
+
+        No change in functionality.
+
+        * rendering/SimpleLineLayoutFlowContents.cpp:
+        (WebCore::SimpleLineLayout::FlowContents::segmentIndexForRunSlow):
+        (WebCore::SimpleLineLayout::FlowContents::segmentIndexForPositionSlow): Deleted.
+        * rendering/SimpleLineLayoutFlowContents.h:
+        (WebCore::SimpleLineLayout::FlowContents::segmentForRun):
+        (WebCore::SimpleLineLayout::FlowContents::segmentIndexForPosition): Deleted.
+        (WebCore::SimpleLineLayout::FlowContents::segmentForPosition): Deleted.
+        * rendering/SimpleLineLayoutResolver.cpp:
+        (WebCore::SimpleLineLayout::RunResolver::Run::text):
+
 2015-03-17  Chris Dumez  <cdumez@apple.com>
 
         [Mac][iOS] setSharedTimerFireInterval() / stopSharedTimer() are expensive
index 123de83..16cb09e 100644 (file)
@@ -51,12 +51,13 @@ FlowContents::FlowContents(const RenderBlockFlow& flow)
 {
 }
 
-unsigned FlowContents::segmentIndexForPositionSlow(unsigned position) const
+unsigned FlowContents::segmentIndexForRunSlow(unsigned start, unsigned end) const
 {
-    auto it = std::lower_bound(m_segments.begin(), m_segments.end(), position, [](const Segment& segment, unsigned position) {
-        return segment.end <= position;
+    auto it = std::lower_bound(m_segments.begin(), m_segments.end(), start, [](const Segment& segment, unsigned start) {
+        return segment.end <= start;
     });
     ASSERT(it != m_segments.end());
+    ASSERT_UNUSED(end, end <= it->end);
     auto index = it - m_segments.begin();
     m_lastSegmentIndex = index;
     return index;
index 17d0d0a..b78f296 100644 (file)
@@ -43,7 +43,7 @@ public:
         String text;
         const RenderObject& renderer;
     };
-    const Segment& segmentForPosition(unsigned) const;
+    const Segment& segmentForRun(unsigned start, unsigned end) const;
     const Segment& segmentForRenderer(const RenderObject&) const;
 
     class Iterator {
@@ -69,10 +69,8 @@ public:
     Iterator begin() const { return Iterator(*this, 0); }
     Iterator end() const { return Iterator(*this, m_segments.size()); }
 
-    unsigned segmentIndexForPosition(unsigned position) const;
-
 private:
-    unsigned segmentIndexForPositionSlow(unsigned position) const;
+    unsigned segmentIndexForRunSlow(unsigned start, unsigned end) const;
     const Vector<Segment, 8> m_segments;
     mutable unsigned m_lastSegmentIndex;
 };
@@ -111,17 +109,13 @@ inline const FlowContents::Segment* FlowContents::Iterator::operator->() const
     return &(m_flowContents.m_segments[m_segmentIndex]);
 }
 
-inline unsigned FlowContents::segmentIndexForPosition(unsigned position) const
+inline const FlowContents::Segment& FlowContents::segmentForRun(unsigned start, unsigned end) const
 {
+    ASSERT(start < end);
     auto& lastSegment = m_segments[m_lastSegmentIndex];
-    if (lastSegment.start <= position && position < lastSegment.end)
-        return m_lastSegmentIndex;
-    return segmentIndexForPositionSlow(position);
-}
-
-inline const FlowContents::Segment& FlowContents::segmentForPosition(unsigned position) const
-{
-    return m_segments[segmentIndexForPosition(position)];
+    if (lastSegment.start <= start && end <= lastSegment.end)
+        return m_segments[m_lastSegmentIndex];
+    return m_segments[segmentIndexForRunSlow(start, end)];
 }
 
 }
index e8d25b6..b23b475 100644 (file)
@@ -76,7 +76,8 @@ StringView RunResolver::Run::text() const
 {
     auto& resolver = m_iterator.resolver();
     auto& run = m_iterator.simpleRun();
-    auto& segment = resolver.m_flowContents.segmentForPosition(run.start);
+    ASSERT(run.start < run.end);
+    auto& segment = resolver.m_flowContents.segmentForRun(run.start, run.end);
     // We currently split runs on segment boundaries (different RenderObject).
     ASSERT(run.end <= segment.end);
     if (segment.text.is8Bit())