Blame dom/html/HTMLLegendElement.cpp

Packit f0b94e
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
Packit f0b94e
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
Packit f0b94e
/* This Source Code Form is subject to the terms of the Mozilla Public
Packit f0b94e
 * License, v. 2.0. If a copy of the MPL was not distributed with this
Packit f0b94e
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Packit f0b94e
Packit f0b94e
#include "mozilla/dom/HTMLLegendElement.h"
Packit f0b94e
#include "mozilla/dom/HTMLLegendElementBinding.h"
Packit f0b94e
#include "nsFocusManager.h"
Packit f0b94e
#include "nsIFrame.h"
Packit f0b94e
Packit f0b94e
NS_IMPL_NS_NEW_HTML_ELEMENT(Legend)
Packit f0b94e
Packit f0b94e
namespace mozilla {
Packit f0b94e
namespace dom {
Packit f0b94e
Packit f0b94e
HTMLLegendElement::~HTMLLegendElement() {}
Packit f0b94e
Packit f0b94e
NS_IMPL_ELEMENT_CLONE(HTMLLegendElement)
Packit f0b94e
Packit f0b94e
nsIContent* HTMLLegendElement::GetFieldSet() const {
Packit f0b94e
  nsIContent* parent = GetParent();
Packit f0b94e
Packit f0b94e
  if (parent && parent->IsHTMLElement(nsGkAtoms::fieldset)) {
Packit f0b94e
    return parent;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  return nullptr;
Packit f0b94e
}
Packit f0b94e
Packit f0b94e
bool HTMLLegendElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
Packit f0b94e
                                       const nsAString& aValue,
Packit f0b94e
                                       nsIPrincipal* aMaybeScriptedPrincipal,
Packit f0b94e
                                       nsAttrValue& aResult) {
Packit f0b94e
  // this contains center, because IE4 does
Packit f0b94e
  static const nsAttrValue::EnumTable kAlignTable[] = {
Packit f0b94e
      {"left", NS_STYLE_TEXT_ALIGN_LEFT},
Packit f0b94e
      {"right", NS_STYLE_TEXT_ALIGN_RIGHT},
Packit f0b94e
      {"center", NS_STYLE_TEXT_ALIGN_CENTER},
Packit f0b94e
      {"bottom", NS_STYLE_VERTICAL_ALIGN_BOTTOM},
Packit f0b94e
      {"top", NS_STYLE_VERTICAL_ALIGN_TOP},
Packit f0b94e
      {nullptr, 0}};
Packit f0b94e
Packit f0b94e
  if (aAttribute == nsGkAtoms::align && aNamespaceID == kNameSpaceID_None) {
Packit f0b94e
    return aResult.ParseEnumValue(aValue, kAlignTable, false);
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
Packit f0b94e
                                              aMaybeScriptedPrincipal, aResult);
Packit f0b94e
}
Packit f0b94e
Packit f0b94e
nsChangeHint HTMLLegendElement::GetAttributeChangeHint(const nsAtom* aAttribute,
Packit f0b94e
                                                       int32_t aModType) const {
Packit f0b94e
  nsChangeHint retval =
Packit f0b94e
      nsGenericHTMLElement::GetAttributeChangeHint(aAttribute, aModType);
Packit f0b94e
  if (aAttribute == nsGkAtoms::align) {
Packit f0b94e
    retval |= NS_STYLE_HINT_REFLOW;
Packit f0b94e
  }
Packit f0b94e
  return retval;
Packit f0b94e
}
Packit f0b94e
Packit f0b94e
nsresult HTMLLegendElement::BindToTree(nsIDocument* aDocument,
Packit f0b94e
                                       nsIContent* aParent,
Packit f0b94e
                                       nsIContent* aBindingParent,
Packit f0b94e
                                       bool aCompileEventHandlers) {
Packit f0b94e
  return nsGenericHTMLElement::BindToTree(aDocument, aParent, aBindingParent,
Packit f0b94e
                                          aCompileEventHandlers);
Packit f0b94e
}
Packit f0b94e
Packit f0b94e
void HTMLLegendElement::UnbindFromTree(bool aDeep, bool aNullParent) {
Packit f0b94e
  nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
Packit f0b94e
}
Packit f0b94e
Packit f0b94e
void HTMLLegendElement::Focus(ErrorResult& aError) {
Packit f0b94e
  nsIFrame* frame = GetPrimaryFrame();
Packit f0b94e
  if (!frame) {
Packit f0b94e
    return;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  int32_t tabIndex;
Packit f0b94e
  if (frame->IsFocusable(&tabIndex, false)) {
Packit f0b94e
    nsGenericHTMLElement::Focus(aError);
Packit f0b94e
    return;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  // If the legend isn't focusable, focus whatever is focusable following
Packit f0b94e
  // the legend instead, bug 81481.
Packit f0b94e
  nsIFocusManager* fm = nsFocusManager::GetFocusManager();
Packit f0b94e
  if (!fm) {
Packit f0b94e
    return;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  nsCOMPtr<nsIDOMElement> result;
Packit f0b94e
  aError = fm->MoveFocus(nullptr, this, nsIFocusManager::MOVEFOCUS_FORWARD,
Packit f0b94e
                         nsIFocusManager::FLAG_NOPARENTFRAME,
Packit f0b94e
                         getter_AddRefs(result));
Packit f0b94e
}
Packit f0b94e
Packit f0b94e
bool HTMLLegendElement::PerformAccesskey(bool aKeyCausesActivation,
Packit f0b94e
                                         bool aIsTrustedEvent) {
Packit f0b94e
  // just use the same behaviour as the focus method
Packit f0b94e
  ErrorResult rv;
Packit f0b94e
  Focus(rv);
Packit f0b94e
  return NS_SUCCEEDED(rv.StealNSResult());
Packit f0b94e
}
Packit f0b94e
Packit f0b94e
already_AddRefed<HTMLFormElement> HTMLLegendElement::GetForm() {
Packit f0b94e
  Element* form = GetFormElement();
Packit f0b94e
  MOZ_ASSERT_IF(form, form->IsHTMLElement(nsGkAtoms::form));
Packit f0b94e
  RefPtr<HTMLFormElement> ret = static_cast<HTMLFormElement*>(form);
Packit f0b94e
  return ret.forget();
Packit f0b94e
}
Packit f0b94e
Packit f0b94e
JSObject* HTMLLegendElement::WrapNode(JSContext* aCx,
Packit f0b94e
                                      JS::Handle<JSObject*> aGivenProto) {
Packit f0b94e
  return HTMLLegendElementBinding::Wrap(aCx, this, aGivenProto);
Packit f0b94e
}
Packit f0b94e
Packit f0b94e
}  // namespace dom
Packit f0b94e
}  // namespace mozilla