Exemplo n.º 1
0
mozilla::java::GeckoBundle::LocalRef AccessibleWrap::ToSmallBundle(
    const uint64_t aState, const nsIntRect& aBounds,
    const uint8_t aActionCount) {
  GECKOBUNDLE_START(nodeInfo);
  GECKOBUNDLE_PUT(nodeInfo, "id", java::sdk::Integer::ValueOf(VirtualViewID()));

  AccessibleWrap* parent = WrapperParent();
  GECKOBUNDLE_PUT(
      nodeInfo, "parentId",
      java::sdk::Integer::ValueOf(parent ? parent->VirtualViewID() : 0));

  uint32_t flags = GetFlags(WrapperRole(), aState, aActionCount);
  GECKOBUNDLE_PUT(nodeInfo, "flags", java::sdk::Integer::ValueOf(flags));
  GECKOBUNDLE_PUT(nodeInfo, "className",
                  java::sdk::Integer::ValueOf(AndroidClass()));

  const int32_t data[4] = {aBounds.x, aBounds.y, aBounds.x + aBounds.width,
                           aBounds.y + aBounds.height};
  GECKOBUNDLE_PUT(nodeInfo, "bounds", jni::IntArray::New(data, 4));

  auto childCount = ChildCount();
  nsTArray<int32_t> children(childCount);
  for (uint32_t i = 0; i < childCount; ++i) {
    auto child = static_cast<AccessibleWrap*>(GetChildAt(i));
    children.AppendElement(child->VirtualViewID());
  }

  GECKOBUNDLE_PUT(nodeInfo, "children",
                  jni::IntArray::New(children.Elements(), children.Length()));

  GECKOBUNDLE_FINISH(nodeInfo);

  return nodeInfo;
}
Exemplo n.º 2
0
mozilla::java::GeckoBundle::LocalRef AccessibleWrap::ToBundle(
    const uint64_t aState, const nsIntRect& aBounds, const uint8_t aActionCount,
    const nsString& aName, const nsString& aTextValue,
    const nsString& aDOMNodeID, const double& aCurVal, const double& aMinVal,
    const double& aMaxVal, const double& aStep,
    nsIPersistentProperties* aAttributes) {
  if (!IsProxy() && IsDefunct()) {
    return nullptr;
  }

  GECKOBUNDLE_START(nodeInfo);
  GECKOBUNDLE_PUT(nodeInfo, "id", java::sdk::Integer::ValueOf(VirtualViewID()));

  AccessibleWrap* parent = WrapperParent();
  GECKOBUNDLE_PUT(
      nodeInfo, "parentId",
      java::sdk::Integer::ValueOf(parent ? parent->VirtualViewID() : 0));

  role role = WrapperRole();
  uint32_t flags = GetFlags(role, aState, aActionCount);
  GECKOBUNDLE_PUT(nodeInfo, "flags", java::sdk::Integer::ValueOf(flags));
  GECKOBUNDLE_PUT(nodeInfo, "className",
                  java::sdk::Integer::ValueOf(AndroidClass()));

  if (aState & states::EDITABLE) {
    GECKOBUNDLE_PUT(nodeInfo, "hint", jni::StringParam(aName));
    GECKOBUNDLE_PUT(nodeInfo, "text", jni::StringParam(aTextValue));
  } else {
    GECKOBUNDLE_PUT(nodeInfo, "text", jni::StringParam(aName));
  }

  nsAutoString geckoRole;
  nsAutoString roleDescription;
  if (VirtualViewID() != kNoID) {
    GetRoleDescription(role, aAttributes, geckoRole, roleDescription);
  }

  GECKOBUNDLE_PUT(nodeInfo, "roleDescription",
                  jni::StringParam(roleDescription));
  GECKOBUNDLE_PUT(nodeInfo, "geckoRole", jni::StringParam(geckoRole));

  GECKOBUNDLE_PUT(nodeInfo, "roleDescription",
                  jni::StringParam(roleDescription));
  GECKOBUNDLE_PUT(nodeInfo, "geckoRole", jni::StringParam(geckoRole));

  if (!aDOMNodeID.IsEmpty()) {
    GECKOBUNDLE_PUT(nodeInfo, "viewIdResourceName",
                    jni::StringParam(aDOMNodeID));
  }

  nsIntRect bounds = Bounds();
  const int32_t data[4] = {bounds.x, bounds.y, bounds.x + bounds.width,
                           bounds.y + bounds.height};
  GECKOBUNDLE_PUT(nodeInfo, "bounds", jni::IntArray::New(data, 4));

  if (HasNumericValue()) {
    GECKOBUNDLE_START(rangeInfo);
    if (aMaxVal == 1 && aMinVal == 0) {
      GECKOBUNDLE_PUT(rangeInfo, "type",
                      java::sdk::Integer::ValueOf(2));  // percent
    } else if (std::round(aStep) != aStep) {
      GECKOBUNDLE_PUT(rangeInfo, "type",
                      java::sdk::Integer::ValueOf(1));  // float
    } else {
      GECKOBUNDLE_PUT(rangeInfo, "type",
                      java::sdk::Integer::ValueOf(0));  // integer
    }

    if (!IsNaN(aCurVal)) {
      GECKOBUNDLE_PUT(rangeInfo, "current", java::sdk::Double::New(aCurVal));
    }
    if (!IsNaN(aMinVal)) {
      GECKOBUNDLE_PUT(rangeInfo, "min", java::sdk::Double::New(aMinVal));
    }
    if (!IsNaN(aMaxVal)) {
      GECKOBUNDLE_PUT(rangeInfo, "max", java::sdk::Double::New(aMaxVal));
    }

    GECKOBUNDLE_FINISH(rangeInfo);
    GECKOBUNDLE_PUT(nodeInfo, "rangeInfo", rangeInfo);
  }

  nsString inputTypeAttr;
  nsAccUtils::GetAccAttr(aAttributes, nsGkAtoms::textInputType, inputTypeAttr);
  int32_t inputType = GetInputType(inputTypeAttr);
  if (inputType) {
    GECKOBUNDLE_PUT(nodeInfo, "inputType",
                    java::sdk::Integer::ValueOf(inputType));
  }

  nsString posinset;
  nsresult rv =
      aAttributes->GetStringProperty(NS_LITERAL_CSTRING("posinset"), posinset);
  if (NS_SUCCEEDED(rv)) {
    int32_t rowIndex;
    if (sscanf(NS_ConvertUTF16toUTF8(posinset).get(), "%d", &rowIndex) > 0) {
      GECKOBUNDLE_START(collectionItemInfo);
      GECKOBUNDLE_PUT(collectionItemInfo, "rowIndex",
                      java::sdk::Integer::ValueOf(rowIndex));
      GECKOBUNDLE_PUT(collectionItemInfo, "columnIndex",
                      java::sdk::Integer::ValueOf(0));
      GECKOBUNDLE_PUT(collectionItemInfo, "rowSpan",
                      java::sdk::Integer::ValueOf(1));
      GECKOBUNDLE_PUT(collectionItemInfo, "columnSpan",
                      java::sdk::Integer::ValueOf(1));
      GECKOBUNDLE_FINISH(collectionItemInfo);

      GECKOBUNDLE_PUT(nodeInfo, "collectionItemInfo", collectionItemInfo);
    }
  }

  nsString colSize;
  rv = aAttributes->GetStringProperty(NS_LITERAL_CSTRING("child-item-count"),
                                      colSize);
  if (NS_SUCCEEDED(rv)) {
    int32_t rowCount;
    if (sscanf(NS_ConvertUTF16toUTF8(colSize).get(), "%d", &rowCount) > 0) {
      GECKOBUNDLE_START(collectionInfo);
      GECKOBUNDLE_PUT(collectionInfo, "rowCount",
                      java::sdk::Integer::ValueOf(rowCount));
      GECKOBUNDLE_PUT(collectionInfo, "columnCount",
                      java::sdk::Integer::ValueOf(1));

      nsString unused;
      rv = aAttributes->GetStringProperty(NS_LITERAL_CSTRING("hierarchical"),
                                          unused);
      if (NS_SUCCEEDED(rv)) {
        GECKOBUNDLE_PUT(collectionInfo, "isHierarchical",
                        java::sdk::Boolean::TRUE());
      }

      if (IsSelect()) {
        int32_t selectionMode = (aState & states::MULTISELECTABLE) ? 2 : 1;
        GECKOBUNDLE_PUT(collectionInfo, "selectionMode",
                        java::sdk::Integer::ValueOf(selectionMode));
      }
      GECKOBUNDLE_FINISH(collectionInfo);

      GECKOBUNDLE_PUT(nodeInfo, "collectionInfo", collectionInfo);
    }
  }

  auto childCount = ChildCount();
  nsTArray<int32_t> children(childCount);
  for (uint32_t i = 0; i < childCount; i++) {
    auto child = static_cast<AccessibleWrap*>(GetChildAt(i));
    children.AppendElement(child->VirtualViewID());
  }

  GECKOBUNDLE_PUT(nodeInfo, "children",
                  jni::IntArray::New(children.Elements(), children.Length()));
  GECKOBUNDLE_FINISH(nodeInfo);

  return nodeInfo;
}