chromium/ui/events/BUILD.gn

# Copyright 2014 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/ozone.gni")
import("//build/config/ui.gni")
import("//testing/test.gni")
import("//ui/base/ui_features.gni")

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

if (is_ios) {
  import("//ios/build/config.gni")
}

static_library("dom_keycode_converter") {
  public = [
    "keycodes/dom/dom_code.h",
    "keycodes/dom/dom_codes_array.h",
    "keycodes/dom/dom_key.h",
    "keycodes/dom/keycode_converter.h",
  ]

  sources = [
    "keycodes/dom/dom_code_data.inc",
    "keycodes/dom/dom_key_data.inc",
    "keycodes/dom/keycode_converter.cc",
  ]

  deps = [ "//base" ]

  if (!is_ios) {
    deps += [ "//ipc:param_traits" ]
  }
}

static_library("dom_keyboard_layout") {
  public = [
    "keycodes/dom/dom_keyboard_layout.h",
    "keycodes/dom/dom_keyboard_layout_manager.h",
  ]

  sources = [
    "keycodes/dom/dom_keyboard_layout.cc",
    "keycodes/dom/dom_keyboard_layout_manager.cc",
  ]

  deps = [
    ":dom_keycode_converter",
    ":events_base",
    "//base",
  ]

  if (is_win || is_mac || use_ozone) {
    public += [ "keycodes/dom/dom_keyboard_layout_map.h" ]

    sources += [
      "keycodes/dom/dom_keyboard_layout_map_base.cc",
      "keycodes/dom/dom_keyboard_layout_map_base.h",
    ]
  }

  # Make sure we don't compile two versions of dom_keyboard_layout_map*
  if (is_mac) {
    sources += [ "keycodes/dom/dom_keyboard_layout_map_mac.mm" ]
  } else if (is_win) {
    sources += [ "keycodes/dom/dom_keyboard_layout_map_win.cc" ]
  } else if (use_ozone) {
    sources += [ "keycodes/dom/dom_keyboard_layout_map_ozone.cc" ]
    deps += [ "//ui/events/ozone/layout" ]
  }

  if (!is_ios) {
    deps += [ "//ipc:param_traits" ]
  }

  # Expose the internals of this target to other packages in this BUILD file
  # so the unit tests can access the private header files.
  # Note: Only 'events_unittests' needs access in this file, however it uses a
  # template which generates different target names on different platforms.
  friend = [ ":*" ]
}

source_set("event_constants") {
  sources = [ "event_constants.h" ]
}

source_set("platform_event") {
  sources = [ "platform_event.h" ]

  public_deps = [ "//base" ]
}

