-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Add DOMNode::compareDocumentPosition() #12146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
. Added constant DOMNode::DOCUMENT_POSITION_DISCONNECTED. | ||
. Added constant DOMNode::DOCUMENT_POSITION_PRECEDING. | ||
. Added constant DOMNode::DOCUMENT_POSITION_FOLLOWING. | ||
. Added constant DOMNode::DOCUMENT_POSITION_CONTAINS. | ||
. Added constant DOMNode::DOCUMENT_POSITION_CONTAINED_BY. | ||
. Added constant DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to make this an enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that too. The problem is that they're bitflags, so they might be OR'ed with eachother. That's something not supported with enums right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enum sets would be nice to have indeed :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just minor questions
. Added constant DOMNode::DOCUMENT_POSITION_DISCONNECTED. | ||
. Added constant DOMNode::DOCUMENT_POSITION_PRECEDING. | ||
. Added constant DOMNode::DOCUMENT_POSITION_FOLLOWING. | ||
. Added constant DOMNode::DOCUMENT_POSITION_CONTAINS. | ||
. Added constant DOMNode::DOCUMENT_POSITION_CONTAINED_BY. | ||
. Added constant DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enum sets would be nice to have indeed :(
ext/dom/node.c
Outdated
|
||
/* Special case: comparing children and attributes. | ||
* They belong to a different tree and are therefore hard to compare, but spec demands attributes to precede children | ||
* according to the pre-order DFS numbering. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DFS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depth-first search. I'll write it out in full.
--EXPECT-- | ||
--- Compare 0 and 1 --- | ||
int(36) | ||
--- Compare 0 and 2 --- | ||
int(36) | ||
--- Compare 1 and 2 --- | ||
int(36) | ||
--- Compare 1 and 0 --- | ||
int(34) | ||
--- Compare 2 and 0 --- | ||
int(34) | ||
--- Compare 2 and 1 --- | ||
int(34) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the values meaningful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll clean it up so it's easier to understand.
echo "--- strong & bar ---\n"; | ||
var_dump($bar->nextElementSibling->compareDocumentPosition($bar) === DOMNode::DOCUMENT_POSITION_PRECEDING); | ||
var_dump($bar->compareDocumentPosition($bar->nextElementSibling) === DOMNode::DOCUMENT_POSITION_FOLLOWING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would the two strong tags compare?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a test for this.
Reference: https://dom.spec.whatwg.org/#dom-node-comparedocumentposition