# Copyright 2014 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.

import("//build/config/features.gni")
import("//build/config/linux/pkg_config.gni")
import("//build/config/ui.gni")
import("//ui/base/ui_features.gni")

declare_args() {
  # Support ChromeOS touchpad gestures with ozone.
  use_evdev_gestures = false
}

if (use_xkbcommon) {
  pkg_config("xkbcommon") {
    packages = [ "xkbcommon" ]
  }
}

if (use_ozone) {
  component("events_ozone") {
    sources = [
      "chromeos/cursor_controller.cc",
      "chromeos/cursor_controller.h",
      "device/device_event.cc",
      "device/device_event.h",
      "device/device_event_observer.h",
      "device/device_manager.cc",
      "device/device_manager.h",
      "device/device_manager_manual.cc",
      "device/device_manager_manual.h",
      "device/udev/device_manager_udev.cc",
      "device/udev/device_manager_udev.h",
      "events_ozone_export.h",
      "keyboard/event_auto_repeat_handler.cc",
      "keyboard/event_auto_repeat_handler.h",
    ]

    deps = [
      "//base",
      "//base/third_party/dynamic_annotations",
      "//ui/display",
      "//ui/events",
      "//ui/events:events_base",
      "//ui/gfx",
    ]

    defines = [ "EVENTS_OZONE_IMPLEMENTATION" ]

    if (!use_udev) {
      sources -= [
        "device/udev/device_manager_udev.cc",
        "device/udev/device_manager_udev.h",
      ]
    }

    if (use_udev) {
      deps += [ "//device/udev_linux" ]
    }
  }

  config("evdev") {
    defines = [ "USE_EVDEV" ]
  }

  config("evdev_gestures") {
    defines = [ "USE_EVDEV_GESTURES" ]
  }

  if (is_linux || is_chromeos) {
    component("events_ozone_evdev") {
      sources = [
        "evdev/device_event_dispatcher_evdev.cc",
        "evdev/device_event_dispatcher_evdev.h",
        "evdev/event_converter_evdev.cc",
        "evdev/event_converter_evdev.h",
        "evdev/event_converter_evdev_impl.cc",
        "evdev/event_converter_evdev_impl.h",
        "evdev/event_device_info.cc",
        "evdev/event_device_info.h",
        "evdev/event_factory_evdev.cc",
        "evdev/event_factory_evdev.h",
        "evdev/event_thread_evdev.cc",
        "evdev/event_thread_evdev.h",
        "evdev/events_ozone_evdev_export.h",
        "evdev/gamepad_event_converter_evdev.cc",
        "evdev/gamepad_event_converter_evdev.h",
        "evdev/input_controller_evdev.cc",
        "evdev/input_controller_evdev.h",
        "evdev/input_device_factory_evdev.cc",
        "evdev/input_device_factory_evdev.h",
        "evdev/input_device_factory_evdev_proxy.cc",
        "evdev/input_device_factory_evdev_proxy.h",
        "evdev/input_device_settings_evdev.cc",
        "evdev/input_device_settings_evdev.h",
        "evdev/input_injector_evdev.cc",
        "evdev/input_injector_evdev.h",
        "evdev/keyboard_evdev.cc",
        "evdev/keyboard_evdev.h",
        "evdev/keyboard_util_evdev.cc",
        "evdev/keyboard_util_evdev.h",
        "evdev/mouse_button_map_evdev.cc",
        "evdev/mouse_button_map_evdev.h",
        "evdev/tablet_event_converter_evdev.cc",
        "evdev/tablet_event_converter_evdev.h",
        "evdev/touch_evdev_debug_buffer.cc",
        "evdev/touch_evdev_debug_buffer.h",
        "evdev/touch_evdev_types.cc",
        "evdev/touch_evdev_types.h",
        "evdev/touch_event_converter_evdev.cc",
        "evdev/touch_event_converter_evdev.h",
        "evdev/touch_filter/edge_touch_filter.cc",
        "evdev/touch_filter/edge_touch_filter.h",
        "evdev/touch_filter/false_touch_finder.cc",
        "evdev/touch_filter/false_touch_finder.h",
        "evdev/touch_filter/far_apart_taps_touch_noise_filter.cc",
        "evdev/touch_filter/far_apart_taps_touch_noise_filter.h",
        "evdev/touch_filter/horizontally_aligned_touch_noise_filter.cc",
        "evdev/touch_filter/horizontally_aligned_touch_noise_filter.h",
        "evdev/touch_filter/low_pressure_filter.cc",
        "evdev/touch_filter/low_pressure_filter.h",
        "evdev/touch_filter/single_position_touch_noise_filter.cc",
        "evdev/touch_filter/single_position_touch_noise_filter.h",
        "evdev/touch_filter/touch_filter.h",
        "gamepad/gamepad_event.cc",
        "gamepad/gamepad_event.h",
        "gamepad/gamepad_mapping.cc",
        "gamepad/gamepad_mapping.h",
        "gamepad/gamepad_observer.h",
        "gamepad/gamepad_provider_ozone.cc",
        "gamepad/gamepad_provider_ozone.h",
        "gamepad/generic_gamepad_mapping.cc",
        "gamepad/generic_gamepad_mapping.h",
        "gamepad/static_gamepad_mapping.cc",
        "gamepad/static_gamepad_mapping.h",
        "gamepad/webgamepad_constants.h",
      ]

      defines = [ "EVENTS_OZONE_EVDEV_IMPLEMENTATION" ]

      deps = [
        ":events_ozone",
        ":events_ozone_layout",
        "//base",
        "//ui/display",
        "//ui/events",
        "//ui/events:dom_keycode_converter",
        "//ui/events:events_base",
        "//ui/events/devices",
        "//ui/events/platform",
        "//ui/gfx",
        "//ui/ozone:ozone_base",
      ]

      public_configs = [ ":evdev" ]

      if (use_evdev_gestures) {
        sources += [
          "evdev/libgestures_glue/event_reader_libevdev_cros.cc",
          "evdev/libgestures_glue/event_reader_libevdev_cros.h",
          "evdev/libgestures_glue/gesture_feedback.cc",
          "evdev/libgestures_glue/gesture_feedback.h",
          "evdev/libgestures_glue/gesture_interpreter_libevdev_cros.cc",
          "evdev/libgestures_glue/gesture_interpreter_libevdev_cros.h",
          "evdev/libgestures_glue/gesture_logging.cc",
          "evdev/libgestures_glue/gesture_logging.h",
          "evdev/libgestures_glue/gesture_property_provider.cc",
          "evdev/libgestures_glue/gesture_property_provider.h",
          "evdev/libgestures_glue/gesture_timer_provider.cc",
          "evdev/libgestures_glue/gesture_timer_provider.h",
        ]

        deps += [
          "//third_party/gestures",
          "//third_party/libevdev",
        ]

        public_configs += [ ":evdev_gestures" ]
      }
    }
  }
}

component("events_ozone_layout") {
  sources = [
    "layout/events_ozone_layout_export.h",
    "layout/keyboard_layout_engine.h",
    "layout/keyboard_layout_engine_manager.cc",
    "layout/keyboard_layout_engine_manager.h",
    "layout/layout_util.cc",
    "layout/layout_util.h",
    "layout/no/no_keyboard_layout_engine.cc",
    "layout/no/no_keyboard_layout_engine.h",
    "layout/stub/stub_keyboard_layout_engine.cc",
    "layout/stub/stub_keyboard_layout_engine.h",
  ]

  defines = [ "EVENTS_OZONE_LAYOUT_IMPLEMENTATION" ]

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

  if (use_xkbcommon) {
    configs += [ ":xkbcommon" ]

    sources += [
      "layout/xkb/xkb_evdev_codes.cc",
      "layout/xkb/xkb_evdev_codes.h",
      "layout/xkb/xkb_key_code_converter.h",
      "layout/xkb/xkb_keyboard_layout_engine.cc",
      "layout/xkb/xkb_keyboard_layout_engine.h",
    ]

    deps += [ "//ui/events/keycodes:xkb" ]
  }
}