• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 Zack Rusin <zack@kde.org>
3  * Copyright (C) 2007 Ryan Leavengood <leavengood@gmail.com>
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #include "config.h"
28 #include "Pasteboard.h"
29 
30 #include "DocumentFragment.h"
31 #include "Editor.h"
32 #include "Frame.h"
33 #include "KURL.h"
34 #include "NotImplemented.h"
35 #include "markup.h"
36 #include <support/Locker.h>
37 #include <Clipboard.h>
38 #include <Message.h>
39 #include <String.h>
40 
41 
42 namespace WebCore {
43 
Pasteboard()44 Pasteboard::Pasteboard()
45 {
46 }
47 
generalPasteboard()48 Pasteboard* Pasteboard::generalPasteboard()
49 {
50     static Pasteboard* pasteboard = new Pasteboard();
51     return pasteboard;
52 }
53 
writeSelection(Range * selectedRange,bool canSmartCopyOrDelete,Frame * frame)54 void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
55 {
56     BClipboard clipboard("WebKit");
57     if (!clipboard.Lock())
58         return;
59 
60     clipboard.Clear();
61     BMessage* data = clipboard.Data();
62     if (!data)
63         return;
64 
65     data->AddString("text/plain", BString(frame->selectedText()));
66     clipboard.Commit();
67 
68     clipboard.Unlock();
69 }
70 
canSmartReplace()71 bool Pasteboard::canSmartReplace()
72 {
73     notImplemented();
74     return false;
75 }
76 
plainText(Frame * frame)77 String Pasteboard::plainText(Frame* frame)
78 {
79     BClipboard clipboard("WebKit");
80     if (!clipboard.Lock())
81         return String();
82 
83     BMessage* data = clipboard.Data();
84     if (!data)
85         return String();
86 
87     BString string;
88     data->FindString("text/plain", &string);
89 
90     clipboard.Unlock();
91 
92     return string;
93 }
94 
documentFragment(Frame * frame,PassRefPtr<Range> context,bool allowPlainText,bool & chosePlainText)95 PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context,
96                                                           bool allowPlainText, bool& chosePlainText)
97 {
98     notImplemented();
99     return 0;
100 }
101 
writeURL(const KURL & url,const String &,Frame *)102 void Pasteboard::writeURL(const KURL& url, const String&, Frame*)
103 {
104     BClipboard clipboard("WebKit");
105     if (!clipboard.Lock())
106         return;
107 
108     clipboard.Clear();
109 
110     BMessage* data = clipboard.Data();
111     if (!data)
112         return;
113 
114     data->AddString("text/plain", url.string());
115     clipboard.Commit();
116 
117     clipboard.Unlock();
118 }
119 
writeImage(Node *,const KURL &,const String &)120 void Pasteboard::writeImage(Node*, const KURL&, const String&)
121 {
122     notImplemented();
123 }
124 
clear()125 void Pasteboard::clear()
126 {
127     BClipboard clipboard("WebKit");
128     if (!clipboard.Lock())
129         return;
130 
131     clipboard.Clear();
132     clipboard.Commit();
133 
134     clipboard.Unlock();
135 }
136 
137 } // namespace WebCore
138 
139