[New Multicolumn] columnNumberForOffset is not patched for new multicolumn code yet.
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Apr 2014 18:48:15 +0000 (18:48 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Apr 2014 18:48:15 +0000 (18:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=131740

Reviewed by Enrica Casucci.

I took the opportunity to clean this code up while adding support for the new columns.
columnNumberForOffset only applied for paginated RenderViews and was really about
pages and not columns. It also only returns an actual page number if the columns are
block progressed (e.g., right-to-left vertical Japanese books).

Therefore I renamed columnNumberForOffset to pageNumberForBlockProgressionOffset and
moved it to RenderView.

I also renamed the member variable of SelectionRect to be pageNumber instead of
columnNumber in order to make it more obvious that this isn't about columns per se
(since the fact that we implemented RenderView's pagination mode using columns is an
implementation detail).

* dom/Range.cpp:
(WebCore::coalesceSelectionRects):
(WebCore::Range::collectSelectionRects):
* platform/ios/SelectionRect.h:
(WebCore::SelectionRect::pageNumber):
(WebCore::SelectionRect::columnNumber): Deleted.
* rendering/RenderImage.cpp:
(WebCore::RenderImage::collectSelectionRects):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::collectSelectionRects):
(WebCore::RenderObject::columnNumberForOffset): Deleted.
* rendering/RenderObject.h:
* rendering/RenderText.cpp:
(WebCore::RenderText::collectSelectionRects):
* rendering/RenderView.cpp:
(WebCore::RenderView::pageNumberForBlockProgressionOffset):
* rendering/RenderView.h:

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

Source/WebCore/ChangeLog
Source/WebCore/dom/Range.cpp
Source/WebCore/platform/ios/SelectionRect.h
Source/WebCore/rendering/RenderImage.cpp
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderObject.h
Source/WebCore/rendering/RenderText.cpp
Source/WebCore/rendering/RenderView.cpp
Source/WebCore/rendering/RenderView.h

index 4aa9bac71d90c099e31ca056323186fa8e08b1db..6961dce9df8f0a846f20dd43855e3788a6ca5019 100644 (file)
@@ -1,3 +1,41 @@
+2014-04-17  David Hyatt  <hyatt@apple.com>
+
+        [New Multicolumn] columnNumberForOffset is not patched for new multicolumn code yet.
+        https://bugs.webkit.org/show_bug.cgi?id=131740
+
+        Reviewed by Enrica Casucci.
+        
+        I took the opportunity to clean this code up while adding support for the new columns.
+        columnNumberForOffset only applied for paginated RenderViews and was really about
+        pages and not columns. It also only returns an actual page number if the columns are
+        block progressed (e.g., right-to-left vertical Japanese books).
+        
+        Therefore I renamed columnNumberForOffset to pageNumberForBlockProgressionOffset and
+        moved it to RenderView.
+        
+        I also renamed the member variable of SelectionRect to be pageNumber instead of
+        columnNumber in order to make it more obvious that this isn't about columns per se
+        (since the fact that we implemented RenderView's pagination mode using columns is an
+        implementation detail).
+
+        * dom/Range.cpp:
+        (WebCore::coalesceSelectionRects):
+        (WebCore::Range::collectSelectionRects):
+        * platform/ios/SelectionRect.h:
+        (WebCore::SelectionRect::pageNumber):
+        (WebCore::SelectionRect::columnNumber): Deleted.
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::collectSelectionRects):
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::collectSelectionRects):
+        (WebCore::RenderObject::columnNumberForOffset): Deleted.
+        * rendering/RenderObject.h:
+        * rendering/RenderText.cpp:
+        (WebCore::RenderText::collectSelectionRects):
+        * rendering/RenderView.cpp:
+        (WebCore::RenderView::pageNumberForBlockProgressionOffset):
+        * rendering/RenderView.h:
+
 2014-04-16  Brent Fulgham  <bfulgham@apple.com>
 
         [Win] A few final cleanups to the DataObject classes.
