Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Unified Diff: third_party/WebKit/Source/core/editing/LayoutSelection.h

Issue 2913773002: [WIP][b:eae_mywip_paint] Paint Selection NG.
Patch Set: update Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 272d016a9fab7f6db869dfee5159145c5c935ff4..33fea24f5b6c143560056331b43e67f2d287230c 100644
--- a/third_party/WebKit/Source/core/editing/LayoutSelection.h
+++ b/third_party/WebKit/Source/core/editing/LayoutSelection.h
@@ -24,11 +24,14 @@
#include "core/editing/Position.h"
#include "core/editing/VisibleSelection.h"
+#include "core/layout/LayoutText.h"
+
#include "platform/heap/Handle.h"
namespace blink {
class FrameSelection;
+class LayoutNGBlockFlow;
// This class represents a selection range in layout tree for painting and
// paint invalidation.
@@ -40,28 +43,54 @@ class FrameSelection;
// 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();
-
+class SelectionPaintRange : public GarbageCollected<SelectionPaintRange> {
public:
- SelectionPaintRange() = default;
+ SelectionPaintRange() = delete;
SelectionPaintRange(LayoutObject* start_layout_object,
int start_offset,
LayoutObject* end_layout_object,
int end_offset);
+ SelectionPaintRange(Node* start_node,
+ LayoutObject* start_layout_object,
+ int start_offset,
+ Node* end_node,
+ LayoutObject* end_layout_object,
+ int end_offset)
+ : SelectionPaintRange(start_layout_object,
+ start_offset,
+ end_layout_object,
+ end_offset) {
+ start_node_ = start_node;
+ end_node_ = end_node;
+ }
+ SelectionPaintRange(const SelectionPaintRange& other)
+ : start_node_(other.start_node_),
+ start_layout_object_(other.start_layout_object_),
+ start_offset_(other.start_offset_),
+ end_node_(other.end_node_),
+ end_layout_object_(other.end_layout_object_),
+ end_offset_(other.end_offset_) {}
bool operator==(const SelectionPaintRange& other) const;
+ Node* StartNode() const { return start_node_; }
LayoutObject* StartLayoutObject() const;
int StartOffset() const;
+ Node* EndNode() const { return end_node_; }
LayoutObject* EndLayoutObject() const;
int EndOffset() const;
- bool IsNull() const { return !start_layout_object_; }
+ DEFINE_INLINE_TRACE() {
+ visitor->Trace(start_node_);
+ visitor->Trace(end_node_);
+ }
private:
+ // TODO(yoichio): start/end_node_ is only used if *_layout_object_ is NG.
+ Member<Node> start_node_;
LayoutObject* start_layout_object_ = nullptr;
int start_offset_ = -1;
+ Member<Node> end_node_;
LayoutObject* end_layout_object_ = nullptr;
int end_offset_ = -1;
};
@@ -80,6 +109,12 @@ class LayoutSelection final : public GarbageCollected<LayoutSelection> {
void InvalidatePaintForSelection();
void ClearSelection();
+ // TODO(yoichio): Returns pair<Union<NGOffset, DOMOffset>, Union<NGOffset,
+ // DOMOffset>>. Content of the Union is decided by if
+ // paint_range_.Start(End)LayoutObject() is NG or not. LayoutObject painter
+ // calliing this should know if the LayoutObject is NG and
+ // LayoutObject.SelectionState because SelectionStartEnd().first doesn't make
+ // sense for SelectionState::kEnd LayoutObject.
std::pair<int, int> SelectionStartEnd();
void OnDocumentShutdown();
@@ -91,7 +126,41 @@ class LayoutSelection final : public GarbageCollected<LayoutSelection> {
Member<FrameSelection> frame_selection_;
bool has_pending_selection_ : 1;
- SelectionPaintRange paint_range_;
+ Member<SelectionPaintRange> paint_range_;
+};
+
+class CORE_EXPORT NGTextOffsetMap : public GarbageCollected<NGTextOffsetMap> {
+ public:
+ class Builder;
+ NGTextOffsetMap() = default;
+ NGTextOffsetMap(const NGTextOffsetMap&& other) {
+ node_to_offset_map_ = std::move(other.node_to_offset_map_);
+ }
+
+ static NGTextOffsetMap Create(const LayoutNGBlockFlow&);
+
+ Optional<int> Get(Node*, int) const;
+
+ DEFINE_INLINE_TRACE() { visitor->Trace(node_to_offset_map_); }
+
+ private:
+ HeapHashMap<std::pair<WeakMember<Node>, int>, int> node_to_offset_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(NGTextOffsetMap);
+};
+
+class CORE_EXPORT NGTextOffsetMap::Builder {
+ STACK_ALLOCATED();
+
+ public:
+ explicit Builder();
+ void Add(Node*, int dom_offset, int layout_offset);
+ NGTextOffsetMap Build();
+
+ private:
+ Member<NGTextOffsetMap> offset_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(Builder);
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698