Bug 80580 - Add TextFieldDecorator and TextFieldDecorationElement
Summary: Add TextFieldDecorator and TextFieldDecorationElement
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kent Tamura
URL:
Keywords:
Depends on:
Blocks: 80479
  Show dependency treegraph
 
Reported: 2012-03-08 01:29 PST by Kent Tamura
Modified: 2012-03-23 16:42 PDT (History)
7 users (show)

See Also:


Attachments
WIP (17.87 KB, patch)
2012-03-08 01:32 PST, Kent Tamura
no flags Details | Formatted Diff | Diff
Patch (30.17 KB, patch)
2012-03-08 23:16 PST, Kent Tamura
no flags Details | Formatted Diff | Diff
WIP 2 (15.15 KB, patch)
2012-03-22 06:55 PDT, Kent Tamura
no flags Details | Formatted Diff | Diff
Patch 2 (15.55 KB, patch)
2012-03-23 00:28 PDT, Kent Tamura
dglazkov: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kent Tamura 2012-03-08 01:29:27 PST
Add TextFieldDecorator and TextFieldDecorationElemeent
Comment 1 Kent Tamura 2012-03-08 01:32:40 PST
Created attachment 130794 [details]
WIP
Comment 2 Dimitri Glazkov (Google) 2012-03-08 08:57:10 PST
Comment on attachment 130794 [details]
WIP

