| 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, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
| 16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
| 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
| 19 * | 19 * |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 #ifndef LayoutSelection_h | 22 #ifndef LayoutSelection_h |
| 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 "core/layout/LayoutText.h" |
| 28 |
| 27 #include "platform/heap/Handle.h" | 29 #include "platform/heap/Handle.h" |
| 28 | 30 |
| 29 namespace blink { | 31 namespace blink { |
| 30 | 32 |
| 31 class FrameSelection; | 33 class FrameSelection; |
| 34 class LayoutNGBlockFlow; |
| 32 | 35 |
| 33 // This class represents a selection range in layout tree for painting and | 36 // This class represents a selection range in layout tree for painting and |
| 34 // paint invalidation. | 37 // paint invalidation. |
| 35 // The current selection to be painted is represented as 2 pairs of | 38 // The current selection to be painted is represented as 2 pairs of |
| 36 // (LayoutObject, offset). | 39 // (LayoutObject, offset). |
| 37 // 2 LayoutObjects are only valid for |Text| node without 'transform' or | 40 // 2 LayoutObjects are only valid for |Text| node without 'transform' or |
| 38 // 'first-letter'. | 41 // 'first-letter'. |
| 39 // TODO(editing-dev): Clarify the meaning of "offset". | 42 // TODO(editing-dev): Clarify the meaning of "offset". |
| 40 // editing/ passes them as offsets in the DOM tree but layout uses them as | 43 // 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 | 44 // offset in the layout tree. This doesn't work in the cases of |
| 42 // CSS first-letter or character transform. See crbug.com/17528. | 45 // CSS first-letter or character transform. See crbug.com/17528. |
| 43 class SelectionPaintRange { | 46 class SelectionPaintRange : public GarbageCollected<SelectionPaintRange> { |
| 44 DISALLOW_NEW(); | |
| 45 | |
| 46 public: | 47 public: |
| 47 SelectionPaintRange() = default; | 48 SelectionPaintRange() = delete; |
| 48 SelectionPaintRange(LayoutObject* start_layout_object, | 49 SelectionPaintRange(LayoutObject* start_layout_object, |
| 49 int start_offset, | 50 int start_offset, |
| 50 LayoutObject* end_layout_object, | 51 LayoutObject* end_layout_object, |
| 51 int end_offset); | 52 int end_offset); |
| 53 SelectionPaintRange(Node* start_node, |
| 54 LayoutObject* start_layout_object, |
| 55 int start_offset, |
| 56 Node* end_node, |
| 57 LayoutObject* end_layout_object, |
| 58 int end_offset) |
| 59 : SelectionPaintRange(start_layout_object, |
| 60 start_offset, |
| 61 end_layout_object, |
| 62 end_offset) { |
| 63 start_node_ = start_node; |
| 64 end_node_ = end_node; |
| 65 } |
| 66 SelectionPaintRange(const SelectionPaintRange& other) |
| 67 : start_node_(other.start_node_), |
| 68 start_layout_object_(other.start_layout_object_), |
| 69 start_offset_(other.start_offset_), |
| 70 end_node_(other.end_node_), |
| 71 end_layout_object_(other.end_layout_object_), |
| 72 end_offset_(other.end_offset_) {} |
| 52 | 73 |
| 53 bool operator==(const SelectionPaintRange& other) const; | 74 bool operator==(const SelectionPaintRange& other) const; |
| 54 | 75 |
| 76 Node* StartNode() const { return start_node_; } |
| 55 LayoutObject* StartLayoutObject() const; | 77 LayoutObject* StartLayoutObject() const; |
| 56 int StartOffset() const; | 78 int StartOffset() const; |
| 79 Node* EndNode() const { return end_node_; } |
| 57 LayoutObject* EndLayoutObject() const; | 80 LayoutObject* EndLayoutObject() const; |
| 58 int EndOffset() const; | 81 int EndOffset() const; |
| 59 | 82 |
| 60 bool IsNull() const { return !start_layout_object_; } | 83 DEFINE_INLINE_TRACE() { |
| 84 visitor->Trace(start_node_); |
| 85 visitor->Trace(end_node_); |
| 86 } |
| 61 | 87 |
| 62 private: | 88 private: |
| 89 // TODO(yoichio): start/end_node_ is only used if *_layout_object_ is NG. |
| 90 Member<Node> start_node_; |
| 63 LayoutObject* start_layout_object_ = nullptr; | 91 LayoutObject* start_layout_object_ = nullptr; |
| 64 int start_offset_ = -1; | 92 int start_offset_ = -1; |
| 93 Member<Node> end_node_; |
| 65 LayoutObject* end_layout_object_ = nullptr; | 94 LayoutObject* end_layout_object_ = nullptr; |
| 66 int end_offset_ = -1; | 95 int end_offset_ = -1; |
| 67 }; | 96 }; |
| 68 | 97 |
| 69 class LayoutSelection final : public GarbageCollected<LayoutSelection> { | 98 class LayoutSelection final : public GarbageCollected<LayoutSelection> { |
| 70 public: | 99 public: |
| 71 static LayoutSelection* Create(FrameSelection& frame_selection) { | 100 static LayoutSelection* Create(FrameSelection& frame_selection) { |
| 72 return new LayoutSelection(frame_selection); | 101 return new LayoutSelection(frame_selection); |
| 73 } | 102 } |
| 74 | 103 |
| 75 bool HasPendingSelection() const { return has_pending_selection_; } | 104 bool HasPendingSelection() const { return has_pending_selection_; } |
| 76 void SetHasPendingSelection() { has_pending_selection_ = true; } | 105 void SetHasPendingSelection() { has_pending_selection_ = true; } |
| 77 void Commit(); | 106 void Commit(); |
| 78 | 107 |
| 79 IntRect SelectionBounds(); | 108 IntRect SelectionBounds(); |
| 80 void InvalidatePaintForSelection(); | 109 void InvalidatePaintForSelection(); |
| 81 | 110 |
| 82 void ClearSelection(); | 111 void ClearSelection(); |
| 112 // TODO(yoichio): Returns pair<Union<NGOffset, DOMOffset>, Union<NGOffset, |
| 113 // DOMOffset>>. Content of the Union is decided by if |
| 114 // paint_range_.Start(End)LayoutObject() is NG or not. LayoutObject painter |
| 115 // calliing this should know if the LayoutObject is NG and |
| 116 // LayoutObject.SelectionState because SelectionStartEnd().first doesn't make |
| 117 // sense for SelectionState::kEnd LayoutObject. |
| 83 std::pair<int, int> SelectionStartEnd(); | 118 std::pair<int, int> SelectionStartEnd(); |
| 84 void OnDocumentShutdown(); | 119 void OnDocumentShutdown(); |
| 85 | 120 |
| 86 DECLARE_TRACE(); | 121 DECLARE_TRACE(); |
| 87 | 122 |
| 88 private: | 123 private: |
| 89 LayoutSelection(FrameSelection&); | 124 LayoutSelection(FrameSelection&); |
| 90 | 125 |
| 91 Member<FrameSelection> frame_selection_; | 126 Member<FrameSelection> frame_selection_; |
| 92 bool has_pending_selection_ : 1; | 127 bool has_pending_selection_ : 1; |
| 93 | 128 |
| 94 SelectionPaintRange paint_range_; | 129 Member<SelectionPaintRange> paint_range_; |
| 130 }; |
| 131 |
| 132 class CORE_EXPORT NGTextOffsetMap : public GarbageCollected<NGTextOffsetMap> { |
| 133 public: |
| 134 class Builder; |
| 135 NGTextOffsetMap() = default; |
| 136 NGTextOffsetMap(const NGTextOffsetMap&& other) { |
| 137 node_to_offset_map_ = std::move(other.node_to_offset_map_); |
| 138 } |
| 139 |
| 140 static NGTextOffsetMap Create(const LayoutNGBlockFlow&); |
| 141 |
| 142 Optional<int> Get(Node*, int) const; |
| 143 |
| 144 DEFINE_INLINE_TRACE() { visitor->Trace(node_to_offset_map_); } |
| 145 |
| 146 private: |
| 147 HeapHashMap<std::pair<WeakMember<Node>, int>, int> node_to_offset_map_; |
| 148 |
| 149 DISALLOW_COPY_AND_ASSIGN(NGTextOffsetMap); |
| 150 }; |
| 151 |
| 152 class CORE_EXPORT NGTextOffsetMap::Builder { |
| 153 STACK_ALLOCATED(); |
| 154 |
| 155 public: |
| 156 explicit Builder(); |
| 157 void Add(Node*, int dom_offset, int layout_offset); |
| 158 NGTextOffsetMap Build(); |
| 159 |
| 160 private: |
| 161 Member<NGTextOffsetMap> offset_map_; |
| 162 |
| 163 DISALLOW_COPY_AND_ASSIGN(Builder); |
| 95 }; | 164 }; |
| 96 | 165 |
| 97 } // namespace blink | 166 } // namespace blink |
| 98 | 167 |
| 99 #endif | 168 #endif |
| OLD | NEW |