nsAccessible*
nsXFormsSelectableAccessible::GetSelectedItem(PRUint32 aIndex)
{
  nsresult rv;
  nsCOMPtr<nsIDOMNode> DOMNode(do_QueryInterface(mContent));
  if (mIsSelect1Element) {
    if (aIndex != 0)
      return nsnull;

    nsCOMPtr<nsIDOMNode> itemDOMNode;
    rv = sXFormsService->GetSelectedItemForSelect1(DOMNode,
                                                   getter_AddRefs(itemDOMNode));
    if (NS_SUCCEEDED(rv) && itemDOMNode) {
      nsCOMPtr<nsINode> itemNode(do_QueryInterface(itemDOMNode));
      return GetAccService()->GetAccessibleInWeakShell(itemNode, mWeakShell);
    }
    return nsnull;
  }

  nsCOMPtr<nsIDOMNodeList> itemNodeList;
  rv = sXFormsService->GetSelectedItemsForSelect(DOMNode,
                                                 getter_AddRefs(itemNodeList));
  if (NS_FAILED(rv) || !itemNodeList)
    return nsnull;

  nsCOMPtr<nsIDOMNode> itemDOMNode;
  itemNodeList->Item(aIndex, getter_AddRefs(itemDOMNode));

  nsCOMPtr<nsINode> itemNode(do_QueryInterface(itemDOMNode));
  return GetAccService()->GetAccessibleInWeakShell(itemNode, mWeakShell);
}
already_AddRefed<nsIArray>
nsXFormsSelectableAccessible::SelectedItems()
{
  nsCOMPtr<nsIMutableArray> selectedItems =
    do_CreateInstance(NS_ARRAY_CONTRACTID);
  if (!selectedItems)
    return nsnull;

  nsresult rv;
  nsCOMPtr<nsIDOMNode> DOMNode(do_QueryInterface(mContent));

  if (mIsSelect1Element) {
    nsCOMPtr<nsIDOMNode> itemDOMNode;
    rv = sXFormsService->GetSelectedItemForSelect1(DOMNode,
                                                   getter_AddRefs(itemDOMNode));
    if (NS_FAILED(rv) || !itemDOMNode)
      return nsnull;

    nsCOMPtr<nsINode> itemNode(do_QueryInterface(itemDOMNode));
    nsIAccessible* item = GetAccService()->GetAccessibleInWeakShell(itemNode,
                                                                    mWeakShell);
    if (item)
      selectedItems->AppendElement(item, PR_FALSE);

    nsIMutableArray* items = nsnull;
    selectedItems.forget(&items);
    return items;
  }

  nsCOMPtr<nsIDOMNodeList> itemNodeList;
  rv = sXFormsService->GetSelectedItemsForSelect(DOMNode,
                                                 getter_AddRefs(itemNodeList));
  if (NS_FAILED(rv) || !itemNodeList)
    return nsnull;

  PRUint32 length = 0;
  itemNodeList->GetLength(&length);
  for (PRUint32 index = 0; index < length; index++) {
    nsCOMPtr<nsIDOMNode> itemDOMNode;
    itemNodeList->Item(index, getter_AddRefs(itemDOMNode));
    if (!itemDOMNode)
      return nsnull;

    nsCOMPtr<nsINode> itemNode(do_QueryInterface(itemDOMNode));
    nsIAccessible* item = GetAccService()->GetAccessibleInWeakShell(itemNode,
                                                                    mWeakShell);
    if (item)
      selectedItems->AppendElement(item, PR_FALSE);
  }

  nsIMutableArray* items = nsnull;
  selectedItems.forget(&items);
  return items;
}
示例#3
0
static inline QHash<PropertyName, QVariant> getProperties(const ModelNode &node)
{
    QHash<PropertyName, QVariant> propertyHash;
    if (QmlObjectNode::isValidQmlObjectNode(node)) {
        foreach (const AbstractProperty &abstractProperty, node.properties()) {
            if (abstractProperty.isVariantProperty()
                    || (abstractProperty.isBindingProperty()
                        && !abstractProperty.name().contains("anchors.")))
                propertyHash.insert(abstractProperty.name(), QmlObjectNode(node).instanceValue(abstractProperty.name()));
        }

        if (QmlItemNode::isValidQmlItemNode(node)) {
            QmlItemNode itemNode(node);

            propertyHash.insert("width", itemNode.instanceValue("width"));
            propertyHash.insert("height", itemNode.instanceValue("height"));
            propertyHash.remove("x");
            propertyHash.remove("y");
            propertyHash.remove("rotation");
            propertyHash.remove("opacity");
        }
    }

    return propertyHash;
}
示例#4
0
void TabViewIndexModel::setupModel()
{
    m_tabViewIndexModel.clear();
    if (m_modelNode.isValid()
            && m_modelNode.metaInfo().isValid()
            && m_modelNode.metaInfo().isSubclassOf("QtQuick.Controls.TabView")) {

        foreach (const QmlDesigner::ModelNode &childModelNode, m_modelNode.defaultNodeAbstractProperty().directSubNodes()) {
            if (childModelNode.metaInfo().isValid()
                    && childModelNode.metaInfo().isSubclassOf("QtQuick.Controls.Tab")) {
                QmlDesigner::QmlItemNode itemNode(childModelNode);
                if (itemNode.isValid()) {
                    m_tabViewIndexModel.append(itemNode.instanceValue("title").toString());
                }
            }
        }
    }
void QmlModelView::changeToState(const ModelNode &node, const QString &stateName)
{
    if (debug)
        qDebug() << this << __FUNCTION__ << node << stateName;

    QmlItemNode itemNode(node);

    QmlModelState newState;
    if (stateName.isEmpty())
        newState = baseState();
    else
        newState = itemNode.states().state(stateName);

    QmlModelState oldState = m_state;

    if (newState.isValid() && oldState != newState) {
        m_state = newState;
        stateChanged(newState, oldState);
    }
}
示例#6
0
void
nsAccUtils::GetPositionAndSizeForXULContainerItem(nsIContent *aContent,
                                                  PRInt32 *aPosInSet,
                                                  PRInt32 *aSetSize)
{
  nsCOMPtr<nsIDOMXULContainerItemElement> item(do_QueryInterface(aContent));
  if (!item)
    return;

  nsCOMPtr<nsIDOMXULContainerElement> container;
  item->GetParentContainer(getter_AddRefs(container));
  if (!container)
    return;

  // Get item count.
  PRUint32 itemsCount = 0;
  container->GetItemCount(&itemsCount);

  // Get item index.
  PRInt32 indexOf = 0;
  container->GetIndexOfItem(item, &indexOf);

  // Calculate set size and position in the set.
  *aSetSize = 0, *aPosInSet = 0;
  for (PRInt32 index = indexOf; index >= 0; index--) {
    nsCOMPtr<nsIDOMXULElement> item;
    container->GetItemAtIndex(index, getter_AddRefs(item));
    nsCOMPtr<nsINode> itemNode(do_QueryInterface(item));

    nsAccessible* itemAcc = GetAccService()->GetAccessible(itemNode);

    if (itemAcc) {
      PRUint32 itemRole = Role(itemAcc);
      if (itemRole == nsIAccessibleRole::ROLE_SEPARATOR)
        break; // We reached the beginning of our group.

      PRUint32 itemState = State(itemAcc);
      if (!(itemState & nsIAccessibleStates::STATE_INVISIBLE)) {
        (*aSetSize)++;
        (*aPosInSet)++;
      }
    }
  }

  for (PRInt32 index = indexOf + 1; index < static_cast<PRInt32>(itemsCount);
       index++) {
    nsCOMPtr<nsIDOMXULElement> item;
    container->GetItemAtIndex(index, getter_AddRefs(item));
    nsCOMPtr<nsINode> itemNode(do_QueryInterface(item));
    
    nsAccessible* itemAcc = GetAccService()->GetAccessible(itemNode);

    if (itemAcc) {
      PRUint32 itemRole = Role(itemAcc);
      if (itemRole == nsIAccessibleRole::ROLE_SEPARATOR)
        break; // We reached the end of our group.

      PRUint32 itemState = State(itemAcc);
      if (!(itemState & nsIAccessibleStates::STATE_INVISIBLE))
        (*aSetSize)++;
    }
  }
}