This looks really great, but this code will become obsolete as soon as we start supporting multiple shadow DOM trees on the text inputs. Once that's in place, we should be able to simply add another shadow DOM tree on top of existing type and put the decoration there. Perhaps you could file a bug on this? We (the Shadow DOM folks) will take care of the refactoring once the stuff is ready.
Comment 3 Kent Tamura 2012-03-08 21:02:30 PST
(In reply to comment #2)
> This looks really great, but this code will become obsolete as soon as we start supporting multiple shadow DOM trees on the text inputs. Once that's in place, we should be able to simply add another shadow DOM tree on top of existing type and put the decoration there. Perhaps you could file a bug on this? We (the Shadow DOM folks) will take care of the refactoring once the stuff is ready.

I don't think multiple shadow DOM trees will help this much.

When one wants to add a decoration button, he needs to do:
 - Provide a custom Element class to add code for mouse events
 - Add shadowPseudoId and default style in html.css if he doesn't use scoped style.
 - Add new -webkit-appearance value and painting code for it if the appearance can not be represented by pure CSS
 - Add code to RenderTextControlSingleLine.cpp if the button affects the size of the host <input>
 - Add the custom Element instance to the host <input> as a shadow element

It seems multiple shadow DOM doesn't improve these tasks.
Comment 4 Kent Tamura 2012-03-08 23:16:33 PST
Created attachment 130987 [details]
Patch
Comment 5 Dimitri Glazkov (Google) 2012-03-09 08:56:50 PST
(In reply to comment #3)
> (In reply to comment #2)
> > This looks really great, but this code will become obsolete as soon as we start supporting multiple shadow DOM trees on the text inputs. Once that's in place, we should be able to simply add another shadow DOM tree on top of existing type and put the decoration there. Perhaps you could file a bug on this? We (the Shadow DOM folks) will take care of the refactoring once the stuff is ready.
> 
> I don't think multiple shadow DOM trees will help this much.
> 
> When one wants to add a decoration button, he needs to do:
>  - Provide a custom Element class to add code for mouse events
>  - Add shadowPseudoId and default style in html.css if he doesn't use scoped style.
>  - Add new -webkit-appearance value and painting code for it if the appearance can not be represented by pure CSS
>  - Add code to RenderTextControlSingleLine.cpp if the button affects the size of the host <input>
>  - Add the custom Element instance to the host <input> as a shadow element
> 
> It seems multiple shadow DOM doesn't improve these tasks.

Sure, but all these are standard, typical things one would need to do to create a functional shadow DOM element. What you're proposing here is a neat, but completely new way and highly specialized way of doing things.

Additionally, if this is just a plain element, I can animate it, and use CSS to lay things out.

I am not objecting to this patch, just trying to suggest that perhaps specialization is not always the best route.
Comment 6 Hajime Morrita 2012-03-15 22:42:26 PDT
Maybe Shinya can help here.

We are going to support multiple shadow roots for non-trivial elements like controls and images.
If we have some concrete usecase to "decorating" such stuff, we can take it as the first client of 
our change.

In that process, some C++ utility classes could be introduced to build such multiple shadows easily.
It'll be like what we did when we introduced ShadowRoot. Let's start from real case, then abstract it out.

Well, I admit that this is highly shadow-biased opinion but...
Comment 7 Dimitri Glazkov (Google) 2012-03-16 10:00:33 PDT
(In reply to comment #6)
> Maybe Shinya can help here.
> 
> We are going to support multiple shadow roots for non-trivial elements like controls and images.
> If we have some concrete usecase to "decorating" such stuff, we can take it as the first client of 
> our change.
> 
> In that process, some C++ utility classes could be introduced to build such multiple shadows easily.
> It'll be like what we did when we introduced ShadowRoot. Let's start from real case, then abstract it out.
> 
> Well, I admit that this is highly shadow-biased opinion but...

Me too! Kent-san, we apologize for proselytizing shadow DOM so much :)

Please connect with Shinya and Morrita and chat with them. I trust that you guys can figure this out f2f.
Comment 8 Kent Tamura 2012-03-22 03:10:28 PDT
I discussed this with morrita and shinyak.
I understand the multiple shadow trees feature can be applied to this.  It would make some benefit if shadow DOM operations were exposed via WebKit API, or if we supported <style scoped> by default.  It makes no benefit at this moment, but we can use it.

I'll make the patch simpler, but the basic structure won't be changed.
Comment 9 Kent Tamura 2012-03-22 06:55:36 PDT
Created attachment 133248 [details]
WIP 2

Simplified
Comment 10 Kent Tamura 2012-03-22 07:03:16 PDT
Comment on attachment 133248 [details]
WIP 2

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

> Source/WebCore/page/ChromeClient.h:314
> +        virtual void addTextFieldDecorationsTo(HTMLInputElement*) { }

ChromeClientChromium::addTextFieldDecorationsTo() implementation will be like:

add another ShadowRoot;
shadowRoot->appendChild(HTMLShadowElement::create());
for (i = 0; i < webView->textFieldDecorators().size(); ++i)
    shadowRoot->appendChild(TextFieldDecorationElement::create(input->document(), webview->textFieldDecorators[i]))
Comment 11 Dimitri Glazkov (Google) 2012-03-22 09:36:06 PDT
Comment on attachment 133248 [details]
WIP 2

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

> Source/WebCore/html/shadow/TextFieldDecorationElement.cpp:59
> +    virtual void paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset) OVERRIDE

I am probably just being dense, but... can you explain why we need custom painting here? Can't we just let style recalc, etc. Take care of this?
Comment 12 Kent Tamura 2012-03-22 18:00:23 PDT
(In reply to comment #11)
> (From update of attachment 133248 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=133248&action=review
> 
> > Source/WebCore/html/shadow/TextFieldDecorationElement.cpp:59
> > +    virtual void paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset) OVERRIDE
> 
> I am probably just being dense, but... can you explain why we need custom painting here? Can't we just let style recalc, etc. Take care of this?
Comment 13 Kent Tamura 2012-03-22 18:08:10 PDT
Comment on attachment 133248 [details]
WIP 2

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

>>> Source/WebCore/html/shadow/TextFieldDecorationElement.cpp:59
>>> +    virtual void paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset) OVERRIDE
>> 
>> I am probably just being dense, but... can you explain why we need custom painting here? Can't we just let style recalc, etc. Take care of this?
> 
> 

I'd like to draw an Image object for TextFieldDecorationElement.  AFAIK, there are two ways to draw an Image object for an element content.
* Use a custom Renderer like this
* Use -webkit-appearance, and implement a paint function of RenderTheme like the previos patch

I switched to the first way to prevent many platforms from depending TextFieldDecorationElement.*.


I don't like to use the standard ways to paint images such as <img src=> and background-image because making such images URL-accessible is not efficient.
Comment 14 Kent Tamura 2012-03-22 18:13:57 PDT
(In reply to comment #13)
> I'd like to draw an Image object for TextFieldDecorationElement.  AFAIK, there are two ways to draw an Image object for an element content.
> * Use a custom Renderer like this
> * Use -webkit-appearance, and implement a paint function of RenderTheme like the previos patch

I have just found a way to set an Image object to HTMLImageElement.  I'll try it.
Comment 15 Kent Tamura 2012-03-23 00:28:03 PDT
Created attachment 133438 [details]
Patch 2

Drop a custom renderer
Comment 16 Kent Tamura 2012-03-23 16:42:59 PDT
Committed r111930: <http://trac.webkit.org/changeset/111930>