| Differences between
and this patch
- a/Source/WebCore/ChangeLog +70 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2016-09-14  Carlos Garnacho <carlosg@gnome.org>
2
3
        [GTK][Wayland] Implement clipboard support
4
        https://bugs.webkit.org/show_bug.cgi?id=146574
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Implement PlatformPasteboard in the GTK+ platform, and move Pasteboard
9
        to using PasteboardStrategy so clipboard management is left to the
10
        UIProcess.
11
12
        DataObjectGtk is still used in the Pasteboard GTK implementation, it's
13
        now just never backed by a GtkClipboard, this object is instead
14
        serialized through PasteboardStrategy, so the UIProcess side can mirror
15
        the content in a GtkClipboard-backed DataObjectGtk, which is then
16
        exposed to the windowing through PlatformPasteboard/PasteboardHelper.
17
18
        When requesting clipboard content, it works similarly, the UIProcess
19
        side first updates its DataObjectGtk, which is then mirrored by the
20
        WebProcess through the PasteboardStrategy requests.
21
22
        * PlatformGTK.cmake: Added PlatformPasteboardGtk.cpp
23
        * editing/gtk/EditorGtk.cpp:
24
        (WebCore::Editor::writeSelectionToPasteboard): Eliminate usage of
25
        PasteboardWebContent callback argument. This is done differently as
26
        we have to signal back the WebProcess.
27
        * platform/Pasteboard.h: Cleaned up of direct GTK+ dependency.
28
        * platform/PasteboardStrategy.h: Added plumbing towards the pasteboard
29
        proxy.
30
        * platform/PlatformPasteboard.h:
31
        * platform/gtk/DataObjectGtk.cpp:
32
        (WebCore::DataObjectGtk::clearAllExceptFilenames): Clear the "smart
33
        paste" flag if set, now that this is DataObjectGtk data.
34
        * platform/gtk/DataObjectGtk.h:
35
        (WebCore::DataObjectGtk::canSmartReplace):
36
        (WebCore::DataObjectGtk::setCanSmartReplace): Added functions, in order
37
        to flag whether a DataObjectGtk has the "smart paste" feature enabled
38
        or not.
39
        * platform/gtk/PasteboardGtk.cpp:
40
        (WebCore::Pasteboard::createForCopyAndPaste):
41
        (WebCore::Pasteboard::createForGlobalSelection):
42
        (WebCore::Pasteboard::Pasteboard):
43
        (WebCore::Pasteboard::writeToClipboard):
44
        (WebCore::Pasteboard::readFromClipboard):
45
        (WebCore::Pasteboard::writePlainText):
46
        (WebCore::Pasteboard::write):
47
        (WebCore::Pasteboard::writePasteboard):
48
        (WebCore::Pasteboard::clear):
49
        (WebCore::Pasteboard::canSmartReplace):
50
        (WebCore::Pasteboard::read):
51
        (WebCore::Pasteboard::hasData):
52
        (WebCore::Pasteboard::types):
53
        (WebCore::Pasteboard::readString):
54
        (WebCore::Pasteboard::readFilenames): Made to use the
55
        PasteboardStrategy instead of PasteboardHelper/GTK+ API.
56
        * platform/gtk/PasteboardHelper.cpp:
57
        (WebCore::PasteboardHelper::~PasteboardHelper):
58
        (WebCore::ClipboardSetData::ClipboardSetData):
59
        (WebCore::clearClipboardContentsCallback):
60
        (WebCore::PasteboardHelper::writeClipboardContents): Remove the GClosure
61
        to notify whether the global selection has been replaced. Use std:function
62
        instead. Remove SmartPasteInclusion argument, now figured out through
63
        DataObjectGtk canSmartPaste() member.
64
        * platform/gtk/PasteboardHelper.h:
65
        * platform/gtk/PlatformPasteboardGtk.cpp: Added.
66
        (WebCore::PlatformPasteboard::PlatformPasteboard):
67
        (WebCore::PlatformPasteboard::writeToClipboard):
68
        (WebCore::PlatformPasteboard::readFromClipboard): Implemented
69
        PlatformPasteboard using PasteboardHelper/GTK+ API.
70
1
2016-09-04  Antti Koivisto  <antti@apple.com>
71
2016-09-04  Antti Koivisto  <antti@apple.com>
2
72
3
        Reverse ownership relation of StyleCachedImage and CSSImageValue
73
        Reverse ownership relation of StyleCachedImage and CSSImageValue
- a/Source/WebCore/PlatformGTK.cmake +1 lines
Lines 221-226 list(APPEND WebCorePlatformGTK_SOURCES a/Source/WebCore/PlatformGTK.cmake_sec1
221
    platform/gtk/PasteboardHelper.cpp
221
    platform/gtk/PasteboardHelper.cpp
222
    platform/gtk/PlatformKeyboardEventGtk.cpp
222
    platform/gtk/PlatformKeyboardEventGtk.cpp
223
    platform/gtk/PlatformMouseEventGtk.cpp
223
    platform/gtk/PlatformMouseEventGtk.cpp
224
    platform/gtk/PlatformPasteboardGtk.cpp
224
    platform/gtk/PlatformScreenGtk.cpp
225
    platform/gtk/PlatformScreenGtk.cpp
225
    platform/gtk/PlatformWheelEventGtk.cpp
226
    platform/gtk/PlatformWheelEventGtk.cpp
226
    platform/gtk/RenderThemeGadget.cpp
227
    platform/gtk/RenderThemeGadget.cpp
- a/Source/WebCore/editing/gtk/EditorGtk.cpp -1 lines
Lines 125-131 void Editor::writeSelectionToPasteboard(Pasteboard& pasteboard) a/Source/WebCore/editing/gtk/EditorGtk.cpp_sec1
125
    pasteboardContent.canSmartCopyOrDelete = canSmartCopyOrDelete();
125
    pasteboardContent.canSmartCopyOrDelete = canSmartCopyOrDelete();
126
    pasteboardContent.text = selectedTextForDataTransfer();
126
    pasteboardContent.text = selectedTextForDataTransfer();
127
    pasteboardContent.markup = createMarkup(*selectedRange(), nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
127
    pasteboardContent.markup = createMarkup(*selectedRange(), nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
128
    pasteboardContent.callback = nullptr;
129
    pasteboard.write(pasteboardContent);
128
    pasteboard.write(pasteboardContent);
130
}
129
}
131
130
- a/Source/WebCore/platform/Pasteboard.h -8 / +5 lines
Lines 32-42 a/Source/WebCore/platform/Pasteboard.h_sec1
32
#include <wtf/Vector.h>
32
#include <wtf/Vector.h>
33
#include <wtf/text/WTFString.h>
33
#include <wtf/text/WTFString.h>
34
34
35
#if PLATFORM(GTK)
36
typedef struct _GtkClipboard GtkClipboard;
37
#include <wtf/glib/GRefPtr.h>
38
#endif
39
40
#if PLATFORM(IOS)
35
#if PLATFORM(IOS)
41
OBJC_CLASS NSArray;
36
OBJC_CLASS NSArray;
42
OBJC_CLASS NSString;
37
OBJC_CLASS NSString;
Lines 83-89 struct PasteboardWebContent { a/Source/WebCore/platform/Pasteboard.h_sec2
83
    bool canSmartCopyOrDelete;
78
    bool canSmartCopyOrDelete;
84
    String text;
79
    String text;
85
    String markup;
80
    String markup;
86
    GRefPtr<GClosure> callback;
87
#endif
81
#endif
88
};
82
};
89
83
Lines 143-150 public: a/Source/WebCore/platform/Pasteboard.h_sec3
143
    ~Pasteboard();
137
    ~Pasteboard();
144
138
145
#if PLATFORM(GTK)
139
#if PLATFORM(GTK)
140
    explicit Pasteboard(const String& name);
146
    explicit Pasteboard(RefPtr<DataObjectGtk>&&);
141
    explicit Pasteboard(RefPtr<DataObjectGtk>&&);
147
    explicit Pasteboard(GtkClipboard*);
148
#endif
142
#endif
149
143
150
#if PLATFORM(WIN)
144
#if PLATFORM(WIN)
Lines 226-233 private: a/Source/WebCore/platform/Pasteboard.h_sec4
226
#endif
220
#endif
227
221
228
#if PLATFORM(GTK)
222
#if PLATFORM(GTK)
223
    enum class ShouldIncludeSmartPaste { No, Yes };
224
    void writeToClipboard(ShouldIncludeSmartPaste = ShouldIncludeSmartPaste::No);
225
    void readFromClipboard();
229
    RefPtr<DataObjectGtk> m_dataObject;
226
    RefPtr<DataObjectGtk> m_dataObject;
230
    GtkClipboard* m_gtkClipboard;
227
    String m_name;
