Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand InputType to cover all possible types #19471

Merged
merged 1 commit into from
Dec 6, 2017

Commits on Dec 6, 2017

  1. Expand InputType to cover all possible types

    This came out of a conversation with nox in IRC:
    https://mozilla.logbot.info/servo/20171201#c13946454-c13946594
    
    The code I was working on which motivated this change is here:
    servo#19461
    
    Previously, InputType::Text was used to represent several different
    values of the type attribute on an input element.
    
    If an input element doesn't have a type attribute, or its type attribute
    doesn't contain a recognised value, then the input's type defaults to
    "text".
    
    Before this change, there were a number of checks in the code which
    directly looked at the type attribute. If those checks matched against
    the value "text", then they were potentially buggy, since an input with
    type=invalid should also behave like an input with type=text.
    
    Rather than have every conditional which cares about the input type also
    have to deal with invalid input types, we can convert the type attribute
    to an InputType enum once, and then match against the enum.
    
    A secondary benefit is that the compiler can tell us whether we've
    missed branches in a match expression. While working on this I
    discovered that the HTMLInputElement::value_mode() method misses a case
    for inputs with type=hidden (this resulted in a failing WPT test
    passing).
    
    I've also implemented the Default trait for InputType, so we now only
    have one place in the code which knows that InputType::Text is the
    default, where previously there were several.
    jonleighton committed Dec 6, 2017
    Configuration menu
    Copy the full SHA
    05bfb8d View commit details
    Browse the repository at this point in the history