Commit a479c8f1 authored by Eitan Isaacson's avatar Eitan Isaacson
Browse files

Bug 1713050 - P2: Add granularity to a11y caret move events. r=morgan

parent d4418e93
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -127,11 +127,13 @@ AccShowEvent::AccShowEvent(LocalAccessible* aTarget)

AccTextSelChangeEvent::AccTextSelChangeEvent(HyperTextAccessible* aTarget,
                                             dom::Selection* aSelection,
                                             int32_t aReason)
                                             int32_t aReason,
                                             int32_t aGranularity)
    : AccEvent(nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED, aTarget,
               eAutoDetect, eCoalesceTextSelChange),
      mSel(aSelection),
      mReason(aReason) {}
      mReason(aReason),
      mGranularity(aGranularity) {}

AccTextSelChangeEvent::~AccTextSelChangeEvent() {}

@@ -246,7 +248,8 @@ already_AddRefed<nsIAccessibleEvent> a11y::MakeXPCEvent(AccEvent* aEvent) {
    AccCaretMoveEvent* cm = downcast_accEvent(aEvent);
    xpEvent = new xpcAccCaretMoveEvent(
        type, ToXPC(acc), ToXPCDocument(doc), node, fromUser,
        cm->GetCaretOffset(), cm->IsSelectionCollapsed(), cm->IsAtEndOfLine());
        cm->GetCaretOffset(), cm->IsSelectionCollapsed(), cm->IsAtEndOfLine(),
        cm->GetGranularity());
    return xpEvent.forget();
  }

+11 −2
Original line number Diff line number Diff line
@@ -348,12 +348,14 @@ class AccCaretMoveEvent : public AccEvent {
 public:
  AccCaretMoveEvent(LocalAccessible* aAccessible, int32_t aCaretOffset,
                    bool aIsSelectionCollapsed, bool aIsAtEndOfLine,
                    int32_t aGranularity,
                    EIsFromUserInput aIsFromUserInput = eAutoDetect)
      : AccEvent(::nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED, aAccessible,
                 aIsFromUserInput),
        mCaretOffset(aCaretOffset),
        mIsSelectionCollapsed(aIsSelectionCollapsed),
        mIsAtEndOfLine(aIsAtEndOfLine) {}
        mIsAtEndOfLine(aIsAtEndOfLine),
        mGranularity(aGranularity) {}
  virtual ~AccCaretMoveEvent() {}

  // AccEvent
@@ -368,11 +370,14 @@ class AccCaretMoveEvent : public AccEvent {
  bool IsSelectionCollapsed() const { return mIsSelectionCollapsed; }
  bool IsAtEndOfLine() { return mIsAtEndOfLine; }

  int32_t GetGranularity() const { return mGranularity; }

 private:
  int32_t mCaretOffset;

  bool mIsSelectionCollapsed;
  bool mIsAtEndOfLine;
  int32_t mGranularity;
};

/**
@@ -381,7 +386,8 @@ class AccCaretMoveEvent : public AccEvent {
class AccTextSelChangeEvent : public AccEvent {
 public:
  AccTextSelChangeEvent(HyperTextAccessible* aTarget,
                        dom::Selection* aSelection, int32_t aReason);
                        dom::Selection* aSelection, int32_t aReason,
                        int32_t aGranularity);
  virtual ~AccTextSelChangeEvent();

  // AccEvent
@@ -397,6 +403,8 @@ class AccTextSelChangeEvent : public AccEvent {
   */
  bool IsCaretMoveOnly() const;

  int32_t GetGranularity() const { return mGranularity; }

  /**
   * Return selection ranges in document/control.
   */
@@ -405,6 +413,7 @@ class AccTextSelChangeEvent : public AccEvent {
 private:
  RefPtr<dom::Selection> mSel;
  int32_t mReason;
  int32_t mGranularity;

  friend class EventQueue;
  friend class SelectionManager;
+10 −7
Original line number Diff line number Diff line
@@ -24,10 +24,12 @@ using namespace mozilla::a11y;
using mozilla::dom::Selection;

struct mozilla::a11y::SelData final {
  SelData(Selection* aSel, int32_t aReason) : mSel(aSel), mReason(aReason) {}
  SelData(Selection* aSel, int32_t aReason, int32_t aGranularity)
      : mSel(aSel), mReason(aReason), mGranularity(aGranularity) {}

  RefPtr<Selection> mSel;
  int16_t mReason;
  int32_t mGranularity;

  NS_INLINE_DECL_REFCOUNTING(SelData)

@@ -148,9 +150,10 @@ void SelectionManager::ProcessTextSelChangeEvent(AccEvent* aEvent) {
                                             selection->FocusOffset());
  mAccWithCaret = caretCntr;
  if (mCaretOffset != -1) {
    RefPtr<AccCaretMoveEvent> caretMoveEvent = new AccCaretMoveEvent(
        caretCntr, mCaretOffset, selection->IsCollapsed(),
        caretCntr->IsCaretAtEndOfLine(), aEvent->FromUserInput());
    RefPtr<AccCaretMoveEvent> caretMoveEvent =
        new AccCaretMoveEvent(caretCntr, mCaretOffset, selection->IsCollapsed(),
                              caretCntr->IsCaretAtEndOfLine(),
                              event->GetGranularity(), aEvent->FromUserInput());
    nsEventShell::FireEvent(caretMoveEvent);
  }
}
@@ -175,7 +178,7 @@ SelectionManager::NotifySelectionChanged(dom::Document* aDocument,
    // Selection manager has longer lifetime than any document accessible,
    // so that we are guaranteed that the notification is processed before
    // the selection manager is destroyed.
    RefPtr<SelData> selData = new SelData(aSelection, aReason);
    RefPtr<SelData> selData = new SelData(aSelection, aReason, aAmount);
    document->HandleNotification<SelectionManager, SelData>(
        this, &SelectionManager::ProcessSelectionChanged, selData);
  }
@@ -211,8 +214,8 @@ void SelectionManager::ProcessSelectionChanged(SelData* aSelData) {
  }

  if (selection->GetType() == SelectionType::eNormal) {
    RefPtr<AccEvent> event =
        new AccTextSelChangeEvent(text, selection, aSelData->mReason);
    RefPtr<AccEvent> event = new AccTextSelChangeEvent(
        text, selection, aSelData->mReason, aSelData->mGranularity);
    text->Document()->FireDelayedEvent(event);

  } else if (selection->GetType() == SelectionType::eSpellCheck) {
+3 −3
Original line number Diff line number Diff line
@@ -934,9 +934,9 @@ nsresult LocalAccessible::HandleAccEvent(AccEvent* aEvent) {
        }
        case nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED: {
          AccCaretMoveEvent* event = downcast_accEvent(aEvent);
          ipcDoc->SendCaretMoveEvent(id, event->GetCaretOffset(),
                                     event->IsSelectionCollapsed(),
                                     event->IsAtEndOfLine());
          ipcDoc->SendCaretMoveEvent(
              id, event->GetCaretOffset(), event->IsSelectionCollapsed(),
              event->IsAtEndOfLine(), event->GetGranularity());
          break;
        }
        case nsIAccessibleEvent::EVENT_TEXT_INSERTED:
+5 −0
Original line number Diff line number Diff line
@@ -25,4 +25,9 @@ interface nsIAccessibleCaretMoveEvent: nsIAccessibleEvent
   * Return true if the caret is at the end of a line.
   */
  readonly attribute bool isAtEndOfLine;

  /**
   * Return caret move granularity.
   */
  readonly attribute long granularity;
};
Loading