chromium/ui/accessibility/platform/BUILD.gn

# Copyright 2020 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/features.gni")
import("//build/config/linux/pkg_config.gni")
import("//build/config/ui.gni")
import("//extensions/buildflags/buildflags.gni")
import("//mojo/public/tools/bindings/mojom.gni")
import("//testing/libfuzzer/fuzzer_test.gni")
import("//testing/test.gni")
import("//tools/json_schema_compiler/json_schema_api.gni")
import("//ui/base/ui_features.gni")

if (is_win) {
  import("//build/toolchain/win/midl.gni")
}

if (is_win) {
  midl("ichromeaccessible") {
    sources = [ "ichromeaccessible.idl" ]
  }
}

if (is_android) {
  import("//build/config/android/rules.gni")
}

component("platform") {
  output_name = "accessibility_platform"

  defines = [ "IS_AX_PLATFORM_IMPL" ]

  visibility = [ "//ui/accessibility" ]

  sources = [
    "ax_node_id_delegate.h",
    "ax_platform.cc",
    "ax_platform.h",
    "ax_platform_node.cc",
    "ax_platform_node.h",
    "ax_platform_node_base.cc",
    "ax_platform_node_base.h",
    "ax_platform_node_delegate.cc",
    "ax_platform_node_delegate.h",
    "ax_platform_node_id.h",
    "ax_platform_tree_manager.cc",
    "ax_platform_tree_manager.h",
    "ax_platform_tree_manager_delegate.h",
    "ax_unique_id.cc",
    "ax_unique_id.h",
    "child_iterator.h",
    "child_iterator_base.cc",
    "child_iterator_base.h",
    "compute_attributes.cc",
    "compute_attributes.h",
    "inspect/ax_api_type.cc",
    "inspect/ax_api_type.h",
    "inspect/ax_event_recorder.cc",
    "inspect/ax_event_recorder.h",
    "inspect/ax_inspect.cc",
    "inspect/ax_inspect.h",
    "inspect/ax_inspect_scenario.cc",
    "inspect/ax_inspect_scenario.h",
    "inspect/ax_inspect_utils.cc",
    "inspect/ax_inspect_utils.h",
    "inspect/ax_optional.h",
    "inspect/ax_property_node.cc",
    "inspect/ax_property_node.h",
    "inspect/ax_script_instruction.cc",
    "inspect/ax_script_instruction.h",
    "inspect/ax_tree_formatter.cc",
    "inspect/ax_tree_formatter.h",
    "inspect/ax_tree_formatter_base.cc",
    "inspect/ax_tree_formatter_base.h",
    "inspect/ax_tree_indexer.h",
  ]

  deps = [
    "//ui/strings:auto_image_annotation_strings",
    "//ui/strings:ax_strings",
  ]

  public_deps = [
    "//ui/accessibility:accessibility_internal",
    "//ui/accessibility:ax_base",
    "//ui/base:buildflags",
    "//ui/display",
  ]

  if (enable_extensions || is_fuchsia) {
    sources += [
      # Use by the Automation API and the Accessibility service.
      # TODO(crbug.com/1357889): Rename to atp/ or javascript/?
      "automation/automation_api_util.cc",
      "automation/automation_api_util.h",
      "automation/automation_ax_tree_wrapper.cc",
      "automation/automation_ax_tree_wrapper.h",
      "automation/automation_position.cc",
      "automation/automation_position.h",
      "automation/automation_tree_manager_owner.cc",
      "automation/automation_tree_manager_owner.h",
      "automation/automation_v8_bindings.cc",
      "automation/automation_v8_bindings.h",
      "automation/automation_v8_router.cc",
      "automation/automation_v8_router.h",
      "automation/v8_handler_function_wrapper.cc",
      "automation/v8_handler_function_wrapper.h",
    ]

    deps += [
      "//base:i18n",
      "//components/crash/core/common:crash_key",
      "//gin",
      "//services/accessibility/public/mojom:automation",
    ]
  }

  if (is_android || is_chromeos_ash) {
    sources += [
      "ax_android_constants.cc",
      "ax_android_constants.h",
    ]
  }

  # BrowserAccessibility was historically used only by AXNodes
  # coming from blink and has a dependency on `cc/base/rtree.h`.
  # If we want to support using BrowserAccessibility on platforms
  # that cannot take this dependency (such as non-blink ios) we
  # will need to refactor to use a different data structure.
  # So don't build on non-blink ios for now.
  if (!(is_ios && !use_blink)) {
    sources += [
      "browser_accessibility.cc",
      "browser_accessibility.h",
      "browser_accessibility_manager.cc",
      "browser_accessibility_manager.h",
      "one_shot_accessibility_tree_search.cc",
      "one_shot_accessibility_tree_search.h",
    ]
  }

  if (is_fuchsia) {
    sources += [
      "fuchsia/accessibility_bridge_fuchsia.h",
      "fuchsia/accessibility_bridge_fuchsia_impl.cc",
      "fuchsia/accessibility_bridge_fuchsia_impl.h",
      "fuchsia/accessibility_bridge_fuchsia_registry.cc",
      "fuchsia/accessibility_bridge_fuchsia_registry.h",
      "fuchsia/ax_platform_node_fuchsia.cc",
      "fuchsia/ax_platform_node_fuchsia.h",
      "fuchsia/browser_accessibility_fuchsia.cc",
      "fuchsia/browser_accessibility_fuchsia.h",
      "fuchsia/browser_accessibility_manager_fuchsia.cc",
      "fuchsia/browser_accessibility_manager_fuchsia.h",
      "fuchsia/semantic_provider.h",
      "fuchsia/semantic_provider_impl.cc",
      "fuchsia/semantic_provider_impl.h",
      "inspect/ax_event_recorder_fuchsia.cc",
      "inspect/ax_event_recorder_fuchsia.h",
    ]

    deps += [ "//third_party/fuchsia-sdk/sdk/pkg/inspect_component_cpp" ]

    public_deps += [
      "//base",
      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.accessibility.semantics:fuchsia.accessibility.semantics_cpp",
      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.math:fuchsia.math_hlcpp",
      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.gfx:fuchsia.ui.gfx_cpp_hlcpp_conversion",
      "//third_party/fuchsia-sdk/sdk/pkg/component_incoming_cpp",
      "//third_party/fuchsia-sdk/sdk/pkg/inspect",
      "//third_party/fuchsia-sdk/sdk/pkg/scenic_cpp",
      "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
      "//ui/aura",
      "//ui/gfx/geometry",
    ]
  }

  if (has_native_accessibility) {
    sources += [
      "ax_platform_text_boundary.cc",
      "ax_platform_text_boundary.h",
    ]

    if (is_win) {
      sources += [
        "ax_fragment_root_delegate_win.h",
        "ax_fragment_root_win.cc",
        "ax_fragment_root_win.h",
        "ax_platform_node_delegate_utils_win.cc",
        "ax_platform_node_delegate_utils_win.h",
        "ax_platform_node_textchildprovider_win.cc",
        "ax_platform_node_textchildprovider_win.h",
        "ax_platform_node_textprovider_win.cc",
        "ax_platform_node_textprovider_win.h",
        "ax_platform_node_textrangeprovider_win.cc",
        "ax_platform_node_textrangeprovider_win.h",
        "ax_platform_node_win.cc",
        "ax_platform_node_win.h",
        "ax_platform_relation_win.cc",
        "ax_platform_relation_win.h",
        "ax_system_caret_win.cc",
        "ax_system_caret_win.h",
        "browser_accessibility_com_win.cc",
        "browser_accessibility_com_win.h",
        "browser_accessibility_manager_win.cc",
        "browser_accessibility_manager_win.h",
        "browser_accessibility_win.cc",
        "browser_accessibility_win.h",
        "iaccessible2/scoped_co_mem_array.h",
        "inspect/ax_call_statement_invoker_win.cc",
        "inspect/ax_call_statement_invoker_win.h",
        "inspect/ax_event_recorder_win.cc",
        "inspect/ax_event_recorder_win.h",
        "inspect/ax_event_recorder_win_uia.cc",
        "inspect/ax_event_recorder_win_uia.h",
        "inspect/ax_inspect_utils_win.cc",
        "inspect/ax_inspect_utils_win.h",
        "inspect/ax_target_win.cc",
        "inspect/ax_target_win.h",
        "inspect/ax_tree_formatter_uia_win.cc",
        "inspect/ax_tree_formatter_uia_win.h",
        "inspect/ax_tree_formatter_win.cc",
        "inspect/ax_tree_formatter_win.h",
        "inspect/ax_tree_indexer_win.h",
        "sequence_affine_com_object_root_win.h",
        "uia_registrar_win.cc",
        "uia_registrar_win.h",
      ]

      public_deps += [
        "//third_party/iaccessible2",
        "//third_party/isimpledom",
        "//ui/accessibility/platform:ichromeaccessible",
      ]

      libs = [
        "oleacc.lib",
        "uiautomationcore.lib",
      ]
    }

    if (is_mac) {
      sources += [
        "ax_event_intent_mac.h",
        "ax_event_intent_mac.mm",
        "ax_platform_node_cocoa.h",
        "ax_platform_node_cocoa.mm",
        "ax_platform_node_mac.h",
        "ax_platform_node_mac.mm",
        "ax_private_attributes_mac.h",
        "ax_private_roles_mac.h",
        "ax_private_webkit_constants_mac.h",
        "ax_private_webkit_constants_mac.mm",
        "ax_utils_mac.h",
        "ax_utils_mac.mm",
        "browser_accessibility_cocoa.h",
        "browser_accessibility_cocoa.mm",
        "browser_accessibility_mac.h",
        "browser_accessibility_mac.mm",
        "browser_accessibility_manager_mac.h",
        "browser_accessibility_manager_mac.mm",
        "inspect/ax_call_statement_invoker_mac.h",
        "inspect/ax_call_statement_invoker_mac.mm",
        "inspect/ax_element_wrapper_mac.h",
        "inspect/ax_element_wrapper_mac.mm",
        "inspect/ax_event_recorder_mac.h",
        "inspect/ax_event_recorder_mac.mm",
        "inspect/ax_inspect_utils_mac.h",
        "inspect/ax_inspect_utils_mac.mm",
        "inspect/ax_transform_mac.h",
        "inspect/ax_transform_mac.mm",
        "inspect/ax_tree_formatter_mac.h",
        "inspect/ax_tree_formatter_mac.mm",
        "inspect/ax_tree_indexer_mac.h",
      ]

      deps += [ "//ui/accelerated_widget_mac" ]

      frameworks = [
        "Accessibility.framework",
        "AppKit.framework",
        "Foundation.framework",
      ]
    }

    if (is_ios) {
      sources += [
        "ax_platform_node_ios.h",
        "ax_platform_node_ios.mm",
        "ax_platform_node_ui_kit_element.h",
        "ax_platform_node_ui_kit_element.mm",
        "browser_accessibility_ios.h",
        "browser_accessibility_ios.mm",
        "browser_accessibility_manager_ios.h",
        "browser_accessibility_manager_ios.mm",
      ]

      frameworks = [
        "Accessibility.framework",
        "UIKit.framework",
        "Foundation.framework",
      ]
    }

    if (use_atk) {
      sources += [
        "atk_util_auralinux.cc",
        "atk_util_auralinux.h",
        "atk_util_auralinux_gtk.cc",
        "ax_platform_atk_hyperlink.cc",
        "ax_platform_atk_hyperlink.h",
        "ax_platform_node_auralinux.cc",
        "ax_platform_node_auralinux.h",
        "browser_accessibility_auralinux.cc",
        "browser_accessibility_auralinux.h",
        "browser_accessibility_manager_auralinux.cc",
        "browser_accessibility_manager_auralinux.h",
        "inspect/ax_call_statement_invoker_auralinux.cc",
        "inspect/ax_call_statement_invoker_auralinux.h",
        "inspect/ax_event_recorder_auralinux.cc",
        "inspect/ax_event_recorder_auralinux.h",
        "inspect/ax_inspect_utils_auralinux.cc",
        "inspect/ax_inspect_utils_auralinux.h",
        "inspect/ax_tree_formatter_auralinux.cc",
        "inspect/ax_tree_formatter_auralinux.h",
        "inspect/ax_tree_indexer.h",
        "inspect/ax_tree_indexer_auralinux.h",
      ]

      configs += [ "//build/config/linux/atspi2" ]

      # ax_platform_text_boundary.h includes atk.h, so ATK is needed
      # as a public config to ensure anything that includes this is
      # able to find atk.h.
      public_configs = [ "//build/config/linux/atk" ]

      if (use_glib) {
        configs += [ "//build/config/linux:glib" ]
      }
      if (use_gio) {
        configs += [ "//build/linux:gio_config" ]
      }
    }
  }
}