semantics_node.h 2.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_NODE_H_
#define FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_NODE_H_

#include <stdint.h>

#include <string>
Y
Yegor 已提交
11
#include <unordered_map>
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include <vector>

#include "third_party/skia/include/core/SkMatrix44.h"
#include "third_party/skia/include/core/SkRect.h"

namespace blink {

// Must match the SemanticsAction enum in semantics.dart.
enum class SemanticsAction : int32_t {
  kTap = 1 << 0,
  kLongPress = 1 << 1,
  kScrollLeft = 1 << 2,
  kScrollRight = 1 << 3,
  kScrollUp = 1 << 4,
  kScrollDown = 1 << 5,
  kIncrease = 1 << 6,
  kDecrease = 1 << 7,
29 30 31 32 33 34 35 36 37
  kShowOnScreen = 1 << 8,
  kMoveCursorForwardByCharacter = 1 << 9,
  kMoveCursorBackwardByCharacter = 1 << 10,
  kSetSelection = 1 << 11,
  kCopy = 1 << 12,
  kCut = 1 << 13,
  kPaste = 1 << 14,
  kDidGainAccessibilityFocus = 1 << 15,
  kDidLoseAccessibilityFocus = 1 << 16,
38 39
};

40 41 42 43 44 45
const int kScrollableSemanticsActions =
    static_cast<int32_t>(SemanticsAction::kScrollLeft) |
    static_cast<int32_t>(SemanticsAction::kScrollRight) |
    static_cast<int32_t>(SemanticsAction::kScrollUp) |
    static_cast<int32_t>(SemanticsAction::kScrollDown);

46 47 48 49
// Must match the SemanticsFlags enum in semantics.dart.
enum class SemanticsFlags : int32_t {
  kHasCheckedState = 1 << 0,
  kIsChecked = 1 << 1,
50
  kIsSelected = 1 << 2,
A
amirh 已提交
51
  kIsButton = 1 << 3,
52 53
  kIsTextField = 1 << 4,
  kIsFocused = 1 << 5,
54 55
  kHasEnabledState = 1 << 6,
  kIsEnabled = 1 << 7,
56 57
  kIsInMutuallyExclusiveGroup = 1 << 8,
  kIsHeader = 1 << 9,
58 59 60
  kIsObscured = 1 << 10,
  kScopesRoute = 1 << 11,
  kNamesRoute = 1 << 12,
61 62 63 64 65 66
};

struct SemanticsNode {
  SemanticsNode();
  ~SemanticsNode();

67 68 69
  bool HasAction(SemanticsAction action);
  bool HasFlag(SemanticsFlags flag);

70 71 72
  int32_t id = 0;
  int32_t flags = 0;
  int32_t actions = 0;
73 74
  int32_t textSelectionBase = -1;
  int32_t textSelectionExtent = -1;
75 76 77
  double scrollPosition = std::nan("");
  double scrollExtentMax = std::nan("");
  double scrollExtentMin = std::nan("");
78
  std::string label;
79 80
  std::string hint;
  std::string value;
81 82
  std::string increasedValue;
  std::string decreasedValue;
83
  int32_t textDirection = 0;  // 0=unknown, 1=rtl, 2=ltr
84
  int32_t nextNodeId = -1;
85
  int32_t previousNodeId = -1;
86

87 88 89 90 91
  SkRect rect = SkRect::MakeEmpty();
  SkMatrix44 transform = SkMatrix44(SkMatrix44::kIdentity_Constructor);
  std::vector<int32_t> children;
};

Y
Yegor 已提交
92 93 94 95 96 97
// Contains semantic nodes that need to be updated.
//
// The keys in the map are stable node IDd, and the values contain
// semantic information for the node corresponding to the ID.
using SemanticsNodeUpdates = std::unordered_map<int32_t, SemanticsNode>;

98 99 100
}  // namespace blink

#endif  // FLUTTER_LIB_UI_SEMANTICS_SEMANTICS_NODE_H_