component("events_base") {
  sources = [
    "base_event_utils.cc",
    "base_event_utils.h",
    "event_latency_metadata.h",
    "event_switches.cc",
    "event_switches.h",
    "events_base_export.h",
    "gesture_curve.h",
    "gesture_event_details.cc",
    "gesture_event_details.h",
    "gestures/fixed_velocity_curve.cc",
    "gestures/fixed_velocity_curve.h",
    "gestures/fling_curve.cc",
    "gestures/fling_curve.h",
    "gestures/physics_based_fling_curve.cc",
    "gestures/physics_based_fling_curve.h",
    "keycodes/dom_us_layout_data.h",
    "keycodes/keyboard_code_conversion.cc",
    "keycodes/keyboard_code_conversion.h",
    "keycodes/keyboard_codes.h",
    "mobile_scroller.cc",
    "mobile_scroller.h",
    "pointer_details.cc",
    "pointer_details.h",
  ]

  if (is_android) {
    sources += [
      "keycodes/keyboard_code_conversion_android.cc",
      "keycodes/keyboard_code_conversion_android.h",
    ]
  }

  if (is_win) {
    sources += [
      "keycodes/keyboard_code_conversion_win.cc",
      "keycodes/keyboard_code_conversion_win.h",
      "keycodes/keyboard_codes_win.h",
      "keycodes/keyboard_defines_win.h",
    ]
  }

  defines = [ "EVENTS_BASE_IMPLEMENTATION" ]

  deps = [
    ":dom_keycode_converter",
    "//build:chromeos_buildflags",
  ]

  public_deps = [
    ":event_constants",
    ":platform_event",
    "//base",
    "//ui/events/platform",
    "//ui/events/types:headers",
    "//ui/gfx/geometry",
  ]

  if (is_mac) {
    sources += [
      "keycodes/keyboard_code_conversion_mac.h",
      "keycodes/keyboard_code_conversion_mac.mm",
    ]
    deps += [ "//base:i18n" ]
  }

  if (is_fuchsia) {
    sources += [
      "keycodes/keyboard_code_conversion_fuchsia.cc",
      "keycodes/keyboard_code_conversion_fuchsia.h",
    ]

    deps += [ "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.input3:fuchsia.ui.input3_cpp" ]
  }

  if (ozone_platform_x11) {
    public_deps += [ "//ui/events/keycodes:x11" ]

    # TODO(crbug.com/40688148): This dependency on //ui/gfx/x
    # is unnecessary and should be removed.  It is included for now
    # to work around a bug in lld that introduces unnecessary
    # nondeterminism in the DSO (see c#6 on the bug for an
    # explanation).
    deps += [ "//ui/gfx/x" ]
  }

  if (!is_ios) {
    deps += [ "//ipc:param_traits" ]
  }

  if (is_mac) {
    frameworks = [
      "AppKit.framework",
      "Carbon.framework",
    ]
  }
}