231
#endif
228
#endif
232
229
233
#if PLATFORM(IOS)
230
#if PLATFORM(IOS)
- a/Source/WebCore/platform/PasteboardStrategy.h +8 lines
Lines 38-43 class URL; a/Source/WebCore/platform/PasteboardStrategy.h_sec1
38
struct PasteboardImage;
38
struct PasteboardImage;
39
struct PasteboardWebContent;
39
struct PasteboardWebContent;
40
40
41
#if PLATFORM(GTK)
42
class DataObjectGtk;
43
#endif
44
41
class PasteboardStrategy {
45
class PasteboardStrategy {
42
public:
46
public:
43
#if PLATFORM(IOS)
47
#if PLATFORM(IOS)
Lines 68-73 public: a/Source/WebCore/platform/PasteboardStrategy.h_sec2
68
    virtual long setPathnamesForType(const Vector<String>&, const String& pasteboardType, const String& pasteboardName) = 0;
72
    virtual long setPathnamesForType(const Vector<String>&, const String& pasteboardType, const String& pasteboardName) = 0;
69
    virtual long setStringForType(const String&, const String& pasteboardType, const String& pasteboardName) = 0;
73
    virtual long setStringForType(const String&, const String& pasteboardType, const String& pasteboardName) = 0;
70
#endif
74
#endif
75
#if PLATFORM(GTK)
76
    virtual void writeToClipboard(const String& pasteboardName, const RefPtr<DataObjectGtk>&) = 0;
77
    virtual RefPtr<DataObjectGtk> readFromClipboard(const String& pasteboardName) = 0;
78
#endif // PLATFORM(GTK)
71
protected:
79
protected:
72
    virtual ~PasteboardStrategy()
80
    virtual ~PasteboardStrategy()
73
    {
81
    {
- a/Source/WebCore/platform/PlatformPasteboard.h +12 lines
Lines 47-52 class URL; a/Source/WebCore/platform/PlatformPasteboard.h_sec1
47
struct PasteboardImage;
47
struct PasteboardImage;
48
struct PasteboardWebContent;
48
struct PasteboardWebContent;
49
49
50
#if PLATFORM(GTK)
51
class DataObjectGtk;
52
#endif
53
50
class PlatformPasteboard {
54
class PlatformPasteboard {
51
public:
55
public:
52
    // FIXME: probably we don't need a constructor that takes a pasteboard name for iOS.
56
    // FIXME: probably we don't need a constructor that takes a pasteboard name for iOS.
Lines 81-86 public: a/Source/WebCore/platform/PlatformPasteboard.h_sec2
81
    WEBCORE_EXPORT URL readURL(int index, const String& pasteboardType);
85
    WEBCORE_EXPORT URL readURL(int index, const String& pasteboardType);
82
    WEBCORE_EXPORT int count();
86
    WEBCORE_EXPORT int count();
83
87
88
#if PLATFORM(GTK)
89
    WEBCORE_EXPORT void writeToClipboard(const RefPtr<DataObjectGtk>&, std::function<void()>&& primarySelectionCleared);
90
    WEBCORE_EXPORT RefPtr<DataObjectGtk> readFromClipboard();
91
#endif
92
84
private:
93
private:
85
#if PLATFORM(MAC)
94
#if PLATFORM(MAC)
86
    RetainPtr<NSPasteboard> m_pasteboard;
95
    RetainPtr<NSPasteboard> m_pasteboard;
Lines 88-93 private: a/Source/WebCore/platform/PlatformPasteboard.h_sec3
88
#if PLATFORM(IOS)
97
#if PLATFORM(IOS)
89
    RetainPtr<UIPasteboard> m_pasteboard;
98
    RetainPtr<UIPasteboard> m_pasteboard;
90
#endif
99
#endif
100
#if PLATFORM(GTK)
101
    GtkClipboard* m_clipboard;
102
#endif
91
};
103
};
92
104
93
}
105
}
- a/Source/WebCore/platform/gtk/DataObjectGtk.cpp +1 lines
Lines 139-144 void DataObjectGtk::clearAllExceptFilenames() a/Source/WebCore/platform/gtk/DataObjectGtk.cpp_sec1
139
    m_url = URL();
139
    m_url = URL();
140
    m_image = nullptr;
140
    m_image = nullptr;
141
    m_unknownTypeData.clear();
141
    m_unknownTypeData.clear();
142
    m_canSmartReplace = false;
142
}
143
}
143
144
144
void DataObjectGtk::clearAll()
145
void DataObjectGtk::clearAll()
- a/Source/WebCore/platform/gtk/DataObjectGtk.h +3 lines
Lines 47-52 public: a/Source/WebCore/platform/gtk/DataObjectGtk.h_sec1
47
    bool hasURL() const { return !m_url.isEmpty() && m_url.isValid(); }
47
    bool hasURL() const { return !m_url.isEmpty() && m_url.isValid(); }
48
    bool hasFilenames() const { return !m_filenames.isEmpty(); }
48
    bool hasFilenames() const { return !m_filenames.isEmpty(); }
49
    bool hasImage() const { return m_image; }
49
    bool hasImage() const { return m_image; }
50
    bool canSmartReplace() const { return m_canSmartReplace; }
50
    void clearURIList() { m_uriList = emptyString(); }
51
    void clearURIList() { m_uriList = emptyString(); }
51
    void clearURL() { m_url = URL(); }
52
    void clearURL() { m_url = URL(); }
52
    void clearImage() { m_image = nullptr; }
53
    void clearImage() { m_image = nullptr; }
Lines 59-64 public: a/Source/WebCore/platform/gtk/DataObjectGtk.h_sec2
59
    void setMarkup(const String&);
60
    void setMarkup(const String&);
60
    void setUnknownTypeData(const String& type, const String& data) { m_unknownTypeData.set(type, data); }
61
    void setUnknownTypeData(const String& type, const String& data) { m_unknownTypeData.set(type, data); }
61
    void setURIList(const String&);
62
    void setURIList(const String&);
63
    void setCanSmartReplace(bool canSmartReplace) { m_canSmartReplace = canSmartReplace; }
62
    String urlLabel() const;
64
    String urlLabel() const;
63
65
64
    void clearAllExceptFilenames();
66
    void clearAllExceptFilenames();
Lines 74-79 private: a/Source/WebCore/platform/gtk/DataObjectGtk.h_sec3
74
    Vector<String> m_filenames;
76
    Vector<String> m_filenames;
75
    GRefPtr<GdkPixbuf> m_image;
77
    GRefPtr<GdkPixbuf> m_image;
76
    HashMap<String, String> m_unknownTypeData;
78
    HashMap<String, String> m_unknownTypeData;
79
    bool m_canSmartReplace { false };
