initial import
[vuplus_webkit] / Source / WebCore / page / qt / FrameQt.cpp
1 /*
2  * Redistribution and use in source and binary forms, with or without
3  * modification, are permitted provided that the following conditions
4  * are met:
5  * 1. Redistributions of source code must retain the above copyright
6  *    notice, this list of conditions and the following disclaimer.
7  * 2. Redistributions in binary form must reproduce the above copyright
8  *    notice, this list of conditions and the following disclaimer in the
9  *    documentation and/or other materials provided with the distribution.
10  *
11  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
12  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
13  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
14  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
15  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
18  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
19  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22  */
23
24 #include "config.h"
25 #include "Document.h"
26 #include "Frame.h"
27 #include "FrameView.h"
28 #include "GraphicsContext.h"
29 #include "Image.h"
30 #include "ImageBuffer.h"
31
32 #include "NotImplemented.h"
33
34 namespace WebCore {
35
36 DragImageRef Frame::nodeImage(Node*)
37 {
38     notImplemented();
39     return 0;
40 }
41
42 DragImageRef Frame::dragImageForSelection()
43 {
44     if (!selection()->isRange())
45         return 0;
46
47     m_doc->updateLayout();
48
49     IntRect paintingRect = enclosingIntRect(selection()->bounds());
50     OwnPtr<ImageBuffer> buffer(ImageBuffer::create(paintingRect.size()));
51     if (!buffer)
52         return 0;
53
54     GraphicsContext* context = buffer->context();
55     context->translate(-paintingRect.x(), -paintingRect.y());
56     context->clip(FloatRect(0, 0, paintingRect.maxX(), paintingRect.maxY()));
57
58     PaintBehavior previousPaintBehavior = m_view->paintBehavior();
59     m_view->setPaintBehavior(PaintBehaviorSelectionOnly);
60     m_view->paintContents(context, paintingRect);
61     m_view->setPaintBehavior(previousPaintBehavior);
62
63     RefPtr<Image> image = buffer->copyImage();
64     return createDragImageFromImage(image.get());
65 }
66
67 }
68 // vim: ts=4 sw=4 et