Skip to content

Commit

Permalink
Bug 1140895 - IPC Proxy for get/set/add/remove Selection, r=tbsaunde
Browse files Browse the repository at this point in the history
  • Loading branch information
rmottola committed Nov 11, 2019
1 parent 24ca5c6 commit 35d3364
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 26 deletions.
72 changes: 46 additions & 26 deletions accessible/atk/nsMaiInterfaceText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,20 +466,28 @@ getTextSelectionCB(AtkText *aText, gint aSelectionNum,
gint *aStartOffset, gint *aEndOffset)
{
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
if (!accWrap)
return nullptr;

HyperTextAccessible* text = accWrap->AsHyperText();
if (!text || !text->IsTextRole())
return nullptr;

int32_t startOffset = 0, endOffset = 0;
text->SelectionBoundsAt(aSelectionNum, &startOffset, &endOffset);
if (accWrap) {
HyperTextAccessible* text = accWrap->AsHyperText();
if (!text || !text->IsTextRole()) {
return nullptr;
}

text->SelectionBoundsAt(aSelectionNum, &startOffset, &endOffset);
*aStartOffset = startOffset;
*aEndOffset = endOffset;

return getTextCB(aText, *aStartOffset, *aEndOffset);
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
nsString data;
proxy->SelectionBoundsAt(aSelectionNum, data, &startOffset, &endOffset);
*aStartOffset = startOffset;
*aEndOffset = endOffset;

NS_ConvertUTF16toUTF8 dataAsUTF8(data);
return (dataAsUTF8.get()) ? g_strdup(dataAsUTF8.get()) : nullptr;
}
return nullptr;
}

// set methods
Expand All @@ -489,44 +497,56 @@ addTextSelectionCB(AtkText *aText,
gint aEndOffset)
{
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
if (!accWrap)
return FALSE;
if (accWrap) {
HyperTextAccessible* text = accWrap->AsHyperText();
if (!text || !text->IsTextRole()) {
return FALSE;
}

HyperTextAccessible* text = accWrap->AsHyperText();
if (!text || !text->IsTextRole())
return FALSE;
return text->AddToSelection(aStartOffset, aEndOffset);
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
return proxy->AddToSelection(aStartOffset, aEndOffset);
}

return text->AddToSelection(aStartOffset, aEndOffset);
return FALSE;
}

static gboolean
removeTextSelectionCB(AtkText *aText,
gint aSelectionNum)
{
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
if (!accWrap)
return FALSE;
if (accWrap) {
HyperTextAccessible* text = accWrap->AsHyperText();
if (!text || !text->IsTextRole()) {
return FALSE;
}

HyperTextAccessible* text = accWrap->AsHyperText();
if (!text || !text->IsTextRole())
return FALSE;
return text->RemoveFromSelection(aSelectionNum);
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
return proxy->RemoveFromSelection(aSelectionNum);
}

return text->RemoveFromSelection(aSelectionNum);
return FALSE;
}

static gboolean
setTextSelectionCB(AtkText *aText, gint aSelectionNum,
gint aStartOffset, gint aEndOffset)
{
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
if (!accWrap)
return FALSE;
if (accWrap) {
HyperTextAccessible* text = accWrap->AsHyperText();
if (!text || !text->IsTextRole()) {
return FALSE;
}

HyperTextAccessible* text = accWrap->AsHyperText();
if (!text || !text->IsTextRole())
return FALSE;
return text->SetSelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset);
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
return proxy->SetSelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset);
}

return text->SetSelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset);
return FALSE;
}

static gboolean
Expand Down
69 changes: 69 additions & 0 deletions accessible/ipc/DocAccessibleChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,5 +374,74 @@ DocAccessibleChild::RecvOffsetAtPoint(const uint64_t& aID,
return true;
}

bool
DocAccessibleChild::RecvSelectionBoundsAt(const uint64_t& aID,
const int32_t& aSelectionNum,
bool* aSucceeded,
nsString* aData,
int32_t* aStartOffset,
int32_t* aEndOffset)
{
*aSucceeded = false;
*aStartOffset = 0;
*aEndOffset = 0;
HyperTextAccessible* acc = IdToHyperTextAccessible(aID);
if (acc && acc->IsTextRole()) {
*aSucceeded =
acc->SelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset);
if (*aSucceeded) {
acc->TextSubstring(*aStartOffset, *aEndOffset, *aData);
}
}

return true;
}

bool
DocAccessibleChild::RecvSetSelectionBoundsAt(const uint64_t& aID,
const int32_t& aSelectionNum,
const int32_t& aStartOffset,
const int32_t& aEndOffset,
bool* aSucceeded)
{
*aSucceeded = false;
HyperTextAccessible* acc = IdToHyperTextAccessible(aID);
if (acc && acc->IsTextRole()) {
*aSucceeded =
acc->SetSelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset);
}

return true;
}

