Bug 80658 - Add tests for dynamic attribute changes for mapping of lang/xml:lang to -webkit-locale
Summary: Add tests for dynamic attribute changes for mapping of lang/xml:lang to -webk...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Matt Falkenhagen
URL:
Keywords:
Depends on:
Blocks: 76364
  Show dependency treegraph
 
Reported: 2012-03-08 17:32 PST by Matt Falkenhagen
Modified: 2012-03-13 01:32 PDT (History)
4 users (show)

See Also:


Attachments
Patch (4.09 KB, patch)
2012-03-08 17:36 PST, Matt Falkenhagen
no flags Details | Formatted Diff | Diff
use setAttributeNodeNS (4.11 KB, patch)
2012-03-12 01:49 PDT, Matt Falkenhagen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Falkenhagen 2012-03-08 17:32:27 PST
Making this bug with a narrower scope than bug 76364 since the first patch doesn't deal with SVG.
Comment 1 Matt Falkenhagen 2012-03-08 17:36:04 PST
Created attachment 130943 [details]
Patch
Comment 2 Alexey Proskuryakov 2012-03-08 18:43:19 PST
Comment on attachment 130943 [details]
Patch

r=me assuming this passes in Firefox, otherwise let's discuss any differences first.
Comment 3 Matt Falkenhagen 2012-03-09 11:37:17 PST
Thanks for the review. This tests mapping of lang to -webkit-locale which I think doesn't have an analogue in Firefox. One thing I'll try to do is confirm that Firefox computed language is the same as all the -webkit-locale values here, by using the CSS :lang selector or in the inspector. I don't know if there is a way to programmatically get the computed language.
Comment 4 Alexey Proskuryakov 2012-03-09 12:23:57 PST
Makes sense to me.
Comment 5 Matt Falkenhagen 2012-03-12 01:40:23 PDT
I found Firefox computed language has the same behavior, with one change: Firefox does not set xml:lang with setAttributeNode but does with setAttributeNodeNS. It looks like it's incorrect to use setAttributeNode for namespaced attributes, so I've revised the patch to use setAttributeNodeNS.

Also, both Firefox and WebKit do an interesting thing when lang is set to the empty string. According to the HTML 5 spec, the empty string means the language is explicitly unknown, which I think means that lang shouldn't be inherited from the parent. But for the CSS :lang selector, both browsers inherit lang, while for font selection, lang is not inherited. For example, in:

<div lang="ko" id="x1">x1
  <div id="x2">x2</div>
  <div id="x3" lang="">x3</div>
</div>

x1 and x2 are in the font for Korean and get CSS styling for :lang(ko), while x3 has CSS styling for :lang(ko) but is not in the font for Korean.

For WebKit, this happens because the :lang selector implementation climbs the DOM tree until it finds a non-empty lang. In contrast, font selection depends on -webkit-locale, which is mapped to "auto" when lang is empty, instead of being inherited.

This behavior is the same regardless of whether lang is set dynamically or not.

I'm thinking it's okay to keep the behavior as is, since at least it matches Firefox and setting lang to the empty string is probably an uncommon use case.

(Also, I just tested IE, and it looks like it does the same thing.)
Comment 6 Matt Falkenhagen 2012-03-12 01:49:38 PDT
Created attachment 131295 [details]
use setAttributeNodeNS
Comment 7 Alexey Proskuryakov 2012-03-12 09:13:06 PDT
Comment on attachment 131295 [details]
use setAttributeNodeNS

> I found Firefox computed language has the same behavior, with one change: Firefox does not set xml:lang with setAttributeNode but does with setAttributeNodeNS. It looks like it's incorrect to use setAttributeNode for namespaced attributes, so I've revised the patch to use setAttributeNodeNS.

This sounds like a bug that needs to be fixed in WebKit, correct?
Comment 8 WebKit Review Bot 2012-03-12 10:13:23 PDT
Comment on attachment 131295 [details]
use setAttributeNodeNS

Clearing flags on attachment: 131295

Committed r110440: <http://trac.webkit.org/changeset/110440>
Comment 9 WebKit Review Bot 2012-03-12 10:13:27 PDT
All reviewed patches have been landed.  Closing bug.
Comment 10 Matt Falkenhagen 2012-03-13 01:32:40 PDT
(In reply to comment #7)
> (From update of attachment 131295 [details])
> > I found Firefox computed language has the same behavior, with one change: Firefox does not set xml:lang with setAttributeNode but does with setAttributeNodeNS. It looks like it's incorrect to use setAttributeNode for namespaced attributes, so I've revised the patch to use setAttributeNodeNS.
> 
> This sounds like a bug that needs to be fixed in WebKit, correct?

Yes, I think so.