#include "chrome/browser/vr/ui_scene_creator.h"
#include <memory>
#include <numbers>
#include <string>
#include <tuple>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/i18n/case_conversion.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/vr/databinding/binding.h"
#include "chrome/browser/vr/elements/draw_phase.h"
#include "chrome/browser/vr/elements/environment/grid.h"
#include "chrome/browser/vr/elements/full_screen_rect.h"
#include "chrome/browser/vr/elements/indicator_spec.h"
#include "chrome/browser/vr/elements/linear_layout.h"
#include "chrome/browser/vr/elements/rect.h"
#include "chrome/browser/vr/elements/scaled_depth_adjuster.h"
#include "chrome/browser/vr/elements/text.h"
#include "chrome/browser/vr/elements/transient_element.h"
#include "chrome/browser/vr/elements/ui_element.h"
#include "chrome/browser/vr/elements/ui_element_name.h"
#include "chrome/browser/vr/elements/vector_icon.h"
#include "chrome/browser/vr/elements/viewport_aware_root.h"
#include "chrome/browser/vr/model/model.h"
#include "chrome/browser/vr/target_property.h"
#include "chrome/browser/vr/ui.h"
#include "chrome/browser/vr/ui_scene.h"
#include "chrome/browser/vr/ui_scene_constants.h"
#include "chrome/grit/generated_resources.h"
#include "components/strings/grit/components_strings.h"
#include "components/vector_icons/vector_icons.h"
#include "device/base/features.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/animation/keyframe/animation_curve.h"
#include "ui/gfx/animation/keyframe/keyframed_animation_curve.h"
#include "ui/gfx/geometry/transform_util.h"
#include "ui/gfx/paint_vector_icon.h"
#if BUILDFLAG(IS_WIN)
#include "chrome/browser/vr/elements/spinner.h"
#endif
namespace vr {
namespace {
template <typename V, typename C, typename S>
void BindColor(Model* model,
V* view,
C color,
const std::string& color_string,
S setter,
const std::string& setter_string) { … }
#define VR_BIND_COLOR(m, v, c, s) …
#define VR_BIND_VISIBILITY(v, c) …
template <typename T, typename... Args>
std::unique_ptr<T> Create(UiElementName name, DrawPhase phase, Args&&... args) { … }
std::unique_ptr<TransientElement> CreateTransientParent(UiElementName name,
int timeout_seconds,
bool animate_opacity) { … }
#if !BUILDFLAG(IS_ANDROID)
std::unique_ptr<UiElement> CreateSpacer(float width, float height) { … }
#endif
void BindIndicatorText(Model* model, Text* text, const IndicatorSpec& spec) { … }
std::unique_ptr<UiElement> CreateWebVrIndicator(Model* model,
IndicatorSpec spec,
DrawPhase phase) { … }
std::unique_ptr<Grid> CreateGrid(Model* model, UiElementName name) { … }
void ApplyFloorTransform(Rect* floor) { … }
void SetVisibleInLayout(UiElement* e, bool v) { … }
#if BUILDFLAG(IS_WIN)
void BindIndicatorTranscienceForWin(
TransientElement* e,
Model* model,
UiScene* scene,
const std::optional<
std::tuple<bool, CapturingStateModel, CapturingStateModel>>& last_value,
const std::tuple<bool, CapturingStateModel, CapturingStateModel>& value) {
const bool in_web_vr_presentation = model->web_vr.IsImmersiveWebXrVisible() &&
model->web_vr.has_received_permissions;
const CapturingStateModel active_capture = std::get<1>(value);
const CapturingStateModel potential_capture = std::get<2>(value);
if (!in_web_vr_presentation) {
e->SetVisibleImmediately(false);
return;
}
e->SetVisible(true);
e->RefreshVisible();
for (const auto& spec : GetIndicatorSpecs()) {
SetVisibleInLayout(
scene->GetUiElementByName(spec.webvr_name),
active_capture.*spec.signal || potential_capture.*spec.signal);
}
e->RemoveKeyframeModels(TRANSFORM);
e->SetTranslate(0, kWebVrPermissionOffsetStart, 0);
std::unique_ptr<gfx::KeyframedTransformAnimationCurve> curve(
gfx::KeyframedTransformAnimationCurve::Create());
gfx::TransformOperations value_1;
value_1.AppendTranslate(0, kWebVrPermissionOffsetStart, 0);
curve->AddKeyframe(gfx::TransformKeyframe::Create(
base::TimeDelta(), value_1,
gfx::CubicBezierTimingFunction::CreatePreset(
gfx::CubicBezierTimingFunction::EaseType::EASE)));
gfx::TransformOperations value_2;
value_2.AppendTranslate(0, kWebVrPermissionOffsetOvershoot, 0);
curve->AddKeyframe(gfx::TransformKeyframe::Create(
base::Milliseconds(kWebVrPermissionOffsetMs), value_2,
gfx::CubicBezierTimingFunction::CreatePreset(
gfx::CubicBezierTimingFunction::EaseType::EASE)));
gfx::TransformOperations value_3;
value_3.AppendTranslate(0, kWebVrPermissionOffsetFinal, 0);
curve->AddKeyframe(gfx::TransformKeyframe::Create(
base::Milliseconds(kWebVrPermissionAnimationDurationMs), value_3,
gfx::CubicBezierTimingFunction::CreatePreset(
gfx::CubicBezierTimingFunction::EaseType::EASE)));
curve->set_target(e);
e->AddKeyframeModel(gfx::KeyframeModel::Create(
std::move(curve), gfx::KeyframeEffect::GetNextKeyframeModelId(),
TRANSFORM));
}
#else
void BindIndicatorTranscience(TransientElement* e,
Model* model,
UiScene* scene,
const bool& in_web_vr_presentation) { … }
#endif
int GetIndicatorsTimeout() { … }
}
UiSceneCreator::UiSceneCreator(UiScene* scene, Ui* ui, Model* model)
: … { … }
UiSceneCreator::~UiSceneCreator() { … }
void UiSceneCreator::CreateScene() { … }
void UiSceneCreator::CreateWebVrRoot() { … }
void UiSceneCreator::CreateExternalPromptNotifcationOverlay() { … }
void UiSceneCreator::CreateWebVrSubtree() { … }
void UiSceneCreator::CreateWebVrTimeoutScreen() { … }
void UiSceneCreator::CreateViewportAwareRoot() { … }
void UiSceneCreator::CreateWebVrOverlayElements() { … }
}