component("events") {
  public = [
    "cocoa/cocoa_event_utils.h",
    "event.h",
    "event_dispatcher.h",
    "event_handler.h",
    "event_modifiers.h",
    "event_observer.h",
    "event_processor.h",
    "event_rewriter.h",
    "event_rewriter_continuation.h",
    "event_sink.h",
    "event_source.h",
    "event_target.h",
    "event_target_iterator.h",
    "event_targeter.h",
    "event_utils.h",
    "events_export.h",
    "gestures/gesture_recognizer.h",
    "gestures/gesture_types.h",
    "null_event_targeter.h",
    "scoped_target_handler.h",
  ]

  sources = [
    "event.cc",
    "event_dispatcher.cc",
    "event_handler.cc",
    "event_modifiers.cc",
    "event_processor.cc",
    "event_rewriter.cc",
    "event_source.cc",
    "event_target.cc",
    "event_targeter.cc",
    "event_utils.cc",
    "events_exports.cc",
    "events_stub.cc",
    "gestures/gesture_recognizer.cc",
    "gestures/gesture_types.cc",
    "null_event_targeter.cc",
    "scoped_target_handler.cc",
  ]

  if (is_win) {
    public += [
      "win/events_win_utils.h",
      "win/system_event_state_lookup.h",
    ]

    sources += [
      "keycodes/platform_key_map_win.cc",
      "keycodes/platform_key_map_win.h",
      "win/events_win.cc",
      "win/events_win_utils.cc",
      "win/system_event_state_lookup.cc",
    ]
  }

  if (is_mac) {
    public += [ "gestures/gesture_recognizer_impl_mac.h" ]

    sources += [
      "cocoa/cocoa_event_utils.mm",
      "cocoa/events_mac.mm",
      "gestures/gesture_recognizer_impl_mac.cc",
    ]
  }

  if (is_ios) {
    sources += [ "ios/events_ios.mm" ]
    frameworks = [ "UIKit.framework" ]
  }

  if (is_linux || is_chromeos || is_win) {
    public += [ "keyboard_event_counter.h" ]
    sources += [ "keyboard_event_counter.cc" ]
  }

  defines = [ "EVENTS_IMPLEMENTATION" ]

  public_deps = [
    ":events_base",
    "//ui/display",
    "//ui/latency",
  ]
  deps = [
    ":dom_keycode_converter",
    ":gesture_detection",
    "//skia",
    "//ui/base:features",
    "//ui/gfx",
    "//ui/gfx/geometry",
  ]

  # Expose the internals of this target to other packages in this BUILD file
  # so the unit tests can access the private header files.
  # Note: Only 'events_unittests' needs access in this file, however it uses a
  # template which generates different target names on different platforms.
  friend = [ ":*" ]

  if (ozone_platform_x11) {
    public += [ "x/x11_event_translation.h" ]
    sources += [ "x/x11_event_translation.cc" ]
    deps += [
      "//ui/base:features",
      "//ui/events/devices",
      "//ui/events/devices/x11",
      "//ui/events/x",
      "//ui/gfx/x",
    ]
  }

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

  if (use_ozone) {
    sources += [ "events_default.cc" ]
  }

  if (is_win && use_ozone) {
    sources -= [ "win/events_win.cc" ]
  }

  if (use_ozone) {
    public += [ "ozone/events_ozone.h" ]
    sources += [ "ozone/events_ozone.cc" ]
    deps += [
      "//ui/base:features",
      "//ui/events/ozone/layout",
    ]
  }

  if (use_aura) {
    public += [
      "gestures/gesture_provider_aura.h",
      "gestures/gesture_recognizer_impl.h",
      "gestures/motion_event_aura.h",
    ]
    sources += [
      "gestures/gesture_provider_aura.cc",
      "gestures/gesture_recognizer_impl.cc",
      "gestures/motion_event_aura.cc",
    ]

    deps += [ "//build:chromeos_buildflags" ]
  }

  if (is_win || is_apple || use_ozone) {
    sources -= [ "events_stub.cc" ]
  }

  if (is_android) {
    public += [
      "android/drag_event_android.h",
      "android/event_handler_android.h",
      "android/gesture_event_android.h",
      "android/gesture_event_type.h",
      "android/key_event_android.h",
      "android/key_event_utils.h",
      "android/motion_event_android.h",

      # TODO(crbug.com/40255699): Move this outside is_android block when
      # consuming cross-platform code which uses it lands.
      "back_gesture_event.h",
    ]
    sources += [
      "android/drag_event_android.cc",
      "android/event_handler_android.cc",
      "android/gesture_event_android.cc",
      "android/key_event_android.cc",
      "android/key_event_utils.cc",
      "android/motion_event_android.cc",
      "back_gesture_event.cc",
    ]
    deps += [
      ":keyevent_jni_headers",
      ":motionevent_jni_headers",
    ]
  }

  if (is_mac) {
    frameworks = [ "AppKit.framework" ]
  }

  if (is_fuchsia) {
    public += [
      "fuchsia/input_event_sink.h",
      "fuchsia/pointer_events_handler.h",
    ]
    sources += [ "fuchsia/pointer_events_handler.cc" ]
    public_deps += [
      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.input:fuchsia.ui.input_hlcpp",
      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.pointer:fuchsia.ui.pointer_cpp",
    ]
  }
}

component("keyboard_hook") {
  public = [ "keyboard_hook.h" ]

  defines = [ "IS_KEYBOARD_HOOK_IMPL" ]

  sources = [
    "keyboard_hook_base.cc",
    "keyboard_hook_base.h",
  ]

  deps = [
    "//base",
    "//ui/events",
    "//ui/events:dom_keycode_converter",
    "//ui/gfx",
  ]

  # Expose the internals of this target to other packages in this BUILD file
  # so the unit tests can access the private header files.
  friend = [ ":*" ]

  if (is_win) {
    public += [
      "win/keyboard_hook_monitor.h",
      "win/keyboard_hook_observer.h",
    ]

    sources += [
      "win/keyboard_hook_monitor_impl.cc",
      "win/keyboard_hook_monitor_impl.h",
      "win/keyboard_hook_win_base.cc",
      "win/keyboard_hook_win_base.h",
      "win/media_keyboard_hook_win.cc",
      "win/modifier_keyboard_hook_win.cc",
    ]
  }

  if (is_mac) {
    sources += [ "mac/keyboard_hook_mac.mm" ]
  }

  if (use_ozone) {
    sources += [ "ozone/keyboard_hook_ozone.cc" ]
    deps += [
      "//ui/base:features",
      "//ui/ozone",
    ]
  }

  if (is_android) {
    sources += [ "android/keyboard_hook_android.cc" ]
  }
}

