tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

GeckoTextMarker.h (3490B)


      1 /* clang-format off */
      2 /* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      3 /* clang-format on */
      4 /* vim: set ts=2 et sw=2 tw=80: */
      5 /* This Source Code Form is subject to the terms of the Mozilla Public
      6 * License, v. 2.0. If a copy of the MPL was not distributed with this
      7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      8 
      9 #ifndef _GeckoTextMarker_H_
     10 #define _GeckoTextMarker_H_
     11 
     12 #include <ApplicationServices/ApplicationServices.h>
     13 #include <Foundation/Foundation.h>
     14 
     15 #include "TextLeafRange.h"
     16 
     17 namespace mozilla {
     18 namespace a11y {
     19 
     20 class Accessible;
     21 class GeckoTextMarkerRange;
     22 
     23 class GeckoTextMarker final {
     24 public:
     25  GeckoTextMarker(Accessible* aAcc, int32_t aOffset);
     26 
     27  explicit GeckoTextMarker(const TextLeafPoint& aTextLeafPoint)
     28      : mPoint(aTextLeafPoint) {}
     29 
     30  GeckoTextMarker() : mPoint() {}
     31 
     32  static GeckoTextMarker MarkerFromAXTextMarker(Accessible* aDoc,
     33                                                AXTextMarkerRef aTextMarker);
     34 
     35  static GeckoTextMarker MarkerFromIndex(Accessible* aRoot, int32_t aIndex);
     36 
     37  AXTextMarkerRef CreateAXTextMarker();
     38 
     39  bool Next();
     40 
     41  bool Previous();
     42 
     43  GeckoTextMarkerRange LeftWordRange() const;
     44 
     45  GeckoTextMarkerRange RightWordRange() const;
     46 
     47  GeckoTextMarkerRange LineRange() const;
     48 
     49  GeckoTextMarkerRange LeftLineRange() const;
     50 
     51  GeckoTextMarkerRange RightLineRange() const;
     52 
     53  GeckoTextMarkerRange ParagraphRange() const;
     54 
     55  GeckoTextMarkerRange StyleRange() const;
     56 
     57  int32_t& Offset() { return mPoint.mOffset; }
     58 
     59  Accessible* Leaf();
     60 
     61  Accessible* Acc() const { return mPoint.mAcc; }
     62 
     63  bool IsValid() const { return !!mPoint; };
     64 
     65  bool operator<(const GeckoTextMarker& aOther) const {
     66    return mPoint < aOther.mPoint;
     67  }
     68 
     69  bool operator==(const GeckoTextMarker& aOther) const {
     70    return mPoint == aOther.mPoint;
     71  }
     72 
     73  TextLeafPoint mPoint;
     74 };
     75 
     76 class GeckoTextMarkerRange final {
     77 public:
     78  GeckoTextMarkerRange(const GeckoTextMarker& aStart,
     79                       const GeckoTextMarker& aEnd)
     80      : mRange(aStart.mPoint, aEnd.mPoint) {}
     81 
     82  GeckoTextMarkerRange(const TextLeafPoint& aStart, const TextLeafPoint& aEnd)
     83      : mRange(aStart, aEnd) {}
     84 
     85  GeckoTextMarkerRange() {}
     86 
     87  explicit GeckoTextMarkerRange(Accessible* aAccessible);
     88 
     89  static GeckoTextMarkerRange MarkerRangeFromAXTextMarkerRange(
     90      Accessible* aDoc, AXTextMarkerRangeRef aTextMarkerRange);
     91 
     92  AXTextMarkerRangeRef CreateAXTextMarkerRange();
     93 
     94  bool IsValid() const { return !!mRange.Start() && !!mRange.End(); };
     95 
     96  GeckoTextMarker Start() { return GeckoTextMarker(mRange.Start()); }
     97 
     98  GeckoTextMarker End() { return GeckoTextMarker(mRange.End()); }
     99 
    100  /**
    101   * Return text enclosed by the range.
    102   */
    103  NSString* Text() const;
    104 
    105  /**
    106   * Return the attributed text enclosed by the range.
    107   */
    108  NSAttributedString* AttributedText() const;
    109 
    110  /**
    111   * Return length of characters enclosed by the range.
    112   */
    113  int32_t Length() const;
    114 
    115  /**
    116   * Return screen bounds of range.
    117   */
    118  NSValue* Bounds() const;
    119 
    120  /**
    121   * Set the current range as the DOM selection.
    122   */
    123  MOZ_CAN_RUN_SCRIPT_BOUNDARY void Select() const;
    124 
    125  /**
    126   * Crops the range if it overlaps the given accessible element boundaries.
    127   * Return true if successfully cropped. false if the range does not intersect
    128   * with the container.
    129   */
    130  bool Crop(Accessible* aContainer) { return mRange.Crop(aContainer); }
    131 
    132  TextLeafRange mRange;
    133 };
    134 
    135 }  // namespace a11y
    136 }  // namespace mozilla
    137 
    138 #endif