#include "ui/accessibility/platform/ax_platform_node.h"
#include "base/debug/crash_logging.h"
#include "base/no_destructor.h"
#include "build/build_config.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/accessibility/platform/ax_platform.h"
#include "ui/accessibility/platform/ax_platform_node_delegate.h"
#include "ui/base/buildflags.h"
namespace ui {
AXPlatformNode::NativeWindowHandlerCallback&
GetNativeWindowHandlerCallbackValue() {
static base::NoDestructor<AXPlatformNode::NativeWindowHandlerCallback>
callback;
return *callback;
}
gfx::NativeViewAccessible& GetPopupFocusOverrideValue() {
#if BUILDFLAG(IS_APPLE)
static base::NoDestructor<gfx::NativeViewAccessible> popup_focus_override;
return *popup_focus_override;
#else
static constinit gfx::NativeViewAccessible popup_focus_override =
gfx::NativeViewAccessible();
return popup_focus_override;
#endif
}
bool AXPlatformNode::allow_ax_mode_changes_ = true;
AXPlatformNode* AXPlatformNode::FromNativeWindow(
gfx::NativeWindow native_window) {
if (GetNativeWindowHandlerCallbackValue()) {
return GetNativeWindowHandlerCallbackValue().Run(native_window);
}
return nullptr;
}
#if !BUILDFLAG(HAS_NATIVE_ACCESSIBILITY)
AXPlatformNode* AXPlatformNode::FromNativeViewAccessible(
gfx::NativeViewAccessible accessible) {
return nullptr;
}
#endif
void AXPlatformNode::RegisterNativeWindowHandler(
AXPlatformNode::NativeWindowHandlerCallback handler) {
GetNativeWindowHandlerCallbackValue() = handler;
}
void AXPlatformNode::SetAXModeChangeAllowed(bool allow) {
allow_ax_mode_changes_ = allow;
}
AXPlatformNodeId AXPlatformNode::GetUniqueId() const {
return GetDelegate()->GetUniqueId();
}
std::string AXPlatformNode::ToString() const {
return GetDelegate()->ToString();
}
std::string AXPlatformNode::SubtreeToString() const {
return GetDelegate()->SubtreeToString();
}
std::ostream& operator<<(std::ostream& stream, AXPlatformNode& node) {
return stream << node.ToString();
}
void AXPlatformNode::SetPopupFocusOverride(
gfx::NativeViewAccessible popup_focus_override) {
GetPopupFocusOverrideValue() = popup_focus_override;
}
gfx::NativeViewAccessible AXPlatformNode::GetPopupFocusOverride() {
return GetPopupFocusOverrideValue();
}
}