component("gesture_detection") {
  sources = [
    "gesture_detection/filtered_gesture_provider.cc",
    "gesture_detection/filtered_gesture_provider.h",
    "gesture_detection/gesture_configuration.cc",
    "gesture_detection/gesture_configuration.h",
    "gesture_detection/gesture_detection_export.h",
    "gesture_detection/gesture_detector.cc",
    "gesture_detection/gesture_detector.h",
    "gesture_detection/gesture_event_data.cc",
    "gesture_detection/gesture_event_data.h",
    "gesture_detection/gesture_event_data_packet.cc",
    "gesture_detection/gesture_event_data_packet.h",
    "gesture_detection/gesture_listeners.cc",
    "gesture_detection/gesture_listeners.h",
    "gesture_detection/gesture_provider.cc",
    "gesture_detection/gesture_provider.h",
    "gesture_detection/gesture_provider_config_helper.cc",
    "gesture_detection/gesture_provider_config_helper.h",
    "gesture_detection/gesture_touch_uma_histogram.cc",
    "gesture_detection/gesture_touch_uma_histogram.h",
    "gesture_detection/scale_gesture_detector.cc",
    "gesture_detection/scale_gesture_detector.h",
    "gesture_detection/scale_gesture_listeners.cc",
    "gesture_detection/scale_gesture_listeners.h",
    "gesture_detection/snap_scroll_controller.cc",
    "gesture_detection/snap_scroll_controller.h",
    "gesture_detection/touch_disposition_gesture_filter.cc",
    "gesture_detection/touch_disposition_gesture_filter.h",
  ]

  public_deps = [ ":velocity_tracker" ]

  deps = [
    ":events_base",
    "//base",
    "//build:chromeos_buildflags",
    "//ui/base:features",
    "//ui/display",
    "//ui/gfx",
    "//ui/gfx/geometry",
    "//ui/latency",
  ]

  defines = [ "GESTURE_DETECTION_IMPLEMENTATION" ]

  if (is_android) {
    sources += [ "gesture_detection/gesture_configuration_android.cc" ]
  } else if (is_ios) {
    sources += [ "gesture_detection/gesture_configuration_ios.cc" ]
  } else if (is_castos) {
    sources += [ "gesture_detection/gesture_configuration_cast.cc" ]
  } else if (use_aura) {
    sources += [ "gesture_detection/gesture_configuration_aura.cc" ]
  } else {
    sources += [ "gesture_detection/gesture_configuration_default.cc" ]
  }
}

component("velocity_tracker") {
  sources = [
    "velocity_tracker/bitset_32.h",
    "velocity_tracker/motion_event.cc",
    "velocity_tracker/motion_event.h",
    "velocity_tracker/motion_event_buffer.cc",
    "velocity_tracker/motion_event_buffer.h",
    "velocity_tracker/motion_event_generic.cc",
    "velocity_tracker/motion_event_generic.h",
    "velocity_tracker/velocity_tracker.cc",
    "velocity_tracker/velocity_tracker.h",
    "velocity_tracker/velocity_tracker_state.cc",
    "velocity_tracker/velocity_tracker_state.h",
  ]

  defines = [ "IS_VELOCITY_TRACKER_IMPL" ]

  deps = [
    ":events_base",
    "//base",
    "//ui/gfx",
    "//ui/gfx/geometry",
  ]
}