77
};
80
};
78
81
79
}
82
}
- a/Source/WebCore/platform/gtk/PasteboardGtk.cpp -37 / +36 lines
Lines 23-31 a/Source/WebCore/platform/gtk/PasteboardGtk.cpp_sec1
23
#include "DataObjectGtk.h"
23
#include "DataObjectGtk.h"
24
#include "DragData.h"
24
#include "DragData.h"
25
#include "Image.h"
25
#include "Image.h"
26
#include "PasteboardStrategy.h"
27
#include "PlatformStrategies.h"
26
#include "URL.h"
28
#include "URL.h"
27
#include "PasteboardHelper.h"
29
#include <wtf/NeverDestroyed.h>
28
#include <gtk/gtk.h>
29
30
30
namespace WebCore {
31
namespace WebCore {
31
32
Lines 40-51 enum ClipboardDataType { a/Source/WebCore/platform/gtk/PasteboardGtk.cpp_sec2
40
41
41
std::unique_ptr<Pasteboard> Pasteboard::createForCopyAndPaste()
42
std::unique_ptr<Pasteboard> Pasteboard::createForCopyAndPaste()
42
{
43
{
43
    return std::make_unique<Pasteboard>(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
44
    return std::make_unique<Pasteboard>("CLIPBOARD");
44
}
45
}
45
46
46
std::unique_ptr<Pasteboard> Pasteboard::createForGlobalSelection()
47
std::unique_ptr<Pasteboard> Pasteboard::createForGlobalSelection()
47
{
48
{
48
    return std::make_unique<Pasteboard>(gtk_clipboard_get(GDK_SELECTION_PRIMARY));
49
    return std::make_unique<Pasteboard>("PRIMARY");
49
}
50
}
50
51
51
std::unique_ptr<Pasteboard> Pasteboard::createPrivate()
52
std::unique_ptr<Pasteboard> Pasteboard::createPrivate()
Lines 76-92 PasteboardImage::~PasteboardImage() a/Source/WebCore/platform/gtk/PasteboardGtk.cpp_sec3
76
77
77
Pasteboard::Pasteboard(RefPtr<DataObjectGtk>&& dataObject)
78
Pasteboard::Pasteboard(RefPtr<DataObjectGtk>&& dataObject)
78
    : m_dataObject(WTFMove(dataObject))
79
    : m_dataObject(WTFMove(dataObject))
79
    , m_gtkClipboard(nullptr)
80
{
80
{
81
    ASSERT(m_dataObject);
81
    ASSERT(m_dataObject);
82
}
82
}
83
83
84
Pasteboard::Pasteboard(GtkClipboard* gtkClipboard)
84
Pasteboard::Pasteboard(const String& name)
85
    : m_dataObject(DataObjectGtk::create())
85
    : m_dataObject(DataObjectGtk::create())
86
    , m_gtkClipboard(gtkClipboard)
86
    , m_name(name)
87
{
87
{
88
    ASSERT(m_dataObject);
89
    PasteboardHelper::singleton().registerClipboard(gtkClipboard);
90
}
88
}
91
89
92
Pasteboard::~Pasteboard()
90
Pasteboard::~Pasteboard()
Lines 121-126 static ClipboardDataType dataObjectTypeFromHTMLClipboardType(const String& rawTy a/Source/WebCore/platform/gtk/PasteboardGtk.cpp_sec4
121
    return ClipboardDataTypeUnknown;
119
    return ClipboardDataTypeUnknown;
122
}
120
}
123
121
122
void Pasteboard::writeToClipboard(ShouldIncludeSmartPaste shouldIncludeSmartPaste)
123
{
124
    if (m_name.isNull())
125
        return;
126
    m_dataObject->setCanSmartReplace(shouldIncludeSmartPaste == ShouldIncludeSmartPaste::Yes);
127
    platformStrategies()->pasteboardStrategy()->writeToClipboard(m_name, m_dataObject);
128
}
129
130
void Pasteboard::readFromClipboard()
131
{
132
    if (m_name.isNull())
133
        return;
134
    m_dataObject = platformStrategies()->pasteboardStrategy()->readFromClipboard(m_name);
135
}
136
124
void Pasteboard::writeString(const String& type, const String& data)
137
void Pasteboard::writeString(const String& type, const String& data)
125
{
138
{
126
    switch (dataObjectTypeFromHTMLClipboardType(type)) {
139
    switch (dataObjectTypeFromHTMLClipboardType(type)) {
Lines 147-154 void Pasteboard::writePlainText(const String& text, SmartReplaceOption smartRepl a/Source/WebCore/platform/gtk/PasteboardGtk.cpp_sec5
147
    m_dataObject->clearAll();
160
    m_dataObject->clearAll();
148
    m_dataObject->setText(text);
161
    m_dataObject->setText(text);
149
162
150
    if (m_gtkClipboard)
163
    writeToClipboard(smartReplaceOption == CanSmartReplace ? ShouldIncludeSmartPaste::Yes : ShouldIncludeSmartPaste::No);
151
        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject, (smartReplaceOption == CanSmartReplace) ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste);
152
}
164
}
153
165
154
void Pasteboard::write(const PasteboardURL& pasteboardURL)
166
void Pasteboard::write(const PasteboardURL& pasteboardURL)
Lines 158-165 void Pasteboard::write(const PasteboardURL& pasteboardURL) a/Source/WebCore/platform/gtk/PasteboardGtk.cpp_sec6
158
    m_dataObject->clearAll();
170
    m_dataObject->clearAll();
159
    m_dataObject->setURL(pasteboardURL.url, pasteboardURL.title);
171
    m_dataObject->setURL(pasteboardURL.url, pasteboardURL.title);
160
172
161
    if (m_gtkClipboard)
173
    writeToClipboard();
162
        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
163
}
174
}
164
175
165
void Pasteboard::write(const PasteboardImage& pasteboardImage)
176
void Pasteboard::write(const PasteboardImage& pasteboardImage)
Lines 174-181 void Pasteboard::write(const PasteboardImage& pasteboardImage) a/Source/WebCore/platform/gtk/PasteboardGtk.cpp_sec7
174
    if (pixbuf)
185
    if (pixbuf)
175
        m_dataObject->setImage(pixbuf.get());
186
        m_dataObject->setImage(pixbuf.get());
176
187
177
    if (m_gtkClipboard)
188
    writeToClipboard();
178
        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
179
}
189
}
180
190
181
void Pasteboard::write(const PasteboardWebContent& pasteboardContent)
191
void Pasteboard::write(const PasteboardWebContent& pasteboardContent)
Lines 184-191 void Pasteboard::write(const PasteboardWebContent& pasteboardContent) a/Source/WebCore/platform/gtk/PasteboardGtk.cpp_sec8
184
    m_dataObject->setText(pasteboardContent.text);
194
    m_dataObject->setText(pasteboardContent.text);
185
    m_dataObject->setMarkup(pasteboardContent.markup);
195
    m_dataObject->setMarkup(pasteboardContent.markup);
186
196
187
    if (m_gtkClipboard)
197
    writeToClipboard(pasteboardContent.canSmartCopyOrDelete ? ShouldIncludeSmartPaste::Yes : ShouldIncludeSmartPaste::No);
188
        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject, pasteboardContent.canSmartCopyOrDelete ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste, pasteboardContent.callback.get());
189
}
198
}
190
199
191
void Pasteboard::writePasteboard(const Pasteboard& sourcePasteboard)
200
void Pasteboard::writePasteboard(const Pasteboard& sourcePasteboard)
Lines 208-215 void Pasteboard::writePasteboard(const Pasteboard& sourcePasteboard) a/Source/WebCore/platform/gtk/PasteboardGtk.cpp_sec9
208
            m_dataObject->setUnknownTypeData(it.key, it.value);
217
            m_dataObject->setUnknownTypeData(it.key, it.value);
209
    }
218
    }
210
219
211
    if (m_gtkClipboard)
220
    writeToClipboard();
212
        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
213
}
221
}
214
222
215
void Pasteboard::clear()
223
void Pasteboard::clear()
Lines 219-227 void Pasteboard::clear() a/Source/WebCore/platform/gtk/PasteboardGtk.cpp_sec10
219
    // attribute's list might still not be empty after calling clearData() (it would
227
    // attribute's list might still not be empty after calling clearData() (it would
220
    // still contain the "Files" string if any files were included in the drag)."
228
    // still contain the "Files" string if any files were included in the drag)."
221
    m_dataObject->clearAllExceptFilenames();
229
    m_dataObject->clearAllExceptFilenames();
222
230
    writeToClipboard();
223
    if (m_gtkClipboard)
224
        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
225
}
231
}
226
232
227
void Pasteboard::clear(const String& type)
233
void Pasteboard::clear(const String& type)
Lines 245-257 void Pasteboard::clear(const String& type) a/Source/WebCore/platform/gtk/PasteboardGtk.cpp_sec11
245
        break;
251
        break;
246
    }
252
    }
247
253
248
    if (m_gtkClipboard)
254
    writeToClipboard();
249
        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
