| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef AXRange_h |
| 6 #define AXRange_h |
| 7 |
| 8 #include "core/editing/TextAffinity.h" |
| 9 #include "core/editing/VisibleSelection.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 class AXObject; |
| 14 |
| 15 class AXRange { |
| 16 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 17 |
| 18 public: |
| 19 AXRange() |
| 20 : anchor_object_(nullptr), |
| 21 anchor_offset_(-1), |
| 22 focus_object_(nullptr), |
| 23 focus_offset_(-1), |
| 24 affinity_(TextAffinity::kDownstream) {} |
| 25 |
| 26 AXRange(AXObject* anchor_object, |
| 27 int anchor_offset, |
| 28 AXObject* focus_object, |
| 29 int focus_offset, |
| 30 TextAffinity affinity = TextAffinity::kDownstream) |
| 31 : anchor_object_(anchor_object), |
| 32 anchor_offset_(anchor_offset), |
| 33 focus_object_(focus_object), |
| 34 focus_offset_(focus_offset), |
| 35 affinity_(affinity) {} |
| 36 |
| 37 explicit AXRange(VisibleSelectionInFlatTree& selection); |
| 38 |
| 39 ~AXRange() = default; |
| 40 |
| 41 AXObject* AnchorObject() { return anchor_object_; } |
| 42 void SetAnchorObject(AXObject* anchor_object) { |
| 43 anchor_object_ = anchor_object; |
| 44 } |
| 45 int AnchorOffset() { return anchor_offset_; } |
| 46 void SetAnchorOffset(int anchor_offset) { anchor_offset_ = anchor_offset; } |
| 47 |
| 48 AXObject* FocusObject() { return focus_object_; } |
| 49 void SetFocusObject(AXObject* focus_object) { focus_object_ = focus_object; } |
| 50 int FocusOffset() { return focus_offset_; } |
| 51 void SetFocusOffset(int focus_offset) { focus_offset_ = focus_offset; } |
| 52 |
| 53 TextAffinity Affinity() { return affinity_; } |
| 54 void SetAffinity(TextAffinity affinity) { affinity_ = affinity; } |
| 55 |
| 56 bool IsValid() const; |
| 57 |
| 58 // Determines if the range only refers to text offsets under the current |
| 59 // object. |
| 60 bool IsSimple() const { |
| 61 return IsValid() && (anchor_object_ == focus_object_); |
| 62 } |
| 63 |
| 64 // In flat tree because AXObjects could be in the shadow DOM. |
| 65 VisibleSelectionInFlatTree AsVisibleSelectionInFlatTree() const; |
| 66 |
| 67 // Tries to set the selection to this range. |
| 68 void Select(); |
| 69 |
| 70 private: |
| 71 // The deepest descendant in which the range starts. |
| 72 Persistent<AXObject> anchor_object_; |
| 73 // The number of characters or child objects in the anchor object before the |
| 74 // range starts. |
| 75 int anchor_offset_; |
| 76 |
| 77 // The deepest descendant in which the range ends. |
| 78 Persistent<AXObject> focus_object_; |
| 79 // The number of characters or child objects in the focus object before the |
| 80 // range ends. |
| 81 int focus_offset_; |
| 82 |
| 83 // When the same character offset could correspond to two possible caret |
| 84 // positions, upstream means it's on the previous line rather than the next |
| 85 // line. |
| 86 TextAffinity affinity_; |
| 87 }; |
| 88 |
| 89 } // namespace blink |
| 90 |
| 91 #endif // AXRange_h |
| OLD | NEW |