# Copyright 2021 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/ui.gni")
import("//components/on_device_translation/buildflags/features.gni")

if (!is_android && !is_ios) {
  static_library("live_caption") {
    sources = [
      "caption_bubble_context.h",
      "caption_bubble_context_remote.cc",
      "caption_bubble_context_remote.h",
      "caption_bubble_controller.h",
      "caption_bubble_session_observer.h",
      "caption_bubble_settings.h",
      "caption_controller_base.cc",
      "caption_controller_base.h",
      "live_caption_bubble_settings.cc",
      "live_caption_bubble_settings.h",
      "live_caption_controller.cc",
      "live_caption_controller.h",
    ]

    deps = [
      "//base",
      "//components/keyed_service/core",
      "//components/live_caption:constants",
      "//components/live_caption:utils",
      "//components/pref_registry",
      "//components/prefs",
      "//components/soda",
      "//components/soda:constants",
      "//components/sync_preferences",
      "//media",
      "//media/mojo/mojom",
      "//mojo/public/cpp/bindings",
      "//ui/native_theme",
    ]

    if (toolkit_views) {
      sources += [
        "views/caption_bubble.cc",
        "views/caption_bubble.h",
        "views/caption_bubble_controller_views.cc",
        "views/caption_bubble_controller_views.h",
        "views/caption_bubble_model.cc",
        "views/caption_bubble_model.h",
        "views/format_constants.h",
        "views/translation_view_wrapper.cc",
        "views/translation_view_wrapper.h",
        "views/translation_view_wrapper_base.cc",
        "views/translation_view_wrapper_base.h",
      ]

      public_deps = [ "//ui/base/mojom:ui_base_types" ]

      deps += [
        "//components/language/core/common",
        "//components/on_device_translation/buildflags",
        "//components/strings",
        "//components/translate/core/browser",
        "//components/vector_icons",
        "//third_party/re2",
        "//ui/accessibility",
        "//ui/base",
        "//ui/compositor",
        "//ui/gfx",
        "//ui/menus",
        "//ui/strings:ui_strings_grit",
        "//ui/views",
      ]

      if (enable_on_device_translation) {
        deps += [ "//components/on_device_translation:translation_installer" ]
      }
    }  # toolkit_views
  }

  static_library("live_translate") {
    sources = [
      "features.cc",
      "features.h",
      "google_api_translation_dispatcher.cc",
      "google_api_translation_dispatcher.h",
      "greedy_text_stabilizer.cc",
      "greedy_text_stabilizer.h",
      "live_translate_controller.cc",
      "live_translate_controller.h",
      "translation_dispatcher.h",
    ]

    public_deps = []

    deps = [
      "//base",
      "//components/keyed_service/core",
      "//components/live_caption:constants",
      "//components/live_caption:utils",
      "//components/pref_registry",
      "//components/prefs",
      "//components/soda",
      "//components/soda:constants",
      "//components/sync_preferences",
      "//content/public/browser",
      "//google_apis",
      "//media",
      "//media/mojo/mojom",
      "//net",
      "//services/data_decoder/public/cpp",
      "//services/data_decoder/public/mojom",
      "//services/network/public/cpp",
      "//services/network/public/mojom",
      "//ui/native_theme",
    ]

    if (enable_on_device_translation) {
      sources += [
        "translation_dispatcher_on_device.cc",
        "translation_dispatcher_on_device.h",
      ]
      public_deps += [
        "//components/on_device_translation:public",
        "//components/on_device_translation/public/mojom",
      ]
      deps += [ "//components/on_device_translation" ]
    }
  }

  source_set("unit_tests") {
    testonly = true

    sources = [
      "caption_controller_base_unittest.cc",
      "caption_util_unittest.cc",
      "google_api_translation_dispatcher_unittest.cc",
      "greedy_text_stabilizer_unittest.cc",
      "live_caption_bubble_settings_unittest.cc",
      "live_translate_controller_unittest.cc",
      "translation_util_unittest.cc",
    ]

    deps = [
      ":live_caption",
      ":live_translate",
      ":utils",
      "//base",
      "//base/test:test_support",
      "//components/live_caption:constants",
      "//components/prefs",
      "//components/prefs:test_support",
      "//components/sync_preferences:test_support",
      "//content/test:test_support",
      "//media",
      "//media/mojo/mojom:speech_recognition",
      "//mojo/public/cpp/bindings",
      "//net:test_support",
      "//services/network:test_support",
      "//testing/gmock",
      "//testing/gtest",
      "//ui/base",
    ]

    if (enable_on_device_translation) {
      sources += [ "translation_dispatcher_on_device_unittest.cc" ]
      deps += [
        "//components/on_device_translation",
        "//components/on_device_translation:test_support",
      ]
    }

    if (is_chromeos) {
      sources += [
        "caption_bubble_context_remote_unittest.cc",

        # This test verifies behavior of the controller
        # in an ash environment and requires ash dependencies.
        "live_caption_controller_unittest.cc",
      ]

      deps += [
        ":constants",
        "//ash/constants",
        "//components/pref_registry",
        "//components/soda",
        "//components/soda:constants",
        "//components/soda:test_support",
        "//ui/native_theme",
        "//ui/views",
      ]
    }
  }
}  # !is_android

source_set("constants") {
  sources = [
    "pref_names.cc",
    "pref_names.h",
  ]

  deps = [
    "//base",
    "//components/prefs",
    "//media",
  ]

  if (!is_android) {
    deps += [ "//components/soda:constants" ]
  }
}

source_set("utils") {
  sources = [
    "caption_util.cc",
    "caption_util.h",
    "translation_util.cc",
    "translation_util.h",
  ]

  deps = [
    ":constants",
    "//base",
    "//components/prefs",
    "//media",
    "//third_party/icu",
    "//third_party/re2",
    "//ui/base",
    "//ui/native_theme",
  ]

  if (!is_android) {
    deps += [ "//components/soda:utils" ]
  }
}
