Index: third_party/WebKit/Source/core/editing/LayoutSelection.h |
diff --git a/third_party/WebKit/Source/core/editing/LayoutSelection.h b/third_party/WebKit/Source/core/editing/LayoutSelection.h |
index 17b7c6dc7f5b15a0e312cb984899cfd2868aed52..7005099327dad10716a60144cb4403e5f6933b65 100644 |
--- a/third_party/WebKit/Source/core/editing/LayoutSelection.h |
+++ b/third_party/WebKit/Source/core/editing/LayoutSelection.h |
@@ -30,6 +30,42 @@ namespace blink { |
class FrameSelection; |
+// This class represents a selection range in layout tree for painting and |
+// paint invalidation. |
+// The current selection to be painted is represented as 2 pairs of |
+// (LayoutObject, offset). |
+// 2 LayoutObjects are only valid for |Text| node without 'transform' or |
+// 'first-letter'. |
+// TODO(editing-dev): Clarify the meaning of "offset". |
+// editing/ passes them as offsets in the DOM tree but layout uses them as |
+// offset in the layout tree. This doesn't work in the cases of |
+// CSS first-letter or character transform. See crbug.com/17528. |
+class SelectionPaintRange { |
+ DISALLOW_NEW(); |
+ |
+ public: |
+ SelectionPaintRange() = default; |
+ SelectionPaintRange(LayoutObject* start_layout_object, |
+ int start_offset, |
+ LayoutObject* end_layout_object, |
+ int end_offset); |
+ |
+ bool operator==(const SelectionPaintRange& other) const; |
+ |
+ LayoutObject* StartLayoutObject() const; |
+ int StartOffset() const; |
+ LayoutObject* EndLayoutObject() const; |
+ int EndOffset() const; |
+ |
+ bool IsNull() const { return !start_layout_object_; } |
+ |
+ private: |
+ LayoutObject* start_layout_object_ = nullptr; |
+ int start_offset_ = -1; |
+ LayoutObject* end_layout_object_ = nullptr; |
+ int end_offset_ = -1; |
+}; |
+ |
class LayoutSelection final : public GarbageCollected<LayoutSelection> { |
public: |
static LayoutSelection* Create(FrameSelection& frame_selection) { |
@@ -47,10 +83,7 @@ class LayoutSelection final : public GarbageCollected<LayoutSelection> { |
kPaintInvalidationNewMinusOld |
}; |
void SetSelection( |
- LayoutObject* start, |
- int start_pos, |
- LayoutObject*, |
- int end_pos, |
+ const SelectionPaintRange&, |
SelectionPaintInvalidationMode = kPaintInvalidationNewXOROld); |
void ClearSelection(); |
std::pair<int, int> SelectionStartEnd(); |
@@ -67,24 +100,7 @@ class LayoutSelection final : public GarbageCollected<LayoutSelection> { |
Member<FrameSelection> frame_selection_; |
bool has_pending_selection_ : 1; |
- // The current selection represented as 2 boundaries. |
- // Selection boundaries are represented in LayoutView by a tuple |
- // (LayoutObject, DOM node offset). |
- // See http://www.w3.org/TR/dom/#range for more information. |
- // |
- // |m_selectionStartPos| and |m_selectionEndPos| are only valid for |
- // |Text| node without 'transform' or 'first-letter'. |
- // |
- // Those are used for selection painting and paint invalidation upon |
- // selection change. |
- LayoutObject* selection_start_; |
- LayoutObject* selection_end_; |
- |
- // TODO(yosin): Clarify the meaning of these variables. editing/ passes |
- // them as offsets in the DOM tree but layout uses them as offset in the |
- // layout tree. |
- int selection_start_pos_; |
- int selection_end_pos_; |
+ SelectionPaintRange paint_range_; |
}; |
} // namespace blink |