1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/base/TextRange.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_a11y_TextRange_h__ 1.11 +#define mozilla_a11y_TextRange_h__ 1.12 + 1.13 +#include "mozilla/Move.h" 1.14 +#include "nsAutoPtr.h" 1.15 + 1.16 +namespace mozilla { 1.17 +namespace a11y { 1.18 + 1.19 +class Accessible; 1.20 +class HyperTextAccessible; 1.21 + 1.22 +/** 1.23 + * Represents a text range within the text control or document. 1.24 + */ 1.25 +class TextRange MOZ_FINAL 1.26 +{ 1.27 +public: 1.28 + TextRange(HyperTextAccessible* aRoot, 1.29 + Accessible* aStartContainer, int32_t aStartOffset, 1.30 + Accessible* aEndContainer, int32_t aEndOffset); 1.31 + TextRange() {} 1.32 + TextRange(TextRange&& aRange) : 1.33 + mRoot(Move(aRange.mRoot)), mStartContainer(Move(aRange.mStartContainer)), 1.34 + mEndContainer(Move(aRange.mEndContainer)), 1.35 + mStartOffset(aRange.mStartOffset), mEndOffset(aRange.mEndOffset) {} 1.36 + 1.37 + TextRange& operator= (TextRange&& aRange) 1.38 + { 1.39 + mRoot = Move(aRange.mRoot); 1.40 + mStartContainer = Move(aRange.mStartContainer); 1.41 + mEndContainer = Move(aRange.mEndContainer); 1.42 + mStartOffset = aRange.mStartOffset; 1.43 + mEndOffset = aRange.mEndOffset; 1.44 + return *this; 1.45 + } 1.46 + 1.47 + Accessible* StartContainer() const { return mStartContainer; } 1.48 + int32_t StartOffset() const { return mStartOffset; } 1.49 + Accessible* EndContainer() const { return mEndContainer; } 1.50 + int32_t EndOffset() const { return mEndOffset; } 1.51 + 1.52 + /** 1.53 + * Return text enclosed by the range. 1.54 + */ 1.55 + void Text(nsAString& aText) const; 1.56 + 1.57 + /** 1.58 + * Return true if this TextRange object represents an actual range of text. 1.59 + */ 1.60 + bool IsValid() const { return mRoot; } 1.61 + 1.62 +private: 1.63 + TextRange(const TextRange& aRange) MOZ_DELETE; 1.64 + TextRange& operator=(const TextRange& aRange) MOZ_DELETE; 1.65 + 1.66 + friend class HyperTextAccessible; 1.67 + friend class xpcAccessibleTextRange; 1.68 + 1.69 + void Set(HyperTextAccessible* aRoot, 1.70 + Accessible* aStartContainer, int32_t aStartOffset, 1.71 + Accessible* aEndContainer, int32_t aEndOffset); 1.72 + 1.73 + nsRefPtr<HyperTextAccessible> mRoot; 1.74 + nsRefPtr<Accessible> mStartContainer; 1.75 + nsRefPtr<Accessible> mEndContainer; 1.76 + int32_t mStartOffset; 1.77 + int32_t mEndOffset; 1.78 +}; 1.79 + 1.80 + 1.81 +} // namespace a11y 1.82 +} // namespace mozilla 1.83 + 1.84 +#endif