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 "Frame.h"
26#include "FrameView.h"
27#include "GraphicsContext.h"
28#include "Image.h"
29#include "ImageBuffer.h"
30
31#include "NotImplemented.h"
32
33namespace WebCore {
34
35DragImageRef Frame::nodeImage(Node*)
36{
37    notImplemented();
38    return 0;
39}
40
41DragImageRef Frame::dragImageForSelection()
42{
43    if (!selection()->isRange())
44        return 0;
45
46    m_doc->updateLayout();
47
48    IntRect paintingRect = enclosingIntRect(selection()->bounds());
49    OwnPtr<ImageBuffer> buffer(ImageBuffer::create(paintingRect.size()));
50    if (!buffer)
51        return 0;
52
53    GraphicsContext* context = buffer->context();
54    context->translate(-paintingRect.x(), -paintingRect.y());
55    context->clip(FloatRect(0, 0, paintingRect.maxX(), paintingRect.maxY()));
56
57    PaintBehavior previousPaintBehavior = m_view->paintBehavior();
58    m_view->setPaintBehavior(PaintBehaviorSelectionOnly);
59    m_view->paintContents(context, paintingRect);
60    m_view->setPaintBehavior(previousPaintBehavior);
61
62    RefPtr<Image> image = buffer->copyImage();
63    return createDragImageFromImage(image.get());
64}
65
66}
67// vim: ts=4 sw=4 et
68