Re: [css-regions] Possible change to the Region interface

On Thu, Oct 3, 2013 at 4:34 PM, Tab Atkins Jr. <jackalmage@gmail.com> wrote:

> On Thu, Oct 3, 2013 at 12:45 PM, Mihnea-Vlad Ovidenie <mihnea@adobe.com>
> wrote:
> > On 10/1/13 6:07 PM, "Boris Zbarsky" <bzbarsky@MIT.EDU> wrote:
> >>Indeed.  Gecko would represent the above as a vector of tagged unions on
> >>the c++ side.
> >
> > Are you saying that Gecko has support for the above scenario without
> > multiple inheritance in the C++ layer? Would you mind pointing me to
> where
> > I should take a look and what are the interfaces involved?
>
> Boris just said how it's done - with tagged unions.  We definitely use
> tagged unions in a few places in WebKit/Blink code.  (I think
> CSSValue, or some interface around that area, uses it.)
>
>
Yes, we have this kind of thing with custom bindings (as Boris points out
strokeStyle) but it's pretty nasty at the implementation level. I suppose
if we started adding more of them we'd need to consider how to automate the
multi type thing.

In general I find APIs like this very confusing for developers. You have no
idea what the return value of the function will be so you have to type
check it all over and duck typing is not possible since the interfaces are
entirely different (ex. String vs CanvasGradient). Often it leads to
breakage when developers assume it's always one of the types.

With the Region + pseudoElement approach you know .element is always an
Element, but occasionally pseudoElement is not an empty string. The types
are always consistent.

If others are in support I suppose we could do (PseudoElement or Element)
for this. I don't think PseudoElement should be an Element though.

- E

Received on Friday, 4 October 2013 04:26:31 UTC