parser/xml/nsSAXAttributes.cpp
author Michael Comella <michael.l.comella@gmail.com>
Tue, 15 Sep 2015 16:46:58 -0700
changeset 266944 ed8188590f14b1aae2e4f44c8196994f375a99f4
parent 201672 616c50b78907ab059a930601a3c9a470e0b96fb3
child 391687 a71af18b39d0115e57e9f2be8a58e2018873f7d4
permissions -rw-r--r--
Bug 1201206 - Correct menu button background on 2.3. r=mhaigh One fear is that different devices set different menu colors and text colors. Since we're using the default text color and set an explicit menu color, the text color may not look good on these devices. I was unable to find a way to override the menu text color. It seems the best way to find out if this is a problem is to land it and test though!

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsSAXAttributes.h"

NS_IMPL_ISUPPORTS(nsSAXAttributes, nsISAXAttributes, nsISAXMutableAttributes)

NS_IMETHODIMP
nsSAXAttributes::GetIndexFromName(const nsAString &aURI,
                                  const nsAString &aLocalName,
                                  int32_t *aResult)
{
  int32_t len = mAttrs.Length();
  int32_t i;
  for (i = 0; i < len; ++i) {
    const SAXAttr &att = mAttrs[i];
    if (att.localName.Equals(aLocalName) && att.uri.Equals(aURI)) {
      *aResult = i;
      return NS_OK;
    }
  }
  *aResult = -1;

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::GetIndexFromQName(const nsAString &aQName, int32_t *aResult)
{
  int32_t len = mAttrs.Length();
  int32_t i;
  for (i = 0; i < len; ++i) {
    const SAXAttr &att = mAttrs[i];
    if (att.qName.Equals(aQName)) {
      *aResult = i;
      return NS_OK;
    }
  }
  *aResult = -1;

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::GetLength(int32_t *aResult)
{
  *aResult = mAttrs.Length();
  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::GetLocalName(uint32_t aIndex, nsAString &aResult)
{
  uint32_t len = mAttrs.Length();
  if (aIndex >= len) {
    aResult.SetIsVoid(true);
  } else {
    const SAXAttr &att = mAttrs[aIndex];
    aResult = att.localName;
  }

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::GetQName(uint32_t aIndex, nsAString &aResult)
{
  uint32_t len = mAttrs.Length();
  if (aIndex >= len) {
    aResult.SetIsVoid(true);
  } else {
    const SAXAttr &att = mAttrs[aIndex];
    aResult = att.qName;
  }

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::GetType(uint32_t aIndex, nsAString &aResult)
{
  uint32_t len = mAttrs.Length();
  if (aIndex >= len) {
    aResult.SetIsVoid(true);
  } else {
    const SAXAttr &att = mAttrs[aIndex];
    aResult = att.type;
  }

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::GetTypeFromName(const nsAString &aURI,
                                 const nsAString &aLocalName,
                                 nsAString &aResult)
{
  int32_t index = -1;
  GetIndexFromName(aURI, aLocalName, &index);
  if (index >= 0) {
    aResult = mAttrs[index].type;
  } else {
    aResult.SetIsVoid(true);
  }

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::GetTypeFromQName(const nsAString &aQName, nsAString &aResult)
{
  int32_t index = -1;
  GetIndexFromQName(aQName, &index);
  if (index >= 0) {
    aResult = mAttrs[index].type;
  } else {
    aResult.SetIsVoid(true);
  }

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::GetURI(uint32_t aIndex, nsAString &aResult)
{
  uint32_t len = mAttrs.Length();
  if (aIndex >= len) {
    aResult.SetIsVoid(true);
  } else {
    const SAXAttr &att = mAttrs[aIndex];
    aResult = att.uri;
  }

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::GetValue(uint32_t aIndex, nsAString &aResult)
{
  uint32_t len = mAttrs.Length();
  if (aIndex >= len) {
    aResult.SetIsVoid(true);
  } else {
    const SAXAttr &att = mAttrs[aIndex];
    aResult = att.value;
  }

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::GetValueFromName(const nsAString &aURI,
                                  const nsAString &aLocalName,
                                  nsAString &aResult)
{
  int32_t index = -1;
  GetIndexFromName(aURI, aLocalName, &index);
  if (index >= 0) {
    aResult = mAttrs[index].value;
  } else {
    aResult.SetIsVoid(true);
  }

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::GetValueFromQName(const nsAString &aQName,
                                   nsAString &aResult)
{
  int32_t index = -1;
  GetIndexFromQName(aQName, &index);
  if (index >= 0) {
    aResult = mAttrs[index].value;
  } else {
    aResult.SetIsVoid(true);
  }

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::AddAttribute(const nsAString &aURI,
                              const nsAString &aLocalName,
                              const nsAString &aQName,
                              const nsAString &aType,
                              const nsAString &aValue)
{
  SAXAttr *att = mAttrs.AppendElement();
  if (!att) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  
  att->uri = aURI;
  att->localName = aLocalName;
  att->qName = aQName;
  att->type = aType;
  att->value = aValue;

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::Clear()
{
  mAttrs.Clear();

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::RemoveAttribute(uint32_t aIndex)
{
  if (aIndex >= mAttrs.Length()) {
    return NS_ERROR_FAILURE;
  }
  mAttrs.RemoveElementAt(aIndex);

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::SetAttributes(nsISAXAttributes *aAttributes)
{
  NS_ENSURE_ARG(aAttributes);

  nsresult rv;
  int32_t len;
  rv = aAttributes->GetLength(&len);
  NS_ENSURE_SUCCESS(rv, rv);

  mAttrs.Clear();
  SAXAttr *att;
  int32_t i;
  for (i = 0; i < len; ++i) {
    att = mAttrs.AppendElement();
    if (!att) {
      return NS_ERROR_OUT_OF_MEMORY;
    }
    rv = aAttributes->GetURI(i, att->uri);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = aAttributes->GetLocalName(i, att->localName);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = aAttributes->GetQName(i, att->qName);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = aAttributes->GetType(i, att->type);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = aAttributes->GetValue(i, att->value);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::SetAttribute(uint32_t aIndex,
                              const nsAString &aURI,
                              const nsAString &aLocalName,
                              const nsAString &aQName,
                              const nsAString &aType,
                              const nsAString &aValue)
{
  if (aIndex >= mAttrs.Length()) {
    return NS_ERROR_FAILURE;
  }

  SAXAttr &att = mAttrs[aIndex];
  att.uri = aURI;
  att.localName = aLocalName;
  att.qName = aQName;
  att.type = aType;
  att.value = aValue;

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::SetLocalName(uint32_t aIndex, const nsAString &aLocalName)
{
  if (aIndex >= mAttrs.Length()) {
    return NS_ERROR_FAILURE;
  }
  mAttrs[aIndex].localName = aLocalName;

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::SetQName(uint32_t aIndex, const nsAString &aQName)
{
  if (aIndex >= mAttrs.Length()) {
    return NS_ERROR_FAILURE;
  }
  mAttrs[aIndex].qName = aQName;

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::SetType(uint32_t aIndex, const nsAString &aType)
{
  if (aIndex >= mAttrs.Length()) {
    return NS_ERROR_FAILURE;
  }
  mAttrs[aIndex].type = aType;

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::SetURI(uint32_t aIndex, const nsAString &aURI)
{
  if (aIndex >= mAttrs.Length()) {
    return NS_ERROR_FAILURE;
  }
  mAttrs[aIndex].uri = aURI;

  return NS_OK;
}

NS_IMETHODIMP
nsSAXAttributes::SetValue(uint32_t aIndex, const nsAString &aValue)
{
  if (aIndex >= mAttrs.Length()) {
    return NS_ERROR_FAILURE;
  }
  mAttrs[aIndex].value = aValue;

  return NS_OK;
}