1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89

ash / system / video_conference / video_conference_utils.cc [blame]

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

#include "ash/system/video_conference/video_conference_utils.h"

#include <string>

#include "ash/public/cpp/style/dark_light_mode_controller.h"
#include "ash/system/video_conference/effects/video_conference_tray_effects_manager_types.h"
#include "base/strings/utf_string_conversions.h"
#include "chromeos/crosapi/mojom/video_conference.mojom.h"
#include "ui/chromeos/styles/cros_tokens_color_mappings.h"

namespace ash::video_conference_utils {

namespace {

std::string GetEffectHistogramNameBase(VcEffectId effect_id) {
  switch (effect_id) {
    case VcEffectId::kTestEffect:
      return "Ash.VideoConferenceTray.TestEffect";
    case VcEffectId::kBackgroundBlur:
      return "Ash.VideoConferenceTray.BackgroundBlur";
    case VcEffectId::kPortraitRelighting:
      return "Ash.VideoConferenceTray.PortraitRelighting";
    case VcEffectId::kNoiseCancellation:
      return "Ash.VideoConferenceTray.NoiseCancellation";
    case VcEffectId::kStyleTransfer:
      return "Ash.VideoConferenceTray.StudioMic";
    case VcEffectId::kLiveCaption:
      return "Ash.VideoConferenceTray.LiveCaption";
    case VcEffectId::kCameraFraming:
      return "Ash.VideoConferenceTray.CameraFraming";
    case VcEffectId::kFaceRetouch:
      return "Ash.VideoConferenceTray.FaceRetouch";
    case VcEffectId::kStudioLook:
      return "Ash.VideoConferenceTray.StudioLook";
  }
}

}  // namespace

std::string GetEffectHistogramNameForClick(VcEffectId effect_id) {
  return GetEffectHistogramNameBase(effect_id) + ".Click";
}

std::string GetEffectHistogramNameForInitialState(VcEffectId effect_id) {
  return GetEffectHistogramNameBase(effect_id) + ".InitialState";
}

std::u16string GetMediaAppDisplayText(
    const mojo::StructPtr<crosapi::mojom::VideoConferenceMediaAppInfo>&
        media_app) {
  auto url = media_app->url;
  auto title = media_app->title;

  // Displays the title if it is not empty. Otherwise, display app url.
  if (!title.empty()) {
    return title;
  }

  if (url) {
    return base::UTF8ToUTF16(url->GetContent());
  }

  return std::u16string();
}

cc::SkottieColorMap CreateColorMapForGradientAnimation(
    const ui::ColorProvider* color_provider) {
  cc::SkottieColorMap map;
  if (DarkLightModeController::Get()->IsDarkModeEnabled()) {
    map[cc::HashSkottieResourceId("cros.sys.illo.complement")] =
        color_provider->GetColor(
            cros_tokens::CrosRefColorIds::kCrosRefSparkleComplement20);
    map[cc::HashSkottieResourceId("cros.sys.illo.analog")] =
        color_provider->GetColor(
            cros_tokens::CrosRefColorIds::kCrosRefSparkleAnalog30);
  } else {
    map[cc::HashSkottieResourceId("cros.sys.illo.complement")] =
        color_provider->GetColor(ui::kColorNativeComplementColor);
    map[cc::HashSkottieResourceId("cros.sys.illo.analog")] =
        color_provider->GetColor(ui::kColorNativeAnalogColor);
  }
  return map;
}

}  // namespace ash::video_conference_utils