KHtml

bidi.h
1 /*
2  * This file is part of the html renderer for KDE.
3  *
4  * Copyright (C) 2000 Lars Knoll ([email protected])
5  * Copyright (C) 2003 Apple Computer, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  */
23 #ifndef BIDI_H
24 #define BIDI_H
25 
26 #include <QString>
27 #include "rendering/render_object.h"
28 
29 namespace khtml
30 {
31 class RenderArena;
32 class RenderObject;
33 class InlineBox;
34 
35 class BidiContext
36 {
37 public:
38  BidiContext(unsigned char level, QChar::Direction embedding, BidiContext *parent = nullptr, bool override = false);
39  ~BidiContext();
40 
41  void ref() const;
42  void deref() const;
43 
44  unsigned char level;
45  bool override : 1;
47  QChar::Direction basicDir : 5;
48 
49  BidiContext *parent;
50 
51  // refcounting....
52  mutable int count;
53 };
54 
55 struct BidiRun {
56  BidiRun(int _start, int _stop, RenderObject *_obj, BidiContext *context, QChar::Direction dir)
57  : start(_start), stop(_stop), obj(_obj), box(nullptr), nextRun(nullptr)
58  {
59  if (dir == QChar::DirON) {
60  dir = context->dir;
61  }
62 
63  level = context->level;
64 
65  // add level of run (cases I1 & I2)
66  if (level % 2) {
67  if (dir == QChar::DirL || dir == QChar::DirAN || dir == QChar::DirEN) {
68  level++;
69  }
70  } else {
71  if (dir == QChar::DirR) {
72  level++;
73  } else if (dir == QChar::DirAN || dir == QChar::DirEN) {
74  level += 2;
75  }
76  }
77  }
78 
79  void detach(RenderArena *renderArena);
80 
81  // Overloaded new operator.
82  void *operator new(size_t sz, RenderArena *renderArena) throw();
83 
84  // Overridden to prevent the normal delete from being called.
85  void operator delete(void *ptr, size_t sz);
86 
87 private:
88  // The normal operator new is disallowed.
89  void *operator new(size_t sz) throw();
90 
91 public:
92  int start;
93  int stop;
94 
95  RenderObject *obj;
96  InlineBox *box;
97 
98  // explicit + implicit levels here
99  uchar level;
100 
101  bool compact : 1;
102 
103  BidiRun *nextRun;
104 };
105 
106 struct BidiIterator;
107 struct BidiState;
108 
109 struct BidiStatus {
110  BidiStatus() : eor(QChar::DirON), lastStrong(QChar::DirON), last(QChar::DirON) {}
111 
112  QChar::Direction eor;
113  QChar::Direction lastStrong;
114  QChar::Direction last;
115 };
116 
117 struct InlineMinMaxIterator {
118  /* InlineMinMaxIterator is a class that will iterate over all render objects that contribute to
119  inline min/max width calculations. Note the following about the way it walks:
120  (1) Positioned content is skipped (since it does not contribute to min/max width of a block)
121  (2) We do not drill into the children of floats or replaced elements, since you can't break
122  in the middle of such an element.
123  (3) Inline flows (e.g., <a>, <span>, <i>) are walked twice, since each side can have
124  distinct borders/margin/padding that contribute to the min/max width.
125  */
126  RenderObject *parent;
127  RenderObject *current;
128  bool endOfInline;
129  bool skipPositioned;
130  InlineMinMaxIterator(RenderObject *p, RenderObject *o, bool eOI = false, bool skipPos = true)
131  : parent(p), current(o), endOfInline(eOI), skipPositioned(skipPos) {}
132  inline RenderObject *next();
133 };
134 
135 inline RenderObject *InlineMinMaxIterator::next()
136 {
137  RenderObject *result = nullptr;
138  bool oldEndOfInline = endOfInline;
139  endOfInline = false;
140  while (current != nullptr || (current == parent)) {
141  //qCDebug(KHTML_LOG) << "current = " << current;
142  if (!oldEndOfInline &&
143  (current == parent ||
144  (!current->isFloating() && !current->isReplaced() && !current->isPositioned()))) {
145  result = current->firstChild();
146  }
147  if (!result) {
148  // We hit the end of our inline. (It was empty, e.g., <span></span>.)
149  if (!oldEndOfInline && current->isInlineFlow()) {
150  result = current;
151  endOfInline = true;
152  break;
153  }
154  while (current && current != parent) {
155  result = current->nextSibling();
156  if (result) {
157  break;
158  }
159  current = current->parent();
160  if (current && current != parent && current->isInlineFlow()) {
161  result = current;
162  endOfInline = true;
163  break;
164  }
165  }
166  }
167 
168  if (!result) {
169  break;
170  }
171 
172  if ((!skipPositioned || !result->isPositioned()) && (result->isText() || result->isBR() ||
173  result->isFloatingOrPositioned() || result->isReplaced() || result->isGlyph() || result->isInlineFlow())) {
174  break;
175  }
176 
177  current = result;
178  result = nullptr;
179  }
180 
181  // Update our position.
182  current = result;
183  return current;
184 }
185 }
186 
187 #endif
This file is part of the HTML rendering engine for KDE.
MESSAGECORE_EXPORT KMime::Content * next(KMime::Content *node, bool allowChildren=true)
void ref()
void deref()
KGuiItem stop()
QStringView level(QStringView ifopt)
KIOFILEWIDGETS_EXPORT QString dir(const QString &fileClass)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:47:58 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.