diff options
author | Steve Block <steveblock@google.com> | 2010-02-02 14:57:50 +0000 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-02-04 15:06:55 +0000 |
commit | d0825bca7fe65beaee391d30da42e937db621564 (patch) | |
tree | 7461c49eb5844ffd1f35d1ba2c8b7584c1620823 /WebCore/platform/gtk/DataObjectGtk.cpp | |
parent | 3db770bd97c5a59b6c7574ca80a39e5a51c1defd (diff) | |
download | external_webkit-d0825bca7fe65beaee391d30da42e937db621564.zip external_webkit-d0825bca7fe65beaee391d30da42e937db621564.tar.gz external_webkit-d0825bca7fe65beaee391d30da42e937db621564.tar.bz2 |
Merge webkit.org at r54127 : Initial merge by git
Change-Id: Ib661abb595522f50ea406f72d3a0ce17f7193c82
Diffstat (limited to 'WebCore/platform/gtk/DataObjectGtk.cpp')
-rw-r--r-- | WebCore/platform/gtk/DataObjectGtk.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/WebCore/platform/gtk/DataObjectGtk.cpp b/WebCore/platform/gtk/DataObjectGtk.cpp new file mode 100644 index 0000000..900fe8e --- /dev/null +++ b/WebCore/platform/gtk/DataObjectGtk.cpp @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2009, Martin Robinson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "DataObjectGtk.h" + +#include "markup.h" +#include <gtk/gtk.h> + +namespace WebCore { + +String DataObjectGtk::text() +{ + if (m_range) + return m_range->text(); + return m_text; +} + +String DataObjectGtk::markup() +{ + if (m_range) + createMarkup(m_range.get(), 0, AnnotateForInterchange); + return m_markup; +} + +void DataObjectGtk::setText(const String& newText) +{ + m_range = 0; + m_text = newText; +} + +void DataObjectGtk::setMarkup(const String& newMarkup) +{ + m_range = 0; + m_markup = newMarkup; +} + +Vector<String> DataObjectGtk::files() +{ + Vector<KURL> uris(uriList()); + Vector<String> files; + + for (size_t i = 0; i < uris.size(); i++) { + KURL& uri = uris[0]; + if (!uri.isValid() || !uri.isLocalFile()) + continue; + + files.append(uri.string()); + } + + return files; +} + +String DataObjectGtk::url() +{ + Vector<KURL> uris(uriList()); + for (size_t i = 0; i < uris.size(); i++) { + KURL& uri = uris[0]; + if (uri.isValid()) + return uri; + } + + return String(); +} + +String DataObjectGtk::urlLabel() +{ + if (hasText()) + return text(); + + if (hasURL()) + return url(); + + return String(); +} + +bool DataObjectGtk::hasURL() +{ + return !url().isEmpty(); +} + +void DataObjectGtk::clear() +{ + m_text = ""; + m_markup = ""; + m_uriList.clear(); + m_image = 0; + m_range = 0; +} + +DataObjectGtk* DataObjectGtk::forClipboard(GtkClipboard* clipboard) +{ + static HashMap<GtkClipboard*, RefPtr<DataObjectGtk> > objectMap; + + if (!objectMap.contains(clipboard)) { + RefPtr<DataObjectGtk> dataObject = DataObjectGtk::create(); + objectMap.set(clipboard, dataObject); + return dataObject.get(); + } + + HashMap<GtkClipboard*, RefPtr<DataObjectGtk> >::iterator it = objectMap.find(clipboard); + return it->second.get(); +} + +} |