1/*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * Copyright (C) 2011-2018 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#pragma once
33
34#include "BaseClickableWithKeyInputType.h"
35#include "FileChooser.h"
36#include "FileIconLoader.h"
37#include <wtf/RefPtr.h>
38
39namespace WebCore {
40
41class DragData;
42class FileList;
43class FileListCreator;
44class Icon;
45
46class FileInputType final : public BaseClickableWithKeyInputType, private FileChooserClient, private FileIconLoaderClient {
47public:
48 explicit FileInputType(HTMLInputElement&);
49 virtual ~FileInputType();
50
51 static Vector<FileChooserFileInfo> filesFromFormControlState(const FormControlState&);
52
53private:
54 const AtomicString& formControlType() const final;
55 FormControlState saveFormControlState() const final;
56 void restoreFormControlState(const FormControlState&) final;
57 bool appendFormData(DOMFormData&, bool) const final;
58 bool valueMissing(const String&) const final;
59 String valueMissingText() const final;
60 void handleDOMActivateEvent(Event&) final;
61 RenderPtr<RenderElement> createInputRenderer(RenderStyle&&) final;
62 bool canSetStringValue() const final;
63 FileList* files() final;
64 void setFiles(RefPtr<FileList>&&) final;
65 enum class RequestIcon { Yes, No };
66 void setFiles(RefPtr<FileList>&&, RequestIcon);
67 String displayString() const final;
68 bool canSetValue(const String&) final;
69 bool getTypeSpecificValue(String&) final; // Checked first, before internal storage or the value attribute.
70 void setValue(const String&, bool valueChanged, TextFieldEventBehavior) final;
71
72#if ENABLE(DRAG_SUPPORT)
73 bool receiveDroppedFiles(const DragData&) final;
74#endif
75
76 Icon* icon() const final;
77 bool isFileUpload() const final;
78 void createShadowSubtree() final;
79 void disabledStateChanged() final;
80 void attributeChanged(const QualifiedName&) final;
81 String defaultToolTip() const final;
82
83 void filesChosen(const Vector<FileChooserFileInfo>&, const String& displayString = { }, Icon* = nullptr) final;
84
85 // FileIconLoaderClient implementation.
86 void iconLoaded(RefPtr<Icon>&&) final;
87
88 void requestIcon(const Vector<String>&);
89
90 void applyFileChooserSettings(const FileChooserSettings&);
91
92 bool allowsDirectories() const;
93
94 RefPtr<FileChooser> m_fileChooser;
95 std::unique_ptr<FileIconLoader> m_fileIconLoader;
96
97 Ref<FileList> m_fileList;
98 RefPtr<FileListCreator> m_fileListCreator;
99 RefPtr<Icon> m_icon;
100 String m_displayString;
101};
102
103} // namespace WebCore
104