michael@0: /* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:expandtab:shiftwidth=2:tabstop=2: michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #import "mozHTMLAccessible.h" michael@0: michael@0: #import "Accessible-inl.h" michael@0: #import "HyperTextAccessible.h" michael@0: michael@0: #import "nsCocoaUtils.h" michael@0: michael@0: @implementation mozHeadingAccessible michael@0: michael@0: - (NSString*)title michael@0: { michael@0: nsAutoString title; michael@0: // XXX use the flattening API when there are available michael@0: // see bug 768298 michael@0: mGeckoAccessible->GetContent()->GetTextContent(title); michael@0: michael@0: return nsCocoaUtils::ToNSString(title); michael@0: } michael@0: michael@0: - (id)value michael@0: { michael@0: if (!mGeckoAccessible || !mGeckoAccessible->IsHyperText()) michael@0: return nil; michael@0: michael@0: uint32_t level = mGeckoAccessible->AsHyperText()->GetLevelInternal(); michael@0: return [NSNumber numberWithInt:level]; michael@0: } michael@0: michael@0: @end michael@0: michael@0: @interface mozLinkAccessible () michael@0: -(NSURL*)url; michael@0: @end michael@0: michael@0: @implementation mozLinkAccessible michael@0: michael@0: - (NSArray*)accessibilityAttributeNames michael@0: { michael@0: // if we're expired, we don't support any attributes. michael@0: if (!mGeckoAccessible) michael@0: return [NSArray array]; michael@0: michael@0: static NSMutableArray* attributes = nil; michael@0: michael@0: if (!attributes) { michael@0: attributes = [[super accessibilityAttributeNames] mutableCopy]; michael@0: [attributes addObject:NSAccessibilityURLAttribute]; michael@0: } michael@0: michael@0: return attributes; michael@0: } michael@0: michael@0: - (id)accessibilityAttributeValue:(NSString *)attribute michael@0: { michael@0: if ([attribute isEqualToString:NSAccessibilityURLAttribute]) michael@0: return [self url]; michael@0: michael@0: return [super accessibilityAttributeValue:attribute]; michael@0: } michael@0: michael@0: - (NSArray*)accessibilityActionNames michael@0: { michael@0: // if we're expired, we don't support any attributes. michael@0: if (!mGeckoAccessible) michael@0: return [NSArray array]; michael@0: michael@0: static NSArray* actionNames = nil; michael@0: michael@0: if (!actionNames) { michael@0: actionNames = [[NSArray alloc] initWithObjects:NSAccessibilityPressAction, michael@0: nil]; michael@0: } michael@0: michael@0: return actionNames; michael@0: } michael@0: michael@0: - (void)accessibilityPerformAction:(NSString*)action michael@0: { michael@0: if (!mGeckoAccessible) michael@0: return; michael@0: michael@0: if ([action isEqualToString:NSAccessibilityPressAction]) michael@0: mGeckoAccessible->DoAction(0); michael@0: else michael@0: [super accessibilityPerformAction:action]; michael@0: } michael@0: michael@0: - (NSString*)customDescription michael@0: { michael@0: return @""; michael@0: } michael@0: michael@0: - (NSString*)value michael@0: { michael@0: return @""; michael@0: } michael@0: michael@0: - (NSURL*)url michael@0: { michael@0: if (!mGeckoAccessible || mGeckoAccessible->IsDefunct()) michael@0: return nil; michael@0: michael@0: nsAutoString value; michael@0: mGeckoAccessible->Value(value); michael@0: michael@0: NSString* urlString = value.IsEmpty() ? nil : nsCocoaUtils::ToNSString(value); michael@0: if (!urlString) michael@0: return nil; michael@0: michael@0: return [NSURL URLWithString:urlString]; michael@0: } michael@0: michael@0: @end