Logo Search packages:      
Sourcecode: chromium-browser version File versions  Download package


// Copyright (c) 2009 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 <vector>

#include "base/scoped_ptr.h"
#include "base/time.h"
#include "gfx/size.h"
#include "third_party/WebKit/WebKit/chromium/public/WebViewClient.h"

namespace gfx {
class Size;

namespace IPC {
class Message;

#if defined(USE_X11)
namespace printing {
class PdfPsMetafile;
typedef PdfPsMetafile NativeMetafile;

class RenderView;
struct ViewMsg_Print_Params;
struct ViewMsg_PrintPage_Params;
struct ViewMsg_PrintPages_Params;

// Class that calls the Begin and End print functions on the frame and changes
// the size of the view temporarily to support full page printing..
// Do not serve any events in the time between construction and destruction of
// this class because it will cause flicker.
class PrepareFrameAndViewForPrint {
  PrepareFrameAndViewForPrint(const ViewMsg_Print_Params& print_params,
                              WebKit::WebFrame* frame,
                              WebKit::WebView* web_view);

  int GetExpectedPageCount() const {
    return expected_pages_count_;

  bool ShouldUseBrowserOverlays() const {
    return use_browser_overlays_;

  const gfx::Size& GetPrintCanvasSize() const {
    return print_canvas_size_;

  WebKit::WebFrame* frame_;
  WebKit::WebView* web_view_;
  gfx::Size print_canvas_size_;
  gfx::Size prev_view_size_;
  int expected_pages_count_;
  bool use_browser_overlays_;


// PrintWebViewHelper handles most of the printing grunt work for RenderView.
// We plan on making print asynchronous and that will require copying the DOM
// of the document and creating a new WebView with the contents.
class PrintWebViewHelper : public WebKit::WebViewClient {
  explicit PrintWebViewHelper(RenderView* render_view);
  virtual ~PrintWebViewHelper();

  void Print(WebKit::WebFrame* frame, bool script_initiated);

  // Is there a background print in progress?
  bool IsPrinting() {
    return print_web_view_ != NULL;

  // Notification when printing is done - signal teardown
  void DidFinishPrinting(bool success);

  // Prints the page listed in |params| as a JPEG image. The width and height of
  // the image will scale propotionally given the |zoom_factor| multiplier. The
  // encoded JPEG data will be written into the supplied vector |image_data|.
  void PrintPageAsJPEG(const ViewMsg_PrintPage_Params& params,
                       WebKit::WebFrame* frame,
                       float zoom_factor,
                       std::vector<unsigned char>* image_data);

  bool CopyAndPrint(const ViewMsg_PrintPages_Params& params,
                    WebKit::WebFrame* web_frame);

  // Prints the page listed in |params|.
#if defined(USE_X11)
  void PrintPage(const ViewMsg_PrintPage_Params& params,
                 const gfx::Size& canvas_size,
                 WebKit::WebFrame* frame,
                 printing::NativeMetafile* metafile);
  void PrintPage(const ViewMsg_PrintPage_Params& params,
                 const gfx::Size& canvas_size,
                 WebKit::WebFrame* frame);

  // Prints all the pages listed in |params|.
  // It will implicitly revert the document to display CSS media type.
  void PrintPages(const ViewMsg_PrintPages_Params& params,
                  WebKit::WebFrame* frame);

  // IPC::Message::Sender
  bool Send(IPC::Message* msg);

  int32 routing_id();

  // WebKit::WebViewClient override:
  virtual void didStopLoading();

  RenderView* render_view_;
  WebKit::WebView* print_web_view_;
  scoped_ptr<ViewMsg_PrintPages_Params> print_pages_params_;
  base::Time last_cancelled_script_print_;
  int user_cancelled_scripted_print_count_;



Generated by  Doxygen 1.6.0   Back to index