<commit_before>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <execinfo.h>

#import "chrome/browser/accessibility/browser_accessibility_cocoa.h"

#include <map>

#include "base/string16.h"
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/renderer_host/render_widget_host_view_mac.h"
#include "grit/webkit_strings.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
#include "ui/base/l10n/l10n_util_mac.h"

namespace {

// Returns an autoreleased copy of the WebAccessibility's attribute.
NSString* NSStringForWebAccessibilityAttribute(
    const std::map<int32, string16>& attributes,
    WebAccessibility::Attribute attribute) {
  std::map<int32, string16>::const_iterator iter =
      attributes.find(attribute);
  NSString* returnValue = @"";
  if (iter != attributes.end()) {
    returnValue = base::SysUTF16ToNSString(iter->second);
  }
  return returnValue;
}

struct MapEntry {
  WebAccessibility::Role webKitValue;
  NSString* nativeValue;
};

static const MapEntry roles[] = {
  { WebAccessibility::ROLE_NONE, NSAccessibilityUnknownRole },
  { WebAccessibility::ROLE_ALERT, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_ALERT_DIALOG, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_APPLICATION, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_ARTICLE, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_BUTTON, NSAccessibilityButtonRole },
  { WebAccessibility::ROLE_CELL, @"AXCell" },
  { WebAccessibility::ROLE_CHECKBOX, NSAccessibilityCheckBoxRole },
  { WebAccessibility::ROLE_COLUMN, NSAccessibilityColumnRole },
  { WebAccessibility::ROLE_COLUMN_HEADER, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_DIALOG, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_DOCUMENT, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_GRID, NSAccessibilityGridRole },
  { WebAccessibility::ROLE_GROUP, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_HEADING, @"AXHeading" },
  { WebAccessibility::ROLE_IGNORED, NSAccessibilityUnknownRole },
  { WebAccessibility::ROLE_IMAGE, NSAccessibilityImageRole },
  { WebAccessibility::ROLE_LANDMARK_BANNER, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_LANDMARK_COMPLEMENTARY, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_LANDMARK_CONTENTINFO, NSAccessibilityGroupRole },
  // TODO: role: main should report SubRole: AXLandmarkMain
  { WebAccessibility::ROLE_LANDMARK_MAIN, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_LANDMARK_NAVIGATION, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_LANDMARK_SEARCH, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_LINK, NSAccessibilityLinkRole },
  { WebAccessibility::ROLE_LIST, NSAccessibilityListRole },
  { WebAccessibility::ROLE_LIST_ITEM, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_LISTBOX, NSAccessibilityListRole },
  { WebAccessibility::ROLE_LOG, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_MARQUEE, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_MATH, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_NOTE, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_POPUP_BUTTON, NSAccessibilityPopUpButtonRole },
  { WebAccessibility::ROLE_RADIO_BUTTON, NSAccessibilityRadioButtonRole },
  { WebAccessibility::ROLE_RADIO_GROUP, NSAccessibilityRadioGroupRole },
  { WebAccessibility::ROLE_REGION, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_ROW, NSAccessibilityRowRole },
  { WebAccessibility::ROLE_ROW_HEADER, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_SCROLLAREA, NSAccessibilityScrollAreaRole },
  { WebAccessibility::ROLE_SCROLLBAR, NSAccessibilityScrollBarRole },
  { WebAccessibility::ROLE_STATIC_TEXT, NSAccessibilityStaticTextRole },
  { WebAccessibility::ROLE_STATUS, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_TAB, NSAccessibilityRadioButtonRole },
  { WebAccessibility::ROLE_TAB_LIST, NSAccessibilityTabGroupRole },
  { WebAccessibility::ROLE_TAB_PANEL, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_TABLE, NSAccessibilityTableRole },
  { WebAccessibility::ROLE_TABLE_HEADER_CONTAINER, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_TAB_GROUP, NSAccessibilityTabGroupRole },
  { WebAccessibility::ROLE_TEXTAREA, NSAccessibilityTextAreaRole },
  { WebAccessibility::ROLE_TEXT_FIELD, NSAccessibilityTextFieldRole },
  { WebAccessibility::ROLE_TIMER, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_TOOLTIP, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_TREE, NSAccessibilityOutlineRole },
  { WebAccessibility::ROLE_TREE_ITEM, NSAccessibilityRowRole },
  { WebAccessibility::ROLE_WEBCORE_LINK, NSAccessibilityLinkRole },
  { WebAccessibility::ROLE_WEB_AREA, @"AXWebArea" },
};

static const MapEntry subroles[] = {
  { WebAccessibility::ROLE_TREE_ITEM, NSAccessibilityOutlineRowSubrole }
};

std::map<WebAccessibility::Role, NSString*> webAccessibilityToNativeRole;
std::map<WebAccessibility::Role, NSString*> webAccessibilityToNativeSubrole;

// GetState checks the bitmask used in webaccessibility.h to check
// if the given state was set on the accessibility object.
bool GetState(BrowserAccessibility* accessibility, int state) {
  return ((accessibility->state() >> state) & 1);
}

} // namespace

