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