From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WebCore/html/Autocapitalize.cpp | 79 + Source/WebCore/html/Autocapitalize.h | 36 + Source/WebCore/html/AutocapitalizeTypes.h | 34 + Source/WebCore/html/Autofill.cpp | 316 + Source/WebCore/html/Autofill.h | 115 + Source/WebCore/html/BaseButtonInputType.cpp | 7 +- Source/WebCore/html/BaseButtonInputType.h | 15 +- Source/WebCore/html/BaseCheckableInputType.cpp | 15 +- Source/WebCore/html/BaseCheckableInputType.h | 27 +- .../html/BaseChooserOnlyDateAndTimeInputType.cpp | 29 +- .../html/BaseChooserOnlyDateAndTimeInputType.h | 30 +- .../WebCore/html/BaseClickableWithKeyInputType.cpp | 24 +- .../WebCore/html/BaseClickableWithKeyInputType.h | 19 +- Source/WebCore/html/BaseDateAndTimeInputType.cpp | 20 +- Source/WebCore/html/BaseDateAndTimeInputType.h | 44 +- Source/WebCore/html/BaseTextInputType.cpp | 2 +- Source/WebCore/html/BaseTextInputType.h | 13 +- Source/WebCore/html/ButtonInputType.h | 13 +- Source/WebCore/html/CachedHTMLCollection.h | 157 + Source/WebCore/html/CheckboxInputType.cpp | 13 +- Source/WebCore/html/CheckboxInputType.h | 24 +- Source/WebCore/html/ClassList.cpp | 88 - Source/WebCore/html/ClassList.h | 66 - Source/WebCore/html/CollectionTraversal.h | 245 + Source/WebCore/html/CollectionType.h | 47 +- Source/WebCore/html/ColorInputType.cpp | 101 +- Source/WebCore/html/ColorInputType.h | 53 +- Source/WebCore/html/DOMFormData.cpp | 9 +- Source/WebCore/html/DOMFormData.h | 12 +- Source/WebCore/html/DOMFormData.idl | 9 +- Source/WebCore/html/DOMSettableTokenList.cpp | 74 - Source/WebCore/html/DOMSettableTokenList.h | 61 - Source/WebCore/html/DOMSettableTokenList.idl | 33 - Source/WebCore/html/DOMTokenList.cpp | 306 +- Source/WebCore/html/DOMTokenList.h | 87 +- Source/WebCore/html/DOMTokenList.idl | 20 +- Source/WebCore/html/DOMURL.cpp | 126 +- Source/WebCore/html/DOMURL.h | 40 +- Source/WebCore/html/DOMURL.idl | 29 +- Source/WebCore/html/DateInputType.cpp | 18 +- Source/WebCore/html/DateInputType.h | 20 +- Source/WebCore/html/DateTimeInputType.cpp | 18 +- Source/WebCore/html/DateTimeInputType.h | 24 +- Source/WebCore/html/DateTimeLocalInputType.cpp | 25 +- Source/WebCore/html/DateTimeLocalInputType.h | 24 +- Source/WebCore/html/EmailInputType.cpp | 23 +- Source/WebCore/html/EmailInputType.h | 22 +- Source/WebCore/html/FTPDirectoryDocument.cpp | 196 +- Source/WebCore/html/FTPDirectoryDocument.h | 27 +- Source/WebCore/html/FileInputType.cpp | 235 +- Source/WebCore/html/FileInputType.h | 65 +- Source/WebCore/html/FormAssociatedElement.cpp | 83 +- Source/WebCore/html/FormAssociatedElement.h | 21 +- Source/WebCore/html/FormController.cpp | 110 +- Source/WebCore/html/FormController.h | 26 +- Source/WebCore/html/FormDataList.cpp | 7 +- Source/WebCore/html/FormDataList.h | 16 +- Source/WebCore/html/FormNamedItem.h | 7 +- .../WebCore/html/GenericCachedHTMLCollection.cpp | 94 + Source/WebCore/html/GenericCachedHTMLCollection.h | 48 + Source/WebCore/html/HTMLAllCollection.cpp | 39 +- Source/WebCore/html/HTMLAllCollection.h | 15 +- Source/WebCore/html/HTMLAllCollection.idl | 11 +- Source/WebCore/html/HTMLAnchorElement.cpp | 384 +- Source/WebCore/html/HTMLAnchorElement.h | 120 +- Source/WebCore/html/HTMLAnchorElement.idl | 43 +- Source/WebCore/html/HTMLAppletElement.cpp | 63 +- Source/WebCore/html/HTMLAppletElement.h | 20 +- Source/WebCore/html/HTMLAppletElement.idl | 19 +- Source/WebCore/html/HTMLAreaElement.cpp | 81 +- Source/WebCore/html/HTMLAreaElement.h | 39 +- Source/WebCore/html/HTMLAreaElement.idl | 22 +- Source/WebCore/html/HTMLAttachmentElement.cpp | 97 + Source/WebCore/html/HTMLAttachmentElement.h | 70 + Source/WebCore/html/HTMLAttachmentElement.idl | 30 + Source/WebCore/html/HTMLAttributeNames.in | 46 +- Source/WebCore/html/HTMLAudioElement.cpp | 20 +- Source/WebCore/html/HTMLAudioElement.h | 25 +- Source/WebCore/html/HTMLAudioElement.idl | 6 +- Source/WebCore/html/HTMLBDIElement.h | 9 +- Source/WebCore/html/HTMLBRElement.cpp | 19 +- Source/WebCore/html/HTMLBRElement.h | 17 +- Source/WebCore/html/HTMLBaseElement.cpp | 15 +- Source/WebCore/html/HTMLBaseElement.h | 23 +- Source/WebCore/html/HTMLBaseElement.idl | 3 +- Source/WebCore/html/HTMLBaseFontElement.cpp | 43 - Source/WebCore/html/HTMLBaseFontElement.h | 40 - Source/WebCore/html/HTMLBaseFontElement.idl | 28 - Source/WebCore/html/HTMLBodyElement.cpp | 306 +- Source/WebCore/html/HTMLBodyElement.h | 67 +- Source/WebCore/html/HTMLBodyElement.idl | 53 +- Source/WebCore/html/HTMLButtonElement.cpp | 76 +- Source/WebCore/html/HTMLButtonElement.h | 54 +- Source/WebCore/html/HTMLButtonElement.idl | 21 +- Source/WebCore/html/HTMLCanvasElement.cpp | 567 +- Source/WebCore/html/HTMLCanvasElement.h | 119 +- Source/WebCore/html/HTMLCanvasElement.idl | 25 +- Source/WebCore/html/HTMLCollection.cpp | 424 +- Source/WebCore/html/HTMLCollection.h | 252 +- Source/WebCore/html/HTMLCollection.idl | 13 +- Source/WebCore/html/HTMLDListElement.cpp | 4 +- Source/WebCore/html/HTMLDListElement.h | 9 +- Source/WebCore/html/HTMLDataElement.cpp | 46 + Source/WebCore/html/HTMLDataElement.h | 40 + Source/WebCore/html/HTMLDataElement.idl | 28 + Source/WebCore/html/HTMLDataListElement.cpp | 12 +- Source/WebCore/html/HTMLDataListElement.h | 13 +- Source/WebCore/html/HTMLDetailsElement.cpp | 184 +- Source/WebCore/html/HTMLDetailsElement.h | 34 +- Source/WebCore/html/HTMLDetailsElement.idl | 5 +- Source/WebCore/html/HTMLDirectoryElement.cpp | 4 +- Source/WebCore/html/HTMLDirectoryElement.h | 9 +- Source/WebCore/html/HTMLDivElement.cpp | 15 +- Source/WebCore/html/HTMLDivElement.h | 13 +- Source/WebCore/html/HTMLDocument.cpp | 143 +- Source/WebCore/html/HTMLDocument.h | 73 +- Source/WebCore/html/HTMLDocument.idl | 42 +- Source/WebCore/html/HTMLElement.cpp | 815 ++- Source/WebCore/html/HTMLElement.h | 135 +- Source/WebCore/html/HTMLElement.idl | 57 +- Source/WebCore/html/HTMLElementsAllInOne.cpp | 116 + Source/WebCore/html/HTMLEmbedElement.cpp | 87 +- Source/WebCore/html/HTMLEmbedElement.h | 30 +- Source/WebCore/html/HTMLEmbedElement.idl | 29 +- Source/WebCore/html/HTMLFieldSetElement.cpp | 150 +- Source/WebCore/html/HTMLFieldSetElement.h | 52 +- Source/WebCore/html/HTMLFieldSetElement.idl | 7 +- Source/WebCore/html/HTMLFontElement.cpp | 9 +- Source/WebCore/html/HTMLFontElement.h | 13 +- Source/WebCore/html/HTMLFontElement.idl | 2 +- Source/WebCore/html/HTMLFormControlElement.cpp | 426 +- Source/WebCore/html/HTMLFormControlElement.h | 153 +- .../html/HTMLFormControlElementWithState.cpp | 19 +- .../WebCore/html/HTMLFormControlElementWithState.h | 18 +- Source/WebCore/html/HTMLFormControlsCollection.cpp | 116 +- Source/WebCore/html/HTMLFormControlsCollection.h | 32 +- Source/WebCore/html/HTMLFormControlsCollection.idl | 5 +- Source/WebCore/html/HTMLFormElement.cpp | 543 +- Source/WebCore/html/HTMLFormElement.h | 142 +- Source/WebCore/html/HTMLFormElement.idl | 32 +- Source/WebCore/html/HTMLFrameElement.cpp | 17 +- Source/WebCore/html/HTMLFrameElement.h | 32 +- Source/WebCore/html/HTMLFrameElement.idl | 27 +- Source/WebCore/html/HTMLFrameElementBase.cpp | 80 +- Source/WebCore/html/HTMLFrameElementBase.h | 61 +- Source/WebCore/html/HTMLFrameOwnerElement.cpp | 51 +- Source/WebCore/html/HTMLFrameOwnerElement.h | 40 +- Source/WebCore/html/HTMLFrameSetElement.cpp | 129 +- Source/WebCore/html/HTMLFrameSetElement.h | 48 +- Source/WebCore/html/HTMLFrameSetElement.idl | 38 +- Source/WebCore/html/HTMLHRElement.cpp | 22 +- Source/WebCore/html/HTMLHRElement.h | 16 +- Source/WebCore/html/HTMLHRElement.idl | 1 + Source/WebCore/html/HTMLHeadElement.cpp | 8 +- Source/WebCore/html/HTMLHeadElement.h | 11 +- Source/WebCore/html/HTMLHeadingElement.cpp | 4 +- Source/WebCore/html/HTMLHeadingElement.h | 7 +- Source/WebCore/html/HTMLHtmlElement.cpp | 16 +- Source/WebCore/html/HTMLHtmlElement.h | 15 +- Source/WebCore/html/HTMLHyperlinkElementUtils.idl | 41 + Source/WebCore/html/HTMLIFrameElement.cpp | 45 +- Source/WebCore/html/HTMLIFrameElement.h | 30 +- Source/WebCore/html/HTMLIFrameElement.idl | 23 +- Source/WebCore/html/HTMLImageElement.cpp | 446 +- Source/WebCore/html/HTMLImageElement.h | 112 +- Source/WebCore/html/HTMLImageElement.idl | 32 +- Source/WebCore/html/HTMLImageLoader.cpp | 43 +- Source/WebCore/html/HTMLImageLoader.h | 17 +- Source/WebCore/html/HTMLInputElement.cpp | 962 +-- Source/WebCore/html/HTMLInputElement.h | 364 +- Source/WebCore/html/HTMLInputElement.idl | 100 +- Source/WebCore/html/HTMLKeygenElement.cpp | 58 +- Source/WebCore/html/HTMLKeygenElement.h | 35 +- Source/WebCore/html/HTMLKeygenElement.idl | 5 +- Source/WebCore/html/HTMLLIElement.cpp | 43 +- Source/WebCore/html/HTMLLIElement.h | 19 +- Source/WebCore/html/HTMLLabelElement.cpp | 76 +- Source/WebCore/html/HTMLLabelElement.h | 30 +- Source/WebCore/html/HTMLLabelElement.idl | 3 - Source/WebCore/html/HTMLLegendElement.cpp | 39 +- Source/WebCore/html/HTMLLegendElement.h | 22 +- Source/WebCore/html/HTMLLegendElement.idl | 3 - Source/WebCore/html/HTMLLinkElement.cpp | 403 +- Source/WebCore/html/HTMLLinkElement.h | 85 +- Source/WebCore/html/HTMLLinkElement.idl | 20 +- Source/WebCore/html/HTMLMapElement.cpp | 35 +- Source/WebCore/html/HTMLMapElement.h | 19 +- Source/WebCore/html/HTMLMarqueeElement.cpp | 65 +- Source/WebCore/html/HTMLMarqueeElement.h | 42 +- Source/WebCore/html/HTMLMarqueeElement.idl | 12 +- Source/WebCore/html/HTMLMediaElement.cpp | 5551 ++++++++++------ Source/WebCore/html/HTMLMediaElement.h | 1080 ++-- Source/WebCore/html/HTMLMediaElement.idl | 88 +- Source/WebCore/html/HTMLMediaElementEnums.h | 61 + Source/WebCore/html/HTMLMediaSession.cpp | 189 - Source/WebCore/html/HTMLMediaSession.h | 83 - Source/WebCore/html/HTMLMediaSource.cpp | 44 - Source/WebCore/html/HTMLMediaSource.h | 76 - Source/WebCore/html/HTMLMenuElement.cpp | 4 +- Source/WebCore/html/HTMLMenuElement.h | 9 +- Source/WebCore/html/HTMLMetaElement.cpp | 47 +- Source/WebCore/html/HTMLMetaElement.h | 20 +- Source/WebCore/html/HTMLMeterElement.cpp | 140 +- Source/WebCore/html/HTMLMeterElement.h | 41 +- Source/WebCore/html/HTMLMeterElement.idl | 12 +- Source/WebCore/html/HTMLModElement.cpp | 4 +- Source/WebCore/html/HTMLModElement.h | 11 +- Source/WebCore/html/HTMLModElement.idl | 2 +- Source/WebCore/html/HTMLNameCollection.cpp | 60 +- Source/WebCore/html/HTMLNameCollection.h | 65 +- Source/WebCore/html/HTMLOListElement.cpp | 37 +- Source/WebCore/html/HTMLOListElement.h | 40 +- Source/WebCore/html/HTMLOListElement.idl | 2 +- Source/WebCore/html/HTMLObjectElement.cpp | 225 +- Source/WebCore/html/HTMLObjectElement.h | 88 +- Source/WebCore/html/HTMLObjectElement.idl | 28 +- Source/WebCore/html/HTMLOptGroupElement.cpp | 70 +- Source/WebCore/html/HTMLOptGroupElement.h | 36 +- Source/WebCore/html/HTMLOptGroupElement.idl | 4 +- Source/WebCore/html/HTMLOptionElement.cpp | 157 +- Source/WebCore/html/HTMLOptionElement.h | 59 +- Source/WebCore/html/HTMLOptionElement.idl | 10 +- Source/WebCore/html/HTMLOptionsCollection.cpp | 45 +- Source/WebCore/html/HTMLOptionsCollection.h | 65 +- Source/WebCore/html/HTMLOptionsCollection.idl | 23 +- Source/WebCore/html/HTMLOutputElement.cpp | 39 +- Source/WebCore/html/HTMLOutputElement.h | 35 +- Source/WebCore/html/HTMLOutputElement.idl | 10 +- Source/WebCore/html/HTMLParagraphElement.cpp | 15 +- Source/WebCore/html/HTMLParagraphElement.h | 13 +- Source/WebCore/html/HTMLParamElement.cpp | 9 +- Source/WebCore/html/HTMLParamElement.h | 13 +- Source/WebCore/html/HTMLParserErrorCodes.cpp | 28 - Source/WebCore/html/HTMLParserErrorCodes.h | 26 - Source/WebCore/html/HTMLParserQuirks.h | 26 - Source/WebCore/html/HTMLPictureElement.cpp | 74 + Source/WebCore/html/HTMLPictureElement.h | 57 + Source/WebCore/html/HTMLPictureElement.idl | 28 + Source/WebCore/html/HTMLPlugInElement.cpp | 168 +- Source/WebCore/html/HTMLPlugInElement.h | 66 +- Source/WebCore/html/HTMLPlugInImageElement.cpp | 561 +- Source/WebCore/html/HTMLPlugInImageElement.h | 139 +- Source/WebCore/html/HTMLPreElement.cpp | 5 +- Source/WebCore/html/HTMLPreElement.h | 11 +- Source/WebCore/html/HTMLProgressElement.cpp | 61 +- Source/WebCore/html/HTMLProgressElement.h | 34 +- Source/WebCore/html/HTMLProgressElement.idl | 13 +- Source/WebCore/html/HTMLQuoteElement.cpp | 13 +- Source/WebCore/html/HTMLQuoteElement.h | 14 +- Source/WebCore/html/HTMLQuoteElement.idl | 2 +- Source/WebCore/html/HTMLScriptElement.cpp | 80 +- Source/WebCore/html/HTMLScriptElement.h | 58 +- Source/WebCore/html/HTMLScriptElement.idl | 10 +- Source/WebCore/html/HTMLSelectElement.cpp | 767 ++- Source/WebCore/html/HTMLSelectElement.h | 141 +- Source/WebCore/html/HTMLSelectElement.idl | 44 +- Source/WebCore/html/HTMLSelectElementWin.cpp | 61 + Source/WebCore/html/HTMLSlotElement.cpp | 155 + Source/WebCore/html/HTMLSlotElement.h | 59 + Source/WebCore/html/HTMLSlotElement.idl | 36 + Source/WebCore/html/HTMLSourceElement.cpp | 104 +- Source/WebCore/html/HTMLSourceElement.h | 42 +- Source/WebCore/html/HTMLSourceElement.idl | 16 +- Source/WebCore/html/HTMLSpanElement.cpp | 9 +- Source/WebCore/html/HTMLSpanElement.h | 12 +- Source/WebCore/html/HTMLStyleElement.cpp | 57 +- Source/WebCore/html/HTMLStyleElement.h | 44 +- Source/WebCore/html/HTMLStyleElement.idl | 2 + Source/WebCore/html/HTMLSummaryElement.cpp | 116 +- Source/WebCore/html/HTMLSummaryElement.h | 28 +- Source/WebCore/html/HTMLTableCaptionElement.cpp | 5 +- Source/WebCore/html/HTMLTableCaptionElement.h | 15 +- Source/WebCore/html/HTMLTableCellElement.cpp | 95 +- Source/WebCore/html/HTMLTableCellElement.h | 45 +- Source/WebCore/html/HTMLTableCellElement.idl | 14 +- Source/WebCore/html/HTMLTableColElement.cpp | 34 +- Source/WebCore/html/HTMLTableColElement.h | 21 +- Source/WebCore/html/HTMLTableColElement.idl | 3 +- Source/WebCore/html/HTMLTableElement.cpp | 298 +- Source/WebCore/html/HTMLTableElement.h | 75 +- Source/WebCore/html/HTMLTableElement.idl | 23 +- Source/WebCore/html/HTMLTablePartElement.cpp | 25 +- Source/WebCore/html/HTMLTablePartElement.h | 11 +- Source/WebCore/html/HTMLTableRowElement.cpp | 161 +- Source/WebCore/html/HTMLTableRowElement.h | 23 +- Source/WebCore/html/HTMLTableRowElement.idl | 7 +- Source/WebCore/html/HTMLTableRowsCollection.cpp | 73 +- Source/WebCore/html/HTMLTableRowsCollection.h | 28 +- Source/WebCore/html/HTMLTableSectionElement.cpp | 131 +- Source/WebCore/html/HTMLTableSectionElement.h | 39 +- Source/WebCore/html/HTMLTableSectionElement.idl | 5 +- Source/WebCore/html/HTMLTagNames.in | 114 +- Source/WebCore/html/HTMLTemplateElement.cpp | 41 +- Source/WebCore/html/HTMLTemplateElement.h | 19 +- Source/WebCore/html/HTMLTemplateElement.idl | 4 +- Source/WebCore/html/HTMLTextAreaElement.cpp | 247 +- Source/WebCore/html/HTMLTextAreaElement.h | 124 +- Source/WebCore/html/HTMLTextAreaElement.idl | 36 +- Source/WebCore/html/HTMLTextFormControlElement.cpp | 469 +- Source/WebCore/html/HTMLTextFormControlElement.h | 111 +- Source/WebCore/html/HTMLTimeElement.cpp | 46 + Source/WebCore/html/HTMLTimeElement.h | 40 + Source/WebCore/html/HTMLTimeElement.idl | 28 + Source/WebCore/html/HTMLTitleElement.cpp | 61 +- Source/WebCore/html/HTMLTitleElement.h | 24 +- Source/WebCore/html/HTMLTitleElement.idl | 4 +- Source/WebCore/html/HTMLTrackElement.cpp | 201 +- Source/WebCore/html/HTMLTrackElement.h | 57 +- Source/WebCore/html/HTMLTrackElement.idl | 10 +- Source/WebCore/html/HTMLUListElement.cpp | 9 +- Source/WebCore/html/HTMLUListElement.h | 15 +- Source/WebCore/html/HTMLUnknownElement.h | 23 +- Source/WebCore/html/HTMLVideoElement.cpp | 282 +- Source/WebCore/html/HTMLVideoElement.h | 121 +- Source/WebCore/html/HTMLVideoElement.idl | 30 +- Source/WebCore/html/HTMLViewSourceDocument.cpp | 294 - Source/WebCore/html/HTMLViewSourceDocument.h | 73 - Source/WebCore/html/HTMLWBRElement.cpp | 52 + Source/WebCore/html/HTMLWBRElement.h | 46 + Source/WebCore/html/HiddenInputType.cpp | 8 +- Source/WebCore/html/HiddenInputType.h | 33 +- Source/WebCore/html/ImageData.cpp | 73 +- Source/WebCore/html/ImageData.h | 19 +- Source/WebCore/html/ImageData.idl | 17 +- Source/WebCore/html/ImageDocument.cpp | 399 +- Source/WebCore/html/ImageDocument.h | 74 +- Source/WebCore/html/ImageInputType.cpp | 74 +- Source/WebCore/html/ImageInputType.h | 39 +- Source/WebCore/html/InputType.cpp | 220 +- Source/WebCore/html/InputType.h | 151 +- Source/WebCore/html/InputTypeNames.cpp | 48 +- Source/WebCore/html/InputTypeNames.h | 6 +- Source/WebCore/html/LabelableElement.cpp | 6 +- Source/WebCore/html/LabelableElement.h | 19 +- Source/WebCore/html/LabelsNodeList.cpp | 8 +- Source/WebCore/html/LabelsNodeList.h | 19 +- Source/WebCore/html/LinkIconCollector.cpp | 117 + Source/WebCore/html/LinkIconCollector.h | 49 + Source/WebCore/html/LinkIconType.h | 38 + Source/WebCore/html/LinkRelAttribute.cpp | 105 +- Source/WebCore/html/LinkRelAttribute.h | 30 +- Source/WebCore/html/MediaController.cpp | 192 +- Source/WebCore/html/MediaController.h | 153 +- Source/WebCore/html/MediaController.idl | 27 +- Source/WebCore/html/MediaControllerInterface.h | 33 +- Source/WebCore/html/MediaDocument.cpp | 185 +- Source/WebCore/html/MediaDocument.h | 31 +- Source/WebCore/html/MediaElementSession.cpp | 783 +++ Source/WebCore/html/MediaElementSession.h | 185 + Source/WebCore/html/MediaEncryptedEvent.cpp | 64 + Source/WebCore/html/MediaEncryptedEvent.h | 65 + Source/WebCore/html/MediaEncryptedEvent.idl | 41 + Source/WebCore/html/MediaEncryptedEventInit.h | 53 + Source/WebCore/html/MediaError.h | 15 +- Source/WebCore/html/MediaError.idl | 6 +- Source/WebCore/html/MediaFragmentURIParser.cpp | 53 +- Source/WebCore/html/MediaFragmentURIParser.h | 25 +- Source/WebCore/html/MediaKeyError.h | 64 - Source/WebCore/html/MediaKeyError.idl | 39 - Source/WebCore/html/MediaKeyEvent.cpp | 68 - Source/WebCore/html/MediaKeyEvent.h | 88 - Source/WebCore/html/MediaKeyEvent.idl | 38 - Source/WebCore/html/MonthInputType.cpp | 18 +- Source/WebCore/html/MonthInputType.h | 30 +- Source/WebCore/html/NumberInputType.cpp | 100 +- Source/WebCore/html/NumberInputType.h | 57 +- Source/WebCore/html/PasswordInputType.cpp | 5 - Source/WebCore/html/PasswordInputType.h | 24 +- Source/WebCore/html/PluginDocument.cpp | 99 +- Source/WebCore/html/PluginDocument.h | 38 +- Source/WebCore/html/PublicURLManager.cpp | 54 +- Source/WebCore/html/PublicURLManager.h | 26 +- Source/WebCore/html/RadioInputType.cpp | 62 +- Source/WebCore/html/RadioInputType.h | 32 +- Source/WebCore/html/RadioNodeList.cpp | 57 +- Source/WebCore/html/RadioNodeList.h | 32 +- Source/WebCore/html/RadioNodeList.idl | 3 +- Source/WebCore/html/RangeInputType.cpp | 120 +- Source/WebCore/html/RangeInputType.h | 71 +- Source/WebCore/html/ResetInputType.cpp | 4 +- Source/WebCore/html/ResetInputType.h | 17 +- Source/WebCore/html/RubyElement.cpp | 60 + Source/WebCore/html/RubyElement.h | 42 + Source/WebCore/html/RubyTextElement.cpp | 61 + Source/WebCore/html/RubyTextElement.h | 42 + Source/WebCore/html/SearchInputType.cpp | 84 +- Source/WebCore/html/SearchInputType.h | 44 +- Source/WebCore/html/StepRange.cpp | 14 +- Source/WebCore/html/StepRange.h | 20 +- Source/WebCore/html/SubmitInputType.cpp | 4 +- Source/WebCore/html/SubmitInputType.h | 23 +- Source/WebCore/html/TelephoneInputType.cpp | 11 - Source/WebCore/html/TelephoneInputType.h | 13 +- Source/WebCore/html/TextDocument.cpp | 10 +- Source/WebCore/html/TextDocument.h | 17 +- Source/WebCore/html/TextFieldInputType.cpp | 414 +- Source/WebCore/html/TextFieldInputType.h | 116 +- Source/WebCore/html/TextInputType.cpp | 16 - Source/WebCore/html/TextInputType.h | 11 +- Source/WebCore/html/TextMetrics.h | 9 +- Source/WebCore/html/TextMetrics.idl | 2 +- Source/WebCore/html/TimeInputType.cpp | 18 +- Source/WebCore/html/TimeInputType.h | 24 +- Source/WebCore/html/TimeRanges.cpp | 192 +- Source/WebCore/html/TimeRanges.h | 105 +- Source/WebCore/html/TimeRanges.idl | 10 +- Source/WebCore/html/TypeAhead.h | 5 +- Source/WebCore/html/URLInputType.cpp | 12 +- Source/WebCore/html/URLInputType.h | 19 +- Source/WebCore/html/URLRegistry.h | 7 +- Source/WebCore/html/URLSearchParams.cpp | 168 + Source/WebCore/html/URLSearchParams.h | 74 + Source/WebCore/html/URLSearchParams.idl | 45 + Source/WebCore/html/URLUtils.h | 308 + Source/WebCore/html/ValidationMessage.cpp | 87 +- Source/WebCore/html/ValidationMessage.h | 19 +- Source/WebCore/html/ValidityState.h | 5 +- Source/WebCore/html/ValidityState.idl | 4 +- Source/WebCore/html/VoidCallback.h | 9 +- Source/WebCore/html/VoidCallback.idl | 8 +- Source/WebCore/html/WebKitMediaKeyError.h | 61 + Source/WebCore/html/WebKitMediaKeyError.idl | 38 + Source/WebCore/html/WeekInputType.cpp | 18 +- Source/WebCore/html/WeekInputType.h | 22 +- .../WebCore/html/canvas/ANGLEInstancedArrays.cpp | 31 +- Source/WebCore/html/canvas/ANGLEInstancedArrays.h | 20 +- .../WebCore/html/canvas/ANGLEInstancedArrays.idl | 6 +- .../html/canvas/CanvasContextAttributes.cpp | 41 - .../WebCore/html/canvas/CanvasContextAttributes.h | 48 - Source/WebCore/html/canvas/CanvasGradient.cpp | 38 +- Source/WebCore/html/canvas/CanvasGradient.h | 60 +- Source/WebCore/html/canvas/CanvasGradient.idl | 13 +- Source/WebCore/html/canvas/CanvasPath.cpp | 238 + Source/WebCore/html/canvas/CanvasPath.h | 63 + Source/WebCore/html/canvas/CanvasPath.idl | 41 + Source/WebCore/html/canvas/CanvasPathMethods.cpp | 181 - Source/WebCore/html/canvas/CanvasPathMethods.h | 64 - Source/WebCore/html/canvas/CanvasPattern.cpp | 26 +- Source/WebCore/html/canvas/CanvasPattern.h | 25 +- Source/WebCore/html/canvas/CanvasPattern.idl | 6 +- Source/WebCore/html/canvas/CanvasProxy.cpp | 4 +- Source/WebCore/html/canvas/CanvasProxy.h | 8 +- .../WebCore/html/canvas/CanvasRenderingContext.cpp | 45 +- .../WebCore/html/canvas/CanvasRenderingContext.h | 32 +- .../WebCore/html/canvas/CanvasRenderingContext.idl | 34 - .../html/canvas/CanvasRenderingContext2D.cpp | 2009 +++--- .../WebCore/html/canvas/CanvasRenderingContext2D.h | 333 +- .../html/canvas/CanvasRenderingContext2D.idl | 220 +- Source/WebCore/html/canvas/CanvasStyle.cpp | 304 +- Source/WebCore/html/canvas/CanvasStyle.h | 214 +- Source/WebCore/html/canvas/DOMPath.cpp | 37 + Source/WebCore/html/canvas/DOMPath.h | 47 +- Source/WebCore/html/canvas/DOMPath.idl | 46 +- Source/WebCore/html/canvas/EXTBlendMinMax.cpp | 49 + Source/WebCore/html/canvas/EXTBlendMinMax.h | 40 + Source/WebCore/html/canvas/EXTBlendMinMax.idl | 33 + Source/WebCore/html/canvas/EXTDrawBuffers.cpp | 183 - Source/WebCore/html/canvas/EXTDrawBuffers.h | 53 - Source/WebCore/html/canvas/EXTDrawBuffers.idl | 72 - Source/WebCore/html/canvas/EXTFragDepth.cpp | 49 + Source/WebCore/html/canvas/EXTFragDepth.h | 40 + Source/WebCore/html/canvas/EXTFragDepth.idl | 31 + Source/WebCore/html/canvas/EXTShaderTextureLOD.cpp | 49 + Source/WebCore/html/canvas/EXTShaderTextureLOD.h | 40 + Source/WebCore/html/canvas/EXTShaderTextureLOD.idl | 31 + .../html/canvas/EXTTextureFilterAnisotropic.cpp | 7 +- .../html/canvas/EXTTextureFilterAnisotropic.h | 15 +- .../html/canvas/EXTTextureFilterAnisotropic.idl | 7 +- Source/WebCore/html/canvas/EXTsRGB.cpp | 49 + Source/WebCore/html/canvas/EXTsRGB.h | 40 + Source/WebCore/html/canvas/EXTsRGB.idl | 35 + Source/WebCore/html/canvas/OESElementIndexUint.cpp | 7 +- Source/WebCore/html/canvas/OESElementIndexUint.h | 15 +- .../WebCore/html/canvas/OESStandardDerivatives.cpp | 7 +- .../WebCore/html/canvas/OESStandardDerivatives.h | 15 +- .../WebCore/html/canvas/OESStandardDerivatives.idl | 6 +- Source/WebCore/html/canvas/OESTextureFloat.cpp | 7 +- Source/WebCore/html/canvas/OESTextureFloat.h | 15 +- .../WebCore/html/canvas/OESTextureFloatLinear.cpp | 7 +- Source/WebCore/html/canvas/OESTextureFloatLinear.h | 15 +- Source/WebCore/html/canvas/OESTextureHalfFloat.cpp | 7 +- Source/WebCore/html/canvas/OESTextureHalfFloat.h | 15 +- .../html/canvas/OESTextureHalfFloatLinear.cpp | 7 +- .../html/canvas/OESTextureHalfFloatLinear.h | 15 +- .../WebCore/html/canvas/OESVertexArrayObject.cpp | 78 +- Source/WebCore/html/canvas/OESVertexArrayObject.h | 27 +- .../WebCore/html/canvas/OESVertexArrayObject.idl | 20 +- .../WebCore/html/canvas/WebGL2RenderingContext.cpp | 1830 ++++++ .../WebCore/html/canvas/WebGL2RenderingContext.h | 201 + .../WebCore/html/canvas/WebGL2RenderingContext.idl | 468 ++ Source/WebCore/html/canvas/WebGLActiveInfo.h | 12 +- Source/WebCore/html/canvas/WebGLAny.cpp | 120 + Source/WebCore/html/canvas/WebGLAny.h | 79 + Source/WebCore/html/canvas/WebGLBuffer.cpp | 142 +- Source/WebCore/html/canvas/WebGLBuffer.h | 46 +- Source/WebCore/html/canvas/WebGLBuffer.idl | 4 +- .../html/canvas/WebGLCompressedTextureATC.cpp | 18 +- .../html/canvas/WebGLCompressedTextureATC.h | 19 +- .../html/canvas/WebGLCompressedTextureATC.idl | 11 +- .../html/canvas/WebGLCompressedTexturePVRTC.cpp | 22 +- .../html/canvas/WebGLCompressedTexturePVRTC.h | 18 +- .../html/canvas/WebGLCompressedTexturePVRTC.idl | 13 +- .../html/canvas/WebGLCompressedTextureS3TC.cpp | 27 +- .../html/canvas/WebGLCompressedTextureS3TC.h | 19 +- .../html/canvas/WebGLCompressedTextureS3TC.idl | 13 +- .../WebCore/html/canvas/WebGLContextAttributes.cpp | 127 - .../WebCore/html/canvas/WebGLContextAttributes.h | 60 +- .../WebCore/html/canvas/WebGLContextAttributes.idl | 27 +- Source/WebCore/html/canvas/WebGLContextEvent.cpp | 14 +- Source/WebCore/html/canvas/WebGLContextEvent.h | 35 +- Source/WebCore/html/canvas/WebGLContextEvent.idl | 7 +- Source/WebCore/html/canvas/WebGLContextGroup.cpp | 55 +- Source/WebCore/html/canvas/WebGLContextGroup.h | 47 +- Source/WebCore/html/canvas/WebGLContextObject.cpp | 22 +- Source/WebCore/html/canvas/WebGLContextObject.h | 25 +- .../WebCore/html/canvas/WebGLDebugRendererInfo.cpp | 9 +- .../WebCore/html/canvas/WebGLDebugRendererInfo.h | 15 +- .../WebCore/html/canvas/WebGLDebugRendererInfo.idl | 8 +- Source/WebCore/html/canvas/WebGLDebugShaders.cpp | 20 +- Source/WebCore/html/canvas/WebGLDebugShaders.h | 19 +- Source/WebCore/html/canvas/WebGLDebugShaders.idl | 4 +- Source/WebCore/html/canvas/WebGLDepthTexture.cpp | 16 +- Source/WebCore/html/canvas/WebGLDepthTexture.h | 19 +- Source/WebCore/html/canvas/WebGLDepthTexture.idl | 6 +- Source/WebCore/html/canvas/WebGLDrawBuffers.cpp | 170 + Source/WebCore/html/canvas/WebGLDrawBuffers.h | 47 + Source/WebCore/html/canvas/WebGLDrawBuffers.idl | 72 + Source/WebCore/html/canvas/WebGLExtension.cpp | 2 +- Source/WebCore/html/canvas/WebGLExtension.h | 23 +- Source/WebCore/html/canvas/WebGLFramebuffer.cpp | 132 +- Source/WebCore/html/canvas/WebGLFramebuffer.h | 23 +- Source/WebCore/html/canvas/WebGLFramebuffer.idl | 4 +- Source/WebCore/html/canvas/WebGLGetInfo.cpp | 322 - Source/WebCore/html/canvas/WebGLGetInfo.h | 142 - Source/WebCore/html/canvas/WebGLLoseContext.cpp | 13 +- Source/WebCore/html/canvas/WebGLLoseContext.h | 19 +- Source/WebCore/html/canvas/WebGLLoseContext.idl | 4 +- Source/WebCore/html/canvas/WebGLObject.cpp | 30 +- Source/WebCore/html/canvas/WebGLObject.h | 28 +- Source/WebCore/html/canvas/WebGLProgram.cpp | 31 +- Source/WebCore/html/canvas/WebGLProgram.h | 38 +- Source/WebCore/html/canvas/WebGLProgram.idl | 4 +- Source/WebCore/html/canvas/WebGLQuery.cpp | 61 + Source/WebCore/html/canvas/WebGLQuery.h | 42 + Source/WebCore/html/canvas/WebGLQuery.idl | 29 + Source/WebCore/html/canvas/WebGLRenderbuffer.cpp | 14 +- Source/WebCore/html/canvas/WebGLRenderbuffer.h | 22 +- Source/WebCore/html/canvas/WebGLRenderbuffer.idl | 4 +- .../WebCore/html/canvas/WebGLRenderingContext.cpp | 6731 ++------------------ Source/WebCore/html/canvas/WebGLRenderingContext.h | 800 +-- .../WebCore/html/canvas/WebGLRenderingContext.idl | 647 +- .../html/canvas/WebGLRenderingContextBase.cpp | 5897 +++++++++++++++++ .../html/canvas/WebGLRenderingContextBase.h | 848 +++ .../html/canvas/WebGLRenderingContextBase.idl | 665 ++ Source/WebCore/html/canvas/WebGLSampler.cpp | 61 + Source/WebCore/html/canvas/WebGLSampler.h | 42 + Source/WebCore/html/canvas/WebGLSampler.idl | 29 + Source/WebCore/html/canvas/WebGLShader.cpp | 16 +- Source/WebCore/html/canvas/WebGLShader.h | 24 +- Source/WebCore/html/canvas/WebGLShader.idl | 4 +- .../html/canvas/WebGLShaderPrecisionFormat.cpp | 4 +- .../html/canvas/WebGLShaderPrecisionFormat.h | 10 +- Source/WebCore/html/canvas/WebGLSharedObject.cpp | 26 +- Source/WebCore/html/canvas/WebGLSharedObject.h | 28 +- Source/WebCore/html/canvas/WebGLSync.cpp | 61 + Source/WebCore/html/canvas/WebGLSync.h | 44 + Source/WebCore/html/canvas/WebGLSync.idl | 29 + Source/WebCore/html/canvas/WebGLTexture.cpp | 111 +- Source/WebCore/html/canvas/WebGLTexture.h | 30 +- Source/WebCore/html/canvas/WebGLTexture.idl | 4 +- .../WebCore/html/canvas/WebGLTransformFeedback.cpp | 61 + .../WebCore/html/canvas/WebGLTransformFeedback.h | 44 + .../WebCore/html/canvas/WebGLTransformFeedback.idl | 29 + .../WebCore/html/canvas/WebGLUniformLocation.cpp | 8 +- Source/WebCore/html/canvas/WebGLUniformLocation.h | 17 +- .../WebCore/html/canvas/WebGLUniformLocation.idl | 7 +- .../WebCore/html/canvas/WebGLVertexArrayObject.cpp | 79 + .../WebCore/html/canvas/WebGLVertexArrayObject.h | 47 + .../WebCore/html/canvas/WebGLVertexArrayObject.idl | 30 + .../html/canvas/WebGLVertexArrayObjectBase.cpp | 107 + .../html/canvas/WebGLVertexArrayObjectBase.h | 78 + .../html/canvas/WebGLVertexArrayObjectOES.cpp | 107 +- .../html/canvas/WebGLVertexArrayObjectOES.h | 81 +- .../html/canvas/WebGLVertexArrayObjectOES.idl | 4 +- Source/WebCore/html/forms/FileIconLoader.cpp | 10 +- Source/WebCore/html/forms/FileIconLoader.h | 15 +- Source/WebCore/html/parser/AtomicHTMLToken.h | 347 +- Source/WebCore/html/parser/CSSPreloadScanner.cpp | 23 +- Source/WebCore/html/parser/CSSPreloadScanner.h | 7 +- .../WebCore/html/parser/HTMLConstructionSite.cpp | 568 +- Source/WebCore/html/parser/HTMLConstructionSite.h | 113 +- Source/WebCore/html/parser/HTMLDocumentParser.cpp | 358 +- Source/WebCore/html/parser/HTMLDocumentParser.h | 140 +- Source/WebCore/html/parser/HTMLElementStack.cpp | 381 +- Source/WebCore/html/parser/HTMLElementStack.h | 102 +- Source/WebCore/html/parser/HTMLEntityParser.cpp | 40 +- Source/WebCore/html/parser/HTMLEntityParser.h | 7 +- Source/WebCore/html/parser/HTMLEntitySearch.h | 7 +- Source/WebCore/html/parser/HTMLEntityTable.h | 7 +- .../html/parser/HTMLFormattingElementList.cpp | 73 +- .../html/parser/HTMLFormattingElementList.h | 53 +- Source/WebCore/html/parser/HTMLInputStream.h | 22 +- .../WebCore/html/parser/HTMLMetaCharsetParser.cpp | 95 +- Source/WebCore/html/parser/HTMLMetaCharsetParser.h | 35 +- Source/WebCore/html/parser/HTMLParserIdioms.cpp | 450 +- Source/WebCore/html/parser/HTMLParserIdioms.h | 93 +- Source/WebCore/html/parser/HTMLParserOptions.cpp | 7 +- Source/WebCore/html/parser/HTMLParserOptions.h | 7 +- Source/WebCore/html/parser/HTMLParserScheduler.cpp | 27 +- Source/WebCore/html/parser/HTMLParserScheduler.h | 58 +- Source/WebCore/html/parser/HTMLPreloadScanner.cpp | 295 +- Source/WebCore/html/parser/HTMLPreloadScanner.h | 82 +- .../WebCore/html/parser/HTMLResourcePreloader.cpp | 50 +- Source/WebCore/html/parser/HTMLResourcePreloader.h | 33 +- Source/WebCore/html/parser/HTMLScriptRunner.cpp | 208 +- Source/WebCore/html/parser/HTMLScriptRunner.h | 31 +- Source/WebCore/html/parser/HTMLScriptRunnerHost.h | 20 +- Source/WebCore/html/parser/HTMLSourceTracker.cpp | 48 +- Source/WebCore/html/parser/HTMLSourceTracker.h | 27 +- Source/WebCore/html/parser/HTMLSrcsetParser.cpp | 276 + Source/WebCore/html/parser/HTMLSrcsetParser.h | 109 + Source/WebCore/html/parser/HTMLStackItem.h | 303 +- Source/WebCore/html/parser/HTMLToken.h | 679 +- Source/WebCore/html/parser/HTMLTokenizer.cpp | 2235 +++---- Source/WebCore/html/parser/HTMLTokenizer.h | 339 +- Source/WebCore/html/parser/HTMLTreeBuilder.cpp | 2499 ++++---- Source/WebCore/html/parser/HTMLTreeBuilder.h | 237 +- .../WebCore/html/parser/HTMLViewSourceParser.cpp | 90 - Source/WebCore/html/parser/HTMLViewSourceParser.h | 79 - .../WebCore/html/parser/InputStreamPreprocessor.h | 92 +- .../WebCore/html/parser/NestingLevelIncrementer.h | 7 +- Source/WebCore/html/parser/ParsingUtilities.h | 83 + Source/WebCore/html/parser/TextDocumentParser.cpp | 23 +- Source/WebCore/html/parser/TextDocumentParser.h | 22 +- .../WebCore/html/parser/TextViewSourceParser.cpp | 43 - Source/WebCore/html/parser/TextViewSourceParser.h | 47 - Source/WebCore/html/parser/XSSAuditor.cpp | 374 +- Source/WebCore/html/parser/XSSAuditor.h | 29 +- Source/WebCore/html/parser/XSSAuditorDelegate.cpp | 45 +- Source/WebCore/html/parser/XSSAuditorDelegate.h | 27 +- .../WebCore/html/shadow/AutoFillButtonElement.cpp | 69 + Source/WebCore/html/shadow/AutoFillButtonElement.h | 52 + Source/WebCore/html/shadow/ContentDistributor.cpp | 162 - Source/WebCore/html/shadow/ContentDistributor.h | 96 - .../WebCore/html/shadow/DetailsMarkerControl.cpp | 29 +- Source/WebCore/html/shadow/DetailsMarkerControl.h | 25 +- .../html/shadow/ImageControlsRootElement.cpp | 51 + .../WebCore/html/shadow/ImageControlsRootElement.h | 51 + Source/WebCore/html/shadow/InsertionPoint.cpp | 162 - Source/WebCore/html/shadow/InsertionPoint.h | 130 - .../html/shadow/MediaControlElementTypes.cpp | 99 +- .../WebCore/html/shadow/MediaControlElementTypes.h | 47 +- .../WebCore/html/shadow/MediaControlElements.cpp | 768 ++- Source/WebCore/html/shadow/MediaControlElements.h | 199 +- Source/WebCore/html/shadow/MediaControls.cpp | 45 +- Source/WebCore/html/shadow/MediaControls.h | 31 +- Source/WebCore/html/shadow/MediaControlsApple.cpp | 568 ++ Source/WebCore/html/shadow/MediaControlsApple.h | 122 + Source/WebCore/html/shadow/MediaControlsGtk.cpp | 378 -- Source/WebCore/html/shadow/MediaControlsGtk.h | 83 - Source/WebCore/html/shadow/MeterShadowElement.cpp | 115 - Source/WebCore/html/shadow/MeterShadowElement.h | 111 - .../WebCore/html/shadow/ProgressShadowElement.cpp | 11 +- Source/WebCore/html/shadow/ProgressShadowElement.h | 32 +- Source/WebCore/html/shadow/SliderThumbElement.cpp | 301 +- Source/WebCore/html/shadow/SliderThumbElement.h | 77 +- Source/WebCore/html/shadow/SpinButtonElement.cpp | 85 +- Source/WebCore/html/shadow/SpinButtonElement.h | 46 +- .../html/shadow/TextControlInnerElements.cpp | 385 +- .../WebCore/html/shadow/TextControlInnerElements.h | 127 +- .../html/shadow/YouTubeEmbedShadowElement.cpp | 49 + .../html/shadow/YouTubeEmbedShadowElement.h | 43 + Source/WebCore/html/shadow/meterElementShadow.css | 36 + Source/WebCore/html/track/AudioTrack.cpp | 157 +- Source/WebCore/html/track/AudioTrack.h | 65 +- Source/WebCore/html/track/AudioTrack.idl | 5 +- Source/WebCore/html/track/AudioTrackList.cpp | 35 +- Source/WebCore/html/track/AudioTrackList.h | 20 +- Source/WebCore/html/track/AudioTrackList.idl | 22 +- Source/WebCore/html/track/BufferedLineReader.cpp | 104 + Source/WebCore/html/track/BufferedLineReader.h | 76 + Source/WebCore/html/track/DataCue.cpp | 193 + Source/WebCore/html/track/DataCue.h | 109 + Source/WebCore/html/track/DataCue.idl | 38 + Source/WebCore/html/track/InbandDataTextTrack.cpp | 122 + Source/WebCore/html/track/InbandDataTextTrack.h | 59 + .../WebCore/html/track/InbandGenericTextTrack.cpp | 239 +- Source/WebCore/html/track/InbandGenericTextTrack.h | 59 +- Source/WebCore/html/track/InbandTextTrack.cpp | 173 +- Source/WebCore/html/track/InbandTextTrack.h | 71 +- .../WebCore/html/track/InbandWebVTTTextTrack.cpp | 64 +- Source/WebCore/html/track/InbandWebVTTTextTrack.h | 38 +- Source/WebCore/html/track/LoadableTextTrack.cpp | 73 +- Source/WebCore/html/track/LoadableTextTrack.h | 60 +- Source/WebCore/html/track/TextTrack.cpp | 436 +- Source/WebCore/html/track/TextTrack.h | 175 +- Source/WebCore/html/track/TextTrack.idl | 42 +- Source/WebCore/html/track/TextTrackCue.cpp | 1094 +--- Source/WebCore/html/track/TextTrackCue.h | 248 +- Source/WebCore/html/track/TextTrackCue.idl | 47 +- Source/WebCore/html/track/TextTrackCueGeneric.cpp | 163 +- Source/WebCore/html/track/TextTrackCueGeneric.h | 69 +- Source/WebCore/html/track/TextTrackCueList.cpp | 145 +- Source/WebCore/html/track/TextTrackCueList.h | 56 +- Source/WebCore/html/track/TextTrackCueList.idl | 4 +- Source/WebCore/html/track/TextTrackList.cpp | 176 +- Source/WebCore/html/track/TextTrackList.h | 34 +- Source/WebCore/html/track/TextTrackList.idl | 21 +- Source/WebCore/html/track/TextTrackRegion.h | 123 - Source/WebCore/html/track/TextTrackRegion.idl | 42 - Source/WebCore/html/track/TextTrackRegionList.h | 65 - Source/WebCore/html/track/TextTrackRegionList.idl | 35 - Source/WebCore/html/track/TrackBase.cpp | 109 +- Source/WebCore/html/track/TrackBase.h | 49 +- Source/WebCore/html/track/TrackEvent.cpp | 32 +- Source/WebCore/html/track/TrackEvent.h | 48 +- Source/WebCore/html/track/TrackEvent.idl | 11 +- Source/WebCore/html/track/TrackListBase.cpp | 63 +- Source/WebCore/html/track/TrackListBase.h | 35 +- Source/WebCore/html/track/VTTCue.cpp | 1180 ++++ Source/WebCore/html/track/VTTCue.h | 231 + Source/WebCore/html/track/VTTCue.idl | 43 + Source/WebCore/html/track/VTTRegion.cpp | 428 ++ Source/WebCore/html/track/VTTRegion.h | 158 + Source/WebCore/html/track/VTTRegion.idl | 43 + Source/WebCore/html/track/VTTRegionList.cpp | 71 + Source/WebCore/html/track/VTTRegionList.h | 71 + Source/WebCore/html/track/VTTRegionList.idl | 35 + Source/WebCore/html/track/VTTScanner.cpp | 180 + Source/WebCore/html/track/VTTScanner.h | 230 + Source/WebCore/html/track/VideoTrack.cpp | 157 +- Source/WebCore/html/track/VideoTrack.h | 65 +- Source/WebCore/html/track/VideoTrack.idl | 5 +- Source/WebCore/html/track/VideoTrackList.cpp | 41 +- Source/WebCore/html/track/VideoTrackList.h | 25 +- Source/WebCore/html/track/VideoTrackList.idl | 23 +- Source/WebCore/html/track/WebVTTElement.cpp | 59 +- Source/WebCore/html/track/WebVTTElement.h | 29 +- Source/WebCore/html/track/WebVTTParser.cpp | 598 +- Source/WebCore/html/track/WebVTTParser.h | 128 +- Source/WebCore/html/track/WebVTTToken.h | 172 +- Source/WebCore/html/track/WebVTTTokenizer.cpp | 322 +- Source/WebCore/html/track/WebVTTTokenizer.h | 83 +- 743 files changed, 49773 insertions(+), 39527 deletions(-) create mode 100644 Source/WebCore/html/Autocapitalize.cpp create mode 100644 Source/WebCore/html/Autocapitalize.h create mode 100644 Source/WebCore/html/AutocapitalizeTypes.h create mode 100644 Source/WebCore/html/Autofill.cpp create mode 100644 Source/WebCore/html/Autofill.h create mode 100644 Source/WebCore/html/CachedHTMLCollection.h delete mode 100644 Source/WebCore/html/ClassList.cpp delete mode 100644 Source/WebCore/html/ClassList.h create mode 100644 Source/WebCore/html/CollectionTraversal.h delete mode 100644 Source/WebCore/html/DOMSettableTokenList.cpp delete mode 100644 Source/WebCore/html/DOMSettableTokenList.h delete mode 100644 Source/WebCore/html/DOMSettableTokenList.idl create mode 100644 Source/WebCore/html/GenericCachedHTMLCollection.cpp create mode 100644 Source/WebCore/html/GenericCachedHTMLCollection.h create mode 100644 Source/WebCore/html/HTMLAttachmentElement.cpp create mode 100644 Source/WebCore/html/HTMLAttachmentElement.h create mode 100644 Source/WebCore/html/HTMLAttachmentElement.idl delete mode 100644 Source/WebCore/html/HTMLBaseFontElement.cpp delete mode 100644 Source/WebCore/html/HTMLBaseFontElement.h delete mode 100644 Source/WebCore/html/HTMLBaseFontElement.idl create mode 100644 Source/WebCore/html/HTMLDataElement.cpp create mode 100644 Source/WebCore/html/HTMLDataElement.h create mode 100644 Source/WebCore/html/HTMLDataElement.idl create mode 100644 Source/WebCore/html/HTMLElementsAllInOne.cpp create mode 100644 Source/WebCore/html/HTMLHyperlinkElementUtils.idl create mode 100644 Source/WebCore/html/HTMLMediaElementEnums.h delete mode 100644 Source/WebCore/html/HTMLMediaSession.cpp delete mode 100644 Source/WebCore/html/HTMLMediaSession.h delete mode 100644 Source/WebCore/html/HTMLMediaSource.cpp delete mode 100644 Source/WebCore/html/HTMLMediaSource.h delete mode 100644 Source/WebCore/html/HTMLParserErrorCodes.cpp delete mode 100644 Source/WebCore/html/HTMLParserErrorCodes.h delete mode 100644 Source/WebCore/html/HTMLParserQuirks.h create mode 100644 Source/WebCore/html/HTMLPictureElement.cpp create mode 100644 Source/WebCore/html/HTMLPictureElement.h create mode 100644 Source/WebCore/html/HTMLPictureElement.idl create mode 100644 Source/WebCore/html/HTMLSelectElementWin.cpp create mode 100644 Source/WebCore/html/HTMLSlotElement.cpp create mode 100644 Source/WebCore/html/HTMLSlotElement.h create mode 100644 Source/WebCore/html/HTMLSlotElement.idl create mode 100644 Source/WebCore/html/HTMLTimeElement.cpp create mode 100644 Source/WebCore/html/HTMLTimeElement.h create mode 100644 Source/WebCore/html/HTMLTimeElement.idl delete mode 100644 Source/WebCore/html/HTMLViewSourceDocument.cpp delete mode 100644 Source/WebCore/html/HTMLViewSourceDocument.h create mode 100644 Source/WebCore/html/HTMLWBRElement.cpp create mode 100644 Source/WebCore/html/HTMLWBRElement.h create mode 100644 Source/WebCore/html/LinkIconCollector.cpp create mode 100644 Source/WebCore/html/LinkIconCollector.h create mode 100644 Source/WebCore/html/LinkIconType.h create mode 100644 Source/WebCore/html/MediaElementSession.cpp create mode 100644 Source/WebCore/html/MediaElementSession.h create mode 100644 Source/WebCore/html/MediaEncryptedEvent.cpp create mode 100644 Source/WebCore/html/MediaEncryptedEvent.h create mode 100644 Source/WebCore/html/MediaEncryptedEvent.idl create mode 100644 Source/WebCore/html/MediaEncryptedEventInit.h delete mode 100644 Source/WebCore/html/MediaKeyError.h delete mode 100644 Source/WebCore/html/MediaKeyError.idl delete mode 100644 Source/WebCore/html/MediaKeyEvent.cpp delete mode 100644 Source/WebCore/html/MediaKeyEvent.h delete mode 100644 Source/WebCore/html/MediaKeyEvent.idl create mode 100644 Source/WebCore/html/RubyElement.cpp create mode 100644 Source/WebCore/html/RubyElement.h create mode 100644 Source/WebCore/html/RubyTextElement.cpp create mode 100644 Source/WebCore/html/RubyTextElement.h create mode 100644 Source/WebCore/html/URLSearchParams.cpp create mode 100644 Source/WebCore/html/URLSearchParams.h create mode 100644 Source/WebCore/html/URLSearchParams.idl create mode 100644 Source/WebCore/html/URLUtils.h create mode 100644 Source/WebCore/html/WebKitMediaKeyError.h create mode 100644 Source/WebCore/html/WebKitMediaKeyError.idl delete mode 100644 Source/WebCore/html/canvas/CanvasContextAttributes.cpp delete mode 100644 Source/WebCore/html/canvas/CanvasContextAttributes.h create mode 100644 Source/WebCore/html/canvas/CanvasPath.cpp create mode 100644 Source/WebCore/html/canvas/CanvasPath.h create mode 100644 Source/WebCore/html/canvas/CanvasPath.idl delete mode 100644 Source/WebCore/html/canvas/CanvasPathMethods.cpp delete mode 100644 Source/WebCore/html/canvas/CanvasPathMethods.h delete mode 100644 Source/WebCore/html/canvas/CanvasRenderingContext.idl mode change 100755 => 100644 Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp create mode 100644 Source/WebCore/html/canvas/DOMPath.cpp create mode 100644 Source/WebCore/html/canvas/EXTBlendMinMax.cpp create mode 100644 Source/WebCore/html/canvas/EXTBlendMinMax.h create mode 100644 Source/WebCore/html/canvas/EXTBlendMinMax.idl delete mode 100644 Source/WebCore/html/canvas/EXTDrawBuffers.cpp delete mode 100644 Source/WebCore/html/canvas/EXTDrawBuffers.h delete mode 100644 Source/WebCore/html/canvas/EXTDrawBuffers.idl create mode 100644 Source/WebCore/html/canvas/EXTFragDepth.cpp create mode 100644 Source/WebCore/html/canvas/EXTFragDepth.h create mode 100644 Source/WebCore/html/canvas/EXTFragDepth.idl create mode 100644 Source/WebCore/html/canvas/EXTShaderTextureLOD.cpp create mode 100644 Source/WebCore/html/canvas/EXTShaderTextureLOD.h create mode 100644 Source/WebCore/html/canvas/EXTShaderTextureLOD.idl create mode 100644 Source/WebCore/html/canvas/EXTsRGB.cpp create mode 100644 Source/WebCore/html/canvas/EXTsRGB.h create mode 100644 Source/WebCore/html/canvas/EXTsRGB.idl create mode 100644 Source/WebCore/html/canvas/WebGL2RenderingContext.cpp create mode 100644 Source/WebCore/html/canvas/WebGL2RenderingContext.h create mode 100644 Source/WebCore/html/canvas/WebGL2RenderingContext.idl create mode 100644 Source/WebCore/html/canvas/WebGLAny.cpp create mode 100644 Source/WebCore/html/canvas/WebGLAny.h delete mode 100644 Source/WebCore/html/canvas/WebGLContextAttributes.cpp create mode 100644 Source/WebCore/html/canvas/WebGLDrawBuffers.cpp create mode 100644 Source/WebCore/html/canvas/WebGLDrawBuffers.h create mode 100644 Source/WebCore/html/canvas/WebGLDrawBuffers.idl delete mode 100644 Source/WebCore/html/canvas/WebGLGetInfo.cpp delete mode 100644 Source/WebCore/html/canvas/WebGLGetInfo.h create mode 100644 Source/WebCore/html/canvas/WebGLQuery.cpp create mode 100644 Source/WebCore/html/canvas/WebGLQuery.h create mode 100644 Source/WebCore/html/canvas/WebGLQuery.idl create mode 100644 Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp create mode 100644 Source/WebCore/html/canvas/WebGLRenderingContextBase.h create mode 100644 Source/WebCore/html/canvas/WebGLRenderingContextBase.idl create mode 100644 Source/WebCore/html/canvas/WebGLSampler.cpp create mode 100644 Source/WebCore/html/canvas/WebGLSampler.h create mode 100644 Source/WebCore/html/canvas/WebGLSampler.idl create mode 100644 Source/WebCore/html/canvas/WebGLSync.cpp create mode 100644 Source/WebCore/html/canvas/WebGLSync.h create mode 100644 Source/WebCore/html/canvas/WebGLSync.idl create mode 100644 Source/WebCore/html/canvas/WebGLTransformFeedback.cpp create mode 100644 Source/WebCore/html/canvas/WebGLTransformFeedback.h create mode 100644 Source/WebCore/html/canvas/WebGLTransformFeedback.idl create mode 100644 Source/WebCore/html/canvas/WebGLVertexArrayObject.cpp create mode 100644 Source/WebCore/html/canvas/WebGLVertexArrayObject.h create mode 100644 Source/WebCore/html/canvas/WebGLVertexArrayObject.idl create mode 100644 Source/WebCore/html/canvas/WebGLVertexArrayObjectBase.cpp create mode 100644 Source/WebCore/html/canvas/WebGLVertexArrayObjectBase.h create mode 100644 Source/WebCore/html/parser/HTMLSrcsetParser.cpp create mode 100644 Source/WebCore/html/parser/HTMLSrcsetParser.h delete mode 100644 Source/WebCore/html/parser/HTMLViewSourceParser.cpp delete mode 100644 Source/WebCore/html/parser/HTMLViewSourceParser.h create mode 100644 Source/WebCore/html/parser/ParsingUtilities.h delete mode 100644 Source/WebCore/html/parser/TextViewSourceParser.cpp delete mode 100644 Source/WebCore/html/parser/TextViewSourceParser.h create mode 100644 Source/WebCore/html/shadow/AutoFillButtonElement.cpp create mode 100644 Source/WebCore/html/shadow/AutoFillButtonElement.h delete mode 100644 Source/WebCore/html/shadow/ContentDistributor.cpp delete mode 100644 Source/WebCore/html/shadow/ContentDistributor.h create mode 100644 Source/WebCore/html/shadow/ImageControlsRootElement.cpp create mode 100644 Source/WebCore/html/shadow/ImageControlsRootElement.h delete mode 100644 Source/WebCore/html/shadow/InsertionPoint.cpp delete mode 100644 Source/WebCore/html/shadow/InsertionPoint.h create mode 100644 Source/WebCore/html/shadow/MediaControlsApple.cpp create mode 100644 Source/WebCore/html/shadow/MediaControlsApple.h delete mode 100644 Source/WebCore/html/shadow/MediaControlsGtk.cpp delete mode 100644 Source/WebCore/html/shadow/MediaControlsGtk.h delete mode 100644 Source/WebCore/html/shadow/MeterShadowElement.cpp delete mode 100644 Source/WebCore/html/shadow/MeterShadowElement.h create mode 100644 Source/WebCore/html/shadow/YouTubeEmbedShadowElement.cpp create mode 100644 Source/WebCore/html/shadow/YouTubeEmbedShadowElement.h create mode 100644 Source/WebCore/html/shadow/meterElementShadow.css create mode 100644 Source/WebCore/html/track/BufferedLineReader.cpp create mode 100644 Source/WebCore/html/track/BufferedLineReader.h create mode 100644 Source/WebCore/html/track/DataCue.cpp create mode 100644 Source/WebCore/html/track/DataCue.h create mode 100644 Source/WebCore/html/track/DataCue.idl create mode 100644 Source/WebCore/html/track/InbandDataTextTrack.cpp create mode 100644 Source/WebCore/html/track/InbandDataTextTrack.h delete mode 100644 Source/WebCore/html/track/TextTrackRegion.h delete mode 100644 Source/WebCore/html/track/TextTrackRegion.idl delete mode 100644 Source/WebCore/html/track/TextTrackRegionList.h delete mode 100644 Source/WebCore/html/track/TextTrackRegionList.idl create mode 100644 Source/WebCore/html/track/VTTCue.cpp create mode 100644 Source/WebCore/html/track/VTTCue.h create mode 100644 Source/WebCore/html/track/VTTCue.idl create mode 100644 Source/WebCore/html/track/VTTRegion.cpp create mode 100644 Source/WebCore/html/track/VTTRegion.h create mode 100644 Source/WebCore/html/track/VTTRegion.idl create mode 100644 Source/WebCore/html/track/VTTRegionList.cpp create mode 100644 Source/WebCore/html/track/VTTRegionList.h create mode 100644 Source/WebCore/html/track/VTTRegionList.idl create mode 100644 Source/WebCore/html/track/VTTScanner.cpp create mode 100644 Source/WebCore/html/track/VTTScanner.h (limited to 'Source/WebCore/html') diff --git a/Source/WebCore/html/Autocapitalize.cpp b/Source/WebCore/html/Autocapitalize.cpp new file mode 100644 index 000000000..1402d4536 --- /dev/null +++ b/Source/WebCore/html/Autocapitalize.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2011 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "Autocapitalize.h" + +#include + +namespace WebCore { + +AutocapitalizeType autocapitalizeTypeForAttributeValue(const AtomicString& attributeValue) +{ + // Omitted / missing values are the Default state. + if (attributeValue.isEmpty()) + return AutocapitalizeTypeDefault; + + if (equalLettersIgnoringASCIICase(attributeValue, "on") || equalLettersIgnoringASCIICase(attributeValue, "sentences")) + return AutocapitalizeTypeSentences; + if (equalLettersIgnoringASCIICase(attributeValue, "off") || equalLettersIgnoringASCIICase(attributeValue, "none")) + return AutocapitalizeTypeNone; + if (equalLettersIgnoringASCIICase(attributeValue, "words")) + return AutocapitalizeTypeWords; + if (equalLettersIgnoringASCIICase(attributeValue, "characters")) + return AutocapitalizeTypeAllCharacters; + + // Unrecognized values fall back to "on". + return AutocapitalizeTypeSentences; +} + +const AtomicString& stringForAutocapitalizeType(AutocapitalizeType type) +{ + switch (type) { + case AutocapitalizeTypeDefault: + return nullAtom; + case AutocapitalizeTypeNone: { + static NeverDestroyed valueNone("none", AtomicString::ConstructFromLiteral); + return valueNone; + } + case AutocapitalizeTypeSentences: { + static NeverDestroyed valueSentences("sentences", AtomicString::ConstructFromLiteral); + return valueSentences; + } + case AutocapitalizeTypeWords: { + static NeverDestroyed valueWords("words", AtomicString::ConstructFromLiteral); + return valueWords; + } + case AutocapitalizeTypeAllCharacters: { + static NeverDestroyed valueAllCharacters("characters", AtomicString::ConstructFromLiteral); + return valueAllCharacters; + } + } + + ASSERT_NOT_REACHED(); + return nullAtom; +} + +} // namespace WebCore diff --git a/Source/WebCore/html/Autocapitalize.h b/Source/WebCore/html/Autocapitalize.h new file mode 100644 index 000000000..1c32579e6 --- /dev/null +++ b/Source/WebCore/html/Autocapitalize.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2011 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "AutocapitalizeTypes.h" +#include + +namespace WebCore { + +AutocapitalizeType autocapitalizeTypeForAttributeValue(const AtomicString&); +const AtomicString& stringForAutocapitalizeType(AutocapitalizeType); + +} // namespace WebCore diff --git a/Source/WebCore/html/AutocapitalizeTypes.h b/Source/WebCore/html/AutocapitalizeTypes.h new file mode 100644 index 000000000..01a0eac9c --- /dev/null +++ b/Source/WebCore/html/AutocapitalizeTypes.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2011 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +typedef enum { + AutocapitalizeTypeDefault, + AutocapitalizeTypeNone, + AutocapitalizeTypeWords, + AutocapitalizeTypeSentences, + AutocapitalizeTypeAllCharacters +} AutocapitalizeType; diff --git a/Source/WebCore/html/Autofill.cpp b/Source/WebCore/html/Autofill.cpp new file mode 100644 index 000000000..6a9212f9c --- /dev/null +++ b/Source/WebCore/html/Autofill.cpp @@ -0,0 +1,316 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "Autofill.h" + +#include "HTMLFormControlElement.h" +#include "HTMLFormElement.h" +#include "HTMLNames.h" +#include +#include +#include +#include + +namespace WebCore { + +enum class AutofillCategory { + Off, + Automatic, + Normal, + Contact, +}; + +struct AutofillInfo { + AutofillFieldName fieldName; + AutofillCategory category; +}; + +static HashMap& fieldNameMap() +{ + static NeverDestroyed> map; + if (map.get().isEmpty()) { + map.get().add(AtomicString("off", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::None, AutofillCategory::Off }); + map.get().add(AtomicString("on", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::None, AutofillCategory::Automatic }); + map.get().add(AtomicString("name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Name, AutofillCategory::Normal }); + map.get().add(AtomicString("honorific-prefix", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::HonorificPrefix, AutofillCategory::Normal }); + map.get().add(AtomicString("given-name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::GivenName, AutofillCategory::Normal }); + map.get().add(AtomicString("additional-name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::AdditionalName, AutofillCategory::Normal }); + map.get().add(AtomicString("family-name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::FamilyName, AutofillCategory::Normal }); + map.get().add(AtomicString("honorific-suffix", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::HonorificSuffix, AutofillCategory::Normal }); + map.get().add(AtomicString("nickname", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Nickname, AutofillCategory::Normal }); + map.get().add(AtomicString("username", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Username, AutofillCategory::Normal }); + map.get().add(AtomicString("new-password", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::NewPassword, AutofillCategory::Normal }); + map.get().add(AtomicString("current-password", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CurrentPassword, AutofillCategory::Normal }); + map.get().add(AtomicString("organization-title", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::OrganizationTitle, AutofillCategory::Normal }); + map.get().add(AtomicString("organization", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Organization, AutofillCategory::Normal }); + map.get().add(AtomicString("street-address", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::StreetAddress, AutofillCategory::Normal }); + map.get().add(AtomicString("address-line1", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::AddressLine1, AutofillCategory::Normal }); + map.get().add(AtomicString("address-line2", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::AddressLine2, AutofillCategory::Normal }); + map.get().add(AtomicString("address-line3", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::AddressLine3, AutofillCategory::Normal }); + map.get().add(AtomicString("address-level4", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::AddressLevel4, AutofillCategory::Normal }); + map.get().add(AtomicString("address-level3", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::AddressLevel3, AutofillCategory::Normal }); + map.get().add(AtomicString("address-level2", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::AddressLevel2, AutofillCategory::Normal }); + map.get().add(AtomicString("address-level1", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::AddressLevel1, AutofillCategory::Normal }); + map.get().add(AtomicString("country", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Country, AutofillCategory::Normal }); + map.get().add(AtomicString("country-name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CountryName, AutofillCategory::Normal }); + map.get().add(AtomicString("postal-code", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::PostalCode, AutofillCategory::Normal }); + map.get().add(AtomicString("cc-name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcName, AutofillCategory::Normal }); + map.get().add(AtomicString("cc-given-name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcGivenName, AutofillCategory::Normal }); + map.get().add(AtomicString("cc-additional-name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcAdditionalName, AutofillCategory::Normal }); + map.get().add(AtomicString("cc-family-name", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcFamilyName, AutofillCategory::Normal }); + map.get().add(AtomicString("cc-number", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcNumber, AutofillCategory::Normal }); + map.get().add(AtomicString("cc-exp", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcExp, AutofillCategory::Normal }); + map.get().add(AtomicString("cc-exp-month", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcExpMonth, AutofillCategory::Normal }); + map.get().add(AtomicString("cc-exp-year", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcExpYear, AutofillCategory::Normal }); + map.get().add(AtomicString("cc-csc", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcCsc, AutofillCategory::Normal }); + map.get().add(AtomicString("cc-type", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::CcType, AutofillCategory::Normal }); + map.get().add(AtomicString("transaction-currency", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TransactionCurrency, AutofillCategory::Normal }); + map.get().add(AtomicString("transaction-amount", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TransactionAmount, AutofillCategory::Normal }); + map.get().add(AtomicString("language", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Language, AutofillCategory::Normal }); + map.get().add(AtomicString("bday", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Bday, AutofillCategory::Normal }); + map.get().add(AtomicString("bday-day", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::BdayDay, AutofillCategory::Normal }); + map.get().add(AtomicString("bday-month", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::BdayMonth, AutofillCategory::Normal }); + map.get().add(AtomicString("bday-year", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::BdayYear, AutofillCategory::Normal }); + map.get().add(AtomicString("sex", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Sex, AutofillCategory::Normal }); + map.get().add(AtomicString("url", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::URL, AutofillCategory::Normal }); + map.get().add(AtomicString("photo", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Photo, AutofillCategory::Normal }); + + map.get().add(AtomicString("tel", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Tel, AutofillCategory::Contact }); + map.get().add(AtomicString("tel-country-code", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TelCountryCode, AutofillCategory::Contact }); + map.get().add(AtomicString("tel-national", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TelNational, AutofillCategory::Contact }); + map.get().add(AtomicString("tel-area-code", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TelAreaCode, AutofillCategory::Contact }); + map.get().add(AtomicString("tel-local", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TelLocal, AutofillCategory::Contact }); + map.get().add(AtomicString("tel-local-prefix", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TelLocalPrefix, AutofillCategory::Contact }); + map.get().add(AtomicString("tel-local-suffix", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TelLocalSuffix, AutofillCategory::Contact }); + map.get().add(AtomicString("tel-extension", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::TelExtension, AutofillCategory::Contact }); + map.get().add(AtomicString("email", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Email, AutofillCategory::Contact }); + map.get().add(AtomicString("impp", AtomicString::ConstructFromLiteral), AutofillInfo{ AutofillFieldName::Impp, AutofillCategory::Contact }); + } + + return map; +} + +AutofillFieldName toAutofillFieldName(const AtomicString& value) +{ + auto map = fieldNameMap(); + auto it = map.find(value); + if (it == map.end()) + return AutofillFieldName::None; + return it->value.fieldName; +} + +static inline bool isContactToken(const AtomicString& token) +{ + static NeverDestroyed home("home", AtomicString::ConstructFromLiteral); + static NeverDestroyed work("work", AtomicString::ConstructFromLiteral); + static NeverDestroyed mobile("mobile", AtomicString::ConstructFromLiteral); + static NeverDestroyed fax("fax", AtomicString::ConstructFromLiteral); + static NeverDestroyed pager("pager", AtomicString::ConstructFromLiteral); + + return token == home || token == work || token == mobile || token == fax || token == pager; +} + +static unsigned maxTokensForAutofillFieldCategory(AutofillCategory category) +{ + switch (category) { + case AutofillCategory::Automatic: + case AutofillCategory::Off: + return 1; + + case AutofillCategory::Normal: + return 3; + + case AutofillCategory::Contact: + return 4; + } + ASSERT_NOT_REACHED(); + return 0; +} + +// https://html.spec.whatwg.org/multipage/forms.html#processing-model-3 +AutofillData AutofillData::createFromHTMLFormControlElement(const HTMLFormControlElement& element) +{ + static NeverDestroyed on("on", AtomicString::ConstructFromLiteral); + static NeverDestroyed off("off", AtomicString::ConstructFromLiteral); + + // Label: Default + // 26. Let the element's IDL-exposed autofill value be the empty string, and its autofill hint set and autofill scope be empty. + // 27. If the element's autocomplete attribute is wearing the autofill anchor mantle, then let the element's autofill field name be the empty string and abort these steps. + // 28. Let form be the element's form owner, if any, or null otherwise. + // 29. If form is not null and form's autocomplete attribute is in the off state, then let the element's autofill field name be "off". Otherwise, let the element's autofill field name be "on". + auto defaultLabel = [&] () -> AutofillData { + if (element.autofillMantle() == AutofillMantle::Anchor) + return { emptyString(), emptyString() }; + + auto form = element.form(); + if (form && form->autocomplete() == off) + return { off, emptyString() }; + return { on, emptyString() }; + }; + + + const AtomicString& attributeValue = element.attributeWithoutSynchronization(HTMLNames::autocompleteAttr); + + // 1. If the element has no autocomplete attribute, then jump to the step labeled default. + if (attributeValue == nullAtom) + return defaultLabel(); + + // 2. Let tokens be the result of splitting the attribute's value on spaces. + SpaceSplitString tokens(attributeValue, true); + + // 3. If tokens is empty, then jump to the step labeled default. + if (tokens.isEmpty()) + return defaultLabel(); + + // 4. Let index be the index of the last token in tokens + unsigned index = tokens.size() - 1; + + // 5. If the indexth token in tokens is not an ASCII case-insensitive match for one of the + // tokens given in the first column of the following table, or if the number of tokens in + // tokens is greater than the maximum number given in the cell in the second column of that + // token's row, then jump to the step labeled default. Otherwise, let field be the string given + // in the cell of the first column of the matching row, and let category be the value of the + // cell in the third column of that same row. + auto& map = fieldNameMap(); + + auto it = map.find(tokens[index]); + if (it == map.end()) + return defaultLabel(); + + auto category = it->value.category; + + if (tokens.size() > maxTokensForAutofillFieldCategory(category)) + return defaultLabel(); + + const auto& field = tokens[index]; + + // 6. If category is Off or Automatic but the element's autocomplete attribute is wearing the + // autofill anchor mantle, then jump to the step labeled default. + auto mantle = element.autofillMantle(); + if ((category == AutofillCategory::Off || category == AutofillCategory::Automatic) && mantle == AutofillMantle::Anchor) + return defaultLabel(); + + // 7. If category is Off, let the element's autofill field name be the string "off", let its + // autofill hint set be empty, and let its IDL-exposed autofill value be the string "off". + // Then, abort these steps. + if (category == AutofillCategory::Off) + return { off, off.get().string() }; + + // 8. If category is Automatic, let the element's autofill field name be the string "on", + // let its autofill hint set be empty, and let its IDL-exposed autofill value be the string + // "on". Then, abort these steps. + if (category == AutofillCategory::Automatic) + return { on, on.get().string() }; + + // 9. Let scope tokens be an empty list. + // 10. Let hint tokens be an empty set. + + // NOTE: We are ignoring these steps as we don't currently make use of scope tokens or hint tokens anywhere. + + // 11. Let IDL value have the same value as field. + String idlValue = field; + + // 12, If the indexth token in tokens is the first entry, then skip to the step labeled done. + if (index == 0) + return { field, idlValue }; + + // 13. Decrement index by one + index--; + + // 14. If category is Contact and the indexth token in tokens is an ASCII case-insensitive match + // for one of the strings in the following list, then run the substeps that follow: + const auto& contactToken = tokens[index]; + if (category == AutofillCategory::Contact && isContactToken(contactToken)) { + // 1. Let contact be the matching string from the list above. + const auto& contact = contactToken; + + // 2. Insert contact at the start of scope tokens. + // 3. Add contact to hint tokens. + + // NOTE: We are ignoring these steps as we don't currently make use of scope tokens or hint tokens anywhere. + + // 4. Let IDL value be the concatenation of contact, a U+0020 SPACE character, and the previous + // value of IDL value (which at this point will always be field). + idlValue = WTF::makeString(contact, " ", idlValue); + + // 5. If the indexth entry in tokens is the first entry, then skip to the step labeled done. + if (index == 0) + return { field, idlValue }; + + // 6. Decrement index by one. + index--; + } + + // 15. If the indexth token in tokens is an ASCII case-insensitive match for one of the strings + // in the following list, then run the substeps that follow: + const auto& modeToken = tokens[index]; + if (equalIgnoringASCIICase(modeToken, "shipping") || equalIgnoringASCIICase(modeToken, "billing")) { + // 1. Let mode be the matching string from the list above. + const auto& mode = modeToken; + + // 2. Insert mode at the start of scope tokens. + // 3. Add mode to hint tokens. + + // NOTE: We are ignoring these steps as we don't currently make use of scope tokens or hint tokens anywhere. + + // 4. Let IDL value be the concatenation of mode, a U+0020 SPACE character, and the previous + // value of IDL value (which at this point will either be field or the concatenation of contact, + // a space, and field). + idlValue = WTF::makeString(mode, " ", idlValue); + + // 5. If the indexth entry in tokens is the first entry, then skip to the step labeled done. + if (index == 0) + return { field, idlValue }; + + // 6. Decrement index by one. + index--; + } + + // 16. If the indexth entry in tokens is not the first entry, then jump to the step labeled default. + if (index != 0) + return defaultLabel(); + + // 17. If the first eight characters of the indexth token in tokens are not an ASCII case-insensitive + // match for the string "section-", then jump to the step labeled default. + const auto& sectionToken = tokens[index]; + if (!sectionToken.startsWithIgnoringASCIICase("section-")) + return defaultLabel(); + + // 18. Let section be the indexth token in tokens, converted to ASCII lowercase. + const auto& section = sectionToken; + + // 19. Insert section at the start of scope tokens. + + // NOTE: We are ignoring this step as we don't currently make use of scope tokens or hint tokens anywhere. + + // 20. Let IDL value be the concatenation of section, a U+0020 SPACE character, and the previous + // value of IDL value. + idlValue = WTF::makeString(section, " ", idlValue); + + return { field, idlValue }; +} + +} // namespace WebCore diff --git a/Source/WebCore/html/Autofill.h b/Source/WebCore/html/Autofill.h new file mode 100644 index 000000000..3a539bac7 --- /dev/null +++ b/Source/WebCore/html/Autofill.h @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2016 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include +#include + +namespace WebCore { + +enum class AutofillMantle { + Expectation, + Anchor +}; + +enum class AutofillFieldName { + None, + Name, + HonorificPrefix, + GivenName, + AdditionalName, + FamilyName, + HonorificSuffix, + Nickname, + Username, + NewPassword, + CurrentPassword, + OrganizationTitle, + Organization, + StreetAddress, + AddressLine1, + AddressLine2, + AddressLine3, + AddressLevel4, + AddressLevel3, + AddressLevel2, + AddressLevel1, + Country, + CountryName, + PostalCode, + CcName, + CcGivenName, + CcAdditionalName, + CcFamilyName, + CcNumber, + CcExp, + CcExpMonth, + CcExpYear, + CcCsc, + CcType, + TransactionCurrency, + TransactionAmount, + Language, + Bday, + BdayDay, + BdayMonth, + BdayYear, + Sex, + URL, + Photo, + Tel, + TelCountryCode, + TelNational, + TelAreaCode, + TelLocal, + TelLocalPrefix, + TelLocalSuffix, + TelExtension, + Email, + Impp +}; + +WEBCORE_EXPORT AutofillFieldName toAutofillFieldName(const AtomicString&); + +class HTMLFormControlElement; + +class AutofillData { +public: + static AutofillData createFromHTMLFormControlElement(const HTMLFormControlElement&); + + AutofillData(const AtomicString& fieldName, const String& idlExposedValue) + : fieldName(fieldName) + , idlExposedValue(idlExposedValue) + { + } + + // We could add support for hint tokens and scope tokens if those ever became useful to anyone. + + AtomicString fieldName; + String idlExposedValue; +}; + +} // namespace WebCore diff --git a/Source/WebCore/html/BaseButtonInputType.cpp b/Source/WebCore/html/BaseButtonInputType.cpp index 0b18b4f07..be4100ac1 100644 --- a/Source/WebCore/html/BaseButtonInputType.cpp +++ b/Source/WebCore/html/BaseButtonInputType.cpp @@ -34,7 +34,6 @@ #include "HTMLInputElement.h" #include "HTMLNames.h" -#include "KeyboardEvent.h" #include "RenderButton.h" namespace WebCore { @@ -52,9 +51,9 @@ bool BaseButtonInputType::appendFormData(FormDataList&, bool) const return false; } -RenderPtr BaseButtonInputType::createInputRenderer(PassRef style) +RenderPtr BaseButtonInputType::createInputRenderer(RenderStyle&& style) { - return createRenderer(element(), std::move(style)); + return createRenderer(element(), WTFMove(style)); } bool BaseButtonInputType::storesValueSeparateFromAttribute() @@ -64,7 +63,7 @@ bool BaseButtonInputType::storesValueSeparateFromAttribute() void BaseButtonInputType::setValue(const String& sanitizedValue, bool, TextFieldEventBehavior) { - element().setAttribute(valueAttr, sanitizedValue); + element().setAttributeWithoutSynchronization(valueAttr, sanitizedValue); } } // namespace WebCore diff --git a/Source/WebCore/html/BaseButtonInputType.h b/Source/WebCore/html/BaseButtonInputType.h index 46571c30f..321cad612 100644 --- a/Source/WebCore/html/BaseButtonInputType.h +++ b/Source/WebCore/html/BaseButtonInputType.h @@ -28,8 +28,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef BaseButtonInputType_h -#define BaseButtonInputType_h +#pragma once #include "BaseClickableWithKeyInputType.h" @@ -41,13 +40,11 @@ protected: explicit BaseButtonInputType(HTMLInputElement& element) : BaseClickableWithKeyInputType(element) { } private: - virtual bool shouldSaveAndRestoreFormControlState() const override; - virtual bool appendFormData(FormDataList&, bool) const override; - virtual RenderPtr createInputRenderer(PassRef) override; - virtual bool storesValueSeparateFromAttribute() override; - virtual void setValue(const String&, bool, TextFieldEventBehavior) override; + bool shouldSaveAndRestoreFormControlState() const override; + bool appendFormData(FormDataList&, bool) const override; + RenderPtr createInputRenderer(RenderStyle&&) override; + bool storesValueSeparateFromAttribute() override; + void setValue(const String&, bool, TextFieldEventBehavior) override; }; } // namespace WebCore - -#endif // BaseButtonInputType_h diff --git a/Source/WebCore/html/BaseCheckableInputType.cpp b/Source/WebCore/html/BaseCheckableInputType.cpp index eb7aefe2d..34104fe48 100644 --- a/Source/WebCore/html/BaseCheckableInputType.cpp +++ b/Source/WebCore/html/BaseCheckableInputType.cpp @@ -60,9 +60,9 @@ bool BaseCheckableInputType::appendFormData(FormDataList& encoding, bool) const return true; } -void BaseCheckableInputType::handleKeydownEvent(KeyboardEvent* event) +void BaseCheckableInputType::handleKeydownEvent(KeyboardEvent& event) { - const String& key = event->keyIdentifier(); + const String& key = event.keyIdentifier(); if (key == "U+0020") { element().setActive(true, true); // No setDefaultHandled(), because IE dispatches a keypress in this case @@ -70,11 +70,11 @@ void BaseCheckableInputType::handleKeydownEvent(KeyboardEvent* event) } } -void BaseCheckableInputType::handleKeypressEvent(KeyboardEvent* event) +void BaseCheckableInputType::handleKeypressEvent(KeyboardEvent& event) { - if (event->charCode() == ' ') { + if (event.charCode() == ' ') { // Prevent scrolling down the page. - event->setDefaultHandled(); + event.setDefaultHandled(); } } @@ -93,7 +93,8 @@ void BaseCheckableInputType::accessKeyAction(bool sendMouseEvents) String BaseCheckableInputType::fallbackValue() const { - return ASCIILiteral("on"); + static NeverDestroyed on("on", AtomicString::ConstructFromLiteral); + return on.get(); } bool BaseCheckableInputType::storesValueSeparateFromAttribute() @@ -103,7 +104,7 @@ bool BaseCheckableInputType::storesValueSeparateFromAttribute() void BaseCheckableInputType::setValue(const String& sanitizedValue, bool, TextFieldEventBehavior) { - element().setAttribute(valueAttr, sanitizedValue); + element().setAttributeWithoutSynchronization(valueAttr, sanitizedValue); } bool BaseCheckableInputType::isCheckable() diff --git a/Source/WebCore/html/BaseCheckableInputType.h b/Source/WebCore/html/BaseCheckableInputType.h index fc60ec1dc..a768e77d4 100644 --- a/Source/WebCore/html/BaseCheckableInputType.h +++ b/Source/WebCore/html/BaseCheckableInputType.h @@ -28,8 +28,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef BaseCheckableInputType_h -#define BaseCheckableInputType_h +#pragma once #include "InputType.h" @@ -39,21 +38,19 @@ namespace WebCore { class BaseCheckableInputType : public InputType { protected: explicit BaseCheckableInputType(HTMLInputElement& element) : InputType(element) { } - virtual void handleKeydownEvent(KeyboardEvent*) override; + void handleKeydownEvent(KeyboardEvent&) override; private: - virtual FormControlState saveFormControlState() const override; - virtual void restoreFormControlState(const FormControlState&) override; - virtual bool appendFormData(FormDataList&, bool) const override; - virtual void handleKeypressEvent(KeyboardEvent*) override; - virtual bool canSetStringValue() const override; - virtual void accessKeyAction(bool sendMouseEvents) override; - virtual String fallbackValue() const override; - virtual bool storesValueSeparateFromAttribute() override; - virtual void setValue(const String&, bool, TextFieldEventBehavior) override; - virtual bool isCheckable() override; + FormControlState saveFormControlState() const override; + void restoreFormControlState(const FormControlState&) override; + bool appendFormData(FormDataList&, bool) const override; + void handleKeypressEvent(KeyboardEvent&) override; + bool canSetStringValue() const override; + void accessKeyAction(bool sendMouseEvents) override; + String fallbackValue() const override; + bool storesValueSeparateFromAttribute() override; + void setValue(const String&, bool, TextFieldEventBehavior) override; + bool isCheckable() override; }; } // namespace WebCore - -#endif // BaseCheckableInputType_h diff --git a/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp b/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp index 732e83e74..437066248 100644 --- a/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp +++ b/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp @@ -24,16 +24,17 @@ */ #include "config.h" -#if ENABLE(DATE_AND_TIME_INPUT_TYPES) #include "BaseChooserOnlyDateAndTimeInputType.h" -#include "Chrome.h" +#if ENABLE(DATE_AND_TIME_INPUT_TYPES) + #include "HTMLDivElement.h" #include "HTMLInputElement.h" #include "Page.h" #include "RenderElement.h" #include "ScriptController.h" #include "ShadowRoot.h" +#include namespace WebCore { @@ -42,7 +43,7 @@ BaseChooserOnlyDateAndTimeInputType::~BaseChooserOnlyDateAndTimeInputType() closeDateTimeChooser(); } -void BaseChooserOnlyDateAndTimeInputType::handleDOMActivateEvent(Event*) +void BaseChooserOnlyDateAndTimeInputType::handleDOMActivateEvent(Event&) { if (element().isDisabledOrReadOnly() || !element().renderer() || !ScriptController::processingUserGesture()) return; @@ -54,33 +55,29 @@ void BaseChooserOnlyDateAndTimeInputType::handleDOMActivateEvent(Event*) DateTimeChooserParameters parameters; if (!element().setupDateTimeChooserParameters(parameters)) return; -#if !PLATFORM(IOS) - // FIXME: Is this correct? Why don't we do this on iOS? - m_dateTimeChooser = element().document().page()->chrome().openDateTimeChooser(this, parameters); -#endif } void BaseChooserOnlyDateAndTimeInputType::createShadowSubtree() { - DEFINE_STATIC_LOCAL(AtomicString, valueContainerPseudo, ("-webkit-date-and-time-value", AtomicString::ConstructFromLiteral)); + static NeverDestroyed valueContainerPseudo("-webkit-date-and-time-value", AtomicString::ConstructFromLiteral); - RefPtr valueContainer = HTMLDivElement::create(element().document()); + auto valueContainer = HTMLDivElement::create(element().document()); valueContainer->setPseudo(valueContainerPseudo); - element().userAgentShadowRoot()->appendChild(valueContainer.get()); + element().userAgentShadowRoot()->appendChild(valueContainer); updateAppearance(); } void BaseChooserOnlyDateAndTimeInputType::updateAppearance() { Node* node = element().userAgentShadowRoot()->firstChild(); - if (!node || !node->isHTMLElement()) + if (!is(node)) return; String displayValue = visibleValue(); if (displayValue.isEmpty()) { // Need to put something to keep text baseline. displayValue = ASCIILiteral(" "); } - toHTMLElement(node)->setInnerText(displayValue, ASSERT_NO_EXCEPTION); + downcast(*node).setInnerText(displayValue); } void BaseChooserOnlyDateAndTimeInputType::setValue(const String& value, bool valueChanged, TextFieldEventBehavior eventBehavior) @@ -102,7 +99,7 @@ void BaseChooserOnlyDateAndTimeInputType::didChooseValue(const String& value) void BaseChooserOnlyDateAndTimeInputType::didEndChooser() { - m_dateTimeChooser.clear(); + m_dateTimeChooser = nullptr; } void BaseChooserOnlyDateAndTimeInputType::closeDateTimeChooser() @@ -111,17 +108,17 @@ void BaseChooserOnlyDateAndTimeInputType::closeDateTimeChooser() m_dateTimeChooser->endChooser(); } -void BaseChooserOnlyDateAndTimeInputType::handleKeydownEvent(KeyboardEvent* event) +void BaseChooserOnlyDateAndTimeInputType::handleKeydownEvent(KeyboardEvent& event) { BaseClickableWithKeyInputType::handleKeydownEvent(element(), event); } -void BaseChooserOnlyDateAndTimeInputType::handleKeypressEvent(KeyboardEvent* event) +void BaseChooserOnlyDateAndTimeInputType::handleKeypressEvent(KeyboardEvent& event) { BaseClickableWithKeyInputType::handleKeypressEvent(element(), event); } -void BaseChooserOnlyDateAndTimeInputType::handleKeyupEvent(KeyboardEvent* event) +void BaseChooserOnlyDateAndTimeInputType::handleKeyupEvent(KeyboardEvent& event) { BaseClickableWithKeyInputType::handleKeyupEvent(*this, event); } diff --git a/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.h b/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.h index 626c12f33..6d54ebf2f 100644 --- a/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.h +++ b/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.h @@ -23,10 +23,10 @@ * SUCH DAMAGE. */ -#ifndef BaseChooserOnlyDateAndTimeInputType_h -#define BaseChooserOnlyDateAndTimeInputType_h +#pragma once #if ENABLE(DATE_AND_TIME_INPUT_TYPES) + #include "BaseClickableWithKeyInputType.h" #include "BaseDateAndTimeInputType.h" #include "DateTimeChooser.h" @@ -44,23 +44,23 @@ private: void closeDateTimeChooser(); // InputType functions: - virtual void createShadowSubtree() override; - virtual void detach() override; - virtual void setValue(const String&, bool valueChanged, TextFieldEventBehavior) override; - virtual void handleDOMActivateEvent(Event*) override; - virtual void handleKeydownEvent(KeyboardEvent*) override; - virtual void handleKeypressEvent(KeyboardEvent*) override; - virtual void handleKeyupEvent(KeyboardEvent*) override; - virtual void accessKeyAction(bool sendMouseEvents) override; - virtual bool isMouseFocusable() const override; + void createShadowSubtree() override; + void detach() override; + void setValue(const String&, bool valueChanged, TextFieldEventBehavior) override; + void handleDOMActivateEvent(Event&) override; + void handleKeydownEvent(KeyboardEvent&) override; + void handleKeypressEvent(KeyboardEvent&) override; + void handleKeyupEvent(KeyboardEvent&) override; + void accessKeyAction(bool sendMouseEvents) override; + bool isMouseFocusable() const override; // DateTimeChooserClient functions: - virtual void didChooseValue(const String&) override; - virtual void didEndChooser() override; + void didChooseValue(const String&) override; + void didEndChooser() override; RefPtr m_dateTimeChooser; }; -} -#endif +} // namespace WebCore + #endif diff --git a/Source/WebCore/html/BaseClickableWithKeyInputType.cpp b/Source/WebCore/html/BaseClickableWithKeyInputType.cpp index f99dc9812..26eb9574f 100644 --- a/Source/WebCore/html/BaseClickableWithKeyInputType.cpp +++ b/Source/WebCore/html/BaseClickableWithKeyInputType.cpp @@ -39,9 +39,9 @@ namespace WebCore { using namespace HTMLNames; -void BaseClickableWithKeyInputType::handleKeydownEvent(HTMLInputElement& element, KeyboardEvent* event) +void BaseClickableWithKeyInputType::handleKeydownEvent(HTMLInputElement& element, KeyboardEvent& event) { - const String& key = event->keyIdentifier(); + const String& key = event.keyIdentifier(); if (key == "U+0020") { element.setActive(true, true); // No setDefaultHandled(), because IE dispatches a keypress in this case @@ -49,23 +49,23 @@ void BaseClickableWithKeyInputType::handleKeydownEvent(HTMLInputElement& element } } -void BaseClickableWithKeyInputType::handleKeypressEvent(HTMLInputElement& element, KeyboardEvent* event) +void BaseClickableWithKeyInputType::handleKeypressEvent(HTMLInputElement& element, KeyboardEvent& event) { - int charCode = event->charCode(); + int charCode = event.charCode(); if (charCode == '\r') { - element.dispatchSimulatedClick(event); - event->setDefaultHandled(); + element.dispatchSimulatedClick(&event); + event.setDefaultHandled(); return; } if (charCode == ' ') { // Prevent scrolling down the page. - event->setDefaultHandled(); + event.setDefaultHandled(); } } -void BaseClickableWithKeyInputType::handleKeyupEvent(InputType& inputType, KeyboardEvent* event) +void BaseClickableWithKeyInputType::handleKeyupEvent(InputType& inputType, KeyboardEvent& event) { - const String& key = event->keyIdentifier(); + const String& key = event.keyIdentifier(); if (key != "U+0020") return; // Simulate mouse click for spacebar for button types. @@ -78,17 +78,17 @@ void BaseClickableWithKeyInputType::accessKeyAction(HTMLInputElement& element, b element.dispatchSimulatedClick(0, sendMouseEvents ? SendMouseUpDownEvents : SendNoEvents); } -void BaseClickableWithKeyInputType::handleKeydownEvent(KeyboardEvent* event) +void BaseClickableWithKeyInputType::handleKeydownEvent(KeyboardEvent& event) { handleKeydownEvent(element(), event); } -void BaseClickableWithKeyInputType::handleKeypressEvent(KeyboardEvent* event) +void BaseClickableWithKeyInputType::handleKeypressEvent(KeyboardEvent& event) { handleKeypressEvent(element(), event); } -void BaseClickableWithKeyInputType::handleKeyupEvent(KeyboardEvent* event) +void BaseClickableWithKeyInputType::handleKeyupEvent(KeyboardEvent& event) { handleKeyupEvent(*this, event); } diff --git a/Source/WebCore/html/BaseClickableWithKeyInputType.h b/Source/WebCore/html/BaseClickableWithKeyInputType.h index 9bf1d483c..cc5457190 100644 --- a/Source/WebCore/html/BaseClickableWithKeyInputType.h +++ b/Source/WebCore/html/BaseClickableWithKeyInputType.h @@ -28,8 +28,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef BaseClickableWithKeyInputType_h -#define BaseClickableWithKeyInputType_h +#pragma once #include "InputType.h" @@ -38,21 +37,19 @@ namespace WebCore { // Base of input types that dispatches a simulated click on space/return key. class BaseClickableWithKeyInputType : public InputType { public: - static void handleKeydownEvent(HTMLInputElement&, KeyboardEvent*); - static void handleKeypressEvent(HTMLInputElement&, KeyboardEvent*); - static void handleKeyupEvent(InputType&, KeyboardEvent*); + static void handleKeydownEvent(HTMLInputElement&, KeyboardEvent&); + static void handleKeypressEvent(HTMLInputElement&, KeyboardEvent&); + static void handleKeyupEvent(InputType&, KeyboardEvent&); static void accessKeyAction(HTMLInputElement&, bool sendMouseEvents); protected: explicit BaseClickableWithKeyInputType(HTMLInputElement& element) : InputType(element) { } private: - virtual void handleKeydownEvent(KeyboardEvent*) override; - virtual void handleKeypressEvent(KeyboardEvent*) override; - virtual void handleKeyupEvent(KeyboardEvent*) override; - virtual void accessKeyAction(bool sendMouseEvents) override; + void handleKeydownEvent(KeyboardEvent&) override; + void handleKeypressEvent(KeyboardEvent&) override; + void handleKeyupEvent(KeyboardEvent&) override; + void accessKeyAction(bool sendMouseEvents) override; }; } // namespace WebCore - -#endif // BaseClickableWithKeyInputType_h diff --git a/Source/WebCore/html/BaseDateAndTimeInputType.cpp b/Source/WebCore/html/BaseDateAndTimeInputType.cpp index 16f5df7e0..4e5dfc0a5 100644 --- a/Source/WebCore/html/BaseDateAndTimeInputType.cpp +++ b/Source/WebCore/html/BaseDateAndTimeInputType.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2010 Google Inc. All rights reserved. + * Copyright (C) 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -29,9 +30,10 @@ */ #include "config.h" -#if ENABLE(DATE_AND_TIME_INPUT_TYPES) #include "BaseDateAndTimeInputType.h" +#if ENABLE(DATE_AND_TIME_INPUT_TYPES) + #include "HTMLInputElement.h" #include "HTMLNames.h" #include "KeyboardEvent.h" @@ -40,6 +42,7 @@ #include #include #include +#include namespace WebCore { @@ -53,9 +56,10 @@ double BaseDateAndTimeInputType::valueAsDate() const return valueAsDouble(); } -void BaseDateAndTimeInputType::setValueAsDate(double value, ExceptionCode&) const +ExceptionOr BaseDateAndTimeInputType::setValueAsDate(double value) const { element().setValue(serializeWithMilliseconds(value)); + return { }; } double BaseDateAndTimeInputType::valueAsDouble() const @@ -64,9 +68,10 @@ double BaseDateAndTimeInputType::valueAsDouble() const return value.isFinite() ? value.toDouble() : DateComponents::invalidMilliseconds(); } -void BaseDateAndTimeInputType::setValueAsDecimal(const Decimal& newValue, TextFieldEventBehavior eventBehavior, ExceptionCode&) const +ExceptionOr BaseDateAndTimeInputType::setValueAsDecimal(const Decimal& newValue, TextFieldEventBehavior eventBehavior) const { element().setValue(serialize(newValue), eventBehavior); + return { }; } bool BaseDateAndTimeInputType::typeMismatchFor(const String& value) const @@ -91,6 +96,11 @@ bool BaseDateAndTimeInputType::isSteppable() const return true; } +void BaseDateAndTimeInputType::minOrMaxAttributeChanged() +{ + element().invalidateStyleForSubtree(); +} + Decimal BaseDateAndTimeInputType::parseToNumber(const String& source, const Decimal& defaultValue) const { DateComponents date; @@ -108,7 +118,7 @@ bool BaseDateAndTimeInputType::parseToDateComponents(const String& source, DateC DateComponents ignoredResult; if (!out) out = &ignoredResult; - return parseToDateComponentsInternal(source.characters(), source.length(), out); + return parseToDateComponentsInternal(StringView(source).upconvertedCharacters(), source.length(), out); } String BaseDateAndTimeInputType::serialize(const Decimal& value) const @@ -174,7 +184,7 @@ bool BaseDateAndTimeInputType::valueMissing(const String& value) const } #if PLATFORM(IOS) -bool BaseDateAndTimeInputType::isKeyboardFocusable(KeyboardEvent*) const +bool BaseDateAndTimeInputType::isKeyboardFocusable(KeyboardEvent&) const { return !element().isReadOnly() && element().isTextFormControlFocusable(); } diff --git a/Source/WebCore/html/BaseDateAndTimeInputType.h b/Source/WebCore/html/BaseDateAndTimeInputType.h index a3bcd3a89..6e15f5d16 100644 --- a/Source/WebCore/html/BaseDateAndTimeInputType.h +++ b/Source/WebCore/html/BaseDateAndTimeInputType.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2010 Google Inc. All rights reserved. + * Copyright (C) 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -28,10 +29,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef BaseDateAndTimeInputType_h -#define BaseDateAndTimeInputType_h +#pragma once #if ENABLE(DATE_AND_TIME_INPUT_TYPES) + #include "DateComponents.h" #include "InputType.h" @@ -42,15 +43,15 @@ class BaseDateAndTimeInputType : public InputType { protected: BaseDateAndTimeInputType(HTMLInputElement& element) : InputType(element) { } - virtual Decimal parseToNumber(const String&, const Decimal&) const override; - virtual bool parseToDateComponents(const String&, DateComponents*) const override; - virtual String sanitizeValue(const String&) const override; - virtual String serialize(const Decimal&) const override; + Decimal parseToNumber(const String&, const Decimal&) const override; + bool parseToDateComponents(const String&, DateComponents*) const override; + String sanitizeValue(const String&) const override; + String serialize(const Decimal&) const override; String serializeWithComponents(const DateComponents&) const; virtual bool setMillisecondToDateComponents(double, DateComponents*) const = 0; - virtual String visibleValue() const override; + String visibleValue() const override; #if PLATFORM(IOS) - virtual bool isKeyboardFocusable(KeyboardEvent*) const override; + bool isKeyboardFocusable(KeyboardEvent&) const override; #endif private: @@ -58,21 +59,22 @@ private: #if !PLATFORM(IOS) virtual DateComponents::Type dateType() const = 0; #endif - virtual double valueAsDate() const override; - virtual void setValueAsDate(double, ExceptionCode&) const override; - virtual double valueAsDouble() const override; - virtual void setValueAsDecimal(const Decimal&, TextFieldEventBehavior, ExceptionCode&) const override; - virtual bool typeMismatchFor(const String&) const override; - virtual bool typeMismatch() const override; - virtual bool valueMissing(const String&) const override; - virtual Decimal defaultValueForStepUp() const override; - virtual bool isSteppable() const override; + double valueAsDate() const override; + ExceptionOr setValueAsDate(double) const override; + double valueAsDouble() const override; + ExceptionOr setValueAsDecimal(const Decimal&, TextFieldEventBehavior) const override; + bool typeMismatchFor(const String&) const override; + bool typeMismatch() const override; + bool valueMissing(const String&) const override; + Decimal defaultValueForStepUp() const override; + void minOrMaxAttributeChanged() override; + bool isSteppable() const override; virtual String serializeWithMilliseconds(double) const; - virtual String localizeValue(const String&) const override; - virtual bool supportsReadOnly() const override; - virtual bool shouldRespectListAttribute() override; + String localizeValue(const String&) const override; + bool supportsReadOnly() const override; + bool shouldRespectListAttribute() override; }; } // namespace WebCore + #endif -#endif // BaseDateAndTimeInputType_h diff --git a/Source/WebCore/html/BaseTextInputType.cpp b/Source/WebCore/html/BaseTextInputType.cpp index 7bed4bf40..56d670973 100644 --- a/Source/WebCore/html/BaseTextInputType.cpp +++ b/Source/WebCore/html/BaseTextInputType.cpp @@ -39,7 +39,7 @@ bool BaseTextInputType::isTextType() const bool BaseTextInputType::patternMismatch(const String& value) const { - const AtomicString& rawPattern = element().fastGetAttribute(patternAttr); + const AtomicString& rawPattern = element().attributeWithoutSynchronization(patternAttr); if (rawPattern.isNull() || value.isEmpty() || !JSC::Yarr::RegularExpression(rawPattern, TextCaseSensitive).isValid()) return false; String pattern = "^(?:" + rawPattern + ")$"; diff --git a/Source/WebCore/html/BaseTextInputType.h b/Source/WebCore/html/BaseTextInputType.h index ee550d459..38d3ae5fe 100644 --- a/Source/WebCore/html/BaseTextInputType.h +++ b/Source/WebCore/html/BaseTextInputType.h @@ -28,8 +28,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef BaseTextInputType_h -#define BaseTextInputType_h +#pragma once #include "TextFieldInputType.h" @@ -42,12 +41,10 @@ protected: explicit BaseTextInputType(HTMLInputElement& element) : TextFieldInputType(element) { } private: - virtual bool isTextType() const override; - virtual bool patternMismatch(const String&) const override; - virtual bool supportsPlaceholder() const override; - virtual bool supportsSelectionAPI() const override; + bool isTextType() const override; + bool patternMismatch(const String&) const override; + bool supportsPlaceholder() const override; + bool supportsSelectionAPI() const override; }; } // namespace WebCore - -#endif // BaseTextInputType_h diff --git a/Source/WebCore/html/ButtonInputType.h b/Source/WebCore/html/ButtonInputType.h index bd405bae9..cc2fd62fc 100644 --- a/Source/WebCore/html/ButtonInputType.h +++ b/Source/WebCore/html/ButtonInputType.h @@ -28,23 +28,20 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ButtonInputType_h -#define ButtonInputType_h +#pragma once #include "BaseButtonInputType.h" namespace WebCore { -class ButtonInputType : public BaseButtonInputType { +class ButtonInputType final : public BaseButtonInputType { public: explicit ButtonInputType(HTMLInputElement& element) : BaseButtonInputType(element) { } private: - virtual const AtomicString& formControlType() const override; - virtual bool supportsValidation() const override; - virtual bool isTextButton() const override; + const AtomicString& formControlType() const override; + bool supportsValidation() const override; + bool isTextButton() const override; }; } // namespace WebCore - -#endif // ButtonInputType_h diff --git a/Source/WebCore/html/CachedHTMLCollection.h b/Source/WebCore/html/CachedHTMLCollection.h new file mode 100644 index 000000000..3fb475279 --- /dev/null +++ b/Source/WebCore/html/CachedHTMLCollection.h @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "CollectionTraversal.h" +#include "HTMLCollection.h" +#include "HTMLElement.h" + +namespace WebCore { + +template +class CachedHTMLCollection : public HTMLCollection { +public: + CachedHTMLCollection(ContainerNode& base, CollectionType); + + virtual ~CachedHTMLCollection(); + + unsigned length() const final { return m_indexCache.nodeCount(collection()); } + Element* item(unsigned offset) const override { return m_indexCache.nodeAt(collection(), offset); } + Element* namedItem(const AtomicString& name) const override; + size_t memoryCost() const final { return m_indexCache.memoryCost() + HTMLCollection::memoryCost(); } + + // For CollectionIndexCache; do not use elsewhere. + using CollectionTraversalIterator = typename CollectionTraversal::Iterator; + CollectionTraversalIterator collectionBegin() const { return CollectionTraversal::begin(collection(), rootNode()); } + CollectionTraversalIterator collectionLast() const { return CollectionTraversal::last(collection(), rootNode()); } + CollectionTraversalIterator collectionEnd() const { return CollectionTraversal::end(rootNode()); } + void collectionTraverseForward(CollectionTraversalIterator& current, unsigned count, unsigned& traversedCount) const { CollectionTraversal::traverseForward(collection(), current, count, traversedCount); } + void collectionTraverseBackward(CollectionTraversalIterator& current, unsigned count) const { CollectionTraversal::traverseBackward(collection(), current, count); } + bool collectionCanTraverseBackward() const { return traversalType != CollectionTraversalType::CustomForwardOnly; } + void willValidateIndexCache() const { document().registerCollection(const_cast&>(*this)); } + + void invalidateCache(Document&) override; + + bool elementMatches(Element&) const; + +private: + HTMLCollectionClass& collection() { return static_cast(*this); } + const HTMLCollectionClass& collection() const { return static_cast(*this); } + + mutable CollectionIndexCache m_indexCache; +}; + +template +CachedHTMLCollection::CachedHTMLCollection(ContainerNode& base, CollectionType collectionType) + : HTMLCollection(base, collectionType) + , m_indexCache(collection()) +{ } + +template +CachedHTMLCollection::~CachedHTMLCollection() +{ + if (m_indexCache.hasValidCache(collection())) + document().unregisterCollection(*this); +} + +template +void CachedHTMLCollection::invalidateCache(Document& document) +{ + HTMLCollection::invalidateCache(document); + if (m_indexCache.hasValidCache(collection())) { + document.unregisterCollection(*this); + m_indexCache.invalidate(collection()); + } +} + +template +bool CachedHTMLCollection::elementMatches(Element&) const +{ + // We call the elementMatches() method directly on the subclass instead for performance. + ASSERT_NOT_REACHED(); + return false; +} + +static inline bool nameShouldBeVisibleInDocumentAll(HTMLElement& element) +{ + // The document.all collection returns only certain types of elements by name, + // although it returns any type of element by id. + return element.hasTagName(HTMLNames::appletTag) + || element.hasTagName(HTMLNames::embedTag) + || element.hasTagName(HTMLNames::formTag) + || element.hasTagName(HTMLNames::imgTag) + || element.hasTagName(HTMLNames::inputTag) + || element.hasTagName(HTMLNames::objectTag) + || element.hasTagName(HTMLNames::selectTag); +} + +static inline bool nameShouldBeVisibleInDocumentAll(Element& element) +{ + return is(element) && nameShouldBeVisibleInDocumentAll(downcast(element)); +} + +template +Element* CachedHTMLCollection::namedItem(const AtomicString& name) const +{ + // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/nameditem.asp + // This method first searches for an object with a matching id + // attribute. If a match is not found, the method then searches for an + // object with a matching name attribute, but only on those elements + // that are allowed a name attribute. + + if (name.isEmpty()) + return nullptr; + + ContainerNode& root = rootNode(); + if (traversalType != CollectionTraversalType::CustomForwardOnly && root.isInTreeScope()) { + Element* candidate = nullptr; + + TreeScope& treeScope = root.treeScope(); + if (treeScope.hasElementWithId(*name.impl())) { + if (!treeScope.containsMultipleElementsWithId(name)) + candidate = treeScope.getElementById(name); + } else if (treeScope.hasElementWithName(*name.impl())) { + if (!treeScope.containsMultipleElementsWithName(name)) { + if ((candidate = treeScope.getElementByName(name))) { + if (!is(*candidate)) + candidate = nullptr; + else if (type() == DocAll && !nameShouldBeVisibleInDocumentAll(*candidate)) + candidate = nullptr; + } + } + } else + return nullptr; + + if (candidate && collection().elementMatches(*candidate)) { + if (traversalType == CollectionTraversalType::ChildrenOnly ? candidate->parentNode() == &root : candidate->isDescendantOf(root)) + return candidate; + } + } + + return namedItemSlow(name); +} + +} // namespace WebCore diff --git a/Source/WebCore/html/CheckboxInputType.cpp b/Source/WebCore/html/CheckboxInputType.cpp index 69cf05bca..b8b7e0875 100644 --- a/Source/WebCore/html/CheckboxInputType.cpp +++ b/Source/WebCore/html/CheckboxInputType.cpp @@ -54,9 +54,9 @@ String CheckboxInputType::valueMissingText() const return validationMessageValueMissingForCheckboxText(); } -void CheckboxInputType::handleKeyupEvent(KeyboardEvent* event) +void CheckboxInputType::handleKeyupEvent(KeyboardEvent& event) { - const String& key = event->keyIdentifier(); + const String& key = event.keyIdentifier(); if (key != "U+0020") return; dispatchSimulatedClickIfActive(event); @@ -92,9 +92,14 @@ bool CheckboxInputType::isCheckbox() const return true; } -bool CheckboxInputType::supportsIndeterminateAppearance() const +bool CheckboxInputType::matchesIndeterminatePseudoClass() const { - return true; + return shouldAppearIndeterminate(); +} + +bool CheckboxInputType::shouldAppearIndeterminate() const +{ + return element().indeterminate(); } } // namespace WebCore diff --git a/Source/WebCore/html/CheckboxInputType.h b/Source/WebCore/html/CheckboxInputType.h index 5a9a20650..155dae404 100644 --- a/Source/WebCore/html/CheckboxInputType.h +++ b/Source/WebCore/html/CheckboxInputType.h @@ -28,28 +28,26 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CheckboxInputType_h -#define CheckboxInputType_h +#pragma once #include "BaseCheckableInputType.h" namespace WebCore { -class CheckboxInputType : public BaseCheckableInputType { +class CheckboxInputType final : public BaseCheckableInputType { public: explicit CheckboxInputType(HTMLInputElement& element) : BaseCheckableInputType(element) { } private: - virtual const AtomicString& formControlType() const override; - virtual bool valueMissing(const String&) const override; - virtual String valueMissingText() const override; - virtual void handleKeyupEvent(KeyboardEvent*) override; - virtual void willDispatchClick(InputElementClickState&) override; - virtual void didDispatchClick(Event*, const InputElementClickState&) override; - virtual bool isCheckbox() const override; - virtual bool supportsIndeterminateAppearance() const override; + const AtomicString& formControlType() const override; + bool valueMissing(const String&) const override; + String valueMissingText() const override; + void handleKeyupEvent(KeyboardEvent&) override; + void willDispatchClick(InputElementClickState&) override; + void didDispatchClick(Event*, const InputElementClickState&) override; + bool isCheckbox() const override; + bool matchesIndeterminatePseudoClass() const override; + bool shouldAppearIndeterminate() const override; }; } // namespace WebCore - -#endif // CheckboxInputType_h diff --git a/Source/WebCore/html/ClassList.cpp b/Source/WebCore/html/ClassList.cpp deleted file mode 100644 index 7e332d4b7..000000000 --- a/Source/WebCore/html/ClassList.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. All rights reserved. - * Copyright (C) 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "ClassList.h" - -#include "Element.h" -#include "HTMLNames.h" -#include "HTMLParserIdioms.h" - -namespace WebCore { - -void ClassList::ref() -{ - m_element.ref(); -} - -void ClassList::deref() -{ - m_element.deref(); -} - -unsigned ClassList::length() const -{ - return m_element.hasClass() ? classNames().size() : 0; -} - -const AtomicString ClassList::item(unsigned index) const -{ - if (index >= length()) - return AtomicString(); - return classNames()[index]; -} - -Element* ClassList::element() const -{ - return &m_element; -} - -bool ClassList::containsInternal(const AtomicString& token) const -{ - return m_element.hasClass() && classNames().contains(token); -} - -AtomicString ClassList::value() const -{ - return m_element.getAttribute(HTMLNames::classAttr); -} - -void ClassList::setValue(const AtomicString& value) -{ - m_element.setAttribute(HTMLNames::classAttr, value); -} - -const SpaceSplitString& ClassList::classNames() const -{ - ASSERT(m_element.hasClass()); - if (m_element.document().inQuirksMode()) { - if (m_classNamesForQuirksMode.isEmpty()) - m_classNamesForQuirksMode.set(value(), false); - return m_classNamesForQuirksMode; - } - return m_element.elementData()->classNames(); -} - -} // namespace WebCore diff --git a/Source/WebCore/html/ClassList.h b/Source/WebCore/html/ClassList.h deleted file mode 100644 index 8aaa4c7c3..000000000 --- a/Source/WebCore/html/ClassList.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. All rights reserved. - * Copyright (C) 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef ClassList_h -#define ClassList_h - -#include "DOMTokenList.h" -#include "SpaceSplitString.h" - -namespace WebCore { - -class Element; - -class ClassList final : public DOMTokenList { -public: - ClassList(Element& element) - : m_element(element) - { - } - - virtual void ref() override; - virtual void deref() override; - - virtual unsigned length() const override; - virtual const AtomicString item(unsigned index) const override; - - virtual Element* element() const override; - - void clearValueForQuirksMode() { m_classNamesForQuirksMode.clear(); } - -private: - virtual bool containsInternal(const AtomicString&) const override; - virtual AtomicString value() const override; - virtual void setValue(const AtomicString&) override; - - const SpaceSplitString& classNames() const; - - Element& m_element; - mutable SpaceSplitString m_classNamesForQuirksMode; -}; - -} // namespace WebCore - -#endif // ClassList_h diff --git a/Source/WebCore/html/CollectionTraversal.h b/Source/WebCore/html/CollectionTraversal.h new file mode 100644 index 000000000..66829338d --- /dev/null +++ b/Source/WebCore/html/CollectionTraversal.h @@ -0,0 +1,245 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "CollectionType.h" +#include "ElementChildIterator.h" +#include "ElementDescendantIterator.h" + +namespace WebCore { + +template +struct CollectionTraversal { }; + +template <> +struct CollectionTraversal { + using Iterator = ElementDescendantIterator; + + static ElementDescendantIterator end(ContainerNode&) { return ElementDescendantIterator(); } + + template + static ElementDescendantIterator begin(const CollectionClass&, ContainerNode& rootNode); + + template + static ElementDescendantIterator last(const CollectionClass&, ContainerNode& rootNode); + + template + static void traverseForward(const CollectionClass&, ElementDescendantIterator& current, unsigned count, unsigned& traversedCount); + + template + static void traverseBackward(const CollectionClass&, ElementDescendantIterator& current, unsigned count); +}; + +template +inline ElementDescendantIterator CollectionTraversal::begin(const CollectionClass& collection, ContainerNode& rootNode) +{ + auto descendants = elementDescendants(rootNode); + auto end = descendants.end(); + for (auto it = descendants.begin(); it != end; ++it) { + if (collection.elementMatches(*it)) { + // Drop iterator assertions because HTMLCollections / NodeList use a fine-grained invalidation scheme. + it.dropAssertions(); + return it; + } + } + return end; +} + +template +inline ElementDescendantIterator CollectionTraversal::last(const CollectionClass& collection, ContainerNode& rootNode) +{ + auto descendants = elementDescendants(rootNode); + ElementDescendantIterator invalid; + for (auto it = descendants.last(); it != invalid; --it) { + if (collection.elementMatches(*it)) { + // Drop iterator assertions because HTMLCollections / NodeList use a fine-grained invalidation scheme. + it.dropAssertions(); + return it; + } + } + return invalid; +} + +template +inline void CollectionTraversal::traverseForward(const CollectionClass& collection, ElementDescendantIterator& current, unsigned count, unsigned& traversedCount) +{ + ASSERT(collection.elementMatches(*current)); + ElementDescendantIterator invalid; + for (traversedCount = 0; traversedCount < count; ++traversedCount) { + do { + ++current; + if (current == invalid) + return; + } while (!collection.elementMatches(*current)); + } +} + +template +inline void CollectionTraversal::traverseBackward(const CollectionClass& collection, ElementDescendantIterator& current, unsigned count) +{ + ASSERT(collection.elementMatches(*current)); + ElementDescendantIterator invalid; + for (; count; --count) { + do { + --current; + if (current == invalid) + return; + } while (!collection.elementMatches(*current)); + } +} + +template <> +struct CollectionTraversal { + using Iterator = ElementChildIterator; + + static ElementChildIterator end(ContainerNode& rootNode) { return ElementChildIterator(rootNode); } + + template + static ElementChildIterator begin(const CollectionClass&, ContainerNode& rootNode); + + template + static ElementChildIterator last(const CollectionClass&, ContainerNode& rootNode); + + template + static void traverseForward(const CollectionClass&, ElementChildIterator& current, unsigned count, unsigned& traversedCount); + + template + static void traverseBackward(const CollectionClass&, ElementChildIterator& current, unsigned count); +}; + +template +inline ElementChildIterator CollectionTraversal::begin(const CollectionClass& collection, ContainerNode& rootNode) +{ + auto children = childrenOfType(rootNode); + auto end = children.end(); + for (auto it = children.begin(); it != end; ++it) { + if (collection.elementMatches(*it)) { + // Drop iterator assertions because HTMLCollections / NodeList use a fine-grained invalidation scheme. + it.dropAssertions(); + return it; + } + } + return end; +} + +template +inline ElementChildIterator CollectionTraversal::last(const CollectionClass& collection, ContainerNode& rootNode) +{ + auto children = childrenOfType(rootNode); + ElementChildIterator invalid(collection.rootNode()); + ElementChildIterator last(rootNode, children.last()); + for (auto it = last; it != invalid; --it) { + if (collection.elementMatches(*it)) { + // Drop iterator assertions because HTMLCollections / NodeList use a fine-grained invalidation scheme. + it.dropAssertions(); + return it; + } + } + return invalid; +} + +template +inline void CollectionTraversal::traverseForward(const CollectionClass& collection, ElementChildIterator& current, unsigned count, unsigned& traversedCount) +{ + ASSERT(collection.elementMatches(*current)); + ElementChildIterator invalid(collection.rootNode()); + for (traversedCount = 0; traversedCount < count; ++traversedCount) { + do { + ++current; + if (current == invalid) + return; + } while (!collection.elementMatches(*current)); + } +} + +template +inline void CollectionTraversal::traverseBackward(const CollectionClass& collection, ElementChildIterator& current, unsigned count) +{ + ASSERT(collection.elementMatches(*current)); + ElementChildIterator invalid(collection.rootNode()); + for (; count; --count) { + do { + --current; + if (current == invalid) + return; + } while (!collection.elementMatches(*current)); + } +} + +template <> +struct CollectionTraversal { + using Iterator = Element*; + + static Element* end(ContainerNode&) { return nullptr; } + + template + static Element* begin(const CollectionClass&, ContainerNode&); + + template + static Element* last(const CollectionClass&, ContainerNode&); + + template + static void traverseForward(const CollectionClass&, Element*& current, unsigned count, unsigned& traversedCount); + + template + static void traverseBackward(const CollectionClass&, Element*&, unsigned count); +}; + +template +inline Element* CollectionTraversal::begin(const CollectionClass& collection, ContainerNode&) +{ + return collection.customElementAfter(nullptr); +} + +template +inline Element* CollectionTraversal::last(const CollectionClass&, ContainerNode&) +{ + ASSERT_NOT_REACHED(); + return nullptr; +} + +template +inline void CollectionTraversal::traverseForward(const CollectionClass& collection, Element*& current, unsigned count, unsigned& traversedCount) +{ + Element* element = current; + for (traversedCount = 0; traversedCount < count; ++traversedCount) { + element = collection.customElementAfter(element); + if (!element) { + current = nullptr; + return; + } + } + current = element; +} + +template +inline void CollectionTraversal::traverseBackward(const CollectionClass&, Element*&, unsigned count) +{ + UNUSED_PARAM(count); + ASSERT_NOT_REACHED(); +} + +} // namespace WebCore diff --git a/Source/WebCore/html/CollectionType.h b/Source/WebCore/html/CollectionType.h index 5130af91d..fdd7f3eb3 100644 --- a/Source/WebCore/html/CollectionType.h +++ b/Source/WebCore/html/CollectionType.h @@ -20,8 +20,7 @@ * */ -#ifndef CollectionType_h -#define CollectionType_h +#pragma once namespace WebCore { @@ -50,9 +49,47 @@ enum CollectionType { SelectedOptions, DataListOptions, MapAreas, - FormControls + FormControls, + ByClass, + ByTag, + ByHTMLTag, + AllDescendants }; -} // namespace +enum class CollectionTraversalType { Descendants, ChildrenOnly, CustomForwardOnly }; +template +struct CollectionTypeTraits { + static const CollectionTraversalType traversalType = CollectionTraversalType::Descendants; +}; + +template<> +struct CollectionTypeTraits { + static const CollectionTraversalType traversalType = CollectionTraversalType::ChildrenOnly; +}; + +template<> +struct CollectionTypeTraits { + static const CollectionTraversalType traversalType = CollectionTraversalType::ChildrenOnly; +}; + +template<> +struct CollectionTypeTraits { + static const CollectionTraversalType traversalType = CollectionTraversalType::ChildrenOnly; +}; + +template<> +struct CollectionTypeTraits { + static const CollectionTraversalType traversalType = CollectionTraversalType::ChildrenOnly; +}; + +template<> +struct CollectionTypeTraits { + static const CollectionTraversalType traversalType = CollectionTraversalType::CustomForwardOnly; +}; + +template<> +struct CollectionTypeTraits { + static const CollectionTraversalType traversalType = CollectionTraversalType::CustomForwardOnly; +}; -#endif +} // namespace WebCore diff --git a/Source/WebCore/html/ColorInputType.cpp b/Source/WebCore/html/ColorInputType.cpp index 97cd43599..d03f6784e 100644 --- a/Source/WebCore/html/ColorInputType.cpp +++ b/Source/WebCore/html/ColorInputType.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2010 Google Inc. All rights reserved. + * Copyright (C) 2015-2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -29,20 +30,24 @@ */ #include "config.h" + #if ENABLE(INPUT_TYPE_COLOR) + #include "ColorInputType.h" #include "CSSPropertyNames.h" #include "Chrome.h" #include "Color.h" +#include "ElementChildIterator.h" +#include "Event.h" #include "HTMLDataListElement.h" #include "HTMLDivElement.h" #include "HTMLInputElement.h" #include "HTMLOptionElement.h" #include "InputTypeNames.h" -#include "MouseEvent.h" #include "RenderObject.h" #include "RenderView.h" +#include "ScopedEventQueue.h" #include "ScriptController.h" #include "ShadowRoot.h" @@ -50,18 +55,30 @@ namespace WebCore { using namespace HTMLNames; -static bool isValidColorString(const String& value) +static bool isValidSimpleColorString(const String& value) { + // See https://html.spec.whatwg.org/multipage/infrastructure.html#valid-simple-colour + if (value.isEmpty()) return false; if (value[0] != '#') return false; - - // We don't accept #rgb and #aarrggbb formats. if (value.length() != 7) return false; - Color color(value); - return color.isValid() && !color.hasAlpha(); + if (value.is8Bit()) { + const LChar* characters = value.characters8(); + for (unsigned i = 1, length = value.length(); i < length; ++i) { + if (!isASCIIHexDigit(characters[i])) + return false; + } + } else { + const UChar* characters = value.characters16(); + for (unsigned i = 1, length = value.length(); i < length; ++i) { + if (!isASCIIHexDigit(characters[i])) + return false; + } + } + return true; } ColorInputType::~ColorInputType() @@ -69,11 +86,6 @@ ColorInputType::~ColorInputType() endColorChooser(); } -void ColorInputType::attach() -{ - observeFeatureIfVisible(FeatureObserver::InputTypeColor); -} - bool ColorInputType::isColorControl() const { return true; @@ -91,15 +103,15 @@ bool ColorInputType::supportsRequired() const String ColorInputType::fallbackValue() const { - return String("#000000"); + return ASCIILiteral("#000000"); } String ColorInputType::sanitizeValue(const String& proposedValue) const { - if (!isValidColorString(proposedValue)) + if (!isValidSimpleColorString(proposedValue)) return fallbackValue(); - return proposedValue.lower(); + return proposedValue.convertToASCIILowercase(); } Color ColorInputType::valueAsColor() const @@ -112,12 +124,12 @@ void ColorInputType::createShadowSubtree() ASSERT(element().shadowRoot()); Document& document = element().document(); - RefPtr wrapperElement = HTMLDivElement::create(document); + auto wrapperElement = HTMLDivElement::create(document); wrapperElement->setPseudo(AtomicString("-webkit-color-swatch-wrapper", AtomicString::ConstructFromLiteral)); - RefPtr colorSwatch = HTMLDivElement::create(document); + auto colorSwatch = HTMLDivElement::create(document); colorSwatch->setPseudo(AtomicString("-webkit-color-swatch", AtomicString::ConstructFromLiteral)); - wrapperElement->appendChild(colorSwatch.release(), ASSERT_NO_EXCEPTION); - element().userAgentShadowRoot()->appendChild(wrapperElement.release(), ASSERT_NO_EXCEPTION); + wrapperElement->appendChild(colorSwatch); + element().userAgentShadowRoot()->appendChild(wrapperElement); updateColorSwatch(); } @@ -134,9 +146,9 @@ void ColorInputType::setValue(const String& value, bool valueChanged, TextFieldE m_chooser->setSelectedColor(valueAsColor()); } -void ColorInputType::handleDOMActivateEvent(Event* event) +void ColorInputType::handleDOMActivateEvent(Event& event) { - if (element().isDisabledOrReadOnly() || !element().renderer()) + if (element().isDisabledFormControl() || !element().renderer()) return; if (!ScriptController::processingUserGesture()) @@ -144,12 +156,12 @@ void ColorInputType::handleDOMActivateEvent(Event* event) if (Chrome* chrome = this->chrome()) { if (!m_chooser) - m_chooser = chrome->createColorChooser(this, valueAsColor()); + m_chooser = chrome->createColorChooser(*this, valueAsColor()); else m_chooser->reattachColorChooser(valueAsColor()); } - event->setDefaultHandled(); + event.setDefaultHandled(); } void ColorInputType::detach() @@ -164,7 +176,7 @@ bool ColorInputType::shouldRespectListAttribute() bool ColorInputType::typeMismatchFor(const String& value) const { - return !isValidColorString(value); + return !isValidSimpleColorString(value); } bool ColorInputType::shouldResetOnDocumentActivation() @@ -174,8 +186,9 @@ bool ColorInputType::shouldResetOnDocumentActivation() void ColorInputType::didChooseColor(const Color& color) { - if (element().isDisabledOrReadOnly() || color == valueAsColor()) + if (element().isDisabledFormControl() || color == valueAsColor()) return; + EventQueueScope scope; element().setValueFromRenderer(color.serialized()); updateColorSwatch(); element().dispatchFormControlChangeEvent(); @@ -183,7 +196,7 @@ void ColorInputType::didChooseColor(const Color& color) void ColorInputType::didEndChooser() { - m_chooser.clear(); + m_chooser = nullptr; } void ColorInputType::endColorChooser() @@ -204,12 +217,21 @@ void ColorInputType::updateColorSwatch() HTMLElement* ColorInputType::shadowColorSwatch() const { ShadowRoot* shadow = element().userAgentShadowRoot(); - return shadow ? toHTMLElement(shadow->firstChild()->firstChild()) : 0; + if (!shadow) + return nullptr; + + auto wrapper = childrenOfType(*shadow).first(); + if (!wrapper) + return nullptr; + + return childrenOfType(*wrapper).first(); } IntRect ColorInputType::elementRectRelativeToRootView() const { - return element().document().view()->contentsToRootView(element().pixelSnappedBoundingBox()); + if (!element().renderer()) + return IntRect(); + return element().document().view()->contentsToRootView(element().renderer()->absoluteBoundingBoxRect()); } Color ColorInputType::currentColor() @@ -220,7 +242,7 @@ Color ColorInputType::currentColor() bool ColorInputType::shouldShowSuggestions() const { #if ENABLE(DATALIST_ELEMENT) - return element().fastHasAttribute(listAttr); + return element().hasAttributeWithoutSynchronization(listAttr); #else return false; #endif @@ -230,22 +252,25 @@ Vector ColorInputType::suggestions() const { Vector suggestions; #if ENABLE(DATALIST_ELEMENT) - HTMLDataListElement* dataList = element().dataList(); - if (dataList) { - RefPtr options = dataList->options(); - for (unsigned i = 0; HTMLOptionElement* option = toHTMLOptionElement(options->item(i)); i++) { - if (!element().isValidValue(option->value())) - continue; - Color color(option->value()); - if (!color.isValid()) - continue; - suggestions.append(color); + if (auto* dataList = element().dataList()) { + Ref options = dataList->options(); + unsigned length = options->length(); + suggestions.reserveInitialCapacity(length); + for (unsigned i = 0; i != length; ++i) { + auto value = downcast(*options->item(i)).value(); + if (isValidSimpleColorString(value)) + suggestions.uncheckedAppend(Color(value)); } } #endif return suggestions; } +void ColorInputType::selectColor(const Color& color) +{ + didChooseColor(color); +} + } // namespace WebCore #endif // ENABLE(INPUT_TYPE_COLOR) diff --git a/Source/WebCore/html/ColorInputType.h b/Source/WebCore/html/ColorInputType.h index 360e3005c..06f60e240 100644 --- a/Source/WebCore/html/ColorInputType.h +++ b/Source/WebCore/html/ColorInputType.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2010 Google Inc. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -28,53 +29,49 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ColorInputType_h -#define ColorInputType_h +#pragma once #if ENABLE(INPUT_TYPE_COLOR) + #include "BaseClickableWithKeyInputType.h" #include "ColorChooserClient.h" namespace WebCore { -class ColorInputType : public BaseClickableWithKeyInputType, public ColorChooserClient { +class ColorInputType final : public BaseClickableWithKeyInputType, private ColorChooserClient { public: explicit ColorInputType(HTMLInputElement& element) : BaseClickableWithKeyInputType(element) { } virtual ~ColorInputType(); - // ColorChooserClient implementation. - virtual void didChooseColor(const Color&) override; - virtual void didEndChooser() override; - virtual IntRect elementRectRelativeToRootView() const override; - virtual Color currentColor() override; - virtual bool shouldShowSuggestions() const override; - virtual Vector suggestions() const override; - private: - virtual void attach() override; - virtual bool isColorControl() const override; - virtual const AtomicString& formControlType() const override; - virtual bool supportsRequired() const override; - virtual String fallbackValue() const override; - virtual String sanitizeValue(const String&) const override; - virtual void createShadowSubtree() override; - virtual void setValue(const String&, bool valueChanged, TextFieldEventBehavior) override; - virtual void handleDOMActivateEvent(Event*) override; - virtual void detach() override; - virtual bool shouldRespectListAttribute() override; - virtual bool typeMismatchFor(const String&) const override; - virtual bool shouldResetOnDocumentActivation() override; + void didChooseColor(const Color&) override; + void didEndChooser() override; + IntRect elementRectRelativeToRootView() const override; + Color currentColor() override; + bool shouldShowSuggestions() const override; + Vector suggestions() const override; + bool isColorControl() const override; + const AtomicString& formControlType() const override; + bool supportsRequired() const override; + String fallbackValue() const override; + String sanitizeValue(const String&) const override; + void createShadowSubtree() override; + void setValue(const String&, bool valueChanged, TextFieldEventBehavior) override; + void handleDOMActivateEvent(Event&) override; + void detach() override; + bool shouldRespectListAttribute() override; + bool typeMismatchFor(const String&) const override; + bool shouldResetOnDocumentActivation() override; + Color valueAsColor() const override; + void selectColor(const Color&) override; - Color valueAsColor() const; void endColorChooser(); void updateColorSwatch(); HTMLElement* shadowColorSwatch() const; - OwnPtr m_chooser; + std::unique_ptr m_chooser; }; } // namespace WebCore #endif // ENABLE(INPUT_TYPE_COLOR) - -#endif // ColorInputType_h diff --git a/Source/WebCore/html/DOMFormData.cpp b/Source/WebCore/html/DOMFormData.cpp index 9a7ce21f4..6442d57c1 100644 --- a/Source/WebCore/html/DOMFormData.cpp +++ b/Source/WebCore/html/DOMFormData.cpp @@ -47,10 +47,9 @@ DOMFormData::DOMFormData(HTMLFormElement* form) if (!form) return; - for (unsigned i = 0; i < form->associatedElements().size(); ++i) { - FormAssociatedElement& element = *form->associatedElements()[i]; - if (!element.asHTMLElement().isDisabledFormControl()) - element.appendFormData(*this, true); + for (auto& element : form->associatedElements()) { + if (!element->asHTMLElement().isDisabledFormControl()) + element->appendFormData(*this, true); } } @@ -60,7 +59,7 @@ void DOMFormData::append(const String& name, const String& value) appendData(name, value); } -void DOMFormData::append(const String& name, Blob* blob, const String& filename) +void DOMFormData::append(const String& name, Blob& blob, const String& filename) { if (!name.isEmpty()) appendBlob(name, blob, filename); diff --git a/Source/WebCore/html/DOMFormData.h b/Source/WebCore/html/DOMFormData.h index 842e62b04..adbcbbfc3 100644 --- a/Source/WebCore/html/DOMFormData.h +++ b/Source/WebCore/html/DOMFormData.h @@ -28,12 +28,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef DOMFormData_h -#define DOMFormData_h +#pragma once #include "FormDataList.h" #include -#include #include namespace WebCore { @@ -44,11 +42,11 @@ class TextEncoding; class DOMFormData : public FormDataList, public RefCounted { public: - static PassRefPtr create(HTMLFormElement* form) { return adoptRef(new DOMFormData(form)); } - static PassRefPtr create(const TextEncoding& encoding) { return adoptRef(new DOMFormData(encoding)); } + static Ref create(HTMLFormElement* form) { return adoptRef(*new DOMFormData(form)); } + static Ref create(const TextEncoding& encoding) { return adoptRef(*new DOMFormData(encoding)); } void append(const String& name, const String& value); - void append(const String& name, Blob*, const String& filename = String()); + void append(const String& name, Blob&, const String& filename = String()); private: explicit DOMFormData(const TextEncoding&); @@ -56,5 +54,3 @@ private: }; } // namespace WebCore - -#endif // DOMFormData_h diff --git a/Source/WebCore/html/DOMFormData.idl b/Source/WebCore/html/DOMFormData.idl index 0035347ba..c8a7f46bd 100644 --- a/Source/WebCore/html/DOMFormData.idl +++ b/Source/WebCore/html/DOMFormData.idl @@ -29,16 +29,13 @@ */ [ - CustomConstructor(optional HTMLFormElement form), + Constructor(optional HTMLFormElement? form), JSGenerateToNativeObject, JSGenerateToJSObject, InterfaceName=FormData, ImplementationLacksVTable, ] interface DOMFormData { - // void append(DOMString name, DOMString value); - // void append(DOMString name, Blob value, optional DOMString filename); - [Custom] void append([Default=Undefined] optional DOMString name, - [Default=Undefined] optional DOMString value, - [Default=Undefined] optional DOMString filename); + void append(USVString name, USVString value); + void append(USVString name, Blob value, optional USVString filename); }; diff --git a/Source/WebCore/html/DOMSettableTokenList.cpp b/Source/WebCore/html/DOMSettableTokenList.cpp deleted file mode 100644 index 741ff595c..000000000 --- a/Source/WebCore/html/DOMSettableTokenList.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. All rights reserved. - * Copyright (C) 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "DOMSettableTokenList.h" - -namespace WebCore { - -PassRefPtr DOMSettableTokenList::create() -{ - return adoptRef(new DOMSettableTokenList()); -} - -void DOMSettableTokenList::ref() -{ - RefCounted::ref(); -} - -void DOMSettableTokenList::deref() -{ - RefCounted::deref(); -} - -unsigned DOMSettableTokenList::length() const -{ - return m_tokens.size(); -} - -const AtomicString DOMSettableTokenList::item(unsigned index) const -{ - if (index >= length()) - return AtomicString(); - return m_tokens[index]; -} - -bool DOMSettableTokenList::containsInternal(const AtomicString& token) const -{ - return m_tokens.contains(token); -} - -AtomicString DOMSettableTokenList::value() const -{ - return m_value; -} - -void DOMSettableTokenList::setValue(const AtomicString& value) -{ - m_value = value; - m_tokens.set(value, false); -} - -} // namespace WebCore diff --git a/Source/WebCore/html/DOMSettableTokenList.h b/Source/WebCore/html/DOMSettableTokenList.h deleted file mode 100644 index 9d3dee6be..000000000 --- a/Source/WebCore/html/DOMSettableTokenList.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. All rights reserved. - * Copyright (C) 2013 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef DOMSettableTokenList_h -#define DOMSettableTokenList_h - -#include "DOMTokenList.h" -#include "SpaceSplitString.h" -#include -#include - -namespace WebCore { - -typedef int ExceptionCode; - -class DOMSettableTokenList : public DOMTokenList, public RefCounted { - WTF_MAKE_FAST_ALLOCATED; -public: - static PassRefPtr create(); - - virtual void ref() override final; - virtual void deref() override final; - - virtual unsigned length() const override final; - virtual const AtomicString item(unsigned index) const override final; - - virtual AtomicString value() const override final; - virtual void setValue(const AtomicString&) override final; - -private: - virtual bool containsInternal(const AtomicString&) const override final; - - AtomicString m_value; - SpaceSplitString m_tokens; -}; - -} // namespace WebCore - -#endif // DOMSettableTokenList_h diff --git a/Source/WebCore/html/DOMSettableTokenList.idl b/Source/WebCore/html/DOMSettableTokenList.idl deleted file mode 100644 index 59d0be260..000000000 --- a/Source/WebCore/html/DOMSettableTokenList.idl +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -[ - JSGenerateToJSObject, - SkipVTableValidation, -] interface DOMSettableTokenList : DOMTokenList { - attribute DOMString value; - - [TreatReturnedNullStringAs=Null] getter DOMString (unsigned long index); -}; - diff --git a/Source/WebCore/html/DOMTokenList.cpp b/Source/WebCore/html/DOMTokenList.cpp index dbd4d2639..0395a2e0f 100644 --- a/Source/WebCore/html/DOMTokenList.cpp +++ b/Source/WebCore/html/DOMTokenList.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2010 Google Inc. All rights reserved. + * Copyright (C) 2015, 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,211 +28,240 @@ #include "ExceptionCode.h" #include "HTMLParserIdioms.h" +#include "SpaceSplitString.h" +#include +#include +#include #include namespace WebCore { -bool DOMTokenList::validateToken(const AtomicString& token, ExceptionCode& ec) +DOMTokenList::DOMTokenList(Element& element, const QualifiedName& attributeName, WTF::Function&& isSupportedToken) + : m_element(element) + , m_attributeName(attributeName) + , m_isSupportedToken(WTFMove(isSupportedToken)) { - if (token.isEmpty()) { - ec = SYNTAX_ERR; - return false; - } +} - unsigned length = token.length(); - for (unsigned i = 0; i < length; ++i) { - if (isHTMLSpace(token[i])) { - ec = INVALID_CHARACTER_ERR; - return false; - } +static inline bool tokenContainsHTMLSpace(const String& token) +{ + return token.find(isHTMLSpace) != notFound; +} + +ExceptionOr DOMTokenList::validateToken(const String& token) +{ + if (token.isEmpty()) + return Exception { SYNTAX_ERR }; + + if (tokenContainsHTMLSpace(token)) + return Exception { INVALID_CHARACTER_ERR }; + + return { }; +} + +ExceptionOr DOMTokenList::validateTokens(const String* tokens, size_t length) +{ + for (size_t i = 0; i < length; ++i) { + auto result = validateToken(tokens[i]); + if (result.hasException()) + return result; } + return { }; +} - return true; +bool DOMTokenList::contains(const AtomicString& token) const +{ + return tokens().contains(token); } -bool DOMTokenList::validateTokens(const Vector& tokens, ExceptionCode& ec) +inline ExceptionOr DOMTokenList::addInternal(const String* newTokens, size_t length) { - for (size_t i = 0; i < tokens.size(); ++i) { - if (!validateToken(tokens[i], ec)) - return false; + // This is usually called with a single token. + Vector uniqueNewTokens; + uniqueNewTokens.reserveInitialCapacity(length); + + auto& tokens = this->tokens(); + + for (size_t i = 0; i < length; ++i) { + auto result = validateToken(newTokens[i]); + if (result.hasException()) + return result; + if (!tokens.contains(newTokens[i]) && !uniqueNewTokens.contains(newTokens[i])) + uniqueNewTokens.uncheckedAppend(newTokens[i]); } - return true; + if (!uniqueNewTokens.isEmpty()) + tokens.appendVector(uniqueNewTokens); + + updateAssociatedAttributeFromTokens(); + + return { }; } -bool DOMTokenList::contains(const AtomicString& token, ExceptionCode& ec) const +ExceptionOr DOMTokenList::add(const Vector& tokens) { - if (!validateToken(token, ec)) - return false; - return containsInternal(token); + return addInternal(tokens.data(), tokens.size()); } -void DOMTokenList::add(const AtomicString& token, ExceptionCode& ec) +ExceptionOr DOMTokenList::add(const AtomicString& token) { - Vector tokens; - tokens.append(token.string()); - add(tokens, ec); + return addInternal(&token.string(), 1); } -void DOMTokenList::add(const Vector& tokens, ExceptionCode& ec) +inline ExceptionOr DOMTokenList::removeInternal(const String* tokensToRemove, size_t length) { - Vector filteredTokens; - for (size_t i = 0; i < tokens.size(); ++i) { - if (!validateToken(tokens[i], ec)) - return; - if (!containsInternal(tokens[i]) && !filteredTokens.contains(tokens[i])) - filteredTokens.append(tokens[i]); - } + auto result = validateTokens(tokensToRemove, length); + if (result.hasException()) + return result; - if (filteredTokens.isEmpty()) - return; + auto& tokens = this->tokens(); + for (size_t i = 0; i < length; ++i) + tokens.removeFirst(tokensToRemove[i]); - setValue(addTokens(value(), filteredTokens)); + updateAssociatedAttributeFromTokens(); + + return { }; } -void DOMTokenList::remove(const AtomicString& token, ExceptionCode& ec) +ExceptionOr DOMTokenList::remove(const Vector& tokens) { - Vector tokens; - tokens.append(token.string()); - remove(tokens, ec); + return removeInternal(tokens.data(), tokens.size()); } -void DOMTokenList::remove(const Vector& tokens, ExceptionCode& ec) +ExceptionOr DOMTokenList::remove(const AtomicString& token) { - if (!validateTokens(tokens, ec)) - return; + return removeInternal(&token.string(), 1); +} - // Check using containsInternal first since it is a lot faster than going - // through the string character by character. - bool found = false; - for (size_t i = 0; i < tokens.size(); ++i) { - if (containsInternal(tokens[i])) { - found = true; - break; +ExceptionOr DOMTokenList::toggle(const AtomicString& token, std::optional force) +{ + auto result = validateToken(token); + if (result.hasException()) + return result.releaseException(); + + auto& tokens = this->tokens(); + + if (tokens.contains(token)) { + if (!force.value_or(false)) { + tokens.removeFirst(token); + updateAssociatedAttributeFromTokens(); + return false; } + return true; } - if (found) - setValue(removeTokens(value(), tokens)); -} - -bool DOMTokenList::toggle(const AtomicString& token, ExceptionCode& ec) -{ - if (!validateToken(token, ec)) + if (force && !force.value()) return false; - if (containsInternal(token)) { - removeInternal(token); - return false; - } - addInternal(token); + tokens.append(token); + updateAssociatedAttributeFromTokens(); return true; } -bool DOMTokenList::toggle(const AtomicString& token, bool force, ExceptionCode& ec) +ExceptionOr DOMTokenList::replace(const AtomicString& token, const AtomicString& newToken) { - if (!validateToken(token, ec)) - return false; + if (token.isEmpty() || newToken.isEmpty()) + return Exception { SYNTAX_ERR }; + + if (tokenContainsHTMLSpace(token) || tokenContainsHTMLSpace(newToken)) + return Exception { INVALID_CHARACTER_ERR }; - if (force) - addInternal(token); + auto& tokens = this->tokens(); + size_t index = tokens.find(token); + if (index == notFound) + return { }; + + if (tokens.find(newToken) != notFound) + tokens.remove(index); else - removeInternal(token); + tokens[index] = newToken; + + updateAssociatedAttributeFromTokens(); - return force; + return { }; } -void DOMTokenList::addInternal(const AtomicString& token) +// https://dom.spec.whatwg.org/#concept-domtokenlist-validation +ExceptionOr DOMTokenList::supports(StringView token) { - if (!containsInternal(token)) - setValue(addToken(value(), token)); + if (!m_isSupportedToken) + return Exception { TypeError }; + return m_isSupportedToken(token); } -void DOMTokenList::removeInternal(const AtomicString& token) +// https://dom.spec.whatwg.org/#dom-domtokenlist-value +const AtomicString& DOMTokenList::value() const { - // Check using contains first since it uses AtomicString comparisons instead - // of character by character testing. - if (!containsInternal(token)) - return; - setValue(removeToken(value(), token)); + return m_element.getAttribute(m_attributeName); } -String DOMTokenList::addToken(const AtomicString& input, const AtomicString& token) +void DOMTokenList::setValue(const String& value) { - Vector tokens; - tokens.append(token.string()); - return addTokens(input, tokens); + m_element.setAttribute(m_attributeName, value); } -String DOMTokenList::addTokens(const AtomicString& input, const Vector& tokens) +void DOMTokenList::updateTokensFromAttributeValue(const String& value) { - bool needsSpace = false; - - StringBuilder builder; - if (!input.isEmpty()) { - builder.append(input); - needsSpace = !isHTMLSpace(input[input.length() - 1]); - } + // Clear tokens but not capacity. + m_tokens.shrink(0); + + HashSet addedTokens; + // https://dom.spec.whatwg.org/#ordered%20sets + for (unsigned start = 0; ; ) { + while (start < value.length() && isHTMLSpace(value[start])) + ++start; + if (start >= value.length()) + break; + unsigned end = start + 1; + while (end < value.length() && !isHTMLSpace(value[end])) + ++end; + + AtomicString token = value.substring(start, end - start); + if (!addedTokens.contains(token)) { + m_tokens.append(token); + addedTokens.add(token); + } - for (size_t i = 0; i < tokens.size(); ++i) { - if (needsSpace) - builder.append(' '); - builder.append(tokens[i]); - needsSpace = true; + start = end + 1; } - return builder.toString(); + m_tokens.shrinkToFit(); + m_tokensNeedUpdating = false; } -String DOMTokenList::removeToken(const AtomicString& input, const AtomicString& token) +void DOMTokenList::associatedAttributeValueChanged(const AtomicString&) { - Vector tokens; - tokens.append(token.string()); - return removeTokens(input, tokens); + // Do not reset the DOMTokenList value if the attribute value was changed by us. + if (m_inUpdateAssociatedAttributeFromTokens) + return; + + m_tokensNeedUpdating = true; } -String DOMTokenList::removeTokens(const AtomicString& input, const Vector& tokens) +// https://dom.spec.whatwg.org/#concept-dtl-update +void DOMTokenList::updateAssociatedAttributeFromTokens() { - // Algorithm defined at http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#remove-a-token-from-a-string - // New spec is at http://dom.spec.whatwg.org/#remove-a-token-from-a-string - - unsigned inputLength = input.length(); - StringBuilder output; // 3 - output.reserveCapacity(inputLength); - unsigned position = 0; // 4 + ASSERT(!m_tokensNeedUpdating); - // Step 5 - while (position < inputLength) { - if (isHTMLSpace(input[position])) { // 6 - output.append(input[position++]); // 6.1, 6.2 - continue; // 6.3 - } - - // Step 7 - StringBuilder s; - while (position < inputLength && isNotHTMLSpace(input[position])) - s.append(input[position++]); - - // Step 8 - if (tokens.contains(s.toStringPreserveCapacity())) { - // Step 8.1 - while (position < inputLength && isHTMLSpace(input[position])) - ++position; - - // Step 8.2 - size_t j = output.length(); - while (j > 0 && isHTMLSpace(output[j - 1])) - --j; - output.resize(j); - - // Step 8.3 - if (position < inputLength && !output.isEmpty()) - output.append(' '); - } else - output.append(s.toStringPreserveCapacity()); // Step 9 + // https://dom.spec.whatwg.org/#concept-ordered-set-serializer + StringBuilder builder; + for (auto& token : tokens()) { + if (!builder.isEmpty()) + builder.append(' '); + builder.append(token); } + AtomicString serializedValue = builder.toAtomicString(); - return output.toString(); + SetForScope inAttributeUpdate(m_inUpdateAssociatedAttributeFromTokens, true); + m_element.setAttribute(m_attributeName, serializedValue); +} + +Vector& DOMTokenList::tokens() +{ + if (m_tokensNeedUpdating) + updateTokensFromAttributeValue(m_element.getAttribute(m_attributeName)); + ASSERT(!m_tokensNeedUpdating); + return m_tokens; } } // namespace WebCore diff --git a/Source/WebCore/html/DOMTokenList.h b/Source/WebCore/html/DOMTokenList.h index 7ca3efae6..53ac5e2f4 100644 --- a/Source/WebCore/html/DOMTokenList.h +++ b/Source/WebCore/html/DOMTokenList.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2010 Google Inc. All rights reserved. + * Copyright (C) 2015, 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -22,58 +23,68 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef DOMTokenList_h -#define DOMTokenList_h +#pragma once -#include -#include +#include "Element.h" namespace WebCore { -class Element; - -typedef int ExceptionCode; - class DOMTokenList { - WTF_MAKE_NONCOPYABLE(DOMTokenList); WTF_MAKE_FAST_ALLOCATED; + WTF_MAKE_FAST_ALLOCATED; public: - DOMTokenList() { } - virtual ~DOMTokenList() {}; + DOMTokenList(Element&, const QualifiedName& attributeName, WTF::Function&& isSupportedToken = { }); + + void associatedAttributeValueChanged(const AtomicString&); + + void ref() { m_element.ref(); } + void deref() { m_element.deref(); } - virtual void ref() = 0; - virtual void deref() = 0; + unsigned length() const; + const AtomicString& item(unsigned index) const; - virtual unsigned length() const = 0; - virtual const AtomicString item(unsigned index) const = 0; + WEBCORE_EXPORT bool contains(const AtomicString&) const; + ExceptionOr add(const Vector&); + ExceptionOr add(const AtomicString&); + ExceptionOr remove(const Vector&); + ExceptionOr remove(const AtomicString&); + WEBCORE_EXPORT ExceptionOr toggle(const AtomicString&, std::optional force); + ExceptionOr replace(const AtomicString& token, const AtomicString& newToken); + ExceptionOr supports(StringView token); - bool contains(const AtomicString&, ExceptionCode&) const; - void add(const Vector&, ExceptionCode&); - void add(const AtomicString&, ExceptionCode&); - void remove(const Vector&, ExceptionCode&); - void remove(const AtomicString&, ExceptionCode&); - bool toggle(const AtomicString&, ExceptionCode&); - bool toggle(const AtomicString&, bool force, ExceptionCode&); + Element& element() const { return m_element; } - AtomicString toString() const { return value(); } + WEBCORE_EXPORT void setValue(const String&); + WEBCORE_EXPORT const AtomicString& value() const; - virtual Element* element() const { return 0; } +private: + void updateTokensFromAttributeValue(const String&); + void updateAssociatedAttributeFromTokens(); -protected: - virtual AtomicString value() const = 0; - virtual void setValue(const AtomicString&) = 0; + WEBCORE_EXPORT Vector& tokens(); + const Vector& tokens() const { return const_cast(*this).tokens(); } - void addInternal(const AtomicString&); - virtual bool containsInternal(const AtomicString&) const = 0; - void removeInternal(const AtomicString&); + static ExceptionOr validateToken(const String&); + static ExceptionOr validateTokens(const String* tokens, size_t length); + ExceptionOr addInternal(const String* tokens, size_t length); + ExceptionOr removeInternal(const String* tokens, size_t length); - static bool validateToken(const AtomicString&, ExceptionCode&); - static bool validateTokens(const Vector&, ExceptionCode&); - static String addToken(const AtomicString&, const AtomicString&); - static String addTokens(const AtomicString&, const Vector&); - static String removeToken(const AtomicString&, const AtomicString&); - static String removeTokens(const AtomicString&, const Vector&); + Element& m_element; + const WebCore::QualifiedName& m_attributeName; + bool m_inUpdateAssociatedAttributeFromTokens { false }; + bool m_tokensNeedUpdating { true }; + Vector m_tokens; + WTF::Function m_isSupportedToken; }; -} // namespace WebCore +inline unsigned DOMTokenList::length() const +{ + return tokens().size(); +} + +inline const AtomicString& DOMTokenList::item(unsigned index) const +{ + auto& tokens = this->tokens(); + return index < tokens.size() ? tokens[index] : nullAtom; +} -#endif // DOMTokenList_h +} // namespace WebCore diff --git a/Source/WebCore/html/DOMTokenList.idl b/Source/WebCore/html/DOMTokenList.idl index d7ace2e84..db99e93be 100644 --- a/Source/WebCore/html/DOMTokenList.idl +++ b/Source/WebCore/html/DOMTokenList.idl @@ -1,5 +1,6 @@ /* * Copyright (C) 2010, Google Inc. All rights reserved. + * Copyright (C) 2016, Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,14 +28,15 @@ SkipVTableValidation, ] interface DOMTokenList { readonly attribute unsigned long length; - [TreatReturnedNullStringAs=Null] getter DOMString item(unsigned long index); - [RaisesException] boolean contains(DOMString token); - [RaisesException] void add(DOMString... tokens); - [RaisesException] void remove(DOMString... tokens); - [RaisesException] boolean toggle(DOMString token, optional boolean force); + getter DOMString? item(unsigned long index); + boolean contains(DOMString token); + [CEReactions, MayThrowException] void add(DOMString... tokens); + [CEReactions, MayThrowException] void remove(DOMString... tokens); + [CEReactions, MayThrowException] boolean toggle(DOMString token, optional boolean force); + [CEReactions, MayThrowException] void replace(DOMString token, DOMString newToken); + [MayThrowException] boolean supports(DOMString token); -#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT - [NotEnumerable] DOMString toString(); -#endif -}; + iterable; + [CEReactions] stringifier attribute DOMString value; +}; diff --git a/Source/WebCore/html/DOMURL.cpp b/Source/WebCore/html/DOMURL.cpp index 3d65fc51c..1a5cd62ec 100644 --- a/Source/WebCore/html/DOMURL.cpp +++ b/Source/WebCore/html/DOMURL.cpp @@ -1,80 +1,130 @@ /* + * Copyright (C) 1999 Lars Knoll (knoll@kde.org) + * (C) 1999 Antti Koivisto (koivisto@kde.org) + * (C) 2000 Simon Hausmann + * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010, 2014 Apple Inc. All rights reserved. + * (C) 2006 Graham Dennis (graham.dennis@gmail.com) * Copyright (C) 2011 Google Inc. All rights reserved. * Copyright (C) 2012 Motorola Mobility Inc. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. */ #include "config.h" - -#if ENABLE(BLOB) - #include "DOMURL.h" #include "ActiveDOMObject.h" #include "Blob.h" #include "BlobURL.h" +#include "ExceptionCode.h" #include "MemoryCache.h" #include "PublicURLManager.h" #include "ResourceRequest.h" #include "ScriptExecutionContext.h" #include "SecurityOrigin.h" +#include "URLSearchParams.h" #include namespace WebCore { -String DOMURL::createObjectURL(ScriptExecutionContext* scriptExecutionContext, Blob* blob) +inline DOMURL::DOMURL(URL&& completeURL, URL&& baseURL) + : m_baseURL(WTFMove(baseURL)) + , m_url(WTFMove(completeURL)) +{ +} + +ExceptionOr> DOMURL::create(const String& url, const String& base) +{ + URL baseURL { URL { }, base }; + if (!baseURL.isValid()) + return Exception { TypeError }; + URL completeURL { baseURL, url }; + if (!completeURL.isValid()) + return Exception { TypeError }; + return adoptRef(*new DOMURL(WTFMove(completeURL), WTFMove(baseURL))); +} + +ExceptionOr> DOMURL::create(const String& url, const DOMURL& base) +{ + return create(url, base.href()); +} + +ExceptionOr> DOMURL::create(const String& url) +{ + URL baseURL { blankURL() }; + URL completeURL { baseURL, url }; + if (!completeURL.isValid()) + return Exception { TypeError }; + return adoptRef(*new DOMURL(WTFMove(completeURL), WTFMove(baseURL))); +} + +DOMURL::~DOMURL() +{ + if (m_searchParams) + m_searchParams->associatedURLDestroyed(); +} + +ExceptionOr DOMURL::setHref(const String& url) +{ + URL completeURL { m_baseURL, url }; + if (!completeURL.isValid()) + return Exception { TypeError }; + m_url = WTFMove(completeURL); + if (m_searchParams) + m_searchParams->updateFromAssociatedURL(); + return { }; +} + +void DOMURL::setQuery(const String& query) +{ + m_url.setQuery(query); +} + +String DOMURL::createObjectURL(ScriptExecutionContext& scriptExecutionContext, Blob& blob) { - if (!scriptExecutionContext || !blob) - return String(); return createPublicURL(scriptExecutionContext, blob); } -String DOMURL::createPublicURL(ScriptExecutionContext* scriptExecutionContext, URLRegistrable* registrable) +String DOMURL::createPublicURL(ScriptExecutionContext& scriptExecutionContext, URLRegistrable& registrable) { - URL publicURL = BlobURL::createPublicURL(scriptExecutionContext->securityOrigin()); + URL publicURL = BlobURL::createPublicURL(scriptExecutionContext.securityOrigin()); if (publicURL.isEmpty()) return String(); - scriptExecutionContext->publicURLManager().registerURL(scriptExecutionContext->securityOrigin(), publicURL, registrable); + scriptExecutionContext.publicURLManager().registerURL(scriptExecutionContext.securityOrigin(), publicURL, registrable); return publicURL.string(); } -void DOMURL::revokeObjectURL(ScriptExecutionContext* scriptExecutionContext, const String& urlString) +URLSearchParams& DOMURL::searchParams() +{ + if (!m_searchParams) + m_searchParams = URLSearchParams::create(search(), this); + return *m_searchParams; +} + +void DOMURL::revokeObjectURL(ScriptExecutionContext& scriptExecutionContext, const String& urlString) { - if (!scriptExecutionContext) - return; - URL url(URL(), urlString); ResourceRequest request(url); -#if ENABLE(CACHE_PARTITIONING) - request.setCachePartition(scriptExecutionContext->topOrigin()->cachePartition()); -#endif - MemoryCache::removeRequestFromCache(scriptExecutionContext, request); + request.setDomainForCachePartition(scriptExecutionContext.topOrigin().domainForCachePartition()); + + MemoryCache::removeRequestFromSessionCaches(scriptExecutionContext, request); - scriptExecutionContext->publicURLManager().revoke(url); + scriptExecutionContext.publicURLManager().revoke(url); } } // namespace WebCore - -#endif // ENABLE(BLOB) diff --git a/Source/WebCore/html/DOMURL.h b/Source/WebCore/html/DOMURL.h index 7d214d1cb..10a7f7070 100644 --- a/Source/WebCore/html/DOMURL.h +++ b/Source/WebCore/html/DOMURL.h @@ -24,36 +24,44 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef DOMURL_h -#define DOMURL_h +#pragma once +#include "ExceptionOr.h" #include "URL.h" +#include "URLUtils.h" #include -#include -#include -#include namespace WebCore { class Blob; class ScriptExecutionContext; class URLRegistrable; +class URLSearchParams; -class DOMURL : public RefCounted { - +class DOMURL : public RefCounted, public URLUtils { public: - static PassRefPtr create() { return adoptRef(new DOMURL); } + static ExceptionOr> create(const String& url, const String& base); + static ExceptionOr> create(const String& url, const DOMURL& base); + static ExceptionOr> create(const String& url); + ~DOMURL(); + + URL href() const { return m_url; } + ExceptionOr setHref(const String& url); + void setQuery(const String&); + + URLSearchParams& searchParams(); -#if ENABLE(BLOB) - static void contextDestroyed(ScriptExecutionContext*); + static String createObjectURL(ScriptExecutionContext&, Blob&); + static void revokeObjectURL(ScriptExecutionContext&, const String&); - static String createObjectURL(ScriptExecutionContext*, Blob*); - static void revokeObjectURL(ScriptExecutionContext*, const String&); + static String createPublicURL(ScriptExecutionContext&, URLRegistrable&); - static String createPublicURL(ScriptExecutionContext*, URLRegistrable*); -#endif +private: + DOMURL(URL&& completeURL, URL&& baseURL); + + URL m_baseURL; + URL m_url; + RefPtr m_searchParams; }; } // namespace WebCore - -#endif // DOMURL_h diff --git a/Source/WebCore/html/DOMURL.idl b/Source/WebCore/html/DOMURL.idl index db695aa89..b278f2667 100644 --- a/Source/WebCore/html/DOMURL.idl +++ b/Source/WebCore/html/DOMURL.idl @@ -25,14 +25,33 @@ */ [ - GlobalContext=DOMWindow&WorkerGlobalScope, - Constructor, + Exposed=(Window,Worker), + Constructor(USVString url), + Constructor(USVString url, USVString base), + Constructor(USVString url, DOMURL base), + ConstructorMayThrowException, JSGenerateToNativeObject, JSGenerateToJSObject, - JSNoStaticTables, InterfaceName=URL, ImplementationLacksVTable, + ExportMacro=WEBCORE_EXPORT, ] interface DOMURL { - [CallWith=ScriptExecutionContext,TreatReturnedNullStringAs=Null,Conditional=BLOB] static DOMString createObjectURL(Blob? blob); - [CallWith=ScriptExecutionContext,Conditional=BLOB] static void revokeObjectURL(DOMString url); + [SetterMayThrowException, URL] stringifier attribute USVString href; + readonly attribute USVString origin; + attribute USVString protocol; + attribute USVString username; + attribute USVString password; + attribute USVString host; + attribute USVString hostname; + attribute USVString port; + attribute USVString pathname; + attribute USVString hash; + attribute USVString search; + [CachedAttribute] readonly attribute URLSearchParams searchParams; + + USVString toJSON(); + + // https://w3c.github.io/FileAPI/#creating-revoking. + [CallWith=ScriptExecutionContext] static DOMString createObjectURL(Blob blob); + [CallWith=ScriptExecutionContext] static void revokeObjectURL(DOMString url); }; diff --git a/Source/WebCore/html/DateInputType.cpp b/Source/WebCore/html/DateInputType.cpp index 91a7bc2ec..1eb61b3f7 100644 --- a/Source/WebCore/html/DateInputType.cpp +++ b/Source/WebCore/html/DateInputType.cpp @@ -35,6 +35,7 @@ #include "HTMLInputElement.h" #include "HTMLNames.h" #include "InputTypeNames.h" +#include namespace WebCore { @@ -49,11 +50,6 @@ DateInputType::DateInputType(HTMLInputElement& element) { } -void DateInputType::attach() -{ - observeFeatureIfVisible(FeatureObserver::InputTypeDate); -} - const AtomicString& DateInputType::formControlType() const { return InputTypeNames::date(); @@ -66,13 +62,13 @@ DateComponents::Type DateInputType::dateType() const StepRange DateInputType::createStepRange(AnyStepHandling anyStepHandling) const { - DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (dateDefaultStep, dateDefaultStepBase, dateStepScaleFactor, StepRange::ParsedStepValueShouldBeInteger)); + static NeverDestroyed stepDescription(dateDefaultStep, dateDefaultStepBase, dateStepScaleFactor, StepRange::ParsedStepValueShouldBeInteger); - const Decimal stepBase = parseToNumber(element().fastGetAttribute(minAttr), 0); - const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), Decimal::fromDouble(DateComponents::minimumDate())); - const Decimal maximum = parseToNumber(element().fastGetAttribute(maxAttr), Decimal::fromDouble(DateComponents::maximumDate())); - const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element().fastGetAttribute(stepAttr)); - return StepRange(stepBase, minimum, maximum, step, stepDescription); + const Decimal stepBase = parseToNumber(element().attributeWithoutSynchronization(minAttr), 0); + const Decimal minimum = parseToNumber(element().attributeWithoutSynchronization(minAttr), Decimal::fromDouble(DateComponents::minimumDate())); + const Decimal maximum = parseToNumber(element().attributeWithoutSynchronization(maxAttr), Decimal::fromDouble(DateComponents::maximumDate())); + const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element().attributeWithoutSynchronization(stepAttr)); + return StepRange(stepBase, RangeLimitations::Valid, minimum, maximum, step, stepDescription); } bool DateInputType::parseToDateComponentsInternal(const UChar* characters, unsigned length, DateComponents* out) const diff --git a/Source/WebCore/html/DateInputType.h b/Source/WebCore/html/DateInputType.h index f14a29f4b..5be1ec3f3 100644 --- a/Source/WebCore/html/DateInputType.h +++ b/Source/WebCore/html/DateInputType.h @@ -28,29 +28,27 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef DateInputType_h -#define DateInputType_h +#pragma once #if ENABLE(INPUT_TYPE_DATE) + #include "BaseChooserOnlyDateAndTimeInputType.h" namespace WebCore { -class DateInputType : public BaseChooserOnlyDateAndTimeInputType { +class DateInputType final : public BaseChooserOnlyDateAndTimeInputType { public: explicit DateInputType(HTMLInputElement&); private: - virtual void attach() override; - virtual const AtomicString& formControlType() const override; - virtual DateComponents::Type dateType() const override; - virtual StepRange createStepRange(AnyStepHandling) const override; - virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const override; - virtual bool setMillisecondToDateComponents(double, DateComponents*) const override; - virtual bool isDateField() const override; + const AtomicString& formControlType() const override; + DateComponents::Type dateType() const override; + StepRange createStepRange(AnyStepHandling) const override; + bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const override; + bool setMillisecondToDateComponents(double, DateComponents*) const override; + bool isDateField() const override; }; } // namespace WebCore #endif -#endif // DateInputType_h diff --git a/Source/WebCore/html/DateTimeInputType.cpp b/Source/WebCore/html/DateTimeInputType.cpp index 1e7fb1ffa..47ed8ea53 100644 --- a/Source/WebCore/html/DateTimeInputType.cpp +++ b/Source/WebCore/html/DateTimeInputType.cpp @@ -36,6 +36,7 @@ #include "HTMLNames.h" #include "InputTypeNames.h" #include +#include namespace WebCore { @@ -45,11 +46,6 @@ static const int dateTimeDefaultStep = 60; static const int dateTimeDefaultStepBase = 0; static const int dateTimeStepScaleFactor = 1000; -void DateTimeInputType::attach() -{ - observeFeatureIfVisible(FeatureObserver::InputTypeDateTime); -} - const AtomicString& DateTimeInputType::formControlType() const { return InputTypeNames::datetime(); @@ -67,13 +63,13 @@ Decimal DateTimeInputType::defaultValueForStepUp() const StepRange DateTimeInputType::createStepRange(AnyStepHandling anyStepHandling) const { - DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (dateTimeDefaultStep, dateTimeDefaultStepBase, dateTimeStepScaleFactor, StepRange::ScaledStepValueShouldBeInteger)); + static NeverDestroyed stepDescription(dateTimeDefaultStep, dateTimeDefaultStepBase, dateTimeStepScaleFactor, StepRange::ScaledStepValueShouldBeInteger); - const Decimal stepBase = parseToNumber(element().fastGetAttribute(minAttr), 0); - const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), Decimal::fromDouble(DateComponents::minimumDateTime())); - const Decimal maximum = parseToNumber(element().fastGetAttribute(maxAttr), Decimal::fromDouble(DateComponents::maximumDateTime())); - const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element().fastGetAttribute(stepAttr)); - return StepRange(stepBase, minimum, maximum, step, stepDescription); + const Decimal stepBase = parseToNumber(element().attributeWithoutSynchronization(minAttr), 0); + const Decimal minimum = parseToNumber(element().attributeWithoutSynchronization(minAttr), Decimal::fromDouble(DateComponents::minimumDateTime())); + const Decimal maximum = parseToNumber(element().attributeWithoutSynchronization(maxAttr), Decimal::fromDouble(DateComponents::maximumDateTime())); + const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element().attributeWithoutSynchronization(stepAttr)); + return StepRange(stepBase, RangeLimitations::Valid, minimum, maximum, step, stepDescription); } bool DateTimeInputType::parseToDateComponentsInternal(const UChar* characters, unsigned length, DateComponents* out) const diff --git a/Source/WebCore/html/DateTimeInputType.h b/Source/WebCore/html/DateTimeInputType.h index aab26a3da..c87ac7b08 100644 --- a/Source/WebCore/html/DateTimeInputType.h +++ b/Source/WebCore/html/DateTimeInputType.h @@ -28,32 +28,30 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef DateTimeInputType_h -#define DateTimeInputType_h +#pragma once #if ENABLE(INPUT_TYPE_DATETIME_INCOMPLETE) + #include "BaseChooserOnlyDateAndTimeInputType.h" #include "BaseDateAndTimeInputType.h" namespace WebCore { -class DateTimeInputType : public BaseChooserOnlyDateAndTimeInputType { +class DateTimeInputType final : public BaseChooserOnlyDateAndTimeInputType { public: explicit DateTimeInputType(HTMLInputElement& element) : BaseDateTimeInputType(element) { } private: - virtual void attach() override; - virtual const AtomicString& formControlType() const override; - virtual DateComponents::Type dateType() const override; - virtual StepRange createStepRange(AnyStepHandling) const override; - virtual Decimal defaultValueForStepUp() const override; - virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const override; - virtual bool setMillisecondToDateComponents(double, DateComponents*) const override; - virtual bool isDateTimeField() const override; - virtual String sanitizeValue(const String&) const override; + const AtomicString& formControlType() const override; + DateComponents::Type dateType() const override; + StepRange createStepRange(AnyStepHandling) const override; + Decimal defaultValueForStepUp() const override; + bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const override; + bool setMillisecondToDateComponents(double, DateComponents*) const override; + bool isDateTimeField() const override; + String sanitizeValue(const String&) const override; }; } // namespace WebCore #endif -#endif // DateTimeInputType_h diff --git a/Source/WebCore/html/DateTimeLocalInputType.cpp b/Source/WebCore/html/DateTimeLocalInputType.cpp index 6f0f24933..bdc385783 100644 --- a/Source/WebCore/html/DateTimeLocalInputType.cpp +++ b/Source/WebCore/html/DateTimeLocalInputType.cpp @@ -29,12 +29,14 @@ */ #include "config.h" -#if ENABLE(INPUT_TYPE_DATETIMELOCAL) #include "DateTimeLocalInputType.h" +#if ENABLE(INPUT_TYPE_DATETIMELOCAL) + #include "HTMLInputElement.h" #include "HTMLNames.h" #include "InputTypeNames.h" +#include namespace WebCore { @@ -44,11 +46,6 @@ static const int dateTimeLocalDefaultStep = 60; static const int dateTimeLocalDefaultStepBase = 0; static const int dateTimeLocalStepScaleFactor = 1000; -void DateTimeLocalInputType::attach() -{ - observeFeatureIfVisible(FeatureObserver::InputTypeDateTimeLocal); -} - const AtomicString& DateTimeLocalInputType::formControlType() const { return InputTypeNames::datetimelocal(); @@ -65,21 +62,21 @@ double DateTimeLocalInputType::valueAsDate() const return DateComponents::invalidMilliseconds(); } -void DateTimeLocalInputType::setValueAsDate(double value, ExceptionCode& ec) const +ExceptionOr DateTimeLocalInputType::setValueAsDate(double value) const { // valueAsDate doesn't work for the datetime-local type according to the standard. - InputType::setValueAsDate(value, ec); + return InputType::setValueAsDate(value); } StepRange DateTimeLocalInputType::createStepRange(AnyStepHandling anyStepHandling) const { - DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (dateTimeLocalDefaultStep, dateTimeLocalDefaultStepBase, dateTimeLocalStepScaleFactor, StepRange::ScaledStepValueShouldBeInteger)); + static NeverDestroyed stepDescription(dateTimeLocalDefaultStep, dateTimeLocalDefaultStepBase, dateTimeLocalStepScaleFactor, StepRange::ScaledStepValueShouldBeInteger); - const Decimal stepBase = parseToNumber(element().fastGetAttribute(minAttr), 0); - const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), Decimal::fromDouble(DateComponents::minimumDateTime())); - const Decimal maximum = parseToNumber(element().fastGetAttribute(maxAttr), Decimal::fromDouble(DateComponents::maximumDateTime())); - const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element().fastGetAttribute(stepAttr)); - return StepRange(stepBase, minimum, maximum, step, stepDescription); + const Decimal stepBase = parseToNumber(element().attributeWithoutSynchronization(minAttr), 0); + const Decimal minimum = parseToNumber(element().attributeWithoutSynchronization(minAttr), Decimal::fromDouble(DateComponents::minimumDateTime())); + const Decimal maximum = parseToNumber(element().attributeWithoutSynchronization(maxAttr), Decimal::fromDouble(DateComponents::maximumDateTime())); + const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element().attributeWithoutSynchronization(stepAttr)); + return StepRange(stepBase, RangeLimitations::Valid, minimum, maximum, step, stepDescription); } bool DateTimeLocalInputType::parseToDateComponentsInternal(const UChar* characters, unsigned length, DateComponents* out) const diff --git a/Source/WebCore/html/DateTimeLocalInputType.h b/Source/WebCore/html/DateTimeLocalInputType.h index b1bc0490d..7a086bc9a 100644 --- a/Source/WebCore/html/DateTimeLocalInputType.h +++ b/Source/WebCore/html/DateTimeLocalInputType.h @@ -28,31 +28,29 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef DateTimeLocalInputType_h -#define DateTimeLocalInputType_h +#pragma once #if ENABLE(INPUT_TYPE_DATETIMELOCAL) + #include "BaseChooserOnlyDateAndTimeInputType.h" namespace WebCore { -class DateTimeLocalInputType : public BaseChooserOnlyDateAndTimeInputType { +class DateTimeLocalInputType final : public BaseChooserOnlyDateAndTimeInputType { public: explicit DateTimeLocalInputType(HTMLInputElement& element) : BaseChooserOnlyDateAndTimeInputType(element) { } private: - virtual void attach() override; - virtual const AtomicString& formControlType() const override; - virtual DateComponents::Type dateType() const override; - virtual double valueAsDate() const override; - virtual void setValueAsDate(double, ExceptionCode&) const override; - virtual StepRange createStepRange(AnyStepHandling) const; - virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const override; - virtual bool setMillisecondToDateComponents(double, DateComponents*) const override; - virtual bool isDateTimeLocalField() const override; + const AtomicString& formControlType() const final; + DateComponents::Type dateType() const final; + double valueAsDate() const final; + ExceptionOr setValueAsDate(double) const final; + StepRange createStepRange(AnyStepHandling) const final; + bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const final; + bool setMillisecondToDateComponents(double, DateComponents*) const final; + bool isDateTimeLocalField() const final; }; } // namespace WebCore #endif -#endif // DateTimeLocalInputType_h diff --git a/Source/WebCore/html/EmailInputType.cpp b/Source/WebCore/html/EmailInputType.cpp index 570270191..31f8aa55b 100644 --- a/Source/WebCore/html/EmailInputType.cpp +++ b/Source/WebCore/html/EmailInputType.cpp @@ -28,15 +28,14 @@ #include "HTMLParserIdioms.h" #include "InputTypeNames.h" #include "LocalizedStrings.h" +#include #include #include namespace WebCore { -static const char emailPattern[] = - "[a-z0-9!#$%&'*+/=?^_`{|}~.-]+" // local part - "@" - "[a-z0-9-]+(\\.[a-z0-9-]+)*"; // domain part +// From https://html.spec.whatwg.org/#valid-e-mail-address. +static const char emailPattern[] = "^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"; static bool isValidEmailAddress(const String& address) { @@ -44,20 +43,14 @@ static bool isValidEmailAddress(const String& address) if (!addressLength) return false; - DEFINE_STATIC_LOCAL(const JSC::Yarr::RegularExpression, regExp, (emailPattern, TextCaseInsensitive)); + static NeverDestroyed regExp(emailPattern, TextCaseInsensitive); int matchLength; - int matchOffset = regExp.match(address, 0, &matchLength); + int matchOffset = regExp.get().match(address, 0, &matchLength); return !matchOffset && matchLength == addressLength; } -void EmailInputType::attach() -{ - TextFieldInputType::attach(); - observeFeatureIfVisible(FeatureObserver::InputTypeEmail); -} - const AtomicString& EmailInputType::formControlType() const { return InputTypeNames::email(); @@ -71,8 +64,8 @@ bool EmailInputType::typeMismatchFor(const String& value) const return !isValidEmailAddress(value); Vector addresses; value.split(',', true, addresses); - for (unsigned i = 0; i < addresses.size(); ++i) { - if (!isValidEmailAddress(stripLeadingAndTrailingHTMLSpaces(addresses[i]))) + for (auto& address : addresses) { + if (!isValidEmailAddress(stripLeadingAndTrailingHTMLSpaces(address))) return true; } return false; @@ -108,7 +101,7 @@ String EmailInputType::sanitizeValue(const String& proposedValue) const StringBuilder strippedValue; for (unsigned i = 0; i < addresses.size(); ++i) { if (i > 0) - strippedValue.append(","); + strippedValue.append(','); strippedValue.append(stripLeadingAndTrailingHTMLSpaces(addresses[i])); } return strippedValue.toString(); diff --git a/Source/WebCore/html/EmailInputType.h b/Source/WebCore/html/EmailInputType.h index a0c645163..0e2fb9725 100644 --- a/Source/WebCore/html/EmailInputType.h +++ b/Source/WebCore/html/EmailInputType.h @@ -28,28 +28,24 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EmailInputType_h -#define EmailInputType_h +#pragma once #include "BaseTextInputType.h" namespace WebCore { -class EmailInputType : public BaseTextInputType { +class EmailInputType final : public BaseTextInputType { public: explicit EmailInputType(HTMLInputElement& element) : BaseTextInputType(element) { } private: - virtual void attach() override; - virtual const AtomicString& formControlType() const override; - virtual bool typeMismatchFor(const String&) const override; - virtual bool typeMismatch() const override; - virtual String typeMismatchText() const override; - virtual bool isEmailField() const override; - virtual bool supportsSelectionAPI() const override; - virtual String sanitizeValue(const String&) const override; + const AtomicString& formControlType() const override; + bool typeMismatchFor(const String&) const override; + bool typeMismatch() const override; + String typeMismatchText() const override; + bool isEmailField() const override; + bool supportsSelectionAPI() const override; + String sanitizeValue(const String&) const override; }; } // namespace WebCore - -#endif // ButtonInputType_h diff --git a/Source/WebCore/html/FTPDirectoryDocument.cpp b/Source/WebCore/html/FTPDirectoryDocument.cpp index ac29b3aef..86cb3024c 100644 --- a/Source/WebCore/html/FTPDirectoryDocument.cpp +++ b/Source/WebCore/html/FTPDirectoryDocument.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2007-2008, 2014-2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -10,10 +10,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY @@ -23,12 +23,14 @@ */ #include "config.h" -#if ENABLE(FTPDIR) #include "FTPDirectoryDocument.h" -#include "ExceptionCodePlaceholder.h" +#if ENABLE(FTPDIR) + +#include "HTMLAnchorElement.h" +#include "HTMLBodyElement.h" #include "HTMLDocumentParser.h" -#include "HTMLNames.h" +#include "HTMLTableCellElement.h" #include "HTMLTableElement.h" #include "LocalizedStrings.h" #include "Logging.h" @@ -36,10 +38,8 @@ #include "Settings.h" #include "SharedBuffer.h" #include "Text.h" -#include #include #include -#include #include namespace WebCore { @@ -48,17 +48,19 @@ using namespace HTMLNames; class FTPDirectoryDocumentParser final : public HTMLDocumentParser { public: - static PassRefPtr create(HTMLDocument& document) + static Ref create(HTMLDocument& document) { - return adoptRef(new FTPDirectoryDocumentParser(document)); + return adoptRef(*new FTPDirectoryDocumentParser(document)); } - virtual void append(PassRefPtr) override; - virtual void finish() override; +private: + void append(RefPtr&&) override; + void finish() override; - virtual bool isWaitingForScripts() const override { return false; } + // FIXME: Why do we need this? + bool isWaitingForScripts() const override { return false; } - inline void checkBuffer(int len = 10) + void checkBuffer(int len = 10) { if ((m_dest - m_buffer) > m_size - len) { // Enlarge buffer @@ -69,8 +71,7 @@ public: m_size = newSize; } } - -private: + FTPDirectoryDocumentParser(HTMLDocument&); // The parser will attempt to load the document template specified via the preference @@ -81,13 +82,13 @@ private: void parseAndAppendOneLine(const String&); void appendEntry(const String& name, const String& size, const String& date, bool isDirectory); - PassRefPtr createTDForFilename(const String&); + Ref createTDForFilename(const String&); RefPtr m_tableElement; - bool m_skipLF; + bool m_skipLF { false }; - int m_size; + int m_size { 254 }; UChar* m_buffer; UChar* m_dest; String m_carryOver; @@ -97,8 +98,6 @@ private: FTPDirectoryDocumentParser::FTPDirectoryDocumentParser(HTMLDocument& document) : HTMLDocumentParser(document) - , m_skipLF(false) - , m_size(254) , m_buffer(static_cast(fastMalloc(sizeof(UChar) * m_size))) , m_dest(m_buffer) { @@ -106,54 +105,58 @@ FTPDirectoryDocumentParser::FTPDirectoryDocumentParser(HTMLDocument& document) void FTPDirectoryDocumentParser::appendEntry(const String& filename, const String& size, const String& date, bool isDirectory) { - RefPtr rowElement = m_tableElement->insertRow(-1, IGNORE_EXCEPTION); - rowElement->setAttribute("class", "ftpDirectoryEntryRow", IGNORE_EXCEPTION); + auto& document = *this->document(); - RefPtr element = document()->createElement(tdTag, false); - element->appendChild(Text::create(*document(), String(&noBreakSpace, 1)), IGNORE_EXCEPTION); + auto rowElement = m_tableElement->insertRow(-1).releaseReturnValue(); + rowElement->setAttributeWithoutSynchronization(HTMLNames::classAttr, AtomicString("ftpDirectoryEntryRow", AtomicString::ConstructFromLiteral)); + + auto typeElement = HTMLTableCellElement::create(tdTag, document); + typeElement->appendChild(Text::create(document, String(&noBreakSpace, 1))); if (isDirectory) - element->setAttribute("class", "ftpDirectoryIcon ftpDirectoryTypeDirectory", IGNORE_EXCEPTION); + typeElement->setAttributeWithoutSynchronization(HTMLNames::classAttr, AtomicString("ftpDirectoryIcon ftpDirectoryTypeDirectory", AtomicString::ConstructFromLiteral)); else - element->setAttribute("class", "ftpDirectoryIcon ftpDirectoryTypeFile", IGNORE_EXCEPTION); - rowElement->appendChild(element, IGNORE_EXCEPTION); - - element = createTDForFilename(filename); - element->setAttribute("class", "ftpDirectoryFileName", IGNORE_EXCEPTION); - rowElement->appendChild(element, IGNORE_EXCEPTION); - - element = document()->createElement(tdTag, false); - element->appendChild(Text::create(*document(), date), IGNORE_EXCEPTION); - element->setAttribute("class", "ftpDirectoryFileDate", IGNORE_EXCEPTION); - rowElement->appendChild(element, IGNORE_EXCEPTION); - - element = document()->createElement(tdTag, false); - element->appendChild(Text::create(*document(), size), IGNORE_EXCEPTION); - element->setAttribute("class", "ftpDirectoryFileSize", IGNORE_EXCEPTION); - rowElement->appendChild(element, IGNORE_EXCEPTION); + typeElement->setAttributeWithoutSynchronization(HTMLNames::classAttr, AtomicString("ftpDirectoryIcon ftpDirectoryTypeFile", AtomicString::ConstructFromLiteral)); + rowElement->appendChild(typeElement); + + auto nameElement = createTDForFilename(filename); + nameElement->setAttributeWithoutSynchronization(HTMLNames::classAttr, AtomicString("ftpDirectoryFileName", AtomicString::ConstructFromLiteral)); + rowElement->appendChild(nameElement); + + auto dateElement = HTMLTableCellElement::create(tdTag, document); + dateElement->appendChild(Text::create(document, date)); + dateElement->setAttributeWithoutSynchronization(HTMLNames::classAttr, AtomicString("ftpDirectoryFileDate", AtomicString::ConstructFromLiteral)); + rowElement->appendChild(dateElement); + + auto sizeElement = HTMLTableCellElement::create(tdTag, document); + sizeElement->appendChild(Text::create(document, size)); + sizeElement->setAttributeWithoutSynchronization(HTMLNames::classAttr, AtomicString("ftpDirectoryFileSize", AtomicString::ConstructFromLiteral)); + rowElement->appendChild(sizeElement); } -PassRefPtr FTPDirectoryDocumentParser::createTDForFilename(const String& filename) +Ref FTPDirectoryDocumentParser::createTDForFilename(const String& filename) { - String fullURL = document()->baseURL().string(); - if (fullURL[fullURL.length() - 1] == '/') - fullURL.append(filename); + auto& document = *this->document(); + + String fullURL = document.baseURL().string(); + if (fullURL.endsWith('/')) + fullURL = fullURL + filename; else - fullURL.append("/" + filename); + fullURL = fullURL + '/' + filename; - RefPtr anchorElement = document()->createElement(aTag, false); - anchorElement->setAttribute("href", fullURL, IGNORE_EXCEPTION); - anchorElement->appendChild(Text::create(*document(), filename), IGNORE_EXCEPTION); + auto anchorElement = HTMLAnchorElement::create(document); + anchorElement->setAttributeWithoutSynchronization(HTMLNames::hrefAttr, fullURL); + anchorElement->appendChild(Text::create(document, filename)); - RefPtr tdElement = document()->createElement(tdTag, false); - tdElement->appendChild(anchorElement, IGNORE_EXCEPTION); + auto tdElement = HTMLTableCellElement::create(tdTag, document); + tdElement->appendChild(anchorElement); - return tdElement.release(); + return WTFMove(tdElement); } static String processFilesizeString(const String& size, bool isDirectory) { if (isDirectory) - return "--"; + return ASCIILiteral("--"); bool valid; int64_t bytes = size.toUInt64(&valid); @@ -171,7 +174,7 @@ static String processFilesizeString(const String& size, bool isDirectory) static bool wasLastDayOfMonth(int year, int month, int day) { - static int lastDays[] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + static const int lastDays[] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; if (month < 0 || month > 11) return false; @@ -241,9 +244,9 @@ static String processFileDateString(const FTPTime& fileTime) String dateString; if (fileTime.tm_year > -1) - dateString = String(months[month]) + " " + String::number(fileTime.tm_mday) + ", " + String::number(fileTime.tm_year); + dateString = makeString(months[month], ' ', String::number(fileTime.tm_mday), ", ", String::number(fileTime.tm_year)); else - dateString = String(months[month]) + " " + String::number(fileTime.tm_mday) + ", " + String::number(now.year()); + dateString = makeString(months[month], ' ', String::number(fileTime.tm_mday), ", ", String::number(now.year())); return dateString + timeOfDay; } @@ -261,7 +264,7 @@ void FTPDirectoryDocumentParser::parseAndAppendOneLine(const String& inputLine) String filename(result.filename, result.filenameLength); if (result.type == FTPDirectoryEntry) { - filename.append("/"); + filename.append('/'); // We have no interest in linking to "current directory" if (filename == "./") @@ -273,22 +276,19 @@ void FTPDirectoryDocumentParser::parseAndAppendOneLine(const String& inputLine) appendEntry(filename, processFilesizeString(result.fileSize, result.type == FTPDirectoryEntry), processFileDateString(result.modifiedTime), result.type == FTPDirectoryEntry); } -static inline PassRefPtr createTemplateDocumentData(Settings* settings) +static inline RefPtr createTemplateDocumentData(const Settings& settings) { - RefPtr buffer = 0; - if (settings) - buffer = SharedBuffer::createWithContentsOfFile(settings->ftpDirectoryTemplatePath()); + RefPtr buffer = SharedBuffer::createWithContentsOfFile(settings.ftpDirectoryTemplatePath()); if (buffer) LOG(FTP, "Loaded FTPDirectoryTemplate of length %i\n", buffer->size()); - return buffer.release(); + return buffer; } bool FTPDirectoryDocumentParser::loadDocumentTemplate() { static SharedBuffer* templateDocumentData = createTemplateDocumentData(document()->settings()).leakRef(); - // FIXME: Instead of storing the data, we'd rather actually parse the template data into the template Document once, - // store that document, then "copy" it whenever we get an FTP directory listing. There are complexities with this - // approach that make it worth putting this off. + // FIXME: Instead of storing the data, it would be more efficient if we could parse the template data into the + // template Document once, store that document, then "copy" it whenever we get an FTP directory listing. if (!templateDocumentData) { LOG_ERROR("Could not load templateData"); @@ -297,30 +297,27 @@ bool FTPDirectoryDocumentParser::loadDocumentTemplate() HTMLDocumentParser::insert(String(templateDocumentData->data(), templateDocumentData->size())); - RefPtr tableElement = document()->getElementById("ftpDirectoryTable"); - if (!tableElement) + auto& document = *this->document(); + + auto* foundElement = document.getElementById(String(ASCIILiteral("ftpDirectoryTable"))); + if (!foundElement) LOG_ERROR("Unable to find element by id \"ftpDirectoryTable\" in the template document."); - else if (!isHTMLTableElement(tableElement.get())) + else if (!is(*foundElement)) LOG_ERROR("Element of id \"ftpDirectoryTable\" is not a table element"); - else - m_tableElement = toHTMLTableElement(tableElement.get()); - - // Bail if we found the table element - if (m_tableElement) + else { + m_tableElement = downcast(foundElement); return true; + } - // Otherwise create one manually - tableElement = document()->createElement(tableTag, false); - m_tableElement = toHTMLTableElement(tableElement.get()); - m_tableElement->setAttribute("id", "ftpDirectoryTable", IGNORE_EXCEPTION); + m_tableElement = HTMLTableElement::create(document); + m_tableElement->setAttributeWithoutSynchronization(HTMLNames::idAttr, AtomicString("ftpDirectoryTable", AtomicString::ConstructFromLiteral)); - // If we didn't find the table element, lets try to append our own to the body - // If that fails for some reason, cram it on the end of the document as a last - // ditch effort - if (Element* body = document()->body()) - body->appendChild(m_tableElement, IGNORE_EXCEPTION); + // If we didn't find the table element, lets try to append our own to the body. + // If that fails for some reason, cram it on the end of the document as a last ditch effort. + if (auto* body = document.bodyOrFrameset()) + body->appendChild(*m_tableElement); else - document()->appendChild(m_tableElement, IGNORE_EXCEPTION); + document.appendChild(*m_tableElement); return true; } @@ -329,23 +326,22 @@ void FTPDirectoryDocumentParser::createBasicDocument() { LOG(FTP, "Creating a basic FTP document structure as no template was loaded"); - // FIXME: Make this "basic document" more acceptable + auto& document = *this->document(); - RefPtr bodyElement = document()->createElement(bodyTag, false); + auto bodyElement = HTMLBodyElement::create(document); + document.appendChild(bodyElement); - document()->appendChild(bodyElement, IGNORE_EXCEPTION); + m_tableElement = HTMLTableElement::create(document); + m_tableElement->setAttributeWithoutSynchronization(HTMLNames::idAttr, AtomicString("ftpDirectoryTable", AtomicString::ConstructFromLiteral)); + m_tableElement->setAttribute(HTMLNames::styleAttr, AtomicString("width:100%", AtomicString::ConstructFromLiteral)); - RefPtr tableElement = document()->createElement(tableTag, false); - m_tableElement = toHTMLTableElement(tableElement.get()); - m_tableElement->setAttribute("id", "ftpDirectoryTable", IGNORE_EXCEPTION); + bodyElement->appendChild(*m_tableElement); - bodyElement->appendChild(m_tableElement, IGNORE_EXCEPTION); + document.processViewport("width=device-width", ViewportArguments::ViewportMeta); } -void FTPDirectoryDocumentParser::append(PassRefPtr inputSource) +void FTPDirectoryDocumentParser::append(RefPtr&& inputSource) { - String source(inputSource); - // Make sure we have the table element to append to by loading the template set in the pref, or // creating a very basic document with the appropriate table if (!m_tableElement) { @@ -357,9 +353,9 @@ void FTPDirectoryDocumentParser::append(PassRefPtr inputSource) bool foundNewLine = false; m_dest = m_buffer; - SegmentedString str = source; - while (!str.isEmpty()) { - UChar c = str.currentChar(); + SegmentedString string { String { WTFMove(inputSource) } }; + while (!string.isEmpty()) { + UChar c = string.currentCharacter(); if (c == '\r') { *m_dest++ = '\n'; @@ -376,7 +372,7 @@ void FTPDirectoryDocumentParser::append(PassRefPtr inputSource) m_skipLF = false; } - str.advance(); + string.advance(); // Maybe enlarge the buffer checkBuffer(); @@ -415,7 +411,7 @@ void FTPDirectoryDocumentParser::finish() m_carryOver = String(); } - m_tableElement = 0; + m_tableElement = nullptr; fastFree(m_buffer); HTMLDocumentParser::finish(); @@ -429,7 +425,7 @@ FTPDirectoryDocument::FTPDirectoryDocument(Frame* frame, const URL& url) #endif } -PassRefPtr FTPDirectoryDocument::createParser() +Ref FTPDirectoryDocument::createParser() { return FTPDirectoryDocumentParser::create(*this); } diff --git a/Source/WebCore/html/FTPDirectoryDocument.h b/Source/WebCore/html/FTPDirectoryDocument.h index 9b99fc9f0..0e07b522f 100644 --- a/Source/WebCore/html/FTPDirectoryDocument.h +++ b/Source/WebCore/html/FTPDirectoryDocument.h @@ -10,39 +10,34 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -#ifndef FTPDirectoryDocument_h -#define FTPDirectoryDocument_h + +#pragma once #include "HTMLDocument.h" namespace WebCore { - -class DOMImplementation; - -class FTPDirectoryDocument : public HTMLDocument { + +class FTPDirectoryDocument final : public HTMLDocument { public: - static PassRefPtr create(Frame* frame, const URL& url) + static Ref create(Frame* frame, const URL& url) { - return adoptRef(new FTPDirectoryDocument(frame, url)); + return adoptRef(*new FTPDirectoryDocument(frame, url)); } private: FTPDirectoryDocument(Frame*, const URL&); - virtual PassRefPtr createParser() override; + Ref createParser() override; }; - -} // namespace WebCore -#endif // FTPDirectoryDocument_h +} // namespace WebCore diff --git a/Source/WebCore/html/FileInputType.cpp b/Source/WebCore/html/FileInputType.cpp index f7ab6b73e..28b6c0661 100644 --- a/Source/WebCore/html/FileInputType.cpp +++ b/Source/WebCore/html/FileInputType.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. + * Copyright (C) 2004-2017 Apple Inc. All rights reserved. * Copyright (C) 2010 Google Inc. All rights reserved. * * This library is free software; you can redistribute it and/or @@ -24,6 +24,7 @@ #include "Chrome.h" #include "DragData.h" +#include "ElementChildIterator.h" #include "Event.h" #include "File.h" #include "FileList.h" @@ -39,48 +40,53 @@ #include "RenderFileUploadControl.h" #include "ScriptController.h" #include "ShadowRoot.h" +#include #include + +namespace WebCore { +class UploadButtonElement; +} + +SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::UploadButtonElement) + static bool isType(const WebCore::Element& element) { return element.isUploadButton(); } + static bool isType(const WebCore::Node& node) { return is(node) && isType(downcast(node)); } +SPECIALIZE_TYPE_TRAITS_END() + namespace WebCore { using namespace HTMLNames; -class UploadButtonElement : public HTMLInputElement { +class UploadButtonElement final : public HTMLInputElement { public: - static PassRefPtr create(Document&); - static PassRefPtr createForMultiple(Document&); + static Ref create(Document&); + static Ref createForMultiple(Document&); private: + bool isUploadButton() const override { return true; } + UploadButtonElement(Document&); - - virtual const AtomicString& shadowPseudoId() const override; }; -PassRefPtr UploadButtonElement::create(Document& document) +Ref UploadButtonElement::create(Document& document) { - RefPtr button = adoptRef(new UploadButtonElement(document)); - button->setType("button"); + Ref button = adoptRef(*new UploadButtonElement(document)); button->setValue(fileButtonChooseFileLabel()); - return button.release(); + return button; } -PassRefPtr UploadButtonElement::createForMultiple(Document& document) +Ref UploadButtonElement::createForMultiple(Document& document) { - RefPtr button = adoptRef(new UploadButtonElement(document)); - button->setType("button"); + Ref button = adoptRef(*new UploadButtonElement(document)); button->setValue(fileButtonChooseMultipleFilesLabel()); - return button.release(); + return button; } UploadButtonElement::UploadButtonElement(Document& document) : HTMLInputElement(inputTag, document, 0, false) { -} - -const AtomicString& UploadButtonElement::shadowPseudoId() const -{ - DEFINE_STATIC_LOCAL(AtomicString, pseudoId, ("-webkit-file-upload-button", AtomicString::ConstructFromLiteral)); - return pseudoId; + setType(AtomicString("button", AtomicString::ConstructFromLiteral)); + setPseudo(AtomicString("-webkit-file-upload-button", AtomicString::ConstructFromLiteral)); } FileInputType::FileInputType(HTMLInputElement& element) @@ -158,12 +164,12 @@ bool FileInputType::appendFormData(FormDataList& encoding, bool multipart) const // If no filename at all is entered, return successful but empty. // Null would be more logical, but Netscape posts an empty file. Argh. if (!numFiles) { - encoding.appendBlob(element().name(), File::create("")); + encoding.appendBlob(element().name(), File::create(emptyString())); return true; } for (unsigned i = 0; i < numFiles; ++i) - encoding.appendBlob(element().name(), fileList->item(i)); + encoding.appendBlob(element().name(), *fileList->item(i)); return true; } @@ -177,7 +183,7 @@ String FileInputType::valueMissingText() const return element().multiple() ? validationMessageValueMissingForMultipleFileText() : validationMessageValueMissingForFileText(); } -void FileInputType::handleDOMActivateEvent(Event* event) +void FileInputType::handleDOMActivateEvent(Event& event) { if (element().isDisabledFormControl()) return; @@ -185,32 +191,26 @@ void FileInputType::handleDOMActivateEvent(Event* event) if (!ScriptController::processingUserGesture()) return; - if (Chrome* chrome = this->chrome()) { + if (auto* chrome = this->chrome()) { FileChooserSettings settings; HTMLInputElement& input = element(); -#if ENABLE(DIRECTORY_UPLOAD) - settings.allowsDirectoryUpload = input.fastHasAttribute(webkitdirectoryAttr); - settings.allowsMultipleFiles = settings.allowsDirectoryUpload || input.fastHasAttribute(multipleAttr); -#else - settings.allowsMultipleFiles = input.fastHasAttribute(multipleAttr); -#endif + settings.allowsMultipleFiles = input.hasAttributeWithoutSynchronization(multipleAttr); settings.acceptMIMETypes = input.acceptMIMETypes(); settings.acceptFileExtensions = input.acceptFileExtensions(); settings.selectedFiles = m_fileList->paths(); #if ENABLE(MEDIA_CAPTURE) - settings.capture = input.capture(); + settings.mediaCaptureType = input.mediaCaptureType(); #endif - applyFileChooserSettings(settings); - chrome->runOpenPanel(input.document().frame(), m_fileChooser); + chrome->runOpenPanel(*input.document().frame(), *m_fileChooser); } - event->setDefaultHandled(); + event.setDefaultHandled(); } -RenderPtr FileInputType::createInputRenderer(PassRef style) +RenderPtr FileInputType::createInputRenderer(RenderStyle&& style) { - return createRenderer(element(), std::move(style)); + return createRenderer(element(), WTFMove(style)); } bool FileInputType::canSetStringValue() const @@ -218,19 +218,9 @@ bool FileInputType::canSetStringValue() const return false; } -bool FileInputType::canChangeFromAnotherType() const -{ - // Don't allow the type to be changed to file after the first type change. - // In other engines this might mean a JavaScript programmer could set a text - // field's value to something like /etc/passwd and then change it to a file input. - // I don't think this would actually occur in WebKit, but this rule still may be - // important for compatibility. - return false; -} - FileList* FileInputType::files() { - return m_fileList.get(); + return m_fileList.ptr(); } bool FileInputType::canSetValue(const String& value) @@ -261,44 +251,19 @@ bool FileInputType::getTypeSpecificValue(String& value) void FileInputType::setValue(const String&, bool, TextFieldEventBehavior) { + // FIXME: Should we clear the file list, or replace it with a new empty one here? This is observable from JavaScript through custom properties. m_fileList->clear(); - m_icon.clear(); - element().setNeedsStyleRecalc(); + m_icon = nullptr; + element().invalidateStyleForSubtree(); } -PassRefPtr FileInputType::createFileList(const Vector& files) const +Ref FileInputType::createFileList(const Vector& files) { - RefPtr fileList(FileList::create()); - size_t size = files.size(); - -#if ENABLE(DIRECTORY_UPLOAD) - // If a directory is being selected, the UI allows a directory to be chosen - // and the paths provided here share a root directory somewhere up the tree; - // we want to store only the relative paths from that point. - if (size && element().fastHasAttribute(webkitdirectoryAttr)) { - // Find the common root path. - String rootPath = directoryName(files[0].path); - for (size_t i = 1; i < size; i++) { - while (!files[i].path.startsWith(rootPath)) - rootPath = directoryName(rootPath); - } - rootPath = directoryName(rootPath); - ASSERT(rootPath.length()); - int rootLength = rootPath.length(); - if (rootPath[rootLength - 1] != '\\' && rootPath[rootLength - 1] != '/') - rootLength += 1; - for (size_t i = 0; i < size; i++) { - // Normalize backslashes to slashes before exposing the relative path to script. - String relativePath = files[i].path.substring(rootLength).replace('\\', '/'); - fileList->append(File::createWithRelativePath(files[i].path, relativePath)); - } - return fileList; - } -#endif - - for (size_t i = 0; i < size; i++) - fileList->append(File::createWithName(files[i].path, files[i].displayName, File::AllContentTypes)); - return fileList; + Vector> fileObjects; + fileObjects.reserveInitialCapacity(files.size()); + for (auto& info : files) + fileObjects.uncheckedAppend(File::createWithName(info.path, info.displayName)); + return FileList::create(WTFMove(fileObjects)); } bool FileInputType::isFileUpload() const @@ -309,46 +274,59 @@ bool FileInputType::isFileUpload() const void FileInputType::createShadowSubtree() { ASSERT(element().shadowRoot()); - element().userAgentShadowRoot()->appendChild(element().multiple() ? UploadButtonElement::createForMultiple(element().document()): UploadButtonElement::create(element().document()), IGNORE_EXCEPTION); + element().userAgentShadowRoot()->appendChild(element().multiple() ? UploadButtonElement::createForMultiple(element().document()): UploadButtonElement::create(element().document())); } void FileInputType::disabledAttributeChanged() { ASSERT(element().shadowRoot()); - UploadButtonElement* button = static_cast(element().userAgentShadowRoot()->firstChild()); - if (button) + + ShadowRoot* root = element().userAgentShadowRoot(); + if (!root) + return; + + if (auto* button = childrenOfType(*root).first()) button->setBooleanAttribute(disabledAttr, element().isDisabledFormControl()); } void FileInputType::multipleAttributeChanged() { ASSERT(element().shadowRoot()); - UploadButtonElement* button = static_cast(element().userAgentShadowRoot()->firstChild()); - if (button) + + ShadowRoot* root = element().userAgentShadowRoot(); + if (!root) + return; + + if (auto* button = childrenOfType(*root).first()) button->setValue(element().multiple() ? fileButtonChooseMultipleFilesLabel() : fileButtonChooseFileLabel()); } +#if !PLATFORM(IOS) + void FileInputType::requestIcon(const Vector& paths) { -#if PLATFORM(IOS) - UNUSED_PARAM(paths); -#else - if (!paths.size()) + if (!paths.size()) { + iconLoaded(nullptr); return; + } - Chrome* chrome = this->chrome(); - if (!chrome) + auto* chrome = this->chrome(); + if (!chrome) { + iconLoaded(nullptr); return; + } if (m_fileIconLoader) m_fileIconLoader->invalidate(); - m_fileIconLoader = std::make_unique(static_cast(*this)); + FileIconLoaderClient& client = *this; + m_fileIconLoader = std::make_unique(client); - chrome->loadIconForFiles(paths, m_fileIconLoader.get()); -#endif + chrome->loadIconForFiles(paths, *m_fileIconLoader); } +#endif + void FileInputType::applyFileChooserSettings(const FileChooserSettings& settings) { if (m_fileChooser) @@ -357,18 +335,20 @@ void FileInputType::applyFileChooserSettings(const FileChooserSettings& settings m_fileChooser = FileChooser::create(this, settings); } -void FileInputType::setFiles(PassRefPtr files) +void FileInputType::setFiles(RefPtr&& files) { if (!files) return; Ref input(element()); + unsigned length = files->length(); + bool pathsChanged = false; - if (files->length() != m_fileList->length()) + if (length != m_fileList->length()) pathsChanged = true; else { - for (unsigned i = 0; i < files->length(); ++i) { + for (unsigned i = 0; i < length; ++i) { if (files->item(i)->path() != m_fileList->item(i)->path()) { pathsChanged = true; break; @@ -376,16 +356,18 @@ void FileInputType::setFiles(PassRefPtr files) } } - m_fileList = files; + m_fileList = files.releaseNonNull(); input->setFormControlValueMatchesRenderer(true); - input->notifyFormStateChanged(); - input->setNeedsValidityCheck(); + input->updateValidity(); +#if !PLATFORM(IOS) Vector paths; - for (unsigned i = 0; i < m_fileList->length(); ++i) - paths.append(m_fileList->item(i)->path()); + paths.reserveInitialCapacity(length); + for (unsigned i = 0; i < length; ++i) + paths.uncheckedAppend(m_fileList->item(i)->path()); requestIcon(paths); +#endif if (input->renderer()) input->renderer()->repaint(); @@ -399,17 +381,19 @@ void FileInputType::setFiles(PassRefPtr files) } #if PLATFORM(IOS) + void FileInputType::filesChosen(const Vector& paths, const String& displayString, Icon* icon) { m_displayString = displayString; filesChosen(paths); - updateRendering(icon); + iconLoaded(icon); } String FileInputType::displayString() const { return m_displayString; } + #endif void FileInputType::filesChosen(const Vector& files) @@ -417,32 +401,12 @@ void FileInputType::filesChosen(const Vector& files) setFiles(createFileList(files)); } -#if ENABLE(DIRECTORY_UPLOAD) -void FileInputType::receiveDropForDirectoryUpload(const Vector& paths) -{ - Chrome* chrome = this->chrome(); - if (!chrome) - return; - - FileChooserSettings settings; - HTMLInputElement* input = element(); - settings.allowsDirectoryUpload = true; - settings.allowsMultipleFiles = true; - settings.selectedFiles.append(paths[0]); - settings.acceptMIMETypes = input->acceptMIMETypes(); - settings.acceptFileExtensions = input->acceptFileExtensions(); - - applyFileChooserSettings(settings); - chrome->enumerateChosenDirectory(m_fileChooser); -} -#endif - -void FileInputType::updateRendering(PassRefPtr icon) +void FileInputType::iconLoaded(RefPtr&& icon) { if (m_icon == icon) return; - m_icon = icon; + m_icon = WTFMove(icon); if (element().renderer()) element().renderer()->repaint(); } @@ -456,18 +420,12 @@ bool FileInputType::receiveDroppedFiles(const DragData& dragData) return false; HTMLInputElement* input = &element(); -#if ENABLE(DIRECTORY_UPLOAD) - if (input->fastHasAttribute(webkitdirectoryAttr)) { - receiveDropForDirectoryUpload(paths); - return true; - } -#endif Vector files; - for (unsigned i = 0; i < paths.size(); ++i) - files.append(FileChooserFileInfo(paths[i])); + for (auto& path : paths) + files.append(FileChooserFileInfo(path)); - if (input->fastHasAttribute(multipleAttr)) + if (input->hasAttributeWithoutSynchronization(multipleAttr)) filesChosen(files); else { Vector firstFileOnly; @@ -485,8 +443,7 @@ Icon* FileInputType::icon() const String FileInputType::defaultToolTip() const { - FileList* fileList = m_fileList.get(); - unsigned listSize = fileList->length(); + unsigned listSize = m_fileList->length(); if (!listSize) { if (element().multiple()) return fileButtonNoFilesSelectedLabel(); @@ -494,8 +451,8 @@ String FileInputType::defaultToolTip() const } StringBuilder names; - for (size_t i = 0; i < listSize; ++i) { - names.append(fileList->item(i)->name()); + for (unsigned i = 0; i < listSize; ++i) { + names.append(m_fileList->item(i)->name()); if (i != listSize - 1) names.append('\n'); } diff --git a/Source/WebCore/html/FileInputType.h b/Source/WebCore/html/FileInputType.h index 3bbad6c31..ee40648d6 100644 --- a/Source/WebCore/html/FileInputType.h +++ b/Source/WebCore/html/FileInputType.h @@ -29,8 +29,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef FileInputType_h -#define FileInputType_h +#pragma once #include "BaseClickableWithKeyInputType.h" #include "FileChooser.h" @@ -43,7 +42,7 @@ class DragData; class FileList; class Icon; -class FileInputType : public BaseClickableWithKeyInputType, private FileChooserClient, private FileIconLoaderClient { +class FileInputType final : public BaseClickableWithKeyInputType, private FileChooserClient, private FileIconLoaderClient { public: explicit FileInputType(HTMLInputElement&); virtual ~FileInputType(); @@ -51,49 +50,45 @@ public: static Vector filesFromFormControlState(const FormControlState&); private: - virtual const AtomicString& formControlType() const override; - virtual FormControlState saveFormControlState() const override; - virtual void restoreFormControlState(const FormControlState&) override; - virtual bool appendFormData(FormDataList&, bool) const override; - virtual bool valueMissing(const String&) const override; - virtual String valueMissingText() const override; - virtual void handleDOMActivateEvent(Event*) override; - virtual RenderPtr createInputRenderer(PassRef) override; - virtual bool canSetStringValue() const override; - virtual bool canChangeFromAnotherType() const override; - virtual FileList* files() override; - virtual void setFiles(PassRefPtr) override; + const AtomicString& formControlType() const final; + FormControlState saveFormControlState() const final; + void restoreFormControlState(const FormControlState&) final; + bool appendFormData(FormDataList&, bool) const final; + bool valueMissing(const String&) const final; + String valueMissingText() const final; + void handleDOMActivateEvent(Event&) final; + RenderPtr createInputRenderer(RenderStyle&&) final; + bool canSetStringValue() const final; + FileList* files() final; + void setFiles(RefPtr&&) final; #if PLATFORM(IOS) - virtual String displayString() const override; + String displayString() const final; #endif - virtual bool canSetValue(const String&) override; - virtual bool getTypeSpecificValue(String&) override; // Checked first, before internal storage or the value attribute. - virtual void setValue(const String&, bool valueChanged, TextFieldEventBehavior) override; + bool canSetValue(const String&) final; + bool getTypeSpecificValue(String&) final; // Checked first, before internal storage or the value attribute. + void setValue(const String&, bool valueChanged, TextFieldEventBehavior) final; #if ENABLE(DRAG_SUPPORT) - virtual bool receiveDroppedFiles(const DragData&) override; + bool receiveDroppedFiles(const DragData&) final; #endif - virtual Icon* icon() const override; - virtual bool isFileUpload() const override; - virtual void createShadowSubtree() override; - virtual void disabledAttributeChanged() override; - virtual void multipleAttributeChanged() override; - virtual String defaultToolTip() const override; + Icon* icon() const final; + bool isFileUpload() const final; + void createShadowSubtree() final; + void disabledAttributeChanged() final; + void multipleAttributeChanged() final; + String defaultToolTip() const final; // FileChooserClient implementation. - virtual void filesChosen(const Vector&) override; + void filesChosen(const Vector&) final; #if PLATFORM(IOS) - virtual void filesChosen(const Vector&, const String& displayString, Icon*) override; + void filesChosen(const Vector&, const String& displayString, Icon*) final; #endif // FileIconLoaderClient implementation. - virtual void updateRendering(PassRefPtr) override; + void iconLoaded(RefPtr&&) final; - PassRefPtr createFileList(const Vector& files) const; -#if ENABLE(DIRECTORY_UPLOAD) - void receiveDropForDirectoryUpload(const Vector&); -#endif + static Ref createFileList(const Vector&); void requestIcon(const Vector&); void applyFileChooserSettings(const FileChooserSettings&); @@ -103,7 +98,7 @@ private: std::unique_ptr m_fileIconLoader; #endif - RefPtr m_fileList; + Ref m_fileList; RefPtr m_icon; #if PLATFORM(IOS) String m_displayString; @@ -111,5 +106,3 @@ private: }; } // namespace WebCore - -#endif // FileInputType_h diff --git a/Source/WebCore/html/FormAssociatedElement.cpp b/Source/WebCore/html/FormAssociatedElement.cpp index 44ee0507a..0cbe029b3 100644 --- a/Source/WebCore/html/FormAssociatedElement.cpp +++ b/Source/WebCore/html/FormAssociatedElement.cpp @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2004-2016 Apple Inc. All rights reserved. * (C) 2006 Alexey Proskuryakov (ap@nypop.com) * * This library is free software; you can redistribute it and/or @@ -44,13 +44,14 @@ public: FormAttributeTargetObserver(const AtomicString& id, FormAssociatedElement&); private: - virtual void idTargetChanged() override; + void idTargetChanged() override; FormAssociatedElement& m_element; }; -FormAssociatedElement::FormAssociatedElement() +FormAssociatedElement::FormAssociatedElement(HTMLFormElement* form) : m_form(nullptr) + , m_formSetByParser(form) { } @@ -59,47 +60,67 @@ FormAssociatedElement::~FormAssociatedElement() setForm(nullptr); } -void FormAssociatedElement::didMoveToNewDocument(Document* oldDocument) +void FormAssociatedElement::didMoveToNewDocument(Document&) { HTMLElement& element = asHTMLElement(); - if (oldDocument && element.fastHasAttribute(formAttr)) + if (element.hasAttributeWithoutSynchronization(formAttr) && element.isConnected()) resetFormAttributeTargetObserver(); } void FormAssociatedElement::insertedInto(ContainerNode& insertionPoint) { - resetFormOwner(); - if (!insertionPoint.inDocument()) + HTMLElement& element = asHTMLElement(); + if (m_formSetByParser) { + // The form could have been removed by a script during parsing. + if (m_formSetByParser->isConnected()) + setForm(m_formSetByParser); + m_formSetByParser = nullptr; + } + + if (m_form && element.rootElement() != m_form->rootElement()) + setForm(nullptr); + + if (!insertionPoint.isConnected()) return; - HTMLElement& element = asHTMLElement(); - if (element.fastHasAttribute(formAttr)) + if (element.hasAttributeWithoutSynchronization(formAttr)) resetFormAttributeTargetObserver(); } +// Compute the highest ancestor instead of calling Node::rootNode in removedFrom / formRemovedFromTree +// since isConnected flag on some form associated elements may not have been updated yet. +static Node* computeRootNode(Node& node) +{ + Node* current = &node; + Node* parent = current; + while ((current = current->parentNode())) + parent = current; + return parent; +} + void FormAssociatedElement::removedFrom(ContainerNode& insertionPoint) { HTMLElement& element = asHTMLElement(); - if (insertionPoint.inDocument() && element.fastHasAttribute(formAttr)) + if (insertionPoint.isConnected() && element.hasAttributeWithoutSynchronization(formAttr)) m_formAttributeTargetObserver = nullptr; // If the form and element are both in the same tree, preserve the connection to the form. // Otherwise, null out our form and remove ourselves from the form's list of elements. - if (m_form && element.highestAncestor() != m_form->highestAncestor()) - setForm(0); + if (m_form && computeRootNode(element) != computeRootNode(*m_form)) + setForm(nullptr); } HTMLFormElement* FormAssociatedElement::findAssociatedForm(const HTMLElement* element, HTMLFormElement* currentAssociatedForm) { - const AtomicString& formId(element->fastGetAttribute(formAttr)); - if (!formId.isNull() && element->inDocument()) { + const AtomicString& formId(element->attributeWithoutSynchronization(formAttr)); + if (!formId.isNull() && element->isConnected()) { // The HTML5 spec says that the element should be associated with // the first element in the document to have an ID that equal to // the value of form attribute, so we put the result of // treeScope().getElementById() over the given element. - HTMLFormElement* newForm = 0; + HTMLFormElement* newForm = nullptr; Element* newFormCandidate = element->treeScope().getElementById(formId); - if (newFormCandidate && isHTMLFormElement(newFormCandidate)) - newForm = toHTMLFormElement(newFormCandidate); + if (is(newFormCandidate)) + newForm = downcast(newFormCandidate); return newForm; } @@ -112,8 +133,8 @@ HTMLFormElement* FormAssociatedElement::findAssociatedForm(const HTMLElement* el void FormAssociatedElement::formRemovedFromTree(const Node* formRoot) { ASSERT(m_form); - if (asHTMLElement().highestAncestor() != formRoot) - setForm(0); + if (computeRootNode(asHTMLElement()) != formRoot) + setForm(nullptr); } void FormAssociatedElement::setForm(HTMLFormElement* newForm) @@ -143,7 +164,7 @@ void FormAssociatedElement::formWillBeDestroyed() if (!m_form) return; willChangeForm(); - m_form = 0; + m_form = nullptr; didChangeForm(); } @@ -152,30 +173,30 @@ void FormAssociatedElement::resetFormOwner() HTMLFormElement* originalForm = m_form; setForm(findAssociatedForm(&asHTMLElement(), m_form)); HTMLElement& element = asHTMLElement(); - if (m_form && m_form != originalForm && m_form->inDocument()) + if (m_form && m_form != originalForm && m_form->isConnected()) element.document().didAssociateFormControl(&element); } void FormAssociatedElement::formAttributeChanged() { HTMLElement& element = asHTMLElement(); - if (!element.fastHasAttribute(formAttr)) { + if (!element.hasAttributeWithoutSynchronization(formAttr)) { // The form attribute removed. We need to reset form owner here. HTMLFormElement* originalForm = m_form; setForm(HTMLFormElement::findClosestFormAncestor(element)); - if (m_form && m_form != originalForm && m_form->inDocument()) + if (m_form && m_form != originalForm && m_form->isConnected()) element.document().didAssociateFormControl(&element); m_formAttributeTargetObserver = nullptr; } else { resetFormOwner(); - if (element.inDocument()) + if (element.isConnected()) resetFormAttributeTargetObserver(); } } bool FormAssociatedElement::customError() const { - return asHTMLElement().willValidate() && !m_customValidationMessage.isEmpty(); + return willValidate() && !m_customValidationMessage.isEmpty(); } bool FormAssociatedElement::hasBadInput() const @@ -203,6 +224,11 @@ bool FormAssociatedElement::stepMismatch() const return false; } +bool FormAssociatedElement::tooShort() const +{ + return false; +} + bool FormAssociatedElement::tooLong() const { return false; @@ -213,10 +239,10 @@ bool FormAssociatedElement::typeMismatch() const return false; } -bool FormAssociatedElement::valid() const +bool FormAssociatedElement::isValid() const { bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow() - || tooLong() || patternMismatch() || valueMissing() || hasBadInput() || customError(); + || tooShort() || tooLong() || patternMismatch() || valueMissing() || hasBadInput() || customError(); return !someError; } @@ -242,7 +268,8 @@ void FormAssociatedElement::setCustomValidity(const String& error) void FormAssociatedElement::resetFormAttributeTargetObserver() { - m_formAttributeTargetObserver = std::make_unique(asHTMLElement().fastGetAttribute(formAttr), *this); + ASSERT_WITH_SECURITY_IMPLICATION(asHTMLElement().isConnected()); + m_formAttributeTargetObserver = std::make_unique(asHTMLElement().attributeWithoutSynchronization(formAttr), *this); } void FormAssociatedElement::formAttributeTargetChanged() diff --git a/Source/WebCore/html/FormAssociatedElement.h b/Source/WebCore/html/FormAssociatedElement.h index ec9424064..66001504e 100644 --- a/Source/WebCore/html/FormAssociatedElement.h +++ b/Source/WebCore/html/FormAssociatedElement.h @@ -21,8 +21,7 @@ * */ -#ifndef FormAssociatedElement_h -#define FormAssociatedElement_h +#pragma once #include "FormNamedItem.h" #include @@ -72,27 +71,28 @@ public: bool badInput() const { return hasBadInput(); } bool customError() const; - // Implementations of patternMismatch, rangeOverflow, rangerUnderflow, stepMismatch, tooLong and valueMissing must call willValidate. + // Implementations of patternMismatch, rangeOverflow, rangerUnderflow, stepMismatch, tooShort, tooLong and valueMissing must call willValidate. virtual bool hasBadInput() const; virtual bool patternMismatch() const; virtual bool rangeOverflow() const; virtual bool rangeUnderflow() const; virtual bool stepMismatch() const; + virtual bool tooShort() const; virtual bool tooLong() const; virtual bool typeMismatch() const; virtual bool valueMissing() const; virtual String validationMessage() const; - bool valid() const; + virtual bool isValid() const; virtual void setCustomValidity(const String&); void formAttributeTargetChanged(); protected: - FormAssociatedElement(); + FormAssociatedElement(HTMLFormElement*); void insertedInto(ContainerNode&); void removedFrom(ContainerNode&); - void didMoveToNewDocument(Document* oldDocument); + void didMoveToNewDocument(Document& oldDocument); void setForm(HTMLFormElement*); void formAttributeChanged(); @@ -106,21 +106,18 @@ protected: String customValidationMessage() const; private: + virtual bool willValidate() const = 0; virtual void refFormAssociatedElement() = 0; virtual void derefFormAssociatedElement() = 0; void resetFormAttributeTargetObserver(); - virtual bool isFormAssociatedElement() const override final { return true; } + bool isFormAssociatedElement() const final { return true; } std::unique_ptr m_formAttributeTargetObserver; HTMLFormElement* m_form; + HTMLFormElement* m_formSetByParser; String m_customValidationMessage; }; -#define FORM_ASSOCIATED_ELEMENT_TYPE_CASTS(ToClassName, predicate) \ - TYPE_CASTS_BASE(ToClassName, FormAssociatedElement, element, element->predicate, element.predicate) - } // namespace - -#endif // FormAssociatedElement_h diff --git a/Source/WebCore/html/FormController.cpp b/Source/WebCore/html/FormController.cpp index 9752d3475..cb824e44c 100644 --- a/Source/WebCore/html/FormController.cpp +++ b/Source/WebCore/html/FormController.cpp @@ -23,6 +23,7 @@ #include "HTMLFormElement.h" #include "HTMLInputElement.h" +#include #include namespace WebCore { @@ -34,7 +35,7 @@ static inline HTMLFormElement* ownerFormForState(const HTMLFormControlElementWit // Assume controls with form attribute have no owners because we restore // state during parsing and form owners of such controls might be // indeterminate. - return control.fastHasAttribute(formAttr) ? 0 : control.form(); + return control.hasAttributeWithoutSynchronization(formAttr) ? 0 : control.form(); } // ---------------------------------------------------------------------------- @@ -55,8 +56,8 @@ void FormControlState::serializeTo(Vector& stateVector) const { ASSERT(!isFailure()); stateVector.append(String::number(m_values.size())); - for (size_t i = 0; i < m_values.size(); ++i) - stateVector.append(m_values[i].isNull() ? emptyString() : m_values[i]); + for (auto& value : m_values) + stateVector.append(value.isNull() ? emptyString() : value); } FormControlState FormControlState::deserialize(const Vector& stateVector, size_t& index) @@ -173,8 +174,12 @@ class SavedFormState { WTF_MAKE_FAST_ALLOCATED; public: - static OwnPtr create(); - static OwnPtr deserialize(const Vector&, size_t& index); + SavedFormState() + : m_controlStateCount(0) + { + } + + static std::unique_ptr deserialize(const Vector&, size_t& index); void serializeTo(Vector&) const; bool isEmpty() const { return m_stateForNewFormElements.isEmpty(); } void appendControlState(const AtomicString& name, const AtomicString& type, const FormControlState&); @@ -183,24 +188,17 @@ public: Vector getReferencedFilePaths() const; private: - SavedFormState() : m_controlStateCount(0) { } - typedef HashMap, FormElementKeyHash, FormElementKeyHashTraits> FormElementStateMap; FormElementStateMap m_stateForNewFormElements; size_t m_controlStateCount; }; -OwnPtr SavedFormState::create() -{ - return adoptPtr(new SavedFormState); -} - static bool isNotFormControlTypeCharacter(UChar ch) { - return ch != '-' && (ch > 'z' || ch < 'a'); + return !(ch == '-' || isASCIILower(ch)); } -OwnPtr SavedFormState::deserialize(const Vector& stateVector, size_t& index) +std::unique_ptr SavedFormState::deserialize(const Vector& stateVector, size_t& index) { if (index >= stateVector.size()) return nullptr; @@ -208,7 +206,7 @@ OwnPtr SavedFormState::deserialize(const Vector& stateVe size_t itemCount = stateVector[index++].toUInt(); if (!itemCount) return nullptr; - OwnPtr savedFormState = adoptPtr(new SavedFormState); + auto savedFormState = std::make_unique(); while (itemCount--) { if (index + 1 >= stateVector.size()) return nullptr; @@ -219,19 +217,18 @@ OwnPtr SavedFormState::deserialize(const Vector& stateVe return nullptr; savedFormState->appendControlState(name, type, state); } - return savedFormState.release(); + return savedFormState; } void SavedFormState::serializeTo(Vector& stateVector) const { stateVector.append(String::number(m_controlStateCount)); - for (FormElementStateMap::const_iterator it = m_stateForNewFormElements.begin(); it != m_stateForNewFormElements.end(); ++it) { - const FormElementKey& key = it->key; - const Deque& queue = it->value; - for (Deque::const_iterator queIterator = queue.begin(); queIterator != queue.end(); ++queIterator) { + for (auto& element : m_stateForNewFormElements) { + const FormElementKey& key = element.key; + for (auto& state : element.value) { stateVector.append(key.name()); stateVector.append(key.type()); - queIterator->serializeTo(stateVector); + state.serializeTo(stateVector); } } } @@ -268,15 +265,12 @@ FormControlState SavedFormState::takeControlState(const AtomicString& name, cons Vector SavedFormState::getReferencedFilePaths() const { Vector toReturn; - for (FormElementStateMap::const_iterator it = m_stateForNewFormElements.begin(); it != m_stateForNewFormElements.end(); ++it) { - const FormElementKey& key = it->key; - if (!equal(key.type(), "file", 4)) + for (auto& element : m_stateForNewFormElements) { + if (!equal(element.key.type(), "file", 4)) continue; - const Deque& queue = it->value; - for (Deque::const_iterator queIterator = queue.begin(); queIterator != queue.end(); ++queIterator) { - const Vector& selectedFiles = HTMLInputElement::filesFromFileInputFormControlState(*queIterator); - for (size_t i = 0; i < selectedFiles.size(); ++i) - toReturn.append(selectedFiles[i].path); + for (auto& state : element.value) { + for (auto& file : HTMLInputElement::filesFromFileInputFormControlState(state)) + toReturn.append(file.path); } } return toReturn; @@ -289,13 +283,11 @@ class FormKeyGenerator { WTF_MAKE_FAST_ALLOCATED; public: - static OwnPtr create() { return adoptPtr(new FormKeyGenerator); } + FormKeyGenerator() = default; AtomicString formKey(const HTMLFormControlElementWithState&); void willDeleteForm(HTMLFormElement*); private: - FormKeyGenerator() { } - typedef HashMap FormToKeyMap; typedef HashMap FormSignatureToNextIndexMap; FormToKeyMap m_formToKeyMap; @@ -307,7 +299,7 @@ static inline void recordFormStructure(const HTMLFormElement& form, StringBuilde // 2 is enough to distinguish forms in webkit.org/b/91209#c0 const size_t namedControlsToBeRecorded = 2; const Vector& controls = form.associatedElements(); - builder.append(" ["); + builder.appendLiteral(" ["); for (size_t i = 0, namedControls = 0; i < controls.size() && namedControls < namedControlsToBeRecorded; ++i) { if (!controls[i]->isFormControlElementWithState()) continue; @@ -319,9 +311,9 @@ static inline void recordFormStructure(const HTMLFormElement& form, StringBuilde continue; namedControls++; builder.append(name); - builder.append(" "); + builder.append(' '); } - builder.append("]"); + builder.append(']'); } static inline String formSignature(const HTMLFormElement& form) @@ -342,7 +334,7 @@ AtomicString FormKeyGenerator::formKey(const HTMLFormControlElementWithState& co { HTMLFormElement* form = ownerFormForState(control); if (!form) { - DEFINE_STATIC_LOCAL(AtomicString, formKeyForNoOwner, ("No owner", AtomicString::ConstructFromLiteral)); + static NeverDestroyed formKeyForNoOwner("No owner", AtomicString::ConstructFromLiteral); return formKeyForNoOwner; } FormToKeyMap::const_iterator it = m_formToKeyMap.find(form); @@ -395,35 +387,34 @@ static String formStateSignature() // In the legacy version of serialized state, the first item was a name // attribute value of a form control. The following string literal should // contain some characters which are rarely used for name attribute values. - DEFINE_STATIC_LOCAL(String, signature, (ASCIILiteral("\n\r?% WebKit serialized form state version 8 \n\r=&"))); + static NeverDestroyed signature(ASCIILiteral("\n\r?% WebKit serialized form state version 8 \n\r=&")); return signature; } -OwnPtr FormController::createSavedFormStateMap(const FormElementListHashSet& controlList) +std::unique_ptr FormController::createSavedFormStateMap(const FormElementListHashSet& controlList) { - OwnPtr keyGenerator = FormKeyGenerator::create(); - OwnPtr stateMap = adoptPtr(new SavedFormStateMap); - for (FormElementListHashSet::const_iterator it = controlList.begin(); it != controlList.end(); ++it) { - HTMLFormControlElementWithState* control = it->get(); + FormKeyGenerator keyGenerator; + auto stateMap = std::make_unique(); + for (auto& control : controlList) { if (!control->shouldSaveAndRestoreFormControlState()) continue; - SavedFormStateMap::AddResult result = stateMap->add(keyGenerator->formKey(*control).impl(), nullptr); - if (result.isNewEntry) - result.iterator->value = SavedFormState::create(); - result.iterator->value->appendControlState(control->name(), control->type(), control->saveFormControlState()); + auto& formState = stateMap->add(keyGenerator.formKey(*control).impl(), nullptr).iterator->value; + if (!formState) + formState = std::make_unique(); + formState->appendControlState(control->name(), control->type(), control->saveFormControlState()); } - return stateMap.release(); + return stateMap; } Vector FormController::formElementsState() const { - OwnPtr stateMap = createSavedFormStateMap(m_formElementsWithState); + std::unique_ptr stateMap = createSavedFormStateMap(m_formElementsWithState); Vector stateVector; stateVector.reserveInitialCapacity(m_formElementsWithState.size() * 4); stateVector.append(formStateSignature()); - for (SavedFormStateMap::const_iterator it = stateMap->begin(); it != stateMap->end(); ++it) { - stateVector.append(it->key.get()); - it->value->serializeTo(stateVector); + for (auto& state : *stateMap) { + stateVector.append(state.key.get()); + state.value->serializeTo(stateVector); } bool hasOnlySignature = stateVector.size() == 1; if (hasOnlySignature) @@ -441,7 +432,7 @@ FormControlState FormController::takeStateForFormElement(const HTMLFormControlEl if (m_savedFormStateMap.isEmpty()) return FormControlState(); if (!m_formKeyGenerator) - m_formKeyGenerator = FormKeyGenerator::create(); + m_formKeyGenerator = std::make_unique(); SavedFormStateMap::iterator it = m_savedFormStateMap.find(m_formKeyGenerator->formKey(control).impl()); if (it == m_savedFormStateMap.end()) return FormControlState(); @@ -461,12 +452,12 @@ void FormController::formStatesFromStateVector(const Vector& stateVector while (i + 1 < stateVector.size()) { AtomicString formKey = stateVector[i++]; - OwnPtr state = SavedFormState::deserialize(stateVector, i); + auto state = SavedFormState::deserialize(stateVector, i); if (!state) { i = 0; break; } - map.add(formKey.impl(), state.release()); + map.add(formKey.impl(), WTFMove(state)); } if (i != stateVector.size()) map.clear(); @@ -494,11 +485,10 @@ void FormController::restoreControlStateFor(HTMLFormControlElementWithState& con void FormController::restoreControlStateIn(HTMLFormElement& form) { - const Vector& elements = form.associatedElements(); - for (size_t i = 0; i < elements.size(); ++i) { - if (!elements[i]->isFormControlElementWithState()) + for (auto& element : form.associatedElements()) { + if (!element->isFormControlElementWithState()) continue; - HTMLFormControlElementWithState* control = static_cast(elements[i]); + HTMLFormControlElementWithState* control = static_cast(element); if (!control->shouldSaveAndRestoreFormControlState()) continue; if (ownerFormForState(*control) != &form) @@ -514,8 +504,8 @@ Vector FormController::getReferencedFilePaths(const Vector& stat Vector toReturn; SavedFormStateMap map; formStatesFromStateVector(stateVector, map); - for (SavedFormStateMap::const_iterator it = map.begin(), end = map.end(); it != end; ++it) - toReturn.appendVector(it->value->getReferencedFilePaths()); + for (auto& state : map.values()) + toReturn.appendVector(state->getReferencedFilePaths()); return toReturn; } diff --git a/Source/WebCore/html/FormController.h b/Source/WebCore/html/FormController.h index e146b64f6..92ad0e672 100644 --- a/Source/WebCore/html/FormController.h +++ b/Source/WebCore/html/FormController.h @@ -19,10 +19,9 @@ * */ -#ifndef FormController_h -#define FormController_h +#pragma once -#include "CheckedRadioButtons.h" +#include "RadioButtonGroups.h" #include #include #include @@ -74,13 +73,10 @@ inline void FormControlState::append(const String& value) class FormController { WTF_MAKE_FAST_ALLOCATED; public: - static OwnPtr create() - { - return adoptPtr(new FormController); - } + FormController(); ~FormController(); - CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; } + RadioButtonGroups& radioButtonGroups() { return m_radioButtonGroups; } void registerFormElementWithState(HTMLFormControlElementWithState*); void unregisterFormElementWithState(HTMLFormControlElementWithState*); @@ -95,22 +91,20 @@ public: void restoreControlStateFor(HTMLFormControlElementWithState&); void restoreControlStateIn(HTMLFormElement&); - static Vector getReferencedFilePaths(const Vector& stateVector); + WEBCORE_EXPORT static Vector getReferencedFilePaths(const Vector& stateVector); private: - typedef ListHashSet, 64> FormElementListHashSet; - typedef HashMap, OwnPtr> SavedFormStateMap; + typedef ListHashSet> FormElementListHashSet; + typedef HashMap, std::unique_ptr> SavedFormStateMap; - FormController(); - static OwnPtr createSavedFormStateMap(const FormElementListHashSet&); + static std::unique_ptr createSavedFormStateMap(const FormElementListHashSet&); FormControlState takeStateForFormElement(const HTMLFormControlElementWithState&); static void formStatesFromStateVector(const Vector&, SavedFormStateMap&); - CheckedRadioButtons m_checkedRadioButtons; + RadioButtonGroups m_radioButtonGroups; FormElementListHashSet m_formElementsWithState; SavedFormStateMap m_savedFormStateMap; - OwnPtr m_formKeyGenerator; + std::unique_ptr m_formKeyGenerator; }; } // namespace WebCore -#endif diff --git a/Source/WebCore/html/FormDataList.cpp b/Source/WebCore/html/FormDataList.cpp index 48fc62969..644faf721 100644 --- a/Source/WebCore/html/FormDataList.cpp +++ b/Source/WebCore/html/FormDataList.cpp @@ -22,6 +22,7 @@ #include "FormDataList.h" #include "LineEnding.h" +#include namespace WebCore { @@ -32,7 +33,7 @@ FormDataList::FormDataList(const TextEncoding& c) void FormDataList::appendString(const String& s) { - CString cstr = m_encoding.encode(s.deprecatedCharacters(), s.length(), EntitiesForUnencodables); + CString cstr = m_encoding.encode(s, EntitiesForUnencodables); m_items.append(normalizeLineEndingsToCRLF(cstr)); } @@ -41,9 +42,9 @@ void FormDataList::appendString(const CString& s) m_items.append(s); } -void FormDataList::appendBlob(PassRefPtr blob, const String& filename) +void FormDataList::appendBlob(Ref&& blob, const String& filename) { - m_items.append(Item(blob, filename)); + m_items.append(Item(WTFMove(blob), filename)); } } // namespace diff --git a/Source/WebCore/html/FormDataList.h b/Source/WebCore/html/FormDataList.h index 24f544990..aa2c2974b 100644 --- a/Source/WebCore/html/FormDataList.h +++ b/Source/WebCore/html/FormDataList.h @@ -18,8 +18,7 @@ * */ -#ifndef FormDataList_h -#define FormDataList_h +#pragma once #include "Blob.h" #include "TextEncoding.h" @@ -34,7 +33,10 @@ public: public: Item() { } Item(const WTF::CString& data) : m_data(data) { } - Item(PassRefPtr blob, const String& filename) : m_blob(blob), m_filename(filename) { } + Item(Ref&& blob, const String& filename) + : m_blob(WTFMove(blob)) + , m_filename(filename) + { } const WTF::CString& data() const { return m_data; } Blob* blob() const { return m_blob.get(); } @@ -63,10 +65,10 @@ public: appendString(key); appendString(String::number(value)); } - void appendBlob(const String& key, PassRefPtr blob, const String& filename = String()) + void appendBlob(const String& key, Ref&& blob, const String& filename = String()) { appendString(key); - appendBlob(blob, filename); + appendBlob(WTFMove(blob), filename); } const Vector& items() const { return m_items; } @@ -75,12 +77,10 @@ public: private: void appendString(const CString&); void appendString(const String&); - void appendBlob(PassRefPtr, const String& filename); + void appendBlob(Ref&&, const String& filename); TextEncoding m_encoding; Vector m_items; }; } // namespace WebCore - -#endif // FormDataList_h diff --git a/Source/WebCore/html/FormNamedItem.h b/Source/WebCore/html/FormNamedItem.h index 0e2cef24e..44184617b 100644 --- a/Source/WebCore/html/FormNamedItem.h +++ b/Source/WebCore/html/FormNamedItem.h @@ -18,8 +18,7 @@ * */ -#ifndef FormNamedItem_h -#define FormNamedItem_h +#pragma once namespace WebCore { @@ -33,6 +32,4 @@ public: virtual bool isFormAssociatedElement() const = 0; }; -} - -#endif /* FormNamedItem_h */ +} // namespace WebCore diff --git a/Source/WebCore/html/GenericCachedHTMLCollection.cpp b/Source/WebCore/html/GenericCachedHTMLCollection.cpp new file mode 100644 index 000000000..83052ecf8 --- /dev/null +++ b/Source/WebCore/html/GenericCachedHTMLCollection.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "GenericCachedHTMLCollection.h" + +#include "HTMLAppletElement.h" +#include "HTMLNames.h" +#include "HTMLObjectElement.h" +#include "HTMLOptionElement.h" + +namespace WebCore { + +using namespace HTMLNames; + +template +bool GenericCachedHTMLCollection::elementMatches(Element& element) const +{ + switch (this->type()) { + case NodeChildren: + return true; + case DocImages: + return element.hasTagName(imgTag); + case DocScripts: + return element.hasTagName(scriptTag); + case DocForms: + return element.hasTagName(formTag); + case TableTBodies: + return element.hasTagName(tbodyTag); + case TRCells: + return element.hasTagName(tdTag) || element.hasTagName(thTag); + case TSectionRows: + return element.hasTagName(trTag); + case SelectedOptions: + return is(element) && downcast(element).selected(); + case DataListOptions: + if (is(element)) { + HTMLOptionElement& option = downcast(element); + if (!option.isDisabledFormControl() && !option.value().isEmpty()) + return true; + } + return false; + case MapAreas: + return element.hasTagName(areaTag); + case DocApplets: + return is(element) || (is(element) && downcast(element).containsJavaApplet()); + case DocEmbeds: + return element.hasTagName(embedTag); + case DocLinks: + return (element.hasTagName(aTag) || element.hasTagName(areaTag)) && element.hasAttributeWithoutSynchronization(hrefAttr); + case DocAnchors: + return element.hasTagName(aTag) && element.hasAttributeWithoutSynchronization(nameAttr); + case ByClass: + case ByTag: + case ByHTMLTag: + case AllDescendants: + case DocAll: + case DocumentNamedItems: + case FormControls: + case SelectOptions: + case TableRows: + case WindowNamedItems: + break; + } + // Remaining collection types have their own CachedHTMLCollection subclasses and are not using GenericCachedHTMLCollection. + ASSERT_NOT_REACHED(); + return false; +} +template bool GenericCachedHTMLCollection::elementMatches(Element&) const; +template bool GenericCachedHTMLCollection::elementMatches(Element&) const; + +} // namespace WebCore diff --git a/Source/WebCore/html/GenericCachedHTMLCollection.h b/Source/WebCore/html/GenericCachedHTMLCollection.h new file mode 100644 index 000000000..56e83d907 --- /dev/null +++ b/Source/WebCore/html/GenericCachedHTMLCollection.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include "CachedHTMLCollection.h" + +namespace WebCore { + +template +class GenericCachedHTMLCollection final : public CachedHTMLCollection, traversalType> { +public: + static Ref create(ContainerNode& base, CollectionType collectionType) + { + return adoptRef(*new GenericCachedHTMLCollection(base, collectionType)); + } + + bool elementMatches(Element&) const; + +private: + GenericCachedHTMLCollection(ContainerNode& base, CollectionType collectionType) + : CachedHTMLCollection, traversalType>(base, collectionType) + { } +}; + +} // namespace WebCore diff --git a/Source/WebCore/html/HTMLAllCollection.cpp b/Source/WebCore/html/HTMLAllCollection.cpp index 1812ab176..13d8de770 100644 --- a/Source/WebCore/html/HTMLAllCollection.cpp +++ b/Source/WebCore/html/HTMLAllCollection.cpp @@ -30,36 +30,41 @@ namespace WebCore { -PassRef HTMLAllCollection::create(Document& document, CollectionType type) +Ref HTMLAllCollection::create(Document& document, CollectionType type) { return adoptRef(*new HTMLAllCollection(document, type)); } -HTMLAllCollection::HTMLAllCollection(Document& document, CollectionType type) - : HTMLCollection(document, type) +inline HTMLAllCollection::HTMLAllCollection(Document& document, CollectionType type) + : AllDescendantsCollection(document, type) { } -HTMLAllCollection::~HTMLAllCollection() +Element* HTMLAllCollection::namedItemWithIndex(const AtomicString& name, unsigned index) const { -} - -Node* HTMLAllCollection::namedItemWithIndex(const AtomicString& name, unsigned index) const -{ - updateNameCache(); + updateNamedElementCache(); + const CollectionNamedElementCache& cache = namedItemCaches(); - if (Vector* cache = idCache(name)) { - if (index < cache->size()) - return cache->at(index); - index -= cache->size(); + if (const Vector* elements = cache.findElementsWithId(name)) { + if (index < elements->size()) + return elements->at(index); + index -= elements->size(); } - if (Vector* cache = nameCache(name)) { - if (index < cache->size()) - return cache->at(index); + if (const Vector* elements = cache.findElementsWithName(name)) { + if (index < elements->size()) + return elements->at(index); } - return 0; + return nullptr; +} + +RefPtr HTMLAllCollection::tags(const String& name) +{ + if (name.isNull()) + return nullptr; + + return ownerNode().getElementsByTagName(name); } } // namespace WebCore diff --git a/Source/WebCore/html/HTMLAllCollection.h b/Source/WebCore/html/HTMLAllCollection.h index 6c93aea72..09249949d 100644 --- a/Source/WebCore/html/HTMLAllCollection.h +++ b/Source/WebCore/html/HTMLAllCollection.h @@ -23,19 +23,18 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef HTMLAllCollection_h -#define HTMLAllCollection_h +#pragma once -#include "HTMLCollection.h" +#include "AllDescendantsCollection.h" namespace WebCore { -class HTMLAllCollection final : public HTMLCollection { +class HTMLAllCollection final : public AllDescendantsCollection { public: - static PassRef create(Document&, CollectionType); - virtual ~HTMLAllCollection(); + static Ref create(Document&, CollectionType); - Node* namedItemWithIndex(const AtomicString& name, unsigned index) const; + Element* namedItemWithIndex(const AtomicString& name, unsigned index) const; + RefPtr tags(const String&); private: HTMLAllCollection(Document&, CollectionType); @@ -43,4 +42,4 @@ private: } // namespace WebCore -#endif // HTMLAllCollection_h +SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(HTMLAllCollection, DocAll) diff --git a/Source/WebCore/html/HTMLAllCollection.idl b/Source/WebCore/html/HTMLAllCollection.idl index a8e4434eb..eb35047e7 100644 --- a/Source/WebCore/html/HTMLAllCollection.idl +++ b/Source/WebCore/html/HTMLAllCollection.idl @@ -25,13 +25,18 @@ [ CustomCall, + CustomNamedGetter, + LegacyUnenumerableNamedProperties, MasqueradesAsUndefined, GenerateIsReachable=ImplOwnerNodeRoot, ] interface HTMLAllCollection { readonly attribute unsigned long length; - [Custom] getter Node item([Default=Undefined] optional unsigned long index); - [Custom] getter Node namedItem(DOMString name); - // FIXME: This should return an HTMLAllCollection. + + [Custom] getter Element? item(unsigned long index); + [Custom] getter (HTMLCollection or Element)? namedItem(DOMString name); + // [Custom] legacycaller (HTMLCollection or Element)? item(optional DOMString nameOrIndex); + + // FIXME: This is not in the standard. Can we remove it? NodeList tags(DOMString name); }; diff --git a/Source/WebCore/html/HTMLAnchorElement.cpp b/Source/WebCore/html/HTMLAnchorElement.cpp index 053e57f7f..e39950806 100644 --- a/Source/WebCore/html/HTMLAnchorElement.cpp +++ b/Source/WebCore/html/HTMLAnchorElement.cpp @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann - * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. + * Copyright (C) 2003-2016 Apple Inc. All rights reserved. * (C) 2006 Graham Dennis (graham.dennis@gmail.com) * * This library is free software; you can redistribute it and/or @@ -24,8 +24,8 @@ #include "config.h" #include "HTMLAnchorElement.h" -#include "Attribute.h" -#include "DNS.h" +#include "DOMTokenList.h" +#include "ElementIterator.h" #include "EventHandler.h" #include "EventNames.h" #include "Frame.h" @@ -33,6 +33,7 @@ #include "FrameLoaderClient.h" #include "FrameLoaderTypes.h" #include "FrameSelection.h" +#include "HTMLCanvasElement.h" #include "HTMLImageElement.h" #include "HTMLParserIdioms.h" #include "KeyboardEvent.h" @@ -41,10 +42,13 @@ #include "PlatformMouseEvent.h" #include "RenderImage.h" #include "ResourceRequest.h" +#include "RuntimeEnabledFeatures.h" #include "SVGImage.h" +#include "ScriptController.h" #include "SecurityOrigin.h" #include "SecurityPolicy.h" #include "Settings.h" +#include "URLUtils.h" #include namespace WebCore { @@ -55,19 +59,18 @@ HTMLAnchorElement::HTMLAnchorElement(const QualifiedName& tagName, Document& doc : HTMLElement(tagName, document) , m_hasRootEditableElementForSelectionOnMouseDown(false) , m_wasShiftKeyDownOnMouseDown(false) - , m_linkRelations(0) , m_cachedVisitedLinkHash(0) { } -PassRefPtr HTMLAnchorElement::create(Document& document) +Ref HTMLAnchorElement::create(Document& document) { - return adoptRef(new HTMLAnchorElement(aTag, document)); + return adoptRef(*new HTMLAnchorElement(aTag, document)); } -PassRefPtr HTMLAnchorElement::create(const QualifiedName& tagName, Document& document) +Ref HTMLAnchorElement::create(const QualifiedName& tagName, Document& document) { - return adoptRef(new HTMLAnchorElement(tagName, document)); + return adoptRef(*new HTMLAnchorElement(tagName, document)); } HTMLAnchorElement::~HTMLAnchorElement() @@ -75,15 +78,6 @@ HTMLAnchorElement::~HTMLAnchorElement() clearRootEditableElementForSelectionOnMouseDown(); } -// This function does not allow leading spaces before the port number. -static unsigned parsePortFromStringPosition(const String& value, unsigned portStart, unsigned& portEnd) -{ - portEnd = portStart; - while (isASCIIDigit(value[portEnd])) - ++portEnd; - return value.substring(portStart, portEnd - portStart).toUInt(); -} - bool HTMLAnchorElement::supportsFocus() const { if (hasEditableStyle()) @@ -94,12 +88,9 @@ bool HTMLAnchorElement::supportsFocus() const bool HTMLAnchorElement::isMouseFocusable() const { -#if !(PLATFORM(EFL) || PLATFORM(GTK)) // Only allow links with tabIndex or contentEditable to be mouse focusable. - // This is our rule for the Mac platform; on many other platforms we focus any link you click on. if (isLink()) return HTMLElement::supportsFocus(); -#endif return HTMLElement::isMouseFocusable(); } @@ -119,16 +110,15 @@ static bool hasNonEmptyBox(RenderBoxModelObject* renderer) // pass in 0,0 for the layout point instead of calling localToAbsolute? Vector rects; renderer->absoluteRects(rects, flooredLayoutPoint(renderer->localToAbsolute())); - size_t size = rects.size(); - for (size_t i = 0; i < size; ++i) { - if (!rects[i].isEmpty()) + for (auto& rect : rects) { + if (!rect.isEmpty()) return true; } return false; } -bool HTMLAnchorElement::isKeyboardFocusable(KeyboardEvent* event) const +bool HTMLAnchorElement::isKeyboardFocusable(KeyboardEvent& event) const { if (!isLink()) return HTMLElement::isKeyboardFocusable(event); @@ -142,51 +132,50 @@ bool HTMLAnchorElement::isKeyboardFocusable(KeyboardEvent* event) const if (!document().frame()->eventHandler().tabsToLinks(event)) return false; - if (isInCanvasSubtree()) + if (!renderer() && ancestorsOfType(*this).first()) return true; return hasNonEmptyBox(renderBoxModelObject()); } -static void appendServerMapMousePosition(StringBuilder& url, Event* event) +static void appendServerMapMousePosition(StringBuilder& url, Event& event) { - if (!event->isMouseEvent()) + if (!is(event)) return; + auto& mouseEvent = downcast(event); - ASSERT(event->target()); - Node* target = event->target()->toNode(); + ASSERT(mouseEvent.target()); + auto* target = mouseEvent.target()->toNode(); ASSERT(target); - if (!isHTMLImageElement(target)) + if (!is(*target)) return; - HTMLImageElement* imageElement = toHTMLImageElement(target); - if (!imageElement || !imageElement->isServerMap()) + auto& imageElement = downcast(*target); + if (!imageElement.isServerMap()) return; - if (!imageElement->renderer() || !imageElement->renderer()->isRenderImage()) + auto* renderer = imageElement.renderer(); + if (!is(renderer)) return; - RenderImage* renderer = toRenderImage(imageElement->renderer()); - // FIXME: This should probably pass true for useTransforms. - FloatPoint absolutePosition = renderer->absoluteToLocal(FloatPoint(static_cast(event)->pageX(), static_cast(event)->pageY())); - int x = absolutePosition.x(); - int y = absolutePosition.y(); + // FIXME: This should probably pass UseTransforms in the MapCoordinatesFlags. + auto absolutePosition = downcast(*renderer).absoluteToLocal(FloatPoint(mouseEvent.pageX(), mouseEvent.pageY())); url.append('?'); - url.appendNumber(x); + url.appendNumber(std::lround(absolutePosition.x())); url.append(','); - url.appendNumber(y); + url.appendNumber(std::lround(absolutePosition.y())); } -void HTMLAnchorElement::defaultEventHandler(Event* event) +void HTMLAnchorElement::defaultEventHandler(Event& event) { if (isLink()) { if (focused() && isEnterKeyKeydownEvent(event) && treatLinkAsLiveForEventType(NonMouseEvent)) { - event->setDefaultHandled(); - dispatchSimulatedClick(event); + event.setDefaultHandled(); + dispatchSimulatedClick(&event); return; } - if (isLinkClick(event) && treatLinkAsLiveForEventType(eventType(event))) { + if (MouseEvent::canTriggerActivationBehavior(event) && treatLinkAsLiveForEventType(eventType(event))) { handleClick(event); return; } @@ -194,10 +183,10 @@ void HTMLAnchorElement::defaultEventHandler(Event* event) if (hasEditableStyle()) { // This keeps track of the editable block that the selection was in (if it was in one) just before the link was clicked // for the LiveWhenNotFocused editable link behavior - if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast(event)->button() != RightButton && document().frame()) { - setRootEditableElementForSelectionOnMouseDown(document().frame()->selection().rootEditableElement()); - m_wasShiftKeyDownOnMouseDown = static_cast(event)->shiftKey(); - } else if (event->type() == eventNames().mouseoverEvent) { + if (event.type() == eventNames().mousedownEvent && is(event) && downcast(event).button() != RightButton && document().frame()) { + setRootEditableElementForSelectionOnMouseDown(document().frame()->selection().selection().rootEditableElement()); + m_wasShiftKeyDownOnMouseDown = downcast(event).shiftKey(); + } else if (event.type() == eventNames().mouseoverEvent) { // These are cleared on mouseover and not mouseout because their values are needed for drag events, // but drag events happen after mouse out events. clearRootEditableElementForSelectionOnMouseDown(); @@ -212,9 +201,7 @@ void HTMLAnchorElement::defaultEventHandler(Event* event) void HTMLAnchorElement::setActive(bool down, bool pause) { if (hasEditableStyle()) { - EditableLinkBehavior editableLinkBehavior = EditableLinkDefaultBehavior; - if (Settings* settings = document().settings()) - editableLinkBehavior = settings->editableLinkBehavior(); + EditableLinkBehavior editableLinkBehavior = document().settings().editableLinkBehavior(); switch (editableLinkBehavior) { default: @@ -228,7 +215,7 @@ void HTMLAnchorElement::setActive(bool down, bool pause) // Don't set the link to be active if the current selection is in the same editable block as // this link case EditableLinkLiveWhenNotFocused: - if (down && document().frame() && document().frame()->selection().rootEditableElement() == rootEditableElement()) + if (down && document().frame() && document().frame()->selection().selection().rootEditableElement() == rootEditableElement()) return; break; @@ -247,19 +234,30 @@ void HTMLAnchorElement::parseAttribute(const QualifiedName& name, const AtomicSt bool wasLink = isLink(); setIsLink(!value.isNull() && !shouldProhibitLinks(this)); if (wasLink != isLink()) - didAffectSelector(AffectedSelectorLink | AffectedSelectorVisited | AffectedSelectorEnabled); + invalidateStyleForSubtree(); if (isLink()) { String parsedURL = stripLeadingAndTrailingHTMLSpaces(value); - if (document().isDNSPrefetchEnabled()) { + if (document().isDNSPrefetchEnabled() && document().frame()) { if (protocolIsInHTTPFamily(parsedURL) || parsedURL.startsWith("//")) - prefetchDNS(document().completeURL(parsedURL).host()); + document().frame()->loader().client().prefetchDNS(document().completeURL(parsedURL).host()); } } invalidateCachedVisitedLinkHash(); } else if (name == nameAttr || name == titleAttr) { // Do nothing. - } else if (name == relAttr) - setRel(value); + } else if (name == relAttr) { + // Update HTMLAnchorElement::relList() if more rel attributes values are supported. + static NeverDestroyed noReferrer("noreferrer", AtomicString::ConstructFromLiteral); + static NeverDestroyed noOpener("noopener", AtomicString::ConstructFromLiteral); + const bool shouldFoldCase = true; + SpaceSplitString relValue(value, shouldFoldCase); + if (relValue.contains(noReferrer)) + m_linkRelations |= Relation::NoReferrer; + if (relValue.contains(noOpener)) + m_linkRelations |= Relation::NoOpener; + if (m_relList) + m_relList->associatedAttributeValueChanged(value); + } else HTMLElement::parseAttribute(name, value); } @@ -276,7 +274,6 @@ bool HTMLAnchorElement::isURLAttribute(const Attribute& attribute) const bool HTMLAnchorElement::canStartSelection() const { - // FIXME: We probably want this same behavior in SVGAElement too if (!isLink()) return HTMLElement::canStartSelection(); return hasEditableStyle(); @@ -284,34 +281,36 @@ bool HTMLAnchorElement::canStartSelection() const bool HTMLAnchorElement::draggable() const { - // Should be draggable if we have an href attribute. - const AtomicString& value = getAttribute(draggableAttr); - if (equalIgnoringCase(value, "true")) + const AtomicString& value = attributeWithoutSynchronization(draggableAttr); + if (equalLettersIgnoringASCIICase(value, "true")) return true; - if (equalIgnoringCase(value, "false")) + if (equalLettersIgnoringASCIICase(value, "false")) return false; - return hasAttribute(hrefAttr); + return hasAttributeWithoutSynchronization(hrefAttr); } URL HTMLAnchorElement::href() const { - return document().completeURL(stripLeadingAndTrailingHTMLSpaces(getAttribute(hrefAttr))); + return document().completeURL(stripLeadingAndTrailingHTMLSpaces(attributeWithoutSynchronization(hrefAttr))); } void HTMLAnchorElement::setHref(const AtomicString& value) { - setAttribute(hrefAttr, value); + setAttributeWithoutSynchronization(hrefAttr, value); } -bool HTMLAnchorElement::hasRel(uint32_t relation) const +bool HTMLAnchorElement::hasRel(Relation relation) const { - return m_linkRelations & relation; + return m_linkRelations.contains(relation); } -void HTMLAnchorElement::setRel(const String& value) +DOMTokenList& HTMLAnchorElement::relList() { - if (SpaceSplitString::spaceSplitStringContainsValue(value, "noreferrer", true)) - m_linkRelations |= RelationNoReferrer; + if (!m_relList) + m_relList = std::make_unique(*this, HTMLNames::relAttr, [](StringView token) { + return equalIgnoringASCIICase(token, "noreferrer") || equalIgnoringASCIICase(token, "noopener"); + }); + return *m_relList; } const AtomicString& HTMLAnchorElement::name() const @@ -319,7 +318,7 @@ const AtomicString& HTMLAnchorElement::name() const return getNameAttribute(); } -short HTMLAnchorElement::tabIndex() const +int HTMLAnchorElement::tabIndex() const { // Skip the supportsFocus check in HTMLElement. return Element::tabIndex(); @@ -327,181 +326,22 @@ short HTMLAnchorElement::tabIndex() const String HTMLAnchorElement::target() const { - return getAttribute(targetAttr); -} - -String HTMLAnchorElement::hash() const -{ - String fragmentIdentifier = href().fragmentIdentifier(); - if (fragmentIdentifier.isEmpty()) - return emptyString(); - return AtomicString(String("#" + fragmentIdentifier)); -} - -void HTMLAnchorElement::setHash(const String& value) -{ - URL url = href(); - if (value[0] == '#') - url.setFragmentIdentifier(value.substring(1)); - else - url.setFragmentIdentifier(value); - setHref(url.string()); -} - -String HTMLAnchorElement::host() const -{ - const URL& url = href(); - if (url.hostEnd() == url.pathStart()) - return url.host(); - if (isDefaultPortForProtocol(url.port(), url.protocol())) - return url.host(); - return url.host() + ":" + String::number(url.port()); -} - -void HTMLAnchorElement::setHost(const String& value) -{ - if (value.isEmpty()) - return; - URL url = href(); - if (!url.canSetHostOrPort()) - return; - - size_t separator = value.find(':'); - if (!separator) - return; - - if (separator == notFound) - url.setHostAndPort(value); - else { - unsigned portEnd; - unsigned port = parsePortFromStringPosition(value, separator + 1, portEnd); - if (!port) { - // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes - // specifically goes against RFC 3986 (p3.2) and - // requires setting the port to "0" if it is set to empty string. - url.setHostAndPort(value.substring(0, separator + 1) + "0"); - } else { - if (isDefaultPortForProtocol(port, url.protocol())) - url.setHostAndPort(value.substring(0, separator)); - else - url.setHostAndPort(value.substring(0, portEnd)); - } - } - setHref(url.string()); -} - -String HTMLAnchorElement::hostname() const -{ - return href().host(); -} - -void HTMLAnchorElement::setHostname(const String& value) -{ - // Before setting new value: - // Remove all leading U+002F SOLIDUS ("/") characters. - unsigned i = 0; - unsigned hostLength = value.length(); - while (value[i] == '/') - i++; - - if (i == hostLength) - return; - - URL url = href(); - if (!url.canSetHostOrPort()) - return; - - url.setHost(value.substring(i)); - setHref(url.string()); -} - -String HTMLAnchorElement::pathname() const -{ - return href().path(); -} - -void HTMLAnchorElement::setPathname(const String& value) -{ - URL url = href(); - if (!url.canSetPathname()) - return; - - if (value[0] == '/') - url.setPath(value); - else - url.setPath("/" + value); - - setHref(url.string()); -} - -String HTMLAnchorElement::port() const -{ - if (href().hasPort()) - return String::number(href().port()); - - return emptyString(); -} - -void HTMLAnchorElement::setPort(const String& value) -{ - URL url = href(); - if (!url.canSetHostOrPort()) - return; - - // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes - // specifically goes against RFC 3986 (p3.2) and - // requires setting the port to "0" if it is set to empty string. - unsigned port = value.toUInt(); - if (isDefaultPortForProtocol(port, url.protocol())) - url.removePort(); - else - url.setPort(port); - - setHref(url.string()); -} - -String HTMLAnchorElement::protocol() const -{ - return href().protocol() + ":"; -} - -void HTMLAnchorElement::setProtocol(const String& value) -{ - URL url = href(); - url.setProtocol(value); - setHref(url.string()); -} - -String HTMLAnchorElement::search() const -{ - String query = href().query(); - return query.isEmpty() ? emptyString() : "?" + query; + return attributeWithoutSynchronization(targetAttr); } String HTMLAnchorElement::origin() const { - RefPtr origin = SecurityOrigin::create(href()); - return origin->toString(); -} - -void HTMLAnchorElement::setSearch(const String& value) -{ - URL url = href(); - String newSearch = (value[0] == '?') ? value.substring(1) : value; - // Make sure that '#' in the query does not leak to the hash. - url.setQuery(newSearch.replaceWithLiteral('#', "%23")); - - setHref(url.string()); + return SecurityOrigin::create(href()).get().toString(); } String HTMLAnchorElement::text() { - return innerText(); + return textContent(); } -String HTMLAnchorElement::toString() const +void HTMLAnchorElement::setText(const String& text) { - return href().string(); + setTextContent(text); } bool HTMLAnchorElement::isLiveLink() const @@ -511,52 +351,54 @@ bool HTMLAnchorElement::isLiveLink() const void HTMLAnchorElement::sendPings(const URL& destinationURL) { - if (!hasAttribute(pingAttr) || !document().settings() || !document().settings()->hyperlinkAuditingEnabled()) + if (!document().frame()) return; - SpaceSplitString pingURLs(getAttribute(pingAttr), false); + if (!hasAttributeWithoutSynchronization(pingAttr) || !document().settings().hyperlinkAuditingEnabled()) + return; + + SpaceSplitString pingURLs(attributeWithoutSynchronization(pingAttr), false); for (unsigned i = 0; i < pingURLs.size(); i++) - PingLoader::sendPing(document().frame(), document().completeURL(pingURLs[i]), destinationURL); + PingLoader::sendPing(*document().frame(), document().completeURL(pingURLs[i]), destinationURL); } -void HTMLAnchorElement::handleClick(Event* event) +void HTMLAnchorElement::handleClick(Event& event) { - event->setDefaultHandled(); + event.setDefaultHandled(); Frame* frame = document().frame(); if (!frame) return; StringBuilder url; - url.append(stripLeadingAndTrailingHTMLSpaces(fastGetAttribute(hrefAttr))); + url.append(stripLeadingAndTrailingHTMLSpaces(attributeWithoutSynchronization(hrefAttr))); appendServerMapMousePosition(url, event); - URL kurl = document().completeURL(url.toString()); + URL completedURL = document().completeURL(url.toString()); + auto downloadAttribute = nullAtom; #if ENABLE(DOWNLOAD_ATTRIBUTE) - if (hasAttribute(downloadAttr)) { - ResourceRequest request(kurl); - - // FIXME: Why are we not calling addExtraFieldsToMainResourceRequest() if this check fails? It sets many important header fields. - if (!hasRel(RelationNoReferrer)) { - String referrer = SecurityPolicy::generateReferrerHeader(document().referrerPolicy(), kurl, frame->loader().outgoingReferrer()); - if (!referrer.isEmpty()) - request.setHTTPReferrer(referrer); - frame->loader().addExtraFieldsToMainResourceRequest(request); - } - - frame->loader().client().startDownload(request, fastGetAttribute(downloadAttr)); - } else + if (RuntimeEnabledFeatures::sharedFeatures().downloadAttributeEnabled()) { + // Ignore the download attribute completely if the href URL is cross origin. + bool isSameOrigin = completedURL.protocolIsData() || document().securityOrigin().canRequest(completedURL); + if (isSameOrigin) + downloadAttribute = attributeWithoutSynchronization(downloadAttr); + else if (hasAttributeWithoutSynchronization(downloadAttr)) + document().addConsoleMessage(MessageSource::Security, MessageLevel::Warning, "The download attribute on anchor was ignored because its href URL has a different security origin."); + } #endif - frame->loader().urlSelected(kurl, target(), event, false, false, hasRel(RelationNoReferrer) ? NeverSendReferrer : MaybeSendReferrer); - sendPings(kurl); + ShouldSendReferrer shouldSendReferrer = hasRel(Relation::NoReferrer) ? NeverSendReferrer : MaybeSendReferrer; + auto newFrameOpenerPolicy = hasRel(Relation::NoOpener) ? std::make_optional(NewFrameOpenerPolicy::Suppress) : std::nullopt; + frame->loader().urlSelected(completedURL, target(), &event, LockHistory::No, LockBackForwardList::No, shouldSendReferrer, document().shouldOpenExternalURLsPolicyToPropagate(), newFrameOpenerPolicy, downloadAttribute); + + sendPings(completedURL); } -HTMLAnchorElement::EventType HTMLAnchorElement::eventType(Event* event) +HTMLAnchorElement::EventType HTMLAnchorElement::eventType(Event& event) { - if (!event->isMouseEvent()) + if (!is(event)) return NonMouseEvent; - return static_cast(event)->shiftKey() ? MouseEventWithShiftKey : MouseEventWithoutShiftKey; + return downcast(event).shiftKey() ? MouseEventWithShiftKey : MouseEventWithoutShiftKey; } bool HTMLAnchorElement::treatLinkAsLiveForEventType(EventType eventType) const @@ -564,11 +406,7 @@ bool HTMLAnchorElement::treatLinkAsLiveForEventType(EventType eventType) const if (!hasEditableStyle()) return true; - Settings* settings = document().settings(); - if (!settings) - return true; - - switch (settings->editableLinkBehavior()) { + switch (document().settings().editableLinkBehavior()) { case EditableLinkDefaultBehavior: case EditableLinkAlwaysLive: return true; @@ -589,24 +427,14 @@ bool HTMLAnchorElement::treatLinkAsLiveForEventType(EventType eventType) const return false; } -bool isEnterKeyKeydownEvent(Event* event) +bool isEnterKeyKeydownEvent(Event& event) { - return event->type() == eventNames().keydownEvent && event->isKeyboardEvent() && static_cast(event)->keyIdentifier() == "Enter"; -} - -bool isLinkClick(Event* event) -{ - return event->type() == eventNames().clickEvent && (!event->isMouseEvent() || static_cast(event)->button() != RightButton); + return event.type() == eventNames().keydownEvent && is(event) && downcast(event).keyIdentifier() == "Enter"; } bool shouldProhibitLinks(Element* element) { -#if ENABLE(SVG) return isInSVGImage(element); -#else - UNUSED_PARAM(element); - return false; -#endif } bool HTMLAnchorElement::willRespondToMouseClickEvents() @@ -618,7 +446,7 @@ typedef HashMap> RootEditableElementMa static RootEditableElementMap& rootEditableElementMap() { - DEFINE_STATIC_LOCAL(RootEditableElementMap, map, ()); + static NeverDestroyed map; return map; } diff --git a/Source/WebCore/html/HTMLAnchorElement.h b/Source/WebCore/html/HTMLAnchorElement.h index 466916325..a7bc6099e 100644 --- a/Source/WebCore/html/HTMLAnchorElement.h +++ b/Source/WebCore/html/HTMLAnchorElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann - * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. + * Copyright (C) 2007-2016 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -21,142 +21,104 @@ * */ -#ifndef HTMLAnchorElement_h -#define HTMLAnchorElement_h +#pragma once #include "HTMLElement.h" #include "HTMLNames.h" #include "LinkHash.h" +#include "URLUtils.h" +#include namespace WebCore { +class DOMTokenList; + // Link relation bitmask values. -// FIXME: Uncomment as the various link relations are implemented. -enum { -// RelationAlternate = 0x00000001, -// RelationArchives = 0x00000002, -// RelationAuthor = 0x00000004, -// RelationBoomark = 0x00000008, -// RelationExternal = 0x00000010, -// RelationFirst = 0x00000020, -// RelationHelp = 0x00000040, -// RelationIndex = 0x00000080, -// RelationLast = 0x00000100, -// RelationLicense = 0x00000200, -// RelationNext = 0x00000400, -// RelationNoFolow = 0x00000800, - RelationNoReferrer = 0x00001000, -// RelationPrev = 0x00002000, -// RelationSearch = 0x00004000, -// RelationSidebar = 0x00008000, -// RelationTag = 0x00010000, -// RelationUp = 0x00020000, +enum class Relation { + NoReferrer = 1 << 0, + NoOpener = 1 << 1, }; -class HTMLAnchorElement : public HTMLElement { +class HTMLAnchorElement : public HTMLElement, public URLUtils { public: - static PassRefPtr create(Document&); - static PassRefPtr create(const QualifiedName&, Document&); + static Ref create(Document&); + static Ref create(const QualifiedName&, Document&); virtual ~HTMLAnchorElement(); - URL href() const; + WEBCORE_EXPORT URL href() const; void setHref(const AtomicString&); const AtomicString& name() const; - String hash() const; - void setHash(const String&); - - String host() const; - void setHost(const String&); - - String hostname() const; - void setHostname(const String&); - - String pathname() const; - void setPathname(const String&); - - String port() const; - void setPort(const String&); - - String protocol() const; - void setProtocol(const String&); - - String search() const; - void setSearch(const String&); + WEBCORE_EXPORT String origin() const; - String origin() const; - - String text(); - - String toString() const; + WEBCORE_EXPORT String text(); + void setText(const String&); bool isLiveLink() const; - virtual bool willRespondToMouseClickEvents() override; + bool willRespondToMouseClickEvents() final; - bool hasRel(uint32_t relation) const; - void setRel(const String&); + bool hasRel(Relation) const; LinkHash visitedLinkHash() const; void invalidateCachedVisitedLinkHash() { m_cachedVisitedLinkHash = 0; } + WEBCORE_EXPORT DOMTokenList& relList(); + protected: HTMLAnchorElement(const QualifiedName&, Document&); - virtual void parseAttribute(const QualifiedName&, const AtomicString&) override; + void parseAttribute(const QualifiedName&, const AtomicString&) override; private: - virtual bool supportsFocus() const override; - virtual bool isMouseFocusable() const override; - virtual bool isKeyboardFocusable(KeyboardEvent*) const override; - virtual void defaultEventHandler(Event*) override; - virtual void setActive(bool active = true, bool pause = false) override final; - virtual void accessKeyAction(bool sendMouseEvents) override; - virtual bool isURLAttribute(const Attribute&) const override; - virtual bool canStartSelection() const override; - virtual String target() const override; - virtual short tabIndex() const override final; - virtual bool draggable() const override; + bool supportsFocus() const override; + bool isMouseFocusable() const override; + bool isKeyboardFocusable(KeyboardEvent&) const override; + void defaultEventHandler(Event&) final; + void setActive(bool active = true, bool pause = false) final; + void accessKeyAction(bool sendMouseEvents) final; + bool isURLAttribute(const Attribute&) const final; + bool canStartSelection() const final; + String target() const override; + int tabIndex() const final; + bool draggable() const final; void sendPings(const URL& destinationURL); - void handleClick(Event*); + void handleClick(Event&); enum EventType { MouseEventWithoutShiftKey, MouseEventWithShiftKey, NonMouseEvent, }; - static EventType eventType(Event*); + static EventType eventType(Event&); bool treatLinkAsLiveForEventType(EventType) const; Element* rootEditableElementForSelectionOnMouseDown() const; void setRootEditableElementForSelectionOnMouseDown(Element*); void clearRootEditableElementForSelectionOnMouseDown(); - bool m_hasRootEditableElementForSelectionOnMouseDown : 1; - bool m_wasShiftKeyDownOnMouseDown : 1; - uint32_t m_linkRelations : 30; + bool m_hasRootEditableElementForSelectionOnMouseDown; + bool m_wasShiftKeyDownOnMouseDown; + OptionSet m_linkRelations; mutable LinkHash m_cachedVisitedLinkHash; + + std::unique_ptr m_relList; }; inline LinkHash HTMLAnchorElement::visitedLinkHash() const { if (!m_cachedVisitedLinkHash) - m_cachedVisitedLinkHash = WebCore::visitedLinkHash(document().baseURL(), fastGetAttribute(HTMLNames::hrefAttr)); + m_cachedVisitedLinkHash = WebCore::visitedLinkHash(document().baseURL(), attributeWithoutSynchronization(HTMLNames::hrefAttr)); return m_cachedVisitedLinkHash; } // Functions shared with the other anchor elements (i.e., SVG). -bool isEnterKeyKeydownEvent(Event*); -bool isLinkClick(Event*); +bool isEnterKeyKeydownEvent(Event&); bool shouldProhibitLinks(Element*); -NODE_TYPE_CASTS(HTMLAnchorElement) - } // namespace WebCore - -#endif // HTMLAnchorElement_h diff --git a/Source/WebCore/html/HTMLAnchorElement.idl b/Source/WebCore/html/HTMLAnchorElement.idl index df6836282..7486d032c 100644 --- a/Source/WebCore/html/HTMLAnchorElement.idl +++ b/Source/WebCore/html/HTMLAnchorElement.idl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2009, 2010 Apple Inc. All rights reserved. + * Copyright (C) 2006-2016 Apple Inc. All rights reserved. * Copyright (C) 2006 Samuel Weinig * * This library is free software; you can redistribute it and/or @@ -21,50 +21,19 @@ interface HTMLAnchorElement : HTMLElement { [Reflect] attribute DOMString charset; [Reflect] attribute DOMString coords; - [Conditional=DOWNLOAD_ATTRIBUTE, Reflect] attribute DOMString download; - [Reflect, URL] attribute DOMString href; + [Conditional=DOWNLOAD_ATTRIBUTE, EnabledAtRuntime=DownloadAttribute, Reflect] attribute DOMString download; [Reflect] attribute DOMString hreflang; [Reflect] attribute DOMString name; - [Reflect] attribute DOMString ping; + [Reflect] attribute USVString ping; [Reflect] attribute DOMString rel; [Reflect] attribute DOMString rev; [Reflect] attribute DOMString shape; [Reflect] attribute DOMString target; [Reflect] attribute DOMString type; -#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C - [Reflect] attribute DOMString accessKey; -#endif + [CEReactions] attribute DOMString text; -#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C - readonly attribute DOMString hash; - readonly attribute DOMString host; - readonly attribute DOMString hostname; - readonly attribute DOMString pathname; - readonly attribute DOMString port; - readonly attribute DOMString protocol; - readonly attribute DOMString search; -#else - [TreatNullAs=NullString] attribute DOMString hash; - [TreatNullAs=NullString] attribute DOMString host; - [TreatNullAs=NullString] attribute DOMString hostname; - [TreatNullAs=NullString] attribute DOMString pathname; - [TreatNullAs=NullString] attribute DOMString port; - [TreatNullAs=NullString] attribute DOMString protocol; - [TreatNullAs=NullString] attribute DOMString search; - - [TreatNullAs=NullString] readonly attribute DOMString origin; -#endif - - readonly attribute DOMString text; - -#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT - [NotEnumerable] DOMString toString(); -#endif - -#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C - // Objective-C extension: - readonly attribute URL absoluteLinkURL; -#endif + [PutForwards=value] readonly attribute DOMTokenList relList; }; +HTMLAnchorElement implements HTMLHyperlinkElementUtils; diff --git a/Source/WebCore/html/HTMLAppletElement.cpp b/Source/WebCore/html/HTMLAppletElement.cpp index ca6fd25ef..5f54f8f31 100644 --- a/Source/WebCore/html/HTMLAppletElement.cpp +++ b/Source/WebCore/html/HTMLAppletElement.cpp @@ -41,16 +41,16 @@ namespace WebCore { using namespace HTMLNames; HTMLAppletElement::HTMLAppletElement(const QualifiedName& tagName, Document& document, bool createdByParser) - : HTMLPlugInImageElement(tagName, document, createdByParser, ShouldNotPreferPlugInsForImages) + : HTMLPlugInImageElement(tagName, document, createdByParser) { ASSERT(hasTagName(appletTag)); m_serviceType = "application/x-java-applet"; } -PassRefPtr HTMLAppletElement::create(const QualifiedName& tagName, Document& document, bool createdByParser) +Ref HTMLAppletElement::create(const QualifiedName& tagName, Document& document, bool createdByParser) { - return adoptRef(new HTMLAppletElement(tagName, document, createdByParser)); + return adoptRef(*new HTMLAppletElement(tagName, document, createdByParser)); } void HTMLAppletElement::parseAttribute(const QualifiedName& name, const AtomicString& value) @@ -68,34 +68,41 @@ void HTMLAppletElement::parseAttribute(const QualifiedName& name, const AtomicSt HTMLPlugInImageElement::parseAttribute(name, value); } +bool HTMLAppletElement::isURLAttribute(const Attribute& attribute) const +{ + return attribute.name().localName() == codebaseAttr + || attribute.name().localName() == objectAttr + || HTMLPlugInImageElement::isURLAttribute(attribute); +} + bool HTMLAppletElement::rendererIsNeeded(const RenderStyle& style) { - if (!fastHasAttribute(codeAttr)) + if (!hasAttributeWithoutSynchronization(codeAttr)) return false; return HTMLPlugInImageElement::rendererIsNeeded(style); } -RenderPtr HTMLAppletElement::createElementRenderer(PassRef style) +RenderPtr HTMLAppletElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&) { if (!canEmbedJava()) - return RenderElement::createFor(*this, std::move(style)); + return RenderElement::createFor(*this, WTFMove(style)); - return RenderEmbeddedObject::createForApplet(*this, std::move(style)); + return RenderEmbeddedObject::createForApplet(*this, WTFMove(style)); } -RenderWidget* HTMLAppletElement::renderWidgetForJSBindings() const +RenderWidget* HTMLAppletElement::renderWidgetLoadingPlugin() const { if (!canEmbedJava()) - return 0; + return nullptr; // Needs to load the plugin immediatedly because this function is called // when JavaScript code accesses the plugin. // FIXME: Check if dispatching events here is safe. - document().updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasksSynchronously); + document().updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasks::Synchronously); return renderWidget(); } -void HTMLAppletElement::updateWidget(PluginCreationOption pluginCreationOption) +void HTMLAppletElement::updateWidget(CreatePlugins createPlugins) { setNeedsWidgetUpdate(false); // FIXME: This should ASSERT isFinishedParsingChildren() instead. @@ -103,13 +110,13 @@ void HTMLAppletElement::updateWidget(PluginCreationOption pluginCreationOption) return; #if PLATFORM(IOS) - UNUSED_PARAM(pluginCreationOption); + UNUSED_PARAM(createPlugins); #else // FIXME: It's sadness that we have this special case here. // See http://trac.webkit.org/changeset/25128 and // plugins/netscape-plugin-setwindow-size.html - if (pluginCreationOption == CreateOnlyNonNetscapePlugins) { - // Ensure updateWidget() is called again during layout to create the Netscape plug-in. + if (createPlugins == CreatePlugins::No) { + // Ensure updateWidget() is called again during layout to create the plug-in. setNeedsWidgetUpdate(true); return; } @@ -117,19 +124,19 @@ void HTMLAppletElement::updateWidget(PluginCreationOption pluginCreationOption) RenderEmbeddedObject* renderer = renderEmbeddedObject(); LayoutUnit contentWidth = renderer->style().width().isFixed() ? LayoutUnit(renderer->style().width().value()) : - renderer->width() - renderer->borderAndPaddingWidth(); + renderer->width() - renderer->horizontalBorderAndPaddingExtent(); LayoutUnit contentHeight = renderer->style().height().isFixed() ? LayoutUnit(renderer->style().height().value()) : - renderer->height() - renderer->borderAndPaddingHeight(); + renderer->height() - renderer->verticalBorderAndPaddingExtent(); Vector paramNames; Vector paramValues; paramNames.append("code"); - paramValues.append(getAttribute(codeAttr).string()); + paramValues.append(attributeWithoutSynchronization(codeAttr).string()); - const AtomicString& codeBase = getAttribute(codebaseAttr); + const AtomicString& codeBase = attributeWithoutSynchronization(codebaseAttr); if (!codeBase.isNull()) { - paramNames.append("codeBase"); + paramNames.append(ASCIILiteral("codeBase")); paramValues.append(codeBase.string()); } @@ -139,18 +146,18 @@ void HTMLAppletElement::updateWidget(PluginCreationOption pluginCreationOption) paramValues.append(name.string()); } - const AtomicString& archive = getAttribute(archiveAttr); + const AtomicString& archive = attributeWithoutSynchronization(archiveAttr); if (!archive.isNull()) { - paramNames.append("archive"); + paramNames.append(ASCIILiteral("archive")); paramValues.append(archive.string()); } - paramNames.append("baseURL"); + paramNames.append(ASCIILiteral("baseURL")); paramValues.append(document().baseURL().string()); - const AtomicString& mayScript = getAttribute(mayscriptAttr); + const AtomicString& mayScript = attributeWithoutSynchronization(mayscriptAttr); if (!mayScript.isNull()) { - paramNames.append("mayScript"); + paramNames.append(ASCIILiteral("mayScript")); paramValues.append(mayScript.string()); } @@ -174,14 +181,10 @@ bool HTMLAppletElement::canEmbedJava() const if (document().isSandboxed(SandboxPlugins)) return false; - Settings* settings = document().settings(); - if (!settings) - return false; - - if (!settings->isJavaEnabled()) + if (!document().settings().isJavaEnabled()) return false; - if (document().securityOrigin()->isLocal() && !settings->isJavaEnabledForLocalFiles()) + if (document().securityOrigin().isLocal() && !document().settings().isJavaEnabledForLocalFiles()) return false; return true; diff --git a/Source/WebCore/html/HTMLAppletElement.h b/Source/WebCore/html/HTMLAppletElement.h index fcfc09ac5..4d5d324a5 100644 --- a/Source/WebCore/html/HTMLAppletElement.h +++ b/Source/WebCore/html/HTMLAppletElement.h @@ -20,8 +20,7 @@ * */ -#ifndef HTMLAppletElement_h -#define HTMLAppletElement_h +#pragma once #include "HTMLPlugInImageElement.h" @@ -29,22 +28,21 @@ namespace WebCore { class HTMLAppletElement final : public HTMLPlugInImageElement { public: - static PassRefPtr create(const QualifiedName&, Document&, bool createdByParser); + static Ref create(const QualifiedName&, Document&, bool createdByParser); private: HTMLAppletElement(const QualifiedName&, Document&, bool createdByParser); - virtual void parseAttribute(const QualifiedName&, const AtomicString&) override; + void parseAttribute(const QualifiedName&, const AtomicString&) final; + bool isURLAttribute(const Attribute&) const final; - virtual bool rendererIsNeeded(const RenderStyle&) override; - virtual RenderPtr createElementRenderer(PassRef) override; + bool rendererIsNeeded(const RenderStyle&) final; + RenderPtr createElementRenderer(RenderStyle&&, const RenderTreePosition&) final; - virtual RenderWidget* renderWidgetForJSBindings() const override; - virtual void updateWidget(PluginCreationOption) override; + RenderWidget* renderWidgetLoadingPlugin() const final; + void updateWidget(CreatePlugins) final; bool canEmbedJava() const; }; -} - -#endif +} // namespace WebCore diff --git a/Source/WebCore/html/HTMLAppletElement.idl b/Source/WebCore/html/HTMLAppletElement.idl index f80b11a5a..261d6ed7a 100644 --- a/Source/WebCore/html/HTMLAppletElement.idl +++ b/Source/WebCore/html/HTMLAppletElement.idl @@ -19,28 +19,19 @@ */ [ + CustomCall, CustomNamedSetter, JSCustomGetOwnPropertySlotAndDescriptor, - CustomCall ] interface HTMLAppletElement : HTMLElement { [Reflect] attribute DOMString align; [Reflect] attribute DOMString alt; [Reflect] attribute DOMString archive; [Reflect] attribute DOMString code; - [Reflect] attribute DOMString codeBase; + [Reflect, URL] attribute USVString codeBase; [Reflect] attribute DOMString height; -#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT - [Reflect] attribute DOMString hspace; -#else - [Reflect] attribute long hspace; -#endif + [Reflect] attribute unsigned long hspace; [Reflect] attribute DOMString name; - [Reflect] attribute DOMString object; -#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT - [Reflect] attribute DOMString vspace; -#else - [Reflect] attribute long vspace; -#endif + [Reflect, URL] attribute USVString object; + [Reflect] attribute unsigned long vspace; [Reflect] attribute DOMString width; }; - diff --git a/Source/WebCore/html/HTMLAreaElement.cpp b/Source/WebCore/html/HTMLAreaElement.cpp index 5eeb31e46..3a51f25f4 100644 --- a/Source/WebCore/html/HTMLAreaElement.cpp +++ b/Source/WebCore/html/HTMLAreaElement.cpp @@ -23,10 +23,10 @@ #include "HTMLAreaElement.h" #include "AffineTransform.h" -#include "Attribute.h" #include "Frame.h" #include "HTMLImageElement.h" #include "HTMLMapElement.h" +#include "HTMLParserIdioms.h" #include "HitTestResult.h" #include "Path.h" #include "RenderImage.h" @@ -38,32 +38,33 @@ using namespace HTMLNames; inline HTMLAreaElement::HTMLAreaElement(const QualifiedName& tagName, Document& document) : HTMLAnchorElement(tagName, document) - , m_coordsLen(0) , m_lastSize(-1, -1) , m_shape(Unknown) { ASSERT(hasTagName(areaTag)); } -PassRefPtr HTMLAreaElement::create(const QualifiedName& tagName, Document& document) +Ref HTMLAreaElement::create(const QualifiedName& tagName, Document& document) { - return adoptRef(new HTMLAreaElement(tagName, document)); + return adoptRef(*new HTMLAreaElement(tagName, document)); } void HTMLAreaElement::parseAttribute(const QualifiedName& name, const AtomicString& value) { if (name == shapeAttr) { - if (equalIgnoringCase(value, "default")) + if (equalLettersIgnoringASCIICase(value, "default")) m_shape = Default; - else if (equalIgnoringCase(value, "circle")) + else if (equalLettersIgnoringASCIICase(value, "circle") || equalLettersIgnoringASCIICase(value, "circ")) m_shape = Circle; - else if (equalIgnoringCase(value, "poly")) + else if (equalLettersIgnoringASCIICase(value, "poly") || equalLettersIgnoringASCIICase(value, "polygon")) m_shape = Poly; - else if (equalIgnoringCase(value, "rect")) + else { + // The missing value default is the rectangle state. m_shape = Rect; + } invalidateCachedRegion(); } else if (name == coordsAttr) { - m_coords = newCoordsArray(value.string(), m_coordsLen); + m_coords = parseHTMLListOfOfFloatingPointNumberValues(value.string()); invalidateCachedRegion(); } else if (name == altAttr || name == accesskeyAttr) { // Do nothing. @@ -79,7 +80,7 @@ void HTMLAreaElement::invalidateCachedRegion() bool HTMLAreaElement::mapMouseEvent(LayoutPoint location, const LayoutSize& size, HitTestResult& result) { if (m_lastSize != size) { - m_region = adoptPtr(new Path(getRegion(size))); + m_region = std::make_unique(getRegion(size)); m_lastSize = size; } @@ -117,6 +118,11 @@ Path HTMLAreaElement::computePath(RenderObject* obj) const return p; } +Path HTMLAreaElement::computePathForFocusRing(const LayoutSize& elementSize) const +{ + return getRegion(m_shape == Default ? elementSize : m_lastSize); +} + // FIXME: Use RenderElement* instead of RenderObject* once we upstream iOS's DOMUIKitExtensions.{h, mm}. LayoutRect HTMLAreaElement::computeRect(RenderObject* obj) const { @@ -125,7 +131,7 @@ LayoutRect HTMLAreaElement::computeRect(RenderObject* obj) const Path HTMLAreaElement::getRegion(const LayoutSize& size) const { - if (!m_coords && m_shape != Default) + if (m_coords.isEmpty() && m_shape != Default) return Path(); LayoutUnit width = size.width(); @@ -134,39 +140,38 @@ Path HTMLAreaElement::getRegion(const LayoutSize& size) const // If element omits the shape attribute, select shape based on number of coordinates. Shape shape = m_shape; if (shape == Unknown) { - if (m_coordsLen == 3) + if (m_coords.size() == 3) shape = Circle; - else if (m_coordsLen == 4) + else if (m_coords.size() == 4) shape = Rect; - else if (m_coordsLen >= 6) + else if (m_coords.size() >= 6) shape = Poly; } Path path; - RenderView* renderView = document().renderView(); switch (shape) { case Poly: - if (m_coordsLen >= 6) { - int numPoints = m_coordsLen / 2; - path.moveTo(FloatPoint(minimumValueForLength(m_coords[0], width, renderView), minimumValueForLength(m_coords[1], height, renderView))); + if (m_coords.size() >= 6) { + int numPoints = m_coords.size() / 2; + path.moveTo(FloatPoint(m_coords[0], m_coords[1])); for (int i = 1; i < numPoints; ++i) - path.addLineTo(FloatPoint(minimumValueForLength(m_coords[i * 2], width, renderView), minimumValueForLength(m_coords[i * 2 + 1], height, renderView))); + path.addLineTo(FloatPoint(m_coords[i * 2], m_coords[i * 2 + 1])); path.closeSubpath(); } break; case Circle: - if (m_coordsLen >= 3) { - Length radius = m_coords[2]; - int r = std::min(minimumValueForLength(radius, width, renderView), minimumValueForLength(radius, height, renderView)); - path.addEllipse(FloatRect(minimumValueForLength(m_coords[0], width, renderView) - r, minimumValueForLength(m_coords[1], height, renderView) - r, 2 * r, 2 * r)); + if (m_coords.size() >= 3) { + double radius = m_coords[2]; + if (radius > 0) + path.addEllipse(FloatRect(m_coords[0] - radius, m_coords[1] - radius, 2 * radius, 2 * radius)); } break; case Rect: - if (m_coordsLen >= 4) { - int x0 = minimumValueForLength(m_coords[0], width, renderView); - int y0 = minimumValueForLength(m_coords[1], height, renderView); - int x1 = minimumValueForLength(m_coords[2], width, renderView); - int y1 = minimumValueForLength(m_coords[3], height, renderView); + if (m_coords.size() >= 4) { + double x0 = m_coords[0]; + double y0 = m_coords[1]; + double x1 = m_coords[2]; + double y1 = m_coords[3]; path.addRect(FloatRect(x0, y0, x1 - x0, y1 - y0)); } break; @@ -183,13 +188,13 @@ Path HTMLAreaElement::getRegion(const LayoutSize& size) const HTMLImageElement* HTMLAreaElement::imageElement() const { Node* mapElement = parentNode(); - if (!mapElement || !isHTMLMapElement(mapElement)) - return 0; + if (!is(mapElement)) + return nullptr; - return toHTMLMapElement(mapElement)->imageElement(); + return downcast(*mapElement).imageElement(); } -bool HTMLAreaElement::isKeyboardFocusable(KeyboardEvent*) const +bool HTMLAreaElement::isKeyboardFocusable(KeyboardEvent&) const { return isFocusable(); } @@ -219,14 +224,14 @@ void HTMLAreaElement::setFocus(bool shouldBeFocused) if (!imageElement) return; - auto renderer = imageElement->renderer(); - if (!renderer || !renderer->isRenderImage()) + auto* renderer = imageElement->renderer(); + if (!is(renderer)) return; - toRenderImage(renderer)->areaElementFocusChanged(this); + downcast(*renderer).areaElementFocusChanged(this); } -void HTMLAreaElement::updateFocusAppearance(bool restorePreviousSelection) +void HTMLAreaElement::updateFocusAppearance(SelectionRestorationMode restorationMode, SelectionRevealMode revealMode) { if (!isFocusable()) return; @@ -235,7 +240,7 @@ void HTMLAreaElement::updateFocusAppearance(bool restorePreviousSelection) if (!imageElement) return; - imageElement->updateFocusAppearance(restorePreviousSelection); + imageElement->updateFocusAppearance(restorationMode, revealMode); } bool HTMLAreaElement::supportsFocus() const @@ -248,7 +253,7 @@ bool HTMLAreaElement::supportsFocus() const String HTMLAreaElement::target() const { - return getAttribute(targetAttr); + return attributeWithoutSynchronization(targetAttr); } } diff --git a/Source/WebCore/html/HTMLAreaElement.h b/Source/WebCore/html/HTMLAreaElement.h index ae6c2a8bb..92291930d 100644 --- a/Source/WebCore/html/HTMLAreaElement.h +++ b/Source/WebCore/html/HTMLAreaElement.h @@ -20,8 +20,7 @@ * */ -#ifndef HTMLAreaElement_h -#define HTMLAreaElement_h +#pragma once #include "HTMLAnchorElement.h" #include "LayoutRect.h" @@ -29,50 +28,46 @@ namespace WebCore { -class HitTestResult; class HTMLImageElement; +class HitTestResult; class Path; class HTMLAreaElement final : public HTMLAnchorElement { public: - static PassRefPtr create(const QualifiedName&, Document&); + static Ref create(const QualifiedName&, Document&); bool isDefault() const { return m_shape == Default; } bool mapMouseEvent(LayoutPoint location, const LayoutSize&, HitTestResult&); - // FIXME: Use RenderElement* instead of RenderObject* once we upstream iOS's DOMUIKitExtensions.{h, mm}. - LayoutRect computeRect(RenderObject*) const; + // FIXME: Use RenderElement& instead of RenderObject*. + WEBCORE_EXPORT LayoutRect computeRect(RenderObject*) const; Path computePath(RenderObject*) const; + Path computePathForFocusRing(const LayoutSize& elementSize) const; // The parent map's image. - HTMLImageElement* imageElement() const; + WEBCORE_EXPORT HTMLImageElement* imageElement() const; private: HTMLAreaElement(const QualifiedName&, Document&); - virtual void parseAttribute(const QualifiedName&, const AtomicString&) override; - virtual bool supportsFocus() const override; - virtual String target() const override; - virtual bool isKeyboardFocusable(KeyboardEvent*) const override; - virtual bool isMouseFocusable() const override; - virtual bool isFocusable() const override; - virtual void updateFocusAppearance(bool /*restorePreviousSelection*/) override; - virtual void setFocus(bool) override; + void parseAttribute(const QualifiedName&, const AtomicString&) final; + bool supportsFocus() const final; + String target() const final; + bool isKeyboardFocusable(KeyboardEvent&) const final; + bool isMouseFocusable() const final; + bool isFocusable() const final; + void updateFocusAppearance(SelectionRestorationMode, SelectionRevealMode) final; + void setFocus(bool) final; enum Shape { Default, Poly, Rect, Circle, Unknown }; Path getRegion(const LayoutSize&) const; void invalidateCachedRegion(); - OwnPtr m_region; - std::unique_ptr m_coords; - int m_coordsLen; + std::unique_ptr m_region; + Vector m_coords; LayoutSize m_lastSize; Shape m_shape; }; -NODE_TYPE_CASTS(HTMLAreaElement) - } //namespace - -#endif diff --git a/Source/WebCore/html/HTMLAreaElement.idl b/Source/WebCore/html/HTMLAreaElement.idl index d0250529b..1598583a3 100644 --- a/Source/WebCore/html/HTMLAreaElement.idl +++ b/Source/WebCore/html/HTMLAreaElement.idl @@ -21,27 +21,15 @@ interface HTMLAreaElement : HTMLElement { [Reflect] attribute DOMString alt; [Reflect] attribute DOMString coords; - [Reflect, URL] attribute DOMString href; [Reflect] attribute boolean noHref; - [Reflect] attribute DOMString ping; + [Reflect] attribute USVString ping; + [Reflect] attribute DOMString rel; [Reflect] attribute DOMString shape; [Reflect] attribute DOMString target; -#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C - [Reflect] attribute DOMString accessKey; -#endif - // IE Extensions - readonly attribute DOMString hash; - readonly attribute DOMString host; - readonly attribute DOMString hostname; - readonly attribute DOMString pathname; - readonly attribute DOMString port; - readonly attribute DOMString protocol; - readonly attribute DOMString search; + [Conditional=DOWNLOAD_ATTRIBUTE, EnabledAtRuntime=DownloadAttribute, Reflect] attribute DOMString download; -#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C - // Objective-C extension: - readonly attribute URL absoluteLinkURL; -#endif + [PutForwards=value] readonly attribute DOMTokenList relList; }; +HTMLAreaElement implements HTMLHyperlinkElementUtils; diff --git a/Source/WebCore/html/HTMLAttachmentElement.cpp b/Source/WebCore/html/HTMLAttachmentElement.cpp new file mode 100644 index 000000000..02e6db799 --- /dev/null +++ b/Source/WebCore/html/HTMLAttachmentElement.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "HTMLAttachmentElement.h" + +#if ENABLE(ATTACHMENT_ELEMENT) + +#include "File.h" +#include "HTMLNames.h" +#include "RenderAttachment.h" + +namespace WebCore { + +using namespace HTMLNames; + +HTMLAttachmentElement::HTMLAttachmentElement(const QualifiedName& tagName, Document& document) + : HTMLElement(tagName, document) +{ + ASSERT(hasTagName(attachmentTag)); +} + +HTMLAttachmentElement::~HTMLAttachmentElement() +{ +} + +Ref HTMLAttachmentElement::create(const QualifiedName& tagName, Document& document) +{ + return adoptRef(*new HTMLAttachmentElement(tagName, document)); +} + +RenderPtr HTMLAttachmentElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&) +{ + return createRenderer(*this, WTFMove(style)); +} + +File* HTMLAttachmentElement::file() const +{ + return m_file.get(); +} + +void HTMLAttachmentElement::setFile(File* file) +{ + m_file = file; + + if (auto* renderer = this->renderer()) + renderer->invalidate(); +} + +void HTMLAttachmentElement::parseAttribute(const QualifiedName& name, const AtomicString& value) +{ + if (name == progressAttr || name == subtitleAttr || name == titleAttr || name == typeAttr) { + if (auto* renderer = this->renderer()) + renderer->invalidate(); + } + + HTMLElement::parseAttribute(name, value); +} + +String HTMLAttachmentElement::attachmentTitle() const +{ + auto& title = attributeWithoutSynchronization(titleAttr); + if (!title.isEmpty()) + return title; + return m_file ? m_file->name() : String(); +} + +String HTMLAttachmentElement::attachmentType() const +{ + return attributeWithoutSynchronization(typeAttr); +} + +} // namespace WebCore + +#endif // ENABLE(ATTACHMENT_ELEMENT) diff --git a/Source/WebCore/html/HTMLAttachmentElement.h b/Source/WebCore/html/HTMLAttachmentElement.h new file mode 100644 index 000000000..9ac6b6a8b --- /dev/null +++ b/Source/WebCore/html/HTMLAttachmentElement.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#if ENABLE(ATTACHMENT_ELEMENT) + +#include "HTMLElement.h" + +namespace WebCore { + +class File; +class RenderAttachment; + +class HTMLAttachmentElement final : public HTMLElement { +public: + static Ref create(const QualifiedName&, Document&); + + WEBCORE_EXPORT File* file() const; + void setFile(File*); + + WEBCORE_EXPORT String attachmentTitle() const; + String attachmentType() const; + + RenderAttachment* renderer() const; + +private: + HTMLAttachmentElement(const QualifiedName&, Document&); + virtual ~HTMLAttachmentElement(); + + RenderPtr createElementRenderer(RenderStyle&&, const RenderTreePosition&) final; + + bool shouldSelectOnMouseDown() final { +#if PLATFORM(IOS) + return false; +#else + return true; +#endif + } + bool canContainRangeEndPoint() const final { return false; } + void parseAttribute(const QualifiedName&, const AtomicString&) final; + + RefPtr m_file; +}; + +} // namespace WebCore + +#endif // ENABLE(ATTACHMENT_ELEMENT) diff --git a/Source/WebCore/html/HTMLAttachmentElement.idl b/Source/WebCore/html/HTMLAttachmentElement.idl new file mode 100644 index 000000000..d69a15780 --- /dev/null +++ b/Source/WebCore/html/HTMLAttachmentElement.idl @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + Conditional=ATTACHMENT_ELEMENT +] interface HTMLAttachmentElement : HTMLElement { + attribute File? file; +}; diff --git a/Source/WebCore/html/HTMLAttributeNames.in b/Source/WebCore/html/HTMLAttributeNames.in index 949d04fdf..88f1a4316 100644 --- a/Source/WebCore/html/HTMLAttributeNames.in +++ b/Source/WebCore/html/HTMLAttributeNames.in @@ -17,7 +17,11 @@ aria-activedescendant aria-atomic aria-busy aria-checked +aria-colcount +aria-colindex +aria-colspan aria-controls +aria-current aria-describedby aria-disabled aria-dropeffect @@ -33,15 +37,21 @@ aria-labeledby aria-labelledby aria-level aria-live +aria-modal aria-multiline aria-multiselectable aria-orientation aria-owns +aria-placeholder aria-posinset aria-pressed aria-readonly aria-relevant aria-required +aria-roledescription +aria-rowcount +aria-rowindex +aria-rowspan aria-selected aria-setsize aria-sort @@ -49,6 +59,7 @@ aria-valuemax aria-valuemin aria-valuenow aria-valuetext +as async autocomplete autofocus @@ -153,6 +164,7 @@ marginheight marginwidth max maxlength +minlength mayscript media mediagroup @@ -162,6 +174,7 @@ multiple muted name nohref +nomodule nonce noresize noshade @@ -169,8 +182,14 @@ novalidate nowrap object onabort +onanimationstart +onanimationiteration +onanimationend +onautocomplete +onautocompleteerror onbeforecopy onbeforecut +onbeforeinput onbeforeload onbeforepaste onbeforeunload @@ -206,10 +225,12 @@ onkeyup ongesturestart ongesturechange ongestureend +onlanguagechange onload onloadeddata onloadedmetadata onloadstart +onmessage onmousedown onmouseenter onmouseleave @@ -246,6 +267,8 @@ onstorage onsuspend onsubmit ontimeupdate +ontoggle +ontouchforcechange ontouchstart ontouchmove ontouchend @@ -264,15 +287,24 @@ onwebkitfullscreenerror onwebkitkeyadded onwebkitkeyerror onwebkitkeymessage +onwebkitmouseforcechanged +onwebkitmouseforcedown +onwebkitmouseforceup +onwebkitmouseforcewillbegin onwebkitneedkey onwebkitsourceclose onwebkitsourceended onwebkitsourceopen onwebkittransitionend +onwebkitwillrevealbottom +onwebkitwillrevealleft +onwebkitwillrevealright +onwebkitwillrevealtop open optimum pattern placeholder +playsinline pluginspage pluginurl ping @@ -301,12 +333,12 @@ scoped scrollamount scrolldelay scrolling -seamless select selected shape size sizes +slot sortable sortdirection span @@ -321,6 +353,7 @@ standby start step style +subtitle summary tabindex tableborder @@ -338,19 +371,24 @@ valign value valuetype version -viewsource vlink vspace webkitallowfullscreen -webkitdirectory +webkitattachmentpath width wrap autocorrect autocapitalize -data-youtube-id onwebkitcurrentplaybacktargetiswirelesschanged onwebkitplaybacktargetavailabilitychanged +onwebkitpresentationmodechanged +x-webkit-imagemenu webkit-playsinline x-webkit-airplay x-webkit-wirelessvideoplaybackdisabled +x-itunes-inherit-uri-query-component + +x-apple-data-detectors +x-apple-data-detectors-type +x-apple-data-detectors-result diff --git a/Source/WebCore/html/HTMLAudioElement.cpp b/Source/WebCore/html/HTMLAudioElement.cpp index b487a3b7e..d34946bec 100644 --- a/Source/WebCore/html/HTMLAudioElement.cpp +++ b/Source/WebCore/html/HTMLAudioElement.cpp @@ -10,10 +10,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -39,23 +39,21 @@ HTMLAudioElement::HTMLAudioElement(const QualifiedName& tagName, Document& docum ASSERT(hasTagName(audioTag)); } -PassRefPtr HTMLAudioElement::create(const QualifiedName& tagName, Document& document, bool createdByParser) +Ref HTMLAudioElement::create(const QualifiedName& tagName, Document& document, bool createdByParser) { - RefPtr audioElement(adoptRef(new HTMLAudioElement(tagName, document, createdByParser))); + Ref audioElement = adoptRef(*new HTMLAudioElement(tagName, document, createdByParser)); audioElement->suspendIfNeeded(); - return audioElement.release(); + return audioElement; } -PassRefPtr HTMLAudioElement::createForJSConstructor(Document& document, const String& src) +Ref HTMLAudioElement::createForJSConstructor(Document& document, const String& src) { - RefPtr audio = adoptRef(new HTMLAudioElement(audioTag, document, false)); + Ref audio = adoptRef(*new HTMLAudioElement(audioTag, document, false)); audio->setPreload("auto"); - if (!src.isNull()) { + if (!src.isNull()) audio->setSrc(src); - audio->scheduleDelayedAction(HTMLMediaElement::LoadMediaResource); - } audio->suspendIfNeeded(); - return audio.release(); + return audio; } } diff --git a/Source/WebCore/html/HTMLAudioElement.h b/Source/WebCore/html/HTMLAudioElement.h index 0f97d1452..6ec7494d1 100644 --- a/Source/WebCore/html/HTMLAudioElement.h +++ b/Source/WebCore/html/HTMLAudioElement.h @@ -11,10 +11,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -24,10 +24,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef HTMLAudioElement_h -#define HTMLAudioElement_h +#pragma once #if ENABLE(VIDEO) + #include "HTMLMediaElement.h" namespace WebCore { @@ -36,16 +36,21 @@ class Document; class HTMLAudioElement final : public HTMLMediaElement { public: - static PassRefPtr create(const QualifiedName&, Document&, bool); - static PassRefPtr createForJSConstructor(Document&, const String& src); + static Ref create(const QualifiedName&, Document&, bool); + static Ref createForJSConstructor(Document&, const String& src); private: HTMLAudioElement(const QualifiedName&, Document&, bool); + + PlatformMediaSession::MediaType presentationType() const final { return PlatformMediaSession::Audio; } }; -NODE_TYPE_CASTS(HTMLAudioElement) +} // namespace WebCore -} //namespace +SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLAudioElement) + static bool isType(const WebCore::HTMLMediaElement& element) { return element.hasTagName(WebCore::HTMLNames::audioTag); } + static bool isType(const WebCore::Element& element) { return is(element) && isType(downcast(element)); } + static bool isType(const WebCore::Node& node) { return is(node) && isType(downcast(node)); } +SPECIALIZE_TYPE_TRAITS_END() -#endif -#endif +#endif // ENABLE(VIDEO) diff --git a/Source/WebCore/html/HTMLAudioElement.idl b/Source/WebCore/html/HTMLAudioElement.idl index 4685ac9fa..6faa26877 100644 --- a/Source/WebCore/html/HTMLAudioElement.idl +++ b/Source/WebCore/html/HTMLAudioElement.idl @@ -10,10 +10,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -26,6 +26,6 @@ [ EnabledAtRuntime, Conditional=VIDEO, - NamedConstructor=Audio([Default=NullString] optional DOMString src) + NamedConstructor=Audio(optional DOMString src) ] interface HTMLAudioElement : HTMLMediaElement { }; diff --git a/Source/WebCore/html/HTMLBDIElement.h b/Source/WebCore/html/HTMLBDIElement.h index d5ec4bf7c..217d28f3b 100644 --- a/Source/WebCore/html/HTMLBDIElement.h +++ b/Source/WebCore/html/HTMLBDIElement.h @@ -18,8 +18,7 @@ * */ -#ifndef HTMLBDIElement_h -#define HTMLBDIElement_h +#pragma once #include "HTMLElement.h" @@ -27,9 +26,9 @@ namespace WebCore { class HTMLBDIElement final : public HTMLElement { public: - static PassRefPtr create(const QualifiedName& name, Document& document) + static Ref create(const QualifiedName& name, Document& document) { - return adoptRef(new HTMLBDIElement(name, document)); + return adoptRef(*new HTMLBDIElement(name, document)); } private: @@ -42,5 +41,3 @@ private: }; } // namespace WebCore - -#endif diff --git a/Source/WebCore/html/HTMLBRElement.cpp b/Source/WebCore/html/HTMLBRElement.cpp index 5eea85ae9..db1f0ccfc 100644 --- a/Source/WebCore/html/HTMLBRElement.cpp +++ b/Source/WebCore/html/HTMLBRElement.cpp @@ -23,7 +23,6 @@ #include "config.h" #include "HTMLBRElement.h" -#include "Attribute.h" #include "CSSPropertyNames.h" #include "CSSValueKeywords.h" #include "HTMLNames.h" @@ -39,14 +38,14 @@ HTMLBRElement::HTMLBRElement(const QualifiedName& tagName, Document& document) ASSERT(hasTagName(brTag)); } -PassRefPtr HTMLBRElement::create(Document& document) +Ref HTMLBRElement::create(Document& document) { - return adoptRef(new HTMLBRElement(brTag, document)); + return adoptRef(*new HTMLBRElement(brTag, document)); } -PassRefPtr HTMLBRElement::create(const QualifiedName& tagName, Document& document) +Ref HTMLBRElement::create(const QualifiedName& tagName, Document& document) { - return adoptRef(new HTMLBRElement(tagName, document)); + return adoptRef(*new HTMLBRElement(tagName, document)); } bool HTMLBRElement::isPresentationAttribute(const QualifiedName& name) const @@ -62,7 +61,7 @@ void HTMLBRElement::collectStyleForPresentationAttribute(const QualifiedName& na // If the string is empty, then don't add the clear property. //
and
are just treated like
by Gecko, Mac IE, etc. -dwh if (!value.isEmpty()) { - if (equalIgnoringCase(value, "all")) + if (equalLettersIgnoringASCIICase(value, "all")) addPropertyToPresentationAttributeStyle(style, CSSPropertyClear, CSSValueBoth); else addPropertyToPresentationAttributeStyle(style, CSSPropertyClear, value); @@ -71,12 +70,12 @@ void HTMLBRElement::collectStyleForPresentationAttribute(const QualifiedName& na HTMLElement::collectStyleForPresentationAttribute(name, value, style); } -RenderPtr HTMLBRElement::createElementRenderer(PassRef style) +RenderPtr HTMLBRElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&) { - if (style.get().hasContent()) - return RenderElement::createFor(*this, std::move(style)); + if (style.hasContent()) + return RenderElement::createFor(*this, WTFMove(style)); - return createRenderer(*this, std::move(style)); + return createRenderer(*this, WTFMove(style)); } } diff --git a/Source/WebCore/html/HTMLBRElement.h b/Source/WebCore/html/HTMLBRElement.h index b5439c5c9..bf446311d 100644 --- a/Source/WebCore/html/HTMLBRElement.h +++ b/Source/WebCore/html/HTMLBRElement.h @@ -21,8 +21,7 @@ * */ -#ifndef HTMLBRElement_h -#define HTMLBRElement_h +#pragma once #include "HTMLElement.h" @@ -30,20 +29,18 @@ namespace WebCore { class HTMLBRElement final : public HTMLElement { public: - static PassRefPtr create(Document&); - static PassRefPtr create(const QualifiedName&, Document&); + static Ref create(Document&); + static Ref create(const QualifiedName&, Document&); - virtual bool canContainRangeEndPoint() const override { return false; } + bool canContainRangeEndPoint() const final { return false; } private: HTMLBRElement(const QualifiedName&, Document&); - virtual bool isPresentationAttribute(const QualifiedName&) const override; - virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) override; + bool isPresentationAttribute(const QualifiedName&) const final; + void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) final; - virtual RenderPtr createElementRenderer(PassRef) override; + RenderPtr createElementRenderer(RenderStyle&&, const RenderTreePosition&) final; }; } // namespace - -#endif diff --git a/Source/WebCore/html/HTMLBaseElement.cpp b/Source/WebCore/html/HTMLBaseElement.cpp index 7e8d2764a..fcfd67b4d 100644 --- a/Source/WebCore/html/HTMLBaseElement.cpp +++ b/Source/WebCore/html/HTMLBaseElement.cpp @@ -23,7 +23,6 @@ #include "config.h" #include "HTMLBaseElement.h" -#include "Attribute.h" #include "Document.h" #include "HTMLNames.h" #include "HTMLParserIdioms.h" @@ -39,9 +38,9 @@ inline HTMLBaseElement::HTMLBaseElement(const QualifiedName& tagName, Document& ASSERT(hasTagName(baseTag)); } -PassRefPtr HTMLBaseElement::create(const QualifiedName& tagName, Document& document) +Ref HTMLBaseElement::create(const QualifiedName& tagName, Document& document) { - return adoptRef(new HTMLBaseElement(tagName, document)); + return adoptRef(*new HTMLBaseElement(tagName, document)); } void HTMLBaseElement::parseAttribute(const QualifiedName& name, const AtomicString& value) @@ -55,7 +54,7 @@ void HTMLBaseElement::parseAttribute(const QualifiedName& name, const AtomicStri Node::InsertionNotificationRequest HTMLBaseElement::insertedInto(ContainerNode& insertionPoint) { HTMLElement::insertedInto(insertionPoint); - if (insertionPoint.inDocument()) + if (insertionPoint.isConnected()) document().processBaseElement(); return InsertionDone; } @@ -63,7 +62,7 @@ Node::InsertionNotificationRequest HTMLBaseElement::insertedInto(ContainerNode& void HTMLBaseElement::removedFrom(ContainerNode& insertionPoint) { HTMLElement::removedFrom(insertionPoint); - if (insertionPoint.inDocument()) + if (insertionPoint.isConnected()) document().processBaseElement(); } @@ -74,7 +73,7 @@ bool HTMLBaseElement::isURLAttribute(const Attribute& attribute) const String HTMLBaseElement::target() const { - return fastGetAttribute(targetAttr); + return attributeWithoutSynchronization(targetAttr); } URL HTMLBaseElement::href() const @@ -83,7 +82,7 @@ URL HTMLBaseElement::href() const // base elements like this one can be used to set that base URL. Thus we need to resolve relative to the document's // URL and ignore the base URL. - const AtomicString& attributeValue = fastGetAttribute(hrefAttr); + const AtomicString& attributeValue = attributeWithoutSynchronization(hrefAttr); if (attributeValue.isNull()) return document().url(); @@ -99,7 +98,7 @@ URL HTMLBaseElement::href() const void HTMLBaseElement::setHref(const AtomicString& value) { - setAttribute(hrefAttr, value); + setAttributeWithoutSynchronization(hrefAttr, value); } } diff --git a/Source/WebCore/html/HTMLBaseElement.h b/Source/WebCore/html/HTMLBaseElement.h index 4054e1758..b5541b49a 100644 --- a/Source/WebCore/html/HTMLBaseElement.h +++ b/Source/WebCore/html/HTMLBaseElement.h @@ -20,8 +20,7 @@ * */ -#ifndef HTMLBaseElement_h -#define HTMLBaseElement_h +#pragma once #include "HTMLElement.h" @@ -29,23 +28,19 @@ namespace WebCore { class HTMLBaseElement final : public HTMLElement { public: - static PassRefPtr create(const QualifiedName&, Document&); + static Ref create(const QualifiedName&, Document&); - URL href() const; - void setHref(const AtomicString&); + WEBCORE_EXPORT URL href() const; + WEBCORE_EXPORT void setHref(const AtomicString&); private: HTMLBaseElement(const QualifiedName&, Document&); - virtual String target() const override; - virtual bool isURLAttribute(const Attribute&) const override; - virtual void parseAttribute(const QualifiedName&, const AtomicString&) override; - virtual InsertionNotificationRequest insertedInto(ContainerNode&) override; - virtual void removedFrom(ContainerNode&) override; + String target() const final; + bool isURLAttribute(const Attribute&) const final; + void parseAttribute(const QualifiedName&, const AtomicString&) final; + InsertionNotificationRequest insertedInto(ContainerNode&) final; + void removedFrom(ContainerNode&) final; }; -NODE_TYPE_CASTS(HTMLBaseElement) - } // namespace - -#endif diff --git a/Source/WebCore/html/HTMLBaseElement.idl b/Source/WebCore/html/HTMLBaseElement.idl index 4d9d39f0f..1167d6479 100644 --- a/Source/WebCore/html/HTMLBaseElement.idl +++ b/Source/WebCore/html/HTMLBaseElement.idl @@ -18,6 +18,7 @@ */ interface HTMLBaseElement : HTMLElement { - [TreatNullAs=NullString] attribute DOMString href; + attribute USVString href; + [Reflect] attribute DOMString target; }; diff --git a/Source/WebCore/html/HTMLBaseFontElement.cpp b/Source/WebCore/html/HTMLBaseFontElement.cpp deleted file mode 100644 index 499f94b32..000000000 --- a/Source/WebCore/html/HTMLBaseFontElement.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 1999 Lars Knoll (knoll@kde.org) - * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006, 2009, 2010 Apple Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#include "config.h" -#include "HTMLBaseFontElement.h" - -#include "HTMLNames.h" - -namespace WebCore { - -using namespace HTMLNames; - -inline HTMLBaseFontElement::HTMLBaseFontElement(const QualifiedName& tagName, Document& document) - : HTMLElement(tagName, document) -{ - ASSERT(hasTagName(basefontTag)); -} - -PassRefPtr HTMLBaseFontElement::create(const QualifiedName& tagName, Document& document) -{ - return adoptRef(new HTMLBaseFontElement(tagName, document)); -} - -} diff --git a/Source/WebCore/html/HTMLBaseFontElement.h b/Source/WebCore/html/HTMLBaseFontElement.h deleted file mode 100644 index 328f66f43..000000000 --- a/Source/WebCore/html/HTMLBaseFontElement.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 1999 Lars Knoll (knoll@kde.org) - * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006, 2009, 2010 Apple Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef HTMLBaseFontElement_h -#define HTMLBaseFontElement_h - -#include "HTMLElement.h" - -namespace WebCore { - -class HTMLBaseFontElement final : public HTMLElement { -public: - static PassRefPtr create(const QualifiedName&, Document&); - -private: - HTMLBaseFontElement(const QualifiedName&, Document&); -}; - -} // namespace - -#endif diff --git a/Source/WebCore/html/HTMLBaseFontElement.idl b/Source/WebCore/html/HTMLBaseFontElement.idl deleted file mode 100644 index 99bb33096..000000000 --- a/Source/WebCore/html/HTMLBaseFontElement.idl +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2006, 2009, 2010 Apple Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -interface HTMLBaseFontElement : HTMLElement { - [Reflect] attribute DOMString color; - [Reflect] attribute DOMString face; -#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C - [Reflect] attribute DOMString size; // this changed to a long, but our existing API is a string -#else - [Reflect] attribute long size; -#endif -}; diff --git a/Source/WebCore/html/HTMLBodyElement.cpp b/Source/WebCore/html/HTMLBodyElement.cpp index 9da1410fe..b1ee9c4c2 100644 --- a/Source/WebCore/html/HTMLBodyElement.cpp +++ b/Source/WebCore/html/HTMLBodyElement.cpp @@ -3,7 +3,7 @@ * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann (hausmann@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. + * Copyright (C) 2004-2017 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -24,18 +24,20 @@ #include "config.h" #include "HTMLBodyElement.h" -#include "Attribute.h" #include "CSSImageValue.h" #include "CSSParser.h" #include "CSSValueKeywords.h" +#include "DOMWindow.h" +#include "DOMWrapperWorld.h" #include "EventNames.h" #include "Frame.h" #include "FrameView.h" -#include "HTMLFrameElementBase.h" +#include "HTMLFrameElement.h" +#include "HTMLIFrameElement.h" #include "HTMLNames.h" #include "HTMLParserIdioms.h" -#include "Page.h" #include "StyleProperties.h" +#include namespace WebCore { @@ -47,14 +49,21 @@ HTMLBodyElement::HTMLBodyElement(const QualifiedName& tagName, Document& documen ASSERT(hasTagName(bodyTag)); } -PassRefPtr HTMLBodyElement::create(Document& document) +bool HTMLBodyElement::isFirstBodyElementOfDocument() const { - return adoptRef(new HTMLBodyElement(bodyTag, document)); + // By spec http://dev.w3.org/csswg/cssom-view/#the-html-body-element + // "The HTML body element is the first body HTML element child of the root HTML element html." + return document().body() == this; } -PassRefPtr HTMLBodyElement::create(const QualifiedName& tagName, Document& document) +Ref HTMLBodyElement::create(Document& document) { - return adoptRef(new HTMLBodyElement(tagName, document)); + return adoptRef(*new HTMLBodyElement(bodyTag, document)); +} + +Ref HTMLBodyElement::create(const QualifiedName& tagName, Document& document) +{ + return adoptRef(*new HTMLBodyElement(tagName, document)); } HTMLBodyElement::~HTMLBodyElement() @@ -73,9 +82,9 @@ void HTMLBodyElement::collectStyleForPresentationAttribute(const QualifiedName& if (name == backgroundAttr) { String url = stripLeadingAndTrailingHTMLSpaces(value); if (!url.isEmpty()) { - auto imageValue = CSSImageValue::create(document().completeURL(url).string()); + auto imageValue = CSSImageValue::create(document().completeURL(url)); imageValue.get().setInitiator(localName()); - style.setProperty(CSSProperty(CSSPropertyBackgroundImage, std::move(imageValue))); + style.setProperty(CSSProperty(CSSPropertyBackgroundImage, WTFMove(imageValue))); } } else if (name == marginwidthAttr || name == leftmarginAttr) { addHTMLLengthToStyle(style, CSSPropertyMarginRight, value); @@ -88,12 +97,56 @@ void HTMLBodyElement::collectStyleForPresentationAttribute(const QualifiedName& } else if (name == textAttr) { addHTMLColorToStyle(style, CSSPropertyColor, value); } else if (name == bgpropertiesAttr) { - if (equalIgnoringCase(value, "fixed")) + if (equalLettersIgnoringASCIICase(value, "fixed")) addPropertyToPresentationAttributeStyle(style, CSSPropertyBackgroundAttachment, CSSValueFixed); } else HTMLElement::collectStyleForPresentationAttribute(name, value, style); } +HTMLElement::EventHandlerNameMap HTMLBodyElement::createWindowEventHandlerNameMap() +{ + static const QualifiedName* const table[] = { + &onbeforeunloadAttr, + &onblurAttr, + &onerrorAttr, + &onfocusAttr, + &onfocusinAttr, + &onfocusoutAttr, + &onhashchangeAttr, + &onlanguagechangeAttr, + &onloadAttr, + &onmessageAttr, + &onofflineAttr, + &ononlineAttr, + &onorientationchangeAttr, + &onpagehideAttr, + &onpageshowAttr, + &onpopstateAttr, + &onresizeAttr, + &onscrollAttr, + &onstorageAttr, + &onunloadAttr, + &onwebkitmouseforcechangedAttr, + &onwebkitmouseforcedownAttr, + &onwebkitmouseforceupAttr, + &onwebkitmouseforcewillbeginAttr, + &onwebkitwillrevealbottomAttr, + &onwebkitwillrevealleftAttr, + &onwebkitwillrevealrightAttr, + &onwebkitwillrevealtopAttr, + }; + + EventHandlerNameMap map; + populateEventHandlerNameMap(map, table); + return map; +} + +const AtomicString& HTMLBodyElement::eventNameForWindowEventHandlerAttribute(const QualifiedName& attributeName) +{ + static NeverDestroyed map = createWindowEventHandlerNameMap(); + return eventNameForEventHandlerAttribute(attributeName, map.get()); +} + void HTMLBodyElement::parseAttribute(const QualifiedName& name, const AtomicString& value) { if (name == vlinkAttr || name == alinkAttr || name == linkAttr) { @@ -105,8 +158,8 @@ void HTMLBodyElement::parseAttribute(const QualifiedName& name, const AtomicStri else document().resetActiveLinkColor(); } else { - RGBA32 color; - if (CSSParser::parseColor(color, value, !document().inQuirksMode())) { + Color color = CSSParser::parseColor(value, !document().inQuirksMode()); + if (color.isValid()) { if (name == linkAttr) document().setLinkColor(color); else if (name == vlinkAttr) @@ -116,64 +169,48 @@ void HTMLBodyElement::parseAttribute(const QualifiedName& name, const AtomicStri } } - setNeedsStyleRecalc(); - } else if (name == onloadAttr) - document().setWindowAttributeEventListener(eventNames().loadEvent, name, value); - else if (name == onbeforeunloadAttr) - document().setWindowAttributeEventListener(eventNames().beforeunloadEvent, name, value); - else if (name == onunloadAttr) - document().setWindowAttributeEventListener(eventNames().unloadEvent, name, value); - else if (name == onpagehideAttr) - document().setWindowAttributeEventListener(eventNames().pagehideEvent, name, value); - else if (name == onpageshowAttr) - document().setWindowAttributeEventListener(eventNames().pageshowEvent, name, value); - else if (name == onpopstateAttr) - document().setWindowAttributeEventListener(eventNames().popstateEvent, name, value); - else if (name == onblurAttr) - document().setWindowAttributeEventListener(eventNames().blurEvent, name, value); - else if (name == onfocusAttr) - document().setWindowAttributeEventListener(eventNames().focusEvent, name, value); -#if ENABLE(ORIENTATION_EVENTS) - else if (name == onorientationchangeAttr) - document().setWindowAttributeEventListener(eventNames().orientationchangeEvent, name, value); -#endif - else if (name == onhashchangeAttr) - document().setWindowAttributeEventListener(eventNames().hashchangeEvent, name, value); - else if (name == onresizeAttr) - document().setWindowAttributeEventListener(eventNames().resizeEvent, name, value); - else if (name == onscrollAttr) - document().setWindowAttributeEventListener(eventNames().scrollEvent, name, value); - else if (name == onselectionchangeAttr) - document().setAttributeEventListener(eventNames().selectionchangeEvent, name, value); - else if (name == onstorageAttr) - document().setWindowAttributeEventListener(eventNames().storageEvent, name, value); - else if (name == ononlineAttr) - document().setWindowAttributeEventListener(eventNames().onlineEvent, name, value); - else if (name == onofflineAttr) - document().setWindowAttributeEventListener(eventNames().offlineEvent, name, value); - else - HTMLElement::parseAttribute(name, value); + invalidateStyleForSubtree(); + return; + } + + if (name == onselectionchangeAttr) { + document().setAttributeEventListener(eventNames().selectionchangeEvent, name, value, mainThreadNormalWorld()); + return; + } + + auto& eventName = eventNameForWindowEventHandlerAttribute(name); + if (!eventName.isNull()) { + document().setWindowAttributeEventListener(eventName, name, value, mainThreadNormalWorld()); + return; + } + + HTMLElement::parseAttribute(name, value); } Node::InsertionNotificationRequest HTMLBodyElement::insertedInto(ContainerNode& insertionPoint) { HTMLElement::insertedInto(insertionPoint); - if (!insertionPoint.inDocument()) + if (!insertionPoint.isConnected()) return InsertionDone; // FIXME: It's surprising this is web compatible since it means a marginwidth and marginheight attribute can // magically appear on the of all documents embedded through