accessible/src/mac/mozHTMLAccessible.mm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:expandtab:shiftwidth=2:tabstop=2:
michael@0 3 */
michael@0 4 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #import "mozHTMLAccessible.h"
michael@0 9
michael@0 10 #import "Accessible-inl.h"
michael@0 11 #import "HyperTextAccessible.h"
michael@0 12
michael@0 13 #import "nsCocoaUtils.h"
michael@0 14
michael@0 15 @implementation mozHeadingAccessible
michael@0 16
michael@0 17 - (NSString*)title
michael@0 18 {
michael@0 19 nsAutoString title;
michael@0 20 // XXX use the flattening API when there are available
michael@0 21 // see bug 768298
michael@0 22 mGeckoAccessible->GetContent()->GetTextContent(title);
michael@0 23
michael@0 24 return nsCocoaUtils::ToNSString(title);
michael@0 25 }
michael@0 26
michael@0 27 - (id)value
michael@0 28 {
michael@0 29 if (!mGeckoAccessible || !mGeckoAccessible->IsHyperText())
michael@0 30 return nil;
michael@0 31
michael@0 32 uint32_t level = mGeckoAccessible->AsHyperText()->GetLevelInternal();
michael@0 33 return [NSNumber numberWithInt:level];
michael@0 34 }
michael@0 35
michael@0 36 @end
michael@0 37
michael@0 38 @interface mozLinkAccessible ()
michael@0 39 -(NSURL*)url;
michael@0 40 @end
michael@0 41
michael@0 42 @implementation mozLinkAccessible
michael@0 43
michael@0 44 - (NSArray*)accessibilityAttributeNames
michael@0 45 {
michael@0 46 // if we're expired, we don't support any attributes.
michael@0 47 if (!mGeckoAccessible)
michael@0 48 return [NSArray array];
michael@0 49
michael@0 50 static NSMutableArray* attributes = nil;
michael@0 51
michael@0 52 if (!attributes) {
michael@0 53 attributes = [[super accessibilityAttributeNames] mutableCopy];
michael@0 54 [attributes addObject:NSAccessibilityURLAttribute];
michael@0 55 }
michael@0 56
michael@0 57 return attributes;
michael@0 58 }
michael@0 59
michael@0 60 - (id)accessibilityAttributeValue:(NSString *)attribute
michael@0 61 {
michael@0 62 if ([attribute isEqualToString:NSAccessibilityURLAttribute])
michael@0 63 return [self url];
michael@0 64
michael@0 65 return [super accessibilityAttributeValue:attribute];
michael@0 66 }
michael@0 67
michael@0 68 - (NSArray*)accessibilityActionNames
michael@0 69 {
michael@0 70 // if we're expired, we don't support any attributes.
michael@0 71 if (!mGeckoAccessible)
michael@0 72 return [NSArray array];
michael@0 73
michael@0 74 static NSArray* actionNames = nil;
michael@0 75
michael@0 76 if (!actionNames) {
michael@0 77 actionNames = [[NSArray alloc] initWithObjects:NSAccessibilityPressAction,
michael@0 78 nil];
michael@0 79 }
michael@0 80
michael@0 81 return actionNames;
michael@0 82 }
michael@0 83
michael@0 84 - (void)accessibilityPerformAction:(NSString*)action
michael@0 85 {
michael@0 86 if (!mGeckoAccessible)
michael@0 87 return;
michael@0 88
michael@0 89 if ([action isEqualToString:NSAccessibilityPressAction])
michael@0 90 mGeckoAccessible->DoAction(0);
michael@0 91 else
michael@0 92 [super accessibilityPerformAction:action];
michael@0 93 }
michael@0 94
michael@0 95 - (NSString*)customDescription
michael@0 96 {
michael@0 97 return @"";
michael@0 98 }
michael@0 99
michael@0 100 - (NSString*)value
michael@0 101 {
michael@0 102 return @"";
michael@0 103 }
michael@0 104
michael@0 105 - (NSURL*)url
michael@0 106 {
michael@0 107 if (!mGeckoAccessible || mGeckoAccessible->IsDefunct())
michael@0 108 return nil;
michael@0 109
michael@0 110 nsAutoString value;
michael@0 111 mGeckoAccessible->Value(value);
michael@0 112
michael@0 113 NSString* urlString = value.IsEmpty() ? nil : nsCocoaUtils::ToNSString(value);
michael@0 114 if (!urlString)
michael@0 115 return nil;
michael@0 116
michael@0 117 return [NSURL URLWithString:urlString];
michael@0 118 }
michael@0 119
michael@0 120 @end

mercurial