static_library("test_support") {
  sources = [
    "test/event_generator.cc",
    "test/event_generator.h",
    "test/events_test_utils.cc",
    "test/events_test_utils.h",
    "test/keyboard_layout.cc",
    "test/keyboard_layout.h",
    "test/motion_event_test_utils.cc",
    "test/motion_event_test_utils.h",
    "test/scoped_event_waiter.cc",
    "test/scoped_event_waiter.h",
    "test/test_event.cc",
    "test/test_event.h",
    "test/test_event_handler.cc",
    "test/test_event_handler.h",
    "test/test_event_processor.cc",
    "test/test_event_processor.h",
    "test/test_event_rewriter.cc",
    "test/test_event_rewriter.h",
    "test/test_event_rewriter_continuation.h",
    "test/test_event_source.cc",
    "test/test_event_source.h",
    "test/test_event_target.cc",
    "test/test_event_target.h",
    "test/test_event_targeter.cc",
    "test/test_event_targeter.h",
  ]

  if (is_mac) {
    sources += [
      "test/cocoa_test_event_utils.h",
      "test/cocoa_test_event_utils.mm",
      "test/keyboard_layout_mac.cc",
    ]
  }

  public_deps = [
    ":dom_keycode_converter",
    ":events",
    ":events_base",
    ":gesture_detection",
    "//ui/events/devices",
  ]
  deps = [
    "//base",
    "//build:chromeos_buildflags",
    "//skia",
    "//ui/events/platform",
    "//ui/gfx",
    "//ui/gfx/geometry",
  ]

  if (is_win) {
    sources += [
      "test/keyboard_hook_monitor_utils.cc",
      "test/keyboard_hook_monitor_utils.h",
      "test/keyboard_layout_win.cc",
    ]
    deps += [ "//ui/events:keyboard_hook" ]
  }

  if (is_mac) {
    frameworks = [ "Carbon.framework" ]
  }

  if (ozone_platform_x11) {
    sources += [
      "test/events_test_utils_x11.cc",
      "test/events_test_utils_x11.h",
      "test/x11_event_waiter.cc",
      "test/x11_event_waiter.h",
    ]
    deps += [
      "//ui/events/devices/x11",
      "//ui/events/keycodes:x11",
      "//ui/events/platform/x11",
      "//ui/events/x",
      "//ui/gfx/x",
    ]
  }

  if (use_ozone) {
    deps += [
      "//ui/base:features",
      "//ui/events/ozone/layout",
    ]
  }

  if (is_fuchsia) {
    sources += [
      "fuchsia/util/pointer_event_utility.cc",
      "fuchsia/util/pointer_event_utility.h",
    ]

    deps += [ "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.pointer:fuchsia.ui.pointer_cpp" ]
  }
}

