Skip to content

Commit 1cd42d3

Browse files
committed
Bug 1826856 - Remove sync AnchorURIAt method. r=Jamie
We can get the URI using the Value method that is already cached when caching is enabled. Differential Revision: https://phabricator.services.mozilla.com/D176067 UltraBlame original commit: f191e51b0456ff8a698605d0db639b6d91a49854
1 parent 0ec9e1e commit 1cd42d3

19 files changed

+120
-136
lines changed

accessible/atk/nsMaiHyperlink.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,21 @@ void finalizeCB(GObject* aObj) {
143143

144144
gchar* getUriCB(AtkHyperlink* aLink, gint aLinkIndex) {
145145
MaiHyperlink* maiLink = GetMaiHyperlink(aLink);
146-
if (!maiLink) return nullptr;
147-
148-
nsAutoCString cautoStr;
149-
if (LocalAccessible* hyperlink = maiLink->GetAccHyperlink()) {
150-
nsCOMPtr<nsIURI> uri = hyperlink->AnchorURIAt(aLinkIndex);
151-
if (!uri) return nullptr;
152-
153-
nsresult rv = uri->GetSpec(cautoStr);
154-
NS_ENSURE_SUCCESS(rv, nullptr);
146+
if (!maiLink) {
147+
return nullptr;
148+
}
155149

156-
return g_strdup(cautoStr.get());
150+
Accessible* acc = maiLink->Acc();
151+
if (!acc) {
152+
return nullptr;
157153
}
158154

159-
bool valid;
160-
maiLink->Proxy()->AnchorURIAt(aLinkIndex, cautoStr, &valid);
161-
if (!valid) return nullptr;
155+
nsAutoCString cautoStr;
156+
nsCOMPtr<nsIURI> uri = acc->AnchorURIAt(aLinkIndex);
157+
if (!uri) return nullptr;
158+
159+
nsresult rv = uri->GetSpec(cautoStr);
160+
NS_ENSURE_SUCCESS(rv, nullptr);
162161

163162
return g_strdup(cautoStr.get());
164163
}

accessible/basetypes/Accessible.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "AccGroupInfo.h"
88
#include "ARIAMap.h"
99
#include "nsAccUtils.h"
10+
#include "nsIURI.h"
1011
#include "Relation.h"
1112
#include "States.h"
1213
#include "mozilla/a11y/FocusManager.h"
@@ -382,13 +383,40 @@ uint32_t Accessible::AnchorCount() {
382383
return 1;
383384
}
384385

385-
Accessible* Accessible::AnchorAt(uint32_t aAnchorIndex) {
386+
Accessible* Accessible::AnchorAt(uint32_t aAnchorIndex) const {
386387
if (IsImageMap()) {
387388
return ChildAt(aAnchorIndex);
388389
}
389390

390391
MOZ_ASSERT(IsLink(), "GetAnchor is called on not hyper link!");
391-
return aAnchorIndex == 0 ? this : nullptr;
392+
return aAnchorIndex == 0 ? const_cast<Accessible*>(this) : nullptr;
393+
}
394+
395+
already_AddRefed<nsIURI> Accessible::AnchorURIAt(uint32_t aAnchorIndex) const {
396+
Accessible* anchor = nullptr;
397+
398+
if (IsTextLeaf() || IsImage()) {
399+
for (Accessible* parent = Parent(); parent && !parent->IsOuterDoc();
400+
parent = parent->Parent()) {
401+
if (parent->IsLink()) {
402+
anchor = parent->AnchorAt(aAnchorIndex);
403+
}
404+
}
405+
} else {
406+
anchor = AnchorAt(aAnchorIndex);
407+
}
408+
409+
if (anchor) {
410+
RefPtr<nsIURI> uri;
411+
nsAutoString spec;
412+
anchor->Value(spec);
413+
nsresult rv = NS_NewURI(getter_AddRefs(uri), spec);
414+
if (NS_SUCCEEDED(rv)) {
415+
return uri.forget();
416+
}
417+
}
418+
419+
return nullptr;
392420
}
393421

394422
bool Accessible::IsSearchbox() const {

accessible/basetypes/Accessible.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class nsStaticAtom;
1717

1818
struct nsRoleMapEntry;
1919

20+
class nsIURI;
21+
2022
namespace mozilla {
2123
namespace a11y {
2224

@@ -588,7 +590,12 @@ class Accessible {
588590

589591

590592

591-
Accessible* AnchorAt(uint32_t aAnchorIndex);
593+
virtual already_AddRefed<nsIURI> AnchorURIAt(uint32_t aAnchorIndex) const;
594+
595+
596+
597+
598+
Accessible* AnchorAt(uint32_t aAnchorIndex) const;
592599

593600

594601

accessible/generic/BaseAccessibles.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,24 +138,6 @@ KeyBinding LinkableAccessible::AccessKey() const {
138138

139139

140140

141-
already_AddRefed<nsIURI> LinkableAccessible::AnchorURIAt(
142-
uint32_t aAnchorIndex) const {
143-
bool isLink;
144-
const LocalAccessible* actionAcc = ActionWalk(&isLink);
145-
if (isLink) {
146-
NS_ASSERTION(actionAcc->IsLink(), "HyperLink isn't implemented.");
147-
148-
if (actionAcc->IsLink()) {
149-
return actionAcc->AnchorURIAt(aAnchorIndex);
150-
}
151-
}
152-
153-
return nullptr;
154-
}
155-
156-
157-
158-
159141

160142
uint64_t DummyAccessible::NativeState() const { return 0; }
161143
uint64_t DummyAccessible::NativeInteractiveState() const { return 0; }

accessible/generic/BaseAccessibles.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ class LinkableAccessible : public AccessibleWrap {
6666

6767
const LocalAccessible* ActionWalk(bool* aIsLink = nullptr,
6868
bool* aIsOnclick = nullptr) const;
69-
70-
virtual already_AddRefed<nsIURI> AnchorURIAt(
71-
uint32_t aAnchorIndex) const override;
7269

7370
protected:
7471
virtual ~LinkableAccessible() {}

accessible/generic/LocalAccessible.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
#include "nsReadableUtils.h"
7171
#include "prdtoa.h"
7272
#include "nsAtom.h"
73-
#include "nsIURI.h"
7473
#include "nsArrayUtils.h"
7574
#include "nsWhitespaceTokenizer.h"
7675
#include "nsAttrName.h"
@@ -2776,12 +2775,6 @@ bool LocalAccessible::IsLink() const {
27762775
return mParent && mParent->IsHyperText() && !IsText();
27772776
}
27782777

2779-
already_AddRefed<nsIURI> LocalAccessible::AnchorURIAt(
2780-
uint32_t aAnchorIndex) const {
2781-
MOZ_ASSERT(IsLink(), "AnchorURIAt is called on not hyper link!");
2782-
return nullptr;
2783-
}
2784-
27852778

27862779

27872780

accessible/generic/LocalAccessible.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,6 @@ class LocalAccessible : public nsISupports, public Accessible {
514514
virtual bool IsLink() const override;
515515

516516

517-
518-
519-
virtual already_AddRefed<nsIURI> AnchorURIAt(uint32_t aAnchorIndex) const;
520-
521-
522517

523518

524519

accessible/html/HTMLImageMapAccessible.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,6 @@ role HTMLImageMapAccessible::NativeRole() const { return roles::IMAGE_MAP; }
4040

4141

4242

43-
already_AddRefed<nsIURI> HTMLImageMapAccessible::AnchorURIAt(
44-
uint32_t aAnchorIndex) const {
45-
LocalAccessible* area = LocalChildAt(aAnchorIndex);
46-
if (!area) return nullptr;
47-
48-
nsIContent* linkContent = area->GetContent();
49-
return linkContent && linkContent->IsElement()
50-
? linkContent->AsElement()->GetHrefURI()
51-
: nullptr;
52-
}
53-
54-
55-
56-
5743
void HTMLImageMapAccessible::UpdateChildAreas(bool aDoFireEvents) {
5844
if (!mContent || !mContent->GetPrimaryFrame()) {
5945
return;

accessible/html/HTMLImageMapAccessible.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ class HTMLImageMapAccessible final : public ImageAccessible {
2626
virtual a11y::role NativeRole() const override;
2727

2828

29-
virtual already_AddRefed<nsIURI> AnchorURIAt(
30-
uint32_t aAnchorIndex) const override;
31-
32-
3329

3430

3531
void UpdateChildAreas(bool aDoFireEvents = true);

accessible/html/HTMLLinkAccessible.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ bool HTMLLinkAccessible::IsLink() const {
120120
return true;
121121
}
122122

123-
already_AddRefed<nsIURI> HTMLLinkAccessible::AnchorURIAt(
124-
uint32_t aAnchorIndex) const {
125-
return aAnchorIndex == 0 ? mContent->AsElement()->GetHrefURI() : nullptr;
126-
}
127-
128123

129124

130125

0 commit comments

Comments
 (0)