KHtml

render_position.h
1 /*
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright (C) 2009 Vyacheslav Tokarev ([email protected])
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef Render_Position_H
23 #define Render_Position_H
24 
25 #include "xml/dom_position.h"
26 #include "rendering/render_object.h"
27 
28 using DOM::Position;
29 
30 namespace DOM
31 {
32 class NodeImpl;
33 }
34 
35 using DOM::NodeImpl;
36 
37 namespace khtml
38 {
39 class InlineBox;
40 
41 class RenderPosition
42 {
43 public:
44  // constructs empty position
45  RenderPosition() {}
46  RenderPosition(const Position &position) : m_position(position) {}
47  RenderPosition(NodeImpl *node, int offset);
48 
49  static RenderPosition fromDOMPosition(const Position &position);
50 
51  Position position() const
52  {
53  return m_position;
54  }
55  const RenderObject *renderer() const
56  {
57  return m_position.isEmpty() ? nullptr : m_position.node()->renderer();
58  }
59  NodeImpl *node() const
60  {
61  return m_position.node();
62  }
63  int domOffset() const
64  {
65  return m_position.offset();
66  }
67 
68  inline bool isEmpty() const
69  {
70  return m_position.isEmpty();
71  }
72  inline bool notEmpty() const
73  {
74  return m_position.notEmpty();
75  }
76 
77  // QRect caretRegion() const;
78 
79  // int renderedOffset() const; // convert to rendered offset, though we need to eliminate other code using it
80  int renderedOffset()
81  {
82  int result;
83  getInlineBoxAndOffset(result);
84  return result;
85  }
86 
87  bool inRenderedContent()
88  {
89  return renderer();
90  }
91  static bool inRenderedContent(const Position &position)
92  {
93  return fromDOMPosition(position).inRenderedContent();
94  }
95 
96  // implementation: same RootInlineBox
97  static bool rendersOnSameLine(const RenderPosition &self, const RenderPosition &other);
98  // implementation: either renderers are different, or inline boxes or offsets inside
99  static bool rendersInDifferentPosition(const RenderPosition &self, const RenderPosition &other);
100 
101  // static bool rendersOnDifferentLine(); // compare inline boxes and its roots
102 
103  // bool isFirstOnRenderedLine() const; // either iterate backwards over DOM tree or check if we're at the beginning of the RootInlineBox?
104  // bool isLastOnRenderedLine() const; // -||-
105 
106  RenderPosition previousLinePosition(int);
107  RenderPosition nextLinePosition(int);
108 
109 protected:
110  // returns rendered offset
111  InlineBox *getInlineBoxAndOffset(int &offset) const;
112 
113 private:
114  Position m_position;
115  // affinity thing, so we'll have where to put caret at the end of inline box or at the start of next one
116 };
117 
118 inline bool operator==(const RenderPosition &a, const RenderPosition &b)
119 {
120  return a.position() == b.position();
121 }
122 
123 inline bool operator!=(const RenderPosition &a, const RenderPosition &b)
124 {
125  return !(a == b);
126 }
127 
128 QDebug operator<<(QDebug stream, const RenderPosition &renderPosition);
129 
130 } // namespace
131 
132 #endif
This file is part of the HTML rendering engine for KDE.
bool operator==(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
This library provides a full-featured HTML parser and widget.
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
bool operator!=(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:08 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.