simon.fraser@apple.com | e1e3f8f | 2009-02-04 02:41:38 +0000 | [diff] [blame] | 1 | /* |
| 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.org | 83cb602 | 2010-06-23 06:44:40 +0000 | [diff] [blame] | 25 | #ifndef RenderSelectionInfo_h |
| 26 | #define RenderSelectionInfo_h |
simon.fraser@apple.com | e1e3f8f | 2009-02-04 02:41:38 +0000 | [diff] [blame] | 27 | |
| 28 | #include "IntRect.h" |
| 29 | #include "RenderBox.h" |
| 30 | |
| 31 | namespace WebCore { |
| 32 | |
ossy@webkit.org | 95c1bc4 | 2011-01-20 16:30:54 +0000 | [diff] [blame] | 33 | class RenderSelectionInfoBase { |
| 34 | WTF_MAKE_NONCOPYABLE(RenderSelectionInfoBase); WTF_MAKE_FAST_ALLOCATED; |
simon.fraser@apple.com | e1e3f8f | 2009-02-04 02:41:38 +0000 | [diff] [blame] | 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->containerForRepaint()) |
| 46 | , m_state(o->selectionState()) |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | RenderObject* object() const { return m_object; } |
hyatt@apple.com | 80ab6e9 | 2009-02-05 17:24:00 +0000 | [diff] [blame] | 51 | RenderBoxModelObject* repaintContainer() const { return m_repaintContainer; } |
simon.fraser@apple.com | e1e3f8f | 2009-02-04 02:41:38 +0000 | [diff] [blame] | 52 | RenderObject::SelectionState state() const { return m_state; } |
| 53 | |
| 54 | protected: |
| 55 | RenderObject* m_object; |
hyatt@apple.com | 80ab6e9 | 2009-02-05 17:24:00 +0000 | [diff] [blame] | 56 | RenderBoxModelObject* m_repaintContainer; |
simon.fraser@apple.com | e1e3f8f | 2009-02-04 02:41:38 +0000 | [diff] [blame] | 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 | , m_rect(o->needsLayout() ? IntRect() : o->selectionRectForRepaint(m_repaintContainer, clipToVisibleContent)) |
| 66 | { |
| 67 | } |
| 68 | |
| 69 | void repaint() |
| 70 | { |
| 71 | m_object->repaintUsingContainer(m_repaintContainer, m_rect); |
| 72 | } |
| 73 | |
| 74 | IntRect rect() const { return m_rect; } |
| 75 | |
| 76 | private: |
| 77 | IntRect m_rect; // relative to repaint container |
| 78 | }; |
| 79 | |
| 80 | |
| 81 | // This struct is used when the selection changes to cache the old and new state of the selection for each RenderBlock. |
| 82 | class RenderBlockSelectionInfo : public RenderSelectionInfoBase { |
| 83 | public: |
| 84 | RenderBlockSelectionInfo(RenderBlock* b) |
| 85 | : RenderSelectionInfoBase(b) |
| 86 | , m_rects(b->needsLayout() ? GapRects() : block()->selectionGapRectsForRepaint(m_repaintContainer)) |
| 87 | { |
| 88 | } |
| 89 | |
| 90 | void repaint() |
| 91 | { |
| 92 | m_object->repaintUsingContainer(m_repaintContainer, m_rects); |
| 93 | } |
| 94 | |
| 95 | RenderBlock* block() const { return toRenderBlock(m_object); } |
| 96 | GapRects rects() const { return m_rects; } |
| 97 | |
| 98 | private: |
| 99 | GapRects m_rects; // relative to repaint container |
| 100 | }; |
| 101 | |
| 102 | } // namespace WebCore |
| 103 | |
| 104 | |
eric@webkit.org | 83cb602 | 2010-06-23 06:44:40 +0000 | [diff] [blame] | 105 | #endif // RenderSelectionInfo_h |