tor-browser

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

MOXMathAccessibles.mm (2923B)


      1 /* clang-format off */
      2 /* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      3 /* clang-format on */
      4 /* This Source Code Form is subject to the terms of the Mozilla Public
      5 * License, v. 2.0. If a copy of the MPL was not distributed with this
      6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      7 
      8 #import "MOXMathAccessibles.h"
      9 
     10 #import "MacUtils.h"
     11 
     12 using namespace mozilla::a11y;
     13 
     14 // XXX WebKit also defines the following attributes.
     15 // See bugs 1176970 and 1176983.
     16 // - NSAccessibilityMathFencedOpenAttribute @"AXMathFencedOpen"
     17 // - NSAccessibilityMathFencedCloseAttribute @"AXMathFencedClose"
     18 // - NSAccessibilityMathPrescriptsAttribute @"AXMathPrescripts"
     19 // - NSAccessibilityMathPostscriptsAttribute @"AXMathPostscripts"
     20 
     21 @implementation MOXMathRootAccessible
     22 
     23 - (id)moxMathRootRadicand {
     24  return [self childAt:0];
     25 }
     26 
     27 - (id)moxMathRootIndex {
     28  return [self childAt:1];
     29 }
     30 
     31 @end
     32 
     33 @implementation MOXMathSquareRootAccessible
     34 
     35 - (id)moxMathRootRadicand {
     36  return [self childAt:0];
     37 }
     38 
     39 @end
     40 
     41 @implementation MOXMathFractionAccessible
     42 
     43 - (id)moxMathFractionNumerator {
     44  return [self childAt:0];
     45 }
     46 
     47 - (id)moxMathFractionDenominator {
     48  return [self childAt:1];
     49 }
     50 
     51 // Bug 1639745: This doesn't actually work.
     52 - (NSNumber*)moxMathLineThickness {
     53  // WebKit sets line thickness to some logical value parsed in the
     54  // renderer object of the <mfrac> element. It's not clear whether the
     55  // exact value is relevant to assistive technologies. From a semantic
     56  // point of view, the only important point is to distinguish between
     57  // <mfrac> elements that have a fraction bar and those that do not.
     58  // Per the MathML 3 spec, the latter happens iff the linethickness
     59  // attribute is of the form [zero-float][optional-unit]. In that case we
     60  // set line thickness to zero and in the other cases we set it to one.
     61  if (NSString* thickness = utils::GetAccAttr(self, nsGkAtoms::linethickness)) {
     62    NSNumberFormatter* formatter =
     63        [[[NSNumberFormatter alloc] init] autorelease];
     64    NSNumber* value = [formatter numberFromString:thickness];
     65    return [NSNumber numberWithBool:[value boolValue]];
     66  } else {
     67    return [NSNumber numberWithInteger:0];
     68  }
     69 }
     70 
     71 @end
     72 
     73 @implementation MOXMathSubSupAccessible
     74 - (id)moxMathBase {
     75  return [self childAt:0];
     76 }
     77 
     78 - (id)moxMathSubscript {
     79  if (mRole == roles::MATHML_SUP) {
     80    return nil;
     81  }
     82 
     83  return [self childAt:1];
     84 }
     85 
     86 - (id)moxMathSuperscript {
     87  if (mRole == roles::MATHML_SUB) {
     88    return nil;
     89  }
     90 
     91  return [self childAt:mRole == roles::MATHML_SUP ? 1 : 2];
     92 }
     93 
     94 @end
     95 
     96 @implementation MOXMathUnderOverAccessible
     97 - (id)moxMathBase {
     98  return [self childAt:0];
     99 }
    100 
    101 - (id)moxMathUnder {
    102  if (mRole == roles::MATHML_OVER) {
    103    return nil;
    104  }
    105 
    106  return [self childAt:1];
    107 }
    108 
    109 - (id)moxMathOver {
    110  if (mRole == roles::MATHML_UNDER) {
    111    return nil;
    112  }
    113 
    114  return [self childAt:mRole == roles::MATHML_OVER ? 1 : 2];
    115 }
    116 @end