250
}
255
}
251
256
252
bool Pasteboard::canSmartReplace()
257
bool Pasteboard::canSmartReplace()
253
{
258
{
254
    return m_gtkClipboard && PasteboardHelper::singleton().clipboardContentSupportsSmartReplace(m_gtkClipboard);
259
    readFromClipboard();
260
    return m_dataObject->canSmartReplace();
255
}
261
}
256
262
257
#if ENABLE(DRAG_SUPPORT)
263
#if ENABLE(DRAG_SUPPORT)
Lines 262-284 void Pasteboard::setDragImage(DragImageRef, const IntPoint&) a/Source/WebCore/platform/gtk/PasteboardGtk.cpp_sec12
262
268
263
void Pasteboard::read(PasteboardPlainText& text)
269
void Pasteboard::read(PasteboardPlainText& text)
264
{
270
{
265
    if (m_gtkClipboard)
271
    readFromClipboard();
266
        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
267
    text.text = m_dataObject->text();
272
    text.text = m_dataObject->text();
268
}
273
}
269
274
270
bool Pasteboard::hasData()
275
bool Pasteboard::hasData()
271
{
276
{
272
    if (m_gtkClipboard)
277
    readFromClipboard();
273
        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
274
275
    return m_dataObject->hasText() || m_dataObject->hasMarkup() || m_dataObject->hasURIList() || m_dataObject->hasImage() || m_dataObject->hasUnknownTypeData();
278
    return m_dataObject->hasText() || m_dataObject->hasMarkup() || m_dataObject->hasURIList() || m_dataObject->hasImage() || m_dataObject->hasUnknownTypeData();
276
}
279
}
277
280
278
Vector<String> Pasteboard::types()
281
Vector<String> Pasteboard::types()
279
{
282
{
280
    if (m_gtkClipboard)
283
    readFromClipboard();
281
        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
282
284
283
    Vector<String> types;
285
    Vector<String> types;
284
    if (m_dataObject->hasText()) {
286
    if (m_dataObject->hasText()) {
Lines 306-313 Vector<String> Pasteboard::types() a/Source/WebCore/platform/gtk/PasteboardGtk.cpp_sec13
306
308
307
String Pasteboard::readString(const String& type)
309
String Pasteboard::readString(const String& type)
308
{
310
{
309
    if (m_gtkClipboard)
311
    readFromClipboard();
310
        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
311
312
312
    switch (dataObjectTypeFromHTMLClipboardType(type)) {
313
    switch (dataObjectTypeFromHTMLClipboardType(type)) {
313
    case ClipboardDataTypeURIList:
314
    case ClipboardDataTypeURIList:
Lines 329-337 String Pasteboard::readString(const String& type) a/Source/WebCore/platform/gtk/PasteboardGtk.cpp_sec14
329
330
330
Vector<String> Pasteboard::readFilenames()
331
Vector<String> Pasteboard::readFilenames()
331
{
332
{
332
    if (m_gtkClipboard)
333
    readFromClipboard();
333
        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
334
335
    return m_dataObject->filenames();
334
    return m_dataObject->filenames();
336
}
335
}
337
336
- a/Source/WebCore/platform/gtk/PasteboardHelper.cpp -29 / +13 lines
Lines 76-83 PasteboardHelper::PasteboardHelper() a/Source/WebCore/platform/gtk/PasteboardHelper.cpp_sec1
76
76
77
PasteboardHelper::~PasteboardHelper()
77
PasteboardHelper::~PasteboardHelper()
78
{
78
{
79
    for (auto* clipboard : m_gtkClipboards)
80
        gtk_clipboard_store(clipboard);
81
}
79
}
82
80
83
GtkTargetList* PasteboardHelper::targetList() const
81
GtkTargetList* PasteboardHelper::targetList() const
Lines 115-120 void PasteboardHelper::getClipboardContents(GtkClipboard* clipboard, DataObjectG a/Source/WebCore/platform/gtk/PasteboardHelper.cpp_sec2
115
            gtk_selection_data_free(data);
113
            gtk_selection_data_free(data);
116
        }
114
        }
117
    }
115
    }
116
117
    dataObject.setCanSmartReplace(gtk_clipboard_wait_is_target_available(clipboard, smartPasteAtom));
118
}
118
}
119
119
120
void PasteboardHelper::fillSelectionData(GtkSelectionData* selectionData, guint info, const DataObjectGtk& dataObject)
120
void PasteboardHelper::fillSelectionData(GtkSelectionData* selectionData, guint info, const DataObjectGtk& dataObject)
Lines 169-175 void PasteboardHelper::fillSelectionData(GtkSelectionData* selectionData, guint a/Source/WebCore/platform/gtk/PasteboardHelper.cpp_sec3
169
    }
169
    }
170
}
170
}
171
171
172
GRefPtr<GtkTargetList> PasteboardHelper::targetListForDataObject(const DataObjectGtk& dataObject, SmartPasteInclusion shouldInludeSmartPaste)
172
GRefPtr<GtkTargetList> PasteboardHelper::targetListForDataObject(const DataObjectGtk& dataObject)
173
{
173
{
174
    GRefPtr<GtkTargetList> list = adoptGRef(gtk_target_list_new(nullptr, 0));
174
    GRefPtr<GtkTargetList> list = adoptGRef(gtk_target_list_new(nullptr, 0));
175
175
Lines 190-196 GRefPtr<GtkTargetList> PasteboardHelper::targetListForDataObject(const DataObjec a/Source/WebCore/platform/gtk/PasteboardHelper.cpp_sec4
190
    if (dataObject.hasUnknownTypeData())
190
    if (dataObject.hasUnknownTypeData())
191
        gtk_target_list_add(list.get(), unknownAtom, 0, TargetTypeUnknown);
191
        gtk_target_list_add(list.get(), unknownAtom, 0, TargetTypeUnknown);
192
192
193
    if (shouldInludeSmartPaste == IncludeSmartPaste)
193
    if (dataObject.canSmartReplace())
194
        gtk_target_list_add(list.get(), smartPasteAtom, 0, TargetTypeSmartPaste);
194
        gtk_target_list_add(list.get(), smartPasteAtom, 0, TargetTypeSmartPaste);
195
195
196
    return list;
196
    return list;
Lines 257-265 Vector<GdkAtom> PasteboardHelper::dropAtomsForContext(GtkWidget* widget, GdkDrag a/Source/WebCore/platform/gtk/PasteboardHelper.cpp_sec5
257
static DataObjectGtk* settingClipboardDataObject = 0;
257
static DataObjectGtk* settingClipboardDataObject = 0;
258
258
259
struct ClipboardSetData {
259
struct ClipboardSetData {
260
    ClipboardSetData(DataObjectGtk* dataObject, GClosure* callback)
260
    ClipboardSetData(DataObjectGtk* dataObject, std::function<void()>&& selectionClearedCallback)
261
        : dataObject(dataObject)
261
        : dataObject(dataObject)
262
        , callback(callback)
262
        , selectionClearedCallback(WTFMove(selectionClearedCallback))
263
    {
263
    {
264
    }
264
    }
265
265
Lines 268-274 struct ClipboardSetData { a/Source/WebCore/platform/gtk/PasteboardHelper.cpp_sec6
268
    }
268
    }
269
269
270
    RefPtr<DataObjectGtk> dataObject;
270
    RefPtr<DataObjectGtk> dataObject;
271
    GRefPtr<GClosure> callback;
271
    std::function<void()> selectionClearedCallback;
272
};
272
};
273
273
274
static void getClipboardContentsCallback(GtkClipboard*, GtkSelectionData *selectionData, guint info, gpointer userData)
274
static void getClipboardContentsCallback(GtkClipboard*, GtkSelectionData *selectionData, guint info, gpointer userData)
Lines 277-283 static void getClipboardContentsCallback(GtkClipboard*, GtkSelectionData *select a/Source/WebCore/platform/gtk/PasteboardHelper.cpp_sec7
277
    PasteboardHelper::singleton().fillSelectionData(selectionData, info, *data->dataObject);
277
    PasteboardHelper::singleton().fillSelectionData(selectionData, info, *data->dataObject);
278
}
278
}
279
279
280
static void clearClipboardContentsCallback(GtkClipboard* clipboard, gpointer userData)
280
static void clearClipboardContentsCallback(GtkClipboard*, gpointer userData)
281
{
281
{
282
    std::unique_ptr<ClipboardSetData> data(static_cast<ClipboardSetData*>(userData));
282
    std::unique_ptr<ClipboardSetData> data(static_cast<ClipboardSetData*>(userData));
283
283
Lines 285-302 static void clearClipboardContentsCallback(GtkClipboard* clipboard, gpointer use a/Source/WebCore/platform/gtk/PasteboardHelper.cpp_sec8
285
    if (data->dataObject.get() != settingClipboardDataObject)
285
    if (data->dataObject.get() != settingClipboardDataObject)
286
        data->dataObject->clearAll();
286
        data->dataObject->clearAll();
287
287
288
    if (!data->callback)
288
    if (data->selectionClearedCallback)
289
        return;
289
        data->selectionClearedCallback();
290
291
    GValue firstArgument = {0, {{0}}};
292
    g_value_init(&firstArgument, G_TYPE_POINTER);
293
    g_value_set_pointer(&firstArgument, clipboard);
294
    g_closure_invoke(data->callback.get(), nullptr, 1, &firstArgument, 0);
295
}
290
}
296
291
297
void PasteboardHelper::writeClipboardContents(GtkClipboard* clipboard, const DataObjectGtk& dataObject, SmartPasteInclusion includeSmartPaste, GClosure* callback)
292
void PasteboardHelper::writeClipboardContents(GtkClipboard* clipboard, const DataObjectGtk& dataObject, std::function<void()>&& primarySelectionCleared)
298
{
293
{
299
    GRefPtr<GtkTargetList> list = targetListForDataObject(dataObject, includeSmartPaste);
294
    GRefPtr<GtkTargetList> list = targetListForDataObject(dataObject);
300
295
301
    int numberOfTargets;
296
    int numberOfTargets;
302
    GtkTargetEntry* table = gtk_target_table_new_from_list(list.get(), &numberOfTargets);
297
    GtkTargetEntry* table = gtk_target_table_new_from_list(list.get(), &numberOfTargets);
Lines 304-310 void PasteboardHelper::writeClipboardContents(GtkClipboard* clipboard, const Dat a/Source/WebCore/platform/gtk/PasteboardHelper.cpp_sec9
304
    if (numberOfTargets > 0 && table) {
299
    if (numberOfTargets > 0 && table) {
305
        settingClipboardDataObject = const_cast<DataObjectGtk*>(&dataObject);
300
        settingClipboardDataObject = const_cast<DataObjectGtk*>(&dataObject);
306
301
307
        auto data = std::make_unique<ClipboardSetData>(settingClipboardDataObject, callback);
302
        auto data = std::make_unique<ClipboardSetData>(settingClipboardDataObject, WTFMove(primarySelectionCleared));
308
        if (gtk_clipboard_set_with_data(clipboard, table, numberOfTargets, getClipboardContentsCallback, clearClipboardContentsCallback, data.get())) {
303
        if (gtk_clipboard_set_with_data(clipboard, table, numberOfTargets, getClipboardContentsCallback, clearClipboardContentsCallback, data.get())) {
309
            gtk_clipboard_set_can_store(clipboard, nullptr, 0);
304
            gtk_clipboard_set_can_store(clipboard, nullptr, 0);
310
            // When gtk_clipboard_set_with_data fails the callbacks are ignored, so we need to leak the data we were passing to clearClipboardContentsCallback.
305
            // When gtk_clipboard_set_with_data fails the callbacks are ignored, so we need to leak the data we were passing to clearClipboardContentsCallback.
Lines 319-334 void PasteboardHelper::writeClipboardContents(GtkClipboard* clipboard, const Dat a/Source/WebCore/platform/gtk/PasteboardHelper.cpp_sec10
319
        gtk_target_table_free(table, numberOfTargets);
314
        gtk_target_table_free(table, numberOfTargets);
320
}
315
}
321
316
322
bool PasteboardHelper::clipboardContentSupportsSmartReplace(GtkClipboard* clipboard)
323
{
324
    return gtk_clipboard_wait_is_target_available(clipboard, smartPasteAtom);
325
}
326
327
void PasteboardHelper::registerClipboard(GtkClipboard* clipboard)
328
{
329
    ASSERT(clipboard);
330
    m_gtkClipboards.add(clipboard);
331
}
332
333
}
317
}
334
318
- a/Source/WebCore/platform/gtk/PasteboardHelper.h -7 / +2 lines
Lines 26-32 a/Source/WebCore/platform/gtk/PasteboardHelper.h_sec1
26
#define PasteboardHelper_h
26
#define PasteboardHelper_h
27
27
28
#include "GRefPtrGtk.h"
28
#include "GRefPtrGtk.h"
29
#include <wtf/HashSet.h>
30
#include <wtf/Noncopyable.h>
29
#include <wtf/Noncopyable.h>
31
#include <wtf/Vector.h>
30
#include <wtf/Vector.h>
32
#include <wtf/glib/GRefPtr.h>
31
#include <wtf/glib/GRefPtr.h>
Lines 43-66 public: a/Source/WebCore/platform/gtk/PasteboardHelper.h_sec2
43
    enum SmartPasteInclusion { IncludeSmartPaste, DoNotIncludeSmartPaste };
42
    enum SmartPasteInclusion { IncludeSmartPaste, DoNotIncludeSmartPaste };
44
43
45
    GtkTargetList* targetList() const;
44
    GtkTargetList* targetList() const;
46
    GRefPtr<GtkTargetList> targetListForDataObject(const DataObjectGtk&, SmartPasteInclusion = DoNotIncludeSmartPaste);
45
    GRefPtr<GtkTargetList> targetListForDataObject(const DataObjectGtk&);
47
    void fillSelectionData(GtkSelectionData*, guint, const DataObjectGtk&);
46
    void fillSelectionData(GtkSelectionData*, guint, const DataObjectGtk&);
48
    void fillDataObjectFromDropData(GtkSelectionData*, guint, DataObjectGtk&);
47
    void fillDataObjectFromDropData(GtkSelectionData*, guint, DataObjectGtk&);
49
    Vector<GdkAtom> dropAtomsForContext(GtkWidget*, GdkDragContext*);
48
    Vector<GdkAtom> dropAtomsForContext(GtkWidget*, GdkDragContext*);
50
    void writeClipboardContents(GtkClipboard*, const DataObjectGtk&, SmartPasteInclusion = DoNotIncludeSmartPaste, GClosure* = 0);
49
    void writeClipboardContents(GtkClipboard*, const DataObjectGtk&, std::function<void()>&& primarySelectionCleared = nullptr);
51
    void getClipboardContents(GtkClipboard*, DataObjectGtk&);
50
    void getClipboardContents(GtkClipboard*, DataObjectGtk&);
52
51
53
    enum PasteboardTargetType { TargetTypeMarkup, TargetTypeText, TargetTypeImage, TargetTypeURIList, TargetTypeNetscapeURL, TargetTypeSmartPaste, TargetTypeUnknown };
52
    enum PasteboardTargetType { TargetTypeMarkup, TargetTypeText, TargetTypeImage, TargetTypeURIList, TargetTypeNetscapeURL, TargetTypeSmartPaste, TargetTypeUnknown };
54
    bool clipboardContentSupportsSmartReplace(GtkClipboard*);
55
56
    void registerClipboard(GtkClipboard*);
57
53
58
private:
54
private:
59
    PasteboardHelper();
55
    PasteboardHelper();
60
    ~PasteboardHelper();
56
    ~PasteboardHelper();
61
57
62
    GRefPtr<GtkTargetList> m_targetList;
58
    GRefPtr<GtkTargetList> m_targetList;
63
    HashSet<GtkClipboard*> m_gtkClipboards;
64
};
59
};
65
60
66
}
61
}
- a/Source/WebCore/platform/gtk/PlatformPasteboardGtk.cpp +49 lines
Line 0 a/Source/WebCore/platform/gtk/PlatformPasteboardGtk.cpp_sec1
1
/*
2
 *  Copyright (C) 2016 Red Hat Inc.
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
#include "config.h"
20
#include "PlatformPasteboard.h"
21
22
#include "Color.h"
23
#include "DataObjectGtk.h"
24
#include "PasteboardHelper.h"
25
#include "SharedBuffer.h"
26
#include "URL.h"
27
#include <gtk/gtk.h>
28
29
namespace WebCore {
30
31
PlatformPasteboard::PlatformPasteboard(const String& pasteboardName)
32
    : m_clipboard(gtk_clipboard_get(gdk_atom_intern(pasteboardName.utf8().data(), TRUE)))
33
{
34
    ASSERT(m_clipboard);
35
}
36
37
void PlatformPasteboard::writeToClipboard(const RefPtr<DataObjectGtk>& dataObject, std::function<void()>&& primarySelectionCleared)
38
{
39
    PasteboardHelper::singleton().writeClipboardContents(m_clipboard, *dataObject, gtk_clipboard_get(GDK_SELECTION_PRIMARY) == m_clipboard ? WTFMove(primarySelectionCleared) : nullptr);
40
}
41
42
RefPtr<DataObjectGtk> PlatformPasteboard::readFromClipboard()
43
{
44
    RefPtr<DataObjectGtk> dataObject = DataObjectGtk::create();
45
    PasteboardHelper::singleton().getClipboardContents(m_clipboard, *dataObject);
46
    return dataObject;
47
}
48
49
}
- a/Source/WebKit2/ChangeLog +65 lines
Lines 1-3 a/Source/WebKit2/ChangeLog_sec1
1
2016-09-14  Carlos Garnacho  <carlosg@gnome.org>
2
3
        [GTK][Wayland] Implement clipboard support
4
        https://bugs.webkit.org/show_bug.cgi?id=146574
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Add the necessary plumbing for the GTK+ backend to use the
9
        PlatformPasteboard in WebCore. All selection data is transmitted
10
        at once through the serialization of PasteboardContentGtk/DataObjectGtk.
11
12
        * PlatformGTK.cmake: Add PasteboardContentGtk.cpp and
13
        WebPasteboardProxyGtk.cpp
14
        * Shared/gtk/ArgumentCodersGtk.cpp:
15
        (IPC::encode):
16
        (IPC::decode): Renamed from encodeDataObject/decodeDataObject
17
        and made public.
18
        (IPC::ArgumentCoder<DragData>::encode):
19
        (IPC::ArgumentCoder<DragData>::decode): Update DataObjectGtk
20
        encode/decode callers. Encode the extra canSmartReplace field.
21
        * Shared/gtk/ArgumentCodersGtk.h: Expose encode/decode methods for
22
        DataObjectGtk.
23
        * Shared/gtk/PasteboardContent.cpp: Added. Wraps a DataObjectGtk
24
        so it can be serialized on WebProcess/UIProcess messaging.
25
        (WebKit::PasteboardContent::PasteboardContent):
26
        (WebKit::PasteboardContent::encode):
27
        (WebKit::PasteboardContent::decode): Methods to encode/decode a
28
        PasteboardContent.
29
        * Shared/gtk/PasteboardContent.h: Added.
30
        * UIProcess/WebFrameProxy.cpp:
31
        (WebKit::WebFrameProxy::collapseSelection): Added plumbing to allow
32
        collapsing the global selection from the UI process side.
33
        * UIProcess/WebFrameProxy.h:
34
        * UIProcess/WebPasteboardProxy.h:
35
        * UIProcess/WebPasteboardProxy.messages.in: Added plumbing for the
36
        GTK+ pasteboard proxy functions.
37
        * UIProcess/gtk/WebPageProxyGtk.cpp:
38
        (WebKit::WebPageProxy::editorStateChanged):
39
        * UIProcess/gtk/WebPasteboardProxyGtk.cpp: Added.
40
        (WebKit::WebPasteboardProxy::writeToClipboard):
41
        (WebKit::WebPasteboardProxy::readFromClipboard): Implemented functions
42
        hooking into the PlatformPasteboard. Per-selection (ie.
43
        primary/clipboard) PlatformPasteboards are kept at this level, so those
44
        are independently set and dealt with.
45
        (WebKit::WebPasteboardProxy::setPrimarySelectionOwner):
46
        (WebKit::WebPasteboardProxy::didDestroyFrame): Implemented functions
47
        to manage the frame currently being currently interacted, so we can
48
        signal back when the global selection has been replaced.
49
        * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
50
        (WebKit::WebPlatformStrategies::writeToClipboard):
51
        (WebKit::WebPlatformStrategies::readFromClipboard): Added methods to
52
        send the WebProcess->UIProcess messages.
53
        * WebProcess/WebCoreSupport/WebPlatformStrategies.h:
54
        * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
55
        (WebKit::WebEditorClient::updateGlobalSelection): Remove GClosure to
56
        get notifications about changes in global selection ownership. This
57
        is done through a WebPage message now, as the UI process manages the
58
        clipboard.
59
        * WebProcess/WebPage/WebPage.h:
60
        * WebProcess/WebPage/WebPage.messages.in:
61
        * WebProcess/WebPage/gtk/WebPageGtk.cpp:
62
        (WebKit::WebPage::collapseSelectionInFrame): Added methods to send
63
        the UIProcess->WebProcess notification that the global selection has
64
        been replaced.
65
1
2016-09-13  Carlos Garcia Campos  <cgarcia@igalia.com>
66
2016-09-13  Carlos Garcia Campos  <cgarcia@igalia.com>
2
67
3
        [GTK] Get rid of DataObjectGtk::forClipboard and cleanup pasteboard code
68
        [GTK] Get rid of DataObjectGtk::forClipboard and cleanup pasteboard code
- a/Source/WebKit2/PlatformGTK.cmake +2 lines
Lines 71-76 list(APPEND WebKit2_SOURCES a/Source/WebKit2/PlatformGTK.cmake_sec1
71
    Shared/gtk/NativeWebMouseEventGtk.cpp
71
    Shared/gtk/NativeWebMouseEventGtk.cpp
72
    Shared/gtk/NativeWebTouchEventGtk.cpp
72
    Shared/gtk/NativeWebTouchEventGtk.cpp
73
    Shared/gtk/NativeWebWheelEventGtk.cpp
73
    Shared/gtk/NativeWebWheelEventGtk.cpp
74
    Shared/gtk/PasteboardContent.cpp
74
    Shared/gtk/PrintInfoGtk.cpp
75
    Shared/gtk/PrintInfoGtk.cpp
75
    Shared/gtk/ProcessExecutablePathGtk.cpp
76
    Shared/gtk/ProcessExecutablePathGtk.cpp
76
    Shared/gtk/WebContextMenuItemGtk.cpp
77
    Shared/gtk/WebContextMenuItemGtk.cpp
Lines 313-318 list(APPEND WebKit2_SOURCES a/Source/WebKit2/PlatformGTK.cmake_sec2
313
    UIProcess/gtk/WebInspectorClientGtk.cpp
314
    UIProcess/gtk/WebInspectorClientGtk.cpp
314
    UIProcess/gtk/WebInspectorProxyGtk.cpp
315
    UIProcess/gtk/WebInspectorProxyGtk.cpp
315
    UIProcess/gtk/WebPageProxyGtk.cpp
316
    UIProcess/gtk/WebPageProxyGtk.cpp
317
    UIProcess/gtk/WebPasteboardProxyGtk.cpp
316
    UIProcess/gtk/WebPopupMenuProxyGtk.cpp
318
    UIProcess/gtk/WebPopupMenuProxyGtk.cpp
317
    UIProcess/gtk/WebPreferencesGtk.cpp
319
    UIProcess/gtk/WebPreferencesGtk.cpp
318
    UIProcess/gtk/WebProcessPoolGtk.cpp
320
    UIProcess/gtk/WebProcessPoolGtk.cpp
- a/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp -4 / +12 lines
Lines 82-88 static bool decodeImage(Decoder& decoder, GRefPtr<GdkPixbuf>& pixbuf) a/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp_sec1
82
    return true;
82
    return true;
83
}
83
}
84
84
85
static void encodeDataObject(Encoder& encoder, const DataObjectGtk* dataObject)
85
void encode(Encoder& encoder, const DataObjectGtk* dataObject)
86
{
86
{
87
    bool hasText = dataObject->hasText();
87
    bool hasText = dataObject->hasText();
88
    encoder << hasText;
88
    encoder << hasText;
Lines 113-121 static void encodeDataObject(Encoder& encoder, const DataObjectGtk* dataObject) a/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp_sec2
113
    encoder << hasUnknownTypeData;
113
    encoder << hasUnknownTypeData;
114
    if (hasUnknownTypeData)
114
    if (hasUnknownTypeData)
115
        encoder << dataObject->unknownTypes();
115
        encoder << dataObject->unknownTypes();
116
117
    bool canSmartReplace = dataObject->canSmartReplace();
118
    encoder << canSmartReplace;
116
}
119
}
117
120
118
static bool decodeDataObject(Decoder& decoder, RefPtr<DataObjectGtk>& dataObject)
121
bool decode(Decoder& decoder, RefPtr<DataObjectGtk>& dataObject)
119
{
122
{
120
    RefPtr<DataObjectGtk> data = DataObjectGtk::create();
123
    RefPtr<DataObjectGtk> data = DataObjectGtk::create();
121
124
Lines 182-187 static bool decodeDataObject(Decoder& decoder, RefPtr<DataObjectGtk>& dataObject a/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp_sec3
182
            data->setUnknownTypeData(it->key, it->value);
185
            data->setUnknownTypeData(it->key, it->value);
183
    }
186
    }
184
187
188
    bool canSmartReplace;
189
    if (!decoder.decode(canSmartReplace))
190
        return false;
191
    data->setCanSmartReplace(canSmartReplace);
192
185
    dataObject = data;
193
    dataObject = data;
186
194
187
    return true;
195
    return true;
Lines 198-204 void ArgumentCoder<DragData>::encode(Encoder& encoder, const DragData& dragData) a/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp_sec4
198
    DataObjectGtk* platformData = dragData.platformData();
206
    DataObjectGtk* platformData = dragData.platformData();
199
    encoder << static_cast<bool>(platformData);
207
    encoder << static_cast<bool>(platformData);
200
    if (platformData)
208
    if (platformData)
201
        encodeDataObject(encoder, platformData);
209
        IPC::encode(encoder, platformData);
202
}
210
}
203
211
204
bool ArgumentCoder<DragData>::decode(Decoder& decoder, DragData& dragData)
212
bool ArgumentCoder<DragData>::decode(Decoder& decoder, DragData& dragData)
Lines 225-231 bool ArgumentCoder<DragData>::decode(Decoder& decoder, DragData& dragData) a/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp_sec5
225
233
226
    RefPtr<DataObjectGtk> platformData;
234
    RefPtr<DataObjectGtk> platformData;
227
    if (hasPlatformData) {
235
    if (hasPlatformData) {
228
        if (!decodeDataObject(decoder, platformData))
236
        if (!IPC::decode(decoder, platformData))
229
            return false;
237
            return false;
230
    }
238
    }
231
239
- a/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.h +3 lines
Lines 52-57 bool decode(Decoder&, GRefPtr<GtkPrintSettings>&); a/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.h_sec1
52
void encode(Encoder&, GtkPageSetup*);
52
void encode(Encoder&, GtkPageSetup*);
53
bool decode(Decoder&, GRefPtr<GtkPageSetup>&);
53
bool decode(Decoder&, GRefPtr<GtkPageSetup>&);
54
54
55
void encode(Encoder&, const WebCore::DataObjectGtk*);
56
bool decode(Decoder&, RefPtr<WebCore::DataObjectGtk>&);
57
55
} // namespace IPC
58
} // namespace IPC
56
59
57
#endif // ArgumentCodersGtk_h
60
#endif // ArgumentCodersGtk_h
- a/Source/WebKit2/Shared/gtk/PasteboardContent.cpp +46 lines
Line 0 a/Source/WebKit2/Shared/gtk/PasteboardContent.cpp_sec1
1
/*
2
 *  Copyright (C) 2016 Red Hat Inc.
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
#include "config.h"
20
#include "PasteboardContent.h"
21
22
#include "ArgumentCodersGtk.h"
23
#include "DataObjectGtk.h"
24
#include "Decoder.h"
25
#include "Encoder.h"
26
#include <wtf/RetainPtr.h>
27
28
namespace WebKit {
29
30
PasteboardContent::PasteboardContent(const RefPtr<WebCore::DataObjectGtk>& data)
31
    : dataObject(data)
32
{
33
    ASSERT(dataObject);
34
}
35
36
void PasteboardContent::encode(IPC::Encoder& encoder) const
37
{
38
    IPC::encode(encoder, dataObject.get());
39
}
40
41
bool PasteboardContent::decode(IPC::Decoder& decoder, PasteboardContent& pasteboardContent)
42
{
43
    return IPC::decode(decoder, pasteboardContent.dataObject);
44
}
45
46
} // namespace WebKit
- a/Source/WebKit2/Shared/gtk/PasteboardContent.h +43 lines
Line 0 a/Source/WebKit2/Shared/gtk/PasteboardContent.h_sec1
1
/*
2
 *  Copyright (C) 2016 Red Hat Inc.
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
#ifndef PasteboardContent_h
20
#define PasteboardContent_h
21
22
#include "DataObjectGtk.h"
23
24
namespace IPC {
25
class Decoder;
26
class Encoder;
27
}
28
29
namespace WebKit {
30
31
struct PasteboardContent {
32
    PasteboardContent() = default;
33
    explicit PasteboardContent(const RefPtr<WebCore::DataObjectGtk>&);
34
35
    RefPtr<WebCore::DataObjectGtk> dataObject;
36
37
    void encode(IPC::Encoder&) const;
38
    static bool decode(IPC::Decoder&, PasteboardContent&);
39
};
40
41
} // namespace WebKit
42
43
#endif // PasteboardContent_h
- a/Source/WebKit2/UIProcess/WebFrameProxy.cpp +14 lines
Lines 31-36 a/Source/WebKit2/UIProcess/WebFrameProxy.cpp_sec1
31
#include "WebFramePolicyListenerProxy.h"
31
#include "WebFramePolicyListenerProxy.h"
32
#include "WebPageMessages.h"
32
#include "WebPageMessages.h"
33
#include "WebPageProxy.h"
33
#include "WebPageProxy.h"
34
#include "WebPasteboardProxy.h"
34
#include "WebProcessPool.h"
35
#include "WebProcessPool.h"
35
#include <WebCore/Image.h>
36
#include <WebCore/Image.h>
36
#include <WebCore/MIMETypeRegistry.h>
37
#include <WebCore/MIMETypeRegistry.h>
Lines 52-57 WebFrameProxy::WebFrameProxy(WebPageProxy* page, uint64_t frameID) a/Source/WebKit2/UIProcess/WebFrameProxy.cpp_sec2
52
WebFrameProxy::~WebFrameProxy()
53
WebFrameProxy::~WebFrameProxy()
53
{
54
{
54
    WebProcessPool::statistics().wkFrameCount--;
55
    WebProcessPool::statistics().wkFrameCount--;
56
#if PLATFORM(GTK)
57
    WebPasteboardProxy::singleton().didDestroyFrame(this);
58
#endif
55
}
59
}
56
60
57
void WebFrameProxy::webProcessWillShutDown()
61
void WebFrameProxy::webProcessWillShutDown()
Lines 254-257 bool WebFrameProxy::didHandleContentFilterUnblockNavigation(const WebCore::Resou a/Source/WebKit2/UIProcess/WebFrameProxy.cpp_sec3
254
}
258
}
255
#endif
259
#endif
256
260
261
#if PLATFORM(GTK)
262
void WebFrameProxy::collapseSelection()
263
{
264
    if (!m_page)
265
        return;
266
267
    m_page->process().send(Messages::WebPage::CollapseSelectionInFrame(m_frameID), m_page->pageID());
268
}
269
#endif
270
257
} // namespace WebKit
271
} // namespace WebKit
- a/Source/WebKit2/UIProcess/WebFrameProxy.h +4 lines
Lines 124-129 public: a/Source/WebKit2/UIProcess/WebFrameProxy.h_sec1
124
    bool didHandleContentFilterUnblockNavigation(const WebCore::ResourceRequest&);
124
    bool didHandleContentFilterUnblockNavigation(const WebCore::ResourceRequest&);
125
#endif
125
#endif
126
126
127
#if PLATFORM(GTK)
128
    void collapseSelection();
129
#endif
130
127
private:
131
private:
128
    WebFrameProxy(WebPageProxy* page, uint64_t frameID);
132
    WebFrameProxy(WebPageProxy* page, uint64_t frameID);
129
133
- a/Source/WebKit2/UIProcess/WebPasteboardProxy.h +17 lines
Lines 40-47 struct PasteboardWebContent; a/Source/WebKit2/UIProcess/WebPasteboardProxy.h_sec1
40
40
41
namespace WebKit {
41
namespace WebKit {
42
42
43
class WebFrameProxy;
43
class WebProcessProxy;
44
class WebProcessProxy;
44
45
46
#if PLATFORM(GTK)
47
class PasteboardContent;
48
#endif
49
45
class WebPasteboardProxy : public IPC::MessageReceiver {
50
class WebPasteboardProxy : public IPC::MessageReceiver {
46
    WTF_MAKE_NONCOPYABLE(WebPasteboardProxy);
51
    WTF_MAKE_NONCOPYABLE(WebPasteboardProxy);
47
    friend class LazyNeverDestroyed<WebPasteboardProxy>;
52
    friend class LazyNeverDestroyed<WebPasteboardProxy>;
Lines 50-55 public: a/Source/WebKit2/UIProcess/WebPasteboardProxy.h_sec2
50
55
51
    void addWebProcessProxy(WebProcessProxy&);
56
    void addWebProcessProxy(WebProcessProxy&);
52
57
58
#if PLATFORM(GTK)
59
    void setPrimarySelectionOwner(WebFrameProxy*);
60
    void didDestroyFrame(WebFrameProxy*);
61
#endif
62
53
private:
63
private:
54
    WebPasteboardProxy();
64
    WebPasteboardProxy();
55
65
Lines 81-86 private: a/Source/WebKit2/UIProcess/WebPasteboardProxy.h_sec3
81
    void setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String&, uint64_t& newChangeCount);
91
    void setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String&, uint64_t& newChangeCount);
82
    void setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size, uint64_t& newChangeCount);
92
    void setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size, uint64_t& newChangeCount);
83
#endif
93
#endif
94
#if PLATFORM(GTK)
95
    void writeToClipboard(const String& pasteboardName, const PasteboardContent&);
96
    void readFromClipboard(const String& pasteboardName, PasteboardContent&);
97
98
    WebFrameProxy* m_primarySelectionOwner { nullptr };
99
    WebFrameProxy* m_frameWritingToClipboard { nullptr };
100
#endif // PLATFORM(GTK)
84
};
101
};
85
102
86
} // namespace WebKit
103
} // namespace WebKit
- a/Source/WebKit2/UIProcess/WebPasteboardProxy.messages.in +5 lines
Lines 48-51 messages -> WebPasteboardProxy { a/Source/WebKit2/UIProcess/WebPasteboardProxy.messages.in_sec1
48
    SetPasteboardStringForType(String pasteboardName, String pasteboardType, String string) -> (uint64_t changeCount)
48
    SetPasteboardStringForType(String pasteboardName, String pasteboardType, String string) -> (uint64_t changeCount)
49
    SetPasteboardBufferForType(String pasteboardName, String pasteboardType, WebKit::SharedMemory::Handle handle, uint64_t size) -> (uint64_t changeCount)
49
    SetPasteboardBufferForType(String pasteboardName, String pasteboardType, WebKit::SharedMemory::Handle handle, uint64_t size) -> (uint64_t changeCount)
50
#endif
50
#endif
51
52
#if PLATFORM(GTK)
53
    WriteToClipboard(String pasteboardName, struct WebKit::PasteboardContent pasteboardContent)
54
    ReadFromClipboard(String pasteboardName) -> (struct WebKit::PasteboardContent pasteboardContent)
55
#endif
51
}
56
}
- a/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp +3 lines
Lines 31-36 a/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp_sec1
31
#include "PageClientImpl.h"
31
#include "PageClientImpl.h"
32
#include "WebKitWebViewBasePrivate.h"
32
#include "WebKitWebViewBasePrivate.h"
33
#include "WebPageMessages.h"
33
#include "WebPageMessages.h"
34
#include "WebPasteboardProxy.h"
34
#include "WebProcessProxy.h"
35
#include "WebProcessProxy.h"
35
#include "WebsiteDataStore.h"
36
#include "WebsiteDataStore.h"
36
#include <WebCore/UserAgentGtk.h>
37
#include <WebCore/UserAgentGtk.h>
Lines 79-84 void WebPageProxy::editorStateChanged(const EditorState& editorState) a/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp_sec2
79
    
80
    
80
    if (editorState.shouldIgnoreCompositionSelectionChange)
81
    if (editorState.shouldIgnoreCompositionSelectionChange)
81
        return;
82
        return;
83
    if (m_editorState.selectionIsRange)
84
        WebPasteboardProxy::singleton().setPrimarySelectionOwner(focusedFrame());
82
    m_pageClient.selectionDidChange();
85
    m_pageClient.selectionDidChange();
83
}
86
}
84
87
- a/Source/WebKit2/UIProcess/gtk/WebPasteboardProxyGtk.cpp +73 lines
Line 0 a/Source/WebKit2/UIProcess/gtk/WebPasteboardProxyGtk.cpp_sec1
1
/*
2
 * Copyright (C) 2016 Red Hat Inc.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
 * THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#include "config.h"
27
#include "WebPasteboardProxy.h"
28
29
#include "PasteboardContent.h"
30
#include "WebFrameProxy.h"
31
#include <WebCore/PlatformPasteboard.h>
32
#include <wtf/HashMap.h>
33
#include <wtf/NeverDestroyed.h>
34
#include <wtf/TemporaryChange.h>
35
#include <wtf/text/StringHash.h>
36
37
using namespace WebCore;
38
39
namespace WebKit {
40
41
void WebPasteboardProxy::writeToClipboard(const String& pasteboardName, const PasteboardContent& pasteboardContent)
42
{
43
    TemporaryChange<WebFrameProxy*> frameWritingToClipboard(m_frameWritingToClipboard, m_primarySelectionOwner);
44
    PlatformPasteboard(pasteboardName).writeToClipboard(pasteboardContent.dataObject, [this] {
45
        if (m_frameWritingToClipboard == m_primarySelectionOwner)
46
            return;
47
        setPrimarySelectionOwner(nullptr);
48
    });
49
}
50
51
void WebPasteboardProxy::readFromClipboard(const String& pasteboardName, PasteboardContent& pasteboardContent)
52
{
53
    pasteboardContent = PasteboardContent(PlatformPasteboard(pasteboardName).readFromClipboard().get());
54
}
55
56
void WebPasteboardProxy::setPrimarySelectionOwner(WebFrameProxy* frame)
57
{
58
    if (m_primarySelectionOwner == frame)
59
        return;
60
61
    if (m_primarySelectionOwner)
62
        m_primarySelectionOwner->collapseSelection();
63
64
    m_primarySelectionOwner = frame;
65
}
66
67
void WebPasteboardProxy::didDestroyFrame(WebFrameProxy* frame)
68
{
69
    if (frame == m_primarySelectionOwner)
70
        m_primarySelectionOwner = nullptr;
71
}
72
73
} // namespace WebKit
- a/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp +22 lines
Lines 69-74 a/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp_sec1
69
#include "StringUtilities.h"
69
#include "StringUtilities.h"
70
#endif
70
#endif
71
71
72
#if PLATFORM(GTK)
73
#include "PasteboardContent.h"
74
#endif
75
72
using namespace WebCore;
76
using namespace WebCore;
73
77
74
namespace WebKit {
78
namespace WebKit {
Lines 339-342 long WebPlatformStrategies::changeCount() a/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp_sec2
339
343
340
#endif // PLATFORM(COCOA)
344
#endif // PLATFORM(COCOA)
341
345
346
#if PLATFORM(GTK)
347
// PasteboardStrategy
348
349
void WebPlatformStrategies::writeToClipboard(const String& pasteboardName, const RefPtr<WebCore::DataObjectGtk>& dataObject)
350
{
351
    PasteboardContent pasteboardContent = PasteboardContent(dataObject.get());
352
    WebProcess::singleton().parentProcessConnection()->send(Messages::WebPasteboardProxy::WriteToClipboard(pasteboardName, pasteboardContent), 0);
353
}
354
355
RefPtr<WebCore::DataObjectGtk> WebPlatformStrategies::readFromClipboard(const String& pasteboardName)
356
{
357
    PasteboardContent pasteboardContent;
358
    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadFromClipboard(pasteboardName), Messages::WebPasteboardProxy::ReadFromClipboard::Reply(pasteboardContent), 0);
359
    return pasteboardContent.dataObject;
360
}
361
362
#endif // PLATFORM(GTK)
363
342
} // namespace WebKit
364
} // namespace WebKit
- a/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h -1 / +4 lines
Lines 86-92 private: a/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h_sec1
86
    long setPathnamesForType(const Vector<String>&, const String& pasteboardType, const String& pasteboardName) override;
86
    long setPathnamesForType(const Vector<String>&, const String& pasteboardType, const String& pasteboardName) override;
87
    long setStringForType(const String&, const String& pasteboardType, const String& pasteboardName) override;
87
    long setStringForType(const String&, const String& pasteboardType, const String& pasteboardName) override;
88
#endif
88
#endif
89
89
#if PLATFORM(GTK)
90
    void writeToClipboard(const String& pasteboardName, const RefPtr<WebCore::DataObjectGtk>&) override;
91
    RefPtr<WebCore::DataObjectGtk> readFromClipboard(const String& pasteboardName) override;
92
#endif
90
};
93
};
91
94
92
} // namespace WebKit
95
} // namespace WebKit
- a/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp -49 lines
Lines 119-163 void WebEditorClient::handleInputMethodKeydown(KeyboardEvent* event) a/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp_sec1
119
        event->setDefaultHandled();
119
        event->setDefaultHandled();
120
}
120
}
121
121
122
class EditorClientFrameDestructionObserver : FrameDestructionObserver {
123
public:
124
    EditorClientFrameDestructionObserver(Frame* frame, GClosure* closure)
125
        : FrameDestructionObserver(frame)
126
        , m_closure(closure)
127
    {
128
        g_closure_add_finalize_notifier(m_closure, this, destroyOnClosureFinalization);
129
    }
130
131
    void frameDestroyed()
132
    {
133
        g_closure_invalidate(m_closure);
134
        FrameDestructionObserver::frameDestroyed();
135
    }
136
private:
137
    GClosure* m_closure;
138
139
    static void destroyOnClosureFinalization(gpointer data, GClosure*)
140
    {
141
        // Calling delete void* will free the memory but won't invoke
142
        // the destructor, something that is a must for us.
143
        EditorClientFrameDestructionObserver* observer = static_cast<EditorClientFrameDestructionObserver*>(data);
144
        delete observer;
145
    }
146
};
147
148
static Frame* frameSettingClipboard;
149
150
static void collapseSelection(GtkClipboard*, Frame* frame)
151
{
152
    if (frameSettingClipboard && frameSettingClipboard == frame)
153
        return;
154
155
    // Collapse the selection without clearing it.
156
    ASSERT(frame);
157
    const VisibleSelection& selection = frame->selection().selection();
158
    frame->selection().setBase(selection.extent(), selection.affinity());
159
}
160
161
void WebEditorClient::updateGlobalSelection(Frame* frame)
122
void WebEditorClient::updateGlobalSelection(Frame* frame)
162
{
123
{
163
    if (!frame->selection().isRange())
124
    if (!frame->selection().isRange())
Lines 166-186 void WebEditorClient::updateGlobalSelection(Frame* frame) a/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp_sec2
166
    if (!range)
127
    if (!range)
167
        return;
128
        return;
168
129
169
    frameSettingClipboard = frame;
170
    GRefPtr<GClosure> callback = adoptGRef(g_cclosure_new(G_CALLBACK(collapseSelection), frame, nullptr));
171
    // This observer will be self-destroyed on closure finalization,
172
    // that will happen either after closure execution or after
173
    // closure invalidation.
174
    new EditorClientFrameDestructionObserver(frame, callback.get());
175
    g_closure_set_marshal(callback.get(), g_cclosure_marshal_VOID__VOID);
176
177
    PasteboardWebContent pasteboardContent;
130
    PasteboardWebContent pasteboardContent;
178
    pasteboardContent.canSmartCopyOrDelete = false;
131
    pasteboardContent.canSmartCopyOrDelete = false;
179
    pasteboardContent.text = range->text();
132
    pasteboardContent.text = range->text();
180
    pasteboardContent.markup = createMarkup(*range, nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
133
    pasteboardContent.markup = createMarkup(*range, nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
181
    pasteboardContent.callback = callback;
182
    Pasteboard::createForGlobalSelection()->write(pasteboardContent);
134
    Pasteboard::createForGlobalSelection()->write(pasteboardContent);
183
    frameSettingClipboard = nullptr;
184
}
135
}
185
136
186
bool WebEditorClient::shouldShowUnicodeMenu()
137
bool WebEditorClient::shouldShowUnicodeMenu()
- a/Source/WebKit2/WebProcess/WebPage/WebPage.h +2 lines
Lines 646-651 public: a/Source/WebKit2/WebProcess/WebPage/WebPage.h_sec1
646
    void setComposition(const String& text, const Vector<WebCore::CompositionUnderline>& underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeLength);
646
    void setComposition(const String& text, const Vector<WebCore::CompositionUnderline>& underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeLength);
647
    void confirmComposition(const String& text, int64_t selectionStart, int64_t selectionLength);
647
    void confirmComposition(const String& text, int64_t selectionStart, int64_t selectionLength);
648
    void cancelComposition();
648
    void cancelComposition();
649
650
    void collapseSelectionInFrame(uint64_t frameID);
649
#endif
651
#endif
650
652
651
#if PLATFORM (GTK) && HAVE(GTK_GESTURES)
653
#if PLATFORM (GTK) && HAVE(GTK_GESTURES)
- a/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in +2 lines
Lines 340-345 messages -> WebPage LegacyReceiver { a/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in_sec1
340
    SetComposition(String text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)
340
    SetComposition(String text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)
341
    ConfirmComposition(String text, int64_t selectionStart, int64_t selectionLength)
341
    ConfirmComposition(String text, int64_t selectionStart, int64_t selectionLength)
342
    CancelComposition()
342
    CancelComposition()
343
344
    CollapseSelectionInFrame(uint64_t frameID)
343
#endif
345
#endif
344
346
345
#if PLATFORM (GTK) && HAVE(GTK_GESTURES)
347
#if PLATFORM (GTK) && HAVE(GTK_GESTURES)
- a/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp +13 lines
Lines 31-38 a/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp_sec1
31
#include "EditorState.h"
31
#include "EditorState.h"
32
#include "NotImplemented.h"
32
#include "NotImplemented.h"
33
#include "WebEvent.h"
33
#include "WebEvent.h"
34
#include "WebFrame.h"
34
#include "WebPageAccessibilityObject.h"
35
#include "WebPageAccessibilityObject.h"
35
#include "WebPageProxyMessages.h"
36
#include "WebPageProxyMessages.h"
37
#include "WebProcess.h"
36
#include "WindowsKeyboardCodes.h"
38
#include "WindowsKeyboardCodes.h"
37
#include <WebCore/BackForwardController.h>
39
#include <WebCore/BackForwardController.h>
38
#include <WebCore/EventHandler.h>
40
#include <WebCore/EventHandler.h>
Lines 216-219 void WebPage::setInputMethodState(bool enabled) a/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp_sec2
216
    send(Messages::WebPageProxy::SetInputMethodState(enabled));
218
    send(Messages::WebPageProxy::SetInputMethodState(enabled));
217
}
219
}
218
220
221
void WebPage::collapseSelectionInFrame(uint64_t frameID)
222
{
223
    WebFrame* frame = WebProcess::singleton().webFrame(frameID);
224
    if (!frame || !frame->coreFrame())
225
        return;
226
227
    // Collapse the selection without clearing it.
228
    const VisibleSelection& selection = frame->coreFrame()->selection().selection();
229
    frame->coreFrame()->selection().setBase(selection.extent(), selection.affinity());
230
}
231
219
} // namespace WebKit
232
} // namespace WebKit

Return to Bug 146574