Bug 1147412 part 10 - Clean up nsHTMLCSSUtils::Get*Property, GetCSSInlinePropertyBase; r=ehsan

This commit is contained in:
Aryeh Gregor 2015-04-19 15:28:50 +03:00
parent cd0831c08e
commit 5028cd21a1
8 changed files with 88 additions and 111 deletions

View File

@ -88,20 +88,17 @@ nsHTMLEditor::GetAbsolutelyPositionedSelectionContainer(nsIDOMElement **_retval)
NS_ENSURE_SUCCESS(res, res);
nsAutoString positionStr;
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(element);
nsCOMPtr<nsINode> node = do_QueryInterface(element);
nsCOMPtr<nsIDOMNode> resultNode;
while (!resultNode && node && !nsEditor::NodeIsType(node, nsGkAtoms::html)) {
res = mHTMLCSSUtils->GetComputedProperty(node, nsGkAtoms::position,
while (!resultNode && node && !node->IsHTMLElement(nsGkAtoms::html)) {
res = mHTMLCSSUtils->GetComputedProperty(*node, *nsGkAtoms::position,
positionStr);
NS_ENSURE_SUCCESS(res, res);
if (positionStr.EqualsLiteral("absolute"))
resultNode = node;
resultNode = GetAsDOMNode(node);
else {
nsCOMPtr<nsIDOMNode> parentNode;
res = node->GetParentNode(getter_AddRefs(parentNode));
NS_ENSURE_SUCCESS(res, res);
node.swap(parentNode);
node = node->GetParentNode();
}
}
@ -195,11 +192,13 @@ NS_IMETHODIMP
nsHTMLEditor::GetElementZIndex(nsIDOMElement * aElement,
int32_t * aZindex)
{
nsCOMPtr<Element> element = do_QueryInterface(aElement);
NS_ENSURE_STATE(element || !aElement);
nsAutoString zIndexStr;
*aZindex = 0;
nsresult res = mHTMLCSSUtils->GetSpecifiedProperty(aElement,
nsGkAtoms::z_index,
nsresult res = mHTMLCSSUtils->GetSpecifiedProperty(*element,
*nsGkAtoms::z_index,
zIndexStr);
NS_ENSURE_SUCCESS(res, res);
if (zIndexStr.EqualsLiteral("auto")) {
@ -208,24 +207,21 @@ nsHTMLEditor::GetElementZIndex(nsIDOMElement * aElement,
nsCOMPtr<nsIDOMNode> parentNode;
res = aElement->GetParentNode(getter_AddRefs(parentNode));
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMNode> node = parentNode;
nsCOMPtr<nsINode> node = do_QueryInterface(parentNode);
nsAutoString positionStr;
while (node &&
zIndexStr.EqualsLiteral("auto") &&
!nsTextEditUtils::IsBody(node)) {
res = mHTMLCSSUtils->GetComputedProperty(node, nsGkAtoms::position,
while (node && zIndexStr.EqualsLiteral("auto") &&
!node->IsHTMLElement(nsGkAtoms::body)) {
res = mHTMLCSSUtils->GetComputedProperty(*node, *nsGkAtoms::position,
positionStr);
NS_ENSURE_SUCCESS(res, res);
if (positionStr.EqualsLiteral("absolute")) {
// ah, we found one, what's its z-index ? If its z-index is auto,
// we have to continue climbing the document's tree
res = mHTMLCSSUtils->GetComputedProperty(node, nsGkAtoms::z_index,
res = mHTMLCSSUtils->GetComputedProperty(*node, *nsGkAtoms::z_index,
zIndexStr);
NS_ENSURE_SUCCESS(res, res);
}
res = node->GetParentNode(getter_AddRefs(parentNode));
NS_ENSURE_SUCCESS(res, res);
node = parentNode;
node = node->GetParentNode();
}
}
@ -485,7 +481,7 @@ nsHTMLEditor::AbsolutelyPositionElement(nsIDOMElement* aElement,
NS_ENSURE_ARG_POINTER(element);
nsAutoString positionStr;
mHTMLCSSUtils->GetComputedProperty(aElement, nsGkAtoms::position,
mHTMLCSSUtils->GetComputedProperty(*element, *nsGkAtoms::position,
positionStr);
bool isPositioned = (positionStr.EqualsLiteral("absolute"));
@ -621,13 +617,13 @@ nsHTMLEditor::CheckPositionedElementBGandFG(nsIDOMElement * aElement,
nsAutoString bgImageStr;
nsresult res =
mHTMLCSSUtils->GetComputedProperty(aElement, nsGkAtoms::background_image,
mHTMLCSSUtils->GetComputedProperty(*element, *nsGkAtoms::background_image,
bgImageStr);
NS_ENSURE_SUCCESS(res, res);
if (bgImageStr.EqualsLiteral("none")) {
nsAutoString bgColorStr;
res =
mHTMLCSSUtils->GetComputedProperty(aElement, nsGkAtoms::backgroundColor,
mHTMLCSSUtils->GetComputedProperty(*element, *nsGkAtoms::backgroundColor,
bgColorStr);
NS_ENSURE_SUCCESS(res, res);
if (bgColorStr.EqualsLiteral("transparent")) {

View File

@ -416,7 +416,7 @@ nsHTMLEditor::GetPositionAndDimensions(nsIDOMElement * aElement,
if (!isPositioned) {
// hmmm... the expensive way now...
nsAutoString positionStr;
mHTMLCSSUtils->GetComputedProperty(aElement, nsGkAtoms::position,
mHTMLCSSUtils->GetComputedProperty(*element, *nsGkAtoms::position,
positionStr);
isPositioned = positionStr.EqualsLiteral("absolute");
}

View File

@ -479,26 +479,17 @@ nsHTMLCSSUtils::CreateCSSPropertyTxn(Element& aElement, nsIAtom& aAttribute,
}
nsresult
nsHTMLCSSUtils::GetSpecifiedProperty(nsIDOMNode *aNode, nsIAtom *aProperty,
nsAString & aValue)
nsHTMLCSSUtils::GetSpecifiedProperty(nsINode& aNode, nsIAtom& aProperty,
nsAString& aValue)
{
return GetCSSInlinePropertyBase(aNode, aProperty, aValue, eSpecified);
return GetCSSInlinePropertyBase(&aNode, &aProperty, aValue, eSpecified);
}
nsresult
nsHTMLCSSUtils::GetComputedProperty(nsIDOMNode *aNode, nsIAtom *aProperty,
nsAString & aValue)
nsHTMLCSSUtils::GetComputedProperty(nsINode& aNode, nsIAtom& aProperty,
nsAString& aValue)
{
return GetCSSInlinePropertyBase(aNode, aProperty, aValue, eComputed);
}
nsresult
nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsIDOMNode* aNode, nsIAtom* aProperty,
nsAString& aValue,
StyleType aStyleType)
{
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
return GetCSSInlinePropertyBase(node, aProperty, aValue, aStyleType);
return GetCSSInlinePropertyBase(&aNode, &aProperty, aValue, eComputed);
}
nsresult

View File

@ -117,17 +117,17 @@ public:
const nsAString & aProperty,
int32_t aIntValue);
/** gets the specified/computed style value of a CSS property for a given node (or its element
* ancestor if it is not an element)
/** Gets the specified/computed style value of a CSS property for a given
* node (or its element ancestor if it is not an element)
*
* @param aNode [IN] a DOM node
* @param aProperty [IN] an atom containing the CSS property to get
* @param aPropertyValue [OUT] the retrieved value of the property
*/
nsresult GetSpecifiedProperty(nsIDOMNode *aNode, nsIAtom *aProperty,
nsAString & aValue);
nsresult GetComputedProperty(nsIDOMNode *aNode, nsIAtom *aProperty,
nsAString & aValue);
nsresult GetSpecifiedProperty(nsINode& aNode, nsIAtom& aProperty,
nsAString& aValue);
nsresult GetComputedProperty(nsINode& aNode, nsIAtom& aProperty,
nsAString& aValue);
/** Removes a CSS property from the specified declarations in STYLE attribute
** and removes the node if it is an useless span
@ -401,8 +401,6 @@ private:
*/
nsresult GetCSSInlinePropertyBase(nsINode* aNode, nsIAtom* aProperty,
nsAString& aValue, StyleType aStyleType);
nsresult GetCSSInlinePropertyBase(nsIDOMNode* aNode, nsIAtom* aProperty,
nsAString& aValue, StyleType aStyleType);
private:

View File

@ -943,9 +943,12 @@ nsHTMLEditRules::GetAlignment(bool *aMixed, nsIHTMLEditor::EAlignment *aAlign)
return NS_OK;
}
nsIAtom* MarginPropertyAtomForIndent(nsHTMLCSSUtils* aHTMLCSSUtils, nsIDOMNode* aNode) {
static nsIAtom* MarginPropertyAtomForIndent(nsHTMLCSSUtils* aHTMLCSSUtils,
nsIDOMNode* aNode) {
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
NS_ENSURE_TRUE(node || !aNode, nsGkAtoms::marginLeft);
nsAutoString direction;
aHTMLCSSUtils->GetComputedProperty(aNode, nsGkAtoms::direction, direction);
aHTMLCSSUtils->GetComputedProperty(*node, *nsGkAtoms::direction, direction);
return direction.EqualsLiteral("rtl") ?
nsGkAtoms::marginRight : nsGkAtoms::marginLeft;
}
@ -976,21 +979,24 @@ nsHTMLEditRules::GetIndentState(bool *aCanIndent, bool *aCanOutdent)
bool useCSS = mHTMLEditor->IsCSSEnabled();
for (i=listCount-1; i>=0; i--)
{
nsCOMPtr<nsIDOMNode> curNode = arrayOfNodes[i];
nsCOMPtr<nsINode> curNode = do_QueryInterface(arrayOfNodes[i]);
NS_ENSURE_STATE(curNode || !arrayOfNodes[i]);
if (nsHTMLEditUtils::IsNodeThatCanOutdent(curNode))
{
if (nsHTMLEditUtils::IsNodeThatCanOutdent(GetAsDOMNode(curNode))) {
*aCanOutdent = true;
break;
}
else if (useCSS) {
// we are in CSS mode, indentation is done using the margin-left (or margin-right) property
NS_ENSURE_STATE(mHTMLEditor);
nsIAtom* marginProperty = MarginPropertyAtomForIndent(mHTMLEditor->mHTMLCSSUtils, curNode);
nsIAtom* marginProperty =
MarginPropertyAtomForIndent(mHTMLEditor->mHTMLCSSUtils,
GetAsDOMNode(curNode));
nsAutoString value;
// retrieve its specified value
NS_ENSURE_STATE(mHTMLEditor);
mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(curNode, marginProperty, value);
mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(*curNode,
*marginProperty, value);
float f;
nsCOMPtr<nsIAtom> unit;
// get its number part and its unit
@ -4143,7 +4149,9 @@ nsHTMLEditRules::WillOutdent(Selection* aSelection,
nsIAtom* marginProperty = MarginPropertyAtomForIndent(mHTMLEditor->mHTMLCSSUtils, curNode);
nsAutoString value;
NS_ENSURE_STATE(mHTMLEditor);
mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(curNode, marginProperty, value);
mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(*curNode_,
*marginProperty,
value);
float f;
nsCOMPtr<nsIAtom> unit;
NS_ENSURE_STATE(mHTMLEditor);
@ -4201,24 +4209,21 @@ nsHTMLEditRules::WillOutdent(Selection* aSelection,
}
// are we inside a blockquote?
nsCOMPtr<nsIDOMNode> n = curNode;
nsCOMPtr<nsIDOMNode> tmp;
nsCOMPtr<nsINode> n = curNode_;
curBlockQuoteIsIndentedWithCSS = false;
// keep looking up the hierarchy as long as we don't hit the body or the
// active editing host or a table element (other than an entire table)
while (!nsTextEditUtils::IsBody(n) && mHTMLEditor &&
mHTMLEditor->IsDescendantOfEditorRoot(n)
&& (nsHTMLEditUtils::IsTable(n) || !nsHTMLEditUtils::IsTableElement(n)))
{
n->GetParentNode(getter_AddRefs(tmp));
if (!tmp) {
while (!n->IsHTMLElement(nsGkAtoms::body) && mHTMLEditor &&
mHTMLEditor->IsDescendantOfEditorRoot(n) &&
(n->IsHTMLElement(nsGkAtoms::table) ||
!nsHTMLEditUtils::IsTableElement(n))) {
if (!n->GetParentNode()) {
break;
}
n = tmp;
if (nsHTMLEditUtils::IsBlockquote(n))
{
n = n->GetParentNode();
if (n->IsHTMLElement(nsGkAtoms::blockquote)) {
// if so, remember it, and remember first node we are taking out of it.
curBlockQuote = n;
curBlockQuote = GetAsDOMNode(n);
firstBQChild = curNode;
lastBQChild = curNode;
break;
@ -4229,14 +4234,15 @@ nsHTMLEditRules::WillOutdent(Selection* aSelection,
nsIAtom* marginProperty = MarginPropertyAtomForIndent(mHTMLEditor->mHTMLCSSUtils, curNode);
nsAutoString value;
NS_ENSURE_STATE(mHTMLEditor);
mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(n, marginProperty, value);
mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(*n, *marginProperty,
value);
float f;
nsCOMPtr<nsIAtom> unit;
NS_ENSURE_STATE(mHTMLEditor);
mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit));
if (f > 0 && !(nsHTMLEditUtils::IsList(curParent) && nsHTMLEditUtils::IsList(curNode)))
{
curBlockQuote = n;
curBlockQuote = GetAsDOMNode(n);
firstBQChild = curNode;
lastBQChild = curNode;
curBlockQuoteIsIndentedWithCSS = true;
@ -8969,7 +8975,8 @@ nsHTMLEditRules::RelativeChangeIndentationOfElementNode(nsIDOMNode *aNode, int8_
GetAsDOMNode(element));
nsAutoString value;
NS_ENSURE_STATE(mHTMLEditor);
mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(aNode, marginProperty, value);
mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(*element, *marginProperty,
value);
float f;
nsCOMPtr<nsIAtom> unit;
NS_ENSURE_STATE(mHTMLEditor);

View File

@ -739,7 +739,7 @@ AssertParserServiceIsCorrect(nsIAtom* aTag, bool aIsBlock)
* Can be used to determine if a new paragraph should be started.
*/
bool
nsHTMLEditor::NodeIsBlockStatic(const dom::Element* aElement)
nsHTMLEditor::NodeIsBlockStatic(const nsINode* aElement)
{
MOZ_ASSERT(aElement);
@ -795,7 +795,7 @@ nsHTMLEditor::NodeIsBlock(nsIDOMNode *aNode, bool *aIsBlock)
bool
nsHTMLEditor::IsBlockNode(nsINode *aNode)
{
return aNode && aNode->IsElement() && NodeIsBlockStatic(aNode->AsElement());
return aNode && NodeIsBlockStatic(aNode);
}
// Non-static version for the nsIEditor interface and JavaScript
@ -825,7 +825,7 @@ nsHTMLEditor::GetBlockNodeParent(nsINode* aNode)
nsCOMPtr<nsINode> p = aNode->GetParentNode();
while (p) {
if (p->IsElement() && NodeIsBlockStatic(p->AsElement())) {
if (NodeIsBlockStatic(p)) {
return p.forget().downcast<Element>();
}
p = p->GetParentNode();
@ -1731,59 +1731,48 @@ nsHTMLEditor::GetCSSBackgroundColorState(bool *aMixed, nsAString &aOutColor, boo
// get selection
nsRefPtr<Selection> selection = GetSelection();
NS_ENSURE_STATE(selection);
NS_ENSURE_STATE(selection && selection->GetRangeAt(0));
// get selection location
nsCOMPtr<nsIDOMNode> parent;
int32_t offset;
nsresult res = GetStartNodeAndOffset(selection, getter_AddRefs(parent),
&offset);
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsINode> parent = selection->GetRangeAt(0)->GetStartParent();
int32_t offset = selection->GetRangeAt(0)->StartOffset();
NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
// is the selection collapsed?
nsCOMPtr<nsIDOMNode> nodeToExamine;
nsCOMPtr<nsINode> nodeToExamine;
if (selection->Collapsed() || IsTextNode(parent)) {
// we want to look at the parent and ancestors
nodeToExamine = parent;
} else {
// otherwise we want to look at the first editable node after
// {parent,offset} and its ancestors for divs with alignment on them
nodeToExamine = GetChildAt(parent, offset);
nodeToExamine = parent->GetChildAt(offset);
//GetNextNode(parent, offset, true, address_of(nodeToExamine));
}
NS_ENSURE_TRUE(nodeToExamine, NS_ERROR_NULL_POINTER);
// is the node to examine a block ?
bool isBlock;
res = NodeIsBlockStatic(nodeToExamine, &isBlock);
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMNode> tmp;
if (aBlockLevel) {
// we are querying the block background (and not the text background), let's
// climb to the block container
nsCOMPtr<nsIDOMNode> blockParent = nodeToExamine;
if (!isBlock) {
nsCOMPtr<Element> blockParent;
if (NodeIsBlockStatic(nodeToExamine)) {
blockParent = nodeToExamine->AsElement();
} else {
blockParent = GetBlockNodeParent(nodeToExamine);
NS_ENSURE_TRUE(blockParent, NS_OK);
}
NS_ENSURE_TRUE(blockParent, NS_OK);
// Make sure to not walk off onto the Document node
nsCOMPtr<nsIDOMElement> element;
do {
// retrieve the computed style of background-color for blockParent
mHTMLCSSUtils->GetComputedProperty(blockParent,
nsGkAtoms::backgroundColor,
mHTMLCSSUtils->GetComputedProperty(*blockParent,
*nsGkAtoms::backgroundColor,
aOutColor);
tmp.swap(blockParent);
res = tmp->GetParentNode(getter_AddRefs(blockParent));
element = do_QueryInterface(blockParent);
blockParent = blockParent->GetParentElement();
// look at parent if the queried color is transparent and if the node to
// examine is not the root of the document
} while (aOutColor.EqualsLiteral("transparent") && element);
} while (aOutColor.EqualsLiteral("transparent") && blockParent);
if (aOutColor.EqualsLiteral("transparent")) {
// we have hit the root of the document and the color is still transparent !
// Grumble... Let's look at the default background color because that's the
@ -1795,15 +1784,11 @@ nsHTMLEditor::GetCSSBackgroundColorState(bool *aMixed, nsAString &aOutColor, boo
// no, we are querying the text background for the Text Highlight button
if (IsTextNode(nodeToExamine)) {
// if the node of interest is a text node, let's climb a level
res = nodeToExamine->GetParentNode(getter_AddRefs(parent));
NS_ENSURE_SUCCESS(res, res);
nodeToExamine = parent;
nodeToExamine = nodeToExamine->GetParentNode();
}
do {
// is the node to examine a block ?
res = NodeIsBlockStatic(nodeToExamine, &isBlock);
NS_ENSURE_SUCCESS(res, res);
if (isBlock) {
if (NodeIsBlockStatic(nodeToExamine)) {
// yes it is a block; in that case, the text background color is transparent
aOutColor.AssignLiteral("transparent");
break;
@ -1811,16 +1796,14 @@ nsHTMLEditor::GetCSSBackgroundColorState(bool *aMixed, nsAString &aOutColor, boo
else {
// no, it's not; let's retrieve the computed style of background-color for the
// node to examine
mHTMLCSSUtils->GetComputedProperty(nodeToExamine,
nsGkAtoms::backgroundColor,
mHTMLCSSUtils->GetComputedProperty(*nodeToExamine,
*nsGkAtoms::backgroundColor,
aOutColor);
if (!aOutColor.EqualsLiteral("transparent")) {
break;
}
}
tmp.swap(nodeToExamine);
res = tmp->GetParentNode(getter_AddRefs(nodeToExamine));
NS_ENSURE_SUCCESS(res, res);
nodeToExamine = nodeToExamine->GetParentNode();
} while ( aOutColor.EqualsLiteral("transparent") && nodeToExamine );
}
return NS_OK;

View File

@ -257,7 +257,7 @@ public:
/** Internal, static version */
// aElement must not be null.
static bool NodeIsBlockStatic(const mozilla::dom::Element* aElement);
static bool NodeIsBlockStatic(const nsINode* aElement);
static nsresult NodeIsBlockStatic(nsIDOMNode *aNode, bool *aIsBlock);
protected:
virtual ~nsHTMLEditor();

View File

@ -253,9 +253,11 @@ nsHTMLEditor::SetAllResizersPosition()
nsAutoString value;
float resizerWidth, resizerHeight;
nsCOMPtr<nsIAtom> dummyUnit;
mHTMLCSSUtils->GetComputedProperty(static_cast<nsIDOMElement*>(GetAsDOMNode(mTopLeftHandle)), nsGkAtoms::width, value);
mHTMLCSSUtils->GetComputedProperty(*mTopLeftHandle, *nsGkAtoms::width,
value);
mHTMLCSSUtils->ParseLength(value, &resizerWidth, getter_AddRefs(dummyUnit));
mHTMLCSSUtils->GetComputedProperty(static_cast<nsIDOMElement*>(GetAsDOMNode(mTopLeftHandle)), nsGkAtoms::height, value);
mHTMLCSSUtils->GetComputedProperty(*mTopLeftHandle, *nsGkAtoms::height,
value);
mHTMLCSSUtils->ParseLength(value, &resizerHeight, getter_AddRefs(dummyUnit));
int32_t rw = (int32_t)((resizerWidth + 1) / 2);