summaryrefslogtreecommitdiffstats
path: root/webkit/glue/scoped_clipboard_writer_glue.cc
blob: f648b7bf1c1b8ebd3d3e80170a89fc22b2337492 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "webkit/glue/scoped_clipboard_writer_glue.h"
#include "base/logging.h"

ScopedClipboardWriterGlue::ScopedClipboardWriterGlue(
    webkit_glue::ClipboardClient* client)
    : ui::ScopedClipboardWriter(client->GetClipboard(),
                                ui::Clipboard::BUFFER_STANDARD),
      context_(client->CreateWriteContext()) {
  // We should never have an instance where both are set.
  DCHECK((clipboard_ && !context_.get()) ||
         (!clipboard_ && context_.get()));
}

ScopedClipboardWriterGlue::~ScopedClipboardWriterGlue() {
  if (!objects_.empty() && context_.get()) {
    context_->Flush(objects_);
  }
}

void ScopedClipboardWriterGlue::WriteBitmapFromPixels(const void* pixels,
                                                      const gfx::Size& size) {
  if (context_.get()) {
    context_->WriteBitmapFromPixels(&objects_, pixels, size);
  } else {
    ScopedClipboardWriter::WriteBitmapFromPixels(pixels, size);
  }
}