Bug 108858

Summary: Store the language internally instead of using lang attribute for WebVTT nodes
Product: WebKit Reporter: Dima Gorbik <dgorbik>
Component: MediaAssignee: Dima Gorbik <dgorbik>
Status: RESOLVED FIXED    
Severity: Normal CC: allan.jensen, ap, benjamin, cmarcelo, dglazkov, eric.carlson, feature-media-reviews, koivisto, macpherson, menard, mifenton, ojan.autocc, silviapf, tkent, vcarbune, webkit-bug-importer, webkit.review.bot
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 43668    
Attachments:
Description Flags
Proposed fix 0.1
webkit.review.bot: commit-queue-
Proposed fix 0.2
tkent: review-
Proposed fix 0.3
none
Proposed fix 0.4
none
Proposed fix 0.5 none

Description Dima Gorbik 2013-02-04 14:06:11 PST
Specs only require language objects have lang attributes. For all other objects the language should be stored internally to enable ':lang' pseudo-class.
Comment 1 Dima Gorbik 2013-02-04 15:58:31 PST
Created attachment 186486 [details]
Proposed fix 0.1
Comment 2 Radar WebKit Bug Importer 2013-02-04 15:59:09 PST
<rdar://problem/13148532>
Comment 3 WebKit Review Bot 2013-02-04 16:44:54 PST
Comment on attachment 186486 [details]
Proposed fix 0.1

Attachment 186486 [details] did not pass cr-linux-debug-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/16367469
Comment 4 Dima Gorbik 2013-02-04 16:57:17 PST
Created attachment 186498 [details]
Proposed fix 0.2

Is it better not to rename?
Comment 5 Kent Tamura 2013-02-04 17:12:10 PST
Comment on attachment 186498 [details]
Proposed fix 0.2

View in context: https://bugs.webkit.org/attachment.cgi?id=186498&action=review

> Source/WebCore/dom/Element.cpp:2156
> -AtomicString Element::computeInheritedLanguage() const
> +AtomicString Element::elementLanguage() const

Please don't rename this function. The name 'compute' indicates this function is not a simple getter and needs higher cost.

> Source/WebCore/html/track/WebVTTElement.h:81
> +    AtomicString language;

m_language
Comment 6 Alexey Proskuryakov 2013-02-04 17:27:46 PST
Comment on attachment 186498 [details]
Proposed fix 0.2

View in context: https://bugs.webkit.org/attachment.cgi?id=186498&action=review

> Source/WebCore/ChangeLog:10
> +        Only language webvtt elements should have a lang attribute so we have to store
> +        the language internally in the element. Refactored the code to make 
> +        computeInheritedLanguage virtual.

Despite this comment, I don't understand why WebVTTElement needs to store language internally. How is it different from every other element with a lang attribute?

> Source/WebCore/dom/Element.h:335
> -    AtomicString computeInheritedLanguage() const;
> +    virtual AtomicString elementLanguage() const;

This function has "compute" as a hint that it's unnecessary slow for most uses. One should almost always take language form the renderer, not from Element.

> Source/WebCore/html/track/WebVTTElement.h:59
> +    virtual AtomicString elementLanguage() const OVERRIDE { return language; }

