OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2006 Apple Computer, Inc. | 3 * Copyright (C) 2006 Apple Computer, Inc. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 12 matching lines...) Expand all Loading... |
23 #define LayoutSelection_h | 23 #define LayoutSelection_h |
24 | 24 |
25 #include "core/editing/Position.h" | 25 #include "core/editing/Position.h" |
26 #include "core/editing/VisibleSelection.h" | 26 #include "core/editing/VisibleSelection.h" |
27 #include "platform/heap/Handle.h" | 27 #include "platform/heap/Handle.h" |
28 | 28 |
29 namespace blink { | 29 namespace blink { |
30 | 30 |
31 class FrameSelection; | 31 class FrameSelection; |
32 | 32 |
| 33 // This class represents a selection range in layout tree for painting and |
| 34 // paint invalidation. |
| 35 // The current selection to be painted is represented as 2 pairs of |
| 36 // (LayoutObject, offset). |
| 37 // 2 LayoutObjects are only valid for |Text| node without 'transform' or |
| 38 // 'first-letter'. |
| 39 // TODO(editing-dev): Clarify the meaning of "offset". |
| 40 // editing/ passes them as offsets in the DOM tree but layout uses them as |
| 41 // offset in the layout tree. This doesn't work in the cases of |
| 42 // CSS first-letter or character transform. See crbug.com/17528. |
| 43 class SelectionPaintRange { |
| 44 DISALLOW_NEW(); |
| 45 |
| 46 public: |
| 47 SelectionPaintRange() = default; |
| 48 SelectionPaintRange(LayoutObject* start_layout_object, |
| 49 int start_offset, |
| 50 LayoutObject* end_layout_object, |
| 51 int end_offset); |
| 52 |
| 53 bool operator==(const SelectionPaintRange& other) const; |
| 54 |
| 55 LayoutObject* StartLayoutObject() const; |
| 56 int StartOffset() const; |
| 57 LayoutObject* EndLayoutObject() const; |
| 58 int EndOffset() const; |
| 59 |
| 60 bool IsNull() const { return !start_layout_object_; } |
| 61 |
| 62 private: |
| 63 LayoutObject* start_layout_object_ = nullptr; |
| 64 int start_offset_ = -1; |
| 65 LayoutObject* end_layout_object_ = nullptr; |
| 66 int end_offset_ = -1; |
| 67 }; |
| 68 |
33 class LayoutSelection final : public GarbageCollected<LayoutSelection> { | 69 class LayoutSelection final : public GarbageCollected<LayoutSelection> { |
34 public: | 70 public: |
35 static LayoutSelection* Create(FrameSelection& frame_selection) { | 71 static LayoutSelection* Create(FrameSelection& frame_selection) { |
36 return new LayoutSelection(frame_selection); | 72 return new LayoutSelection(frame_selection); |
37 } | 73 } |
38 | 74 |
39 bool HasPendingSelection() const { return has_pending_selection_; } | 75 bool HasPendingSelection() const { return has_pending_selection_; } |
40 void SetHasPendingSelection() { has_pending_selection_ = true; } | 76 void SetHasPendingSelection() { has_pending_selection_ = true; } |
41 void Commit(); | 77 void Commit(); |
42 | 78 |
43 IntRect SelectionBounds(); | 79 IntRect SelectionBounds(); |
44 void InvalidatePaintForSelection(); | 80 void InvalidatePaintForSelection(); |
45 enum SelectionPaintInvalidationMode { | 81 enum SelectionPaintInvalidationMode { |
46 kPaintInvalidationNewXOROld, | 82 kPaintInvalidationNewXOROld, |
47 kPaintInvalidationNewMinusOld | 83 kPaintInvalidationNewMinusOld |
48 }; | 84 }; |
49 void SetSelection( | 85 void SetSelection( |
50 LayoutObject* start, | 86 const SelectionPaintRange&, |
51 int start_pos, | |
52 LayoutObject*, | |
53 int end_pos, | |
54 SelectionPaintInvalidationMode = kPaintInvalidationNewXOROld); | 87 SelectionPaintInvalidationMode = kPaintInvalidationNewXOROld); |
55 void ClearSelection(); | 88 void ClearSelection(); |
56 std::pair<int, int> SelectionStartEnd(); | 89 std::pair<int, int> SelectionStartEnd(); |
57 void OnDocumentShutdown(); | 90 void OnDocumentShutdown(); |
58 | 91 |
59 DECLARE_TRACE(); | 92 DECLARE_TRACE(); |
60 | 93 |
61 private: | 94 private: |
62 LayoutSelection(FrameSelection&); | 95 LayoutSelection(FrameSelection&); |
63 | 96 |
64 SelectionInFlatTree CalcVisibleSelection( | 97 SelectionInFlatTree CalcVisibleSelection( |
65 const VisibleSelectionInFlatTree&) const; | 98 const VisibleSelectionInFlatTree&) const; |
66 | 99 |
67 Member<FrameSelection> frame_selection_; | 100 Member<FrameSelection> frame_selection_; |
68 bool has_pending_selection_ : 1; | 101 bool has_pending_selection_ : 1; |
69 | 102 |
70 // The current selection represented as 2 boundaries. | 103 SelectionPaintRange paint_range_; |
71 // Selection boundaries are represented in LayoutView by a tuple | |
72 // (LayoutObject, DOM node offset). | |
73 // See http://www.w3.org/TR/dom/#range for more information. | |
74 // | |
75 // |m_selectionStartPos| and |m_selectionEndPos| are only valid for | |
76 // |Text| node without 'transform' or 'first-letter'. | |
77 // | |
78 // Those are used for selection painting and paint invalidation upon | |
79 // selection change. | |
80 LayoutObject* selection_start_; | |
81 LayoutObject* selection_end_; | |
82 | |
83 // TODO(yosin): Clarify the meaning of these variables. editing/ passes | |
84 // them as offsets in the DOM tree but layout uses them as offset in the | |
85 // layout tree. | |
86 int selection_start_pos_; | |
87 int selection_end_pos_; | |
88 }; | 104 }; |
89 | 105 |
90 } // namespace blink | 106 } // namespace blink |
91 | 107 |
92 #endif | 108 #endif |
OLD | NEW |