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  *
      8  * This library is free software; you can redistribute it and/or
      9  * modify it under the terms of the GNU Library General Public
     10  * License as published by the Free Software Foundation; either
     11  * version 2 of the License, or (at your option) any later version.
     12  *
     13  * This library is distributed in the hope that it will be useful,
     14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16  * Library General Public License for more details.
     17  *
     18  * You should have received a copy of the GNU Library General Public License
     19  * along with this library; see the file COPYING.LIB.  If not, write to
     20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     21  * Boston, MA 02110-1301, USA.
     22  *
     23  */
     24 
     25 #ifndef RenderSelectionInfo_h
     26 #define RenderSelectionInfo_h
     27 
     28 #include "core/rendering/RenderBox.h"
     29 #include "platform/geometry/IntRect.h"
     30 
     31 namespace WebCore {
     32 
     33 class RenderSelectionInfoBase {
     34     WTF_MAKE_NONCOPYABLE(RenderSelectionInfoBase); WTF_MAKE_FAST_ALLOCATED;
     35 public:
     36     RenderSelectionInfoBase()
     37         : m_object(0)
     38         , m_repaintContainer(0)
     39         , m_state(RenderObject::SelectionNone)
     40     {
     41     }
     42 
     43     RenderSelectionInfoBase(RenderObject* o)
     44         : m_object(o)
     45         , m_repaintContainer(o->containerForPaintInvalidation())
     46         , m_state(o->selectionState())
     47     {
     48     }
     49 
     50     RenderObject* object() const { return m_object; }
     51     const RenderLayerModelObject* repaintContainer() const { return m_repaintContainer; }
     52     RenderObject::SelectionState state() const { return m_state; }
     53 
     54 protected:
     55     RenderObject* m_object;
     56     const RenderLayerModelObject* m_repaintContainer;
     57     RenderObject::SelectionState m_state;
     58 };
     59 
     60 // This struct is used when the selection changes to cache the old and new state of the selection for each RenderObject.
     61 class RenderSelectionInfo : public RenderSelectionInfoBase {
     62 public:
     63     RenderSelectionInfo(RenderObject* o, bool clipToVisibleContent)
     64         : RenderSelectionInfoBase(o)
     65     {
     66         if (o->canUpdateSelectionOnRootLineBoxes()) {
     67             m_rect = o->selectionRectForPaintInvalidation(m_repaintContainer, clipToVisibleContent);
     68             // FIXME: groupedMapping() leaks the squashing abstraction. See RenderBlockSelectionInfo for more details.
     69             if (m_repaintContainer && m_repaintContainer->groupedMapping())
     70                 RenderLayer::mapRectToRepaintBacking(m_repaintContainer, m_repaintContainer, m_rect);
     71         } else {
     72             m_rect = LayoutRect();
     73         }
     74     }
     75 
     76     void repaint()
     77     {
     78         m_object->invalidatePaintUsingContainer(m_repaintContainer, enclosingIntRect(m_rect), InvalidationSelection);
     79     }
     80 
     81     LayoutRect rect() const { return m_rect; }
     82 
     83 private:
     84     LayoutRect m_rect; // relative to repaint container
     85 };
     86 
     87 
     88 // This struct is used when the selection changes to cache the old and new state of the selection for each RenderBlock.
     89 class RenderBlockSelectionInfo : public RenderSelectionInfoBase {
     90 public:
     91     RenderBlockSelectionInfo(RenderBlock* b)
     92         : RenderSelectionInfoBase(b)
     93     {
     94         if (b->canUpdateSelectionOnRootLineBoxes())
     95             m_rects = block()->selectionGapRectsForRepaint(m_repaintContainer);
     96         else
     97             m_rects = GapRects();
     98     }
     99 
    100     void repaint()
    101     {
    102         LayoutRect repaintRect = enclosingIntRect(m_rects);
    103         // FIXME: this is leaking the squashing abstraction. However, removing the groupedMapping() condiitional causes
    104         // RenderBox::mapRectToRepaintBacking to get called, which makes rect adjustments even if you pass the same
    105         // repaintContainer as the render object. Find out why it does that and fix.
    106         if (m_repaintContainer && m_repaintContainer->groupedMapping())
    107             RenderLayer::mapRectToRepaintBacking(m_repaintContainer, m_repaintContainer, repaintRect);
    108         m_object->invalidatePaintUsingContainer(m_repaintContainer, enclosingIntRect(repaintRect), InvalidationSelection);
    109     }
    110 
    111     RenderBlock* block() const { return toRenderBlock(m_object); }
    112     GapRects rects() const { return m_rects; }
    113 
    114 private:
    115     GapRects m_rects; // relative to repaint container
    116 };
    117 
    118 } // namespace WebCore
    119 
    120 
    121 #endif // RenderSelectionInfo_h
    122