File indexing completed on 2025-01-12 12:27:57
0001 /* 0002 * This file is part of the HTML widget for KDE. 0003 * 0004 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org) 0005 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 0006 * 0007 * This library is free software; you can redistribute it and/or 0008 * modify it under the terms of the GNU Library General Public 0009 * License as published by the Free Software Foundation; either 0010 * version 2 of the License, or (at your option) any later version. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Library General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Library General Public License 0018 * along with this library; see the file COPYING.LIB. If not, write to 0019 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 * Boston, MA 02110-1301, USA. 0021 * 0022 */ 0023 #ifndef render_canvas_h 0024 #define render_canvas_h 0025 0026 #include "render_block.h" 0027 0028 class KHTMLView; 0029 0030 namespace khtml 0031 { 0032 0033 class RenderPage; 0034 class RenderStyle; 0035 0036 enum CanvasMode { 0037 CanvasViewPort, // Paints inside a viewport 0038 CanvasPage, // Paints one page 0039 CanvasDocument // Paints the whole document 0040 }; 0041 0042 class RenderCanvas : public RenderBlock 0043 { 0044 public: 0045 RenderCanvas(DOM::NodeImpl *node, KHTMLView *view); 0046 ~RenderCanvas(); 0047 0048 const char *renderName() const override 0049 { 0050 return "RenderCanvas"; 0051 } 0052 0053 bool isCanvas() const override 0054 { 0055 return true; 0056 } 0057 0058 void setStyle(RenderStyle *style) override; 0059 void layout() override; 0060 void calcWidth() override; 0061 void calcHeight() override; 0062 void calcMinMaxWidth() override; 0063 bool absolutePosition(int &xPos, int &yPos, bool f = false) const override; 0064 0065 int docHeight() const; 0066 int docWidth() const; 0067 0068 KHTMLView *view() const 0069 { 0070 return m_view; 0071 } 0072 0073 void repaint(Priority p = NormalPriority) override; 0074 void repaintRectangle(int x, int y, int w, int h, Priority p = NormalPriority, bool f = false) override; 0075 void repaintViewRectangle(int x, int y, int w, int h, bool asap = false); 0076 bool needsFullRepaint() const; 0077 void deferredRepaint(RenderObject *o); 0078 void scheduleDeferredRepaints(); 0079 0080 void paint(PaintInfo &, int tx, int ty) override; 0081 void paintBoxDecorations(PaintInfo &paintInfo, int _tx, int _ty) override; 0082 virtual void setSelection(RenderObject *s, int sp, RenderObject *e, int ep); 0083 virtual void clearSelection(bool doRepaint = true); 0084 virtual RenderObject *selectionStart() const 0085 { 0086 return m_selectionStart; 0087 } 0088 virtual RenderObject *selectionEnd() const 0089 { 0090 return m_selectionEnd; 0091 } 0092 bool hasSelection() const 0093 { 0094 return m_selectionStart && m_selectionEnd; 0095 } 0096 0097 void setPrintImages(bool enable) 0098 { 0099 m_printImages = enable; 0100 } 0101 bool printImages() const 0102 { 0103 return m_printImages; 0104 } 0105 0106 void setCanvasMode(CanvasMode mode) 0107 { 0108 m_canvasMode = mode; 0109 } 0110 CanvasMode canvasMode() const 0111 { 0112 return m_canvasMode; 0113 } 0114 0115 void setPagedMode(bool b) 0116 { 0117 m_pagedMode = b; 0118 } 0119 void setStaticMode(bool b) 0120 { 0121 m_staticMode = b; 0122 } 0123 0124 bool pagedMode() const 0125 { 0126 return m_pagedMode; 0127 } 0128 bool staticMode() const 0129 { 0130 return m_staticMode; 0131 } 0132 0133 void setPageTop(int top) 0134 { 0135 m_pageTop = top; 0136 // m_y = top; 0137 } 0138 void setPageBottom(int bottom) 0139 { 0140 m_pageBottom = bottom; 0141 } 0142 int pageTop() const 0143 { 0144 return m_pageTop; 0145 } 0146 int pageBottom() const 0147 { 0148 return m_pageBottom; 0149 } 0150 0151 int pageTopAfter(int y) const override 0152 { 0153 if (pageHeight() == 0) { 0154 return 0; 0155 } 0156 return (y / pageHeight() + 1) * pageHeight(); 0157 } 0158 0159 int crossesPageBreak(int top, int bottom) const override 0160 { 0161 if (pageHeight() == 0) { 0162 return false; 0163 } 0164 int pT = top / pageHeight(); 0165 // bottom is actually the first line not in the box 0166 int pB = (bottom - 1) / pageHeight(); 0167 return (pT == pB) ? 0 : (pB + 1); 0168 } 0169 0170 void setPageNumber(int number) 0171 { 0172 m_pageNr = number; 0173 } 0174 int pageNumber() const 0175 { 0176 return m_pageNr; 0177 } 0178 0179 void updateInvalidatedFonts(); 0180 public: 0181 void setWidth(int width) override 0182 { 0183 m_rootWidth = m_width = width; 0184 } 0185 void setHeight(int height) override 0186 { 0187 m_rootHeight = m_height = height; 0188 } 0189 0190 // void setPageHeight( int height ) { m_viewportHeight = m_pageHeight = height; } 0191 int pageHeight() const 0192 { 0193 return m_pageBottom - m_pageTop; 0194 } 0195 0196 int viewportWidth() const 0197 { 0198 return m_viewportWidth; 0199 } 0200 int viewportHeight() const 0201 { 0202 return m_viewportHeight; 0203 } 0204 0205 RenderPage *page(); 0206 0207 QRect selectionRect() const; 0208 QRegion staticRegion() const; 0209 0210 void setMaximalOutlineSize(int o) 0211 { 0212 m_maximalOutlineSize = o; 0213 } 0214 int maximalOutlineSize() const 0215 { 0216 return m_maximalOutlineSize; 0217 } 0218 0219 void setNeedsWidgetMasks(bool b = true); 0220 bool needsWidgetMasks() const 0221 { 0222 return m_needsWidgetMasks; 0223 } 0224 0225 void addStaticObject(RenderObject *o, bool positioned = false); 0226 void removeStaticObject(RenderObject *o, bool positioned = false); 0227 0228 void updateDocSizeAfterLayerTranslation(RenderObject *o, bool posXOffset, bool posYOffset); 0229 0230 bool isPerformingLayout() const 0231 { 0232 return m_isPerformingLayout; 0233 } 0234 protected: 0235 // makes sure document, scrollbars and viewport size are accurate 0236 void updateDocumentSize(); 0237 0238 // internal setters for cached values of document width/height 0239 // Setting to -1/-1 invalidates the cache. 0240 void setCachedDocWidth(int w) 0241 { 0242 m_cachedDocWidth = w; 0243 } 0244 void setCachedDocHeight(int h) 0245 { 0246 m_cachedDocHeight = h; 0247 } 0248 0249 void selectionStartEnd(int &spos, int &epos) override; 0250 0251 QRect viewRect() const override; 0252 0253 KHTMLView *m_view; 0254 0255 RenderObject *m_selectionStart; 0256 RenderObject *m_selectionEnd; 0257 int m_selectionStartPos; 0258 int m_selectionEndPos; 0259 0260 CanvasMode m_canvasMode; 0261 0262 int m_rootWidth; 0263 int m_rootHeight; 0264 0265 int m_viewportWidth; 0266 int m_viewportHeight; 0267 0268 int m_cachedDocWidth; 0269 int m_cachedDocHeight; 0270 0271 bool m_printImages; 0272 bool m_needsFullRepaint; 0273 0274 // Canvas is not interactive 0275 bool m_staticMode; 0276 // Canvas is paged 0277 bool m_pagedMode; 0278 // Canvas contains overlaid widgets 0279 bool m_needsWidgetMasks; 0280 // Whether we are currently performing a layout 0281 bool m_isPerformingLayout; 0282 0283 short m_pageNr; 0284 0285 int m_pageTop; 0286 int m_pageBottom; 0287 0288 RenderPage *m_page; 0289 0290 int m_maximalOutlineSize; // Used to apply a fudge factor to dirty-rect checks on blocks/tables. 0291 QList<RenderObject *> m_dirtyChildren; 0292 QSet<RenderObject *>m_fixedBackground; 0293 QSet<RenderObject *>m_fixedPosition; 0294 }; 0295 0296 inline RenderCanvas *RenderObject::canvas() const 0297 { 0298 return static_cast<RenderCanvas *>(document()->renderer()); 0299 } 0300 0301 // Represents the page-context of CSS 0302 class RenderPage 0303 { 0304 public: 0305 RenderPage(RenderCanvas *canvas) : m_canvas(canvas), 0306 m_marginTop(0), m_marginBottom(0), 0307 m_marginLeft(0), m_marginRight(0), 0308 m_pageWidth(0), m_pageHeight(0), 0309 m_fixedSize(false) 0310 { 0311 m_style = new RenderPageStyle(); 0312 } 0313 virtual ~RenderPage() 0314 { 0315 delete m_style; 0316 } 0317 0318 int marginTop() const 0319 { 0320 return m_marginTop; 0321 } 0322 int marginBottom() const 0323 { 0324 return m_marginBottom; 0325 } 0326 int marginLeft() const 0327 { 0328 return m_marginLeft; 0329 } 0330 int marginRight() const 0331 { 0332 return m_marginRight; 0333 } 0334 0335 void setMarginTop(int margin) 0336 { 0337 m_marginTop = margin; 0338 } 0339 void setMarginBottom(int margin) 0340 { 0341 m_marginBottom = margin; 0342 } 0343 void setMarginLeft(int margin) 0344 { 0345 m_marginLeft = margin; 0346 } 0347 void setMarginRight(int margin) 0348 { 0349 m_marginRight = margin; 0350 } 0351 0352 int pageWidth() const 0353 { 0354 return m_pageWidth; 0355 } 0356 int pageHeight() const 0357 { 0358 return m_pageHeight; 0359 } 0360 0361 void setPageSize(int width, int height) 0362 { 0363 m_pageWidth = width; 0364 m_pageHeight = height; 0365 } 0366 0367 // Returns true if size was set by document, false if set by user-agent 0368 bool fixedSize() const 0369 { 0370 return m_fixedSize; 0371 } 0372 void setFixedSize(bool b) 0373 { 0374 m_fixedSize = b; 0375 } 0376 0377 RenderPageStyle *style() 0378 { 0379 return m_style; 0380 } 0381 const RenderPageStyle *style() const 0382 { 0383 return m_style; 0384 } 0385 0386 protected: 0387 RenderCanvas *m_canvas; 0388 RenderPageStyle *m_style; 0389 0390 int m_marginTop; 0391 int m_marginBottom; 0392 int m_marginLeft; 0393 int m_marginRight; 0394 0395 int m_pageWidth; 0396 int m_pageHeight; 0397 0398 bool m_fixedSize; 0399 }; 0400 0401 } 0402 #endif