Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright (C) 2000 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 2000 Antti Koivisto (koivisto (at) kde.org)
      4  *           (C) 2000 Dirk Mueller (mueller (at) kde.org)
      5  *           (C) 2004 Allan Sandfeld Jensen (kde (at) carewolf.com)
      6  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
      7  * Copyright (C) 2009 Google Inc. All rights reserved.
      8  *
      9  * This library is free software; you can redistribute it and/or
     10  * modify it under the terms of the GNU Library General Public
     11  * License as published by the Free Software Foundation; either
     12  * version 2 of the License, or (at your option) any later version.
     13  *
     14  * This library is distributed in the hope that it will be useful,
     15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     17  * Library General Public License for more details.
     18  *
     19  * You should have received a copy of the GNU Library General Public License
     20  * along with this library; see the file COPYING.LIB.  If not, write to
     21  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     22  * Boston, MA 02110-1301, USA.
     23  *
     24  */
     25 
     26 #ifndef PaintInfo_h
     27 #define PaintInfo_h
     28 
     29 #if ENABLE(SVG)
     30 #include "AffineTransform.h"
     31 #endif
     32 
     33 #include "GraphicsContext.h"
     34 #include "IntRect.h"
     35 #include "PaintPhase.h"
     36 #include <wtf/HashMap.h>
     37 #include <wtf/ListHashSet.h>
     38 
     39 namespace WebCore {
     40 
     41 class OverlapTestRequestClient;
     42 class RenderInline;
     43 class RenderObject;
     44 
     45 typedef HashMap<OverlapTestRequestClient*, IntRect> OverlapTestRequestMap;
     46 
     47 /*
     48  * Paint the object and its children, clipped by (x|y|w|h).
     49  * (tx|ty) is the calculated position of the parent
     50  */
     51 struct PaintInfo {
     52     PaintInfo(GraphicsContext* newContext, const IntRect& newRect, PaintPhase newPhase, bool newForceBlackText,
     53               RenderObject* newPaintingRoot, ListHashSet<RenderInline*>* newOutlineObjects,
     54               OverlapTestRequestMap* overlapTestRequests = 0)
     55         : context(newContext)
     56         , rect(newRect)
     57         , phase(newPhase)
     58         , forceBlackText(newForceBlackText)
     59         , paintingRoot(newPaintingRoot)
     60         , outlineObjects(newOutlineObjects)
     61         , overlapTestRequests(overlapTestRequests)
     62     {
     63     }
     64 
     65     void updatePaintingRootForChildren(const RenderObject* renderer)
     66     {
     67         if (!paintingRoot)
     68             return;
     69 
     70         // If we're the painting root, kids draw normally, and see root of 0.
     71         if (paintingRoot == renderer) {
     72             paintingRoot = 0;
     73             return;
     74         }
     75     }
     76 
     77     bool shouldPaintWithinRoot(const RenderObject* renderer) const
     78     {
     79         return !paintingRoot || paintingRoot == renderer;
     80     }
     81 
     82 #if ENABLE(SVG)
     83     void applyTransform(const AffineTransform& localToAncestorTransform)
     84     {
     85         if (localToAncestorTransform.isIdentity())
     86             return;
     87 
     88         context->concatCTM(localToAncestorTransform);
     89 
     90         if (rect == infiniteRect())
     91             return;
     92 
     93         rect = localToAncestorTransform.inverse().mapRect(rect);
     94     }
     95 #endif
     96 
     97     static IntRect infiniteRect() { return IntRect(INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX); }
     98 
     99     // FIXME: Introduce setters/getters at some point. Requires a lot of changes throughout rendering/.
    100     GraphicsContext* context;
    101     IntRect rect;
    102     PaintPhase phase;
    103     bool forceBlackText;
    104     RenderObject* paintingRoot; // used to draw just one element and its visual kids
    105     ListHashSet<RenderInline*>* outlineObjects; // used to list outlines that should be painted by a block with inline children
    106     OverlapTestRequestMap* overlapTestRequests;
    107 };
    108 
    109 } // namespace WebCore
    110 
    111 #endif // PaintInfo_h
    112