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

Unified Diff: third_party/WebKit/Source/modules/accessibility/AXRange.h

Issue 2745713002: WIP: Modified AXPosition to work with objects with both embedded object characters and text. (Closed)
Patch Set: Simplified and cleaned up selection code in Blink > Accessibility. 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/modules/accessibility/AXRange.h
diff --git a/third_party/WebKit/Source/modules/accessibility/AXRange.h b/third_party/WebKit/Source/modules/accessibility/AXRange.h
new file mode 100644
index 0000000000000000000000000000000000000000..80e1f56a011de7cf6d66d85ee80b9055a27d5d9a
--- /dev/null
+++ b/third_party/WebKit/Source/modules/accessibility/AXRange.h
@@ -0,0 +1,91 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef AXRange_h
+#define AXRange_h
+
+#include "core/editing/TextAffinity.h"
+#include "core/editing/VisibleSelection.h"
+
+namespace blink {
+
+class AXObject;
+
+class AXRange {
+ DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
+
+ public:
+ AXRange()
+ : anchor_object_(nullptr),
+ anchor_offset_(-1),
+ focus_object_(nullptr),
+ focus_offset_(-1),
+ affinity_(TextAffinity::kDownstream) {}
+
+ AXRange(AXObject* anchor_object,
+ int anchor_offset,
+ AXObject* focus_object,
+ int focus_offset,
+ TextAffinity affinity = TextAffinity::kDownstream)
+ : anchor_object_(anchor_object),
+ anchor_offset_(anchor_offset),
+ focus_object_(focus_object),
+ focus_offset_(focus_offset),
+ affinity_(affinity) {}
+
+ explicit AXRange(VisibleSelectionInFlatTree& selection);
+
+ ~AXRange() = default;
+
+ AXObject* AnchorObject() { return anchor_object_; }
+ void SetAnchorObject(AXObject* anchor_object) {
+ anchor_object_ = anchor_object;
+ }
+ int AnchorOffset() { return anchor_offset_; }
+ void SetAnchorOffset(int anchor_offset) { anchor_offset_ = anchor_offset; }
+
+ AXObject* FocusObject() { return focus_object_; }
+ void SetFocusObject(AXObject* focus_object) { focus_object_ = focus_object; }
+ int FocusOffset() { return focus_offset_; }
+ void SetFocusOffset(int focus_offset) { focus_offset_ = focus_offset; }
+
+ TextAffinity Affinity() { return affinity_; }
+ void SetAffinity(TextAffinity affinity) { affinity_ = affinity; }
+
+ bool IsValid() const;
+
+ // Determines if the range only refers to text offsets under the current
+ // object.
+ bool IsSimple() const {
+ return IsValid() && (anchor_object_ == focus_object_);
+ }
+
+ // In flat tree because AXObjects could be in the shadow DOM.
+ VisibleSelectionInFlatTree AsVisibleSelectionInFlatTree() const;
+
+ // Tries to set the selection to this range.
+ void Select();
+
+ private:
+ // The deepest descendant in which the range starts.
+ Persistent<AXObject> anchor_object_;
+ // The number of characters or child objects in the anchor object before the
+ // range starts.
+ int anchor_offset_;
+
+ // The deepest descendant in which the range ends.
+ Persistent<AXObject> focus_object_;
+ // The number of characters or child objects in the focus object before the
+ // range ends.
+ int focus_offset_;
+
+ // When the same character offset could correspond to two possible caret
+ // positions, upstream means it's on the previous line rather than the next
+ // line.
+ TextAffinity affinity_;
+};
+
+} // namespace blink
+
+#endif // AXRange_h

Powered by Google App Engine
This is Rietveld 408576698