1 | /* |
2 | * Copyright (C) 2009, Martin Robinson |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
17 | */ |
18 | |
19 | #pragma once |
20 | |
21 | #include "Image.h" |
22 | #include <wtf/HashMap.h> |
23 | #include <wtf/RefCounted.h> |
24 | #include <wtf/URL.h> |
25 | #include <wtf/text/StringHash.h> |
26 | |
27 | namespace WebCore { |
28 | |
29 | class SelectionData : public RefCounted<SelectionData> { |
30 | WTF_MAKE_FAST_ALLOCATED; |
31 | public: |
32 | static Ref<SelectionData> create() |
33 | { |
34 | return adoptRef(*new SelectionData); |
35 | } |
36 | |
37 | void setText(const String&); |
38 | const String& text() const { return m_text; } |
39 | bool hasText() const { return !m_text.isEmpty(); } |
40 | void clearText() { m_text = emptyString(); } |
41 | |
42 | void setMarkup(const String& newMarkup) { m_markup = newMarkup; } |
43 | const String& markup() const { return m_markup; } |
44 | bool hasMarkup() const { return !m_markup.isEmpty(); } |
45 | void clearMarkup() { m_markup = emptyString(); } |
46 | |
47 | void setURL(const URL&, const String&); |
48 | const URL& url() const { return m_url; } |
49 | const String& urlLabel() const; |
50 | bool hasURL() const { return !m_url.isEmpty() && m_url.isValid(); } |
51 | void clearURL() { m_url = URL(); } |
52 | |
53 | void setURIList(const String&); |
54 | const String& uriList() const { return m_uriList; } |
55 | const Vector<String>& filenames() const { return m_filenames; } |
56 | bool hasURIList() const { return !m_uriList.isEmpty(); } |
57 | bool hasFilenames() const { return !m_filenames.isEmpty(); } |
58 | void clearURIList() { m_uriList = emptyString(); } |
59 | |
60 | void setImage(Image* newImage) { m_image = newImage; } |
61 | Image* image() const { return m_image.get(); } |
62 | bool hasImage() const { return m_image; } |
63 | void clearImage() { m_image = nullptr; } |
64 | |
65 | void setUnknownTypeData(const String& type, const String& data) { m_unknownTypeData.set(type, data); } |
66 | String unknownTypeData(const String& type) const { return m_unknownTypeData.get(type); } |
67 | const HashMap<String, String>& unknownTypes() const { return m_unknownTypeData; } |
68 | bool hasUnknownTypeData() const { return !m_unknownTypeData.isEmpty(); } |
69 | |
70 | void setCanSmartReplace(bool canSmartReplace) { m_canSmartReplace = canSmartReplace; } |
71 | bool canSmartReplace() const { return m_canSmartReplace; } |
72 | |
73 | void clearAll(); |
74 | void clearAllExceptFilenames(); |
75 | |
76 | private: |
77 | String m_text; |
78 | String m_markup; |
79 | URL m_url; |
80 | String m_uriList; |
81 | Vector<String> m_filenames; |
82 | RefPtr<Image> m_image; |
83 | HashMap<String, String> m_unknownTypeData; |
84 | bool m_canSmartReplace { false }; |
85 | }; |
86 | |
87 | } // namespace WebCore |
88 | |