index ab1f240ce795fef7fd8022031c5bff3dd94d1245..b0ee0ea20a16a6f872578753668806daafc05cea 100644 (file)
@@ -1711,7 +1711,7 @@ static inline void adjustLineHeightOfSelectionRects(Vector<SelectionRect>& rects
 
 static SelectionRect coalesceSelectionRects(const SelectionRect& original, const SelectionRect& previous)
 {
-    SelectionRect result(unionRect(previous.rect(), original.rect()), original.isHorizontal(), original.columnNumber());
+    SelectionRect result(unionRect(previous.rect(), original.rect()), original.isHorizontal(), original.pageNumber());
     result.setDirection(original.containsStart() || original.containsEnd() ? original.direction() : previous.direction());
     result.setContainsStart(previous.containsStart() || original.containsStart());
     result.setContainsEnd(previous.containsEnd() || original.containsEnd());
@@ -1823,7 +1823,7 @@ void Range::collectSelectionRects(Vector<SelectionRect>& rects)
                 lineBottom = currentRectBottom;
             } else {
                 lastLineBottom = lineBottom;
-                if (currentRectTop <= lastLineBottom && i && rects[i].columnNumber() == rects[i - 1].columnNumber()) {
+                if (currentRectTop <= lastLineBottom && i && rects[i].pageNumber() == rects[i - 1].pageNumber()) {
                     lastLineTop = lineTop;
                     lineBottom = lastLineTop;
                 } else {
@@ -1914,13 +1914,13 @@ void Range::collectSelectionRects(Vector<SelectionRect>& rects)
                 // For iBooks, the interior lines may cross multiple horizontal pages.
                 interiorUnionRect.unite(currentRect.rect());
             } else {
-                unionedRects.append(SelectionRect(interiorUnionRect, currentRect.isHorizontal(), currentRect.columnNumber()));
+                unionedRects.append(SelectionRect(interiorUnionRect, currentRect.isHorizontal(), currentRect.pageNumber()));
                 interiorUnionRect = currentRect.rect();
             }
         } else {
             // Processing last line.
             if (!interiorUnionRect.isEmpty()) {
-                unionedRects.append(SelectionRect(interiorUnionRect, currentRect.isHorizontal(), currentRect.columnNumber()));
+                unionedRects.append(SelectionRect(interiorUnionRect, currentRect.isHorizontal(), currentRect.pageNumber()));
                 interiorUnionRect = IntRect();
             }
 
index 9dc91fdf1e7c8056dc06925af0d22b4530e7529d..4e02a3cd35a33e00fd089d87da0c085f717e0f8c 100644 (file)
@@ -62,7 +62,7 @@ public:
     bool isHorizontal() const { return m_isHorizontal; }
     bool isInFixedPosition() const { return m_isInFixedPosition; }
     bool isRubyText() const { return m_isRubyText; }
-    int columnNumber() const { return m_columnNumber; }
+    int pageNumber() const { return m_pageNumber; }
 
     void setRect(const IntRect& rect) { m_rect = rect; }
 
@@ -125,7 +125,7 @@ private:
     bool m_isHorizontal;
     bool m_isInFixedPosition;
     bool m_isRubyText;
-    int m_columnNumber;
+    int m_pageNumber;
 };
 
 } // namespace WebCore
index f52c205a9f5886e83c43c7e3554627832a1ec70d..01b64822f178978150da0e1efbb21fcbc2ab5383 100644 (file)
@@ -112,7 +112,7 @@ void RenderImage::collectSelectionRects(Vector<SelectionRect>& rects, unsigned,
 
     // FIXME: We should consider either making SelectionRect a struct or better organize its optional fields into
     // an auxiliary struct to simplify its initialization.
-    rects.append(SelectionRect(absoluteBounds, containingBlock->style().direction(), lineExtentBounds.x(), lineExtentBounds.maxX(), lineExtentBounds.maxY(), 0, false /* line break */, isFirstOnLine, isLastOnLine, false /* contains start */, false /* contains end */, containingBlock->style().isHorizontalWritingMode(), isFixed, false /* ruby text */, columnNumberForOffset(absoluteBounds.x())));
+    rects.append(SelectionRect(absoluteBounds, containingBlock->style().direction(), lineExtentBounds.x(), lineExtentBounds.maxX(), lineExtentBounds.maxY(), 0, false /* line break */, isFirstOnLine, isLastOnLine, false /* contains start */, false /* contains end */, containingBlock->style().isHorizontalWritingMode(), isFixed, false /* ruby text */, view().pageNumberForBlockProgressionOffset(absoluteBounds.x())));
 }
 #endif
 
index a338213d1dbf81e1e2054700bbeff92fb18611d1..ff0ccc27b55a027c0651895866040615ea91a071 100644 (file)
@@ -1086,26 +1086,6 @@ void RenderObject::paintOutline(PaintInfo& paintInfo, const LayoutRect& paintRec
         graphicsContext->endTransparencyLayer();
 }
 
-// FIXME: Make this return an unsigned integer?
-int RenderObject::columnNumberForOffset(int offset)
-{
-    int columnNumber = 0;
-    RenderBlock* containingBlock = this->containingBlock();
-    RenderView& view = containingBlock->view();
-    const Pagination& pagination = view.frameView().frame().page()->pagination();
-    if (pagination.mode == Pagination::Unpaginated)
-        return columnNumber;
-
-    ColumnInfo* columnInfo = view.columnInfo();
-    if (columnInfo && !columnInfo->progressionIsInline()) {
-        if (!columnInfo->progressionIsReversed())
-            columnNumber = (pagination.pageLength + pagination.gap - offset) / (pagination.pageLength + pagination.gap);
-        else
-            columnNumber = offset / (pagination.pageLength + pagination.gap);
-    }
-    return columnNumber;
-}
-
 #if PLATFORM(IOS)
 // This function is similar in spirit to RenderText::absoluteRectsForRange, but returns rectangles
 // which are annotated with additional state which helps iOS draw selections in its unique way.
@@ -1133,7 +1113,7 @@ void RenderObject::collectSelectionRects(Vector<SelectionRect>& rects, unsigned
 
     unsigned numberOfQuads = quads.size();
     for (unsigned i = 0; i < numberOfQuads; ++i)
-        rects.append(SelectionRect(quads[i].enclosingBoundingBox(), isHorizontalWritingMode(), columnNumberForOffset(quads[i].enclosingBoundingBox().x())));
+        rects.append(SelectionRect(quads[i].enclosingBoundingBox(), isHorizontalWritingMode(), view().pageNumberForBlockProgressionOffset(quads[i].enclosingBoundingBox().x())));
 }
 #endif
 
index 44824a0e64ed3f99ea9ed2c79fa1e225b233cecf..730477e25337eafc6c472c7714f6ea1f8c551bcc 100644 (file)
@@ -879,8 +879,6 @@ public:
 
     void drawLineForBoxSide(GraphicsContext*, float x1, float y1, float x2, float y2, BoxSide, Color, EBorderStyle, float adjbw1, float adjbw2, bool antialias = false);
 protected:
-    int columnNumberForOffset(int offset);
-
     void paintFocusRing(PaintInfo&, const LayoutPoint&, RenderStyle*);
     void paintOutline(PaintInfo&, const LayoutRect&);
     void addPDFURLRect(GraphicsContext*, const LayoutRect&);
index 3efd282fe54c4709dabf4c5ab13ff9f31fd664a7..53cd444a805980ba3d76590044234c4a7e86751d 100644 (file)
@@ -391,7 +391,7 @@ void RenderText::collectSelectionRects(Vector<SelectionRect>& rects, unsigned st
             }
         }
 
-        rects.append(SelectionRect(absRect, box->direction(), extentsRect.x(), extentsRect.maxX(), extentsRect.maxY(), 0, box->isLineBreak(), isFirstOnLine, isLastOnLine, containsStart, containsEnd, boxIsHorizontal, isFixed, containingBlock->isRubyText(), columnNumberForOffset(absRect.x())));
+        rects.append(SelectionRect(absRect, box->direction(), extentsRect.x(), extentsRect.maxX(), extentsRect.maxY(), 0, box->isLineBreak(), isFirstOnLine, isLastOnLine, containsStart, containsEnd, boxIsHorizontal, isFixed, containingBlock->isRubyText(), view().pageNumberForBlockProgressionOffset(absRect.x())));
     }
 }
 #endif
index cc3b7d9c355c13ee9c726826a624cdc392c6a1d8..df40522441ee839c26d1b0747ecbfadb82b39329 100644 (file)
@@ -41,6 +41,7 @@
 #include "RenderLayer.h"
 #include "RenderLayerBacking.h"
 #include "RenderLayerCompositor.h"
+#include "RenderMultiColumnFlowThread.h"
 #include "RenderNamedFlowThread.h"
 #include "RenderSelectionInfo.h"
 #include "RenderWidget.h"
@@ -1224,4 +1225,36 @@ RenderView::RepaintRegionAccumulator::~RepaintRegionAccumulator()
     m_rootView->flushAccumulatedRepaintRegion();
 }
 
