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

Side by Side Diff: third_party/WebKit/Source/core/editing/LayoutSelection.h

Issue 2901263002: Introduce SelectionPaintRange in LayoutSelection (Closed)
Patch Set: Make SelectionPaintRange immutable 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 unified diff | Download patch
OLDNEW
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
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 class SelectionPaintRange {
34 DISALLOW_NEW();
35
36 public:
37 SelectionPaintRange() = default;
38 SelectionPaintRange(LayoutObject* start_layout_object,
39 int start_offset,
40 LayoutObject* end_layout_object,
41 int end_offset);
42
43 bool operator==(const SelectionPaintRange& other) const;
44 bool operator!=(const SelectionPaintRange& other) const;
45
46 LayoutObject* StartLayoutObject() const { return start_layout_object_; }
yosin_UTC9 2017/05/24 09:31:18 Let's have |IsNull()| and we should not make gette
yoichio 2017/05/25 02:00:36 Done.
47 int StartOffset() const { return start_offset_; }
48 LayoutObject* EndLayoutObject() const { return end_layout_object_; }
49 int EndOffset() const { return end_offset_; }
50
51 private:
52 // The current selection represented as 2 boundaries.
53 // Selection boundaries are represented in LayoutView by a tuple
54 // (LayoutObject, DOM node offset).
55 // See http://www.w3.org/TR/dom/#range for more information.
56 //
57 // |start_layout_object_| and |end_layout_object_| are only valid for
58 // |Text| node without 'transform' or 'first-letter'.
59 //
60 // Those are used for selection painting and paint invalidation upon
61 // selection change.
62 // TODO(editing-dev): Clarify the meaning of |start_offset_| and
63 // |end_offset_|. editing/ passes them as offsets in the DOM tree but layout
64 // uses them as offset in the layout tree.
65 LayoutObject* start_layout_object_ = nullptr;
66 int start_offset_ = -1;
67 LayoutObject* end_layout_object_ = nullptr;
68 int end_offset_ = -1;
69 };
70
33 class LayoutSelection final : public GarbageCollected<LayoutSelection> { 71 class LayoutSelection final : public GarbageCollected<LayoutSelection> {
34 public: 72 public:
35 static LayoutSelection* Create(FrameSelection& frame_selection) { 73 static LayoutSelection* Create(FrameSelection& frame_selection) {
36 return new LayoutSelection(frame_selection); 74 return new LayoutSelection(frame_selection);
37 } 75 }
38 76
39 bool HasPendingSelection() const { return has_pending_selection_; } 77 bool HasPendingSelection() const { return has_pending_selection_; }
40 void SetHasPendingSelection() { has_pending_selection_ = true; } 78 void SetHasPendingSelection() { has_pending_selection_ = true; }
41 void Commit(); 79 void Commit();
42 80
43 IntRect SelectionBounds(); 81 IntRect SelectionBounds();
44 void InvalidatePaintForSelection(); 82 void InvalidatePaintForSelection();
45 enum SelectionPaintInvalidationMode { 83 enum SelectionPaintInvalidationMode {
46 kPaintInvalidationNewXOROld, 84 kPaintInvalidationNewXOROld,
47 kPaintInvalidationNewMinusOld 85 kPaintInvalidationNewMinusOld
48 }; 86 };
49 void SetSelection( 87 void SetSelection(
50 LayoutObject* start, 88 const SelectionPaintRange&,
51 int start_pos,
52 LayoutObject*,
53 int end_pos,
54 SelectionPaintInvalidationMode = kPaintInvalidationNewXOROld); 89 SelectionPaintInvalidationMode = kPaintInvalidationNewXOROld);
55 void ClearSelection(); 90 void ClearSelection();
56 std::pair<int, int> SelectionStartEnd(); 91 std::pair<int, int> SelectionStartEnd();
57 void OnDocumentShutdown(); 92 void OnDocumentShutdown();
58 93
59 DECLARE_TRACE(); 94 DECLARE_TRACE();
60 95
61 private: 96 private:
62 LayoutSelection(FrameSelection&); 97 LayoutSelection(FrameSelection&);
63 98
64 SelectionInFlatTree CalcVisibleSelection( 99 SelectionInFlatTree CalcVisibleSelection(
65 const VisibleSelectionInFlatTree&) const; 100 const VisibleSelectionInFlatTree&) const;
66 101
67 Member<FrameSelection> frame_selection_; 102 Member<FrameSelection> frame_selection_;
68 bool has_pending_selection_ : 1; 103 bool has_pending_selection_ : 1;
69 104
70 // The current selection represented as 2 boundaries. 105 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 }; 106 };
89 107
90 } // namespace blink 108 } // namespace blink
91 109
92 #endif 110 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698