diff options
author | Leon Clarke <leonclarke@google.com> | 2010-06-03 14:33:32 +0100 |
---|---|---|
committer | Leon Clarke <leonclarke@google.com> | 2010-06-08 12:24:51 +0100 |
commit | 5af96e2c7b73ebc627c6894727826a7576d31758 (patch) | |
tree | f9d5e6f6175ccd7e3d14de9b290f08937a0d17ba /WebCore/platform/gtk | |
parent | 8cc4fcf4f6adcbc0e0aebfc24fbad9a4cddf2cfb (diff) | |
download | external_webkit-5af96e2c7b73ebc627c6894727826a7576d31758.zip external_webkit-5af96e2c7b73ebc627c6894727826a7576d31758.tar.gz external_webkit-5af96e2c7b73ebc627c6894727826a7576d31758.tar.bz2 |
Merge webkit.org at r60469 : Initial merge by git.
Change-Id: I66a0047aa2af802f66bb0c7f2a8b02247a596234
Diffstat (limited to 'WebCore/platform/gtk')
-rw-r--r-- | WebCore/platform/gtk/FileSystemGtk.cpp | 1 | ||||
-rw-r--r-- | WebCore/platform/gtk/PasteboardGtk.cpp | 118 | ||||
-rw-r--r-- | WebCore/platform/gtk/RenderThemeGtk.cpp | 27 | ||||
-rw-r--r-- | WebCore/platform/gtk/RenderThemeGtk.h | 5 | ||||
-rw-r--r-- | WebCore/platform/gtk/ScrollbarGtk.cpp | 1 |
5 files changed, 65 insertions, 87 deletions
diff --git a/WebCore/platform/gtk/FileSystemGtk.cpp b/WebCore/platform/gtk/FileSystemGtk.cpp index 6cad4d9..ddcf0aa 100644 --- a/WebCore/platform/gtk/FileSystemGtk.cpp +++ b/WebCore/platform/gtk/FileSystemGtk.cpp @@ -258,6 +258,7 @@ int writeToFile(PlatformFileHandle handle, const char* data, int length) if (bytesWritten < 0) return -1; totalBytesWritten += bytesWritten; + data += bytesWritten; } return totalBytesWritten; diff --git a/WebCore/platform/gtk/PasteboardGtk.cpp b/WebCore/platform/gtk/PasteboardGtk.cpp index 9e7b23a..599f7da 100644 --- a/WebCore/platform/gtk/PasteboardGtk.cpp +++ b/WebCore/platform/gtk/PasteboardGtk.cpp @@ -20,6 +20,7 @@ #include "config.h" #include "Pasteboard.h" +#include "DataObjectGtk.h" #include "DocumentFragment.h" #include "Frame.h" #include "NotImplemented.h" @@ -29,50 +30,13 @@ #include "RenderImage.h" #include "KURL.h" #include "markup.h" +#include <wtf/gobject/GRefPtr.h> #include <wtf/text/CString.h> #include <gtk/gtk.h> namespace WebCore { -class PasteboardSelectionData { -public: - PasteboardSelectionData(gchar* text, gchar* markup) - : m_text(text) - , m_markup(markup) { } - - ~PasteboardSelectionData() { - g_free(m_text); - g_free(m_markup); - } - - const gchar* text() const { return m_text; } - const gchar* markup() const { return m_markup; } - -private: - gchar* m_text; - gchar* m_markup; -}; - -static void clipboard_get_contents_cb(GtkClipboard *clipboard, GtkSelectionData *selection_data, - guint info, gpointer data) { - PasteboardSelectionData* clipboardData = reinterpret_cast<PasteboardSelectionData*>(data); - ASSERT(clipboardData); - if (info == Pasteboard::generalPasteboard()->helper()->getIdForTargetType(PasteboardHelper::TargetTypeMarkup)) - gtk_selection_data_set(selection_data, selection_data->target, 8, - reinterpret_cast<const guchar*>(clipboardData->markup()), - strlen(clipboardData->markup())); - else - gtk_selection_data_set_text(selection_data, clipboardData->text(), -1); -} - -static void clipboard_clear_contents_cb(GtkClipboard *clipboard, gpointer data) { - PasteboardSelectionData* clipboardData = reinterpret_cast<PasteboardSelectionData*>(data); - ASSERT(clipboardData); - delete clipboardData; -} - - Pasteboard* Pasteboard::generalPasteboard() { static Pasteboard* pasteboard = new Pasteboard(); @@ -102,22 +66,18 @@ void Pasteboard::setHelper(PasteboardHelper* helper) void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame) { GtkClipboard* clipboard = m_helper->getClipboard(frame); - gchar* text = g_strdup(frame->selectedText().utf8().data()); - gchar* markup = g_strdup(createMarkup(selectedRange, 0, AnnotateForInterchange).utf8().data()); - PasteboardSelectionData* data = new PasteboardSelectionData(text, markup); - - gint n_targets; - GtkTargetEntry* targets = gtk_target_table_new_from_list(m_helper->targetList(), &n_targets); - gtk_clipboard_set_with_data(clipboard, targets, n_targets, - clipboard_get_contents_cb, clipboard_clear_contents_cb, data); - gtk_target_table_free(targets, n_targets); + DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard); + dataObject->setText(frame->selectedText()); + dataObject->setMarkup(createMarkup(selectedRange, 0, AnnotateForInterchange)); + m_helper->writeClipboardContents(clipboard); } void Pasteboard::writePlainText(const String& text) { - CString utf8 = text.utf8(); GtkClipboard* clipboard = gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD); - gtk_clipboard_set_text(clipboard, utf8.data(), utf8.length()); + DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard); + dataObject->setText(text); + m_helper->writeClipboardContents(clipboard); } void Pasteboard::writeURL(const KURL& url, const String&, Frame* frame) @@ -126,10 +86,12 @@ void Pasteboard::writeURL(const KURL& url, const String&, Frame* frame) return; GtkClipboard* clipboard = m_helper->getClipboard(frame); - GtkClipboard* primary = m_helper->getPrimarySelectionClipboard(frame); - CString utf8 = url.string().utf8(); - gtk_clipboard_set_text(clipboard, utf8.data(), utf8.length()); - gtk_clipboard_set_text(primary, utf8.data(), utf8.length()); + DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard); + + Vector<KURL> uriList; + uriList.append(url); + dataObject->setURIList(uriList); + m_helper->writeClipboardContents(clipboard); } void Pasteboard::writeImage(Node* node, const KURL&, const String&) @@ -144,16 +106,15 @@ void Pasteboard::writeImage(Node* node, const KURL&, const String&) Image* image = cachedImage->image(); ASSERT(image); - GdkPixbuf* pixbuf = image->getGdkPixbuf(); - gtk_clipboard_set_image(clipboard, pixbuf); - g_object_unref(pixbuf); + GRefPtr<GdkPixbuf> pixbuf = adoptGRef(image->getGdkPixbuf()); + DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard); + dataObject->setImage(pixbuf.get()); + m_helper->writeClipboardContents(clipboard); } void Pasteboard::clear() { - GtkClipboard* clipboard = gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD); - - gtk_clipboard_clear(clipboard); + gtk_clipboard_clear(gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD)); } bool Pasteboard::canSmartReplace() @@ -165,33 +126,24 @@ bool Pasteboard::canSmartReplace() PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { - GdkAtom textHtml = gdk_atom_intern_static_string("text/html"); GtkClipboard* clipboard = m_helper->getCurrentClipboard(frame); + DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard); + m_helper->getClipboardContents(clipboard); + chosePlainText = false; - if (GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, textHtml)) { - ASSERT(data->data); - RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("text/plain", "UTF-8", true); - String html = decoder->decode(reinterpret_cast<char*>(data->data), data->length); - html += decoder->flush(); - gtk_selection_data_free(data); - - if (!html.isEmpty()) { - RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), html, "", FragmentScriptingNotAllowed); - if (fragment) - return fragment.release(); - } + if (dataObject->hasMarkup()) { + RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), dataObject->markup(), "", FragmentScriptingNotAllowed); + if (fragment) + return fragment.release(); } if (!allowPlainText) return 0; - if (gchar* utf8 = gtk_clipboard_wait_for_text(clipboard)) { - String text = String::fromUTF8(utf8); - g_free(utf8); - + if (dataObject->hasText()) { chosePlainText = true; - RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), text); + RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), dataObject->text()); if (fragment) return fragment.release(); } @@ -202,16 +154,10 @@ PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefP String Pasteboard::plainText(Frame* frame) { GtkClipboard* clipboard = m_helper->getCurrentClipboard(frame); + DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard); - gchar* utf8 = gtk_clipboard_wait_for_text(clipboard); - - if (!utf8) - return String(); - - String text = String::fromUTF8(utf8); - g_free(utf8); - - return text; + m_helper->getClipboardContents(clipboard); + return dataObject->text(); } } diff --git a/WebCore/platform/gtk/RenderThemeGtk.cpp b/WebCore/platform/gtk/RenderThemeGtk.cpp index aec50f6..c572e77 100644 --- a/WebCore/platform/gtk/RenderThemeGtk.cpp +++ b/WebCore/platform/gtk/RenderThemeGtk.cpp @@ -25,6 +25,7 @@ #include "RenderThemeGtk.h" #include "AffineTransform.h" +#include "CSSValueKeywords.h" #include "GOwnPtr.h" #include "Gradient.h" #include "GraphicsContext.h" @@ -126,6 +127,7 @@ static int mozGtkRefCount = 0; RenderThemeGtk::RenderThemeGtk() : m_gtkWindow(0) , m_gtkContainer(0) + , m_gtkButton(0) , m_gtkEntry(0) , m_gtkTreeView(0) , m_panelColor(Color::white) @@ -605,6 +607,18 @@ void RenderThemeGtk::systemFont(int, FontDescription&) const notImplemented(); } +Color RenderThemeGtk::systemColor(int cssValueId) const +{ + switch (cssValueId) { + case CSSValueButtontext: + return Color(gtkButton()->style->fg[GTK_STATE_NORMAL]); + case CSSValueCaptiontext: + return Color(gtkEntry()->style->fg[GTK_STATE_NORMAL]); + default: + return RenderTheme::systemColor(cssValueId); + } +} + static void gtkStyleSetCallback(GtkWidget* widget, GtkStyle* previous, RenderTheme* renderTheme) { // FIXME: Make sure this function doesn't get called many times for a single GTK+ style change signal. @@ -625,6 +639,19 @@ GtkContainer* RenderThemeGtk::gtkContainer() const return m_gtkContainer; } +GtkWidget* RenderThemeGtk::gtkButton() const +{ + if (m_gtkButton) + return m_gtkButton; + + m_gtkButton = gtk_button_new(); + g_signal_connect(m_gtkButton, "style-set", G_CALLBACK(gtkStyleSetCallback), const_cast<RenderThemeGtk*>(this)); + gtk_container_add(gtkContainer(), m_gtkButton); + gtk_widget_realize(m_gtkButton); + + return m_gtkButton; +} + GtkWidget* RenderThemeGtk::gtkEntry() const { if (m_gtkEntry) diff --git a/WebCore/platform/gtk/RenderThemeGtk.h b/WebCore/platform/gtk/RenderThemeGtk.h index e9185a5..b62b41c 100644 --- a/WebCore/platform/gtk/RenderThemeGtk.h +++ b/WebCore/platform/gtk/RenderThemeGtk.h @@ -82,8 +82,9 @@ public: virtual void platformColorsDidChange(); - // System fonts. + // System fonts and colors. virtual void systemFont(int propId, FontDescription&) const; + virtual Color systemColor(int cssValueId) const; #if ENABLE(VIDEO) virtual String extraMediaControlsStyleSheet(); @@ -138,6 +139,7 @@ private: /* * hold the state */ + GtkWidget* gtkButton() const; GtkWidget* gtkEntry() const; GtkWidget* gtkTreeView() const; @@ -149,6 +151,7 @@ private: mutable GtkWidget* m_gtkWindow; mutable GtkContainer* m_gtkContainer; + mutable GtkWidget* m_gtkButton; mutable GtkWidget* m_gtkEntry; mutable GtkWidget* m_gtkTreeView; diff --git a/WebCore/platform/gtk/ScrollbarGtk.cpp b/WebCore/platform/gtk/ScrollbarGtk.cpp index 00cbcf0..3d4cc47 100644 --- a/WebCore/platform/gtk/ScrollbarGtk.cpp +++ b/WebCore/platform/gtk/ScrollbarGtk.cpp @@ -20,6 +20,7 @@ #include "config.h" #include "ScrollbarGtk.h" +#include "GtkVersioning.h" #include "IntRect.h" #include "GraphicsContext.h" #include "FrameView.h" |