use elicitation::Established;
use crate::{
CaptionedMedia, ContrastDescriptor, ContrastPair, ErrorDescriptor, ErrorField, FocusDescriptor,
FocusIndicator, KeyboardDescriptor, KeyboardPath, LabelDescriptor, LabeledElement,
LanguageDescriptor, LanguagePage, LevelAaEvidence, MediaDescriptor, OperableEvidence,
OperableInterface, PerceivedEvidence, PerceivedSection, PointerTarget, RobustEvidence,
RobustWidget, StructureDescriptor, StructuredElement, TargetDescriptor, TimedElement,
TimingDescriptor, UiResult, UnderstandableEvidence, UnderstandableInterface,
WcagAudioDescriptionPrerecorded, WcagCaptionsSynchronized, WcagCharacterShortcutsRemappable,
WcagContrastEnhancedLargeText, WcagContrastEnhancedNormalText, WcagContrastMinimumLargeText,
WcagContrastMinimumNormalText, WcagErrorIdentificationDescriptive, WcagErrorPreventionLegal,
WcagErrorSuggestionProvided, WcagFocusAppearanceEnhancedArea, WcagFocusAppearanceMinimumArea,
WcagFocusVisibleKeyboard, WcagFormLabelsProgrammatic, WcagHeadingStructureProgrammatic,
WcagKeyboardNotTrapped, WcagKeyboardOperable, WcagLabelInNameMatch,
WcagLabelsOrInstructionsPresent, WcagLevelAAValid, WcagListStructureProgrammatic,
WcagNamePresent, WcagNonTextContrastMinimum, WcagOperableValid, WcagPageLanguageIdentified,
WcagPartLanguageIdentified, WcagPerceivedValid, WcagPointerCancellationUpEvent,
WcagPointerGesturesSimpleAlternative, WcagRobustValid, WcagTableHeadersProgrammatic,
WcagTargetSizeEnhanced, WcagTargetSizeMinimum, WcagTextResizable, WcagTimingAdjustable,
WcagUnderstandableValid, WidgetId,
};
pub trait WcagContrastFactory: Send + Sync {
fn build_contrast_minimum(
&self,
input: ContrastDescriptor,
) -> UiResult<(ContrastPair, Established<WcagContrastMinimumNormalText>)>;
fn build_contrast_minimum_large(
&self,
input: ContrastDescriptor,
) -> UiResult<(ContrastPair, Established<WcagContrastMinimumLargeText>)>;
fn build_contrast_enhanced(
&self,
input: ContrastDescriptor,
) -> UiResult<(ContrastPair, Established<WcagContrastEnhancedNormalText>)>;
fn build_contrast_enhanced_large(
&self,
input: ContrastDescriptor,
) -> UiResult<(ContrastPair, Established<WcagContrastEnhancedLargeText>)>;
fn build_non_text_contrast(
&self,
input: ContrastDescriptor,
) -> UiResult<(ContrastPair, Established<WcagNonTextContrastMinimum>)>;
}
pub trait WcagLabelFactory: Send + Sync {
fn build_labeled_element(
&self,
input: LabelDescriptor,
) -> UiResult<(LabeledElement, Established<WcagNamePresent>)>;
fn build_labeled_form_field(
&self,
input: LabelDescriptor,
) -> UiResult<(LabeledElement, Established<WcagFormLabelsProgrammatic>)>;
fn build_label_in_name(
&self,
input: LabelDescriptor,
) -> UiResult<(LabeledElement, Established<WcagLabelInNameMatch>)>;
}
pub trait WcagFocusFactory: Send + Sync {
fn build_focus_visible(
&self,
input: FocusDescriptor,
) -> UiResult<(FocusIndicator, Established<WcagFocusVisibleKeyboard>)>;
fn build_focus_appearance_minimum(
&self,
input: FocusDescriptor,
) -> UiResult<(FocusIndicator, Established<WcagFocusAppearanceMinimumArea>)>;
fn build_focus_appearance_enhanced(
&self,
input: FocusDescriptor,
) -> UiResult<(FocusIndicator, Established<WcagFocusAppearanceEnhancedArea>)>;
}
pub trait WcagKeyboardFactory: Send + Sync {
fn build_keyboard_accessible(
&self,
input: KeyboardDescriptor,
) -> UiResult<(KeyboardPath, Established<WcagKeyboardOperable>)>;
fn build_keyboard_escape(
&self,
input: KeyboardDescriptor,
) -> UiResult<(KeyboardPath, Established<WcagKeyboardNotTrapped>)>;
fn build_remappable_shortcut(
&self,
input: KeyboardDescriptor,
) -> UiResult<(KeyboardPath, Established<WcagCharacterShortcutsRemappable>)>;
}
pub trait WcagTimingFactory: Send + Sync {
fn build_timed_element(
&self,
input: TimingDescriptor,
) -> UiResult<(TimedElement, Established<WcagTimingAdjustable>)>;
}
pub trait WcagTargetFactory: Send + Sync {
fn build_target_minimum(
&self,
input: TargetDescriptor,
) -> UiResult<(PointerTarget, Established<WcagTargetSizeMinimum>)>;
fn build_target_enhanced(
&self,
input: TargetDescriptor,
) -> UiResult<(PointerTarget, Established<WcagTargetSizeEnhanced>)>;
fn build_pointer_gesture_alternative(
&self,
input: TargetDescriptor,
) -> UiResult<(
PointerTarget,
Established<WcagPointerGesturesSimpleAlternative>,
)>;
fn build_pointer_cancellation(
&self,
input: TargetDescriptor,
) -> UiResult<(PointerTarget, Established<WcagPointerCancellationUpEvent>)>;
}
pub trait WcagStructureFactory: Send + Sync {
fn build_heading(
&self,
input: StructureDescriptor,
) -> UiResult<(
StructuredElement,
Established<WcagHeadingStructureProgrammatic>,
)>;
fn build_list(
&self,
input: StructureDescriptor,
) -> UiResult<(
StructuredElement,
Established<WcagListStructureProgrammatic>,
)>;
fn build_table(
&self,
input: StructureDescriptor,
) -> UiResult<(StructuredElement, Established<WcagTableHeadersProgrammatic>)>;
fn build_resizable_text(
&self,
input: StructureDescriptor,
) -> UiResult<(StructuredElement, Established<WcagTextResizable>)>;
}
pub trait WcagMediaFactory: Send + Sync {
fn build_captioned_media(
&self,
input: MediaDescriptor,
) -> UiResult<(CaptionedMedia, Established<WcagCaptionsSynchronized>)>;
fn build_audio_described_media(
&self,
input: MediaDescriptor,
) -> UiResult<(CaptionedMedia, Established<WcagAudioDescriptionPrerecorded>)>;
}
pub trait WcagLanguageFactory: Send + Sync {
fn build_language_page(
&self,
input: LanguageDescriptor,
) -> UiResult<(LanguagePage, Established<WcagPageLanguageIdentified>)>;
fn build_language_element(
&self,
input: LanguageDescriptor,
) -> UiResult<(LanguagePage, Established<WcagPartLanguageIdentified>)>;
}
pub trait WcagErrorFactory: Send + Sync {
fn build_identified_error(
&self,
input: ErrorDescriptor,
) -> UiResult<(ErrorField, Established<WcagErrorIdentificationDescriptive>)>;
fn build_labeled_field(
&self,
input: ErrorDescriptor,
) -> UiResult<(ErrorField, Established<WcagLabelsOrInstructionsPresent>)>;
fn build_error_suggestion(
&self,
input: ErrorDescriptor,
) -> UiResult<(ErrorField, Established<WcagErrorSuggestionProvided>)>;
fn build_error_prevention(
&self,
input: ErrorDescriptor,
) -> UiResult<(ErrorField, Established<WcagErrorPreventionLegal>)>;
}
pub trait WcagPerceivedFactory: Send + Sync {
fn build_perceivable(
&self,
evidence: PerceivedEvidence,
) -> (PerceivedSection, Established<WcagPerceivedValid>);
}
pub trait WcagOperableFactory: Send + Sync {
fn build_operable(
&self,
evidence: OperableEvidence,
) -> (OperableInterface, Established<WcagOperableValid>);
}
pub trait WcagUnderstandableFactory: Send + Sync {
fn build_understandable(
&self,
evidence: UnderstandableEvidence,
) -> (
UnderstandableInterface,
Established<WcagUnderstandableValid>,
);
}
pub trait WcagRobustFactory: Send + Sync {
fn build_robust(
&self,
evidence: RobustEvidence,
) -> (RobustWidget, Established<WcagRobustValid>);
}
pub trait WcagElementMeta: Send + Sync {
fn element_role(&self, id: WidgetId) -> UiResult<Option<String>>;
fn element_label(&self, id: WidgetId) -> UiResult<Option<String>>;
fn element_description(&self, id: WidgetId) -> UiResult<Option<String>>;
fn element_has_focus(&self, id: WidgetId) -> UiResult<bool>;
fn element_state(&self, id: WidgetId) -> UiResult<Option<String>>;
}
pub trait WcagPageMeta: Send + Sync {
fn page_title(&self) -> UiResult<Option<String>>;
fn page_language(&self) -> UiResult<Option<String>>;
fn navigation_landmarks(&self) -> UiResult<Vec<WidgetId>>;
fn page_headings(&self) -> UiResult<Vec<WidgetId>>;
}
pub trait WcagBackend:
WcagContrastFactory
+ WcagLabelFactory
+ WcagFocusFactory
+ WcagKeyboardFactory
+ WcagTimingFactory
+ WcagTargetFactory
+ WcagStructureFactory
+ WcagMediaFactory
+ WcagLanguageFactory
+ WcagErrorFactory
+ WcagPerceivedFactory
+ WcagOperableFactory
+ WcagUnderstandableFactory
+ WcagRobustFactory
+ WcagElementMeta
+ WcagPageMeta
+ Send
+ Sync
{
fn build_level_aa(&self, evidence: LevelAaEvidence) -> Established<WcagLevelAAValid>;
}
impl<T> WcagBackend for T
where
T: WcagContrastFactory
+ WcagLabelFactory
+ WcagFocusFactory
+ WcagKeyboardFactory
+ WcagTimingFactory
+ WcagTargetFactory
+ WcagStructureFactory
+ WcagMediaFactory
+ WcagLanguageFactory
+ WcagErrorFactory
+ WcagPerceivedFactory
+ WcagOperableFactory
+ WcagUnderstandableFactory
+ WcagRobustFactory
+ WcagElementMeta
+ WcagPageMeta
+ Send
+ Sync,
{
fn build_level_aa(&self, evidence: LevelAaEvidence) -> Established<WcagLevelAAValid> {
Established::prove(&evidence)
}
}