#include "ui/views/interaction/interaction_sequence_views.h"
#include <string_view>
#include <utility>
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/base/interaction/interaction_sequence.h"
#include "ui/views/interaction/element_tracker_views.h"
#include "ui/views/view.h"
#include "ui/views/view_class_properties.h"
namespace views {
std::unique_ptr<ui::InteractionSequence::Step>
InteractionSequenceViews::WithInitialView(
View* view,
ui::InteractionSequence::StepStartCallback start_callback,
ui::InteractionSequence::StepEndCallback end_callback) {
auto* const element =
ElementTrackerViews::GetInstance()->GetElementForView(view);
if (element) {
return ui::InteractionSequence::WithInitialElement(
element, std::move(start_callback), std::move(end_callback));
}
ui::ElementContext context = ElementTrackerViews::GetContextForView(view);
ui::ElementIdentifier identifier = view->GetProperty(kElementIdentifierKey);
return ui::InteractionSequence::StepBuilder()
.SetContext(context)
.SetElementID(identifier)
.SetType(ui::InteractionSequence::StepType::kShown)
.SetMustBeVisibleAtStart(true)
.SetMustRemainVisible(true)
.SetStartCallback(std::move(start_callback))
.SetEndCallback(std::move(end_callback))
.Build();
}
void InteractionSequenceViews::NameView(ui::InteractionSequence* sequence,
View* view,
std::string_view name) {
ui::TrackedElement* element = nullptr;
if (view) {
element = ElementTrackerViews::GetInstance()->GetElementForView(
view, true);
DCHECK(element);
}
sequence->NameElement(element, name);
}
}