Bug 150341 - Drop unnecessary Node::toInputElement() virtual function
Summary: Drop unnecessary Node::toInputElement() virtual function
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-19 14:34 PDT by Chris Dumez
Modified: 2015-10-19 20:30 PDT (History)
4 users (show)

See Also:


Attachments
Patch (43.77 KB, patch)
2015-10-19 16:09 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (43.77 KB, patch)
2015-10-19 18:40 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (43.73 KB, patch)
2015-10-19 19:42 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2015-10-19 14:34:43 PDT
Drop unnecessary Node::toInputElement() virtual function and use the usual is<HTMLInputElement>() / downcast< HTMLInputElement >() instead.
Comment 1 Chris Dumez 2015-10-19 16:09:48 PDT
Created attachment 263522 [details]
Patch
Comment 2 Chris Dumez 2015-10-19 18:40:34 PDT
Created attachment 263541 [details]
Patch
Comment 3 Darin Adler 2015-10-19 19:30:42 PDT
Comment on attachment 263541 [details]
Patch

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

> Source/WebCore/accessibility/AccessibilityNodeObject.cpp:675
>      Node* node = this->node();
> -    if (!node)
> +    if (!is<HTMLInputElement>(node))
>          return false;
>  
> -    HTMLInputElement* inputElement = node->toInputElement();
> -    if (!inputElement)
> -        return false;
> -
> -    return inputElement->shouldAppearIndeterminate();
> +    return downcast<HTMLInputElement>(*node).shouldAppearIndeterminate();

I might have written it:

    return is<HTMLInputElement>(node) && downcast<HTMLInputElement>(*node).shouldAppearIndeterminate();

I noticed you doing something similar in a function below.

> Source/WebCore/html/shadow/SliderThumbElement.cpp:575
>      // Only HTMLInputElement creates SliderThumbElement instances as its shadow nodes.
>      // So, shadowHost() must be an HTMLInputElement.
> -    Element* host = shadowHost();
> -    return host ? host->toInputElement() : 0;
> +    auto* host = shadowHost();
> +    return is<HTMLInputElement>(host) ? downcast<HTMLInputElement>(host) : nullptr;

It’s peculiar that this code checks is<HTMLInputElement> yet has a comment stating that the check is not needed. I’m thinking that the comment is likely correct, and we could probably write:

    return downcast<HTMLInputElement>(shadowHost());

But obviously it’s less risky to leave the behavior unchanged.
Comment 4 Chris Dumez 2015-10-19 19:42:01 PDT
Created attachment 263545 [details]
Patch
Comment 5 Chris Dumez 2015-10-19 19:44:12 PDT
Comment on attachment 263541 [details]
Patch

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

>> Source/WebCore/accessibility/AccessibilityNodeObject.cpp:675
>> +    return downcast<HTMLInputElement>(*node).shouldAppearIndeterminate();
> 
> I might have written it:
> 
>     return is<HTMLInputElement>(node) && downcast<HTMLInputElement>(*node).shouldAppearIndeterminate();
> 
> I noticed you doing something similar in a function below.

Done before landing.

>> Source/WebCore/html/shadow/SliderThumbElement.cpp:575
>> +    return is<HTMLInputElement>(host) ? downcast<HTMLInputElement>(host) : nullptr;
> 
> It’s peculiar that this code checks is<HTMLInputElement> yet has a comment stating that the check is not needed. I’m thinking that the comment is likely correct, and we could probably write:
> 
>     return downcast<HTMLInputElement>(shadowHost());
> 
> But obviously it’s less risky to leave the behavior unchanged.

I checked that this is only used by RangeInputType so I made the change.
Comment 6 WebKit Commit Bot 2015-10-19 20:30:15 PDT
Comment on attachment 263545 [details]
Patch

Clearing flags on attachment: 263545

Committed r191327: <http://trac.webkit.org/changeset/191327>
Comment 7 WebKit Commit Bot 2015-10-19 20:30:19 PDT
All reviewed patches have been landed.  Closing bug.