| Index: ui/accessibility/ax_range.h
|
| diff --git a/ui/accessibility/ax_range.h b/ui/accessibility/ax_range.h
|
| index 914f350d3a74d292ccaa90ca4531dc0c6c3739c5..4acbd893deab58bf71840a33adecb7470028faa8 100644
|
| --- a/ui/accessibility/ax_range.h
|
| +++ b/ui/accessibility/ax_range.h
|
| @@ -9,6 +9,8 @@
|
| #include <utility>
|
|
|
| #include "base/strings/string16.h"
|
| +#include "ui/accessibility/ax_export.h"
|
| +#include "ui/accessibility/ax_position.h"
|
|
|
| namespace ui {
|
|
|
| @@ -16,69 +18,29 @@ namespace ui {
|
| //
|
| // In order to avoid any confusion regarding whether a deep or a shallow copy is
|
| // being performed, this class can be moved but not copied.
|
| -template <class AXPositionType>
|
| -class AXRange {
|
| +class AX_EXPORT AXAbstractRange {
|
| public:
|
| - AXRange()
|
| - : anchor_(AXPositionType::CreateNullPosition()),
|
| - focus_(AXPositionType::CreateNullPosition()) {}
|
| -
|
| - AXRange(std::unique_ptr<AXPositionType> anchor,
|
| - std::unique_ptr<AXPositionType> focus) {
|
| - if (anchor) {
|
| - anchor_ = std::move(anchor);
|
| - } else {
|
| - anchor_ = AXPositionType::CreateNullPosition();
|
| - }
|
| - if (focus) {
|
| - focus_ = std::move(focus);
|
| - } else {
|
| - focus = AXPositionType::CreateNullPosition();
|
| - }
|
| - }
|
| -
|
| - AXRange(const AXRange& other) = delete;
|
| + AXAbstractRange(std::unique_ptr<AXPositionBase> anchor,
|
| + std::unique_ptr<AXPositionBase> focus);
|
| + AXAbstractRange(AXAbstractRange&& other);
|
|
|
| - AXRange(AXRange&& other) : AXRange() {
|
| - anchor_.swap(other.anchor_);
|
| - focus_.swap(other.focus_);
|
| - }
|
| + AXAbstractRange(const AXAbstractRange& other) = delete;
|
| + AXAbstractRange& operator=(const AXAbstractRange& other) = delete;
|
| + AXAbstractRange& operator=(AXAbstractRange&& other) = delete;
|
|
|
| - AXRange& operator=(const AXRange& other) = delete;
|
| -
|
| - AXRange& operator=(const AXRange&& other) {
|
| - if (this != other) {
|
| - anchor_ = AXPositionType::CreateNullPosition();
|
| - focus_ = AXPositionType::CreateNullPosition();
|
| - anchor_.swap(other.anchor_);
|
| - focus_.swap(other.focus_);
|
| - }
|
| - return *this;
|
| - }
|
| -
|
| - virtual ~AXRange() {}
|
| + ~AXAbstractRange();
|
|
|
| bool IsNull() const {
|
| return !anchor_ || !focus_ || anchor_->IsNullPosition() ||
|
| focus_->IsNullPosition();
|
| }
|
|
|
| - AXPositionType* anchor() const {
|
| - DCHECK(anchor_);
|
| - return anchor_.get();
|
| - }
|
| -
|
| - AXPositionType* focus() const {
|
| - DCHECK(focus_);
|
| - return focus_.get();
|
| - }
|
| -
|
| base::string16 GetText() const {
|
| base::string16 text;
|
| if (IsNull())
|
| return text;
|
|
|
| - std::unique_ptr<AXPositionType> start, end;
|
| + std::unique_ptr<AXPositionBase> start, end;
|
| if (*anchor_ < *focus_) {
|
| start = anchor_->AsLeafTextPosition();
|
| end = focus_->AsLeafTextPosition();
|
| @@ -106,9 +68,44 @@ class AXRange {
|
| return text.substr(0, text_length);
|
| }
|
|
|
| + AXPositionBase* anchor() const { return anchor_.get(); }
|
| + AXPositionBase* focus() const { return focus_.get(); }
|
| +
|
| + protected:
|
| + std::unique_ptr<AXPositionBase> anchor_;
|
| + std::unique_ptr<AXPositionBase> focus_;
|
| +};
|
| +
|
| +template <class AXPositionType>
|
| +class AXRange : public AXAbstractRange {
|
| + public:
|
| + AXRange() : AXAbstractRange(CreateNull(), CreateNull()) {}
|
| + AXRange(std::unique_ptr<AXPositionType> anchor,
|
| + std::unique_ptr<AXPositionType> focus)
|
| + : AXAbstractRange(anchor ? AsBase(std::move(anchor)) : CreateNull(),
|
| + focus ? AsBase(std::move(focus)) : CreateNull()) {}
|
| + AXRange(AXRange&& other) = default;
|
| +
|
| + AXRange(const AXRange& other) = delete;
|
| + AXRange& operator=(const AXRange& other) = delete;
|
| + AXRange& operator=(AXRange&& other) = delete;
|
| +
|
| + typename AXPositionType::ConcreteNodeType* GetAnchorNode() const {
|
| + return static_cast<AXPositionType*>(anchor_.get())->GetAnchor();
|
| + }
|
| + typename AXPositionType::ConcreteNodeType* GetFocusNode() const {
|
| + return static_cast<AXPositionType*>(focus_.get())->GetAnchor();
|
| + }
|
| +
|
| private:
|
| - std::unique_ptr<AXPositionType> anchor_;
|
| - std::unique_ptr<AXPositionType> focus_;
|
| + static std::unique_ptr<AXPositionBase> AsBase(
|
| + std::unique_ptr<AXPositionType> concrete) {
|
| + return base::WrapUnique<AXPositionBase>(concrete.release());
|
| + }
|
| +
|
| + static std::unique_ptr<AXPositionBase> CreateNull() {
|
| + return AsBase(AXPositionType::CreateConcreteNullPosition());
|
| + }
|
| };
|
|
|
| } // namespace ui
|
|
|