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
Offset: Operate "relative to document" correctly #3096
Closed
Closed
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8fba235
Offset: Operate "relative to document" correctly
anseki 8dd15ec
Offset: Fix indention in test code
anseki 3d72e54
Offset: Add test cases
anseki f40e903
Offset: Add comment in test code
anseki fa231be
Offset: rewrite the test
anseki d56c818
Offset: replace test code
anseki File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | ||
<title>body</title> | ||
<style type="text/css" media="screen"> | ||
html, body { border: solid red; } | ||
html { background-color: green; } | ||
body { background-color: yellow; } | ||
#marker1 { background-color: blue; } | ||
#marker2 { background-color: orange; position: absolute; } | ||
</style> | ||
<script src="../../jquery.js"></script> | ||
<script src="../iframeTest.js"></script> | ||
<script type="text/javascript" charset="utf-8"> | ||
jQuery(function() { | ||
startIframeTest(); | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<div id="marker1">marker1</div> | ||
<div id="marker2">marker2</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not exactly., I'm saying that
situations
and "CASE 1"/"CASE 2"/"CASE 3" should be removed in favor of a simpler approach. ThetestIframe
callback shouldn't need to do too much:And there could easily be ways to simplify even further.
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.
Sorry, I have to learn English...
So, please check following:
margin
andborder
. Did I mistake again?assert.deepEqual()
s that are passed return value from.offset()
failed.I found this:
https://github.com/jquery/jquery/blob/master/external/qunit/qunit.js#L1628
if ( a.constructor === b.constructor ) {
Expected values that were made in the test code and return values from
.offset()
that were made iniframe
have constructor in different namespaces (i.e. window), thereforea.constructor === b.constructor
isfalse
.Return values from
.offset()
have to be copied to be checked byassert.deepEqual()
.supportjQuery.extend({}, $( "#static" ).offset())
html{position}
isstatic
andbody{position}
isnon-static
.For example, in a case
html{position:static} body{position:relative}
:I think, this code is incorrect:
If
body
hasposition:non-static
, the element is positioned relative tobody
without being affected byposition
of<html>
.body
was already positioned withmargin
,border
andpadding
of<html>
.Therefore the code should be:
html{position}
is notstatic
orrelative
.I think, this code is incorrect:
If
<html>
hasposition:non-static
, it is positioned withmargin
even ifpotision
is other thanrelative
.Therefore the code should be:
This is solved by fixing
originAdjust
andorigin
.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.
The test code I wrote might do the almost same as your code, by removing code that changes
margin
andborder
.But I didn't think that it should change
top
andleft
of<html>
andbody
.Therefore I think that I can't write PR. Maybe, I can't understand your request well by my very poor English.
Then, I hope that someone write PR.
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.
BTW, why the test doesn't need to change
border
?I think that this is PR to fix bug with
clientTop/clientLeft
(i.e. border).At least, it should test in cases of that
<html>
hasborder
and noborder
.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.
No problem. And it's not all your misunderstanding; my suggestions are changing as I learn new details of browser behavior around this issue.
It was a partial mistake. I wasn't saying that margin and border need to change, just that test cases should cover both zero and nonzero values. Further, we already have tests for the no-margin no-border no-padding cases, and I have since concluded that the "only margin" and "only border" cases are unnecessary, so this PR can focus on situations in which all the box styles are nonzero.
👍
I definitely mis-defined
origin
, and I agree that your fix is correct.Again, a correct fix for my mistake.
I really think we're close. My complaint wan't about what you were testing, just how it was being tested. And as shown above, you clearly have the right insights.
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.
Thank you very much for your very attentive care.
I understood that the test doesn't have to change
border
.I have more questions.
top/left
ofhtml/body
?I think that these properties affect
getBoundingClientRect()
method of browser, and.offset()
method of jQuery calculates with a return value of thegetBoundingClientRect()
without consideringtop/left
.That is, if the result become incorrect by changing
top/left
, it is bug ofgetBoundingClientRect()
method (i.e. browser), not jQuery.Also,
top/left
ofhtml/body
are usually not changed..offset()
to another element unnecessary?https://github.com/anseki/jquery/blob/offset-html-border/test/unit/offset.js#L650
This is not "round-trip". I thought that the test should compare an element that was positioned by
.offset()
and another element that was positioned by native CSS, forsetOffset()
.setOffset()
must position an element at the same position as another element that was positioned by various CSS properties (position
,border
, etc.).I think that a cases of an element that has
position:static
are important becausesetOffset()
calculates distance from current coordinates.offset
method returns incorrect value in Firefox #3080 (comment)That is, it compares coordinates that was got without
.offset
and coordinates that was changed by.offset
that should not be affected by border of<html>
.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.
If there are such bugs, we need to know so we can work around them (or document our failure to do so).
Nor do html or body elements usually have borders. The point is verifying that our functions perform as claimed.
I agree. We should do both
$( "#absolute" ).offset( absoluteOffset )
and$( "#static" ).offset( absoluteOffset )
and expect the subsequent.offset()
to matchabsoluteOffset
. I updated my suggestions accordingly.