tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

XULTextElement.cpp (2313B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "mozilla/dom/XULTextElement.h"
      8 
      9 #include "mozilla/dom/Element.h"
     10 #include "mozilla/dom/ToJSValue.h"
     11 #include "mozilla/dom/XULTextElementBinding.h"
     12 #include "nsCOMPtr.h"
     13 #include "nsChangeHint.h"
     14 #include "nsIContent.h"
     15 #include "nsIMutationObserver.h"
     16 #include "nsPresContext.h"
     17 
     18 namespace mozilla::dom {
     19 
     20 nsChangeHint XULTextElement::GetAttributeChangeHint(
     21    const nsAtom* aAttribute, AttrModType aModType) const {
     22  const bool reframe = [&] {
     23    if (aAttribute == nsGkAtoms::value) {
     24      // If we have an accesskey we need to recompute our -moz-label-content.
     25      // Otherwise this is handled by either the attribute text node, or
     26      // nsTextBoxFrame for crop="center".
     27      return IsAdditionOrRemoval(aModType) || HasAttr(nsGkAtoms::accesskey);
     28    }
     29    if (aAttribute == nsGkAtoms::crop || aAttribute == nsGkAtoms::accesskey) {
     30      // value attr + crop="center" still uses nsTextBoxFrame. accesskey
     31      // requires reframing as per the above comment.
     32      return HasAttr(nsGkAtoms::value);
     33    }
     34    return false;
     35  }();
     36  if (reframe) {
     37    return nsChangeHint_ReconstructFrame;
     38  }
     39  return nsXULElement::GetAttributeChangeHint(aAttribute, aModType);
     40 }
     41 
     42 void XULTextElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
     43                                  const nsAttrValue* aValue,
     44                                  const nsAttrValue* aOldValue,
     45                                  nsIPrincipal* aSubjectPrincipal,
     46                                  bool aNotify) {
     47  nsXULElement::AfterSetAttr(aNamespaceID, aName, aValue, aOldValue,
     48                             aSubjectPrincipal, aNotify);
     49  if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::disabled) {
     50    SetStates(ElementState::DISABLED, !!aValue, aNotify);
     51  }
     52 }
     53 
     54 JSObject* XULTextElement::WrapNode(JSContext* aCx,
     55                                   JS::Handle<JSObject*> aGivenProto) {
     56  return XULTextElement_Binding::Wrap(aCx, this, aGivenProto);
     57 }
     58 
     59 }  // namespace mozilla::dom