PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/third_party/blink/renderer/core/html/forms/input_type.h

http://github.com/chromium/chromium
C Header | 282 lines | 169 code | 38 blank | 75 comment | 0 complexity | d79825875b54571b8d574e775f6b4370 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.0, BSD-2-Clause, LGPL-2.1, MPL-2.0, 0BSD, EPL-1.0, MPL-2.0-no-copyleft-exception, GPL-2.0, BitTorrent-1.0, CPL-1.0, LGPL-3.0, Unlicense, BSD-3-Clause, CC0-1.0, JSON, MIT, GPL-3.0, CC-BY-SA-3.0, AGPL-1.0
  1. /*
  2. * Copyright (C) 2010 Google Inc. All rights reserved.
  3. * Copyright (C) 2011 Apple Inc. All rights reserved.
  4. * Copyright (C) 2012 Samsung Electronics. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of Google Inc. nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FORMS_INPUT_TYPE_H_
  33. #define THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FORMS_INPUT_TYPE_H_
  34. #include "base/macros.h"
  35. #include "third_party/blink/renderer/core/core_export.h"
  36. #include "third_party/blink/renderer/core/frame/web_feature_forward.h"
  37. #include "third_party/blink/renderer/core/html/forms/color_chooser_client.h"
  38. #include "third_party/blink/renderer/core/html/forms/step_range.h"
  39. #include "third_party/blink/renderer/core/html/forms/text_control_element.h"
  40. namespace blink {
  41. class ChromeClient;
  42. class DragData;
  43. class ExceptionState;
  44. class FileList;
  45. class FormData;
  46. class InputTypeView;
  47. // An InputType object represents the type-specific part of an HTMLInputElement.
  48. // Do not expose instances of InputType and classes derived from it to classes
  49. // other than HTMLInputElement.
  50. class CORE_EXPORT InputType : public GarbageCollected<InputType> {
  51. public:
  52. static InputType* Create(HTMLInputElement&, const AtomicString&);
  53. static const AtomicString& NormalizeTypeName(const AtomicString&);
  54. virtual ~InputType();
  55. virtual void Trace(Visitor*);
  56. virtual InputTypeView* CreateView() = 0;
  57. virtual const AtomicString& FormControlType() const = 0;
  58. // Type query functions
  59. // Any time we are using one of these functions it's best to refactor
  60. // to add a virtual function to allow the input type object to do the
  61. // work instead, or at least make a query function that asks a higher
  62. // level question. These functions make the HTMLInputElement class
  63. // inflexible because it's harder to add new input types if there is
  64. // scattered code with special cases for various types.
  65. virtual bool IsInteractiveContent() const;
  66. virtual bool IsTextButton() const;
  67. virtual bool IsTextField() const;
  68. // Form value functions
  69. virtual bool ShouldSaveAndRestoreFormControlState() const;
  70. virtual bool IsFormDataAppendable() const;
  71. virtual void AppendToFormData(FormData&) const;
  72. virtual String ResultForDialogSubmit() const;
  73. // DOM property functions
  74. // Returns a string value in ValueMode::kFilename.
  75. virtual String ValueInFilenameValueMode() const;
  76. // Default string to be used for showing button and form submission if |value|
  77. // is missing.
  78. virtual String DefaultLabel() const;
  79. // https://html.spec.whatwg.org/C/#dom-input-value
  80. enum class ValueMode { kValue, kDefault, kDefaultOn, kFilename };
  81. virtual ValueMode GetValueMode() const = 0;
  82. virtual double ValueAsDate() const;
  83. virtual void SetValueAsDate(const base::Optional<base::Time>&,
  84. ExceptionState&) const;
  85. virtual double ValueAsDouble() const;
  86. virtual void SetValueAsDouble(double,
  87. TextFieldEventBehavior,
  88. ExceptionState&) const;
  89. virtual void SetValueAsDecimal(const Decimal&,
  90. TextFieldEventBehavior,
  91. ExceptionState&) const;
  92. // Functions related to 'checked'
  93. virtual void ReadingChecked() const;
  94. // The function is called just before updating checkedness.
  95. virtual void WillUpdateCheckedness(bool new_checked);
  96. // Validation functions
  97. // Returns a validation message as .first, and title attribute value as
  98. // .second if patternMismatch.
  99. std::pair<String, String> ValidationMessage(const InputTypeView&) const;
  100. virtual bool SupportsValidation() const;
  101. virtual bool TypeMismatchFor(const String&) const;
  102. // Type check for the current input value. We do nothing for some types
  103. // though typeMismatchFor() does something for them because of value
  104. // sanitization.
  105. virtual bool TypeMismatch() const;
  106. virtual bool SupportsRequired() const;
  107. virtual bool ValueMissing(const String&) const;
  108. virtual bool PatternMismatch(const String&) const;
  109. virtual bool TooLong(const String&,
  110. TextControlElement::NeedsToCheckDirtyFlag) const;
  111. virtual bool TooShort(const String&,
  112. TextControlElement::NeedsToCheckDirtyFlag) const;
  113. bool RangeUnderflow(const String&) const;
  114. bool RangeOverflow(const String&) const;
  115. bool IsInRange(const String&) const;
  116. bool IsOutOfRange(const String&) const;
  117. void InRangeChanged() const;
  118. virtual Decimal DefaultValueForStepUp() const;
  119. double Minimum() const;
  120. double Maximum() const;
  121. bool StepMismatch(const String&) const;
  122. bool GetAllowedValueStep(Decimal*) const;
  123. virtual StepRange CreateStepRange(AnyStepHandling) const;
  124. void StepUp(double, ExceptionState&);
  125. void StepUpFromLayoutObject(int);
  126. virtual String BadInputText() const;
  127. virtual String RangeOverflowText(const Decimal& maximum) const;
  128. virtual String RangeUnderflowText(const Decimal& minimum) const;
  129. virtual String ReversedRangeOutOfRangeText(const Decimal& minimum,
  130. const Decimal& maximum) const;
  131. virtual String RangeInvalidText(const Decimal& minimum,
  132. const Decimal& maximum) const;
  133. virtual String TypeMismatchText() const;
  134. virtual String ValueMissingText() const;
  135. virtual bool CanSetStringValue() const;
  136. virtual String LocalizeValue(const String&) const;
  137. virtual String VisibleValue() const;
  138. // Returing the null string means "use the default value."
  139. // This function must be called only by HTMLInputElement::sanitizeValue().
  140. virtual String SanitizeValue(const String&) const;
  141. virtual String SanitizeUserInputValue(const String&) const;
  142. virtual void WarnIfValueIsInvalid(const String&) const;
  143. void WarnIfValueIsInvalidAndElementIsVisible(const String&) const;
  144. virtual bool IsKeyboardFocusable() const;
  145. virtual bool MayTriggerVirtualKeyboard() const;
  146. virtual bool CanBeSuccessfulSubmitButton();
  147. virtual bool MatchesDefaultPseudoClass();
  148. // Miscellaneous functions
  149. virtual bool LayoutObjectIsNeeded();
  150. virtual void CountUsage();
  151. virtual void SanitizeValueInResponseToMinOrMaxAttributeChange();
  152. virtual bool ShouldRespectAlignAttribute();
  153. virtual FileList* Files();
  154. // Should return true if the file list was were changed.
  155. virtual bool SetFiles(FileList*);
  156. virtual void SetFilesAndDispatchEvents(FileList*);
  157. virtual void SetFilesFromPaths(const Vector<String>&);
  158. // Should return true if the given DragData has more than one dropped files.
  159. virtual bool ReceiveDroppedFiles(const DragData*);
  160. virtual String DroppedFileSystemId();
  161. // Should return true if the corresponding layoutObject for a type can display
  162. // a suggested value.
  163. virtual bool CanSetSuggestedValue();
  164. virtual bool ShouldSendChangeEventAfterCheckedChanged();
  165. virtual bool CanSetValue(const String&);
  166. virtual void SetValue(const String&,
  167. bool value_changed,
  168. TextFieldEventBehavior,
  169. TextControlSetValueSelection);
  170. virtual bool ShouldRespectListAttribute();
  171. virtual bool IsEnumeratable();
  172. virtual bool IsCheckable();
  173. virtual bool IsSteppable() const;
  174. virtual bool ShouldRespectHeightAndWidthAttributes();
  175. virtual int MaxLength() const;
  176. virtual int MinLength() const;
  177. virtual bool SupportsPlaceholder() const;
  178. virtual bool SupportsReadOnly() const;
  179. virtual String DefaultToolTip(const InputTypeView&) const;
  180. virtual Decimal FindClosestTickMarkValue(const Decimal&);
  181. virtual bool HasLegalLinkAttribute(const QualifiedName&) const;
  182. virtual const QualifiedName& SubResourceAttributeName() const;
  183. virtual void CopyNonAttributeProperties(const HTMLInputElement&);
  184. virtual void OnAttachWithLayoutObject();
  185. // Parses the specified string for the type, and return
  186. // the Decimal value for the parsing result if the parsing
  187. // succeeds; Returns defaultValue otherwise. This function can
  188. // return NaN or Infinity only if defaultValue is NaN or Infinity.
  189. virtual Decimal ParseToNumber(const String&,
  190. const Decimal& default_value) const;
  191. // Create a string representation of the specified Decimal value for the
  192. // input type. If NaN or Infinity is specified, this returns an empty
  193. // string. This should not be called for types without valueAsNumber.
  194. virtual String Serialize(const Decimal&) const;
  195. virtual bool ShouldAppearIndeterminate() const;
  196. virtual bool SupportsInputModeAttribute() const;
  197. virtual bool SupportsSelectionAPI() const;
  198. // Gets width and height of the input element if the type of the
  199. // element is image. It returns 0 if the element is not image type.
  200. virtual unsigned Height() const;
  201. virtual unsigned Width() const;
  202. virtual void DispatchSearchEvent();
  203. // For test purpose
  204. virtual ColorChooserClient* GetColorChooserClient();
  205. protected:
  206. InputType(HTMLInputElement& element) : element_(element) {}
  207. HTMLInputElement& GetElement() const { return *element_; }
  208. ChromeClient* GetChromeClient() const;
  209. Locale& GetLocale() const;
  210. Decimal ParseToNumberOrNaN(const String&) const;
  211. void CountUsageIfVisible(WebFeature) const;
  212. // Derive the step base, following the HTML algorithm steps.
  213. Decimal FindStepBase(const Decimal&) const;
  214. StepRange CreateStepRange(AnyStepHandling,
  215. const Decimal& step_base_default,
  216. const Decimal& minimum_default,
  217. const Decimal& maximum_default,
  218. const StepRange::StepDescription&) const;
  219. StepRange CreateReversibleStepRange(AnyStepHandling,
  220. const Decimal& step_base_default,
  221. const Decimal& minimum_default,
  222. const Decimal& maximum_default,
  223. const StepRange::StepDescription&) const;
  224. void AddWarningToConsole(const char* message_format,
  225. const String& value) const;
  226. private:
  227. // Helper for stepUp()/stepDown(). Adds step value * count to the current
  228. // value.
  229. void ApplyStep(const Decimal&,
  230. double count,
  231. AnyStepHandling,
  232. TextFieldEventBehavior,
  233. ExceptionState&);
  234. StepRange CreateStepRange(AnyStepHandling,
  235. const Decimal& step_base_default,
  236. const Decimal& minimum_default,
  237. const Decimal& maximum_default,
  238. const StepRange::StepDescription&,
  239. bool supports_reversed_range) const;
  240. Member<HTMLInputElement> element_;
  241. DISALLOW_COPY_AND_ASSIGN(InputType);
  242. };
  243. } // namespace blink
  244. #endif