File: FragmentainerIterator.cpp

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (163 lines) | stat: -rw-r--r-- 6,472 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "core/layout/FragmentainerIterator.h"

#include "core/layout/LayoutMultiColumnSet.h"

namespace blink {

FragmentainerIterator::FragmentainerIterator(
    const LayoutFlowThread& flowThread,
    const LayoutRect& physicalBoundingBoxInFlowThread,
    const LayoutRect& clipRectInMulticolContainer)
    : m_flowThread(flowThread),
      m_clipRectInMulticolContainer(clipRectInMulticolContainer),
      m_currentFragmentainerGroupIndex(0) {
  // Put the bounds into flow thread-local coordinates by flipping it first.
  // This is how rectangles typically are represented in layout, i.e. with the
  // block direction coordinate flipped, if writing mode is vertical-rl.
  LayoutRect boundsInFlowThread = physicalBoundingBoxInFlowThread;
  m_flowThread.flipForWritingMode(boundsInFlowThread);

  if (m_flowThread.isHorizontalWritingMode()) {
    m_logicalTopInFlowThread = boundsInFlowThread.y();
    m_logicalBottomInFlowThread = boundsInFlowThread.maxY();
  } else {
    m_logicalTopInFlowThread = boundsInFlowThread.x();
    m_logicalBottomInFlowThread = boundsInFlowThread.maxX();
  }

  // Jump to the first interesting column set.
  m_currentColumnSet = flowThread.columnSetAtBlockOffset(
      m_logicalTopInFlowThread, LayoutBox::AssociateWithLatterPage);
  if (!m_currentColumnSet) {
    setAtEnd();
    return;
  }
  // Then find the first interesting fragmentainer group.
  m_currentFragmentainerGroupIndex =
      m_currentColumnSet->fragmentainerGroupIndexAtFlowThreadOffset(
          m_logicalTopInFlowThread, LayoutBox::AssociateWithLatterPage);

  // Now find the first and last fragmentainer we're interested in. We'll also
  // clip against the clip rect here. In case the clip rect doesn't intersect
  // with any of the fragmentainers, we have to move on to the next
  // fragmentainer group, and see if we find something there.
  if (!setFragmentainersOfInterest()) {
    moveToNextFragmentainerGroup();
    if (atEnd())
      return;
  }
}

void FragmentainerIterator::advance() {
  DCHECK(!atEnd());

  if (m_currentFragmentainerIndex < m_endFragmentainerIndex) {
    m_currentFragmentainerIndex++;
  } else {
    // That was the last fragmentainer to visit in this fragmentainer group.
    // Advance to the next group.
    moveToNextFragmentainerGroup();
    if (atEnd())
      return;
  }
}

LayoutSize FragmentainerIterator::paginationOffset() const {
  DCHECK(!atEnd());
  const MultiColumnFragmentainerGroup& group = currentGroup();
  LayoutUnit fragmentainerLogicalTopInFlowThread =
      group.logicalTopInFlowThread() +
      m_currentFragmentainerIndex * group.logicalHeight();
  return group.flowThreadTranslationAtOffset(
      fragmentainerLogicalTopInFlowThread, LayoutBox::AssociateWithLatterPage,
      CoordinateSpaceConversion::Visual);
}

LayoutRect FragmentainerIterator::fragmentainerInFlowThread() const {
  DCHECK(!atEnd());
  LayoutRect fragmentainerInFlowThread =
      currentGroup().flowThreadPortionRectAt(m_currentFragmentainerIndex);
  m_flowThread.flipForWritingMode(fragmentainerInFlowThread);
  return fragmentainerInFlowThread;
}

LayoutRect FragmentainerIterator::clipRectInFlowThread() const {
  DCHECK(!atEnd());
  LayoutRect clipRect = currentGroup().flowThreadPortionOverflowRectAt(
      m_currentFragmentainerIndex);
  m_flowThread.flipForWritingMode(clipRect);
  return clipRect;
}

const MultiColumnFragmentainerGroup& FragmentainerIterator::currentGroup()
    const {
  DCHECK(!atEnd());
  return m_currentColumnSet
      ->fragmentainerGroups()[m_currentFragmentainerGroupIndex];
}

void FragmentainerIterator::moveToNextFragmentainerGroup() {
  do {
    m_currentFragmentainerGroupIndex++;
    if (m_currentFragmentainerGroupIndex >=
        m_currentColumnSet->fragmentainerGroups().size()) {
      // That was the last fragmentainer group in this set. Advance to the next.
      m_currentColumnSet = m_currentColumnSet->nextSiblingMultiColumnSet();
      m_currentFragmentainerGroupIndex = 0;
      if (!m_currentColumnSet ||
          m_currentColumnSet->logicalTopInFlowThread() >=
              m_logicalBottomInFlowThread) {
        setAtEnd();
        return;  // No more sets or next set out of range. We're done.
      }
    }
    if (currentGroup().logicalTopInFlowThread() >=
        m_logicalBottomInFlowThread) {
      // This fragmentainer group doesn't intersect with the range we're
      // interested in. We're done.
      setAtEnd();
      return;
    }
  } while (!setFragmentainersOfInterest());
}

bool FragmentainerIterator::setFragmentainersOfInterest() {
  const MultiColumnFragmentainerGroup& group = currentGroup();

  // Figure out the start and end fragmentainers for the block range we're
  // interested in. We might not have to walk the entire fragmentainer group.
  group.columnIntervalForBlockRangeInFlowThread(
      m_logicalTopInFlowThread, m_logicalBottomInFlowThread,
      m_currentFragmentainerIndex, m_endFragmentainerIndex);

  if (hasClipRect()) {
    // Now intersect with the fragmentainers that actually intersect with the
    // visual clip rect, to narrow it down even further. The clip rect needs to
    // be relative to the current fragmentainer group.
    LayoutRect clipRect = m_clipRectInMulticolContainer;
    LayoutSize offset = group.flowThreadTranslationAtOffset(
        group.logicalTopInFlowThread(), LayoutBox::AssociateWithFormerPage,
        CoordinateSpaceConversion::Visual);
    clipRect.move(-offset);
    unsigned firstFragmentainerInClipRect, lastFragmentainerInClipRect;
    group.columnIntervalForVisualRect(clipRect, firstFragmentainerInClipRect,
                                      lastFragmentainerInClipRect);
    // If the two fragmentainer intervals are disjoint, there's nothing of
    // interest in this fragmentainer group.
    if (firstFragmentainerInClipRect > m_endFragmentainerIndex ||
        lastFragmentainerInClipRect < m_currentFragmentainerIndex)
      return false;
    if (m_currentFragmentainerIndex < firstFragmentainerInClipRect)
      m_currentFragmentainerIndex = firstFragmentainerInClipRect;
    if (m_endFragmentainerIndex > lastFragmentainerInClipRect)
      m_endFragmentainerIndex = lastFragmentainerInClipRect;
  }
  DCHECK(m_endFragmentainerIndex >= m_currentFragmentainerIndex);
  return true;
}

}  // namespace blink