if (use_blink) {
  test("events_unittests") {
    use_xvfb = use_xvfb_in_this_config

    sources = [
      "blink/blink_event_util_unittest.cc",
      "blink/fling_booster_unittest.cc",
      "blink/web_input_event_traits_unittest.cc",
      "blink/web_input_event_unittest.cc",
      "event_dispatcher_unittest.cc",
      "event_processor_unittest.cc",
      "event_rewriter_unittest.cc",
      "event_target_unittest.cc",
      "event_unittest.cc",
      "gesture_detection/filtered_gesture_provider_unittest.cc",
      "gesture_detection/gesture_event_data_packet_unittest.cc",
      "gesture_detection/gesture_provider_unittest.cc",
      "gesture_detection/snap_scroll_controller_unittest.cc",
      "gesture_detection/touch_disposition_gesture_filter_unittest.cc",
      "gestures/blink/web_gesture_curve_impl_unittest.cc",
      "gestures/fling_curve_unittest.cc",
      "gestures/physics_based_fling_curve_unittest.cc",
      "keycodes/dom/keycode_converter_unittest.cc",
      "keycodes/keyboard_code_conversion_unittest.cc",
      "mobile_scroller_unittest.cc",
      "mojom/mojom_traits_unittest.cc",
      "platform/platform_event_source_unittest.cc",
      "scoped_target_handler_unittest.cc",
      "test/scoped_event_waiter_unittest.cc",
      "velocity_tracker/bitset_32_unittest.cc",
      "velocity_tracker/motion_event_buffer_unittest.cc",
      "velocity_tracker/motion_event_generic_unittest.cc",
      "velocity_tracker/velocity_tracker_unittest.cc",
    ]

    if (is_mac) {
      sources += [ "cocoa/events_mac_unittest.mm" ]
    }

    if (is_linux || is_chromeos || is_win) {
      sources += [ "keyboard_event_counter_unittest.cc" ]
    }

    deps = [
      ":dom_keyboard_layout",
      ":dom_keycode_converter",
      ":events",
      ":events_base",
      ":gesture_detection",
      ":test_support",
      ":velocity_tracker",
      "//base",
      "//base/test:test_support",
      "//cc",
      "//ipc:test_support",
      "//mojo/core/test:run_all_unittests",
      "//mojo/public/cpp/bindings",
      "//mojo/public/cpp/test_support:test_utils",
      "//skia",
      "//testing/gmock",
      "//testing/gtest",
      "//third_party/blink/public:blink_headers",
      "//ui/base:test_support",
      "//ui/display",
      "//ui/events/blink",
      "//ui/events/devices",
      "//ui/events/gestures/blink",
      "//ui/events/mojom",
      "//ui/events/platform",
      "//ui/gfx/geometry/mojom:mojom_traits",
      "//ui/gfx/ipc/geometry",
    ]

    if (is_android) {
      sources += [ "android/motion_event_android_unittest.cc" ]
      deps += [ "//ui/android:ui_full_java" ]
    } else {
      data_deps = [ "//third_party/angle:includes" ]
    }

    if (use_ozone) {
      sources += [ "devices/device_data_manager_unittest.cc" ]
    }

    if (use_ozone) {
      deps += [
        "//ui/events/devices:unittests",
        "//ui/events/ozone:unittests",
        "//ui/events/ozone/layout",
      ]
    }

    if (use_aura) {
      sources += [
        "gestures/gesture_provider_aura_unittest.cc",
        "gestures/motion_event_aura_unittest.cc",
      ]
    }

    if (is_win) {
      sources += [
        "blink/web_input_event_builders_win_unittest.cc",
        "keycodes/platform_key_map_win_unittest.cc",
        "win/event_utils_win_unittest.cc",
        "win/media_keyboard_hook_win_unittest.cc",
        "win/modifier_keyboard_hook_win_unittest.cc",
      ]
      deps += [ "//ui/events:keyboard_hook" ]
    }

    if (is_castos) {
      sources += [ "chromecast/scroller_unittest.cc" ]
    }

    if (is_fuchsia) {
      sources += [
        "fuchsia/pointer_events_handler_unittest.cc",
        "keycodes/keyboard_code_conversion_fuchsia_unittest.cc",
      ]

      deps += [
        "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.input:fuchsia.ui.input_hlcpp",
        "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.input3:fuchsia.ui.input3_cpp",
        "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.pointer:fuchsia.ui.pointer_cpp",
        "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.pointer:fuchsia.ui.pointer_cpp_hlcpp_conversion",
        "//third_party/fuchsia-sdk/sdk/pkg/scenic_cpp_testing",
      ]
    }

    if (is_win || is_mac || use_ozone) {
      sources += [ "keycodes/dom/dom_keyboard_layout_map_unittest.cc" ]
      deps += [ ":dom_keyboard_layout" ]
    }
  }
}

if (is_android) {
  generate_jar_jni("motionevent_jni_headers") {
    classes = [ "android/view/MotionEvent.class" ]
  }

  generate_jar_jni("keyevent_jni_headers") {
    classes = [ "android/view/KeyEvent.class" ]
  }
}

# This target is added as a dependency of browser interactive_ui_tests. It must
# be source_set, otherwise the linker will drop the tests as dead code.
source_set("events_interactive_ui_tests") {
  testonly = true
  if (is_win) {
    sources = [ "win/media_keyboard_hook_win_interactive_test.cc" ]

    deps = [
      ":events",
      ":keyboard_hook",
      ":test_support",
      "//base/test:test_support",
      "//testing/gtest",
    ]
  }
}