I don't think that virtualizing core DOM functions is a great approach for WebVTT in general. Virtual function calls are slower, and a lot of effort has been invested in devirtualizing everything we could.
Comment 7 Dima Gorbik 2013-02-04 17:36:12 PST
Created attachment 186508 [details]
Proposed fix 0.3
Comment 8 Dima Gorbik 2013-02-04 17:50:36 PST
(In reply to comment #6)
> (From update of attachment 186498 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=186498&action=review
> 
> > Source/WebCore/ChangeLog:10
> > +        Only language webvtt elements should have a lang attribute so we have to store
> > +        the language internally in the element. Refactored the code to make 
> > +        computeInheritedLanguage virtual.
> 
> Despite this comment, I don't understand why WebVTTElement needs to store language internally. How is it different from every other element with a lang attribute?

If we store the language in the attribute then c[lang="en"] rule will work though it shouldn't according to specs. This is a difference between html and webvtt elements.  

> I don't think that virtualizing core DOM functions is a great approach for WebVTT in general. Virtual function calls are slower, and a lot of effort has been invested in devirtualizing everything we could.
In general yes, but what about this case? This function is already quite heavy in terms of performance. Also I will have to call a virtual isWebVTTElement anyway.
Comment 9 Kent Tamura 2013-02-04 17:55:38 PST
Comment on attachment 186498 [details]
Proposed fix 0.2

View in context: https://bugs.webkit.org/attachment.cgi?id=186498&action=review

>>> Source/WebCore/ChangeLog:10
>>> +        computeInheritedLanguage virtual.
>> 
>> Despite this comment, I don't understand why WebVTTElement needs to store language internally. How is it different from every other element with a lang attribute?
> 
> If we store the language in the attribute then c[lang="en"] rule will work though it shouldn't according to specs. This is a difference between html and webvtt elements.

Doesn't :lang pseudo-class work?
Comment 10 Kent Tamura 2013-02-04 17:57:48 PST
Comment on attachment 186498 [details]
Proposed fix 0.2

View in context: https://bugs.webkit.org/attachment.cgi?id=186498&action=review

>>>> Source/WebCore/ChangeLog:10
>>>> +        computeInheritedLanguage virtual.
>>> 
>>> Despite this comment, I don't understand why WebVTTElement needs to store language internally. How is it different from every other element with a lang attribute?
>> 
>> If we store the language in the attribute then c[lang="en"] rule will work though it shouldn't according to specs. This is a difference between html and webvtt elements.
> 
> Doesn't :lang pseudo-class work?

An, I understand.  The language information comes from VTT, not HTML/DOM.
Comment 11 Dima Gorbik 2013-02-04 18:01:50 PST
Created attachment 186514 [details]
Proposed fix 0.4
Comment 12 Benjamin Poulain 2013-02-04 23:30:13 PST
Comment on attachment 186514 [details]
Proposed fix 0.4

View in context: https://bugs.webkit.org/attachment.cgi?id=186514&action=review

> Source/WebCore/html/track/WebVTTElement.cpp:74
> +    , m_language(nullAtom)

You should not have to write this, AtomicString default constructor is equivalent to the nullAtom.

> Source/WebCore/html/track/WebVTTElement.h:59
> +    virtual AtomicString computeInheritedLanguage() const OVERRIDE { return m_language; }

IMHO, this is abusing inheritance. The language your return has nothing to do with the InheritedLanguage.
Comment 13 Dima Gorbik 2013-02-05 00:54:07 PST
(In reply to comment #12)
> > Source/WebCore/html/track/WebVTTElement.h:59
> > +    virtual AtomicString computeInheritedLanguage() const OVERRIDE { return m_language; }
> 
> IMHO, this is abusing inheritance. The language your return has nothing to do with the InheritedLanguage.

The language I return is an inherited language but it's being pre-cached. The implementation we have in Element is related to html elements. That's why I suggested renaming at first. Those are different algorithms for getting a language for elements of different types.
Comment 14 Antti Koivisto 2013-02-05 10:19:39 PST
WebVTT selector matching does not really operate on DOM object at all. That WebVTT nodes are implemented as Elements an implementation detail. They are not conceptually elements. This is why I think it is was appropriate to have explicit test in SelectorChecker rather than hiding the differences behind virtual function.

In other words I don't think there is problem to solve here.
Comment 15 Dima Gorbik 2013-02-05 14:20:19 PST
Created attachment 186704 [details]
Proposed fix 0.5

Okay, it's probably better to leave this code the way it was.
Comment 16 WebKit Review Bot 2013-02-06 15:34:52 PST
Comment on attachment 186704 [details]
Proposed fix 0.5

Clearing flags on attachment: 186704

Committed r142043: <http://trac.webkit.org/changeset/142043>
Comment 17 WebKit Review Bot 2013-02-06 15:34:57 PST
All reviewed patches have been landed.  Closing bug.
Comment 18 Eric Carlson 2014-02-07 17:14:05 PST
*** Bug 101351 has been marked as a duplicate of this bug. ***