bool
DocAccessibleChild::RecvAddToSelection(const uint64_t& aID,
const int32_t& aStartOffset,
const int32_t& aEndOffset,
bool* aSucceeded)
{
*aSucceeded = false;
HyperTextAccessible* acc = IdToHyperTextAccessible(aID);
if (acc && acc->IsTextRole()) {
*aSucceeded = acc->AddToSelection(aStartOffset, aEndOffset);
}

return true;
}

bool
DocAccessibleChild::RecvRemoveFromSelection(const uint64_t& aID,
const int32_t& aSelectionNum,
bool* aSucceeded)
{
*aSucceeded = false;
HyperTextAccessible* acc = IdToHyperTextAccessible(aID);
if (acc && acc->IsTextRole()) {
*aSucceeded = acc->RemoveFromSelection(aSelectionNum);
}

return true;
}

}
}
23 changes: 23 additions & 0 deletions accessible/ipc/DocAccessibleChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,29 @@ class DocAccessibleChild : public PDocAccessibleChild
const int32_t& aY,
const uint32_t& aCoordType,
int32_t* aRetVal) override;

virtual bool RecvSelectionBoundsAt(const uint64_t& aID,
const int32_t& aSelectionNum,
bool* aSucceeded,
nsString* aData,
int32_t* aStartOffset,
int32_t* aEndOffset) override;

virtual bool RecvSetSelectionBoundsAt(const uint64_t& aID,
const int32_t& aSelectionNum,
const int32_t& aStartOffset,
const int32_t& aEndOffset,
bool* aSucceeded) override;

virtual bool RecvAddToSelection(const uint64_t& aID,
const int32_t& aStartOffset,
const int32_t& aEndOffset,
bool* aSucceeded) override;

virtual bool RecvRemoveFromSelection(const uint64_t& aID,
const int32_t& aSelectionNum,
bool* aSucceeded) override;

private:
bool PersistentPropertiesToArray(nsIPersistentProperties* aProps,
nsTArray<Attribute>* aAttributes);
Expand Down
10 changes: 10 additions & 0 deletions accessible/ipc/PDocAccessible.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ child:

prio(high) sync OffsetAtPoint(uint64_t aID, int32_t aX, int32_t aY, uint32_t aCoordType)
returns(int32_t aRetVal);

prio(high) sync SelectionBoundsAt(uint64_t aID, int32_t aSelectionNum)
returns(bool aSucceeded, nsString aData, int32_t aStartOffset, int32_t aEndOffset);
prio(high) sync SetSelectionBoundsAt(uint64_t aID, int32_t aSelectionNum,
int32_t aStartOffset, int32_t aEndOffset)
returns(bool aSucceeded);
prio(high) sync AddToSelection(uint64_t aID, int32_t aStartOffset, int32_t aEndOffset)
returns(bool aSucceeded);
prio(high) sync RemoveFromSelection(uint64_t aID, int32_t aSelectionNum)
returns(bool aSucceeded);
};

}
Expand Down
40 changes: 40 additions & 0 deletions accessible/ipc/ProxyAccessible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,45 @@ ProxyAccessible::OffsetAtPoint(int32_t aX, int32_t aY, uint32_t aCoordType)
return retVal;
}

bool
ProxyAccessible::SelectionBoundsAt(int32_t aSelectionNum,
nsString& aData,
int32_t* aStartOffset,
int32_t* aEndOffset)
{
bool retVal = false;
unused << mDoc->SendSelectionBoundsAt(mID, aSelectionNum, &retVal, &aData,
aStartOffset, aEndOffset);
return retVal;
}

bool
ProxyAccessible::SetSelectionBoundsAt(int32_t aSelectionNum,
int32_t aStartOffset,
int32_t aEndOffset)
{
bool retVal = false;
unused << mDoc->SendSetSelectionBoundsAt(mID, aSelectionNum, aStartOffset,
aEndOffset, &retVal);
return retVal;
}

bool
ProxyAccessible::AddToSelection(int32_t aStartOffset,
int32_t aEndOffset)
{
bool retVal = false;
unused << mDoc->SendAddToSelection(mID, aStartOffset, aEndOffset, &retVal);
return retVal;
}

bool
ProxyAccessible::RemoveFromSelection(int32_t aSelectionNum)
{
bool retVal = false;
unused << mDoc->SendRemoveFromSelection(mID, aSelectionNum, &retVal);
return retVal;
}

}
}
14 changes: 14 additions & 0 deletions accessible/ipc/ProxyAccessible.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ class ProxyAccessible

int32_t OffsetAtPoint(int32_t aX, int32_t aY, uint32_t aCoordType);

bool SelectionBoundsAt(int32_t aSelectionNum,
nsString& aData,
int32_t* aStartOffset,
int32_t* aEndOffset);

bool SetSelectionBoundsAt(int32_t aSelectionNum,
int32_t aStartOffset,
int32_t aEndOffset);

bool AddToSelection(int32_t aStartOffset,
int32_t aEndOffset);

bool RemoveFromSelection(int32_t aSelectionNum);

/**
* Allow the platform to store a pointers worth of data on us.
*/
Expand Down

0 comments on commit 35d3364

Please sign in to comment.