content/base/public/DirectionalityUtils.h

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 *
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef DirectionalityUtils_h___
michael@0 8 #define DirectionalityUtils_h___
michael@0 9
michael@0 10 #include "nscore.h"
michael@0 11
michael@0 12 class nsIContent;
michael@0 13 class nsIDocument;
michael@0 14 class nsINode;
michael@0 15 class nsAString;
michael@0 16 class nsAttrValue;
michael@0 17 class nsTextNode;
michael@0 18
michael@0 19 namespace mozilla {
michael@0 20 namespace dom {
michael@0 21 class Element;
michael@0 22 } // namespace dom
michael@0 23 } // namespace mozilla
michael@0 24
michael@0 25 namespace mozilla {
michael@0 26
michael@0 27 enum Directionality {
michael@0 28 eDir_NotSet,
michael@0 29 eDir_RTL,
michael@0 30 eDir_LTR,
michael@0 31 eDir_Auto
michael@0 32 };
michael@0 33
michael@0 34 /**
michael@0 35 * Set the directionality of an element according to the algorithm defined at
michael@0 36 * http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#the-directionality,
michael@0 37 * not including elements with auto direction.
michael@0 38 *
michael@0 39 * @return the directionality that the element was set to
michael@0 40 */
michael@0 41 Directionality RecomputeDirectionality(mozilla::dom::Element* aElement,
michael@0 42 bool aNotify = true);
michael@0 43
michael@0 44 /**
michael@0 45 * Set the directionality of any descendants of a node that do not themselves
michael@0 46 * have a dir attribute.
michael@0 47 * For performance reasons we walk down the descendant tree in the rare case
michael@0 48 * of setting the dir attribute, rather than walking up the ancestor tree in
michael@0 49 * the much more common case of getting the element's directionality.
michael@0 50 */
michael@0 51 void SetDirectionalityOnDescendants(mozilla::dom::Element* aElement,
michael@0 52 Directionality aDir,
michael@0 53 bool aNotify = true);
michael@0 54
michael@0 55 /**
michael@0 56 * Walk the descendants of a node in tree order and, for any text node
michael@0 57 * descendant that determines the directionality of some element and is not a
michael@0 58 * descendant of another descendant of the original node with dir=auto,
michael@0 59 * redetermine that element's directionality
michael@0 60 */
michael@0 61 void WalkDescendantsResetAutoDirection(mozilla::dom::Element* aElement);
michael@0 62
michael@0 63 /**
michael@0 64 * After setting dir=auto on an element, walk its descendants in tree order.
michael@0 65 * If the node doesn't have the NODE_ANCESTOR_HAS_DIR_AUTO flag, set the
michael@0 66 * NODE_ANCESTOR_HAS_DIR_AUTO flag on all of its descendants.
michael@0 67 * Resolve the directionality of the element by the "downward propagation
michael@0 68 * algorithm" (defined in section 3 in the comments at the beginning of
michael@0 69 * DirectionalityUtils.cpp)
michael@0 70 */
michael@0 71 void WalkDescendantsSetDirAuto(mozilla::dom::Element* aElement,
michael@0 72 bool aNotify = true);
michael@0 73
michael@0 74 /**
michael@0 75 * After unsetting dir=auto on an element, walk its descendants in tree order,
michael@0 76 * skipping any that have dir=auto themselves, and unset the
michael@0 77 * NODE_ANCESTOR_HAS_DIR_AUTO flag
michael@0 78 */
michael@0 79 void WalkDescendantsClearAncestorDirAuto(mozilla::dom::Element* aElement);
michael@0 80
michael@0 81 /**
michael@0 82 * When the contents of a text node are about to change, retrieve the current
michael@0 83 * directionality of the text
michael@0 84 *
michael@0 85 * @return whether the text node affects the directionality of any element
michael@0 86 */
michael@0 87 bool TextNodeWillChangeDirection(nsIContent* aTextNode, Directionality* aOldDir,
michael@0 88 uint32_t aOffset);
michael@0 89
michael@0 90 /**
michael@0 91 * After the contents of a text node have changed, change the directionality
michael@0 92 * of any elements whose directionality is determined by that node
michael@0 93 */
michael@0 94 void TextNodeChangedDirection(nsIContent* aTextNode, Directionality aOldDir,
michael@0 95 bool aNotify);
michael@0 96
michael@0 97 /**
michael@0 98 * When a text node is appended to an element, find any ancestors with dir=auto
michael@0 99 * whose directionality will be determined by the text node
michael@0 100 */
michael@0 101 void SetDirectionFromNewTextNode(nsIContent* aTextNode);
michael@0 102
michael@0 103 /**
michael@0 104 * When a text node is removed from a document, find any ancestors whose
michael@0 105 * directionality it determined and redetermine their directionality
michael@0 106 *
michael@0 107 * @param aTextNode the text node
michael@0 108 * @param aNullParent whether the the parent is also being removed
michael@0 109 * (passed from UnbindFromTree)
michael@0 110 */
michael@0 111 void ResetDirectionSetByTextNode(nsTextNode* aTextNode, bool aNullParent);
michael@0 112
michael@0 113 /**
michael@0 114 * Set the directionality of an element according to the directionality of the
michael@0 115 * text in aValue
michael@0 116 */
michael@0 117 void SetDirectionalityFromValue(mozilla::dom::Element* aElement,
michael@0 118 const nsAString& aValue,
michael@0 119 bool aNotify);
michael@0 120
michael@0 121 /**
michael@0 122 * Called when setting the dir attribute on an element, immediately after
michael@0 123 * AfterSetAttr. This is instead of using BeforeSetAttr or AfterSetAttr, because
michael@0 124 * in AfterSetAttr we don't know the old value, so we can't identify all cases
michael@0 125 * where we need to walk up or down the document tree and reset the direction;
michael@0 126 * and in BeforeSetAttr we can't do the walk because this element hasn't had the
michael@0 127 * value set yet so the results will be wrong.
michael@0 128 */
michael@0 129 void OnSetDirAttr(mozilla::dom::Element* aElement,
michael@0 130 const nsAttrValue* aNewValue,
michael@0 131 bool hadValidDir,
michael@0 132 bool hadDirAuto,
michael@0 133 bool aNotify);
michael@0 134
michael@0 135 /**
michael@0 136 * Called when binding a new element to the tree, to set the
michael@0 137 * NodeAncestorHasDirAuto flag and set the direction of the element and its
michael@0 138 * ancestors if necessary
michael@0 139 */
michael@0 140 void SetDirOnBind(mozilla::dom::Element* aElement, nsIContent* aParent);
michael@0 141
michael@0 142 /**
michael@0 143 * Called when unbinding an element from the tree, to recompute the
michael@0 144 * directionality of the element if it doesn't have autodirection, and to
michael@0 145 * clean up any entries in nsTextDirectionalityMap that refer to it.
michael@0 146 */
michael@0 147 void ResetDir(mozilla::dom::Element* aElement);
michael@0 148 } // end namespace mozilla
michael@0 149
michael@0 150 #endif /* DirectionalityUtils_h___ */

mercurial