KHtml

render_canvas.h
1 /*
2  * This file is part of the HTML widget for KDE.
3  *
4  * Copyright (C) 1999-2003 Lars Knoll ([email protected])
5  * (C) 2005 Allan Sandfeld Jensen ([email protected])
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 render_canvas_h
24 #define render_canvas_h
25 
26 #include "render_block.h"
27 
28 class KHTMLView;
29 
30 namespace khtml
31 {
32 
33 class RenderPage;
34 class RenderStyle;
35 
36 enum CanvasMode {
37  CanvasViewPort, // Paints inside a viewport
38  CanvasPage, // Paints one page
39  CanvasDocument // Paints the whole document
40 };
41 
42 class RenderCanvas : public RenderBlock
43 {
44 public:
45  RenderCanvas(DOM::NodeImpl *node, KHTMLView *view);
46  ~RenderCanvas();
47 
48  const char *renderName() const override
49  {
50  return "RenderCanvas";
51  }
52 
53  bool isCanvas() const override
54  {
55  return true;
56  }
57 
58  void setStyle(RenderStyle *style) override;
59  void layout() override;
60  void calcWidth() override;
61  void calcHeight() override;
62  void calcMinMaxWidth() override;
63  bool absolutePosition(int &xPos, int &yPos, bool f = false) const override;
64 
65  int docHeight() const;
66  int docWidth() const;
67 
68  KHTMLView *view() const
69  {
70  return m_view;
71  }
72 
73  void repaint(Priority p = NormalPriority) override;
74  void repaintRectangle(int x, int y, int w, int h, Priority p = NormalPriority, bool f = false) override;
75  void repaintViewRectangle(int x, int y, int w, int h, bool asap = false);
76  bool needsFullRepaint() const;
77  void deferredRepaint(RenderObject *o);
78  void scheduleDeferredRepaints();
79 
80  void paint(PaintInfo &, int tx, int ty) override;
81  void paintBoxDecorations(PaintInfo &paintInfo, int _tx, int _ty) override;
82  virtual void setSelection(RenderObject *s, int sp, RenderObject *e, int ep);
83  virtual void clearSelection(bool doRepaint = true);
84  virtual RenderObject *selectionStart() const
85  {
86  return m_selectionStart;
87  }
88  virtual RenderObject *selectionEnd() const
89  {
90  return m_selectionEnd;
91  }
92  bool hasSelection() const
93  {
94  return m_selectionStart && m_selectionEnd;
95  }
96 
97  void setPrintImages(bool enable)
98  {
99  m_printImages = enable;
100  }
101  bool printImages() const
102  {
103  return m_printImages;
104  }
105 
106  void setCanvasMode(CanvasMode mode)
107  {
108  m_canvasMode = mode;
109  }
110  CanvasMode canvasMode() const
111  {
112  return m_canvasMode;
113  }
114 
115  void setPagedMode(bool b)
116  {
117  m_pagedMode = b;
118  }
119  void setStaticMode(bool b)
120  {
121  m_staticMode = b;
122  }
123 
124  bool pagedMode() const
125  {
126  return m_pagedMode;
127  }
128  bool staticMode() const
129  {
130  return m_staticMode;
131  }
132 
133  void setPageTop(int top)
134  {
135  m_pageTop = top;
136 // m_y = top;
137  }
138  void setPageBottom(int bottom)
139  {
140  m_pageBottom = bottom;
141  }
142  int pageTop() const
143  {
144  return m_pageTop;
145  }
146  int pageBottom() const
147  {
148  return m_pageBottom;
149  }
150 
151  int pageTopAfter(int y) const override
152  {
153  if (pageHeight() == 0) {
154  return 0;
155  }
156  return (y / pageHeight() + 1) * pageHeight();
157  }
158 
159  int crossesPageBreak(int top, int bottom) const override
160  {
161  if (pageHeight() == 0) {
162  return false;
163  }
164  int pT = top / pageHeight();
165  // bottom is actually the first line not in the box
166  int pB = (bottom - 1) / pageHeight();
167  return (pT == pB) ? 0 : (pB + 1);
168  }
169 
170  void setPageNumber(int number)
171  {
172  m_pageNr = number;
173  }
174  int pageNumber() const
175  {
176  return m_pageNr;
177  }
178 
179  void updateInvalidatedFonts();
180 public:
181  void setWidth(int width) override
182  {
183  m_rootWidth = m_width = width;
184  }
185  void setHeight(int height) override
186  {
187  m_rootHeight = m_height = height;
188  }
189 
190 // void setPageHeight( int height ) { m_viewportHeight = m_pageHeight = height; }
191  int pageHeight() const
192  {
193  return m_pageBottom - m_pageTop;
194  }
195 
196  int viewportWidth() const
197  {
198  return m_viewportWidth;
199  }
200  int viewportHeight() const
201  {
202  return m_viewportHeight;
203  }
204 
205  RenderPage *page();
206 
207  QRect selectionRect() const;
208  QRegion staticRegion() const;
209 
210  void setMaximalOutlineSize(int o)
211  {
212  m_maximalOutlineSize = o;
213  }
214  int maximalOutlineSize() const
215  {
216  return m_maximalOutlineSize;
217  }
218 
219  void setNeedsWidgetMasks(bool b = true);
220  bool needsWidgetMasks() const
221  {
222  return m_needsWidgetMasks;
223  }
224 
225  void addStaticObject(RenderObject *o, bool positioned = false);
226  void removeStaticObject(RenderObject *o, bool positioned = false);
227 
228  void updateDocSizeAfterLayerTranslation(RenderObject *o, bool posXOffset, bool posYOffset);
229 
230  bool isPerformingLayout() const
231  {
232  return m_isPerformingLayout;
233  }
234 protected:
235  // makes sure document, scrollbars and viewport size are accurate
236  void updateDocumentSize();
237 
238  // internal setters for cached values of document width/height
239  // Setting to -1/-1 invalidates the cache.
240  void setCachedDocWidth(int w)
241  {
242  m_cachedDocWidth = w;
243  }
244  void setCachedDocHeight(int h)
245  {
246  m_cachedDocHeight = h;
247  }
248 
249  void selectionStartEnd(int &spos, int &epos) override;
250 
251  QRect viewRect() const override;
252 
253  KHTMLView *m_view;
254 
255  RenderObject *m_selectionStart;
256  RenderObject *m_selectionEnd;
257  int m_selectionStartPos;
258  int m_selectionEndPos;
259 
260  CanvasMode m_canvasMode;
261 
262  int m_rootWidth;
263  int m_rootHeight;
264 
265  int m_viewportWidth;
266  int m_viewportHeight;
267 
268  int m_cachedDocWidth;
269  int m_cachedDocHeight;
270 
271  bool m_printImages;
272  bool m_needsFullRepaint;
273 
274  // Canvas is not interactive
275  bool m_staticMode;
276  // Canvas is paged
277  bool m_pagedMode;
278  // Canvas contains overlaid widgets
279  bool m_needsWidgetMasks;
280  // Whether we are currently performing a layout
281  bool m_isPerformingLayout;
282 
283  short m_pageNr;
284 
285  int m_pageTop;
286  int m_pageBottom;
287 
288  RenderPage *m_page;
289 
290  int m_maximalOutlineSize; // Used to apply a fudge factor to dirty-rect checks on blocks/tables.
291  QList<RenderObject *> m_dirtyChildren;
292  QSet<RenderObject *>m_fixedBackground;
293  QSet<RenderObject *>m_fixedPosition;
294 };
295 
296 inline RenderCanvas *RenderObject::canvas() const
297 {
298  return static_cast<RenderCanvas *>(document()->renderer());
299 }
300 
301 // Represents the page-context of CSS
302 class RenderPage
303 {
304 public:
305  RenderPage(RenderCanvas *canvas) : m_canvas(canvas),
306  m_marginTop(0), m_marginBottom(0),
307  m_marginLeft(0), m_marginRight(0),
308  m_pageWidth(0), m_pageHeight(0),
309  m_fixedSize(false)
310  {
311  m_style = new RenderPageStyle();
312  }
313  virtual ~RenderPage()
314  {
315  delete m_style;
316  }
317 
318  int marginTop() const
319  {
320  return m_marginTop;
321  }
322  int marginBottom() const
323  {
324  return m_marginBottom;
325  }
326  int marginLeft() const
327  {
328  return m_marginLeft;
329  }
330  int marginRight() const
331  {
332  return m_marginRight;
333  }
334 
335  void setMarginTop(int margin)
336  {
337  m_marginTop = margin;
338  }
339  void setMarginBottom(int margin)
340  {
341  m_marginBottom = margin;
342  }
343  void setMarginLeft(int margin)
344  {
345  m_marginLeft = margin;
346  }
347  void setMarginRight(int margin)
348  {
349  m_marginRight = margin;
350  }
351 
352  int pageWidth() const
353  {
354  return m_pageWidth;
355  }
356  int pageHeight() const
357  {
358  return m_pageHeight;
359  }
360 
361  void setPageSize(int width, int height)
362  {
363  m_pageWidth = width;
364  m_pageHeight = height;
365  }
366 
367  // Returns true if size was set by document, false if set by user-agent
368  bool fixedSize() const
369  {
370  return m_fixedSize;
371  }
372  void setFixedSize(bool b)
373  {
374  m_fixedSize = b;
375  }
376 
377  RenderPageStyle *style()
378  {
379  return m_style;
380  }
381  const RenderPageStyle *style() const
382  {
383  return m_style;
384  }
385 
386 protected:
387  RenderCanvas *m_canvas;
388  RenderPageStyle *m_style;
389 
390  int m_marginTop;
391  int m_marginBottom;
392  int m_marginLeft;
393  int m_marginRight;
394 
395  int m_pageWidth;
396  int m_pageHeight;
397 
398  bool m_fixedSize;
399 };
400 
401 }
402 #endif
This file is part of the HTML rendering engine for KDE.
Renders and displays HTML in a QScrollArea.
Definition: khtmlview.h:97
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Aug 3 2020 22:45:42 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.