@implementation BrowserAccessibilityCocoa

+ (void)initialize {
  const size_t numRoles = sizeof(roles) / sizeof(roles[0]);
  for (size_t i = 0; i < numRoles; ++i) {
    webAccessibilityToNativeRole[roles[i].webKitValue] = roles[i].nativeValue;<commit_msg>Add all remaining roles in our role mapping array. <commit_after>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <execinfo.h>

#import "chrome/browser/accessibility/browser_accessibility_cocoa.h"

#include <map>

#include "base/string16.h"
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/renderer_host/render_widget_host_view_mac.h"
#include "grit/webkit_strings.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
#include "ui/base/l10n/l10n_util_mac.h"

namespace {

// Returns an autoreleased copy of the WebAccessibility's attribute.
NSString* NSStringForWebAccessibilityAttribute(
    const std::map<int32, string16>& attributes,
    WebAccessibility::Attribute attribute) {
  std::map<int32, string16>::const_iterator iter =
      attributes.find(attribute);
  NSString* returnValue = @"";
  if (iter != attributes.end()) {
    returnValue = base::SysUTF16ToNSString(iter->second);
  }
  return returnValue;
}

struct MapEntry {
  WebAccessibility::Role webKitValue;
  NSString* nativeValue;
};

static const MapEntry roles[] = {
  { WebAccessibility::ROLE_NONE, NSAccessibilityUnknownRole },
  { WebAccessibility::ROLE_ALERT, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_ALERT_DIALOG, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_ANNOTATION, NSAccessibilityUnknownRole },
  { WebAccessibility::ROLE_APPLICATION, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_ARTICLE, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_BROWSER, NSAccessibilityBrowserRole },
  { WebAccessibility::ROLE_BUSY_INDICATOR, NSAccessibilityBusyIndicatorRole },
  { WebAccessibility::ROLE_BUTTON, NSAccessibilityButtonRole },
  { WebAccessibility::ROLE_CELL, @"AXCell" },
  { WebAccessibility::ROLE_CHECKBOX, NSAccessibilityCheckBoxRole },
  { WebAccessibility::ROLE_COLOR_WELL, NSAccessibilityColorWellRole },
  { WebAccessibility::ROLE_COLUMN, NSAccessibilityColumnRole },
  { WebAccessibility::ROLE_COLUMN_HEADER, @"AXCell" },
  { WebAccessibility::ROLE_DEFINITION_LIST_DEFINITION,
      NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_DEFINITION_LIST_TERM, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_DIALOG, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_DIRECTORY, NSAccessibilityListRole },
  { WebAccessibility::ROLE_DISCLOSURE_TRIANGLE,
      NSAccessibilityDisclosureTriangleRole },
  { WebAccessibility::ROLE_DOCUMENT, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_DRAWER, NSAccessibilityDrawerRole },
  { WebAccessibility::ROLE_EDITABLE_TEXT, NSAccessibilityTextFieldRole },
  { WebAccessibility::ROLE_GRID, NSAccessibilityGridRole },
  { WebAccessibility::ROLE_GROUP, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_GROW_AREA, NSAccessibilityGrowAreaRole },
  { WebAccessibility::ROLE_HEADING, @"AXHeading" },
  { WebAccessibility::ROLE_HELP_TAG, NSAccessibilityHelpTagRole },
  { WebAccessibility::ROLE_IGNORED, NSAccessibilityUnknownRole },
  { WebAccessibility::ROLE_IMAGE, NSAccessibilityImageRole },
  { WebAccessibility::ROLE_IMAGE_MAP, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_IMAGE_MAP_LINK, NSAccessibilityLinkRole },
  { WebAccessibility::ROLE_INCREMENTOR, NSAccessibilityIncrementorRole },
  { WebAccessibility::ROLE_LANDMARK_APPLICATION, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_LANDMARK_BANNER, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_LANDMARK_COMPLEMENTARY, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_LANDMARK_CONTENTINFO, NSAccessibilityGroupRole },
  // TODO: role: main should report SubRole: AXLandmarkMain
  { WebAccessibility::ROLE_LANDMARK_MAIN, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_LANDMARK_NAVIGATION, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_LANDMARK_SEARCH, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_LINK, NSAccessibilityLinkRole },
  { WebAccessibility::ROLE_LIST, NSAccessibilityListRole },
  { WebAccessibility::ROLE_LIST_ITEM, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_LIST_MARKER, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_LISTBOX, NSAccessibilityListRole },
  { WebAccessibility::ROLE_LISTBOX_OPTION, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_LOG, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_MARQUEE, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_MATH, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_MATTE, NSAccessibilityMatteRole },
  { WebAccessibility::ROLE_MENU, NSAccessibilityMenuRole },
  { WebAccessibility::ROLE_MENU_ITEM, NSAccessibilityMenuItemRole },
  { WebAccessibility::ROLE_MENU_BUTTON, NSAccessibilityButtonRole },
  { WebAccessibility::ROLE_MENU_LIST_OPTION, NSAccessibilityMenuItemRole },
  { WebAccessibility::ROLE_MENU_LIST_POPUP, NSAccessibilityUnknownRole },
  { WebAccessibility::ROLE_NOTE, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_OUTLINE, NSAccessibilityOutlineRole },
  { WebAccessibility::ROLE_POPUP_BUTTON, NSAccessibilityPopUpButtonRole },
  { WebAccessibility::ROLE_PROGRESS_INDICATOR,
      NSAccessibilityProgressIndicatorRole },
  { WebAccessibility::ROLE_RADIO_BUTTON, NSAccessibilityRadioButtonRole },
  { WebAccessibility::ROLE_RADIO_GROUP, NSAccessibilityRadioGroupRole },
  { WebAccessibility::ROLE_REGION, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_ROW, NSAccessibilityRowRole },
  { WebAccessibility::ROLE_ROW_HEADER, @"AXCell" },
  { WebAccessibility::ROLE_RULER, NSAccessibilityRulerRole },
  { WebAccessibility::ROLE_RULER_MARKER, NSAccessibilityRulerMarkerRole },
  { WebAccessibility::ROLE_SCROLLAREA, NSAccessibilityScrollAreaRole },
  { WebAccessibility::ROLE_SCROLLBAR, NSAccessibilityScrollBarRole },
  { WebAccessibility::ROLE_SHEET, NSAccessibilitySheetRole },
  { WebAccessibility::ROLE_SLIDER, NSAccessibilitySliderRole },
  { WebAccessibility::ROLE_SLIDER_THUMB, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_SPLITTER, NSAccessibilitySplitterRole },
  { WebAccessibility::ROLE_SPLIT_GROUP, NSAccessibilitySplitGroupRole },
  { WebAccessibility::ROLE_STATIC_TEXT, NSAccessibilityStaticTextRole },
  { WebAccessibility::ROLE_STATUS, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_SYSTEM_WIDE, NSAccessibilityUnknownRole },
  { WebAccessibility::ROLE_TAB, NSAccessibilityRadioButtonRole },
  { WebAccessibility::ROLE_TAB_LIST, NSAccessibilityTabGroupRole },
  { WebAccessibility::ROLE_TAB_PANEL, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_TABLE, NSAccessibilityTableRole },
  { WebAccessibility::ROLE_TABLE_HEADER_CONTAINER, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_TAB_GROUP, NSAccessibilityTabGroupRole },
  { WebAccessibility::ROLE_TEXTAREA, NSAccessibilityTextAreaRole },
  { WebAccessibility::ROLE_TEXT_FIELD, NSAccessibilityTextFieldRole },
  { WebAccessibility::ROLE_TIMER, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_TOOLBAR, NSAccessibilityToolbarRole },
  { WebAccessibility::ROLE_TOOLTIP, NSAccessibilityGroupRole },
  { WebAccessibility::ROLE_TREE, NSAccessibilityOutlineRole },
  { WebAccessibility::ROLE_TREE_GRID, NSAccessibilityTableRole },
  { WebAccessibility::ROLE_TREE_ITEM, NSAccessibilityRowRole },
  { WebAccessibility::ROLE_VALUE_INDICATOR, NSAccessibilityValueIndicatorRole },
  { WebAccessibility::ROLE_WEBCORE_LINK, NSAccessibilityLinkRole },
  { WebAccessibility::ROLE_WEB_AREA, @"AXWebArea" },
  { WebAccessibility::ROLE_WINDOW, NSAccessibilityUnknownRole },
};

static const MapEntry subroles[] = {
  { WebAccessibility::ROLE_TREE_ITEM, NSAccessibilityOutlineRowSubrole }
};

std::map<WebAccessibility::Role, NSString*> webAccessibilityToNativeRole;
std::map<WebAccessibility::Role, NSString*> webAccessibilityToNativeSubrole;

// GetState checks the bitmask used in webaccessibility.h to check
// if the given state was set on the accessibility object.
bool GetState(BrowserAccessibility* accessibility, int state) {
  return ((accessibility->state() >> state) & 1);
}

} // namespace

@implementation BrowserAccessibilityCocoa

+ (void)initialize {
  const size_t numRoles = sizeof(roles) / sizeof(roles[0]);
  for (size_t i = 0; i < numRoles; ++i) {
    webAccessibilityToNativeRole[roles[i].webKitValue] = roles[i].nativeValue;
{'fraction_non_alphanumeric': 0.09868186676166726, 'fraction_numerical': 0.0032775204845030283, 'mean_word_length': 8.12020792722547, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6269853', 'n_tokens_mistral': 4601, 'n_tokens_neox': 4366, 'n_words': 612}