2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-04-17 08:03:10 +04:00
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#ifndef DirectionalityUtils_h___
|
|
|
|
#define DirectionalityUtils_h___
|
|
|
|
|
2012-12-11 19:45:50 +04:00
|
|
|
#include "nscore.h"
|
2017-08-17 02:48:52 +03:00
|
|
|
#include "nsStringFwd.h"
|
2012-11-21 14:13:57 +04:00
|
|
|
|
2012-04-17 08:03:10 +04:00
|
|
|
class nsIContent;
|
2012-11-21 14:13:57 +04:00
|
|
|
class nsAttrValue;
|
|
|
|
class nsTextNode;
|
2012-04-17 08:03:10 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class Element;
|
2018-07-21 13:11:06 +03:00
|
|
|
class HTMLSlotElement;
|
2012-04-17 08:03:10 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2016-09-07 05:20:17 +03:00
|
|
|
enum Directionality : uint8_t { eDir_NotSet, eDir_RTL, eDir_LTR, eDir_Auto };
|
2012-04-17 08:03:10 +04:00
|
|
|
|
2017-06-09 22:59:40 +03:00
|
|
|
/**
|
|
|
|
* Various methods for returning the directionality of a string using the
|
|
|
|
* first-strong algorithm defined in http://unicode.org/reports/tr9/#P2
|
|
|
|
*
|
|
|
|
* @param[out] aFirstStrong the offset to the first character in the string with
|
|
|
|
* strong directionality, or UINT32_MAX if there is none (return
|
|
|
|
value is eDir_NotSet).
|
|
|
|
* @return the directionality of the string
|
|
|
|
*/
|
|
|
|
Directionality GetDirectionFromText(const char16_t* aText,
|
|
|
|
const uint32_t aLength,
|
|
|
|
uint32_t* aFirstStrong = nullptr);
|
|
|
|
|
2012-04-17 08:03:10 +04:00
|
|
|
/**
|
|
|
|
* Set the directionality of an element according to the algorithm defined at
|
|
|
|
* http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#the-directionality,
|
|
|
|
* not including elements with auto direction.
|
|
|
|
*
|
|
|
|
* @return the directionality that the element was set to
|
|
|
|
*/
|
|
|
|
Directionality RecomputeDirectionality(mozilla::dom::Element* aElement,
|
|
|
|
bool aNotify = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the directionality of any descendants of a node that do not themselves
|
|
|
|
* have a dir attribute.
|
|
|
|
* For performance reasons we walk down the descendant tree in the rare case
|
|
|
|
* of setting the dir attribute, rather than walking up the ancestor tree in
|
|
|
|
* the much more common case of getting the element's directionality.
|
|
|
|
*/
|
2012-11-21 14:13:57 +04:00
|
|
|
void SetDirectionalityOnDescendants(mozilla::dom::Element* aElement,
|
2012-04-17 08:03:10 +04:00
|
|
|
Directionality aDir, bool aNotify = true);
|
|
|
|
|
2012-11-21 14:13:57 +04:00
|
|
|
/**
|
|
|
|
* Walk the descendants of a node in tree order and, for any text node
|
|
|
|
* descendant that determines the directionality of some element and is not a
|
|
|
|
* descendant of another descendant of the original node with dir=auto,
|
|
|
|
* redetermine that element's directionality
|
|
|
|
*/
|
|
|
|
void WalkDescendantsResetAutoDirection(mozilla::dom::Element* aElement);
|
|
|
|
|
2018-07-21 13:11:06 +03:00
|
|
|
/**
|
|
|
|
* In case a slot element was added or removed or its assigned nodes changed,
|
|
|
|
* it may change the directionality of ancestors or assigned nodes.
|
|
|
|
*/
|
|
|
|
void SlotStateChanged(mozilla::dom::HTMLSlotElement* aSlot);
|
|
|
|
|
2012-11-21 14:13:57 +04:00
|
|
|
/**
|
|
|
|
* After setting dir=auto on an element, walk its descendants in tree order.
|
|
|
|
* If the node doesn't have the NODE_ANCESTOR_HAS_DIR_AUTO flag, set the
|
|
|
|
* NODE_ANCESTOR_HAS_DIR_AUTO flag on all of its descendants.
|
|
|
|
* Resolve the directionality of the element by the "downward propagation
|
|
|
|
* algorithm" (defined in section 3 in the comments at the beginning of
|
|
|
|
* DirectionalityUtils.cpp)
|
|
|
|
*/
|
|
|
|
void WalkDescendantsSetDirAuto(mozilla::dom::Element* aElement,
|
|
|
|
bool aNotify = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* After unsetting dir=auto on an element, walk its descendants in tree order,
|
|
|
|
* skipping any that have dir=auto themselves, and unset the
|
|
|
|
* NODE_ANCESTOR_HAS_DIR_AUTO flag
|
|
|
|
*/
|
2018-07-21 13:11:06 +03:00
|
|
|
void WalkDescendantsClearAncestorDirAuto(nsIContent* aContent);
|
2012-11-21 14:13:57 +04:00
|
|
|
|
|
|
|
/**
|
2014-08-06 13:02:59 +04:00
|
|
|
* When the contents of a text node are about to change, retrieve the current
|
|
|
|
* directionality of the text
|
|
|
|
*
|
|
|
|
* @return whether the text node affects the directionality of any element
|
|
|
|
*/
|
2019-05-22 08:18:48 +03:00
|
|
|
bool TextNodeWillChangeDirection(nsTextNode* aTextNode, Directionality* aOldDir,
|
2014-08-06 13:02:59 +04:00
|
|
|
uint32_t aOffset);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* After the contents of a text node have changed, change the directionality
|
|
|
|
* of any elements whose directionality is determined by that node
|
2012-11-21 14:13:57 +04:00
|
|
|
*/
|
2016-03-19 00:21:50 +03:00
|
|
|
void TextNodeChangedDirection(nsTextNode* aTextNode, Directionality aOldDir,
|
2014-08-06 13:02:59 +04:00
|
|
|
bool aNotify);
|
2012-11-21 14:13:57 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* When a text node is appended to an element, find any ancestors with dir=auto
|
|
|
|
* whose directionality will be determined by the text node
|
|
|
|
*/
|
2016-03-19 00:21:50 +03:00
|
|
|
void SetDirectionFromNewTextNode(nsTextNode* aTextNode);
|
2012-11-21 14:13:57 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* When a text node is removed from a document, find any ancestors whose
|
|
|
|
* directionality it determined and redetermine their directionality
|
2013-08-08 10:54:18 +04:00
|
|
|
*
|
|
|
|
* @param aTextNode the text node
|
2012-11-21 14:13:57 +04:00
|
|
|
*/
|
2015-05-08 03:07:16 +03:00
|
|
|
void ResetDirectionSetByTextNode(nsTextNode* aTextNode);
|
2012-11-21 14:13:57 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the directionality of an element according to the directionality of the
|
|
|
|
* text in aValue
|
|
|
|
*/
|
|
|
|
void SetDirectionalityFromValue(mozilla::dom::Element* aElement,
|
|
|
|
const nsAString& aValue, bool aNotify);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when setting the dir attribute on an element, immediately after
|
|
|
|
* AfterSetAttr. This is instead of using BeforeSetAttr or AfterSetAttr, because
|
|
|
|
* in AfterSetAttr we don't know the old value, so we can't identify all cases
|
|
|
|
* where we need to walk up or down the document tree and reset the direction;
|
|
|
|
* and in BeforeSetAttr we can't do the walk because this element hasn't had the
|
|
|
|
* value set yet so the results will be wrong.
|
|
|
|
*/
|
|
|
|
void OnSetDirAttr(mozilla::dom::Element* aElement, const nsAttrValue* aNewValue,
|
|
|
|
bool hadValidDir, bool hadDirAuto, bool aNotify);
|
2012-04-17 08:03:10 +04:00
|
|
|
|
2013-01-06 13:45:28 +04:00
|
|
|
/**
|
|
|
|
* Called when binding a new element to the tree, to set the
|
|
|
|
* NodeAncestorHasDirAuto flag and set the direction of the element and its
|
|
|
|
* ancestors if necessary
|
|
|
|
*/
|
|
|
|
void SetDirOnBind(mozilla::dom::Element* aElement, nsIContent* aParent);
|
|
|
|
|
2013-01-06 13:45:28 +04:00
|
|
|
/**
|
|
|
|
* Called when unbinding an element from the tree, to recompute the
|
|
|
|
* directionality of the element if it doesn't have autodirection, and to
|
|
|
|
* clean up any entries in nsTextDirectionalityMap that refer to it.
|
|
|
|
*/
|
|
|
|
void ResetDir(mozilla::dom::Element* aElement);
|
2012-04-17 08:03:10 +04:00
|
|
|
} // end namespace mozilla
|
|
|
|
|
|
|
|
#endif /* DirectionalityUtils_h___ */
|