src/ui/a11y/lib/screen_reader/change_semantic_level_action.cc
// Cycles through the available semantic levels, starting at |level|, where the direction is defined
// by |direction|. If |is_slider_focused| is true, the Semantic Level kAdjustValue is part of the
// list.
Cycles through the available semantic levels, starting at |level|, where the direction is defined
by |direction|. If |is_slider_focused| is true, the Semantic Level kAdjustValue is part of the
list.
Cycles through the available semantic levels starting at |level| where the direction is defined by |direction| . If |is_slider_focused| is true the Semantic Level kAdjustValue is part of the list .
ScreenReaderContext::SemanticLevel NextSemanticLevelInDirection(
    ScreenReaderContext::SemanticLevel level, bool is_slider_focused,
    ChangeSemanticLevelAction::Direction direction) {
  static const std::vector<ScreenReaderContext::SemanticLevel> semantic_level_list = {
      ScreenReaderContext::SemanticLevel::kNormalNavigation,
      ScreenReaderContext::SemanticLevel::kAdjustValue,
      ScreenReaderContext::SemanticLevel::kCharacter, ScreenReaderContext::SemanticLevel::kWord};
  static const std::vector<ScreenReaderContext::SemanticLevel> semantic_level_list_no_sliders = {
      ScreenReaderContext::SemanticLevel::kNormalNavigation,
      ScreenReaderContext::SemanticLevel::kCharacter, ScreenReaderContext::SemanticLevel::kWord};
  decltype(semantic_level_list)* semantic_level_list_for_node;
  if (is_slider_focused) {
    semantic_level_list_for_node = &semantic_level_list;
  } else {
    semantic_level_list_for_node = &semantic_level_list_no_sliders;
  }
  auto index = 0;
  for (const auto& item : *semantic_level_list_for_node) {
    if (level == item) {
      break;
    }
    ++index;
  }
  FX_DCHECK(index < static_cast<int>(semantic_level_list_for_node->size()));
  int n = semantic_level_list_for_node->size();
  switch (direction) {
    case ChangeSemanticLevelAction::Direction::kForward:
      index = (index + 1) % n;
      break;
    case ChangeSemanticLevelAction::Direction::kBackward:
      index = (n + (index - 1)) % n;
      break;
  }
  auto new_level = semantic_level_list_for_node->at(index);
  return new_level;
}
ScreenReaderContext :: SemanticLevel NextSemanticLevelInDirection ( ScreenReaderContext :: SemanticLevel level , bool is_slider_focused , ChangeSemanticLevelAction :: Direction direction ) { static const std :: vector < ScreenReaderContext :: SemanticLevel > semantic_level_list = { ScreenReaderContext :: SemanticLevel :: kNormalNavigation , ScreenReaderContext :: SemanticLevel :: kAdjustValue , ScreenReaderContext :: SemanticLevel :: kCharacter , ScreenReaderContext :: SemanticLevel :: kWord } ; static const std :: vector < ScreenReaderContext :: SemanticLevel > semantic_level_list_no_sliders = { ScreenReaderContext :: SemanticLevel :: kNormalNavigation , ScreenReaderContext :: SemanticLevel :: kCharacter , ScreenReaderContext :: SemanticLevel :: kWord } ; decltype ( semantic_level_list ) * semantic_level_list_for_node ; if ( is_slider_focused ) { semantic_level_list_for_node = & semantic_level_list ; } else { semantic_level_list_for_node = & semantic_level_list_no_sliders ; } auto index = 0 ; for ( const auto & item : * semantic_level_list_for_node ) { if ( level == item ) { break ; } ++ index ; } FX_DCHECK ( index < static_cast < int > ( semantic_level_list_for_node -> size ( ) ) ) ; int n = semantic_level_list_for_node -> size ( ) ; switch ( direction ) { case ChangeSemanticLevelAction :: Direction :: kForward : index = ( index + 1 ) % n ; break ; case ChangeSemanticLevelAction :: Direction :: kBackward : index = ( n + ( index - 1 ) ) % n ; break ; } auto new_level = semantic_level_list_for_node -> at ( index ) ; return new_level ; }
Cycles through the available semantic levels, starting at |level|, where the direction is defined
by |direction|.
Cycles through the available semantic levels starting at |level| where the direction is defined by |direction| .
// In the first semantic level list, all semantic levels are present. In the second, all but // kAdjustValue, which is not present if the focused semantic node is a slider.