+unsigned RenderView::pageNumberForBlockProgressionOffset(int offset) const
+{
+    int columnNumber = 0;
+    const Pagination& pagination = frameView().frame().page()->pagination();
+    if (pagination.mode == Pagination::Unpaginated)
+        return columnNumber;
+    
+    bool progressionIsInline = false;
+    bool progressionIsReversed = false;
+    
+    if (hasColumns()) {
+        ColumnInfo* colInfo = columnInfo();
+        if (!colInfo)
+            return columnNumber;
+        progressionIsInline = colInfo->progressionIsInline();
+        progressionIsReversed = colInfo->progressionIsReversed();
+    } else if (multiColumnFlowThread()) {
+        progressionIsInline = multiColumnFlowThread()->progressionIsInline();
+        progressionIsReversed = multiColumnFlowThread()->progressionIsReversed();
+    } else
+        return columnNumber;
+    
+    if (!progressionIsInline) {
+        if (!progressionIsReversed)
+            columnNumber = (pagination.pageLength + pagination.gap - offset) / (pagination.pageLength + pagination.gap);
+        else
+            columnNumber = offset / (pagination.pageLength + pagination.gap);
+    }
+
+    return columnNumber;
+}
+
 } // namespace WebCore
index 686f30932aa47ff0b851cabd80decb6adc46efe3..a0ffbdbcbcd49b8856b61b3dee3e6e4ecadf95a4 100644 (file)
@@ -154,6 +154,12 @@ public:
     }
     LayoutUnit pageOrViewLogicalHeight() const;
 
+    // This method is used to assign a page number only when pagination modes have
+    // a block progression. This happens with vertical-rl books for example, but it
+    // doesn't happen for normal horizontal-tb books. This is a very specialized
+    // function and should not be mistaken for a general page number API.
+    unsigned pageNumberForBlockProgressionOffset(int offset) const;
+
     // FIXME: These functions are deprecated. No code should be added that uses these.
     int bestTruncatedAt() const { return m_legacyPrinting.m_bestTruncatedAt; }
     void setBestTruncatedAt(int y, RenderBoxModelObject* forRenderer, bool forcedBreak = false);
@@ -238,7 +244,7 @@ protected:
     virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const override;
     virtual void mapAbsoluteToLocalPoint(MapCoordinatesFlags, TransformState&) const override;
     virtual bool requiresColumns(int desiredColumnCount) const override;
-    
+
 private:
     void initializeLayoutState(LayoutState&);