summaryrefslogtreecommitdiffstats
path: root/accessible/mac/MOXMathAccessibles.mm
blob: 7bfe2e3e05a03cff48fed3f034752e0d7043e06f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* clang-format off */
/* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* clang-format on */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#import "MOXMathAccessibles.h"

#import "MacUtils.h"

using namespace mozilla::a11y;

// XXX WebKit also defines the following attributes.
// See bugs 1176970 and 1176983.
// - NSAccessibilityMathFencedOpenAttribute @"AXMathFencedOpen"
// - NSAccessibilityMathFencedCloseAttribute @"AXMathFencedClose"
// - NSAccessibilityMathPrescriptsAttribute @"AXMathPrescripts"
// - NSAccessibilityMathPostscriptsAttribute @"AXMathPostscripts"

@implementation MOXMathRootAccessible

- (id)moxMathRootRadicand {
  return [self childAt:0];
}

- (id)moxMathRootIndex {
  return [self childAt:1];
}

@end

@implementation MOXMathSquareRootAccessible

- (id)moxMathRootRadicand {
  return [self childAt:0];
}

@end

@implementation MOXMathFractionAccessible

- (id)moxMathFractionNumerator {
  return [self childAt:0];
}

- (id)moxMathFractionDenominator {
  return [self childAt:1];
}

// Bug 1639745: This doesn't actually work.
- (NSNumber*)moxMathLineThickness {
  // WebKit sets line thickness to some logical value parsed in the
  // renderer object of the <mfrac> element. It's not clear whether the
  // exact value is relevant to assistive technologies. From a semantic
  // point of view, the only important point is to distinguish between
  // <mfrac> elements that have a fraction bar and those that do not.
  // Per the MathML 3 spec, the latter happens iff the linethickness
  // attribute is of the form [zero-float][optional-unit]. In that case we
  // set line thickness to zero and in the other cases we set it to one.
  if (NSString* thickness =
          utils::GetAccAttr(self, nsGkAtoms::linethickness_)) {
    NSNumberFormatter* formatter =
        [[[NSNumberFormatter alloc] init] autorelease];
    NSNumber* value = [formatter numberFromString:thickness];
    return [NSNumber numberWithBool:[value boolValue]];
  } else {
    return [NSNumber numberWithInteger:0];
  }
}

@end

@implementation MOXMathSubSupAccessible
- (id)moxMathBase {
  return [self childAt:0];
}

- (id)moxMathSubscript {
  if (mRole == roles::MATHML_SUP) {
    return nil;
  }

  return [self childAt:1];
}

- (id)moxMathSuperscript {
  if (mRole == roles::MATHML_SUB) {
    return nil;
  }

  return [self childAt:mRole == roles::MATHML_SUP ? 1 : 2];
}

@end

@implementation MOXMathUnderOverAccessible
- (id)moxMathBase {
  return [self childAt:0];
}

- (id)moxMathUnder {
  if (mRole == roles::MATHML_OVER) {
    return nil;
  }

  return [self childAt:1];
}

- (id)moxMathOver {
  if (mRole == roles::MATHML_UNDER) {
    return nil;
  }

  return [self childAt:mRole == roles::MATHML_OVER ? 1 : 2];
}
@end