Chromium HTML5 新的 Input 类型tel对应c++

时间:2024-10-28 18:29:41

一、Input 类型: tel

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>test</title> 
</head>
<body>

<form action="demo-form.php">
  电话号码: <input type="tel" name="usrtel"><br>
  <input type="submit">
</form>

</body>
</html>

二、tel c++接口定义:

third_party\blink\renderer\core\html\forms\telephone_input_type.h

third_party\blink\renderer\core\html\forms\telephone_input_type.cc

namespace blink {

class TelephoneInputType final : public BaseTextInputType {
 public:
  explicit TelephoneInputType(HTMLInputElement& element)
      : BaseTextInputType(Type::kTelephone, element) {}

 private:
  void CountUsage() override;
};

template <>
struct DowncastTraits<TelephoneInputType> {
  static bool AllowFrom(const InputType& type) {
    return type.IsTelephoneInputType();
  }
};

}  // namespace blink

三、看下tel构建堆栈: