blob: a09fc1a00fdc5d167b51fb0a4ed58b9dbe3cf799 [file] [log] [blame]
simon.fraser@apple.come1e3f8f2009-02-04 02:41:38 +00001/*
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * (C) 2004 Allan Sandfeld Jensen (kde@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
eric@webkit.org83cb6022010-06-23 06:44:40 +000025#ifndef RenderSelectionInfo_h
26#define RenderSelectionInfo_h
simon.fraser@apple.come1e3f8f2009-02-04 02:41:38 +000027
28#include "IntRect.h"
29#include "RenderBox.h"
30
31namespace WebCore {
32
eric@webkit.orge56ee8a2009-11-29 15:57:19 +000033class RenderSelectionInfoBase : public Noncopyable {
simon.fraser@apple.come1e3f8f2009-02-04 02:41:38 +000034public:
35 RenderSelectionInfoBase()
36 : m_object(0)
37 , m_repaintContainer(0)
38 , m_state(RenderObject::SelectionNone)
39 {
40 }
41
42 RenderSelectionInfoBase(RenderObject* o)
43 : m_object(o)
44 , m_repaintContainer(o->containerForRepaint())
45 , m_state(o->selectionState())
46 {
47 }
48
49 RenderObject* object() const { return m_object; }
hyatt@apple.com80ab6e92009-02-05 17:24:00 +000050 RenderBoxModelObject* repaintContainer() const { return m_repaintContainer; }
simon.fraser@apple.come1e3f8f2009-02-04 02:41:38 +000051 RenderObject::SelectionState state() const { return m_state; }
52
53protected:
54 RenderObject* m_object;
hyatt@apple.com80ab6e92009-02-05 17:24:00 +000055 RenderBoxModelObject* m_repaintContainer;
simon.fraser@apple.come1e3f8f2009-02-04 02:41:38 +000056 RenderObject::SelectionState m_state;
57};
58
59// This struct is used when the selection changes to cache the old and new state of the selection for each RenderObject.
60class RenderSelectionInfo : public RenderSelectionInfoBase {
61public:
62 RenderSelectionInfo(RenderObject* o, bool clipToVisibleContent)
63 : RenderSelectionInfoBase(o)
64 , m_rect(o->needsLayout() ? IntRect() : o->selectionRectForRepaint(m_repaintContainer, clipToVisibleContent))
65 {
66 }
67
68 void repaint()
69 {
70 m_object->repaintUsingContainer(m_repaintContainer, m_rect);
71 }
72
73 IntRect rect() const { return m_rect; }
74
75private:
76 IntRect m_rect; // relative to repaint container
77};
78
79
80// This struct is used when the selection changes to cache the old and new state of the selection for each RenderBlock.
81class RenderBlockSelectionInfo : public RenderSelectionInfoBase {
82public:
83 RenderBlockSelectionInfo(RenderBlock* b)
84 : RenderSelectionInfoBase(b)
85 , m_rects(b->needsLayout() ? GapRects() : block()->selectionGapRectsForRepaint(m_repaintContainer))
86 {
87 }
88
89 void repaint()
90 {
91 m_object->repaintUsingContainer(m_repaintContainer, m_rects);
92 }
93
94 RenderBlock* block() const { return toRenderBlock(m_object); }
95 GapRects rects() const { return m_rects; }
96
97private:
98 GapRects m_rects; // relative to repaint container
99};
100
101} // namespace WebCore
102
103
eric@webkit.org83cb6022010-06-23 06:44:40 +0000104#endif // RenderSelectionInfo_h