summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xfa_test/FormFiller_Test/BookMarkView.cpp197
-rw-r--r--xfa_test/FormFiller_Test/BookMarkView.h67
-rw-r--r--xfa_test/FormFiller_Test/ChildFrm.cpp112
-rw-r--r--xfa_test/FormFiller_Test/ChildFrm.h64
-rw-r--r--xfa_test/FormFiller_Test/ConvertDlg.cpp65
-rw-r--r--xfa_test/FormFiller_Test/ConvertDlg.h47
-rw-r--r--xfa_test/FormFiller_Test/ExportPage.cpp189
-rw-r--r--xfa_test/FormFiller_Test/ExportPage.h59
-rw-r--r--xfa_test/FormFiller_Test/FX_SplitterWnd.cpp373
-rw-r--r--xfa_test/FormFiller_Test/FX_SplitterWnd.h44
-rw-r--r--xfa_test/FormFiller_Test/FindDlg.cpp73
-rw-r--r--xfa_test/FormFiller_Test/FindDlg.h50
-rw-r--r--xfa_test/FormFiller_Test/GotoPageDlg.cpp65
-rw-r--r--xfa_test/FormFiller_Test/GotoPageDlg.h48
-rw-r--r--xfa_test/FormFiller_Test/JS_ResponseDlg.cpp152
-rw-r--r--xfa_test/FormFiller_Test/JS_ResponseDlg.h64
-rw-r--r--xfa_test/FormFiller_Test/MainFrm.cpp238
-rw-r--r--xfa_test/FormFiller_Test/MainFrm.h56
-rw-r--r--xfa_test/FormFiller_Test/ReaderVC.cpp195
-rw-r--r--xfa_test/FormFiller_Test/ReaderVC.dsp460
-rw-r--r--xfa_test/FormFiller_Test/ReaderVC.h54
-rw-r--r--xfa_test/FormFiller_Test/ReaderVC.rc741
-rw-r--r--xfa_test/FormFiller_Test/ReaderVCDoc.cpp113
-rw-r--r--xfa_test/FormFiller_Test/ReaderVCDoc.h59
-rw-r--r--xfa_test/FormFiller_Test/ReaderVCView.cpp3750
-rw-r--r--xfa_test/FormFiller_Test/ReaderVCView.h375
-rw-r--r--xfa_test/FormFiller_Test/StdAfx.cpp8
-rw-r--r--xfa_test/FormFiller_Test/StdAfx.h99
-rw-r--r--xfa_test/FormFiller_Test/TestJsDlg.cpp58
-rw-r--r--xfa_test/FormFiller_Test/TestJsDlg.h46
-rw-r--r--xfa_test/FormFiller_Test/ZoomDlg.cpp104
-rw-r--r--xfa_test/FormFiller_Test/ZoomDlg.h48
-rw-r--r--xfa_test/FormFiller_Test/res/BigHandCursor.curbin326 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/Rd_SelText_Icon.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/Rd_SelText_Icon_Dis.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/ReaderVC.icobin1078 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/ReaderVC.rc213
-rw-r--r--xfa_test/FormFiller_Test/res/ReaderVCDoc.icobin1078 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/SmallHandCursor.curbin326 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/Toolbar.bmpbin5590 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/bookmark.bmpbin2358 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/bound.curbin326 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/point.curbin326 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_actual_size.bmpbin406 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_bookmark1.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_clockwise.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_counterclockwise.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_first.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_fit_page.bmpbin406 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_fit_width.bmpbin406 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hand1.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_about2.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_actual_size.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_bookmark1.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_clockwise.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_counterclockwise.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_first.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_first.xpm109
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_fit_page.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_fit_width.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_hand1.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_last.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_next.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_open1.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_prev.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_print.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_search.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_snap_shot.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_zoomin.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_hot_zoomout.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_last.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_next.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_prev.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_print.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_search.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_snap_shot.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_zoomin.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/res/tool_zoomout.bmpbin1654 -> 0 bytes
-rw-r--r--xfa_test/FormFiller_Test/resource.h113
-rw-r--r--xfa_test/pdf/BUILD.gn99
-rw-r--r--xfa_test/pdf/DEPS9
-rw-r--r--xfa_test/pdf/Info.plist44
-rw-r--r--xfa_test/pdf/OWNERS4
-rw-r--r--xfa_test/pdf/button.cc179
-rw-r--r--xfa_test/pdf/button.h71
-rw-r--r--xfa_test/pdf/chunk_stream.cc172
-rw-r--r--xfa_test/pdf/chunk_stream.h48
-rw-r--r--xfa_test/pdf/control.cc117
-rw-r--r--xfa_test/pdf/control.h77
-rw-r--r--xfa_test/pdf/document_loader.cc513
-rw-r--r--xfa_test/pdf/document_loader.h124
-rw-r--r--xfa_test/pdf/draw_utils.cc343
-rw-r--r--xfa_test/pdf/draw_utils.h94
-rw-r--r--xfa_test/pdf/fading_control.cc75
-rw-r--r--xfa_test/pdf/fading_control.h32
-rw-r--r--xfa_test/pdf/fading_controls.cc316
-rw-r--r--xfa_test/pdf/fading_controls.h84
-rw-r--r--xfa_test/pdf/instance.cc2778
-rw-r--r--xfa_test/pdf/instance.h531
-rw-r--r--xfa_test/pdf/number_image_generator.cc81
-rw-r--r--xfa_test/pdf/number_image_generator.h37
-rw-r--r--xfa_test/pdf/out_of_process_instance.cc1369
-rw-r--r--xfa_test/pdf/out_of_process_instance.h345
-rw-r--r--xfa_test/pdf/page_indicator.cc127
-rw-r--r--xfa_test/pdf/page_indicator.h72
-rw-r--r--xfa_test/pdf/paint_aggregator.cc263
-rw-r--r--xfa_test/pdf/paint_aggregator.h130
-rw-r--r--xfa_test/pdf/paint_manager.cc302
-rw-r--r--xfa_test/pdf/paint_manager.h205
-rw-r--r--xfa_test/pdf/pdf.cc275
-rw-r--r--xfa_test/pdf/pdf.def7
-rw-r--r--xfa_test/pdf/pdf.gyp200
-rw-r--r--xfa_test/pdf/pdf.h24
-rw-r--r--xfa_test/pdf/pdf.rc104
-rw-r--r--xfa_test/pdf/pdf_engine.h321
-rw-r--r--xfa_test/pdf/pdfium/pdfium_assert_matching_enums.cc207
-rw-r--r--xfa_test/pdf/pdfium/pdfium_engine.cc3883
-rw-r--r--xfa_test/pdf/pdfium/pdfium_engine.h687
-rw-r--r--xfa_test/pdf/pdfium/pdfium_mem_buffer_file_read.cc34
-rw-r--r--xfa_test/pdf/pdfium/pdfium_mem_buffer_file_read.h30
-rw-r--r--xfa_test/pdf/pdfium/pdfium_mem_buffer_file_write.cc33
-rw-r--r--xfa_test/pdf/pdfium/pdfium_mem_buffer_file_write.h34
-rw-r--r--xfa_test/pdf/pdfium/pdfium_page.cc477
-rw-r--r--xfa_test/pdf/pdfium/pdfium_page.h136
-rw-r--r--xfa_test/pdf/pdfium/pdfium_range.cc79
-rw-r--r--xfa_test/pdf/pdfium/pdfium_range.h54
-rw-r--r--xfa_test/pdf/preview_mode_client.cc162
-rw-r--r--xfa_test/pdf/preview_mode_client.h77
-rw-r--r--xfa_test/pdf/progress_control.cc283
-rw-r--r--xfa_test/pdf/progress_control.h72
-rw-r--r--xfa_test/pdf/resource.h14
-rw-r--r--xfa_test/pdf/resource_consts.h49
-rw-r--r--xfa_test/pdf/thumbnail_control.cc301
-rw-r--r--xfa_test/pdf/thumbnail_control.h67
-rw-r--r--xfa_test/process/process.cc712
-rw-r--r--xfa_test/process/script.txt21
136 files changed, 0 insertions, 25292 deletions
diff --git a/xfa_test/FormFiller_Test/BookMarkView.cpp b/xfa_test/FormFiller_Test/BookMarkView.cpp
deleted file mode 100644
index 283c9a47cc..0000000000
--- a/xfa_test/FormFiller_Test/BookMarkView.cpp
+++ /dev/null
@@ -1,197 +0,0 @@
-// BookMarkView.cpp : implementation file
-//
-
-#include "stdafx.h"
-#include "ReaderVC.h"
-#include "ChildFrm.h"
-#include "BookMarkView.h"
-#include "ReaderVCDoc.h"
-#include "ReaderVCView.h"
-
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-// CBookMarkView
-
-IMPLEMENT_DYNCREATE(CBookMarkView, CTreeView)
-
-CBookMarkView::CBookMarkView()
-{
- m_pFram = NULL;
- m_pDoc = NULL;
-}
-
-CBookMarkView::~CBookMarkView()
-{
-}
-
-
-BEGIN_MESSAGE_MAP(CBookMarkView, CTreeView)
- //{{AFX_MSG_MAP(CBookMarkView)
- ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
- //}}AFX_MSG_MAP
-END_MESSAGE_MAP()
-
-/////////////////////////////////////////////////////////////////////////////
-// CBookMarkView drawing
-
-void CBookMarkView::OnDraw(CDC* pDC)
-{
- CReaderVCDoc* pDoc = GetDocument();
- // TODO: add draw code here
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// CBookMarkView diagnostics
-
-#ifdef _DEBUG
-void CBookMarkView::AssertValid() const
-{
- CTreeView::AssertValid();
-}
-
-void CBookMarkView::Dump(CDumpContext& dc) const
-{
- CTreeView::Dump(dc);
-}
-
-CReaderVCDoc* CBookMarkView::GetDocument() // non-debug version is inline
-{
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CReaderVCDoc)));
- return (CReaderVCDoc*)m_pDocument;
-}
-#endif //_DEBUG
-
-/////////////////////////////////////////////////////////////////////////////
-// CBookMarkView message handlers
-
-void CBookMarkView::OnInitialUpdate()
-{
- CTreeView::OnInitialUpdate();
- CReaderVCDoc* pDoc = GetDocument();
- if (! m_pFram || !m_pFram->m_pView)
- return;
- m_pDoc = m_pFram->m_pView->GetPDFDoc();
- if(m_pDoc == NULL) return;
- int num = m_pFram->m_pView->GetTotalPages();
- CString strName = pDoc->GetTitle();
- FPDF_BOOKMARK bookmark1 = NULL;
-
- //////////////////////////////////////////////////////////////////////////
- //insert items
-
-// CTreeCtrl &treeCtrl = this->GetTreeCtrl();
-// m_hItemRoot = treeCtrl.InsertItem(strName,0,0,TVI_ROOT,TVI_FIRST);
-// treeCtrl.SetItemData(m_hItemRoot,0);
-// bookmark1 = FPDFBookmark_GetFirstChild(m_pDoc, NULL);
-// if (bookmark1 == NULL)//insert the page index to tree
-// {
-// for (int i=0; i<num; i++)
-// {
-// CString str;
-// str.Format(_T("Page%d"), i+1);
-// HTREEITEM hItem = treeCtrl.InsertItem(str);
-// treeCtrl.SetItemData(hItem, i);
-// }
-// }else{
-// while(bookmark1 != NULL) {
-// this->InsertChildItem(bookmark1, m_hItemRoot, treeCtrl);
-// bookmark1 = FPDFBookmark_GetNextSibling(m_pDoc,bookmark1);
-// }
-// }
-// treeCtrl.Expand(m_hItemRoot,TVE_EXPAND);
-//
-// LONG nStyle = ::GetWindowLong(this->m_hWnd, GWL_STYLE);
-// nStyle |= TVS_LINESATROOT;
-// nStyle |= TVS_HASLINES;
-// nStyle |= TVS_HASBUTTONS;
-// ::SetWindowLong(this->m_hWnd, GWL_STYLE, nStyle);
-
-}
-
-void CBookMarkView::InsertChildItem(FPDF_BOOKMARK bookmark, HTREEITEM hItem, CTreeCtrl &treectrl)
-{
-
-// CString strTitle;
-// DWORD dwItemData = 0;
-// WCHAR buffer[1024];
-// CString str;
-// int strlenth = 0;
-// unsigned long pdf_actType = 0;
-// //FPDF_BOOKMARK
-// FPDF_DEST dest = NULL;
-// FPDF_ACTION action = NULL;
-//
-// memset(buffer,0,1024*sizeof(WCHAR));
-// strlenth = FPDFBookmark_GetTitle(bookmark, buffer, 0);
-// int nlen = WideCharToMultiByte(CP_ACP,0,buffer,-1,NULL,NULL,NULL,NULL);
-// char *buffer1 = new char[nlen];
-// memset(buffer1,0,nlen);
-// WideCharToMultiByte(CP_ACP,0,buffer,strlenth,buffer1,nlen,NULL,NULL);
-// buffer1[nlen -1] = '\0';
-// /* int strl = strlen(buffer1);
-// strTitle = buffer;//
-// strTitle = strTitle.Left(strl-1);*/
-// hItem = treectrl.InsertItem(buffer1, 0, 0, hItem, TVI_LAST);
-// action = FPDFBookmark_GetAction(bookmark);
-// if (action != NULL)
-// {
-// pdf_actType = FPDFAction_GetType(action);
-// if (pdf_actType == 1)
-// {
-// dest = FPDFAction_GetDest(m_pDoc, action);
-// dwItemData = FPDFDest_GetPageIndex(m_pDoc, dest);
-// int nZoomMode = FPDFDest_GetZoomMode(dest);
-// if(nZoomMode == 1)
-// {
-// double nStartX = FPDFDest_GetZoomParam(dest, 0);
-// double nStartY = FPDFDest_GetZoomParam(dest, 1);
-// CPoint pos((int)nStartX, (int)nStartY);
-// m_PosMap.SetAt(hItem, pos);
-// }
-// treectrl.SetItemData(hItem, dwItemData);
-//
-// }else{
-// dwItemData = 0;
-// treectrl.SetItemData(hItem, dwItemData);
-// }
-//
-// }else{
-// dest = FPDFBookmark_GetDest(m_pDoc, bookmark);
-// dwItemData = FPDFDest_GetPageIndex(m_pDoc, dest);
-// treectrl.SetItemData(hItem, dwItemData);
-// }
-//
-// bookmark = FPDFBookmark_GetFirstChild(m_pDoc, bookmark);
-// while(bookmark != NULL)
-// {
-// this->InsertChildItem(bookmark, hItem, treectrl);
-// bookmark = FPDFBookmark_GetNextSibling(m_pDoc, bookmark);
-// }
-// delete buffer1;
-}
-
-void CBookMarkView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
-{
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- // TODO: Add your control notification handler code here
- HTREEITEM hItem;
- DWORD dwPageIdex= 0;
- if(m_pDoc == NULL) return;
- hItem = GetTreeCtrl().GetSelectedItem();
- dwPageIdex = GetTreeCtrl().GetItemData(hItem);
- CPoint p;
- if(0 == m_PosMap.Lookup(hItem, p))
- {
- p.x = 0;
- p.y = 0;
- }
- m_pFram->m_pView->LoadPDFPage(m_pDoc, dwPageIdex, p);
- m_pFram->m_pView->Invalidate();
- *pResult = 0;
-}
-
diff --git a/xfa_test/FormFiller_Test/BookMarkView.h b/xfa_test/FormFiller_Test/BookMarkView.h
deleted file mode 100644
index d10964c0ec..0000000000
--- a/xfa_test/FormFiller_Test/BookMarkView.h
+++ /dev/null
@@ -1,67 +0,0 @@
-#if !defined(AFX_BOOKMARKVIEW_H__B1EB2803_BE21_4768_A54B_2DE1E0FC968A__INCLUDED_)
-#define AFX_BOOKMARKVIEW_H__B1EB2803_BE21_4768_A54B_2DE1E0FC968A__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-// BookMarkView.h : header file
-//
-
-class CChildFrame;
-class CReaderVCDoc;
-/////////////////////////////////////////////////////////////////////////////
-// CBookMarkView view
-
-class CBookMarkView : public CTreeView
-{
-protected:
- CBookMarkView(); // protected constructor used by dynamic creation
- DECLARE_DYNCREATE(CBookMarkView)
-
-// Attributes
-public:
- CChildFrame *m_pFram;
- FPDF_DOCUMENT m_pDoc;
- HTREEITEM m_hItemRoot;
- CReaderVCDoc* GetDocument();
-// Operations
-public:
- void InsertChildItem(FPDF_BOOKMARK bookmark, HTREEITEM hItem, CTreeCtrl &treectrl);
-
-// Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CBookMarkView)
- public:
- virtual void OnInitialUpdate();
- protected:
- virtual void OnDraw(CDC* pDC); // overridden to draw this view
- //}}AFX_VIRTUAL
-
-// Implementation
-protected:
- virtual ~CBookMarkView();
-#ifdef _DEBUG
- virtual void AssertValid() const;
- virtual void Dump(CDumpContext& dc) const;
-#endif
-
- // Generated message map functions
-protected:
- //{{AFX_MSG(CBookMarkView)
- afx_msg void OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult);
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
-private:
- CMap<HTREEITEM, HTREEITEM&, CPoint, CPoint&> m_PosMap;
-};
-
-#ifndef _DEBUG // debug version in PDFReaderVCView.cpp
-inline CReaderVCDoc* CBookMarkView::GetDocument()
-{ return (CReaderVCDoc*)m_pDocument; }
-#endif
-/////////////////////////////////////////////////////////////////////////////
-
-//{{AFX_INSERT_LOCATION}}
-// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
-
-#endif // !defined(AFX_BOOKMARKVIEW_H__B1EB2803_BE21_4768_A54B_2DE1E0FC968A__INCLUDED_)
diff --git a/xfa_test/FormFiller_Test/ChildFrm.cpp b/xfa_test/FormFiller_Test/ChildFrm.cpp
deleted file mode 100644
index 8d32a72ac7..0000000000
--- a/xfa_test/FormFiller_Test/ChildFrm.cpp
+++ /dev/null
@@ -1,112 +0,0 @@
-// ChildFrm.cpp : implementation of the CChildFrame class
-//
-
-#include "stdafx.h"
-#include "ReaderVC.h"
-
-#include "ChildFrm.h"
-#include "FX_SplitterWnd.h"
-#include "BookmarkView.h"
-#include "ReaderVCView.h"
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-// CChildFrame
-
-IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)
-
-BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
- //{{AFX_MSG_MAP(CChildFrame)
- ON_WM_SIZE()
- //}}AFX_MSG_MAP
-END_MESSAGE_MAP()
-
-/////////////////////////////////////////////////////////////////////////////
-// CChildFrame construction/destruction
-
-CChildFrame::CChildFrame()
-{
- // TODO: add member initialization code here
- //m_nPosH = m_nPosV = 0;
-// m_pBkView = NULL;
- m_pView = NULL;
-// m_bBookmark = FALSE;
-}
-
-CChildFrame::~CChildFrame()
-{
-/* if (m_pBkView != NULL)
- {
- delete m_pBkView;
- m_pBkView = NULL;
- }
- if (m_pView != NULL)
- {
- delete m_pView;
- m_pView = NULL;
- }*/
-}
-
-BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
-{
-
- if( !CMDIChildWnd::PreCreateWindow(cs) )
- return FALSE;
- cs.style |= WS_MAXIMIZE | WS_VISIBLE;
- return TRUE;
-}
-
-
-
-/////////////////////////////////////////////////////////////////////////////
-// CChildFrame diagnostics
-
-#ifdef _DEBUG
-void CChildFrame::AssertValid() const
-{
- CMDIChildWnd::AssertValid();
-}
-
-void CChildFrame::Dump(CDumpContext& dc) const
-{
- CMDIChildWnd::Dump(dc);
-}
-
-#endif //_DEBUG
-
-/////////////////////////////////////////////////////////////////////////////
-// CChildFrame message handlers
-
-
-
-
-
-void CChildFrame::OnSize(UINT nType, int cx, int cy)
-{
- CMDIChildWnd::OnSize(nType, cx, cy);
-
-
-}
-
-BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
-{
- if ( !m_wndSplitter.CreateStatic( this, 1, 2 ) ||
- !m_wndSplitter.CreateView( 0,0,RUNTIME_CLASS(CBookMarkView),CSize(180,0),pContext )||
- !m_wndSplitter.CreateView( 0,1,pContext->m_pNewViewClass,CSize(0,0),pContext ))
- {
- return FALSE;
- }
- m_pBkView = (CBookMarkView *)(m_wndSplitter.GetPane(0,0));
- m_pBkView->m_pFram = this;
- m_pView = (CReaderVCView*)(m_wndSplitter.GetPane(0,1));
- m_pView->m_pFram = this;
- this->SetActiveView( (CView*)m_wndSplitter.GetPane(0,1) );
-
- return TRUE;
-
- //return CMDIChildWnd::OnCreateClient(lpcs, pContext);
-}
diff --git a/xfa_test/FormFiller_Test/ChildFrm.h b/xfa_test/FormFiller_Test/ChildFrm.h
deleted file mode 100644
index dcfc7bd8bc..0000000000
--- a/xfa_test/FormFiller_Test/ChildFrm.h
+++ /dev/null
@@ -1,64 +0,0 @@
-// ChildFrm.h : interface of the CChildFrame class
-//
-/////////////////////////////////////////////////////////////////////////////
-
-#if !defined(AFX_CHILDFRM_H__452F838E_A3F7_4BBF_B4BB_4765F4D394E7__INCLUDED_)
-#define AFX_CHILDFRM_H__452F838E_A3F7_4BBF_B4BB_4765F4D394E7__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-
-//class CFX_SplitterWnd;
-#include "FX_SplitterWnd.h"
-class CReaderVCView;
-class CBookMarkView;
-//class CFX_SplitterWnd;
-class CChildFrame : public CMDIChildWnd
-{
- DECLARE_DYNCREATE(CChildFrame)
-public:
- CChildFrame();
-
-// Attributes
-public:
- CFX_SplitterWnd m_wndSplitter;
- CReaderVCView* m_pView;
- CBookMarkView* m_pBkView;
-// BOOL m_bBookmark;
-// Operations
-public:
-
-// Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CChildFrame)
- public:
- virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
- protected:
- virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
- //}}AFX_VIRTUAL
-
-// Implementation
-public:
- virtual ~CChildFrame();
-#ifdef _DEBUG
- virtual void AssertValid() const;
- virtual void Dump(CDumpContext& dc) const;
-#endif
-
-// Generated message map functions
-protected:
- //{{AFX_MSG(CChildFrame)
- afx_msg void OnSize(UINT nType, int cx, int cy);
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
-private:
- //int m_nPosH, m_nPosV;
-};
-
-/////////////////////////////////////////////////////////////////////////////
-
-//{{AFX_INSERT_LOCATION}}
-// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
-
-#endif // !defined(AFX_CHILDFRM_H__452F838E_A3F7_4BBF_B4BB_4765F4D394E7__INCLUDED_)
diff --git a/xfa_test/FormFiller_Test/ConvertDlg.cpp b/xfa_test/FormFiller_Test/ConvertDlg.cpp
deleted file mode 100644
index ec31948144..0000000000
--- a/xfa_test/FormFiller_Test/ConvertDlg.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-// ConvertDlg.cpp : implementation file
-//
-
-#include "stdafx.h"
-#include "ReaderVC.h"
-#include "ConvertDlg.h"
-
-#include "MainFrm.h"
-#include "ChildFrm.h"
-#include "ReaderVCView.h"
-
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-// CConvertDlg dialog
-
-
-CConvertDlg::CConvertDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CConvertDlg::IDD, pParent)
-{
- //{{AFX_DATA_INIT(CConvertDlg)
- m_nFlag = -1;
- //}}AFX_DATA_INIT
-}
-
-
-void CConvertDlg::DoDataExchange(CDataExchange* pDX)
-{
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CConvertDlg)
- DDX_Radio(pDX, IDC_RADIO_Stream, m_nFlag);
- //}}AFX_DATA_MAP
-}
-
-
-BEGIN_MESSAGE_MAP(CConvertDlg, CDialog)
- //{{AFX_MSG_MAP(CConvertDlg)
- //}}AFX_MSG_MAP
-END_MESSAGE_MAP()
-
-/////////////////////////////////////////////////////////////////////////////
-// CConvertDlg message handlers
-
-BOOL CConvertDlg::OnInitDialog()
-{
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- m_pView = (CReaderVCView *)(((CChildFrame *)((CMainFrame *)AfxGetMainWnd())->GetActiveFrame())->GetActiveView());
- ASSERT(m_pView);
- ((CButton *)GetDlgItem(IDC_RADIO_Appearance))->SetCheck(1);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
-}
-
-void CConvertDlg::OnOK()
-{
- // TODO: Add extra validation here
- UpdateData(TRUE);
- CDialog::OnOK();
-}
diff --git a/xfa_test/FormFiller_Test/ConvertDlg.h b/xfa_test/FormFiller_Test/ConvertDlg.h
deleted file mode 100644
index 8ef993208a..0000000000
--- a/xfa_test/FormFiller_Test/ConvertDlg.h
+++ /dev/null
@@ -1,47 +0,0 @@
-#if !defined(AFX_CONVERTDLG_H__9BB8EADD_CCDD_4C68_A8A0_C1656653A947__INCLUDED_)
-#define AFX_CONVERTDLG_H__9BB8EADD_CCDD_4C68_A8A0_C1656653A947__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-// ConvertDlg.h : header file
-//
-
-/////////////////////////////////////////////////////////////////////////////
-// CConvertDlg dialog
-class CReaderVCView;
-class CConvertDlg : public CDialog
-{
-// Construction
-public:
- CConvertDlg(CWnd* pParent = NULL); // standard constructor
-
-// Dialog Data
- //{{AFX_DATA(CConvertDlg)
- enum { IDD = IDD_DLG_CONVERT };
- int m_nFlag;
- //}}AFX_DATA
-
-
-// Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CConvertDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
-
-// Implementation
-protected:
- CReaderVCView *m_pView;
- // Generated message map functions
- //{{AFX_MSG(CConvertDlg)
- virtual BOOL OnInitDialog();
- virtual void OnOK();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
-};
-
-//{{AFX_INSERT_LOCATION}}
-// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
-
-#endif // !defined(AFX_CONVERTDLG_H__9BB8EADD_CCDD_4C68_A8A0_C1656653A947__INCLUDED_)
diff --git a/xfa_test/FormFiller_Test/ExportPage.cpp b/xfa_test/FormFiller_Test/ExportPage.cpp
deleted file mode 100644
index 76287a7d0b..0000000000
--- a/xfa_test/FormFiller_Test/ExportPage.cpp
+++ /dev/null
@@ -1,189 +0,0 @@
-// ExportPage.cpp : implementation file
-//
-
-#include "stdafx.h"
-#include "ReaderVC.h"
-#include "ExportPage.h"
-
-#include "MainFrm.h"
-#include "ChildFrm.h"
-#include "ReaderVCView.h"
-
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-// CExportPage dialog
-
-
-CExportPage::CExportPage(CWnd* pParent /*=NULL*/)
- : CDialog(CExportPage::IDD, pParent)
-{
- //{{AFX_DATA_INIT(CExportPage)
- m_nHeight = 0;
- m_nPageHeight = 0;
- m_nRotate = 0;
- m_nWidth = 0;
- m_nPageWidth = 0;
- //}}AFX_DATA_INIT
- m_bitmap = NULL;
-}
-
-
-void CExportPage::DoDataExchange(CDataExchange* pDX)
-{
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CExportPage)
- DDX_Text(pDX, IDC_EDIT_HEIGHT, m_nHeight);
- DDX_Text(pDX, IDC_EDIT_PAGE_HEIGHT, m_nPageHeight);
- DDX_Text(pDX, IDC_EDIT_ROTATE, m_nRotate);
- DDX_Text(pDX, IDC_EDIT_WIDTH, m_nWidth);
- DDX_Text(pDX, IDC_EDIT_PAGE_WIDTH, m_nPageWidth);
- //}}AFX_DATA_MAP
-}
-
-
-BEGIN_MESSAGE_MAP(CExportPage, CDialog)
- //{{AFX_MSG_MAP(CExportPage)
- ON_BN_CLICKED(IDC_Rander_Page, OnRanderPage)
- ON_BN_CLICKED(IDC_Save, OnSave)
- ON_WM_PAINT()
- //}}AFX_MSG_MAP
-END_MESSAGE_MAP()
-
-/////////////////////////////////////////////////////////////////////////////
-// CExportPage message handlers
-
-void CExportPage::OnRanderPage()
-{
- if (m_pView)
- {
- UpdateData(TRUE);
- m_page=m_pView->GetPage();
- if (!m_page) return;
- if (m_nRotate==1 || m_nRotate==3)
- {
- int temp;
- temp=m_nHeight;
- m_nHeight=m_nWidth;
- m_nWidth=temp;
- }
- m_bitmap=FPDFBitmap_Create(m_nWidth,m_nHeight,FPDFBitmap_BGRx);
- FPDFBitmap_FillRect(m_bitmap,0,0,m_nWidth,m_nHeight,0xff,0xff,0xff,0xff);
- FPDF_RenderPageBitmap(m_bitmap,m_page,0,0,200,200,m_nRotate,FPDF_ANNOT);
- Invalidate();
- if (m_nRotate==1 || m_nRotate==3)
- {
- int temp;
- temp=m_nHeight;
- m_nHeight=m_nWidth;
- m_nWidth=temp;
- }
- //FPDFBitmap_Destroy(bitmap);
- UpdateData(FALSE);
- }
-
-}
-
-void CExportPage::InitDialogInfo(CReaderVCView *pView)
-{
- m_pView=pView;
- if (pView) m_page=pView->GetPage();
- SetDlgInfo();
-}
-
-void CExportPage::SetDlgInfo()
-{
- if (!m_page) return;
- double height,width;
- width=FPDF_GetPageWidth(m_page);
- height=FPDF_GetPageHeight(m_page);
-
- UpdateData(TRUE);
- m_nPageHeight = (int)height;
- m_nPageWidth = (int)width;
- m_nWidth=(int)width/3;
- m_nHeight=(int)height/3;
- UpdateData(FALSE);
-}
-
-void CExportPage::OnSave()
-{
- CFileDialog SavDlg(FALSE,"","",OFN_FILEMUSTEXIST |OFN_HIDEREADONLY,"bmp(*.bmp)|*.bmp||All Files(*.*)|*.*");
- if (SavDlg.DoModal()==IDOK)
- {
- CString strFileName = SavDlg.GetPathName();
- BITMAPFILEHEADER bitmapFileHeader;
- BITMAPINFOHEADER bitmapInfoHeader;
- BITMAP strBitmap;
- int wBitCount = 32;
- winbmp.GetBitmap(&strBitmap);
- DWORD dwBmBitsSize = ((strBitmap.bmWidth * wBitCount+31)/32) * 4 * strBitmap.bmHeight;
-
- bitmapFileHeader.bfType = 0x4D42;
- bitmapFileHeader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + dwBmBitsSize;
- bitmapFileHeader.bfReserved1 = bitmapFileHeader.bfReserved2 = 0;
- bitmapFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
-
- bitmapInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
- bitmapInfoHeader.biWidth = strBitmap.bmWidth;
- bitmapInfoHeader.biHeight = strBitmap.bmHeight;
- bitmapInfoHeader.biPlanes = 1;
- bitmapInfoHeader.biBitCount = wBitCount;
- bitmapInfoHeader.biClrImportant = BI_RGB;
- bitmapInfoHeader.biSizeImage = 0; //strBitmap.bmWidth * strBitmap.bmHeight;
- bitmapInfoHeader.biXPelsPerMeter = 0;
- bitmapInfoHeader.biYPelsPerMeter = 0;
- bitmapInfoHeader.biClrUsed = 0;
- bitmapInfoHeader.biCompression = 0;
-
- char* context = new char[dwBmBitsSize];
- CWindowDC dc(NULL);
- GetDIBits(dc.GetSafeHdc(), (HBITMAP)winbmp.m_hObject, 0, bitmapInfoHeader.biHeight, (LPVOID)context,(BITMAPINFO*)&bitmapInfoHeader, DIB_RGB_COLORS);
-
- CFile file;
- file.Open(strFileName, CFile::modeCreate|CFile::modeWrite);
- file.Write(&bitmapFileHeader, sizeof(BITMAPFILEHEADER));
- file.Write(&bitmapInfoHeader, sizeof(BITMAPINFOHEADER));
- file.Write(context, dwBmBitsSize);
-
- file.Close();
- delete context;
- }
-}
-
-void CExportPage::OnPaint()
-{
- CPaintDC dc(this); // device context for painting
-
- // TODO: Add your message handler code here
- if(m_bitmap)
- {
- // CDC* pDc=GetDC();
- int bufsize=FPDFBitmap_GetStride(m_bitmap)*m_nHeight;
- void* bmpbuf=FPDFBitmap_GetBuffer(m_bitmap);
- CDC MemDC;
- CDC *pDc = GetDlgItem(IDC_STATIC_BITMAP)->GetDC(); //ID: picture
- CRect rect;
- ((CWnd *)GetDlgItem(IDC_STATIC_BITMAP))->GetWindowRect(rect);
-
- MemDC.CreateCompatibleDC(pDc);
- if((HBITMAP)winbmp != NULL)
- winbmp.DeleteObject();
- if(HBITMAP(winbmp) == NULL)
- {
- winbmp.CreateCompatibleBitmap(pDc,m_nWidth,m_nHeight);
- winbmp.SetBitmapBits(bufsize,bmpbuf);
- }
-
- MemDC.SelectObject(&winbmp);
-
- pDc->BitBlt(0 , 0 , rect.Width(), rect.Height(), &MemDC,0,0,SRCCOPY);
- //pDc->StretchBlt(0,0,rect.right-rect.left,rect.bottom-rect.top,&MemDC,0,0,m_nWidth,m_nHeight,SRCCOPY);
- MemDC.DeleteDC();
- }
- // Do not call CDialog::OnPaint() for painting messages
-}
diff --git a/xfa_test/FormFiller_Test/ExportPage.h b/xfa_test/FormFiller_Test/ExportPage.h
deleted file mode 100644
index 1742991c76..0000000000
--- a/xfa_test/FormFiller_Test/ExportPage.h
+++ /dev/null
@@ -1,59 +0,0 @@
-#if !defined(AFX_EXPORTPAGE_H__D9B06547_96CA_4749_88CB_2506D8AF61D6__INCLUDED_)
-#define AFX_EXPORTPAGE_H__D9B06547_96CA_4749_88CB_2506D8AF61D6__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-// ExportPage.h : header file
-//
-
-/////////////////////////////////////////////////////////////////////////////
-// CExportPage dialog
-class CReaderVCView;
-
-class CExportPage : public CDialog
-{
-// Construction
-public:
- CBitmap winbmp;
- FPDF_BITMAP m_bitmap;
- FPDF_PAGE m_page;
- CReaderVCView *m_pView;
- void SetDlgInfo();
- void InitDialogInfo(CReaderVCView *pView);
- CExportPage(CWnd* pParent = NULL); // standard constructor
-
-// Dialog Data
- //{{AFX_DATA(CExportPage)
- enum { IDD = IDD_EXPORT_PAGE };
- int m_nHeight;
- int m_nPageHeight;
- int m_nRotate;
- int m_nWidth;
- int m_nPageWidth;
- //}}AFX_DATA
-
-
-// Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CExportPage)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
-
-// Implementation
-protected:
-
- // Generated message map functions
- //{{AFX_MSG(CExportPage)
- afx_msg void OnRanderPage();
- afx_msg void OnSave();
- afx_msg void OnPaint();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
-};
-
-//{{AFX_INSERT_LOCATION}}
-// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
-
-#endif // !defined(AFX_EXPORTPAGE_H__D9B06547_96CA_4749_88CB_2506D8AF61D6__INCLUDED_)
diff --git a/xfa_test/FormFiller_Test/FX_SplitterWnd.cpp b/xfa_test/FormFiller_Test/FX_SplitterWnd.cpp
deleted file mode 100644
index 4024bb5c91..0000000000
--- a/xfa_test/FormFiller_Test/FX_SplitterWnd.cpp
+++ /dev/null
@@ -1,373 +0,0 @@
-// FX_SplitterWnd.cpp: implementation of the CFX_SplitterWnd class.
-//
-//////////////////////////////////////////////////////////////////////
-
-#include "stdafx.h"
-//#include "teststatusbar.h"
-#include "FX_SplitterWnd.h"
-
-#include <afxpriv.h>
-
-#ifdef _DEBUG
-#undef THIS_FILE
-static char THIS_FILE[]=__FILE__;
-#define new DEBUG_NEW
-#endif
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-CFX_SplitterWnd::CFX_SplitterWnd()
-{
- m_cxSplitter = m_cySplitter = 4 + 1 + 1;
- m_cxBorderShare = m_cyBorderShare = 0;
- m_cxSplitterGap = m_cySplitterGap = 4 + 1 + 1;
- m_cxBorder = m_cyBorder = 1;
- m_nHidedCol = -1;
- m_bBarLocked = FALSE;
-}
-
-CFX_SplitterWnd::~CFX_SplitterWnd()
-{
-
-}
-
-BEGIN_MESSAGE_MAP(CFX_SplitterWnd, CSplitterWnd)
- //{{AFX_MSG_MAP(CFX_SplitterWnd)
- ON_WM_LBUTTONDOWN()
- ON_WM_MOUSEMOVE()
- //}}AFX_MSG_MAP
-END_MESSAGE_MAP()
-
-void CFX_SplitterWnd::OnDrawSplitter(CDC *pDC,ESplitType nType,const CRect &rectArg)
-{
- if((nType != splitBorder) || (pDC == NULL))
- {
- CSplitterWnd::OnDrawSplitter(pDC, nType, rectArg);
- return;
- }
-
- pDC->Draw3dRect(rectArg, GetSysColor(COLOR_BTNSHADOW), GetSysColor(COLOR_BTNHIGHLIGHT));
-}
-void CFX_SplitterWnd::RecalcLayout()
-{
- ASSERT_VALID(this);
- ASSERT(m_nRows > 0 && m_nCols > 0); // must have at least one pane
-
- CRect rectClient;
- GetClientRect(rectClient);
- rectClient.InflateRect(-m_cxBorder, -m_cyBorder);
-
- CRect rectInside;
- GetInsideRect(rectInside);
-
- // layout columns (restrict to possible sizes)
- LayoutRowCol(m_pColInfo, m_nCols, rectInside.Width(), m_cxSplitterGap);
- LayoutRowCol(m_pRowInfo, m_nRows, rectInside.Height(), m_cySplitterGap);
-
- // adjust the panes (and optionally scroll bars)
-
- // give the hint for the maximum number of HWNDs
- AFX_SIZEPARENTPARAMS layout;
- layout.hDWP = ::BeginDeferWindowPos((m_nCols + 1) * (m_nRows + 1) + 1);
-
- // size of scrollbars
- int cx = rectClient.right - rectInside.right;
- int cy = rectClient.bottom - rectInside.bottom;
-
- // reposition size box
- if (m_bHasHScroll && m_bHasVScroll)
- {
- CWnd* pScrollBar = GetDlgItem(AFX_IDW_SIZE_BOX);
- ASSERT(pScrollBar != NULL);
-
- // fix style if necessary
- BOOL bSizingParent = (GetSizingParent() != NULL);
- // modifyStyle returns TRUE if style changes
- if (pScrollBar->ModifyStyle(SBS_SIZEGRIP|SBS_SIZEBOX,
- bSizingParent ? SBS_SIZEGRIP : SBS_SIZEBOX))
- pScrollBar->Invalidate();
- pScrollBar->EnableWindow(bSizingParent);
-
- // reposition the size box
- DeferClientPos(&layout, pScrollBar,
- rectInside.right,
- rectInside.bottom, cx, cy, TRUE);
- }
-
- // reposition scroll bars
- if (m_bHasHScroll)
- {
- int cxSplitterBox = m_cxSplitter;// split box bigger
- int x = rectClient.left;
- int y = rectInside.bottom;
- for (int col = 0; col < m_nCols; col++)
- {
- CWnd* pScrollBar = GetDlgItem(AFX_IDW_HSCROLL_FIRST + col);
- ASSERT(pScrollBar != NULL);
- int cx = m_pColInfo[col].nCurSize;
- if (col == 0 && m_nCols < m_nMaxCols)
- x += cxSplitterBox, cx -= cxSplitterBox;
- DeferClientPos(&layout, pScrollBar, x, y, cx, cy, TRUE);
- x += cx + m_cxSplitterGap;
- }
- }
-
- if (m_bHasVScroll)
- {
- int cySplitterBox = m_cySplitter;// split box bigger
- int x = rectInside.right;
- int y = rectClient.top;
- for (int row = 0; row < m_nRows; row++)
- {
- CWnd* pScrollBar = GetDlgItem(AFX_IDW_VSCROLL_FIRST + row);
- ASSERT(pScrollBar != NULL);
- int cy = m_pRowInfo[row].nCurSize;
- if (row == 0 && m_nRows < m_nMaxRows)
- y += cySplitterBox, cy -= cySplitterBox;
- DeferClientPos(&layout, pScrollBar, x, y, cx, cy, TRUE);
- y += cy + m_cySplitterGap;
- }
- }
-
- //BLOCK: Reposition all the panes
- {
- int x = rectClient.left;
- for (int col = 0; col < m_nCols; col++)
- {
- int cx = m_pColInfo[col].nCurSize;
- int y = rectClient.top;
- for (int row = 0; row < m_nRows; row++)
- {
- int cy = m_pRowInfo[row].nCurSize;
- CWnd* pWnd = GetPane(row, col);
- DeferClientPos(&layout, pWnd, x, y, cx, cy, FALSE);
- y += cy + m_cySplitterGap;
- }
- x += cx + m_cxSplitterGap;
- }
- }
-
- // move and resize all the windows at once!
- if (layout.hDWP == NULL || !::EndDeferWindowPos(layout.hDWP))
- TRACE0("Warning: DeferWindowPos failed - low system resources.\n");
-
- // invalidate all the splitter bars (with NULL pDC)
- DrawAllSplitBars(NULL, rectInside.right, rectInside.bottom);
-}
-
-void CFX_SplitterWnd::DeferClientPos(AFX_SIZEPARENTPARAMS *lpLayout,CWnd *pWnd,int x,int y,int cx,int cy,BOOL bScrollBar)
-{
- ASSERT(pWnd != NULL);
- ASSERT(pWnd->m_hWnd != NULL);
-
- if (bScrollBar)
- {
- // if there is enough room, draw scroll bar without border
- // if there is not enough room, set the WS_BORDER bit so that
- // we will at least get a proper border drawn
- BOOL bNeedBorder = (cx <= 1 || cy <= 1);
- pWnd->ModifyStyle(bNeedBorder ? 0 : 1, bNeedBorder ? 1 : 0);
- }
- CRect rect(x, y, x+cx, y+cy);
-
- // adjust for 3d border (splitter windows have implied border)
- if ((pWnd->GetExStyle() & WS_EX_CLIENTEDGE) || pWnd->IsKindOf(RUNTIME_CLASS(CSplitterWnd)))
- {
- rect.InflateRect(1, 1); // for proper draw CFlatSplitterWnd in view
-// rect.InflateRect(afxData.cxBorder2, afxData.cyBorder2);
- }
-
- // first check if the new rectangle is the same as the current
- CRect rectOld;
- pWnd->GetWindowRect(rectOld);
- pWnd->GetParent()->ScreenToClient(&rectOld);
- if (rect != rectOld)
- AfxRepositionWindow(lpLayout, pWnd->m_hWnd, rect);
-}
-
-void CFX_SplitterWnd::LayoutRowCol(CSplitterWnd::CRowColInfo *pInfoArray,int nMax,int nSize,int nSizeSplitter)
-{
- ASSERT(pInfoArray != NULL);
- ASSERT(nMax > 0);
- ASSERT(nSizeSplitter > 0);
-
- CSplitterWnd::CRowColInfo* pInfo;
- int i;
-
- if (nSize < 0)
- nSize = 0; // if really too small, layout as zero size
-
- // start with ideal sizes
- for (i = 0, pInfo = pInfoArray; i < nMax-1; i++, pInfo++)
- {
- if (pInfo->nIdealSize < pInfo->nMinSize)
- pInfo->nIdealSize = 0; // too small to see
- pInfo->nCurSize = pInfo->nIdealSize;
- }
- pInfo->nCurSize = INT_MAX; // last row/column takes the rest
-
- for (i = 0, pInfo = pInfoArray; i < nMax; i++, pInfo++)
- {
- ASSERT(nSize >= 0);
- if (nSize == 0)
- {
- // no more room (set pane to be invisible)
- pInfo->nCurSize = 0;
- continue; // don't worry about splitters
- }
- else if (nSize < pInfo->nMinSize && i != 0)
- {
- // additional panes below the recommended minimum size
- // aren't shown and the size goes to the previous pane
- pInfo->nCurSize = 0;
-
- // previous pane already has room for splitter + border
- // add remaining size and remove the extra border
- (pInfo-1)->nCurSize += nSize + 2;
- nSize = 0;
- }
- else
- {
- // otherwise we can add the second pane
- ASSERT(nSize > 0);
- if (pInfo->nCurSize == 0)
- {
- // too small to see
- if (i != 0)
- pInfo->nCurSize = 0;
- }
- else if (nSize < pInfo->nCurSize)
- {
- // this row/col won't fit completely - make as small as possible
- pInfo->nCurSize = nSize;
- nSize = 0;
- }
- else
- {
- // can fit everything
- nSize -= pInfo->nCurSize;
- }
- }
-
- // see if we should add a splitter
- ASSERT(nSize >= 0);
- if (i != nMax - 1)
- {
- // should have a splitter
- if (nSize > nSizeSplitter)
- {
- nSize -= nSizeSplitter; // leave room for splitter + border
- ASSERT(nSize > 0);
- }
- else
- {
- // not enough room - add left over less splitter size
- pInfo->nCurSize += nSize;
- if (pInfo->nCurSize > (nSizeSplitter - 2))
- pInfo->nCurSize -= (nSizeSplitter - 2);
- nSize = 0;
- }
- }
- }
- ASSERT(nSize == 0); // all space should be allocated
-}
-
-void CFX_SplitterWnd::HideColumn(int nCol)
-{
- if ( m_nHidedCol != -1 )
- return;
-
- ASSERT_VALID(this);
- ASSERT(m_nCols > 1);
- ASSERT(nCol < m_nCols);
- ASSERT(m_nHidedCol == -1);
- m_nHidedCol = nCol;
-
- // if the column has an active window -- change it
- int rowActive, colActive;
- if (GetActivePane(&rowActive, &colActive) != NULL &&
- colActive == nCol)
- {
- if (++colActive >= m_nCols)
- colActive = 0;
- SetActivePane(rowActive, colActive);
- }
-
- // hide all column panes
- for (int row = 0; row < m_nRows; row++)
- {
- CWnd* pPaneHide = GetPane(row, nCol);
- ASSERT(pPaneHide != NULL);
- pPaneHide->ShowWindow(SW_HIDE);
- pPaneHide->SetDlgCtrlID(
- AFX_IDW_PANE_FIRST + row * 16 + m_nCols);
-
- for (int col = nCol + 1; col < m_nCols; col++)
- {
- CWnd* pPane = GetPane(row, col);
- ASSERT(pPane != NULL);
- pPane->SetDlgCtrlID(IdFromRowCol(row, col - 1));
- }
- }
- m_nCols--;
- m_pColInfo[m_nCols].nCurSize = m_pColInfo[nCol].nCurSize;
- RecalcLayout();
-}
-
-void CFX_SplitterWnd::ShowColumn()
-{
- if ( m_nHidedCol == -1 )
- return;
-
- ASSERT_VALID(this);
- ASSERT(m_nCols < m_nMaxCols);
- ASSERT(m_nHidedCol != -1);
-
- int colNew = m_nHidedCol;
- m_nHidedCol = -1;
- int cxNew = m_pColInfo[m_nCols].nCurSize;
- m_nCols++; // add a column
- ASSERT(m_nCols == m_nMaxCols);
-
- // fill the hided column
- int col;
- for (int row = 0; row < m_nRows; row++)
- {
- CWnd* pPaneShow = GetDlgItem(
- AFX_IDW_PANE_FIRST + row * 16 + m_nCols);
- ASSERT(pPaneShow != NULL);
- pPaneShow->ShowWindow(SW_SHOWNA);
-
- for (col = m_nCols - 2; col >= colNew; col--)
- {
- CWnd* pPane = GetPane(row, col);
- ASSERT(pPane != NULL);
- pPane->SetDlgCtrlID(IdFromRowCol(row, col + 1));
- }
-
- pPaneShow->SetDlgCtrlID(IdFromRowCol(row, colNew));
- }
-
- // new panes have been created -- recalculate layout
- for (col = colNew + 1; col < m_nCols; col++)
- m_pColInfo[col].nIdealSize = m_pColInfo[col - 1].nCurSize;
- m_pColInfo[colNew].nIdealSize = cxNew;
-
- RecalcLayout();
-}
-
-void CFX_SplitterWnd::OnLButtonDown(UINT nFlags, CPoint point)
-{
- if (!m_bBarLocked)
- CSplitterWnd::OnLButtonDown(nFlags, point);
-}
-
-void CFX_SplitterWnd::OnMouseMove(UINT nFlags, CPoint point)
-{
- if (!m_bBarLocked)
- CSplitterWnd::OnMouseMove(nFlags, point);
- else
- CWnd::OnMouseMove(nFlags, point);
-}
diff --git a/xfa_test/FormFiller_Test/FX_SplitterWnd.h b/xfa_test/FormFiller_Test/FX_SplitterWnd.h
deleted file mode 100644
index 94893c9719..0000000000
--- a/xfa_test/FormFiller_Test/FX_SplitterWnd.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// FX_SplitterWnd.h: interface for the CFX_SplitterWnd class.
-//
-//////////////////////////////////////////////////////////////////////
-
-#if !defined(AFX_FX_SPLITTERWND_H__4BF45CD9_0C9D_4223_9D0E_9ECA148F49FB__INCLUDED_)
-#define AFX_FX_SPLITTERWND_H__4BF45CD9_0C9D_4223_9D0E_9ECA148F49FB__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-
-class CFX_SplitterWnd : public CSplitterWnd
-{
-public:
- CFX_SplitterWnd();
- virtual ~CFX_SplitterWnd();
-
-public:
- virtual void OnDrawSplitter(CDC *pDC,ESplitType nType,const CRect &rectArg);
- virtual void RecalcLayout();
- static void DeferClientPos(AFX_SIZEPARENTPARAMS *lpLayout,CWnd *pWnd,int x,int y,int cx,int cy,BOOL bScrollBar);
- static void LayoutRowCol(CSplitterWnd::CRowColInfo *pInfoArray,int nMax,int nSize,int nSizeSplitter);
- void LockBar(BOOL bState=TRUE){m_bBarLocked=bState;}
- void HideColumn(int nCol);
- void ShowColumn();
-
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CFX_SplitterWnd)
- //}}AFX_VIRTUAL
-
- // Generated message map functions
-protected:
- //{{AFX_MSG(CFX_SplitterWnd)
- afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
- afx_msg void OnMouseMove(UINT nFlags, CPoint point);
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
-protected:
- BOOL m_bBarLocked;
- int m_nHidedCol;
-
-};
-
-#endif // !defined(AFX_FX_SPLITTERWND_H__4BF45CD9_0C9D_4223_9D0E_9ECA148F49FB__INCLUDED_)
diff --git a/xfa_test/FormFiller_Test/FindDlg.cpp b/xfa_test/FormFiller_Test/FindDlg.cpp
deleted file mode 100644
index 88548d991f..0000000000
--- a/xfa_test/FormFiller_Test/FindDlg.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-// FindDlg.cpp : implementation file
-//
-
-#include "stdafx.h"
-#include "ReaderVC.h"
-#include "FindDlg.h"
-
-#include "MainFrm.h"
-#include "ChildFrm.h"
-#include "ReaderVCView.h"
-
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-// CFindDlg dialog
-
-
-CFindDlg::CFindDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CFindDlg::IDD, pParent)
-{
- //{{AFX_DATA_INIT(CFindDlg)
- m_bMatchCase = FALSE;
- m_bWholeWord = FALSE;
- m_strFindWhat = _T("");
- m_nDirection = -1;
- //}}AFX_DATA_INIT
-}
-
-
-void CFindDlg::DoDataExchange(CDataExchange* pDX)
-{
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CFindDlg)
- DDX_Check(pDX, IDC_CHECK_MATCHCASE, m_bMatchCase);
- DDX_Check(pDX, IDC_CHECK_MATCHWHOLE, m_bWholeWord);
- DDX_Text(pDX, IDC_EDIT1, m_strFindWhat);
- DDX_Radio(pDX, IDC_RADIO_Down, m_nDirection);
- //}}AFX_DATA_MAP
-}
-
-
-BEGIN_MESSAGE_MAP(CFindDlg, CDialog)
- //{{AFX_MSG_MAP(CFindDlg)
- //}}AFX_MSG_MAP
-END_MESSAGE_MAP()
-
-/////////////////////////////////////////////////////////////////////////////
-// CFindDlg message handlers
-
-void CFindDlg::OnOK()
-{
- // TODO: Add extra validation here
- UpdateData(TRUE);
- m_pView->FindText(m_strFindWhat, m_bMatchCase, m_bWholeWord, m_nDirection);
- //CDialog::OnOK();
-}
-
-BOOL CFindDlg::OnInitDialog()
-{
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- m_pView = (CReaderVCView *)(((CChildFrame *)((CMainFrame *)AfxGetMainWnd())->GetActiveFrame())->GetActiveView());
- ASSERT(m_pView);
- ((CButton *)GetDlgItem(IDC_RADIO_Down))->SetCheck(1);
- ((CButton *)GetDlgItem(IDC_CHECK_MATCHWHOLE))->SetCheck(1);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
-}
diff --git a/xfa_test/FormFiller_Test/FindDlg.h b/xfa_test/FormFiller_Test/FindDlg.h
deleted file mode 100644
index 18ef88dc96..0000000000
--- a/xfa_test/FormFiller_Test/FindDlg.h
+++ /dev/null
@@ -1,50 +0,0 @@
-#if !defined(AFX_FINDDLG_H__355AF96B_B487_4503_8658_7F37B397D38A__INCLUDED_)
-#define AFX_FINDDLG_H__355AF96B_B487_4503_8658_7F37B397D38A__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-// FindDlg.h : header file
-//
-
-/////////////////////////////////////////////////////////////////////////////
-// CFindDlg dialog
-class CReaderVCView;
-class CFindDlg : public CDialog
-{
-// Construction
-public:
- CFindDlg(CWnd* pParent = NULL); // standard constructor
-
-// Dialog Data
- //{{AFX_DATA(CFindDlg)
- enum { IDD = IDD_DLG_FIND };
- BOOL m_bMatchCase;
- BOOL m_bWholeWord;
- CString m_strFindWhat;
- int m_nDirection;
- //}}AFX_DATA
-
-
-// Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CFindDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
-
-// Implementation
-protected:
- CReaderVCView *m_pView;
- // Generated message map functions
- //{{AFX_MSG(CFindDlg)
- virtual void OnOK();
- virtual BOOL OnInitDialog();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
-};
-
-//{{AFX_INSERT_LOCATION}}
-// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
-
-#endif // !defined(AFX_FINDDLG_H__355AF96B_B487_4503_8658_7F37B397D38A__INCLUDED_)
diff --git a/xfa_test/FormFiller_Test/GotoPageDlg.cpp b/xfa_test/FormFiller_Test/GotoPageDlg.cpp
deleted file mode 100644
index 5c189c8c52..0000000000
--- a/xfa_test/FormFiller_Test/GotoPageDlg.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-// GotoPageDlg.cpp : implementation file
-//
-
-#include "stdafx.h"
-#include "ReaderVC.h"
-#include "GotoPageDlg.h"
-
-#include "MainFrm.h"
-#include "ChildFrm.h"
-#include "ReaderVCView.h"
-
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-// CGotoPageDlg dialog
-
-
-CGotoPageDlg::CGotoPageDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CGotoPageDlg::IDD, pParent)
-{
- //{{AFX_DATA_INIT(CGotoPageDlg)
- m_nPageIndex = 0;
- //}}AFX_DATA_INIT
-}
-
-
-void CGotoPageDlg::DoDataExchange(CDataExchange* pDX)
-{
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CGotoPageDlg)
- DDX_Text(pDX, IDC_EDIT1, m_nPageIndex);
- //}}AFX_DATA_MAP
-}
-
-
-BEGIN_MESSAGE_MAP(CGotoPageDlg, CDialog)
- //{{AFX_MSG_MAP(CGotoPageDlg)
- //}}AFX_MSG_MAP
-END_MESSAGE_MAP()
-
-/////////////////////////////////////////////////////////////////////////////
-// CGotoPageDlg message handlers
-
-void CGotoPageDlg::OnOK()
-{
- // TODO: Add extra validation here
- if (NULL == m_pView) return;
- UpdateData(TRUE);
- m_pView->GotoPage(m_nPageIndex);
- CDialog::OnOK();
-}
-
-BOOL CGotoPageDlg::OnInitDialog()
-{
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- m_pView = (CReaderVCView *)(((CChildFrame *)((CMainFrame *)AfxGetMainWnd())->GetActiveFrame())->GetActiveView());
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
-}
diff --git a/xfa_test/FormFiller_Test/GotoPageDlg.h b/xfa_test/FormFiller_Test/GotoPageDlg.h
deleted file mode 100644
index 40f6bea1c2..0000000000
--- a/xfa_test/FormFiller_Test/GotoPageDlg.h
+++ /dev/null
@@ -1,48 +0,0 @@
-#if !defined(AFX_GOTOPAGEDLG_H__674C0708_4B25_4465_A73F_310610F9B991__INCLUDED_)
-#define AFX_GOTOPAGEDLG_H__674C0708_4B25_4465_A73F_310610F9B991__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-// GotoPageDlg.h : header file
-//
-
-/////////////////////////////////////////////////////////////////////////////
-// CGotoPageDlg dialog
-class CReaderVCView;
-class CGotoPageDlg : public CDialog
-{
-// Construction
-public:
- CGotoPageDlg(CWnd* pParent = NULL); // standard constructor
-
-// Dialog Data
- //{{AFX_DATA(CGotoPageDlg)
- enum { IDD = IDD_DLG_GOTOPAGE };
- int m_nPageIndex;
- //}}AFX_DATA
-
-
-// Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CGotoPageDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
-private:
- CReaderVCView *m_pView;
-// Implementation
-protected:
-
- // Generated message map functions
- //{{AFX_MSG(CGotoPageDlg)
- virtual void OnOK();
- virtual BOOL OnInitDialog();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
-};
-
-//{{AFX_INSERT_LOCATION}}
-// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
-
-#endif // !defined(AFX_GOTOPAGEDLG_H__674C0708_4B25_4465_A73F_310610F9B991__INCLUDED_)
diff --git a/xfa_test/FormFiller_Test/JS_ResponseDlg.cpp b/xfa_test/FormFiller_Test/JS_ResponseDlg.cpp
deleted file mode 100644
index 043efc24c4..0000000000
--- a/xfa_test/FormFiller_Test/JS_ResponseDlg.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-// JS_ResponseDlg.cpp : implementation file
-//
-
-#include "stdafx.h"
-#include "readervc.h"
-#include "JS_ResponseDlg.h"
-
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-// CJS_ResponseDlg dialog
-
-
-CJS_ResponseDlg::CJS_ResponseDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CJS_ResponseDlg::IDD, pParent)
-{
- //{{AFX_DATA_INIT(CJS_ResponseDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_swTitle =(FPDF_WIDESTRING) L"";
- m_swQuestion =(FPDF_WIDESTRING) L"";
- m_swLabel =(FPDF_WIDESTRING) L"";
- m_swDefault =(FPDF_WIDESTRING) L"";
- m_swResponse =L"";
- m_bIsVisible = false;
- m_pResponseEdit = NULL;
-}
-
-
-void CJS_ResponseDlg::DoDataExchange(CDataExchange* pDX)
-{
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CJS_ResponseDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
-}
-
-
-BEGIN_MESSAGE_MAP(CJS_ResponseDlg, CDialog)
- //{{AFX_MSG_MAP(CJS_ResponseDlg)
- // NOTE: the ClassWizard will add message map macros here
- ON_BN_CLICKED(ID_JS_OK, OnResOk)
- ON_BN_CLICKED(ID_JS_CANCEL, OnResCancel)
- //}}AFX_MSG_MAP
-END_MESSAGE_MAP()
-
-/////////////////////////////////////////////////////////////////////////////
-// CJS_ResponseDlg message handlers
-BOOL CJS_ResponseDlg::OnInitDialog()
-{
- CDialog::OnInitDialog();
-
- ::SetWindowTextW(this->GetSafeHwnd(), (LPCWSTR)m_swTitle);
-
- CStatic* pQuestion = (CStatic*)GetDlgItem(IDC_JS_QUESTION);
- ::SetWindowTextW(pQuestion->GetSafeHwnd(), (LPCWSTR)m_swQuestion);
-
- CStatic* pLabel = (CStatic*)GetDlgItem(IDC_JS_ANSWER);
-
- CRect DialogRect;
- CRect LabelRect;
- RECT rect;
- GetWindowRect(&DialogRect);
- pLabel->GetWindowRect(&LabelRect);
-
- if(m_swLabel == (FPDF_WIDESTRING)L"")
- {
- rect.left = DialogRect.left + 20;
- pLabel->ShowWindow(SW_HIDE);
- }
- else
- {
- rect.left = LabelRect.right + 1;
- ::SetWindowTextW(pLabel->GetSafeHwnd(), (LPCWSTR)m_swLabel);
- }
-
- rect.top = LabelRect.top - 3;
- rect.right = DialogRect.right - 20;
- rect.bottom = LabelRect.bottom + 2;
- ScreenToClient(&rect);
- m_pResponseEdit = new CEdit();
-
- if(m_bIsVisible)
- m_pResponseEdit->Create(ES_AUTOVSCROLL | ES_NOHIDESEL | ES_PASSWORD | WS_BORDER, rect, this, IDC_JS_EDIT);
- else
- m_pResponseEdit->Create(ES_AUTOVSCROLL | ES_NOHIDESEL | WS_BORDER, rect, this, IDC_JS_EDIT);
-
- ::SetWindowTextW(m_pResponseEdit->GetSafeHwnd(), (LPCWSTR)m_swDefault);
- m_pResponseEdit->ShowWindow(SW_SHOW);
-
- return TRUE;
-}
-
-void CJS_ResponseDlg::OnResOk()
-{
- m_swResponse = (wchar_t*)malloc(sizeof(wchar_t) * 250);
- ::GetWindowTextW(m_pResponseEdit->GetSafeHwnd(), m_swResponse, 250);
-
- if(m_pResponseEdit)
- {
- m_pResponseEdit->DestroyWindow();
- delete m_pResponseEdit;
- m_pResponseEdit = NULL;
- }
- CDialog::OnOK();
-}
-
-void CJS_ResponseDlg::OnResCancel()
-{
- if(m_pResponseEdit)
- {
- m_pResponseEdit->DestroyWindow();
- delete m_pResponseEdit;
- m_pResponseEdit = NULL;
- }
-
- CDialog::OnCancel();
-}
-
-void CJS_ResponseDlg::SetTitle(FPDF_WIDESTRING swTitle)
-{
- m_swTitle = swTitle;
-}
-
-void CJS_ResponseDlg::SetQuestion(FPDF_WIDESTRING swQuestion)
-{
- m_swQuestion = swQuestion;
-}
-
-void CJS_ResponseDlg::SetLabel(FPDF_WIDESTRING swLabel)
-{
- m_swLabel = swLabel;
-}
-
-void CJS_ResponseDlg::SetDefault(FPDF_WIDESTRING swDefault)
-{
- m_swDefault = swDefault;
-}
-
-FPDF_WIDESTRING CJS_ResponseDlg::GetResponse()
-{
- return (FPDF_WIDESTRING)m_swResponse;
-}
-
-void CJS_ResponseDlg::SetIsVisible(FPDF_BOOL bPassword)
-{
- m_bIsVisible = bPassword;
-}
diff --git a/xfa_test/FormFiller_Test/JS_ResponseDlg.h b/xfa_test/FormFiller_Test/JS_ResponseDlg.h
deleted file mode 100644
index c3410c49bc..0000000000
--- a/xfa_test/FormFiller_Test/JS_ResponseDlg.h
+++ /dev/null
@@ -1,64 +0,0 @@
-#if !defined(AFX_JS_RESPONSEDLG_H__AE1575EB_3F0A_46E7_B278_089C74F2B34C__INCLUDED_)
-#define AFX_JS_RESPONSEDLG_H__AE1575EB_3F0A_46E7_B278_089C74F2B34C__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-// JS_ResponseDlg.h : header file
-//
-
-/////////////////////////////////////////////////////////////////////////////
-// CJS_ResponseDlg dialog
-
-class CJS_ResponseDlg : public CDialog
-{
-// Construction
-public:
- CJS_ResponseDlg(CWnd* pParent = NULL); // standard constructor
- ~CJS_ResponseDlg(){ if(m_swResponse) free(m_swResponse); }
-
-// Dialog Data
- //{{AFX_DATA(CJS_ResponseDlg)
- enum { IDD = IDD_DLG_RESPONSE };
- // NOTE: the ClassWizard will add data members here
- //}}AFX_DATA
-public:
- void SetTitle(FPDF_WIDESTRING swTitle);
- void SetQuestion(FPDF_WIDESTRING swQuestion);
- void SetDefault(FPDF_WIDESTRING swDefault);
- void SetLabel(FPDF_WIDESTRING swLabel);
- void SetIsVisible(FPDF_BOOL bPassword);
- FPDF_WIDESTRING GetResponse();
-
-private:
- FPDF_WIDESTRING m_swTitle;
- FPDF_WIDESTRING m_swQuestion;
- FPDF_WIDESTRING m_swDefault;
- FPDF_WIDESTRING m_swLabel;
- wchar_t* m_swResponse;
- FPDF_BOOL m_bIsVisible;
- CEdit* m_pResponseEdit;
-// Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CJS_ResponseDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
-
-// Implementation
-protected:
-
- // Generated message map functions
- //{{AFX_MSG(CJS_ResponseDlg)
- // NOTE: the ClassWizard will add member functions here
- virtual BOOL OnInitDialog();
- afx_msg void OnResOk();
- afx_msg void OnResCancel();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
-};
-
-//{{AFX_INSERT_LOCATION}}
-// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
-
-#endif // !defined(AFX_JS_RESPONSEDLG_H__AE1575EB_3F0A_46E7_B278_089C74F2B34C__INCLUDED_)
diff --git a/xfa_test/FormFiller_Test/MainFrm.cpp b/xfa_test/FormFiller_Test/MainFrm.cpp
deleted file mode 100644
index b6e59439b6..0000000000
--- a/xfa_test/FormFiller_Test/MainFrm.cpp
+++ /dev/null
@@ -1,238 +0,0 @@
-// MainFrm.cpp : implementation of the CMainFrame class
-//
-
-#include "stdafx.h"
-#include "ReaderVC.h"
-
-#include "MainFrm.h"
-
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-// CMainFrame
-
-IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
-
-BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code !
- ON_WM_CREATE()
- //}}AFX_MSG_MAP
-END_MESSAGE_MAP()
-
-static UINT indicators[] =
-{
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
-};
-
-/////////////////////////////////////////////////////////////////////////////
-// CMainFrame construction/destruction
-
-CMainFrame::CMainFrame()
-{
- // TODO: add member initialization code here
-
-}
-
-CMainFrame::~CMainFrame()
-{
-}
-
-int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
-{
- if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbar\n");
- return -1; // fail to create
- }
-
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status bar\n");
- return -1; // fail to create
- }
-
- // TODO: Delete these three lines if you don't want the toolbar to
- // be dockable
-
- m_wndToolBar.ModifyStyle(0,TBSTYLE_FLAT | CBRS_TOOLTIPS | TBSTYLE_TRANSPARENT | TBBS_CHECKBOX);
- m_wndToolBar.GetToolBarCtrl().SetButtonWidth(40,40);
-
- CImageList ImgList,ImgList1;
- CBitmap bm;
- ImgList.Create(22,22,ILC_COLOR8|ILC_MASK, 16, 16);
- ImgList.SetBkColor(::GetSysColor(15));
- bm.LoadBitmap(IDB_BITMAP23);//OPEN
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP35);//Print
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP17);//first page
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP24);//prev page
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP22);//next page
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP21);//last page
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP16);//count clockwise
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP15);//clockwise
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP14);//zoom in
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP26);//zoom out
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP13);//actual size
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP18);//fit page
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP19);//fit width
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP36);//search
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP7);//Bookmark
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP25);//snap shot
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP2);//select text
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP20);//hand tool
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP12);//about
- ImgList.Add(&bm,RGB(0,255,0));
- bm.Detach();
- m_wndToolBar.GetToolBarCtrl().SetImageList(&ImgList);
- //m_wndToolBar.GetToolBarCtrl().SetHotImageList(&ImgList);
- ImgList.Detach();
-
- ImgList1.Create(22,22,ILC_COLOR8|ILC_MASK, 16, 16);
- ImgList1.SetBkColor(::GetSysColor(15));
- bm.LoadBitmap(IDB_BITMAP23);//open
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP30);//printer
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP8);//first page
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP29);//prev page
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP28);//next page
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP27);//last page
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP1);//count clockwise
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP6);//clockwise
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP33);//zoom in
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP34);//zoom out
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP4);//actual size
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP9);//fit page
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP10);//fit width
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP31);//search
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP5);//bookmark
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP32);//snap
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP3);//select text
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP11);//hand tool
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- bm.LoadBitmap(IDB_BITMAP12);//about
- ImgList1.Add(&bm,RGB(0,255,0));
- bm.Detach();
- m_wndToolBar.GetToolBarCtrl().SetDisabledImageList(&ImgList1);
- ImgList1.Detach();
-
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
-
- return 0;
-}
-
-BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
-{
- if( !CMDIFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
-
- return TRUE;
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// CMainFrame diagnostics
-
-#ifdef _DEBUG
-void CMainFrame::AssertValid() const
-{
- CMDIFrameWnd::AssertValid();
-}
-
-void CMainFrame::Dump(CDumpContext& dc) const
-{
- CMDIFrameWnd::Dump(dc);
-}
-
-#endif //_DEBUG
-
-/////////////////////////////////////////////////////////////////////////////
-// CMainFrame message handlers
-
diff --git a/xfa_test/FormFiller_Test/MainFrm.h b/xfa_test/FormFiller_Test/MainFrm.h
deleted file mode 100644
index 1b9f128fba..0000000000
--- a/xfa_test/FormFiller_Test/MainFrm.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// MainFrm.h : interface of the CMainFrame class
-//
-/////////////////////////////////////////////////////////////////////////////
-
-#if !defined(AFX_MAINFRM_H__B05284F9_FD96_49A9_B8B2_F77706A9A02B__INCLUDED_)
-#define AFX_MAINFRM_H__B05284F9_FD96_49A9_B8B2_F77706A9A02B__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-
-class CMainFrame : public CMDIFrameWnd
-{
- DECLARE_DYNAMIC(CMainFrame)
-public:
- CMainFrame();
-
-// Attributes
-public:
- CStatusBar m_wndStatusBar;
- CToolBar m_wndToolBar;
-// Operations
-public:
-
-// Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CMainFrame)
- virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
- //}}AFX_VIRTUAL
-
-// Implementation
-public:
- virtual ~CMainFrame();
-#ifdef _DEBUG
- virtual void AssertValid() const;
- virtual void Dump(CDumpContext& dc) const;
-#endif
-
-protected: // control bar embedded members
-
-// Generated message map functions
-protected:
- //{{AFX_MSG(CMainFrame)
- afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
- // NOTE - the ClassWizard will add and remove member functions here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
-};
-
-/////////////////////////////////////////////////////////////////////////////
-
-//{{AFX_INSERT_LOCATION}}
-// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
-
-#endif // !defined(AFX_MAINFRM_H__B05284F9_FD96_49A9_B8B2_F77706A9A02B__INCLUDED_)
diff --git a/xfa_test/FormFiller_Test/ReaderVC.cpp b/xfa_test/FormFiller_Test/ReaderVC.cpp
deleted file mode 100644
index 2d58c25062..0000000000
--- a/xfa_test/FormFiller_Test/ReaderVC.cpp
+++ /dev/null
@@ -1,195 +0,0 @@
-// ReaderVC.cpp : Defines the class behaviors for the application.
-//
-
-#include "stdafx.h"
-#include "ReaderVC.h"
-
-#include "MainFrm.h"
-#include "ChildFrm.h"
-#include "ReaderVCDoc.h"
-#include "ReaderVCView.h"
-#include "BookmarkView.h"
-
-
-
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-// CReaderVCApp
-
-BEGIN_MESSAGE_MAP(CReaderVCApp, CWinApp)
- //{{AFX_MSG_MAP(CReaderVCApp)
- ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- // Standard file based document commands
- ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
- ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
- // Standard print setup command
- ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
-END_MESSAGE_MAP()
-
-/////////////////////////////////////////////////////////////////////////////
-// CReaderVCApp construction
-
-
-CReaderVCApp::CReaderVCApp()
-{
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
-
-
-
- m_pActiveView = NULL;
-
-
-
-// FPDF_InitFormFillEnviroument(this);
-}
-
-CReaderVCApp::~CReaderVCApp()
-{
-
-
-
-}
-/////////////////////////////////////////////////////////////////////////////
-// The one and only CReaderVCApp object
-
-CReaderVCApp theApp;
-
-/////////////////////////////////////////////////////////////////////////////
-// CReaderVCApp initialization
-extern void SetSampleFontInfo();
-BOOL CReaderVCApp::InitInstance()
-{
- AfxEnableControlContainer();
- FPDF_InitLibrary(this->m_hInstance);
-// FPDF_UnlockDLL("SDKRDYX0408","5E5885A8AD61A855485D9F6C85BE82EF7C1F63AC");
-
- SetSampleFontInfo();
- // Standard initialization
- // If you are not using these features and wish to reduce the size
- // of your final executable, you should remove from the following
- // the specific initialization routines you do not need.
-
-#ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
-#else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
-#endif
-
- // Change the registry key under which our settings are stored.
- // TODO: You should modify this string to be something appropriate
- // such as the name of your company or organization.
- SetRegistryKey(_T("Local AppWizard-Generated Applications"));
-
- LoadStdProfileSettings(); // Load standard INI file options (including MRU)
-
- // Register the application's document templates. Document templates
- // serve as the connection between documents, frame windows and views.
-
- CMultiDocTemplate* pDocTemplate;
- pDocTemplate = new CMultiDocTemplate(
- IDR_READERTYPE,
- RUNTIME_CLASS(CReaderVCDoc),
- RUNTIME_CLASS(CChildFrame), // custom MDI child frame
- RUNTIME_CLASS(CReaderVCView));
- AddDocTemplate(pDocTemplate);
-
- CMultiDocTemplate* pDocTemplate1;
- pDocTemplate1 = new CMultiDocTemplate(
- IDR_READERTYPE,
- RUNTIME_CLASS(CReaderVCDoc),
- RUNTIME_CLASS(CChildFrame), // custom MDI child frame
- RUNTIME_CLASS(CBookMarkView));
- AddDocTemplate(pDocTemplate1);
- // create main MDI Frame window
- CMainFrame* pMainFrame = new CMainFrame;
- if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
- return FALSE;
- m_pMainWnd = pMainFrame;
- // Parse command line for standard shell commands, DDE, file open
- CCommandLineInfo cmdInfo;
- cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
- ParseCommandLine(cmdInfo);
-
- // Dispatch commands specified on the command line
- if (!ProcessShellCommand(cmdInfo))
- return FALSE;
-
- // The main window has been initialized, so show and update it.
- pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);
- pMainFrame->UpdateWindow();
- return TRUE;
-}
-
-
-/////////////////////////////////////////////////////////////////////////////
-// CAboutDlg dialog used for App About
-
-class CAboutDlg : public CDialog
-{
-public:
- CAboutDlg();
-
-// Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
-
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
-
-// Implementation
-protected:
- //{{AFX_MSG(CAboutDlg)
- afx_msg void OnMetalfile();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
-};
-
-CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
-{
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
-}
-
-void CAboutDlg::DoDataExchange(CDataExchange* pDX)
-{
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
-}
-
-BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- //}}AFX_MSG_MAP
-END_MESSAGE_MAP()
-
-// App command to run the dialog
-void CReaderVCApp::OnAppAbout()
-{
- CAboutDlg aboutDlg;
- aboutDlg.DoModal();
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// CReaderVCApp message handlers
-
-
-int CReaderVCApp::ExitInstance()
-{
- // TODO: Add your specialized code here and/or call the base class
- FPDF_DestroyLibrary();
-
- return CWinApp::ExitInstance();
-}
diff --git a/xfa_test/FormFiller_Test/ReaderVC.dsp b/xfa_test/FormFiller_Test/ReaderVC.dsp
deleted file mode 100644
index 8d95e07d81..0000000000
--- a/xfa_test/FormFiller_Test/ReaderVC.dsp
+++ /dev/null
@@ -1,460 +0,0 @@
-# Microsoft Developer Studio Project File - Name="ReaderVC" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Application" 0x0101
-
-CFG=ReaderVC - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "ReaderVC.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "ReaderVC.mak" CFG="ReaderVC - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "ReaderVC - Win32 Release" (based on "Win32 (x86) Application")
-!MESSAGE "ReaderVC - Win32 Debug" (based on "Win32 (x86) Application")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "ReaderVC - Win32 Release"
-
-# PROP BASE Use_MFC 6
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 6
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /D "FPDFSDK_EXPORTS" /FR /Yu"stdafx.h" /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x804 /d "NDEBUG" /d "_AFXDLL"
-# ADD RSC /l 0x804 /d "NDEBUG" /d "_AFXDLL"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 /nologo /subsystem:windows /machine:I386
-# ADD LINK32 /nologo /subsystem:windows /machine:I386 /out:"../../lib/rel_w32_vc6/ReaderVC.exe"
-
-!ELSEIF "$(CFG)" == "ReaderVC - Win32 Debug"
-
-# PROP BASE Use_MFC 6
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 6
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /D "FPDFSDK_EXPORTS" /FR /Yu"stdafx.h" /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x804 /d "_DEBUG" /d "_AFXDLL"
-# ADD RSC /l 0x804 /d "_DEBUG" /d "_AFXDLL"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 Msimg32.lib /nologo /subsystem:windows /map /debug /machine:I386 /out:"../../lib/dbg_w32_vc6/ReaderVC.exe" /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "ReaderVC - Win32 Release"
-# Name "ReaderVC - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\BookMarkView.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\ChildFrm.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\ConvertDlg.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\ExportPage.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\FindDlg.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\FX_SplitterWnd.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\GotoPageDlg.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\JS_ResponseDlg.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\MainFrm.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\ReaderVC.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\ReaderVC.rc
-# End Source File
-# Begin Source File
-
-SOURCE=.\ReaderVCDoc.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\ReaderVCView.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.cpp
-# ADD CPP /Yc"stdafx.h"
-# End Source File
-# Begin Source File
-
-SOURCE=.\TestJsDlg.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\ZoomDlg.cpp
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\BookMarkView.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\ChildFrm.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\ConvertDlg.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\ExportPage.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\FindDlg.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\FX_SplitterWnd.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\GotoPageDlg.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\JS_ResponseDlg.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\MainFrm.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\ReaderVC.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\ReaderVCDoc.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\ReaderVCView.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\Resource.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\StdAfx.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\TestJsDlg.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\ZoomDlg.h
-# End Source File
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
-# Begin Source File
-
-SOURCE=.\res\BigHandCursor.cur
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\bitmap1.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\bitmap12.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\bitmap19.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\bitmap2.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\bitmap20.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\bitmap21.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\bitmap22.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\bitmap23.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\bitmap26.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\bookmark.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\bound.cur
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\formOptions.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\point.cur
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\Rd_SelText_Icon.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\Rd_SelText_Icon_Dis.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\ReaderVC.ico
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\ReaderVC.rc2
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\ReaderVCDoc.ico
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\SmallHandCursor.cur
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_actual_size.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_bookmark1.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_clockwise.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_counterclockwise.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_first.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_fit_page.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_fit_width.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hand1.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_about2.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_actual_size.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_bookmark1.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_clockwise.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_counterclockwise.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_first.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_fit_page.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_fit_width.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_hand1.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_last.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_next.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_open1.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_prev.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_print.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_search.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_snap_shot.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_zoomin.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_hot_zoomout.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_last.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_next.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_prev.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_print.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_search.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_snap_shot.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_zoomin.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\tool_zoomout.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\Toolbar.bmp
-# End Source File
-# Begin Source File
-
-SOURCE=.\res\unknowncolor_gray.bmp
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=.\ReadMe.txt
-# End Source File
-# End Target
-# End Project
diff --git a/xfa_test/FormFiller_Test/ReaderVC.h b/xfa_test/FormFiller_Test/ReaderVC.h
deleted file mode 100644
index 11bcc4354f..0000000000
--- a/xfa_test/FormFiller_Test/ReaderVC.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// ReaderVC.h : main header file for the READERVC application
-//
-
-#if !defined(AFX_READERVC_H__7873A15F_A60F_4C05_9DC6_C3914C224EAA__INCLUDED_)
-#define AFX_READERVC_H__7873A15F_A60F_4C05_9DC6_C3914C224EAA__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-
-#ifndef __AFXWIN_H__
- #error include 'stdafx.h' before including this file for PCH
-#endif
-
-class CReaderVCView;
-
-#include "resource.h" // main symbols
-
-/////////////////////////////////////////////////////////////////////////////
-// CReaderVCApp:
-// See ReaderVC.cpp for the implementation of this class
-//
-
-class CReaderVCApp : public CWinApp
-{
-public:
- CReaderVCApp();
- ~CReaderVCApp();
- CReaderVCView * m_pActiveView;
-
-// Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CReaderVCApp)
- public:
- virtual BOOL InitInstance();
- virtual int ExitInstance();
- //}}AFX_VIRTUAL
-
-// Implementation
- //{{AFX_MSG(CReaderVCApp)
- afx_msg void OnAppAbout();
- // NOTE - the ClassWizard will add and remove member functions here.
- // DO NOT EDIT what you see in these blocks of generated code !
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
-};
-
-
-/////////////////////////////////////////////////////////////////////////////
-
-//{{AFX_INSERT_LOCATION}}
-// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
-
-#endif // !defined(AFX_READERVC_H__7873A15F_A60F_4C05_9DC6_C3914C224EAA__INCLUDED_)
diff --git a/xfa_test/FormFiller_Test/ReaderVC.rc b/xfa_test/FormFiller_Test/ReaderVC.rc
deleted file mode 100644
index bf647aefb6..0000000000
--- a/xfa_test/FormFiller_Test/ReaderVC.rc
+++ /dev/null
@@ -1,741 +0,0 @@
-//Microsoft Developer Studio generated resource script.
-//
-#include "resource.h"
-
-#define APSTUDIO_READONLY_SYMBOLS
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 2 resource.
-//
-#include "afxres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-#undef APSTUDIO_READONLY_SYMBOLS
-
-/////////////////////////////////////////////////////////////////////////////
-// Chinese (P.R.C.) resources
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
-#ifdef _WIN32
-LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
-#pragma code_page(936)
-#endif //_WIN32
-
-#ifdef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// TEXTINCLUDE
-//
-
-1 TEXTINCLUDE DISCARDABLE
-BEGIN
- "resource.h\0"
-END
-
-2 TEXTINCLUDE DISCARDABLE
-BEGIN
- "#include ""afxres.h""\r\n"
- "\0"
-END
-
-3 TEXTINCLUDE DISCARDABLE
-BEGIN
- "#define _AFX_NO_SPLITTER_RESOURCES\r\n"
- "#define _AFX_NO_OLE_RESOURCES\r\n"
- "#define _AFX_NO_TRACKER_RESOURCES\r\n"
- "#define _AFX_NO_PROPERTY_RESOURCES\r\n"
- "\r\n"
- "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)\r\n"
- "#ifdef _WIN32\r\n"
- "LANGUAGE 4, 2\r\n"
- "#pragma code_page(936)\r\n"
- "#endif //_WIN32\r\n"
- "#include ""res\\ReaderVC.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
- "#include ""l.chs\\afxres.rc"" // Standard components\r\n"
- "#include ""l.chs\\afxprint.rc"" // printing/print preview resources\r\n"
- "#endif\r\n"
- "\0"
-END
-
-#endif // APSTUDIO_INVOKED
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Icon
-//
-
-// Icon with lowest ID value placed first to ensure application icon
-// remains consistent on all systems.
-IDR_MAINFRAME ICON DISCARDABLE "res\\ReaderVC.ico"
-IDR_READERTYPE ICON DISCARDABLE "res\\ReaderVCDoc.ico"
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Bitmap
-//
-
-IDR_MAINFRAME BITMAP MOVEABLE PURE "res\\Toolbar.bmp"
-IDB_BITMAP1 BITMAP DISCARDABLE "res\\tool_counterclockwise.bmp"
-IDB_BITMAP2 BITMAP DISCARDABLE "res\\Rd_SelText_Icon.bmp"
-IDB_BITMAP3 BITMAP DISCARDABLE "res\\Rd_SelText_Icon_Dis.bmp"
-IDB_BITMAP4 BITMAP DISCARDABLE "res\\tool_actual_size.bmp"
-IDB_BITMAP5 BITMAP DISCARDABLE "res\\tool_bookmark1.bmp"
-IDB_BITMAP6 BITMAP DISCARDABLE "res\\tool_clockwise.bmp"
-IDB_BITMAP7 BITMAP DISCARDABLE "res\\tool_hot_bookmark1.bmp"
-IDB_BITMAP8 BITMAP DISCARDABLE "res\\tool_first.bmp"
-IDB_BITMAP9 BITMAP DISCARDABLE "res\\tool_fit_page.bmp"
-IDB_BITMAP10 BITMAP DISCARDABLE "res\\tool_fit_width.bmp"
-IDB_BITMAP11 BITMAP DISCARDABLE "res\\tool_hand1.bmp"
-IDB_BITMAP12 BITMAP DISCARDABLE "res\\tool_hot_about2.bmp"
-IDB_BITMAP13 BITMAP DISCARDABLE "res\\tool_hot_actual_size.bmp"
-IDB_BITMAP14 BITMAP DISCARDABLE "res\\tool_hot_zoomin.bmp"
-IDB_BITMAP15 BITMAP DISCARDABLE "res\\tool_hot_clockwise.bmp"
-IDB_BITMAP16 BITMAP DISCARDABLE "res\\tool_hot_counterclockwise.bmp"
-IDB_BITMAP17 BITMAP DISCARDABLE "res\\tool_hot_first.bmp"
-IDB_BITMAP18 BITMAP DISCARDABLE "res\\tool_hot_fit_page.bmp"
-IDB_BITMAP19 BITMAP DISCARDABLE "res\\tool_hot_fit_width.bmp"
-IDB_BITMAP20 BITMAP DISCARDABLE "res\\tool_hot_hand1.bmp"
-IDB_BITMAP21 BITMAP DISCARDABLE "res\\tool_hot_last.bmp"
-IDB_BITMAP22 BITMAP DISCARDABLE "res\\tool_hot_next.bmp"
-IDB_BITMAP23 BITMAP DISCARDABLE "res\\tool_hot_open1.bmp"
-IDB_BITMAP24 BITMAP DISCARDABLE "res\\tool_hot_prev.bmp"
-IDB_BITMAP26 BITMAP DISCARDABLE "res\\tool_hot_zoomout.bmp"
-IDB_BITMAP27 BITMAP DISCARDABLE "res\\tool_last.bmp"
-IDB_BITMAP28 BITMAP DISCARDABLE "res\\tool_next.bmp"
-IDB_BITMAP29 BITMAP DISCARDABLE "res\\tool_prev.bmp"
-IDB_BITMAP30 BITMAP DISCARDABLE "res\\tool_print.bmp"
-IDB_BITMAP31 BITMAP DISCARDABLE "res\\tool_search.bmp"
-IDB_BITMAP32 BITMAP DISCARDABLE "res\\tool_snap_shot.bmp"
-IDB_BITMAP33 BITMAP DISCARDABLE "res\\tool_zoomin.bmp"
-IDB_BITMAP34 BITMAP DISCARDABLE "res\\tool_zoomout.bmp"
-IDB_BITMAP25 BITMAP DISCARDABLE "res\\tool_hot_snap_shot.bmp"
-IDB_BITMAP35 BITMAP DISCARDABLE "res\\tool_hot_print.bmp"
-IDB_BITMAP36 BITMAP DISCARDABLE "res\\tool_hot_search.bmp"
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Toolbar
-//
-
-IDR_MAINFRAME TOOLBAR DISCARDABLE 24, 24
-BEGIN
- BUTTON ID_FILE_OPEN
- SEPARATOR
- BUTTON ID_FILE_PRINT
- SEPARATOR
- BUTTON ID_DOC_FIRSTPAGE
- BUTTON ID_DOC_PREPAGE
- BUTTON ID_DOC_NEXTPAGE
- BUTTON ID_DOC_LASTPAGE
- SEPARATOR
- BUTTON ID_VIEW_COUNTERCLOCKWISE
- BUTTON ID_VIEW_CLOCKWISE
- SEPARATOR
- BUTTON ID_VIEW_ZOOMIN
- BUTTON ID_VIEW_ZOOMOUT
- SEPARATOR
- BUTTON ID_VIEW_ACTUALSIZE
- BUTTON ID_VIEW_FITPAGE
- BUTTON ID_VIEW_FITWIDTH
- SEPARATOR
- BUTTON ID_EDIT_FIND
- SEPARATOR
- BUTTON ID_VIEW_BOOKMARK
- SEPARATOR
- BUTTON ID_TOOL_SNAPSHOT
- BUTTON ID_TOOL_SELECT
- BUTTON ID_TOOL_HAND
- BUTTON ID_APP_ABOUT
-END
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Accelerator
-//
-
-IDR_MAINFRAME ACCELERATORS PRELOAD MOVEABLE PURE
-BEGIN
- "+", ID_VIEW_ZOOMIN, VIRTKEY, CONTROL, NOINVERT
- "-", ID_VIEW_ZOOMOUT, VIRTKEY, CONTROL, NOINVERT
- "1", ID_VIEW_ACTUALSIZE, VIRTKEY, CONTROL, NOINVERT
- "2", ID_VIEW_FITPAGE, VIRTKEY, CONTROL, NOINVERT
- "3", ID_VIEW_FITWIDTH, VIRTKEY, CONTROL, NOINVERT
- "C", ID_EDIT_COPY, VIRTKEY, CONTROL, NOINVERT
- "F", ID_EDIT_FIND, VIRTKEY, CONTROL, NOINVERT
- "M", ID_VIEW_ZOOMTO, VIRTKEY, CONTROL, NOINVERT
- "N", ID_FILE_NEW, VIRTKEY, CONTROL, NOINVERT
- "N", ID_DOC_GOTOPAGE, VIRTKEY, SHIFT, CONTROL,
- NOINVERT
- "O", ID_FILE_OPEN, VIRTKEY, CONTROL, NOINVERT
- "P", ID_FILE_PRINT, VIRTKEY, CONTROL, NOINVERT
- "S", ID_FILE_SAVE, VIRTKEY, CONTROL, NOINVERT
- "V", ID_EDIT_PASTE, VIRTKEY, CONTROL, NOINVERT
- VK_BACK, ID_EDIT_UNDO, VIRTKEY, ALT, NOINVERT
- VK_DELETE, ID_EDIT_CUT, VIRTKEY, SHIFT, NOINVERT
- VK_F6, ID_NEXT_PANE, VIRTKEY, NOINVERT
- VK_F6, ID_PREV_PANE, VIRTKEY, SHIFT, NOINVERT
- VK_INSERT, ID_EDIT_COPY, VIRTKEY, CONTROL, NOINVERT
- VK_INSERT, ID_EDIT_PASTE, VIRTKEY, SHIFT, NOINVERT
- "X", ID_EDIT_CUT, VIRTKEY, CONTROL, NOINVERT
- "Z", ID_EDIT_UNDO, VIRTKEY, CONTROL, NOINVERT
-END
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Dialog
-//
-
-IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 235, 55
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "About ReaderVC"
-FONT 9, "ËÎÌå"
-BEGIN
- ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20
- LTEXT "Foxit SDK Demo 1.0 version",IDC_STATIC,40,10,126,8,
- SS_NOPREFIX
- LTEXT "All rights Reserved",IDC_STATIC,40,25,119,8
- DEFPUSHBUTTON "OK",IDOK,178,7,50,14,WS_GROUP
-END
-
-IDD_DLG_GOTOPAGE DIALOG DISCARDABLE 0, 0, 133, 29
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Goto Page"
-FONT 10, "MS Sans Serif"
-BEGIN
- DEFPUSHBUTTON "OK",IDOK,91,7,35,14
- LTEXT "Goto",IDC_STATIC,8,9,16,9
- EDITTEXT IDC_EDIT1,25,7,64,14,ES_AUTOHSCROLL
-END
-
-IDD_DLG_ZOOMTO DIALOG DISCARDABLE 0, 0, 141, 45
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Zoom To"
-FONT 10, "MS Sans Serif"
-BEGIN
- DEFPUSHBUTTON "OK",IDOK,38,24,29,14
- LTEXT "Zoom to",IDC_STATIC,7,9,30,8
- DEFPUSHBUTTON "Cancel",IDCANCEL,75,24,29,14
- COMBOBOX IDC_COMBO1,37,7,78,132,CBS_DROPDOWN | WS_VSCROLL |
- WS_TABSTOP
-END
-
-IDD_DLG_FIND DIALOG DISCARDABLE 0, 0, 222, 70
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Find Text"
-FONT 10, "MS Sans Serif"
-BEGIN
- DEFPUSHBUTTON "&Find Next",IDOK,174,7,41,13
- PUSHBUTTON "&Cancel",IDCANCEL,175,24,40,13
- LTEXT "&Find What",IDC_STATIC,7,10,38,10
- EDITTEXT IDC_EDIT1,46,7,124,16,ES_AUTOHSCROLL
- CONTROL "Match &Case",IDC_CHECK_MATCHCASE,"Button",
- BS_AUTOCHECKBOX | WS_TABSTOP,7,30,90,11
- CONTROL "Match &Whole word only",IDC_CHECK_MATCHWHOLE,"Button",
- BS_AUTOCHECKBOX | WS_TABSTOP,7,48,97,10
- GROUPBOX "Direction",IDC_STATIC,104,28,68,32
- CONTROL "Down",IDC_RADIO_Down,"Button",BS_AUTORADIOBUTTON |
- WS_GROUP,109,42,29,10
- CONTROL "Up",IDC_RADIO_UP,"Button",BS_AUTORADIOBUTTON,146,42,19,
- 10
-END
-
-IDD_DLG_CONVERT DIALOG DISCARDABLE 0, 0, 128, 74
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Convert mode"
-FONT 10, "System"
-BEGIN
- DEFPUSHBUTTON "OK",IDOK,17,55,42,12
- PUSHBUTTON "Cancel",IDCANCEL,69,55,42,12
- GROUPBOX "Flags for ConvertText",IDC_STATIC,16,7,95,46
- CONTROL "Stream order",IDC_RADIO_Stream,"Button",
- BS_AUTORADIOBUTTON | WS_GROUP,30,20,69,8
- CONTROL "Appearance order",IDC_RADIO_Appearance,"Button",
- BS_AUTORADIOBUTTON,30,31,69,8
-END
-
-IDD_EXPORT_PAGE DIALOG DISCARDABLE 0, 0, 230, 229
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Export Page"
-FONT 10, "System"
-BEGIN
- LTEXT "Width",IDC_STATIC,22,16,20,8
- LTEXT "Height",IDC_STATIC,21,37,22,8
- LTEXT "Rotate",IDC_STATIC,21,61,22,8
- LTEXT "Bitmap Width",IDC_STATIC,102,14,45,8
- LTEXT "Bitmap Height",IDC_STATIC,99,35,47,8
- PUSHBUTTON "Rander Page ",IDC_Rander_Page,102,58,50,14
- PUSHBUTTON "Save As...",IDC_Save,158,58,50,14
- EDITTEXT IDC_EDIT_PAGE_WIDTH,45,14,40,14,ES_AUTOHSCROLL
- EDITTEXT IDC_EDIT_PAGE_HEIGHT,45,35,40,14,ES_AUTOHSCROLL
- EDITTEXT IDC_EDIT_ROTATE,45,59,40,14,ES_AUTOHSCROLL
- EDITTEXT IDC_EDIT_WIDTH,149,13,40,14,ES_AUTOHSCROLL
- EDITTEXT IDC_EDIT_HEIGHT,148,33,40,14,ES_AUTOHSCROLL
- CONTROL "",IDC_STATIC_BITMAP,"Static",SS_BLACKFRAME,18,87,196,
- 127
-END
-
-IDD_DLG_RESPONSE DIALOG DISCARDABLE 0, 0, 241, 66
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Dialog"
-FONT 8, "System"
-BEGIN
- DEFPUSHBUTTON "OK",ID_JS_OK,116,45,50,14
- PUSHBUTTON "Cancel",ID_JS_CANCEL,184,45,50,14
- LTEXT "",IDC_JS_QUESTION,7,7,227,12
- LTEXT "",IDC_JS_ANSWER,7,26,27,12
-END
-
-IDD_TEST_JS DIALOG DISCARDABLE 0, 0, 187, 96
-STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
-CAPTION "Dialog"
-FONT 10, "System"
-BEGIN
- EDITTEXT IDC_EDIT1,7,18,173,33,ES_MULTILINE | ES_AUTOHSCROLL
- PUSHBUTTON "Run JS",IDC_BUTTON1,130,68,50,14
-END
-
-
-#ifndef _MAC
-/////////////////////////////////////////////////////////////////////////////
-//
-// Version
-//
-
-VS_VERSION_INFO VERSIONINFO
- FILEVERSION 1,0,0,1
- PRODUCTVERSION 1,0,0,1
- FILEFLAGSMASK 0x3fL
-#ifdef _DEBUG
- FILEFLAGS 0x1L
-#else
- FILEFLAGS 0x0L
-#endif
- FILEOS 0x4L
- FILETYPE 0x1L
- FILESUBTYPE 0x0L
-BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "080404b0"
- BEGIN
- VALUE "Comments", "\0"
- VALUE "CompanyName", "\0"
- VALUE "FileDescription", "ReaderVC Microsoft »ù´¡ÀàÓ¦ÓóÌÐò\0"
- VALUE "FileVersion", "1, 0, 0, 1\0"
- VALUE "InternalName", "ReaderVC\0"
- VALUE "LegalCopyright", "°æȨËùÓÐ (C) 2007\0"
- VALUE "LegalTrademarks", "\0"
- VALUE "OriginalFilename", "ReaderVC.EXE\0"
- VALUE "PrivateBuild", "\0"
- VALUE "ProductName", "ReaderVC Ó¦ÓóÌÐò\0"
- VALUE "ProductVersion", "1, 0, 0, 1\0"
- VALUE "SpecialBuild", "\0"
- END
- END
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x804, 1200
- END
-END
-
-#endif // !_MAC
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// DESIGNINFO
-//
-
-#ifdef APSTUDIO_INVOKED
-GUIDELINES DESIGNINFO DISCARDABLE
-BEGIN
- IDD_ABOUTBOX, DIALOG
- BEGIN
- LEFTMARGIN, 7
- RIGHTMARGIN, 228
- TOPMARGIN, 7
- BOTTOMMARGIN, 48
- END
-
- IDD_DLG_GOTOPAGE, DIALOG
- BEGIN
- LEFTMARGIN, 7
- RIGHTMARGIN, 126
- TOPMARGIN, 7
- BOTTOMMARGIN, 22
- END
-
- IDD_DLG_ZOOMTO, DIALOG
- BEGIN
- LEFTMARGIN, 7
- RIGHTMARGIN, 134
- TOPMARGIN, 7
- BOTTOMMARGIN, 38
- END
-
- IDD_DLG_FIND, DIALOG
- BEGIN
- LEFTMARGIN, 7
- RIGHTMARGIN, 215
- TOPMARGIN, 7
- BOTTOMMARGIN, 63
- END
-
- IDD_DLG_CONVERT, DIALOG
- BEGIN
- LEFTMARGIN, 7
- RIGHTMARGIN, 121
- TOPMARGIN, 7
- BOTTOMMARGIN, 67
- END
-
- IDD_EXPORT_PAGE, DIALOG
- BEGIN
- LEFTMARGIN, 7
- RIGHTMARGIN, 223
- TOPMARGIN, 7
- BOTTOMMARGIN, 222
- END
-
- IDD_DLG_RESPONSE, DIALOG
- BEGIN
- LEFTMARGIN, 7
- RIGHTMARGIN, 234
- TOPMARGIN, 7
- BOTTOMMARGIN, 59
- END
-
- IDD_TEST_JS, DIALOG
- BEGIN
- LEFTMARGIN, 7
- RIGHTMARGIN, 180
- TOPMARGIN, 7
- BOTTOMMARGIN, 89
- END
-END
-#endif // APSTUDIO_INVOKED
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Cursor
-//
-
-IDC_CURSOR1 CURSOR DISCARDABLE "res\\SmallHandCursor.cur"
-IDC_CURSOR2 CURSOR DISCARDABLE "res\\BigHandCursor.cur"
-IDC_CURSOR3 CURSOR DISCARDABLE "res\\bound.cur"
-IDC_CURSOR4 CURSOR DISCARDABLE "res\\point.cur"
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// String Table
-//
-
-STRINGTABLE PRELOAD DISCARDABLE
-BEGIN
- IDR_MAINFRAME "ReaderVC"
- IDR_READERTYPE "\nReader\nReader\n\n\nReaderVC.Document\nReader Document"
-END
-
-STRINGTABLE PRELOAD DISCARDABLE
-BEGIN
- AFX_IDS_APP_TITLE "ReaderVC"
- AFX_IDS_IDLEMESSAGE "¾ÍÐ÷"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_INDICATOR_EXT "À©Õ¹Ãû"
- ID_INDICATOR_CAPS "´óд"
- ID_INDICATOR_NUM "Êý×Ö"
- ID_INDICATOR_SCRL "¹ö¶¯"
- ID_INDICATOR_OVR "¸Äд"
- ID_INDICATOR_REC "¼Ç¼"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_FILE_NEW "½¨Á¢ÐÂÎĵµ\nн¨"
- ID_FILE_OPEN "´ò¿ªÒ»¸öÏÖÓÐÎĵµ\n´ò¿ª"
- ID_FILE_CLOSE "¹Ø±Õ»î¶¯Îĵµ\n¹Ø±Õ"
- ID_FILE_SAVE "±£´æ»î¶¯Îĵµ\n±£´æ"
- ID_FILE_SAVE_AS "½«»î¶¯ÎĵµÒÔÒ»¸öÐÂÎļþÃû±£´æ\nÁí´æΪ"
- ID_FILE_PAGE_SETUP "¸Ä±ä´òÓ¡Ñ¡Ïî\nÒ³ÃæÉèÖÃ"
- ID_FILE_PRINT_SETUP "¸Ä±ä´òÓ¡»ú¼°´òÓ¡Ñ¡Ïî\n´òÓ¡ÉèÖÃ"
- ID_FILE_PRINT "´òÓ¡»î¶¯Îĵµ\n´òÓ¡"
- ID_FILE_PRINT_PREVIEW "ÏÔʾÕûÒ³\n´òÓ¡Ô¤ÀÀ"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_APP_ABOUT "ÏÔʾ³ÌÐòÐÅÏ¢£¬°æ±¾ºÅºÍ°æȨ\n¹ØÓÚ"
- ID_APP_EXIT "Í˳öÓ¦ÓóÌÐò£»Ìáʾ±£´æÎĵµ\nÍ˳ö"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_FILE_MRU_FILE1 "´ò¿ª¸ÃÎĵµ"
- ID_FILE_MRU_FILE2 "´ò¿ª¸ÃÎĵµ"
- ID_FILE_MRU_FILE3 "´ò¿ª¸ÃÎĵµ"
- ID_FILE_MRU_FILE4 "´ò¿ª¸ÃÎĵµ"
- ID_FILE_MRU_FILE5 "´ò¿ª¸ÃÎĵµ"
- ID_FILE_MRU_FILE6 "´ò¿ª¸ÃÎĵµ"
- ID_FILE_MRU_FILE7 "´ò¿ª¸ÃÎĵµ"
- ID_FILE_MRU_FILE8 "´ò¿ª¸ÃÎĵµ"
- ID_FILE_MRU_FILE9 "´ò¿ª¸ÃÎĵµ"
- ID_FILE_MRU_FILE10 "´ò¿ª¸ÃÎĵµ"
- ID_FILE_MRU_FILE11 "´ò¿ª¸ÃÎĵµ"
- ID_FILE_MRU_FILE12 "´ò¿ª¸ÃÎĵµ"
- ID_FILE_MRU_FILE13 "´ò¿ª¸ÃÎĵµ"
- ID_FILE_MRU_FILE14 "´ò¿ª¸ÃÎĵµ"
- ID_FILE_MRU_FILE15 "´ò¿ª¸ÃÎĵµ"
- ID_FILE_MRU_FILE16 "´ò¿ª¸ÃÎĵµ"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_NEXT_PANE "Çл»µ½ÏÂÒ»¸ö´°¸ñ\nÏÂÒ»´°¸ñ"
- ID_PREV_PANE "Çл»»ØÇ°Ò»¸ö´°¸ñ\nÇ°Ò»´°¸ñ"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_WINDOW_NEW "Ϊ»î¶¯Îĵµ´ò¿ªÁíÒ»¸ö´°¿Ú\nн¨´°¿Ú"
- ID_WINDOW_ARRANGE "½«Í¼±êÅÅÁÐÔÚ´°¿Úµ×²¿\nÅÅÁÐͼ±ê"
- ID_WINDOW_CASCADE "ÅÅÁд°¿Ú³ÉÏ໥Öصþ\n²ãµþ´°¿Ú"
- ID_WINDOW_TILE_HORZ "ÅÅÁд°¿Ú³É»¥²»Öصþ\nƽÆÌ´°¿Ú"
- ID_WINDOW_TILE_VERT "ÅÅÁд°¿Ú³É»¥²»Öصþ\nƽÆÌ´°¿Ú"
- ID_WINDOW_SPLIT "½«»î¶¯µÄ´°¿Ú·Ö¸ô³É´°¸ñ\n·Ö¸ô"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_EDIT_CLEAR "ɾ³ý±»Ñ¡¶ÔÏó\nɾ³ý"
- ID_EDIT_CLEAR_ALL "È«²¿É¾³ý\nÈ«²¿É¾³ý"
- ID_EDIT_COPY "¸´ÖƱ»Ñ¡¶ÔÏó²¢½«ÆäÖÃÓÚ¼ôÌù°åÉÏ\n¸´ÖÆ"
- ID_EDIT_CUT "¼ôÇб»Ñ¡¶ÔÏó²¢½«ÆäÖÃÓÚ¼ôÌù°åÉÏ\n¼ôÇÐ"
- ID_EDIT_FIND "²éÕÒÖ¸¶¨µÄÕýÎÄ\n²éÕÒ"
- ID_EDIT_PASTE "²åÈë¼ôÌù°åÄÚÈÝ\nÕ³Ìù"
- ID_EDIT_REPEAT "Öظ´ÉÏÒ»²½²Ù×÷\nÖظ´"
- ID_EDIT_REPLACE "Óò»Í¬µÄÕýÎÄÌæ»»Ö¸¶¨µÄÕýÎÄ\nÌæ»»"
- ID_EDIT_SELECT_ALL "Ñ¡ÔñÕû¸öÎĵµ\nÑ¡ÔñÈ«²¿"
- ID_EDIT_UNDO "³·Ïû×îºóÒ»²½²Ù×÷\n³·Ïû"
- ID_EDIT_REDO "ÖØÐÂÖ´ÐÐÏÈÇ°Òѳ·ÏûµÄ²Ù×÷\nÖØÐÂÖ´ÐÐ"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- ID_VIEW_TOOLBAR "Show or hide the ToolBar\nShow or hide the ToolBar"
- ID_VIEW_STATUS_BAR "Show or hide\nShow or hide"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- AFX_IDS_SCSIZE "¸Ä±ä´°¿Ú´óС"
- AFX_IDS_SCMOVE "¸Ä±ä´°¿ÚλÖÃ"
- AFX_IDS_SCMINIMIZE "½«´°¿ÚËõС³Éͼ±ê"
- AFX_IDS_SCMAXIMIZE "°Ñ´°¿Ú·Å´óµ½×î´ó³ß´ç"
- AFX_IDS_SCNEXTWINDOW "Çл»µ½ÏÂÒ»¸öÎĵµ´°¿Ú"
- AFX_IDS_SCPREVWINDOW "Çл»µ½ÏÈÇ°µÄÎĵµ´°¿Ú"
- AFX_IDS_SCCLOSE "¹Ø±Õ»î¶¯µÄ´°¿Ú²¢Ìáʾ±£´æËùÓÐÎĵµ"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- AFX_IDS_SCRESTORE "°Ñ´°¿Ú»Ö¸´µ½Õý³£´óС"
- AFX_IDS_SCTASKLIST "¼¤»îÈÎÎñ±í"
- AFX_IDS_MDICHILD "¼¤»î¸Ã´°¿Ú"
-END
-
-STRINGTABLE DISCARDABLE
-BEGIN
- AFX_IDS_PREVIEW_CLOSE "¹Ø±Õ´òÓ¡Ô¤ÀÀģʽ\nÈ¡ÏûÔ¤ÔÄ"
-END
-
-#endif // Chinese (P.R.C.) resources
-/////////////////////////////////////////////////////////////////////////////
-
-
-/////////////////////////////////////////////////////////////////////////////
-// English (U.S.) resources
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
-#ifdef _WIN32
-LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
-#pragma code_page(1252)
-#endif //_WIN32
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Menu
-//
-
-IDR_READERTYPE MENU PRELOAD DISCARDABLE
-BEGIN
- POPUP "&File"
- BEGIN
- MENUITEM "&Open...\tCtrl+O", ID_FILE_OPEN
- MENUITEM "&Close", ID_FILE_CLOSE
- MENUITEM "&Save As...", ID_FILE_SAVE
- MENUITEM SEPARATOR
- MENUITEM "&Print...\tCtrl+P", ID_FILE_PRINT
- MENUITEM "P&rinter Setup...", ID_FILE_PRINT_SETUP
- MENUITEM SEPARATOR
- MENUITEM "Recently File", ID_FILE_MRU_FILE1, GRAYED
- MENUITEM SEPARATOR
- MENUITEM "E&xit...\tCtrl+Q", ID_APP_EXIT
- END
- POPUP "&Edit"
- BEGIN
- MENUITEM "&Copy Select Text", ID_EDIT_COPY
- MENUITEM "&Find Text...\tCtrl+F", ID_EDIT_FIND
- END
- POPUP "&View"
- BEGIN
- MENUITEM "Zoom &In\t\tNum+", ID_VIEW_ZOOMIN
- MENUITEM "Zoom &Out\t\tNum-", ID_VIEW_ZOOMOUT
- MENUITEM "Zoom &To...\tCtrl+M", ID_VIEW_ZOOMTO
- MENUITEM SEPARATOR
- MENUITEM "&Actual Size\tCtrl+1", ID_VIEW_ACTUALSIZE
- MENUITEM "Fit &Page\tCtrl+2", ID_VIEW_FITPAGE
- MENUITEM "Fit &Width\tCtrl+3", ID_VIEW_FITWIDTH
- MENUITEM SEPARATOR
- POPUP "&Rotate View"
- BEGIN
- MENUITEM "&Clockwise\tShift+Ctrl+Plus", ID_VIEW_CLOCKWISE, HELP
- MENUITEM "Counterclock&wise\tShift+Ctrl+Minus",
- ID_VIEW_COUNTERCLOCKWISE
- END
- MENUITEM SEPARATOR
- MENUITEM "&ToolBar", ID_VIEW_TOOLBAR
- MENUITEM "&StatusBar", ID_VIEW_STATUS_BAR
- END
- POPUP "&Document"
- BEGIN
- MENUITEM "&First Page \t\tHome", ID_DOC_FIRSTPAGE
- MENUITEM "P&revious Page\tLeft Arrow", ID_DOC_PREPAGE
- MENUITEM "&Next Page\tRight Arrow", ID_DOC_NEXTPAGE
- MENUITEM "&Last Page\tEnd", ID_DOC_LASTPAGE
- MENUITEM SEPARATOR
- MENUITEM "&Goto Page...\tShift+Ctrl+N", ID_DOC_GOTOPAGE
- MENUITEM "", TEST_PRINT_METALFILE
- END
- POPUP "&Tool"
- BEGIN
- MENUITEM "&Hand Tool", ID_TOOL_HAND
- MENUITEM "Se&lect Text", ID_TOOL_SELECT
- MENUITEM "&Snapshot", ID_TOOL_SNAPSHOT
- MENUITEM "Pdf2txt", ID_TOOL_PDF2TXT
- MENUITEM "Extract links", ID_TOOL_EXTRACTLINKS
- MENUITEM "Test JavaScript", IDM_Test_JS
- END
- POPUP "&Bitmap"
- BEGIN
- MENUITEM "&Export PDF to bitmap", ID_EXPORT_PDF_TO_BITMAP
- END
- POPUP "&Help"
- BEGIN
- MENUITEM "About ReaderVC(&A)...", ID_APP_ABOUT
- END
-END
-
-IDR_MAINFRAME MENU PRELOAD DISCARDABLE
-BEGIN
- POPUP "&File"
- BEGIN
- MENUITEM "&Open...\tCtrl+O", ID_FILE_OPEN
- MENUITEM "&Close", ID_FILE_CLOSE
- MENUITEM "&Save As...", ID_FILE_SAVE
- MENUITEM SEPARATOR
- MENUITEM "&Print...\tCtrl+P", ID_FILE_PRINT
- MENUITEM "P&rinter Setup...", ID_FILE_PRINT_SETUP
- MENUITEM SEPARATOR
- MENUITEM "Recently File", ID_FILE_MRU_FILE1, GRAYED
- MENUITEM SEPARATOR
- MENUITEM "E&xit...\tCtrl+Q", ID_APP_EXIT
- END
- POPUP "&Edit"
- BEGIN
- MENUITEM SEPARATOR
- MENUITEM "&Copy Select Text", ID_EDIT_COPY
- MENUITEM "&Find Text...\tCtrl+F", ID_EDIT_FIND
- END
- POPUP "&View"
- BEGIN
- MENUITEM "Zoom &In\t\tNum+", ID_VIEW_ZOOMIN
- MENUITEM "Zoom &Out\t\tNum-", ID_VIEW_ZOOMOUT
- MENUITEM "Zoom &To...\tCtrl+M", ID_VIEW_ZOOMTO
- MENUITEM SEPARATOR
- MENUITEM "&Actual Size\tCtrl+1", ID_VIEW_ACTUALSIZE
- MENUITEM "Fit &Page\tCtrl+2", ID_VIEW_FITPAGE
- MENUITEM "Fit &Width\tCtrl+3", ID_VIEW_FITWIDTH
- MENUITEM SEPARATOR
- POPUP "&Rotate View"
- BEGIN
- MENUITEM "&Clockwise\tShift+Ctrl+Plus", ID_VIEW_CLOCKWISE, HELP
- MENUITEM "Counterclock&wise\tShift+Ctrl+Minus",
- ID_VIEW_COUNTERCLOCKWISE
- END
- MENUITEM SEPARATOR
- MENUITEM "&ToolBar", ID_VIEW_TOOLBAR
- MENUITEM "&StatusBar", ID_VIEW_STATUS_BAR
- END
- POPUP "&Document"
- BEGIN
- MENUITEM "&First Page \t\tHome", ID_DOC_FIRSTPAGE
- MENUITEM "P&revious Page\tLeft Arrow", ID_DOC_PREPAGE
- MENUITEM "&Next Page\tRight Arrow", ID_DOC_NEXTPAGE
- MENUITEM "&Last Page\tEnd", ID_DOC_LASTPAGE
- MENUITEM SEPARATOR
- MENUITEM "&Goto Page...\tShift+Ctrl+N", ID_DOC_GOTOPAGE
- MENUITEM "Print MetalFile", TEST_PRINT_METALFILE
- END
- POPUP "&Tool"
- BEGIN
- MENUITEM "&Hand Tool", ID_TOOL_HAND
- MENUITEM "Se&lect Text", ID_TOOL_SELECT
- MENUITEM "&Snapshot", ID_TOOL_SNAPSHOT
- MENUITEM "Pdf2txt", ID_TOOL_PDF2TXT
- MENUITEM "Extract links", ID_TOOL_EXTRACTLINKS
- END
- POPUP "&Bitmap"
- BEGIN
- MENUITEM "&Export PDF to bitmap", ID_EXPORT_PDF_TO_BITMAP
- END
- POPUP "&Help"
- BEGIN
- MENUITEM "About ReaderVC(&A)...", ID_APP_ABOUT
- END
-END
-
-#endif // English (U.S.) resources
-/////////////////////////////////////////////////////////////////////////////
-
-
-
-#ifndef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 3 resource.
-//
-#define _AFX_NO_SPLITTER_RESOURCES
-#define _AFX_NO_OLE_RESOURCES
-#define _AFX_NO_TRACKER_RESOURCES
-#define _AFX_NO_PROPERTY_RESOURCES
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
-#ifdef _WIN32
-LANGUAGE 4, 2
-#pragma code_page(936)
-#endif //_WIN32
-#include "res\ReaderVC.rc2" // non-Microsoft Visual C++ edited resources
-#include "l.chs\afxres.rc" // Standard components
-#include "l.chs\afxprint.rc" // printing/print preview resources
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-#endif // not APSTUDIO_INVOKED
-
diff --git a/xfa_test/FormFiller_Test/ReaderVCDoc.cpp b/xfa_test/FormFiller_Test/ReaderVCDoc.cpp
deleted file mode 100644
index e06515d67e..0000000000
--- a/xfa_test/FormFiller_Test/ReaderVCDoc.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-// ReaderVCDoc.cpp : implementation of the CReaderVCDoc class
-//
-
-#include "stdafx.h"
-#include "ReaderVC.h"
-
-#include "MainFrm.h"
-#include "ChildFrm.h"
-#include "ReaderVCDoc.h"
-#include "ReaderVCView.h"
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-// CReaderVCDoc
-
-IMPLEMENT_DYNCREATE(CReaderVCDoc, CDocument)
-
-BEGIN_MESSAGE_MAP(CReaderVCDoc, CDocument)
- //{{AFX_MSG_MAP(CReaderVCDoc)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
-END_MESSAGE_MAP()
-
-/////////////////////////////////////////////////////////////////////////////
-// CReaderVCDoc construction/destruction
-
-CReaderVCDoc::CReaderVCDoc()
-{
- // TODO: add one-time construction code here
-
-}
-
-CReaderVCDoc::~CReaderVCDoc()
-{
-}
-
-BOOL CReaderVCDoc::OnNewDocument()
-{
- if (!CDocument::OnNewDocument())
- return FALSE;
-
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
-
- return TRUE;
-}
-
-
-
-/////////////////////////////////////////////////////////////////////////////
-// CReaderVCDoc serialization
-
-void CReaderVCDoc::Serialize(CArchive& ar)
-{
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- }
- else
- {
- // TODO: add loading code here
- }
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// CReaderVCDoc diagnostics
-
-#ifdef _DEBUG
-void CReaderVCDoc::AssertValid() const
-{
- CDocument::AssertValid();
-}
-
-void CReaderVCDoc::Dump(CDumpContext& dc) const
-{
- CDocument::Dump(dc);
-}
-#endif //_DEBUG
-
-/////////////////////////////////////////////////////////////////////////////
-// CReaderVCDoc commands
-
-BOOL CReaderVCDoc::OnOpenDocument(LPCTSTR lpszPathName)
-{
- if (!CDocument::OnOpenDocument(lpszPathName))
- return FALSE;
-
- // TODO: Add your specialized creation code here
- void* pDoc = FPDF_LoadDocument(lpszPathName, NULL);
-
- m_strPDFName=lpszPathName;
- if(NULL == pDoc) return FALSE;
- POSITION pos = GetFirstViewPosition();
- int nCount = FPDF_GetPageCount(pDoc);
- while (pos != NULL)
- {
- CView* pView = GetNextView(pos);
- if(pView->IsKindOf(RUNTIME_CLASS(CReaderVCView)))
- {
- CMainFrame* pMFrm = (CMainFrame*)AfxGetMainWnd();
- CChildFrame* pChildFrm =(CChildFrame*) pMFrm->GetActiveFrame();
- pChildFrm->SetActiveView(pView, TRUE);
-// FPDFApp_SetDocument(((CReaderVCView*)pView)->GetFPDFApp(), (FPDF_DOCUMENT)pDoc);
- ((CReaderVCView*)pView)->SetPDFDocument(pDoc, nCount);
- }
- }
- return TRUE;
-}
diff --git a/xfa_test/FormFiller_Test/ReaderVCDoc.h b/xfa_test/FormFiller_Test/ReaderVCDoc.h
deleted file mode 100644
index 5bfc7e17f8..0000000000
--- a/xfa_test/FormFiller_Test/ReaderVCDoc.h
+++ /dev/null
@@ -1,59 +0,0 @@
- // ReaderVCDoc.h : interface of the CReaderVCDoc class
-//
-/////////////////////////////////////////////////////////////////////////////
-
-#if !defined(AFX_READERVCDOC_H__6E0B9799_0661_4DB3_9E40_FB2D17F0D5EB__INCLUDED_)
-#define AFX_READERVCDOC_H__6E0B9799_0661_4DB3_9E40_FB2D17F0D5EB__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-
-
-class CReaderVCDoc : public CDocument
-{
-protected: // create from serialization only
- CReaderVCDoc();
- DECLARE_DYNCREATE(CReaderVCDoc)
-
-// Attributes
-public:
-
-// Operations
-public:
-
-// Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CReaderVCDoc)
- public:
- virtual BOOL OnNewDocument();
- virtual void Serialize(CArchive& ar);
- virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
- //}}AFX_VIRTUAL
-
-// Implementation
-public:
- CString m_strPDFName;
- virtual ~CReaderVCDoc();
-#ifdef _DEBUG
- virtual void AssertValid() const;
- virtual void Dump(CDumpContext& dc) const;
-#endif
-
-protected:
-
-// Generated message map functions
-protected:
- //{{AFX_MSG(CReaderVCDoc)
- // NOTE - the ClassWizard will add and remove member functions here.
- // DO NOT EDIT what you see in these blocks of generated code !
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
-};
-
-/////////////////////////////////////////////////////////////////////////////
-
-//{{AFX_INSERT_LOCATION}}
-// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
-
-#endif // !defined(AFX_READERVCDOC_H__6E0B9799_0661_4DB3_9E40_FB2D17F0D5EB__INCLUDED_)
diff --git a/xfa_test/FormFiller_Test/ReaderVCView.cpp b/xfa_test/FormFiller_Test/ReaderVCView.cpp
deleted file mode 100644
index ef0b58bfbb..0000000000
--- a/xfa_test/FormFiller_Test/ReaderVCView.cpp
+++ /dev/null
@@ -1,3750 +0,0 @@
-// ReaderVCView.cpp : implementation of the CReaderVCView class
-//
-
-#include "stdafx.h"
-#include "ReaderVC.h"
-#include "MainFrm.h"
-#include "ChildFrm.h"
-#include "ReaderVCDoc.h"
-#include "ReaderVCView.h"
-
-#include "GotoPageDlg.h"
-#include "ZoomDlg.h"
-#include "FindDlg.h"
-#include "ConvertDlg.h"
-#include "JS_ResponseDlg.h"
-#include "TestJsDlg.h"
-//#include "../../include/pp_event.h"
-
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-// CReaderVCView
-
-IMPLEMENT_DYNCREATE(CReaderVCView, CView)
-
-BEGIN_MESSAGE_MAP(CReaderVCView, CView)
- //{{AFX_MSG_MAP(CReaderVCView)
- ON_COMMAND(ID_DOC_FIRSTPAGE, OnDocFirstpage)
- ON_COMMAND(ID_DOC_GOTOPAGE, OnDocGotopage)
- ON_COMMAND(ID_DOC_LASTPAGE, OnDocLastpage)
- ON_COMMAND(ID_DOC_NEXTPAGE, OnDocNextpage)
- ON_COMMAND(ID_DOC_PREPAGE, OnDocPrepage)
- ON_COMMAND(ID_VIEW_CLOCKWISE, OnClockwise)
- ON_COMMAND(ID_VIEW_COUNTERCLOCKWISE, OnCounterclockwise)
- ON_COMMAND(ID_VIEW_ACTUALSIZE, OnViewActualSize)
- ON_COMMAND(ID_VIEW_FITPAGE, OnViewFitPage)
- ON_COMMAND(ID_VIEW_FITWIDTH, OnViewFitWidth)
- ON_COMMAND(ID_VIEW_ZOOMIN, OnViewZoomIn)
- ON_COMMAND(ID_VIEW_ZOOMOUT, OnViewZoomOut)
- ON_COMMAND(ID_VIEW_ZOOMTO, OnViewZoomTo)
- ON_COMMAND(ID_EDIT_FIND, OnEditFind)
- ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEMOVE()
- ON_WM_KEYDOWN()
- ON_COMMAND(ID_TOOL_SNAPSHOT, OnToolSnapshot)
- ON_COMMAND(ID_TOOL_SELECT, OnToolSelect)
- ON_COMMAND(ID_TOOL_HAND, OnToolHand)
- ON_COMMAND(ID_TOOL_PDF2TXT, OnToolPdf2txt)
- ON_WM_SIZE()
- ON_WM_HSCROLL()
- ON_WM_VSCROLL()
- ON_COMMAND(ID_TOOL_EXTRACTLINKS, OnToolExtractlinks)
- ON_WM_DESTROY()
- ON_UPDATE_COMMAND_UI(ID_DOC_FIRSTPAGE, OnUpdateDocFirstpage)
- ON_UPDATE_COMMAND_UI(ID_DOC_LASTPAGE, OnUpdateDocLastpage)
- ON_UPDATE_COMMAND_UI(ID_DOC_NEXTPAGE, OnUpdateDocNextpage)
- ON_UPDATE_COMMAND_UI(ID_DOC_PREPAGE, OnUpdateDocPrepage)
- ON_UPDATE_COMMAND_UI(ID_TOOL_HAND, OnUpdateToolHand)
- ON_UPDATE_COMMAND_UI(ID_TOOL_SNAPSHOT, OnUpdateToolSnapshot)
- ON_UPDATE_COMMAND_UI(ID_TOOL_SELECT, OnUpdateToolSelect)
- ON_COMMAND(ID_VIEW_BOOKMARK, OnViewBookmark)
- ON_WM_MOUSEWHEEL()
- ON_WM_CONTEXTMENU()
- ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
- ON_COMMAND(ID_RENDERBITMAP, OnRenderbitmap)
- ON_COMMAND(ID_EXPORT_PDF_TO_BITMAP, OnExportPdfToBitmap)
- ON_WM_CHAR()
- ON_WM_KEYUP()
- ON_COMMAND(ID_FILE_SAVE, OnFileSave)
- ON_COMMAND(IDM_Test_JS, OnTestJS)
- ON_COMMAND(TEST_PRINT_METALFILE, OnPrintMetalfile)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
-END_MESSAGE_MAP()
-
-/////////////////////////////////////////////////////////////////////////////
-// CReaderVCView construction/destruction
-void Sample_PageToDevice(struct _FPDF_FORMFILLINFO* pThis,FPDF_PAGE page,double page_x,double page_y, int* device_x, int* device_y)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- pView->PageToDeviceImpl(page, page_x, page_y, device_x, device_y);
- }
- //((CReaderVCView*)pThis)->PageToDeviceImpl(page, page_x, page_y, device_x, device_y);
-}
-
-void Sample_Invalidate(struct _FPDF_FORMFILLINFO* pThis,FPDF_PAGE page, double left, double top, double right, double bottom)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- pView->InvalidateImpl(page,left, top, right, bottom);
- }
- //((CReaderVCView*)pThis)->InvalidateImpl(page,left, top, right, bottom);
-}
-
-void Sample_OutputSelectedRect(struct _FPDF_FORMFILLINFO* pThis,FPDF_PAGE page, double left, double top, double right, double bottom)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- pView->OutputSelectedRectImpl(page,left, top, right, bottom);
- }
-}
-
-void Sample_DeviceToPage(struct _FPDF_FORMFILLINFO* pThis,FPDF_PAGE page,int device_x, int device_y, double* page_x, double* page_y)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- pView->DeviceToPageImpl(page, device_x, device_y, page_x, page_y);
- }
- //((CReaderVCView*)pThis)->DeviceToPageImpl(page, device_x, device_y, page_x, page_y);
-}
-/* /* Remove by Amy Lin 20100913, Since we don't this the FFI_SetCaret any more.
-void Sample_SetCaret(struct _FPDF_FORMFILLINFO* pThis,FPDF_PAGE page,double page_x, double page_y, int nWidth, int nHeight)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- pView->SetCaretImpl(page, page_x, page_y, nWidth, nHeight);
- }
- //((CReaderVCView*)pThis)->SetCaretImpl(page, page_x, page_y, nWidth, nHeight);
-}
-*/
-void Sample_Release(struct _FPDF_FORMFILLINFO* pThis)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- pView->ReleaseImpl();
- }
- //((CReaderVCView*)pThis)->ReleaseImpl();
-}
-
-
-int Sample_SetTimer(struct _FPDF_FORMFILLINFO* pThis, int uElapse, TimerCallback lpTimerFunc)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- return pView->SetTimerImpl(uElapse, lpTimerFunc);
- }else{
- return -1;
- }
- //return ((CReaderVCView*)pThis)->SetTimerImpl(uElapse, lpTimerFunc);
-}
-
-void Sample_KillTimer(struct _FPDF_FORMFILLINFO* pThis,int nID)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- pView->KillTimerImpl(nID);
- }
- //((CReaderVCView*)pThis)->KillTimerImpl(nID);
-}
-
-void Sample_SetCursor(struct _FPDF_FORMFILLINFO* pThis,int nCursorType)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- pView->SetCurorImpl(nCursorType);
- }
- //((CReaderVCView*)pThis)->SetCurorImpl(nCursorType);
-}
-
-void Sample_OnChange(struct _FPDF_FORMFILLINFO* pThis)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- pView->OnChangeImpl();
- }
-}
-FPDF_BOOL Sample_IsSHIFTKeyDown(struct _FPDF_FORMFILLINFO* pThis)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- return pView->IsSHIFTKeyDownImpl();
- }
- return FALSE;
-}
-FPDF_BOOL Sample_IsCTRLKeyDown(struct _FPDF_FORMFILLINFO* pThis)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- return pView->IsCTRLKeyDownImpl();
- }
- return FALSE;
-}
-FPDF_BOOL Sample_IsALTKeyDown(struct _FPDF_FORMFILLINFO* pThis)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- return pView->IsALTKeyDownImpl();
- }
- return FALSE;
-}
-FPDF_BOOL Sample_IsINSERTKeyDown(struct _FPDF_FORMFILLINFO* pThis)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- return pView->IsINSERTKeyDownImpl();
- }
- return FALSE;
-}
-
-FPDF_PAGE Sample_GetPage(struct _FPDF_FORMFILLINFO* pThis,FPDF_DOCUMENT document, int nPageIndex)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- return pView->GetPageImpl(document,nPageIndex);
- }
- return NULL;
-}
-
-FPDF_PAGE Sample_GetCurrentPage(struct _FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- return pView->GetCurrentPageImpl(document);
- }
- return NULL;
-}
-
-int Sample_GetRotation(struct _FPDF_FORMFILLINFO* pThis, FPDF_PAGE page)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- return pView->GetRotationImpl(page);
- }
- return NULL;
-}
-FPDF_SYSTEMTIME Sample_GetLocalTime(struct _FPDF_FORMFILLINFO* pThis)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- return pView->GetLocalTimeImpl();
- }
- return FPDF_SYSTEMTIME();
-}
-
-void SampleRelease(struct _FPDF_SYSFONTINFO* pThis)
-{
- ((CSampleFontInfo*)pThis)->ReleaseImpl();
-}
-
-void SampleEnumFonts(struct _FPDF_SYSFONTINFO* pThis, void* pMapper)
-{
- ((CSampleFontInfo*)pThis)->EnumFontsImpl(pMapper);
-}
-
-void* SampleMapFont(struct _FPDF_SYSFONTINFO* pThis, int weight, int bItalic, int charset, int pitch_family,
- const char* face, int* bExact)
-{
- return ((CSampleFontInfo*)pThis)->MapFontImpl(weight, bItalic, charset, pitch_family, face, bExact);
-}
-
-unsigned long SampleGetFontData(struct _FPDF_SYSFONTINFO* pThis, void* hFont,
- unsigned int table, unsigned char* buffer, unsigned long buf_size)
-{
- return ((CSampleFontInfo*)pThis)->GetFontDataImpl(hFont, table, buffer, buf_size);
-}
-
-unsigned long SampleGetFaceName(struct _FPDF_SYSFONTINFO* pThis, void* hFont, char* buffer, unsigned long buf_size)
-{
- return ((CSampleFontInfo*)pThis)->GetFaceNameImpl(hFont, buffer, buf_size);
-}
-
-int SampleGetFontCharset(struct _FPDF_SYSFONTINFO* pThis, void* hFont)
-{
- return ((CSampleFontInfo*)pThis)->GetFontCharsetImpl(hFont);
-}
-
-void SampleDeleteFont(struct _FPDF_SYSFONTINFO* pThis, void* hFont)
-{
- ((CSampleFontInfo*)pThis)->DeleteFontImpl(hFont);
-}
-
-void SetSampleFontInfo()
-{
- CSampleFontInfo* pFontInfo = new CSampleFontInfo;
- pFontInfo->version = 1;
- pFontInfo->DeleteFont = SampleDeleteFont;
- pFontInfo->EnumFonts = SampleEnumFonts;
- pFontInfo->GetFaceName = SampleGetFaceName;
- pFontInfo->GetFont = NULL;
- pFontInfo->GetFontCharset = SampleGetFontCharset;
- pFontInfo->GetFontData = SampleGetFontData;
- pFontInfo->MapFont = SampleMapFont;
- pFontInfo->Release = SampleRelease;
- FPDF_SetSystemFontInfo(pFontInfo);
-}
-
-void Sample_ExecuteNamedAction(struct _FPDF_FORMFILLINFO* pThis, FPDF_BYTESTRING namedAction)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if ( pView )
- {
- pView->ExecuteNamedActionImpl(namedAction);
- }
-
-}
-void CReaderVCView::ExecuteNamedActionImpl(FPDF_BYTESTRING namedaction)
-{
- if(strcmp("Print", (LPCSTR)namedaction) == 0)
- OnFilePrint();
-}
-void CReaderVCView::OutputSelectedRectImpl(FPDF_PAGE page, double left, double top, double right, double bottom)
-{
-
- if(page == m_pPage)
- {
-
- int device_left, device_top, device_right, device_bottom;
-
- int nActualRangeX = 0;
- int nActualRangeY = 0;
- if ( m_nRotateFlag % 2 == 0 )
- {
- nActualRangeX = m_nActualSizeX;
- nActualRangeY = m_nActualSizeY;
- }else{
- nActualRangeX = m_nActualSizeY;
- nActualRangeY = m_nActualSizeX;
- }
-
- FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),
- (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, left, top, &device_left, &device_top);
-
- FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),
- (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, right, bottom, &device_right, &device_bottom);
-
- CRect rc(device_left,device_top, device_right, device_bottom);
-
-
-
- m_SelectArray.Add(rc);
-
-
- }
-}
-
-void Sample_Release(FPDF_LPVOID clientData)
-{
- if (!clientData) return;
-
- fclose(((FPDF_FILE*)clientData)->file);
- delete ((FPDF_FILE*)clientData);
-}
-
-FPDF_DWORD Sample_GetSize(FPDF_LPVOID clientData)
-{
- if (!clientData) return 0;
-
- long curPos = ftell(((FPDF_FILE*)clientData)->file);
- fseek(((FPDF_FILE*)clientData)->file, 0, SEEK_END);
- long size = ftell(((FPDF_FILE*)clientData)->file);
- fseek(((FPDF_FILE*)clientData)->file, curPos, SEEK_SET);
-
- return (FPDF_DWORD)size;
-}
-
-FPDF_RESULT Sample_ReadBlock(FPDF_LPVOID clientData, FPDF_DWORD offset, FPDF_LPVOID buffer, FPDF_DWORD size)
-{
- if (!clientData) return -1;
-
- fseek(((FPDF_FILE*)clientData)->file, (long)offset, SEEK_SET);
- size_t readSize = fread(buffer, 1, size, ((FPDF_FILE*)clientData)->file);
- return readSize == size ? 0 : -1;
-}
-
-FPDF_RESULT Sample_WriteBlock(FPDF_LPVOID clientData, FPDF_DWORD offset, FPDF_LPCVOID buffer, FPDF_DWORD size)
-{
- if (!clientData) return -1;
-
- fseek(((FPDF_FILE*)clientData)->file, (long)offset, SEEK_SET);
- //Write data
- size_t writeSize = fwrite(buffer, 1, size, ((FPDF_FILE*)clientData)->file);
- return writeSize == size ? 0 : -1;
-}
-
-FPDF_RESULT Sample_Flush(FPDF_LPVOID clientData)
-{
- if (!clientData) return -1;
-
- //Flush file
- fflush(((FPDF_FILE*)clientData)->file);
-
- return 0;
-}
-
-FPDF_RESULT Sample_Truncate(FPDF_LPVOID clientData, FPDF_DWORD size)
-{
- return 0;
-}
-
-void Sample_DisplayCaret(struct _FPDF_FORMFILLINFO* pThis, FPDF_PAGE page, FPDF_BOOL bVisible, double left, double top, double right, double bottom)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if (!pView) return;
-
- HWND hWnd = pView->m_hWnd;
-
- if (bVisible)
- {
- CPoint ltPt;
- pView->PageToDevice(left, top, ltPt);
- CPoint rbPt;
- pView->PageToDevice(right, bottom, rbPt);
- CRect rcCaret(ltPt, rbPt);
-
- ::DestroyCaret();
- ::CreateCaret(hWnd, (HBITMAP)0, rcCaret.Width(), rcCaret.Height());
- ::SetCaretPos (rcCaret.left, rcCaret.top);
- ::ShowCaret(hWnd);
- }
- else
- {
- ::DestroyCaret();
- ::HideCaret(hWnd);
- }
-}
-
-int Sample_GetCurrentPageIndex(struct _FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document)
-{
- CReaderVCView* pView =(CReaderVCView*)pThis;
- if (!pView) return -1;
-
- return pView->GetCurrentPageIndex();
-}
-
-void Sample_SetCurrentPage(struct _FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document, int iCurPage)
-{
- CReaderVCView* pView = (CReaderVCView*)pThis;
- if (!pView) return;
-
- FPDF_DOCUMENT curDoc = pView->GetPDFDoc();
- if (curDoc != document)
- return;
-
- int nPageCount = FPDF_GetPageCount(curDoc);
- if (nPageCount > iCurPage)
- {
- int nCurPageInx = pView->GetCurrentPageIndex();
- if (nCurPageInx != iCurPage)
- {
- pView->GotoPage(nCurPageInx);
- }
- }
-}
-
-void Sample_GotoURL(struct _FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document, FPDF_WIDESTRING wsURL)
-{
- CReaderVCView* pView = (CReaderVCView*)pThis;
- if (!pView) return;
-
- wchar_t* pURL = (wchar_t*)wsURL;
- MessageBoxW(NULL, pURL, NULL, MB_OK);
-}
-
-FPDF_WIDESTRING Sample_GetURL(struct _FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document)
-{
- CReaderVCView* pView = (CReaderVCView*)pThis;
- if (!pView) return NULL;
-
- if (pView->GetPDFDoc() != document)
- return NULL;
-
- //not support in this demo
-
- return NULL;
-}
-
-void Sample_AddDoRecord(struct _FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document, FPDF_WIDGET hWidget)
-{
- //not support
-}
-
-void Sample_PageEvent(struct _FPDF_FORMFILLINFO* pThis, FPDF_PAGE page, FPDF_DWORD eventFlag)
-{
- //
-}
-
-void Sample_GetPageViewRect(struct _FPDF_FORMFILLINFO* pThis, FPDF_PAGE page, double* left, double* top, double* right, double* bottom)
-{
- CReaderVCView* pView = (CReaderVCView*)pThis;
- if (!pView) return;
-
- if (pView->GetPage() != page)
- return;
-
- CRect clientRect;
- pView->GetClientRect(&clientRect);
-
- *left = (double)clientRect.left;
- *right = (double)clientRect.right;
- *top = (double)clientRect.top;
- *bottom = (double)clientRect.bottom;
-}
-
-#define WM_XFAMENU_COPY 10000
-
-FPDF_BOOL Sample_PopupMenu(struct _FPDF_FORMFILLINFO* pThis, FPDF_PAGE page, FPDF_WIDGET hWidget, int menuFlag, float x, float y)
-{
- CReaderVCView* pView = (CReaderVCView*)pThis;
- if (!pView)
- return FALSE;
-
- CMenu menu;
- menu.CreatePopupMenu();
-
- int nMenuIndex = 0;
-
- if (menuFlag & FXFA_MEMU_COPY)
- menu.InsertMenu(nMenuIndex++, MF_BYPOSITION, WM_XFAMENU_COPY, "Copy");
- //...
-
- CPoint pt;
- pView->PageToDevice(x, y, pt);
-
- UINT nID = menu.TrackPopupMenu(TPM_RIGHTBUTTON, pt.x, pt.y, pView);
- switch(nID)
- {
- case WM_XFAMENU_COPY:
- {
- FPDF_DWORD length = 0;
- FPDF_Widget_Copy(pView->GetPDFDoc(), hWidget, NULL, &length);
- if (length > 0)
- {
- unsigned short* buffer = (unsigned short*)malloc((length+1)*sizeof(unsigned short));
- memset(buffer, 0, (length+1)*sizeof(unsigned short));
- FPDF_Widget_Copy(pView->GetPDFDoc(), hWidget, buffer, &length);
- free(buffer);
- }
- }
- break;
- }
-
- menu.DestroyMenu();
-
- return TRUE;
-}
-
-FPDF_FILEHANDLER* Sample_OpenFile(struct _FPDF_FORMFILLINFO* pThis, int fileFlag, FPDF_WIDESTRING wsURL)
-{
- char* pszURL;
- CString strURL;
- if (wsURL == NULL) {
- if (fileFlag == FXFA_FILE_XDP)
- strURL = "C://temp.xdp";
- else if(fileFlag == FXFA_FILE_XML)
- strURL = "C://temp.xml";
- }
- else {
- int iSize;
- iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsURL, -1, NULL, 0, NULL, NULL);
- pszURL = (char*)malloc((iSize+1));
- WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsURL, -1, pszURL, iSize, NULL, NULL);
- CString str(pszURL);
- strURL = str;
- }
-
-
- FILE* file = fopen(strURL, "r");
- FPDF_FILE* pFileHander = new FPDF_FILE;
- pFileHander->file = file;
- pFileHander->fileHandler.clientData = pFileHander;
- pFileHander->fileHandler.Flush = Sample_Flush;
- pFileHander->fileHandler.GetSize = Sample_GetSize;
- pFileHander->fileHandler.ReadBlock = Sample_ReadBlock;
- pFileHander->fileHandler.Release = Sample_Release;
- pFileHander->fileHandler.Truncate = Sample_Truncate;
- pFileHander->fileHandler.WriteBlock = Sample_WriteBlock;
-
- free(pszURL);
- return &pFileHander->fileHandler;
-}
-
-FPDF_BOOL Sample_GetFilePath(struct _FPDF_FORMFILLINFO* pThis, FPDF_FILEHANDLER* pFileHandler, FPDF_BSTR* path)
-{
- CReaderVCView* pView = (CReaderVCView*)pThis;
- if (!pView)
- return NULL;
-
- CString filePath = pView->GetFilePath();
- FPDF_BStr_Set(path, filePath.GetBuffer(filePath.GetLength()), filePath.GetLength());
-
- return TRUE;
-}
-
-void Sample_EmailTo(struct _FPDF_FORMFILLINFO* pThis, FPDF_FILEHANDLER* fileHandler, FPDF_WIDESTRING emailTo)
-{
- MessageBoxW(NULL, (wchar_t*)emailTo, L"Sample_email", MB_OK);
-}
-
-void Sample_UploadTo(struct _FPDF_FORMFILLINFO* pThis, FPDF_FILEHANDLER* fileHandler, FPDF_WIDESTRING uploadTo)
-{
- int iSize;
- char* pszURL;
- iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)uploadTo, -1, NULL, 0, NULL, NULL);
- pszURL = (char*)malloc((iSize+1));
- WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)uploadTo, -1, pszURL, iSize, NULL, NULL);
- CString strPath(pszURL);
-
- CString strUploadPath = "C://test";
- int pos = strPath.ReverseFind('.');
- if (pos != -1){
- CString suffix = strPath.Right(strPath.GetLength()-pos);
- strUploadPath += suffix;
- }
-
- FILE* file = fopen(strUploadPath, "r");
- if (file) {
- int size = fileHandler->GetSize(fileHandler->clientData);
- BYTE* buffer = (BYTE*)malloc(size);
- fileHandler->ReadBlock(fileHandler->clientData, 0, buffer, size);
- fwrite(buffer, size, 1, file);
- fflush(file);
- fclose(file);
- free(buffer);
- }
-
- free(pszURL);
-}
-
-int Sample_GetAppName(struct _FPDF_FORMFILLINFO* pThis, void* appName, int length)
-{
- if(appName == NULL || length <= 0)
- {
- CString name = AfxGetAppName();
- return name.GetLength();
- }
- else
- {
- CString name = AfxGetAppName();
- int len = name.GetLength();
- if(length > len)
- length = len;
- memcpy(appName, name.GetBuffer(name.GetLength()), length);
- return length;
- }
-}
-
-int Sample_GetPlatform(struct _FPDF_FORMFILLINFO* pThis, void* platform, int length)
-{
- if(platform == NULL || length <= 0)
- {
- return 3;
- }
- else
- {
- if(length > 3)
- length = 3;
- memcpy(platform, "win", length);
- return length;
- }
-}
-
-int Sample_GetDocumentCount(struct _FPDF_FORMFILLINFO* pThis)
-{
- return 1;
-}
-
-int Sample_GetCurDocumentIndex(struct _FPDF_FORMFILLINFO* pThis)
-{
- return 0;
-}
-
-FPDF_LPFILEHANDLER Sample_DownloadFromURL(struct _FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING URL)
-{
- int iSize;
- char* pszURL;
- iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)URL, -1, NULL, 0, NULL, NULL);
- pszURL = (char*)malloc((iSize+1));
- WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)URL, -1, pszURL, iSize, NULL, NULL);
- CString strURL(pszURL);
-
- CString bsLocal = strURL;
- CReaderVCView::CreateLocalPath(bsLocal);
-
- if (strURL.Left(7) == "http://")
- {
- CInternetSession sess;
- CHttpFile *pFile = (CHttpFile*)sess.OpenURL(strURL);
- int iLength = pFile->GetLength();
- if (pFile == NULL || iLength < 1) return NULL;
-
- FILE *pImageFile = fopen(bsLocal, "wb");
-
- BYTE* pContent = new BYTE[iLength];
- memset(pContent, 0, iLength);
- int iRead = pFile->Read(pContent, iLength);
-
- fwrite(pContent, 1, iLength, pImageFile);
- free(pContent);
- fflush(pImageFile);
- fclose(pImageFile);
-
- pFile->Close();
- delete pFile;
- sess.Close();
- }
- else if (strURL.Left(6) == "ftp://")
- {
- CInternetSession sess;
- CFtpConnection* pConnect = sess.GetFtpConnection(bsLocal, "NULL", "NULL");
- CInternetFile* pFile = pConnect->OpenFile(bsLocal);
-
- int iLength = pFile->GetLength();
- if (pFile == NULL || iLength < 1) return NULL;
- FILE *pImageFile = fopen(bsLocal, "wb");
-
- BYTE* pContent = new BYTE[iLength];
- memset(pContent, 0, iLength);
- int iRead = pFile->Read(pContent, iLength);
-
- fwrite(pContent, 1, iLength, pImageFile);
- free(pContent);
- fflush(pImageFile);
- fclose(pImageFile);
-
- pFile->Close();
- delete pFile;
- sess.Close();
- }
-
- free(pszURL);
-
- FPDF_FILE* fileWrap = new FPDF_FILE;
- FILE* file = fopen(bsLocal, "r");
- fileWrap->file = file;
- fileWrap->fileHandler.clientData = fileWrap;
- fileWrap->fileHandler.ReadBlock = Sample_ReadBlock;
- fileWrap->fileHandler.GetSize = Sample_GetSize;
- fileWrap->fileHandler.Flush = Sample_Flush;
- fileWrap->fileHandler.Release = Sample_Release;
- fileWrap->fileHandler.Truncate = Sample_Truncate;
- fileWrap->fileHandler.WriteBlock = Sample_WriteBlock;
-
- return &fileWrap->fileHandler;
-}
-
-FPDF_BOOL Sample_PostRequestURL(struct _FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING wsURL, FPDF_WIDESTRING wsData, FPDF_WIDESTRING wsContentType, FPDF_WIDESTRING wsEncode, FPDF_WIDESTRING wsHeader, FPDF_BSTR* respone)
-{
- int iSize;
- char* pszURL;
- iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsURL, -1, NULL, 0, NULL, NULL);
- pszURL = (char*)malloc((iSize+1));
- WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsURL, -1, pszURL, iSize, NULL, NULL);
- CString csURL(pszURL);
-
- char* pszData;
- iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsData, -1, NULL, 0, NULL, NULL);
- pszData = (char*)malloc(iSize+1);
- WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsData, -1, pszData, iSize, NULL, NULL);
- CString csData(pszData);
-
- char* pszContentType;
- iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsContentType, -1, NULL, 0, NULL, NULL);
- pszContentType = (char*)malloc(iSize+1);
- WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsContentType, -1, pszContentType, iSize, NULL, NULL);
- CString csContentType(pszContentType);
-
- char* pszHeader;
- iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsHeader, -1, NULL, 0, NULL, NULL);
- pszHeader = (char*)malloc(iSize+1);
- WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsHeader, -1, pszHeader, iSize, NULL, NULL);
- CString csHeader(pszHeader);
-
- CString csApp = AfxGetAppName();
- csApp += L"/1.0";
- BOOL bRet = FALSE;
- DWORD dwServiceType = 0, dwFlags = ICU_NO_META;
- CString csServer, sObject, csUserName, csPassword;
- INTERNET_PORT nPort = 0;
-
- bRet = AfxParseURLEx(csURL, dwServiceType, csServer, sObject, nPort, csUserName, csPassword, dwFlags);
- if (!bRet)
- return bRet;
-
- if (dwServiceType != AFX_INET_SERVICE_HTTP && dwServiceType != AFX_INET_SERVICE_HTTPS)
- return bRet;
-
- CString csObject = sObject;
- CString csResponse;
- bRet = CReaderVCView::HttpDataPost(csData, csApp, csObject, csServer, csUserName, csPassword, nPort,
- dwServiceType == AFX_INET_SERVICE_HTTPS, csContentType, csHeader, csResponse);
-
- FPDF_BStr_Init(respone);
- FPDF_BStr_Set(respone, (FPDF_LPCSTR)csResponse.GetBuffer(csResponse.GetLength()), csResponse.GetLength());
-
- free(pszURL);
- free(pszData);
- free(pszContentType);
- free(pszHeader);
-
- return true;
-}
-
-FPDF_BOOL Sample_PutRequestURL(struct _FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING wsURL, FPDF_WIDESTRING wsData, FPDF_WIDESTRING wsEncode)
-{
- int iSize;
- char* pszURL;
- iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsURL, -1, NULL, 0, NULL, NULL);
- pszURL = (char*)malloc((iSize+1));
- WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsURL, -1, pszURL, iSize, NULL, NULL);
- CString csURL(pszURL);
-
- char* pszData;
- iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsData, -1, NULL, 0, NULL, NULL);
- pszData = (char*)malloc((iSize+1));
- WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsData, -1, pszData, iSize, NULL, NULL);
- CString csData(pszData);
-
- CString csApp = AfxGetAppName();
- csApp += L"/1.0";
- BOOL bRet = FALSE;
- DWORD dwServiceType = 0, dwFlags = ICU_NO_META;
- CString csServer, sObject, csUserName, csPassword;
- INTERNET_PORT nPort = 0;
-
- bRet = AfxParseURLEx(csURL, dwServiceType, csServer, sObject, nPort, csUserName, csPassword, dwFlags);
- if (!bRet)
- return bRet;
-
- if (dwServiceType != AFX_INET_SERVICE_HTTP && dwServiceType != AFX_INET_SERVICE_HTTPS)
- return bRet;
-
- CString csObject = sObject;
-
- bRet = CReaderVCView::HttpDataPut(csData, csApp, csObject, csServer, csUserName, csPassword, nPort, dwServiceType == AFX_INET_SERVICE_HTTPS);
-
- free(pszData);
- free(pszURL);
- return TRUE;
-}
-
-FPDF_BOOL Sample_ShowFileDialog(struct _FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING wsTitle, FPDF_WIDESTRING wsFilter, FPDF_BOOL isOpen, FPDF_STRINGHANDLE pathArr)
-{
- int iSize;
- char* pszFilter;
- iSize = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsFilter, -1, NULL, 0, NULL, NULL);
- pszFilter = (char*)malloc((iSize+1));
- WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wsFilter, -1, pszFilter, iSize, NULL, NULL);
-
- CFileDialog fileOpen(isOpen, NULL,NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST, pszFilter);
- // fileOpen.m_ofn.Flags|=OFN_ENABLEHOOK|OFN_ALLOWMULTISELECT;
- if(fileOpen.DoModal()==IDCANCEL)
- {
- return FALSE;
- }
-
- POSITION pos;
- pos=fileOpen.GetStartPosition();
- CString csFile;
- while(pos!=NULL)
- {
- csFile=fileOpen.GetNextPathName(pos);
- FPDF_StringHandleAddString(pathArr, csFile.GetBuffer(csFile.GetLength()), csFile.GetLength());
- }
-
- free(pszFilter);
- return TRUE;
-}
-
-FPDF_SYSTEMTIME CReaderVCView::GetLocalTimeImpl()
-{
- FPDF_SYSTEMTIME sys;
- time_t curTime;
- time(&curTime);
- tm* pTm = localtime(&curTime);
- if(pTm)
- {
- sys.wDay = pTm->tm_mday;
- sys.wDayOfWeek= pTm->tm_wday;
- sys.wHour = pTm->tm_hour;
- sys.wMilliseconds = 0;
- sys.wMinute = pTm->tm_min;
- sys.wMonth = pTm->tm_mon;
- sys.wSecond = pTm->tm_sec;
- sys.wYear = pTm->tm_year + 1900;
- }
-
- return sys;
-}
-
-int CReaderVCView::GetRotationImpl(FPDF_PAGE page)
-{
- return m_nRotateFlag;
-}
-
-FPDF_PAGE CReaderVCView::GetPageImpl(FPDF_DOCUMENT document,int nPageIndex)
-{
- FPDF_PAGE page = NULL;
- m_pageMap.Lookup(nPageIndex, page);
- if(page)
- return page;
- page = FPDF_LoadPage(document, nPageIndex);
- FORM_OnAfterLoadPage(page, m_pApp);
- m_pageMap.SetAt(nPageIndex, page);
- return page;
-}
-
-FPDF_PAGE CReaderVCView::GetCurrentPageImpl(FPDF_DOCUMENT document)
-{
- return m_pPage;
-}
-
-bool CReaderVCView::IsALTKeyDownImpl()
-{
- return GetKeyState(VK_MENU) < 0;
-}
-bool CReaderVCView::IsINSERTKeyDownImpl()
-{
- return GetKeyState(VK_INSERT) & 0x01;
-}
-bool CReaderVCView::IsSHIFTKeyDownImpl()
-{
- return !((GetKeyState(VK_SHIFT)&0x8000) == 0);
-}
-bool CReaderVCView::IsCTRLKeyDownImpl()
-{
- return GetKeyState(VK_CONTROL) < 0;
-}
-
-void CReaderVCView::OnChangeImpl()
-{
-
-}
-
-CString CReaderVCView::GetFilePath()
-{
- CReaderVCDoc* pDoc = GetDocument();
- if(pDoc)
- {
- return pDoc->m_strPDFName;
- }
- return "";
-}
-
-BOOL CReaderVCView::SubmitFormImpl(void* pBuffer, int nLength, CString strURL)
-{
- CString tempFDFFile = "D://1.fdf";
-
- if (pBuffer == NULL || nLength <= 0)
- {
- return FALSE;
- }
-
- CFile file;
- if (file.Open(tempFDFFile, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary))
- {
- file.Write(pBuffer, nLength);
- file.Close();
- }
-
- return TRUE;
-}
-
-int Sample_appResponse(struct _IPDF_JsPlatform* pThis, FPDF_WIDESTRING Question, FPDF_WIDESTRING Title,
- FPDF_WIDESTRING Default, FPDF_WIDESTRING cLabel, FPDF_BOOL bPassword, void* response, int length)
-{
- CReaderVCView* pView = (CReaderVCView*)pThis->m_pFormfillinfo;
- FPDF_WIDESTRING wsResponse;
-
- if (pView->m_pwsResponse && response != NULL)
- {
- wsResponse = (FPDF_WIDESTRING)pView->m_pwsResponse;
- length = wcslen((const wchar_t*)wsResponse);
- memcpy(response, wsResponse, length*sizeof(wchar_t));
- pView->m_pwsResponse = NULL;
- }
- else
- {
- CJS_ResponseDlg dlg;
- dlg.SetTitle(Title);
- dlg.SetDefault(Default);
- dlg.SetLabel(cLabel);
- dlg.SetQuestion(Question);
- dlg.SetIsVisible(bPassword);
- int iRet = dlg.DoModal();
-
- if (iRet == 1)
- {
- wsResponse = dlg.GetResponse();
- length = wcslen((const wchar_t*)wsResponse);
- pView->m_pwsResponse = new wchar_t[length+1];
- memset(pView->m_pwsResponse, 0, length*sizeof(wchar_t));
- memcpy(pView->m_pwsResponse, wsResponse, length*sizeof(wchar_t));
- pView->m_pwsResponse[length] = L'\0';
- }
- }
-
- return length*sizeof(wchar_t);
-}
-
-int Sample_appalert(struct _IPDF_JsPlatform* pThis, FPDF_WIDESTRING Msg, FPDF_WIDESTRING Title, int Type, int Icon)
-{
- int nRet = 0;
- if(pThis && pThis->m_pFormfillinfo)
- {
- CReaderVCView* pView = (CReaderVCView*)pThis->m_pFormfillinfo;
- int msgType = MB_OK;
- switch(Type)
- {
-
- case 1:
- msgType = MB_OKCANCEL;
- break;
- case 2:
- msgType = MB_YESNO;
- break;
- case 3:
- msgType = MB_YESNOCANCEL;
- break;
- case 0:
- default:
- break;
- }
- nRet = MessageBoxW(pView->m_hWnd, (const wchar_t*)Msg, (const wchar_t*)Title, msgType);
- switch(nRet)
- {
- case IDOK:
- return 1;
- case IDCANCEL:
- return 2;
- case IDNO:
- return 3;
- case IDYES:
- return 4;
- }
- return nRet;
- }
- return nRet;
-}
-
-void Sample_appbeep(struct _IPDF_JsPlatform* pThis, int nType)
-{
- MessageBeep(nType);
- //AfxMessageBox("aaaa");
-}
-
-
-CString userSelFilePath;
-int Sample_fieldBrowse(struct _IPDF_JsPlatform* pThis,void* filePath, int length)
-{
- if(userSelFilePath.IsEmpty())
- {
- CFileDialog fd(FALSE, "fdf");
- if(fd.DoModal() == IDOK)
- {
- userSelFilePath = fd.GetPathName();
-
- if(filePath == NULL || length == 0)
- return userSelFilePath.GetLength() + 1;
- else
- return 0;
- }
- else
- return 0;
- }
- else
- {
- int nLen = userSelFilePath.GetLength()+1;
- if(length > nLen)
- length = nLen;
- memcpy(filePath, userSelFilePath.GetBuffer(length), length);
- userSelFilePath.ReleaseBuffer();
- userSelFilePath = "";
- return length;
- }
-}
-int Sample_docGetFilePath(struct _IPDF_JsPlatform* pThis, void* filePath, int length)
-{
- if(pThis && pThis->m_pFormfillinfo)
- {
- CReaderVCView* pView = (CReaderVCView*)pThis->m_pFormfillinfo;
- CString csFilePath = pView->GetFilePath();
-
- int nbufflen = csFilePath.GetLength() + 1;
- if(filePath == NULL || length == 0)
- return nbufflen;
-
- if(length > nbufflen)
- length = nbufflen;
- memcpy(filePath, csFilePath.GetBuffer(length), length);
- csFilePath.ReleaseBuffer();
-
- return length;
-
- }
- return 0;
-}
-
-void Sample_docSubmitForm(struct _IPDF_JsPlatform* pThis,void* formData, int length, FPDF_WIDESTRING URL)
-{
- if(pThis && pThis->m_pFormfillinfo)
- {
- CReaderVCView *pView = (CReaderVCView*)pThis->m_pFormfillinfo;
- if (pView)
- {
- pView->SubmitFormImpl(formData, length, "");
- }
- }
-}
-
-void Sample_gotoPage(struct _IPDF_JsPlatform* pThis, int nPageNum)
-{
- if(pThis && pThis->m_pFormfillinfo)
- {
- CReaderVCView *pView = (CReaderVCView*)pThis->m_pFormfillinfo;
- if (pView)
- {
- pView->GotoPage(nPageNum);
- }
- }
-}
-
-CReaderVCView::CReaderVCView()
-{
- // TODO: add construction code here
- m_pFram = NULL;
- m_pExportPageDlg = NULL;
- m_pDoc = NULL;
- m_pPage = NULL;
- m_nTotalPage = 0;
- m_nRotateFlag = 0;
- m_dbScaleFactor = 1.0f;
- m_nPageIndex = -1;
- m_dbPageWidth = 0.0f;
- m_dbPageHeight = 0.0f;
- m_nStartX = 0;
- m_nStartY = 0;
- m_nActualSizeX = 0;
- m_nActualSizeY = 0;
-
- //for search text
- m_pTextPage = NULL;
- m_FindInfo.m_strFind = _T("");
- m_FindInfo.m_nFlag = -1;
- m_FindInfo.m_nDirection = -1;
- m_FindInfo.m_nStartPageIndex = -1;
- m_FindInfo.m_nStartCharIndex = -1;
- m_FindInfo.m_bFirst = TRUE;
- m_FindInfo.m_pCurFindBuf = NULL;
- m_pSCHHandle = NULL;
-
- m_rtFind = NULL;
- m_nRectNum = 0;
-
- //for select text
- m_bSelect = FALSE;
- m_bHand = TRUE;
- m_bSnap = FALSE;
- m_bHasChar = FALSE;
-
- m_ptLBDown.x = m_ptLBDown.y = 0;
- m_ptLBUp.x = m_ptLBUp.y = 0;
- m_ptOld.x = m_ptOld.y = 0;
-
- m_nStartIndex = m_nEndIndex = m_nOldIndex = -1;
- m_rtArray.RemoveAll();
- m_rtOld.left = m_rtOld.right = m_rtOld.bottom = m_rtOld.top = 0;
-
- m_nPosH = m_nPosV = -1;
-
- // for links
- m_pLink = NULL;
- m_bBookmark = FALSE;
-
- m_bmp = NULL;
- m_pwsResponse = NULL;
-
- this->FFI_Invalidate = Sample_Invalidate;
- this->Release= Sample_Release;
- this->FFI_SetTimer = Sample_SetTimer;
- this->FFI_KillTimer = Sample_KillTimer;
- this->FFI_GetLocalTime = Sample_GetLocalTime;
- this->FFI_SetCursor = Sample_SetCursor;
- this->FFI_OnChange = Sample_OnChange;
- this->FFI_GetPage = Sample_GetPage;
- this->FFI_GetCurrentPage = Sample_GetCurrentPage;
- this->FFI_GetRotation = Sample_GetRotation;
- this->FFI_OutputSelectedRect = Sample_OutputSelectedRect;
- this->FFI_ExecuteNamedAction = Sample_ExecuteNamedAction;
- this->FFI_OutputSelectedRect = NULL;
- this->FFI_SetTextFieldFocus = NULL;
- this->FFI_DoGoToAction = NULL;
- this->FFI_DoURIAction = NULL;
- this->FFI_DisplayCaret = Sample_DisplayCaret;
- this->FFI_GetCurrentPageIndex = Sample_GetCurrentPageIndex;
- this->FFI_SetCurrentPage = Sample_SetCurrentPage;
- this->FFI_GotoURL = Sample_GotoURL;
- this->FFI_GetPageViewRect = Sample_GetPageViewRect;
- this->FFI_PopupMenu = Sample_PopupMenu;
- this->FFI_OpenFile = Sample_OpenFile;
- this->FFI_GetFilePath = Sample_GetFilePath;
- this->FFI_EmailTo = Sample_EmailTo;
- this->FFI_UploadTo = Sample_UploadTo;
- this->FFI_GetPlatform = Sample_GetPlatform;
- this->FFI_GetDocumentCount = Sample_GetDocumentCount;
- this->FFI_GetCurDocumentIndex = Sample_GetCurDocumentIndex;
- this->FFI_DownloadFromURL = Sample_DownloadFromURL;
- this->FFI_PostRequestURL = Sample_PostRequestURL;
- this->FFI_PutRequestURL = Sample_PutRequestURL;
- this->FFI_ShowFileDialog = Sample_ShowFileDialog;
- this->version = 1;
-
- this->m_pJsPlatform = NULL;
- this->m_pJsPlatform = new IPDF_JSPLATFORM;
- memset(m_pJsPlatform, 0, sizeof(IPDF_JSPLATFORM));
- this->m_pJsPlatform->app_alert = Sample_appalert;
- this->m_pJsPlatform->app_response = Sample_appResponse;
- this->m_pJsPlatform->app_beep = Sample_appbeep;
- this->m_pJsPlatform->Field_browse =Sample_fieldBrowse;
- this->m_pJsPlatform->Doc_getFilePath = Sample_docGetFilePath;
- this->m_pJsPlatform->Doc_submitForm = Sample_docSubmitForm;
- this->m_pJsPlatform->Doc_gotoPage = Sample_gotoPage;
- this->m_pJsPlatform->m_pFormfillinfo = this;
-
- m_pApp = NULL;
-}
-
-
-CReaderVCView::~CReaderVCView()
-{
-
-// FPDF_DestroyApp(m_App);
-
- if(m_pTextPage != NULL)
- {
- FPDFText_ClosePage(m_pTextPage);
- m_pTextPage = NULL;
- }
- if (m_pLink != NULL)
- {
- FPDFLink_CloseWebLinks(m_pLink);
- m_pLink = NULL;
- }
-
- POSITION pos = m_pageMap.GetStartPosition();
- while(pos)
- {
- int nIndex = 0;
- FPDF_PAGE page = NULL;
- m_pageMap.GetNextAssoc(pos, nIndex, page);
-
- if (page)
- {
- FORM_OnBeforeClosePage(page, m_pApp);
- FPDF_ClosePage(page);
- }
- }
- m_pPage = NULL;
-
- if (m_pDoc != NULL)
- {
- //Should strictly follow the reverse order of initialization .
- FORM_DoDocumentAAction(m_pApp, FPDFDOC_AACTION_WC);
- if(m_pApp)
- FPDFDOC_ExitFormFillEnviroument(m_pApp);
- FPDF_CloseDocument(m_pDoc);
- m_pDoc = NULL;
- }
- if (m_FindInfo.m_pCurFindBuf != NULL)
- {
- delete []m_FindInfo.m_pCurFindBuf;
- m_FindInfo.m_pCurFindBuf = NULL;
- }
- if (m_rtFind != NULL)
- {
- delete m_rtFind;
- m_rtFind = NULL;
- }
- if(m_bmp != NULL)
- {
- FPDFBitmap_Destroy(m_bmp);
- }
-
- if (m_pwsResponse)
- {
- delete m_pwsResponse;
- m_pwsResponse = NULL;
- }
-
- if(this->m_pJsPlatform)
- delete m_pJsPlatform;
-
- m_mapTimerFuns.RemoveAll();
-// m_formFiledInfo.Release();
-// }
-// m_rtArray.RemoveAll();
-}
-
-BOOL CReaderVCView::PreCreateWindow(CREATESTRUCT& cs)
-{
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- cs.style |= WS_MAXIMIZE | WS_VISIBLE | WS_VSCROLL |WS_HSCROLL;
- return CView::PreCreateWindow(cs);
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// CReaderVCView drawing
-
-void CReaderVCView::OnDraw(CDC* pDC)
-{
- CReaderVCDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- DrawPage(m_nRotateFlag, pDC);
- DrawAllRect(pDC);
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// CReaderVCView printing
-
-BOOL CReaderVCView::OnPreparePrinting(CPrintInfo* pInfo)
-{
- // default preparation
- return DoPreparePrinting(pInfo);
-}
-
-void CReaderVCView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
-{
- // TODO: add extra initialization before printing
-}
-
-void CReaderVCView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
-{
- // TODO: add cleanup after printing
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// CReaderVCView diagnostics
-
-#ifdef _DEBUG
-void CReaderVCView::AssertValid() const
-{
- CView::AssertValid();
-}
-
-void CReaderVCView::Dump(CDumpContext& dc) const
-{
- CView::Dump(dc);
-}
-
-CReaderVCDoc* CReaderVCView::GetDocument() // non-debug version is inline
-{
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CReaderVCDoc)));
- return (CReaderVCDoc*)m_pDocument;
-}
-#endif //_DEBUG
-
-/////////////////////////////////////////////////////////////////////////////
-// CReaderVCView message handlers
-
-BOOL CReaderVCView::LoadPDFPage(FPDF_DOCUMENT doc, int nIndex, CPoint pos)
-{
- if(NULL == doc) return FALSE;
- if(nIndex < 0) nIndex = 0;
- if(nIndex > m_nTotalPage) nIndex = m_nTotalPage;
-
- FORM_DoPageAAction(m_pPage, m_pApp, FPDFPAGE_AACTION_CLOSE);
-
- m_pPage = NULL;
- m_pageMap.Lookup(nIndex, m_pPage);
- if(!m_pPage)
- {
- m_pPage = FPDF_LoadPage(doc, nIndex);
- FORM_OnAfterLoadPage(m_pPage, m_pApp);
- m_pageMap.SetAt(nIndex, m_pPage);
- }
- if(NULL == m_pPage) return FALSE;
-
- FORM_DoPageAAction(m_pPage, m_pApp, FPDFPAGE_AACTION_OPEN);
-
- m_nPageIndex = nIndex;
- SetPageMetrics(m_pPage);
-
- if (m_pTextPage != NULL)
- {
- FPDFText_ClosePage(m_pTextPage);
- m_pTextPage = NULL;
- }
- m_pTextPage = FPDFText_LoadPage(m_pPage);
-
-
- CChildFrame *pParent = (CChildFrame *)this->GetParentFrame();
- if (pParent != NULL)
- {
- pParent->SetActiveView(this);
- SyncScroll();
- }
-
- if(pos.x !=0 && pos.y != 0)
- {
- FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(m_nActualSizeX * m_dbScaleFactor),
- (int)(m_nActualSizeY * m_dbScaleFactor), m_nRotateFlag, pos.x, pos.y, &m_nStartX, &m_nStartY);
- m_nStartX = -m_nStartX + 20;
- m_nStartY = -m_nStartY + 20;
-
- int nSizeX = 0;
- int nSizeY = 0;
- if (1 == m_nRotateFlag || 3 == m_nRotateFlag)
- {
- nSizeX = m_nActualSizeY;
- nSizeY = m_nActualSizeX;
- }
- else
- {
- nSizeX = m_nActualSizeX;
- nSizeY = m_nActualSizeY;
- }
- SCROLLINFO scrinfo;
- GetScrollInfo(SB_VERT, &scrinfo);
- scrinfo.nMin = 0;
- scrinfo.nMax =(int) (nSizeY * m_dbScaleFactor + abs(m_nStartY));
- SetScrollInfo(SB_VERT, &scrinfo);
- SetScrollPos(SB_VERT, abs(m_nStartY), TRUE);
-
- GetScrollInfo(SB_HORZ, &scrinfo);
- scrinfo.nMin = 0;
- scrinfo.nMax = (int)(nSizeX * m_dbScaleFactor + abs(m_nStartX));
- SetScrollInfo(SB_HORZ, &scrinfo);
- SetScrollPos(SB_HORZ, abs(m_nStartX), TRUE);
- }
- this->Invalidate(TRUE);
-// FPDFApp_SetPage(m_App, m_pPage);
- return TRUE;
-
-}
-
-
-void CReaderVCView::InvalidateImpl(FPDF_PAGE page, double left, double top, double right, double bottom)
-{
- int device_left, device_top, device_right, device_bottom;
-
- int nActualRangeX = 0;
- int nActualRangeY = 0;
- if ( m_nRotateFlag % 2 == 0 )
- {
- nActualRangeX = m_nActualSizeX;
- nActualRangeY = m_nActualSizeY;
- }else{
- nActualRangeX = m_nActualSizeY;
- nActualRangeY = m_nActualSizeX;
- }
-
- FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),
- (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, left, top, &device_left, &device_top);
-
- FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),
- (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, right, bottom, &device_right, &device_bottom);
-
- CRect rc(device_left,device_top, device_right, device_bottom);
-// TRACE("left = %d\r\n", device_left);
-// TRACE("top = %d\r\n", device_top);
-// TRACE("right = %d\r\n", device_right);
-// TRACE("bottom = %d\r\n", device_bottom);
- if(device_right-device_left>5)
- TRACE("left=%d,top=%d,right=%d,bottom=%d\r\n",device_left,device_top,device_right,device_bottom);
- ::InvalidateRect(m_hWnd, rc, FALSE);
-}
-
-void CReaderVCView::SetCaretImpl(FPDF_PAGE page,double page_x, double page_y, int nWidth, int nHeight)
-{
-
-}
-
-void CReaderVCView::ReleaseImpl()
-{
-
-}
-CMap<int, int,TimerCallback, TimerCallback> CReaderVCView::m_mapTimerFuns;
-int CReaderVCView::SetTimerImpl(int uElapse, TimerCallback lpTimerFunc)
-{
- int nTimeID = ::SetTimer(NULL, 0, uElapse, TimerProc);
- m_mapTimerFuns.SetAt(nTimeID, lpTimerFunc);
- return nTimeID;
-}
-
-void CReaderVCView::KillTimerImpl(int nID)
-{
- ::KillTimer(NULL, nID);
- m_mapTimerFuns.RemoveKey(nID);
-}
-
-void CReaderVCView::SetCurorImpl(int nCursorType)
-{
- HCURSOR hcur = LoadCursor(NULL, IDC_UPARROW);
- switch(nCursorType)
- {
- case FXCT_ARROW:
- case FXCT_NESW:
- case FXCT_NWSE:
- case FXCT_VBEAM:
- case FXCT_HBEAM:
- case FXCT_HAND:
- // ::SetCursor(hcur);
- break;
- }
-}
-
-void CReaderVCView::PageToDeviceImpl(FPDF_PAGE page,double page_x,double page_y, int* device_x, int* device_y)
-{
- int nActualRangeX = 0;
- int nActualRangeY = 0;
- if ( m_nRotateFlag % 2 == 0 )
- {
- nActualRangeX = m_nActualSizeX;
- nActualRangeY = m_nActualSizeY;
- }else{
- nActualRangeX = m_nActualSizeY;
- nActualRangeY = m_nActualSizeX;
- }
- FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),
- (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, page_x, page_y,device_x, device_y);
-}
-
-void CReaderVCView::DeviceToPageImpl(FPDF_PAGE page,int device_x, int device_y, double* page_x, double* page_y)
-{
- int nActualRangeX = 0;
- int nActualRangeY = 0;
- if ( m_nRotateFlag % 2 == 0 )
- {
- nActualRangeX = m_nActualSizeX;
- nActualRangeY = m_nActualSizeY;
- }else{
- nActualRangeX = m_nActualSizeY;
- nActualRangeY = m_nActualSizeX;
- }
- FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),
- (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, device_x, device_y, page_x, page_y);
-
-}
-
-void CReaderVCView::SetPageMetrics(FPDF_PAGE pPage)
-{
- m_nStartX = 10;
- m_nStartY = 10;
- if(NULL==pPage) return;
- //get pdf page width an height;
- m_dbPageWidth = FPDF_GetPageWidth(pPage);
- m_dbPageHeight = FPDF_GetPageHeight(pPage);
-
- CDC *pDC = GetDC();
- int ix, iy;
- ix = pDC->GetDeviceCaps(LOGPIXELSX);
- iy = pDC->GetDeviceCaps(LOGPIXELSY);
- m_nActualSizeX = (int)(m_dbPageWidth / 72 * ix + 0.5f);//convert pdf coordinates to device
- m_nActualSizeY = (int)(m_dbPageHeight / 72 * iy + 0.5f);//convert pdf coordinates to device
- ReleaseDC(pDC);
-
-}
-
-void CReaderVCView::SetScalFactor(double dbScal)
-{
- if(dbScal > 64 ) m_dbScaleFactor = 64;
- if( dbScal < 0) m_dbScaleFactor = 0.08f;
- m_dbScaleFactor = dbScal;
-}
-void CReaderVCView::DrawPage(int nRotate, CDC *pDC)
-{
- int nSizeX = m_nActualSizeX;
- int nSizeY = m_nActualSizeY;
-
- if (1 == nRotate || 3 == nRotate)
- {
- int temp = nSizeX;
- nSizeX = nSizeY;
- nSizeY = temp;
- }
-
- int nShowSizeX = (int)(nSizeX * m_dbScaleFactor + m_nStartX);
- int nShowSizeY = (int)(nSizeY * m_dbScaleFactor + m_nStartY);
-
-
- CRect rc;
- pDC->GetClipBox(&rc);
- FPDF_BITMAP bmptemp = FPDFBitmap_Create(rc.Width(), rc.Height(), 0);
- int nClientWidth = FPDFBitmap_GetWidth(bmptemp);
- int nClientHeight = FPDFBitmap_GetHeight(bmptemp);
-
-
- FPDFBitmap_FillRect(bmptemp, 0, 0, nClientWidth, nClientHeight, 255,255,255, 0);
- FPDF_RenderPageBitmap(bmptemp, m_pPage, m_nStartX-rc.left, m_nStartY-rc.top, (int)(nSizeX * m_dbScaleFactor), (int)(nSizeY * m_dbScaleFactor), nRotate,
- FPDF_LCD_TEXT | FPDF_NO_NATIVETEXT);
- FPDF_FFLDraw(m_pApp, bmptemp, m_pPage, m_nStartX-rc.left, m_nStartY-rc.top, (int)(nSizeX * m_dbScaleFactor), (int)(nSizeY * m_dbScaleFactor), nRotate,
- FPDF_ANNOT | FPDF_LCD_TEXT | FPDF_NO_NATIVETEXT);
-
- // m_pPage2 = FPDF_LoadPage(m_pDoc, 2);
- // FPDF_RenderPageBitmap(m_bmp, m_pPage2, m_nStartX+500, m_nStartY, (int)(nSizeX * m_dbScaleFactor), (int)(nSizeY * m_dbScaleFactor), nRotate,
- // FPDF_LCD_TEXT | FPDF_NO_NATIVETEXT);
- // FPDF_FFLDraw(m_pApp, m_bmp, m_pPage2, m_nStartX+500, m_nStartY, (int)(nSizeX * m_dbScaleFactor), (int)(nSizeY * m_dbScaleFactor), nRotate,
- // FPDF_ANNOT | FPDF_LCD_TEXT | FPDF_NO_NATIVETEXT);
-
- int t = FPDFBitmap_GetStride(bmptemp);
- int bufsize=FPDFBitmap_GetStride(bmptemp)*nClientHeight;
- void* bmpbuf=FPDFBitmap_GetBuffer(bmptemp);
- CDC MemDC;
-
- CBitmap winbmp;
- MemDC.CreateCompatibleDC(pDC);
- if((HBITMAP)winbmp != NULL)
- winbmp.DeleteObject();
- if(HBITMAP(winbmp) == NULL)
- {
- winbmp.CreateCompatibleBitmap(pDC,nClientWidth,nClientHeight);
- winbmp.SetBitmapBits(bufsize,bmpbuf);
- }
-
- MemDC.SelectObject(&winbmp);
-
- pDC->BitBlt(rc.left , rc.top , nClientWidth, nClientHeight, &MemDC,0,0,SRCCOPY);
- MemDC.DeleteDC();
-
- FPDFBitmap_Destroy(bmptemp);
-
-
- int size = m_SelectArray.GetSize();
- for(int i=0; i<size; i++)
- {
-
-
- CRect rc = m_SelectArray.GetAt(i);
-
- CDC memdc;
- CBitmap bmp,*pOldBitmap;
- memdc.CreateCompatibleDC(pDC);
-
- bmp.CreateCompatibleBitmap(pDC,rc.Width(),rc.Height());
-
- pOldBitmap = memdc.SelectObject(&bmp);
-
- memdc.FillSolidRect(0,0,rc.Width(),rc.Height(),RGB(0,100,160));
-
- BLENDFUNCTION bf;
-
- bf.BlendOp = AC_SRC_OVER;
-
- bf.BlendFlags = 0;
-
- bf.SourceConstantAlpha = 0x4f;
-
- bf.AlphaFormat = 0;
-
-
-
- BOOL ret=AlphaBlend(pDC->GetSafeHdc(),rc.left,rc.top,rc.Width(),rc.Height(),memdc.GetSafeHdc(),0,0,rc.Width(),rc.Height(),bf);
-
- memdc.SelectObject(pOldBitmap);
- memdc.DeleteDC();
- bmp.DeleteObject();
-
- }
- m_SelectArray.RemoveAll();
-
-
-
-
-}
-
-void CReaderVCView::GetNewPageSize(int &nsizeX, int &nsizeY)
-{
- int nSizeX = m_nActualSizeX;
- int nSizeY = m_nActualSizeY;
- if (1 == m_nRotateFlag || 3 == m_nRotateFlag)
- {
- int temp = nSizeX;
- nSizeX = nSizeY;
- nSizeY = temp;
- }
- nsizeX = (int)(nSizeX*m_dbScaleFactor);
- nsizeY = (int)(nSizeY*m_dbScaleFactor);
-}
-
-void CReaderVCView::OnDocFirstpage()
-{
-
- if(m_nPageIndex == 0) return;
- this->m_nPageIndex = 0;
- this->LoadPDFPage(m_pDoc, 0);
- DeleteAllRect();
-}
-
-void CReaderVCView::OnDocGotopage()
-{
- CGotoPageDlg dlg;
- dlg.DoModal();
-}
-
-void CReaderVCView::OnDocLastpage()
-{
-// FPDF_DOCUMENT doc = FPDF_LoadDocument("d:\\a1.pdf", "");
-// FPDF_PAGE page = FPDF_LoadPage(doc, 0);
-// FPDF_IMAGEOBJECT imgObject = FPDFPageObj_NewImgeObj(doc);
-// long ret = FPDFImageObj_LoadFromFileEx(&page, 1 ,
-// imgObject, "E:\\temp\\temp\\k.gif",TRUE
-// );
-// FPDFImageObj_SetMatrix(imgObject, 240, 0, 0, 160, 1*50, 0 );
-// FPDFPage_InsertObject(page, imgObject);
-// FPDFPage_GenerateContent(page);
-// FPDF_SaveAsFile(doc, "D:\\out.pdf", 0, NULL, 0, NULL, 0);
-// FPDF_ClosePage(page);
-// FPDF_CloseDocument(doc);
-// return;
-
-
- if(m_nPageIndex == m_nTotalPage -1) return;
- this->m_nPageIndex = m_nTotalPage -1;
- LoadPDFPage(m_pDoc, m_nPageIndex);
- DeleteAllRect();
-}
-
-void CReaderVCView::OnDocNextpage()
-{
- m_nPageIndex ++ ;
- m_nPageIndex %= m_nTotalPage;
- LoadPDFPage(m_pDoc, m_nPageIndex);
- DeleteAllRect();
-}
-
-void CReaderVCView::OnDocPrepage()
-{
- m_nPageIndex --;
- if(m_nPageIndex < 0) m_nPageIndex = m_nTotalPage-1;
- LoadPDFPage(m_pDoc, m_nPageIndex);
- DeleteAllRect();
-}
-
-void CReaderVCView::OnClockwise()
-{
- m_nRotateFlag ++;
- m_nRotateFlag %= 4;
- LoadPDFPage(m_pDoc, m_nPageIndex);
-}
-
-void CReaderVCView::OnCounterclockwise()
-{
- m_nRotateFlag --;
- if (m_nRotateFlag < 0) m_nRotateFlag = 3;
- LoadPDFPage(m_pDoc, m_nPageIndex);
-}
-
-BOOL CReaderVCView::SetPDFDocument(FPDF_DOCUMENT pDoc, int nPageNum)
-{
- if(pDoc == NULL) return FALSE;
-
- m_pApp = FPDFDOC_InitFormFillEnviroument(pDoc,this);
- FPDF_LoadXFA(pDoc);
-
- FORM_DoDocumentJSAction(m_pApp);
- FORM_DoDocumentOpenAction(m_pApp);
-// FORM_OnAfterLoadDocument(m_pApp);
- FPDF_SetFormFieldHighlightColor(m_pApp, 0, RGB(0,255, 0));
- FPDF_SetFormFieldHighlightAlpha(m_pApp, 128);
-
-
- m_pDoc = pDoc;
- m_nTotalPage = nPageNum;
- if(!LoadPDFPage(m_pDoc, 0)) return FALSE;
-
- return TRUE;
-}
-
-void CReaderVCView::GotoPage(int index)
-{
- if(index < 0 || index >= m_nTotalPage){MessageBoxA("Invalidate index");}
- if(index == m_nPageIndex) return;
- if(!LoadPDFPage(m_pDoc, index)) return;
- DeleteAllRect();
-}
-
-void CReaderVCView::OnViewActualSize()
-{
- m_nStartX = m_nStartY = 10;
- ScalPage(1.0f);
-}
-
-void CReaderVCView::OnViewFitPage()
-{
- m_nStartX = m_nStartY = 10;
- CRect rect;
- GetClientRect(rect);
- double dbHeight = rect.Height();
- double dbScal = dbHeight / m_nActualSizeY;
- ScalPage(dbScal);
-}
-
-void CReaderVCView::OnViewFitWidth()
-{
- m_nStartX = m_nStartY = 10;
- CRect rect;
- GetClientRect(rect);
- double dbWidth= rect.Width();
- double dbScal = dbWidth / m_nActualSizeX;
- ScalPage(dbScal);
-}
-
-void CReaderVCView::OnViewZoomIn()
-{
- double dbScal = m_dbScaleFactor;
- dbScal += 0.25f;
- if(dbScal > 6400.0f) return;
- ScalPage(dbScal);
-
-}
-
-void CReaderVCView::OnViewZoomOut()
-{
- double dbScal = m_dbScaleFactor;
- dbScal -= 0.25f;
- if(dbScal < 0.25f) return;
- ScalPage(dbScal);
-}
-
-void CReaderVCView::OnViewZoomTo()
-{
- CZoomDlg dlg;
- dlg.DoModal();
-}
-
-void CReaderVCView::ScalPage(double dbScal)
-{
- SetScalFactor(dbScal);
- CChildFrame *pParent = (CChildFrame *)this->GetParentFrame();
- if (pParent != NULL)
- {
- pParent->SetActiveView(this);
- SyncScroll();
- }
- Invalidate(TRUE);
-}
-
-void CReaderVCView::OnEditFind()
-{
- if(m_pTextPage == NULL)
- {
- AfxMessageBox("Sorry, the fpdftext.dll may has expired. For keeping on using the dll, please contact sales@foxitsoftware.com.");
- return;
- }
- CFindDlg dlg;
- dlg.DoModal();
-}
-
-void CReaderVCView::FindText(CString strFind, BOOL bCase, BOOL bWholeword, int Direction)
-{
- CString str;
- str = m_FindInfo.m_strFind;
- int nFlag = 0;
- if(bCase) { nFlag |= FPDF_MATCHCASE; }
- if(bWholeword) { nFlag |= FPDF_MATCHWHOLEWORD; }
-
- if(NULL == m_pTextPage) return;
-
- if (strFind.Compare(str) != 0 || nFlag != m_FindInfo.m_nFlag)//new search
- {
- if (NULL == m_pTextPage) return;
- if (NULL != m_pSCHHandle)
- {
- FPDFText_FindClose(m_pSCHHandle);
- m_pSCHHandle = NULL;
- }
-
- int len = MultiByteToWideChar(CP_ACP, 0, strFind.GetBuffer(0), -1, NULL, NULL);
- wchar_t *pBuf = new wchar_t[len];
- memset(pBuf, 0, len*sizeof(wchar_t));
- MultiByteToWideChar(CP_ACP, 0, strFind.GetBuffer(0), strFind.GetLength(), pBuf, len);
- pBuf[len-1] = L'\0';
- m_pSCHHandle = FPDFText_FindStart(m_pTextPage, (FPDF_WIDESTRING)pBuf, nFlag, 0);
- if(NULL == m_pSCHHandle) return;
-
- if (m_FindInfo.m_pCurFindBuf != NULL)
- {
- delete []m_FindInfo.m_pCurFindBuf;
- m_FindInfo.m_pCurFindBuf = NULL;
- }
- m_FindInfo.m_pCurFindBuf = new wchar_t[len];
- memset(m_FindInfo.m_pCurFindBuf, 0, len*sizeof(wchar_t));
- memcpy(m_FindInfo.m_pCurFindBuf, pBuf, len*sizeof(wchar_t));
-
- delete []pBuf;
-
-
- //save the find info
- m_FindInfo.m_strFind = strFind;
- m_FindInfo.m_nFlag = nFlag;
- m_FindInfo.m_nDirection = Direction;
- m_FindInfo.m_nStartPageIndex = m_nPageIndex;
- m_FindInfo.m_bFirst = TRUE;
-
-
- }
- FindNext(Direction);
-}
-
-void CReaderVCView::FindNext(int nDirection)
-{
- if(NULL == m_pSCHHandle) return;
- BOOL bResult = FALSE;
-
- if (nDirection != m_FindInfo.m_nDirection)
- {
- m_FindInfo.m_nDirection = nDirection;
- m_FindInfo.m_bFirst = TRUE;
- }
-
- if (0 == nDirection)// find down
- {
- bResult = FPDFText_FindNext(m_pSCHHandle);
- }
- if (1 == nDirection)
- {
- bResult = FPDFText_FindPrev(m_pSCHHandle);
- }
-
- while(!bResult){
-
- if (m_rtFind != NULL)
- {
- delete [] m_rtFind;
- m_rtFind = NULL;
- }
-
- if (0 == nDirection)
- {
- m_nPageIndex ++;
- m_nPageIndex %= m_nTotalPage;
- if(!LoadPDFPage(m_pDoc, m_nPageIndex)) return;
- if (NULL == m_pTextPage) return;
- if (NULL != m_pSCHHandle)
- {
- FPDFText_FindClose(m_pSCHHandle);
- m_pSCHHandle = NULL;
- }
- m_pSCHHandle = FPDFText_FindStart(m_pTextPage, (FPDF_WIDESTRING)m_FindInfo.m_pCurFindBuf, m_FindInfo.m_nFlag, 0);
- if(NULL == m_pSCHHandle) break;
- bResult = FPDFText_FindNext(m_pSCHHandle);
- if(!bResult && m_nPageIndex == m_FindInfo.m_nStartPageIndex) break;
- }
- else
- {
- m_nPageIndex --;
- if (m_nPageIndex < 0) {m_nPageIndex = m_nTotalPage - 1;}
- if(!LoadPDFPage(m_pDoc, m_nPageIndex)) return;
- if (NULL == m_pTextPage) return;
- if (NULL != m_pSCHHandle)
- {
- FPDFText_FindClose(m_pSCHHandle);
- m_pSCHHandle = NULL;
- }
- m_pSCHHandle = FPDFText_FindStart(m_pTextPage, (FPDF_WIDESTRING)m_FindInfo.m_pCurFindBuf, m_FindInfo.m_nFlag, 0);
- if(NULL == m_pSCHHandle) break;
- bResult = FPDFText_FindPrev(m_pSCHHandle);
- if(!bResult && m_nPageIndex == m_FindInfo.m_nStartPageIndex) break;
- }
- }//end while
-
- if(!bResult)//find over
- {
- FPDFText_FindClose(m_pSCHHandle);
- m_pSCHHandle = NULL;
-
- if (m_rtFind != NULL)
- {
- delete [] m_rtFind;
- m_rtFind = NULL;
- }
-
- m_FindInfo.m_bFirst = TRUE;
- m_FindInfo.m_nDirection = -1;
- m_FindInfo.m_nFlag = -1;
- m_FindInfo.m_nStartCharIndex = -1;
- m_FindInfo.m_nStartPageIndex = -1;
- m_FindInfo.m_pCurFindBuf = NULL;
- m_FindInfo.m_strFind = _T("");
-
- MessageBox("Find complete!", "Find Infomation", MB_OK | MB_ICONINFORMATION);
- return;
- }
-
-
-
- int index = FPDFText_GetSchResultIndex(m_pSCHHandle);
- if (m_nPageIndex == m_FindInfo.m_nStartPageIndex && index == m_FindInfo.m_nStartCharIndex && !m_FindInfo.m_bFirst )
- {
- if (NULL != m_pSCHHandle)
- {
- FPDFText_FindClose(m_pSCHHandle);
- m_pSCHHandle = NULL;
- }
- MessageBox("Find complete!", "Find Infomation", MB_OK | MB_ICONINFORMATION);
- return;
- }else{
- CDC *pDC = GetDC();
- DrawAllRect(pDC);//update
-
- int nCount = FPDFText_GetSchCount(m_pSCHHandle);
- int nRects = FPDFText_CountRects(m_pTextPage, index, nCount);
- if (m_rtFind != NULL)
- {
- delete [] m_rtFind;
- m_rtFind = NULL;
- }
- m_rtFind = new PDFRect[nRects];
- m_nRectNum = nRects;
- for (int i=0; i<nRects; i++)
- {
- double left, top, right, bottom;
- FPDFText_GetRect(m_pTextPage, i, &left, &top, &right, &bottom);
- m_rtFind[i].m_dbLeft = left;
- m_rtFind[i].m_dbTop = top;
- m_rtFind[i].m_dbRight = right;
- m_rtFind[i].m_dbBottom = bottom;
- }
- DrawAllRect(pDC);//draw new rect
- ReleaseDC(pDC);
- }
-
- if (m_FindInfo.m_bFirst)
- {//find first string, store info;
- m_FindInfo.m_bFirst = FALSE;
- m_FindInfo.m_nStartCharIndex = index;
- m_FindInfo.m_nStartPageIndex = m_nPageIndex;
- }
-
-}
-
-void CReaderVCView::DrawReverse(CDC *pDC, CRect rect)
-{
- CRect rt = rect;
- rect.left = __min(rt.left, rt.right);
- rect.right = __max(rt.left, rt.right);
- rect.top = __min(rt.top, rt.bottom);
- rect.bottom = __max(rt.top, rt.bottom);
-
- ASSERT(pDC);
- int bmp_width=abs(rect.Width());
- int bmp_height=abs(rect.Height());
- HBITMAP hbmp = CreateCompatibleBitmap(pDC->m_hDC, bmp_width, bmp_height);
- CDC MemDC;
- MemDC.CreateCompatibleDC(pDC);
- HBITMAP holdbmp = (HBITMAP)MemDC.SelectObject(hbmp);
- // copy screen DC to memory DC
- BitBlt(MemDC, 0, 0, bmp_width, bmp_height, pDC->m_hDC, rect.left,rect.top, SRCCOPY);
- MemDC.SelectObject(holdbmp);
-
- BITMAPINFO bmi;
- memset(&bmi, 0, sizeof bmi);
- bmi.bmiHeader.biSize = sizeof bmi.bmiHeader;
- bmi.bmiHeader.biBitCount = 24;
- bmi.bmiHeader.biClrImportant = 0;
- bmi.bmiHeader.biClrUsed = 0;
- bmi.bmiHeader.biCompression = BI_RGB;
- bmi.bmiHeader.biHeight = bmp_height;
- bmi.bmiHeader.biPlanes = 1;
- bmi.bmiHeader.biSizeImage = 0;
- bmi.bmiHeader.biWidth = bmp_width;
- bmi.bmiHeader.biXPelsPerMeter = 0;
- bmi.bmiHeader.biYPelsPerMeter = 0;
-
- // get bitmap stream
- int ret = GetDIBits(MemDC, hbmp, 0,bmp_height, NULL, &bmi, DIB_RGB_COLORS);
-
- int size = bmi.bmiHeader.biSizeImage;
-
- BYTE* pBits = new BYTE[size];
- memset(pBits, 0, size);
- ret = GetDIBits(MemDC, hbmp, 0,bmp_height, pBits, &bmi, DIB_RGB_COLORS);
- ret = GetLastError();
- DeleteObject(hbmp);
- MemDC.DeleteDC();
- for (int row = 0; row < bmp_height; row ++) {
- int pitch = (bmp_width * 3 + 3) / 4 * 4;
- int rowpos = row * pitch;
- for(int col = 0; col < bmp_width; col ++){
- int i = rowpos + col * 3;
- pBits[i] = 255-pBits[i] ;
- pBits[i + 1] = 255-pBits[i + 1];
- pBits[i + 2] = 255-pBits[i + 2];
- }
- }
- ret = SetDIBitsToDevice(pDC->m_hDC,rect.left,rect.top,bmp_width, bmp_height,0, 0, 0, bmp_height, pBits, &bmi, DIB_RGB_COLORS);
- delete []pBits;
-
-}
-
-void CReaderVCView::DrawAllRect(CDC *pDC)
-{
- int i;
- int left, top, right, bottom;
-
- int nSizeX = 0;
- int nSizeY = 0;
-// int temp = 0;
- if (1 == m_nRotateFlag || 3 == m_nRotateFlag)
- {
- nSizeX = m_nActualSizeY;
- nSizeY = m_nActualSizeX;
- }
- else
- {
- nSizeX = m_nActualSizeX;
- nSizeY = m_nActualSizeY;
- }
- ASSERT(pDC);
- if (m_rtFind != NULL)
- {
- for (i=0; i<m_nRectNum; i++)
- {
-
- PDFRect rect = m_rtFind[i];
- FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nSizeX * m_dbScaleFactor),
- (int)(nSizeY * m_dbScaleFactor), m_nRotateFlag, rect.m_dbLeft, rect.m_dbTop, &left, &top);
- FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nSizeX * m_dbScaleFactor),
- (int)(nSizeY * m_dbScaleFactor), m_nRotateFlag, rect.m_dbRight, rect.m_dbBottom, &right, &bottom);
- CRect rt(left, top, right, bottom);
- DrawReverse(pDC, rt);
-
- }
- }
-
- if (m_rtArray.GetSize() != 0)
- {
- for (i=0; i<m_rtArray.GetSize(); i++)
- {
- PDFRect rect = m_rtArray.GetAt(i);
- FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nSizeX * m_dbScaleFactor),
- (int)(nSizeY * m_dbScaleFactor), m_nRotateFlag, rect.m_dbLeft, rect.m_dbTop, &left, &top);
- FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nSizeX * m_dbScaleFactor),
- (int)(nSizeY * m_dbScaleFactor), m_nRotateFlag, rect.m_dbRight, rect.m_dbBottom, &right, &bottom);
- CRect rt(left, top, right, bottom);
- DrawReverse(pDC, rt);
- }
- }
-}
-
-void CReaderVCView::DeleteAllRect()
-{
- CDC *pDC = GetDC();
- DrawAllRect(pDC);
- ReleaseDC(pDC);
-
- if (m_rtFind != NULL)
- {
- delete []m_rtFind;
- m_rtFind = NULL;
- }
-
- if (m_rtArray.GetSize() != 0)
- {
- m_rtArray.RemoveAll();
- }
-}
-
-void CReaderVCView::OnFilePrint()
-{
- CString strDoc = GetDocument()->GetTitle();
- CPrintDialog dlg(FALSE, PD_PAGENUMS | PD_USEDEVMODECOPIES);
- dlg.m_pd.nMinPage = dlg.m_pd.nFromPage =1;
- dlg.m_pd.nMaxPage = dlg.m_pd.nToPage = m_nTotalPage;
- if (dlg.DoModal() == IDOK)
- {
- int from_page, to_page;
- if (dlg.PrintAll())
- {
- from_page = dlg.m_pd.nMinPage;
- to_page = dlg.m_pd.nMaxPage;
- }
- else if (dlg.PrintRange())
- {
- from_page = dlg.GetFromPage();
- to_page = dlg.GetToPage();
- }
- else if (dlg.PrintSelection())
- {
- from_page = to_page = m_nPageIndex + 1;
- }
-
- HDC printDC;
- DOCINFO docInfo;
-
- printDC = dlg.CreatePrinterDC();
- if(NULL == printDC) return;
- docInfo.cbSize = sizeof(DOCINFO);
- docInfo.fwType = 0;
- docInfo.lpszDatatype = NULL;
- docInfo.lpszOutput = NULL;
- docInfo.lpszDocName = strDoc;
-
- if(StartDoc(printDC, &docInfo) <= 0) return;
- //FPDF_DOCUMENT pDoc = NULL;
- FPDF_PAGE pPage = NULL;
- CString str;
- for (int i=from_page-1; i<to_page; i++)
- {
- if(pPage != NULL)
- {
- FPDF_ClosePage(pPage);
- pPage = NULL;
- }
- pPage = FPDF_LoadPage(m_pDoc, i);
- double npagewidth = FPDF_GetPageWidth(m_pPage);
- double npageheight = FPDF_GetPageHeight(m_pPage);
-
- int logpixelsx,logpixelsy;
- //calculate the page size
- logpixelsx = GetDeviceCaps(printDC,LOGPIXELSX);
- logpixelsy = GetDeviceCaps(printDC,LOGPIXELSY);
- int nsizeX = (int)(npagewidth / 72 *logpixelsx + 0.5f);
- int nsizeY = (int)(npageheight / 72 *logpixelsy + 0.5f);
-
- if(StartPage(printDC) <= 0)
- {
- str.Format("one error occured when start the page %d", i);
- MessageBox(str);
- return;
- }
-
- //render to print device
- FPDF_RenderPage(printDC, pPage, m_nStartX, m_nStartY, nsizeX, nsizeY, m_nRotateFlag, 0);
-
- if(EndPage(printDC) <= 0)
- {
- str.Format("one error occured when close the page %d", i);
- MessageBox(str);
- return;
- }
-
- }//end for
- EndDoc(printDC);
- if(!DeleteDC(printDC))// delete printDC
- MessageBox("can not delete the printer");
- }
-}
-
-void CReaderVCView::OnLButtonDown(UINT nFlags, CPoint point)
-{
- // TODO: Add your message handler code here and/or call default
-
- double page_x = 0;
- double page_y = 0;
- DeviceToPage(point, page_x, page_y);
-
- if(m_pApp)
- {
- FPDF_BOOL b= FORM_OnLButtonDown(m_pApp, m_pPage,ComposeFlag(),page_x, page_y);
- if(b)
- return;
- }
- DeleteAllRect();
- LoadMyCursor(1);
- m_ptLBDown = point;
-
-
- if (m_bSelect)
- {
- m_bHasChar = GetCharIndexByPoint(point, m_nStartIndex);
- CreateCaret(point);
- }
- if (m_bHand)
- {
- m_nPosH = GetScrollPos(SB_HORZ);//SetScrollPos(SB_VERT, point.y, TRUE);
- m_nPosV = GetScrollPos(SB_VERT);
- }
- CView::OnLButtonDown(nFlags, point);
-}
-
-void CReaderVCView::OnLButtonUp(UINT nFlags, CPoint point)
-{
-
- // TODO: Add your message handler code here and/or call default
- double page_x = 0;
- double page_y = 0;
- DeviceToPage(point, page_x, page_y);
-
- if(m_pApp)
- {
- if(FORM_OnLButtonUp(m_pApp, m_pPage,ComposeFlag(), page_x, page_y))
- return;
- }
- LoadMyCursor();
- m_ptLBUp = point;
- if (m_bSelect || m_bSnap)
- {
- CDC *pDC = GetDC();
- CPen *pOldPen;
- CPen pen;
- CBrush *pOldBr;
- CRect rect;
- pen.CreatePen(PS_DASH, 2, RGB(255,0,0));
- pOldPen = pDC->SelectObject(&pen);
- pOldBr = (CBrush*) (pDC->SelectStockObject(NULL_BRUSH));
- int nOldRop = pDC->SetROP2(R2_XORPEN);
- pDC->Rectangle(m_rtOld);
- pDC->SetROP2(nOldRop);
- m_rtOld.left = m_rtOld.top = m_rtOld.right = m_rtOld.bottom = 0;
- ReleaseDC(pDC);
- }
-
- if (m_bSnap)
- {
- BOOL open = OpenClipboard();
- if (open)
- {
- ::EmptyClipboard();
- int bmpWidth = abs(point.x - m_ptLBDown.x);
- int bmpHeight = abs(point.y - m_ptLBDown.y);
- if (bmpHeight == 0 || bmpWidth == 0)return;
- CRect bmpRect(m_ptLBDown, point);
- CClientDC dc(this);
- CBitmap *pBitmap = new CBitmap();
- pBitmap->CreateCompatibleBitmap(&dc,bmpWidth,bmpHeight);
- CDC memDC;
- memDC.CreateCompatibleDC(&dc);
- memDC.SelectObject(pBitmap);
- CBrush whiteBrush(RGB(255,255,255));
- //memDC.FillRect(bmpRect,&whiteBrush);
- memDC.BitBlt(0, 0, bmpRect.Width(), bmpRect.Height(),&dc, bmpRect.left, bmpRect.top,SRCCOPY);
- HBITMAP hBitmap = (HBITMAP) *pBitmap;
- :: SetClipboardData(CF_BITMAP, hBitmap);
- ::CloseClipboard();
- MessageBox("The selected area has been copied to clipboard!");
- delete pBitmap;
- }
- }
-
- FPDF_LINK hlink=NULL;
- double pdfx,pdfy;
-
- int nActualRangeX = 0;
- int nActualRangeY = 0;
- if ( m_nRotateFlag % 2 == 0 )
- {
- nActualRangeX = m_nActualSizeX;
- nActualRangeY = m_nActualSizeY;
- }else{
- nActualRangeX = m_nActualSizeY;
- nActualRangeY = m_nActualSizeX;
- }
-
- FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),
- (int)(nActualRangeY * m_dbScaleFactor),m_nRotateFlag,point.x,point.y,&pdfx,&pdfy);
- hlink=FPDFLink_GetLinkAtPoint(m_pPage,pdfx,pdfy);
- if (hlink)
- {
- FPDF_ACTION haction=NULL;
- FPDF_DEST hLinkDest=NULL;
- haction=FPDFLink_GetAction(hlink);
- hLinkDest=FPDFLink_GetDest(m_pDoc,hlink);
- if (haction)
- {
- int nActionType=FPDFAction_GetType(haction);
- switch(nActionType)
- {
- case PDFACTION_UNSUPPORTED: // Unsupported action type
- break;
- case PDFACTION_GOTO: // Go to a destination within current document
- {
- FPDF_LINK hActLinkDest = FPDFAction_GetDest(m_pDoc,haction);
- if (hActLinkDest)
- {
- int nPageIndex=FPDFDest_GetPageIndex(m_pDoc,hActLinkDest);
- GotoPage(nPageIndex);
- }
- }
- break;
- case PDFACTION_REMOTEGOTO: // Go to a destination within another document
-
- // FPDFAction_GetFilePath(...);
- // .....
- break;
- case PDFACTION_URI: // Universal Resource Identifier, including web pages and
- // other Internet based resources
- // int nsize= FPDFAction_GetURIPath(m_pDoc,haction);
- // ...
- break;
- case PDFACTION_LAUNCH: // Launch an application or open a file
- // FPDFAction_GetFilePath(...)
- break;
- default :
- break;
- }
- }
- else if (hLinkDest)
- {
- int nPageIndex=FPDFDest_GetPageIndex(m_pDoc,hLinkDest);
- GotoPage(nPageIndex);
- }
- }
- CView::OnLButtonUp(nFlags, point);
-}
-
-void CReaderVCView::OnMouseMove(UINT nFlags, CPoint point)
-{
- // TODO: Add your message handler code here and/or call default
- double page_x = 0;
- double page_y = 0;
- DeviceToPage(point, page_x, page_y);
-
- if(m_pApp)
- {
- if(FORM_OnMouseMove(m_pApp, m_pPage,ComposeFlag(), page_x, page_y))
- return;
- }
- if (nFlags == MK_LBUTTON)
- {
- LoadMyCursor(1);
- }else{LoadMyCursor();}
-
- CDC *pDC = GetDC();
-
- if (m_bSelect && nFlags == MK_LBUTTON)
- {
- if (m_bHasChar)
- {
- if (m_ptOld.x == 0 && m_ptOld.y == 0){m_ptOld = m_ptLBDown;}
-
- int nIndex = 0;
- if (!GetCharIndexByPoint(point, nIndex)) return;
- if(nIndex == m_nEndIndex) return;
-
- DrawAllRect(pDC);//update all rect
-
- m_nEndIndex = nIndex;
- GetRects(m_nStartIndex, m_nEndIndex); //get the rect and store into m_rtArray
- DrawAllRect(pDC);//draw new rect
- }
- else
- {
- CPen *pOldPen;
- CPen pen;
- CBrush *pOldBr;
- CRect rect;
- pen.CreatePen(PS_DASH, 2, RGB(255,0,0));
- pOldPen = pDC->SelectObject(&pen);
- pOldBr = (CBrush*) (pDC->SelectStockObject(NULL_BRUSH));
- int nOldRop = pDC->SetROP2(R2_XORPEN);
- int nModle = pDC->Rectangle(m_rtOld);
-
-
- DrawAllRect(pDC);//update all rect
- rect = SelectSegment(m_ptLBDown, point);
- DrawAllRect(pDC);
-
- pDC->Rectangle(rect);
- pDC->SelectObject(pOldBr);
- pDC->SelectObject(pOldPen);
- pDC->SetROP2(nModle);
- m_rtOld = rect;
- }
- }
-
- if (m_bHand && nFlags == MK_LBUTTON)
- {
- int curPos, prevPos;
- //CChildFrame *pFrame = (CChildFrame *) GetParentFrame();
-
- int dy = m_ptLBDown.y - point.y;
- prevPos = m_nPosV;
- curPos = prevPos + dy;
- prevPos = SetScrollPos(SB_VERT, curPos, TRUE);
- curPos = GetScrollPos(SB_VERT);
- int distance;
- distance = prevPos - curPos;
- m_nStartY += distance;
- ScrollWindow(0, distance);
-
- dy = m_ptLBDown.x - point.x;
- prevPos = m_nPosH;
- curPos = prevPos + dy;
- prevPos = SetScrollPos(SB_HORZ, curPos, TRUE);
- curPos = GetScrollPos(SB_HORZ);
- distance = prevPos - curPos;
- m_nStartX += distance;
- ScrollWindow(distance, 0);
-
- }
- if (m_bSnap && nFlags == MK_LBUTTON)
- {
- CPen *pOldPen;
- CPen pen;
- CBrush *pOldBr;
- CRect rect(m_ptLBDown, point);
- pen.CreatePen(PS_DASH, 2, RGB(255,0,0));
- pOldPen = pDC->SelectObject(&pen);
- pOldBr = (CBrush*) (pDC->SelectStockObject(NULL_BRUSH));
- int nOldRop = pDC->SetROP2(R2_XORPEN);
- int nModle = pDC->Rectangle(m_rtOld);
-
- pDC->Rectangle(rect);
- pDC->SelectObject(pOldBr);
- pDC->SelectObject(pOldPen);
- pDC->SetROP2(nModle);
- m_rtOld = rect;
-
- }
-
- FPDF_LINK hlink=NULL;
- double pdfx,pdfy;
-
- int nActualRangeX = 0;
- int nActualRangeY = 0;
- if ( m_nRotateFlag % 2 == 0 )
- {
- nActualRangeX = m_nActualSizeX;
- nActualRangeY = m_nActualSizeY;
- }else{
- nActualRangeX = m_nActualSizeY;
- nActualRangeY = m_nActualSizeX;
- }
-
- FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),
- (int)(nActualRangeY * m_dbScaleFactor),m_nRotateFlag,point.x,point.y,&pdfx,&pdfy);
- hlink=FPDFLink_GetLinkAtPoint(m_pPage,pdfx,pdfy);
- if (hlink)
- {
- HCURSOR hCur = AfxGetApp()->LoadCursor(IDC_CURSOR4);
- ::SetCursor(hCur);
- }
- ReleaseDC(pDC);
-//
- CView::OnMouseMove(nFlags, point);
-}
-
-void CReaderVCView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
-{
- // TODO: Add your message handler code here and/or call default
-// double page_x = 0;
-// double page_y = 0;
-// DeviceToPage(point, page_x, page_y);
-
- if(m_pApp)
- {
- if(FORM_OnKeyDown(m_pApp, m_pPage, nChar, ComposeFlag()))
- return;
- }
- switch(nChar)
- {
- case 35:
- OnDocLastpage();
- break;
- case 36:
- OnDocFirstpage();
- break;
- case 37:
- this->OnDocPrepage();
- break;
- case 39:
- this->OnDocNextpage();
- break;
- case 38:
-
- break;
- case 40:
-
- break;
- default:
- break;
- }
- CView::OnKeyDown(nChar, nRepCnt, nFlags);
-}
-
-void CReaderVCView::OnToolSnapshot()
-{
- m_bSnap = TRUE;
- m_bHand = FALSE;
- m_bSelect = FALSE;
- this->HideCaret();
-}
-
-void CReaderVCView::OnToolSelect()
-{
- if(m_pTextPage == NULL)
- {
- AfxMessageBox("Sorry, the fpdftext.dll may has expired. For keeping on using the dll, please contact sales@foxitsoftware.com.");
- return;
- }
- m_bSnap = FALSE;
- m_bHand = FALSE;
- m_bSelect = TRUE;
-}
-
-void CReaderVCView::OnToolHand()
-{
- m_bSnap = FALSE;
- m_bHand = TRUE;
- m_bSelect = FALSE;
- this->HideCaret();
-}
-
-void CReaderVCView::LoadMyCursor(int nflag)
-{
- HCURSOR hCur;
- if (nflag == 1)
- {
- if (m_bSelect)
- {
- hCur = AfxGetApp()->LoadCursor(IDC_CURSOR3);
- }
- else if (m_bSnap)
- {
- hCur = AfxGetApp()->LoadStandardCursor(IDC_CROSS);
- }
- else
- {
- hCur = AfxGetApp()->LoadCursor(IDC_CURSOR1);
- }
- }
- else if (m_bHand)
- {
- hCur = AfxGetApp()->LoadCursor(IDC_CURSOR2);
- }
- else if (m_bSelect)
- {
- hCur = AfxGetApp()->LoadCursor(IDC_CURSOR3);
- }
- else if (m_bSnap)
- {
- hCur = AfxGetApp()->LoadStandardCursor(IDC_CROSS);
- }else
- {
- hCur = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
- }
- ::SetCursor(hCur);
-}
-
-BOOL CReaderVCView::DeviceToPage(CPoint pt, double& page_x, double& page_y)
-{
-// if(NULL == m_pTextPage) return FALSE;
- int nActualRangeX = 0;
- int nActualRangeY = 0;
- if ( m_nRotateFlag % 2 == 0 )
- {
- nActualRangeX = m_nActualSizeX;
- nActualRangeY = m_nActualSizeY;
- }else{
- nActualRangeX = m_nActualSizeY;
- nActualRangeY = m_nActualSizeX;
- }
-// switch ( m_nRotateFlag % 4 )
-// {
-// case 0:
-// case 2:
-// {
-// FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, m_nActualSizeX * m_dbScaleFactor,
-// m_nActualSizeY * m_dbScaleFactor, m_nRotateFlag, pt.x, pt.y, &page_x, &page_y);
-// break;
-// }
-// case 1:
-// case 3:
-// {
-// FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, m_nActualSizeY * m_dbScaleFactor,
-// m_nActualSizeX * m_dbScaleFactor, m_nRotateFlag, pt.x, pt.y, &page_x, &page_y);
-// break;
-// }
-// }
-
- FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),
- (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, pt.x, pt.y, &page_x, &page_y);
- return TRUE;
-}
-
-BOOL CReaderVCView::PageToDevice(double page_x, double page_y, CPoint& pt)
-{
- int nActualRangeX = 0;
- int nActualRangeY = 0;
- if ( m_nRotateFlag % 2 == 0 )
- {
- nActualRangeX = m_nActualSizeX;
- nActualRangeY = m_nActualSizeY;
- }else{
- nActualRangeX = m_nActualSizeY;
- nActualRangeY = m_nActualSizeX;
- }
-
- FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),
- (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, page_x, page_y, (int*)&pt.x, (int*)&pt.y);
- return TRUE;
-}
-
-BOOL CReaderVCView::GetCharIndexByPoint(CPoint pt, int &nIndex)
-{
- double page_x = 0.0f;
- double page_y = 0.0f;
-
- if(NULL == m_pTextPage) return FALSE;
- int nActualRangeX = 0;
- int nActualRangeY = 0;
- if ( m_nRotateFlag % 2 == 0 )
- {
- nActualRangeX = m_nActualSizeX;
- nActualRangeY = m_nActualSizeY;
- }else{
- nActualRangeX = m_nActualSizeY;
- nActualRangeY = m_nActualSizeX;
- }
- FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),
- (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, pt.x, pt.y, &page_x, &page_y);
-// FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, m_nActualSizeX * m_dbScaleFactor,
-// m_nActualSizeY * m_dbScaleFactor, m_nRotateFlag, pt.x, pt.y, &page_x, &page_y);
-
- nIndex = FPDFText_GetCharIndexAtPos(m_pTextPage, page_x, page_y, 10, 10);
- if (-3 == nIndex || -1 == nIndex) return FALSE;
- return TRUE;
-}
-
-void CReaderVCView::CreateCaret(CPoint pt)
-{
- double a, b, c, d;
- int nIndex = 0;
- int nAcent = 0, nDecent = 0;
- double orgx = 0.0f, orgy = 0.0f;
- double fontsize = 0.0f;
- int left = 0, right = 0;
- int top = 0, bottom = 0;
- //double left_char, right_char, top_char, bottom_char;//char bounding box
- FPDF_FONT pfont = NULL;
-
- if(!GetCharIndexByPoint(pt, nIndex)) return;
- fontsize = FPDFText_GetFontSize(m_pTextPage, nIndex);
-// FPDFText_GetOrigin(m_pTextPage, nIndex, &orgx, &orgy);
-// pfont = FPDFText_GetFont(m_pTextPage, nIndex);
-// if(NULL == pfont) return;
-// nAcent = FPDFFont_GetAscent(pfont);
-// nDecent = FPDFFont_GetDescent(pfont);
-// FPDFText_GetMatrix(m_pTextPage, nIndex, &a, &b, &c, &d);
-// nAcent =(int)((nAcent * fontsize / 1000.0f) * d + orgy + 0.5f);
-// nDecent = (int)((nDecent * fontsize / 1000.0f) * d + orgy + 0.5f);
-//
-// int nActualRangeX = 0;
-// int nActualRangeY = 0;
-// if ( m_nRotateFlag % 2 == 0 )
-// {
-// nActualRangeX = m_nActualSizeX;
-// nActualRangeY = m_nActualSizeY;
-// }else{
-// nActualRangeX = m_nActualSizeY;
-// nActualRangeY = m_nActualSizeX;
-// }
-// FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),
-// (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, orgx, nAcent, &left, &top);
-//
-// FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),
-// (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, orgx, nDecent, &right, &bottom);
-//
-// // FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, m_nActualSizeX * m_dbScaleFactor,
-// // m_nActualSizeY * m_dbScaleFactor, m_nRotateFlag, orgx, nAcent, &left, &top);
-// //
-// // FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, m_nActualSizeX * m_dbScaleFactor,
-// // m_nActualSizeY * m_dbScaleFactor, m_nRotateFlag, orgx, nDecent, &right, &bottom);
-//
-// this->CreateSolidCaret(2, abs(top - bottom));
-//
-// /* FPDFText_GetCharBox(m_pTextPage, nIndex, &left_char, &right_char, &bottom_char, &top_char);
-//
-// FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, m_nActualSizeX * m_dbScaleFactor,
-// m_nActualSizeY * m_dbScaleFactor, m_nRotateFlag, left_char, top_char, &left, &top);
-// FPDF_PageToDevice(m_pPage, m_nStartX, m_nStartY, m_nActualSizeX * m_dbScaleFactor,
-// m_nActualSizeY * m_dbScaleFactor, m_nRotateFlag, right_char, bottom_char, &right, &bottom);*/
-// this->SetCaretPos(CPoint(left, top-2));
-// this->ShowCaret();
-
-
-}
-
-void CReaderVCView::GetRects(int nStart, int nEnd)
-{
- int temp, nCount;
- nCount = nEnd - nStart;
- if (nCount < 0)
- {
- temp = nEnd;
- nEnd = nStart;
- nStart = temp;
-
- nCount = abs(nCount);
- }
- nCount ++;
-
- int num = FPDFText_CountRects(m_pTextPage, nStart, nCount);
- if(num == 0) return;
-
- if (m_rtArray.GetSize() > 0)
- {
- m_rtArray.RemoveAll();
- }
- PDFRect rect;
- for (int i=0; i<num; i++)
- {
- FPDFText_GetRect(m_pTextPage, i, &rect.m_dbLeft, &rect.m_dbTop, &rect.m_dbRight, &rect.m_dbBottom);
- m_rtArray.Add(rect);
- }
- return;
-}
-
-CRect CReaderVCView::SelectSegment(CPoint pt_lt, CPoint pt_rb)
-{
- CRect rect(pt_lt, pt_rb);
-// double left, top, right, bottom;
-// int start_index = 0, nCount = 0;
-// int nRect = 0;
-//
-// int nActualRangeX = 0;
-// int nActualRangeY = 0;
-// if ( m_nRotateFlag % 2 == 0 )
-// {
-// nActualRangeX = m_nActualSizeX;
-// nActualRangeY = m_nActualSizeY;
-// }else{
-// nActualRangeX = m_nActualSizeY;
-// nActualRangeY = m_nActualSizeX;
-// }
-// FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),
-// (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, rect.left, rect.top, &left, &top);
-// FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, (int)(nActualRangeX * m_dbScaleFactor),
-// (int)(nActualRangeY * m_dbScaleFactor), m_nRotateFlag, rect.right, rect.bottom, &right, &bottom);
-//
-// // FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, m_nActualSizeX * m_dbScaleFactor,
-// // m_nActualSizeY * m_dbScaleFactor, m_nRotateFlag, rect.left, rect.top, &left, &top);
-// // FPDF_DeviceToPage(m_pPage, m_nStartX, m_nStartY, m_nActualSizeX * m_dbScaleFactor,
-// // m_nActualSizeY * m_dbScaleFactor, m_nRotateFlag, rect.right, rect.bottom, &right, &bottom);
-//
-// int num = FPDFText_CountBoundedSegments(m_pTextPage, left, top, right, bottom);
-//
-// if (m_rtArray.GetSize() > 0)
-// {
-// m_rtArray.RemoveAll();
-// }
-//
-// CDC *pDC = GetDC();
-// for (int i=0; i<num; i++)
-// {
-// FPDFText_GetBoundedSegment(m_pTextPage, i, &start_index, &nCount);
-// nRect = FPDFText_CountRects(m_pTextPage, start_index, nCount);
-//
-// PDFRect rect_select;
-// for (int j=0; j<num; j++)
-// {
-// FPDFText_GetRect(m_pTextPage, j, &rect_select.m_dbLeft, &rect_select.m_dbTop, &rect_select.m_dbRight, &rect_select.m_dbBottom);
-// m_rtArray.Add(rect_select);
-// }
-// }
-// ReleaseDC(pDC);
- return rect;
-}
-
-void CReaderVCView::OnToolPdf2txt()
-{
- // TODO: Add your command handler code here
- if(m_pTextPage == NULL)
- {
- AfxMessageBox("Sorry, the fpdftext.dll may has expired. For keeping on using the dll, please contact sales@foxitsoftware.com.");
- return;
- }
- CConvertDlg condlg;
- if(condlg.DoModal() == IDOK)
- {
- int nFlag=condlg.m_nFlag;
- CReaderVCDoc *pDoc = this->GetDocument();
- CString pdfname=pDoc->m_strPDFName;
- CString strname=pdfname,stem;
- if (strname.Find(".pdf") != -1 || strname.Find(".PDF") != -1)
- {
- int startatr=strname.ReverseFind('\\');
- stem=strname.Mid(startatr+1,strname.GetLength()-startatr-5);
- }
- CString defaultname=stem+".txt";
-
- char szFilter[] = "Text File(*.txt)|*.txt";
- CFileDialog dlg(FALSE, ".txt", defaultname, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, NULL);
-
- if (dlg.DoModal() == IDOK)
- {
-// CString txtname=dlg.GetPathName();
-// BOOL bFlag=FPDFText_PDFToText(pdfname,txtname,nFlag,NULL);
-// if(! bFlag)
-// MessageBox("Convert Failure!");
- }
- }
-}
-
-void CReaderVCView::SyncScroll()
-{
- CRect rect;
- GetClientRect(rect);
-
- int nSizeX = 0;
- int nSizeY = 0;
- //int temp = 0;
-
- if (1 == m_nRotateFlag || 3 == m_nRotateFlag)
- {
- nSizeX = m_nActualSizeY;
- nSizeY = m_nActualSizeX;
- }
- else
- {
- nSizeX = m_nActualSizeX;
- nSizeY = m_nActualSizeY;
- }
-
- SCROLLINFO scrinfo;
- scrinfo.cbSize = sizeof(SCROLLINFO);
- GetScrollInfo(SB_HORZ, &scrinfo);
- scrinfo.nMin =0;
- scrinfo.nMax = (int)(nSizeX * m_dbScaleFactor);
- scrinfo.nPage = (unsigned int)(__min(nSizeX * m_dbScaleFactor, rect.Width()));
- if (nSizeX * m_dbScaleFactor < rect.Width()){scrinfo.fMask |= SIF_DISABLENOSCROLL;}
- SetScrollInfo(SB_HORZ, &scrinfo);
- SetScrollPos(SB_HORZ, 0);
- //m_nPosH = nPosH;
-
- GetScrollInfo(SB_VERT, &scrinfo);
- scrinfo.nMin = 0;
- scrinfo.nMax = (int)(nSizeY * m_dbScaleFactor);
- scrinfo.nPage =(unsigned int)( __min(nSizeY * m_dbScaleFactor, rect.Height()));
- if (nSizeY * m_dbScaleFactor < rect.Height()){scrinfo.fMask |= SIF_DISABLENOSCROLL;}
- SetScrollInfo(SB_VERT, &scrinfo);
- SetScrollPos(SB_VERT, 0);
-
-}
-
-void CReaderVCView::OnSize(UINT nType, int cx, int cy)
-{
- CView::OnSize(nType, cx, cy);
- SyncScroll();
- if(m_bmp)
- {
- FPDFBitmap_Destroy(m_bmp);
- m_bmp = NULL;
- }
-
- m_bmp = FPDFBitmap_Create(cx, cy, 0);
-
- // TODO: Add your message handler code here
-}
-
-void CReaderVCView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
-{
- // TODO: Add your message handler code here and/or call default
- int prevPos = GetScrollPos(SB_HORZ);
- int curPos = prevPos;
- int nMin, nMax, nPage;
- GetScrollRange(SB_HORZ, &nMin, &nMax);
- SCROLLINFO si;
- GetScrollInfo(SB_HORZ, &si);
- nPage = si.nPage;
-
- switch(nSBCode)
- {
- case SB_TOP:
- curPos = nMin;
- break;
- case SB_BOTTOM:
- curPos = nMax;
- break;
- case SB_LINEUP:
- curPos --;
- break;
- case SB_LINEDOWN:
- curPos ++;
- break;
- case SB_ENDSCROLL:
- return;
- case SB_PAGEDOWN:
- curPos += nPage;
- break;
- case SB_PAGEUP:
- curPos -= nPage;
- break;
- case SB_THUMBPOSITION:
- curPos = si.nTrackPos;
- break;
- case SB_THUMBTRACK:
- curPos = si.nTrackPos;
- break;
- }
-
- if (curPos < nMin) { curPos = nMin;}
- if(curPos > nMax){ curPos = nMax;}
- SetScrollPos(SB_HORZ, curPos);
-
- int distance;
- distance = prevPos - curPos;
- m_nStartX += distance;
- ScrollWindow(distance, 0);
- CRect rect;
- GetClientRect(rect);
- CRect rtnew(rect.left, rect.top, rect.left+distance, rect.bottom);
- InvalidateRect(&rtnew);
-
- CView::OnHScroll(nSBCode, nPos, pScrollBar);
-}
-
-void CReaderVCView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
-{
- // TODO: Add your message handler code here and/or call default
- int prevPos = GetScrollPos(SB_VERT);
- int curPos = prevPos;
- int nMin, nMax, nPage;
- GetScrollRange(SB_VERT, &nMin, &nMax);
- SCROLLINFO si;
- GetScrollInfo(SB_VERT, &si);
- nPage = si.nPage;
-
- switch(nSBCode)
- {
- case SB_TOP:
- curPos = nMin;
- break;
- case SB_BOTTOM:
- curPos = nMax;
- break;
- case SB_LINEUP:
- curPos --;
- break;
- case SB_LINEDOWN:
- curPos ++;
- break;
- case SB_ENDSCROLL:
- return;
- case SB_PAGEDOWN:
- curPos += nPage;
- break;
- case SB_PAGEUP:
- curPos -= nPage;
- break;
- case SB_THUMBPOSITION:
- curPos = si.nTrackPos;
- break;
- case SB_THUMBTRACK:
- curPos = si.nTrackPos;
- break;
- }
-
- if (curPos < nMin) { curPos = nMin;}
- if(curPos > nMax){ curPos = nMax;}
- SetScrollPos(SB_VERT, curPos);
-
- int distance;
- distance = prevPos - curPos;
- m_nStartY += distance;
- ScrollWindow(0, distance);
-
- CRect rect;
- GetClientRect(rect);
- CRect rtnew(rect.left, rect.bottom + distance, rect.right, rect.bottom);
- CRect rtnew2(rect.left, rect.top, rect.right, rect.top + distance);
- InvalidateRect(&rtnew);
- InvalidateRect(&rtnew2);
-
- CView::OnVScroll(nSBCode, nPos, pScrollBar);
-}
-
-void CReaderVCView::OnToolExtractlinks()
-{
- if(m_pTextPage == NULL)
- {
- AfxMessageBox("Sorry, the fpdftext.dll may has expired. For keeping on using the dll, please contact sales@foxitsoftware.com.");
- return;
- }
- CString strLink = _T("");
- wchar_t *pBuf = NULL;
- if(m_pLink != NULL)
- {
- FPDFLink_CloseWebLinks(m_pLink);
- m_pLink = NULL;
- }
- m_pLink = FPDFLink_LoadWebLinks(m_pTextPage);
- if(m_pLink == NULL) return;
-
- int nCount = FPDFLink_CountWebLinks(m_pLink);
- if (nCount == 0) return;
- if (m_rtArray.GetSize()!=0)
- {
- m_rtArray.RemoveAll();
- }
- for (int i=0; i<nCount; i++)
- {
- int nlen = FPDFLink_GetURL(m_pLink, i, NULL, 0)+1;
- pBuf = new wchar_t[nlen];
- memset(pBuf, 0, nlen*sizeof(wchar_t));
- FPDFLink_GetURL(m_pLink, i, (unsigned short*)pBuf, nlen);
- pBuf[nlen-1] = L'\0';
- int n = WideCharToMultiByte(CP_ACP, 0, pBuf, -1, NULL, NULL, NULL, NULL);
- char *p = new char[n];
- memset(p, 0, n);
- WideCharToMultiByte(CP_ACP, 0, pBuf, nlen, p, n, NULL, NULL);
- p[n-1] = '\0';
- strLink += p;
- strLink += "\r\n";
- delete []pBuf;
- delete []p;
- int nRects = FPDFLink_CountRects(m_pLink, i);
- for (int j=0; j<nRects; j++)
- {
- PDFRect rect;
- FPDFLink_GetRect(m_pLink, i, j,
- &rect.m_dbLeft, &rect.m_dbTop, &rect.m_dbRight, &rect.m_dbBottom);
- m_rtArray.Add(rect);
- }
- }
- CDC *pDC = GetDC();
- DrawAllRect(pDC);
- ReleaseDC(pDC);
-
- MessageBox(strLink, "Web Links in this page");
-
-}
-
-void CReaderVCView::OnInitialUpdate()
-{
- CView::OnInitialUpdate();
-
- // TODO: Add your specialized code here and/or call the base class
-}
-
-void CReaderVCView::OnDestroy()
-{
- CView::OnDestroy();
- // TODO: Add your message handler code here
-}
-
-void CReaderVCView::OnUpdateDocFirstpage(CCmdUI* pCmdUI)
-{
- if (0 == m_nPageIndex)
- {
- pCmdUI->Enable(FALSE);
- }
- else
- {
- pCmdUI->Enable(TRUE);
- }
-
-}
-
-void CReaderVCView::OnUpdateDocLastpage(CCmdUI* pCmdUI)
-{
- if (m_nPageIndex == m_nTotalPage - 1)
- {
- pCmdUI->Enable(FALSE);
- }
- else
- {
- pCmdUI->Enable(TRUE);
- }
-
-}
-
-void CReaderVCView::OnUpdateDocNextpage(CCmdUI* pCmdUI)
-{
- if (m_nPageIndex == m_nTotalPage - 1)
- {
- pCmdUI->Enable(FALSE);
- }
- else
- {
- pCmdUI->Enable(TRUE);
- }
-
-}
-
-void CReaderVCView::OnUpdateDocPrepage(CCmdUI* pCmdUI)
-{
- if (0 == m_nPageIndex)
- {
- pCmdUI->Enable(FALSE);
- }
- else
- {
- pCmdUI->Enable(TRUE);
- }
-
-}
-
-void CReaderVCView::OnUpdateToolHand(CCmdUI* pCmdUI)
-{
- // TODO: Add your command update UI handler code here
- if (m_bHand)
- {
- pCmdUI->SetCheck(1);
- }
- else
- {
- pCmdUI->SetCheck(0);
- }
-
-
-}
-
-void CReaderVCView::OnUpdateToolSnapshot(CCmdUI* pCmdUI)
-{
- if (m_bSnap)
- {
- pCmdUI->SetCheck(1);
- }
- else
- {
- pCmdUI->SetCheck(0);
- }
-
-}
-
-void CReaderVCView::OnUpdateToolSelect(CCmdUI* pCmdUI)
-{
- if (m_bSelect)
- {
- pCmdUI->SetCheck(1);
- }
- else
- {
- pCmdUI->SetCheck(0);
- }
-
-}
-
-void CReaderVCView::OnViewBookmark()
-{
- // TODO: Add your command handler code here
- CChildFrame* pParent = (CChildFrame*)GetParentFrame();
- if(pParent == NULL) return;
- if (m_bBookmark) {
- pParent->m_wndSplitter.ShowColumn();
-
- }else{
- pParent->m_wndSplitter.HideColumn(0);
- }
- m_bBookmark = !m_bBookmark;
-}
-
-
-
-BOOL CReaderVCView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
-{
- ScreenToClient(&pt);
- // TODO: Add your message handler code here and/or call default
- double page_x = 0;
- double page_y = 0;
- DeviceToPage(pt, page_x, page_y);
-
- if(m_pApp)
- {
-// FPDF_BOOL b= FORM_OnMouseWheel(m_pApp, m_pPage,ComposeFlag(),0,zDelta,page_x, page_y);
-// if(b)
-// return TRUE;
- }
-
- int curPosY = 0;
- int prevPosY = 0;
- int distanceY = 25;
- if(zDelta > 0)
- {
- curPosY = GetScrollPos(SB_VERT);
- prevPosY = SetScrollPos(SB_VERT, curPosY - distanceY, TRUE);
- curPosY = GetScrollPos(SB_VERT);
- distanceY = prevPosY - curPosY;
- m_nStartY = m_nStartY + distanceY;
- ScrollWindow(0, distanceY);
- }
- else
- {
- curPosY = GetScrollPos(SB_VERT);
- prevPosY = SetScrollPos(SB_VERT, curPosY + distanceY, TRUE);
- curPosY = GetScrollPos(SB_VERT);
- distanceY = curPosY - prevPosY;
- m_nStartY = m_nStartY - distanceY;
- ScrollWindow(0, -distanceY);
- }
- return CView::OnMouseWheel(nFlags, zDelta, pt);
-}
-
-void CReaderVCView::OnContextMenu(CWnd* pWnd, CPoint point)
-{
-
-}
-
-void CReaderVCView::OnEditCopy()
-{
-
- if(m_pTextPage == NULL)
- {
- AfxMessageBox("Sorry, the fpdftext.dll may has expired. For keeping on using the dll, please contact sales@foxitsoftware.com.");
- return;
- }
- long left = 0;
- long top = 0;
- long right = 0;
- long bottom = 0;
- LPWSTR pBuff = NULL;
- int buflen = 0;
- CString csCopyText;
-
- if(m_rtArray.GetSize() != 0)
- {
- for (int i=0; i<m_rtArray.GetSize(); i++)
- {
- PDFRect rect = m_rtArray.GetAt(i);
- buflen = FPDFText_GetBoundedText(m_pTextPage, rect.m_dbLeft, rect.m_dbTop, rect.m_dbRight,
- rect.m_dbBottom, (unsigned short*)pBuff, 0) + 1;
- if(buflen == 0)
- return;
- pBuff = new wchar_t[2*buflen];
- memset(pBuff, 0, 2*buflen);
-
- FPDFText_GetBoundedText(m_pTextPage, rect.m_dbLeft, rect.m_dbTop, rect.m_dbRight,
- rect.m_dbBottom, (unsigned short*)pBuff, buflen);
-
- int n = WideCharToMultiByte(CP_ACP, 0, pBuff, -1, NULL, NULL, NULL, NULL);
- char *p = new char[n];
- memset(p, 0, n);
- WideCharToMultiByte(CP_ACP, 0, pBuff, buflen, p, n, NULL, NULL);
- csCopyText = csCopyText + CString(p);
- delete[] p;
- }
-
- ::OpenClipboard(NULL);
- ::EmptyClipboard();
- HANDLE hClip=GlobalAlloc(GMEM_MOVEABLE,csCopyText.GetLength()+1);
- char* pBuf=(char*)GlobalLock(hClip);
- strcpy(pBuf,csCopyText);
- GlobalUnlock(hClip);
- HANDLE hSuccess = SetClipboardData(CF_TEXT, hClip);
- if(NULL != hSuccess)
- AfxMessageBox("copy success!");
- ::CloseClipboard();
-
-
- }
-
-}
-
-void CReaderVCView::OnRenderbitmap()
-{
-
-}
-
-void CReaderVCView::OnExportPdfToBitmap()
-{
- if (!m_pExportPageDlg)
- {
- m_pExportPageDlg=new CExportPage;
- m_pExportPageDlg->Create(IDD_EXPORT_PAGE,this);
- m_pExportPageDlg->InitDialogInfo(this);
- m_pExportPageDlg->ShowWindow(SW_SHOW);
- }
- else
- m_pExportPageDlg->ShowWindow(SW_SHOW);
-}
-
-BOOL CReaderVCView::PreTranslateMessage(MSG* pMsg)
-{
- // TODO: Add your specialized code here and/or call the base class
-// PP_Event event;
-// if(pMsg->message == WM_LBUTTONDOWN)
-// {
-// event.type = PP_Event_Type_MouseDown;
-//
-// int xPos = (int)(WORD)(pMsg->lParam);
-// int yPos = (int)(WORD)((pMsg->lParam >> 16) & 0xFFFF);
-//
-// event.u.mouse.x = xPos;
-// event.u.mouse.y = yPos;
-// FPDF_FormFillEventMsg(m_pPage, event);
-// }
-// if(pMsg->message == WM_LBUTTONUP)
-// {
-// event.type = PP_Event_Type_MouseUp;
-//
-// int xPos = (int)(WORD)(pMsg->lParam);
-// int yPos = (int)(WORD)((pMsg->lParam >> 16) & 0xFFFF);
-//
-// event.u.mouse.x = xPos;
-// event.u.mouse.y = yPos;
-// FPDF_FormFillEventMsg(m_pPage, event);
-// }
- return CView::PreTranslateMessage(pMsg);
-}
-
-void CReaderVCView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
-{
- // TODO: Add your message handler code here and/or call default
- if(m_pApp)
- {
- if(FORM_OnChar(m_pApp, m_pPage, nChar, ComposeFlag()))
- return ;
- }
- CView::OnChar(nChar, nRepCnt, nFlags);
-}
-
-void CReaderVCView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
-{
- // TODO: Add your specialized code here and/or call the base class
- ((CReaderVCApp*)AfxGetApp())->m_pActiveView = (CReaderVCView*)pActivateView;
- CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
-}
-
-void CReaderVCView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
-{
- // TODO: Add your message handler code here and/or call default
- if(m_pApp)
- FORM_OnKeyUp(m_pApp, m_pPage, nChar, ComposeFlag());
- CView::OnKeyUp(nChar, nRepCnt, nFlags);
-}
-
-
-int G_WriteBlock( FPDF_FILEWRITE* pThis, const void* pData, unsigned long size);
-class CSDK_FileWrite:public FPDF_FILEWRITE
-{
-public:
- CSDK_FileWrite()
- {
- m_fp = NULL;
- version = 0;
- WriteBlock = G_WriteBlock;
- }
-public:
- FILE* m_fp;
-};
-int G_WriteBlock( FPDF_FILEWRITE* pThis, const void* pData, unsigned long size)
-{
- CSDK_FileWrite* pFW = (CSDK_FileWrite*)pThis;
- return fwrite(pData, sizeof(char), size, pFW->m_fp);
-}
-void CReaderVCView::OnFileSave()
-{
- // TODO: Add your command handler code here
- if(m_pDoc != NULL)
- {
- CFileDialog dlg(FALSE,"",NULL,NULL,"PDF(*.PDF)|*.PDF||All Files(*.*)|*.*");
- if (dlg.DoModal() == IDOK)
- {
- CString strPDFName = dlg.GetPathName();
-
- CSDK_FileWrite fw;
- fw.m_fp = fopen(dlg.GetPathName(), "wb");
-
- FPDF_SaveAsCopy(m_pDoc, &fw, 0);
- fclose(fw.m_fp);
-// FPDF_SaveAsFile(m_pDoc, strPDFName.GetBuffer(strPDFName.GetLength()), 0, NULL, 0, NULL, 0);
- }
- }
-}
-
-
-
-void CReaderVCView::OnTestJS()
-{
- // TODO: Add your command handler code here
- //FPDF_WIDESTRING js = L"run=app.setInterval(\"app.alert(\\\"ok\\\")\");app.setTimeOut(\"app.clearInterval(run)\", 6000);";
-// FPDF_WIDESTRING js = L"app.alert(AFNumber_Keystroke(\'aaaaaaaaa\'))";
-// FPDF_WIDESTRING js = L"app.mailMsg(1)";
- //FPDF_WIDESTRING js = L"app.setTimeOut(\"app.clearInterval(1)\", 6000);";
- //FPDF_WIDESTRING js = L"t.1";
-// RunJS(m_pApp, js);
- CTestJsDlg dlg;
- dlg.init(m_pApp);
- dlg.DoModal();
-}
-
-//This function is to simulate the pp event.
-#define PP_EVENT_MODIFIER_SHIFTKEY 1<<0
-#define PP_EVENT_MODIFIER_CONTROLKEY 1<<1
-#define PP_EVENT_MODIFIER_ALTKEY 1<<2
-unsigned int CReaderVCView::ComposeFlag()
-{
- unsigned int nFlag = 0;
- if(IsALTpressed())
- nFlag = nFlag|PP_EVENT_MODIFIER_ALTKEY;
- if(IsCTRLpressed())
- nFlag = nFlag|PP_EVENT_MODIFIER_CONTROLKEY;
- if(IsSHIFTpressed())
- nFlag = nFlag|PP_EVENT_MODIFIER_SHIFTKEY;
- return nFlag;
-}
-
-void CReaderVCView::OnPrintMetalfile()
-{
- FPDF_PAGE page = FPDF_LoadPage(m_pDoc, 0);
- if (!page) {
- return;
- }
-
- HDC printer_dc = CreateDC("WINSPOOL", "Microsoft XPS Document Writer", NULL,
- NULL);
- if (!printer_dc) {
- printf("Could not create printer DC\n");
- return;
- }
- DOCINFO di = {0};
- di.cbSize = sizeof(DOCINFO);
- di.lpszDocName = "Foxit print test";
- int job_id = StartDoc(printer_dc, &di);
-
- StartPage(printer_dc);
-
- SetGraphicsMode(printer_dc, GM_ADVANCED);
- XFORM xform = {0, 0, 0, 0, 0, 0};
- xform.eM11 = xform.eM22 = 2;
- ModifyWorldTransform(printer_dc, &xform, MWT_LEFTMULTIPLY);
-
- int dc_width = GetDeviceCaps(printer_dc, PHYSICALWIDTH);
- int dc_height = GetDeviceCaps(printer_dc, PHYSICALHEIGHT);
- HDC metafile_dc = CreateEnhMetaFile(printer_dc, NULL, NULL, NULL);
- XFORM xform1 = {0, 0, 0, 0, 0, 0};
- xform1.eM11 = xform1.eM22 = 0.5;
- ModifyWorldTransform(metafile_dc, &xform1, MWT_LEFTMULTIPLY);
- FPDF_RenderPage(metafile_dc, page, 0, 0, dc_width, dc_height, 0, 0);
-
- HENHMETAFILE emf = CloseEnhMetaFile(metafile_dc);
-
- ENHMETAHEADER header = {0};
- GetEnhMetaFileHeader(emf, sizeof(header), &header);
-
- PlayEnhMetaFile(printer_dc, emf, (RECT *)&header.rclBounds);
-
- EndPage(printer_dc);
- EndDoc(printer_dc);
-
- DeleteEnhMetaFile(emf);
- DeleteDC(printer_dc);
-
-}
-
-void CReaderVCView::CreateLocalPath(CString &csPath)
-{
- csPath = "c://test.pdf";
-}
-
-BOOL CReaderVCView::HttpDataPost(CString csData, CString csAppName, CString csObject, CString csServer, CString csUserName, CString csPassword, INTERNET_PORT nPort , BOOL IsHTTPS, CString csContentType, CString csAddHeader, CString &csResponse)
-{
- DWORD retCode = 0;
- BOOL bRet = FALSE;
- TRY
- {
- CInternetSession sess(csAppName);
- CHttpConnection* pConnect = sess.GetHttpConnection(csServer, nPort, csUserName, csPassword);
- if (pConnect == NULL)
- return FALSE;
-
- DWORD dwRequestFlags = INTERNET_FLAG_EXISTING_CONNECT;
- if ( IsHTTPS == TRUE)
- dwRequestFlags |= INTERNET_FLAG_SECURE;
- CHttpFile* pHttpFile = pConnect->OpenRequest(CHttpConnection::HTTP_VERB_POST, csObject, NULL, 1, NULL, NULL, dwRequestFlags);
- if (pHttpFile != NULL)
- {
- CString strData = csData;
- DWORD dwLength = strData.GetLength();
-
- CString strHeaders;
- strHeaders.Format("Content-Type: %s\r\nContent-Length: %d\r\n", csContentType, dwLength);
- strHeaders += csAddHeader;
- pHttpFile->AddRequestHeaders(strHeaders);
- DWORD dwTotalLength = dwLength + strHeaders.GetLength();
-
-resend:
- bRet = pHttpFile->SendRequestEx(dwTotalLength);
- pHttpFile->Write(csData, dwLength);
-
- pHttpFile->QueryInfoStatusCode( retCode );
- if (HTTP_STATUS_OK == retCode) //succ
- {
- char buf[4096] = {0};
- UINT bytesRead = 0;
- while( ( bytesRead = pHttpFile->Read( buf, 4095 ) ) > 0 )
- {
- buf[bytesRead] = '\0';
- size_t aLen = strlen( buf ) + 1;
- int wLen = MultiByteToWideChar( 936, 0, buf, aLen, NULL, 0 );
-
- LPOLESTR lpw = new WCHAR [wLen];
- MultiByteToWideChar( 936, 0, buf, aLen, lpw, wLen );
- csResponse += lpw;
- delete [] lpw;
-
- memset( buf, 0, 4096 );
- }
- }
- bRet = pHttpFile->EndRequest();
- if (bRet)
- {
- // Handle any authentication dialogs.
- if (NeedAuth(pHttpFile))
- {
- DWORD dwErr;
- dwErr = pHttpFile->ErrorDlg(GetDesktopWindow(),
- bRet ? ERROR_SUCCESS : GetLastError(),
- FLAGS_ERROR_UI_FILTER_FOR_ERRORS |
- FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS |
- FLAGS_ERROR_UI_FLAGS_GENERATE_DATA,
- NULL);
- if (dwErr == ERROR_INTERNET_FORCE_RETRY)
- {
- goto resend;
- }
- else if(dwErr == 0)
- {
- bRet = FALSE;
- }
- }
- }
- pHttpFile->Close();
- delete pHttpFile;
- }
- pConnect->Close();
- delete pConnect;
- sess.Close();
- }
- CATCH_ALL(e)
- {
- return FALSE;
- }
- END_CATCH_ALL
- return bRet;
-}
-
-BOOL CReaderVCView::HttpDataPut(CString csData, CString csAppName, CString csObject, CString csServer, CString csUserName, CString csPassword, INTERNET_PORT nPort, BOOL IsHTTPS)
-{
- DWORD retCode = 0;
- BOOL bRet = FALSE;
- TRY
- {
- CInternetSession sess(csAppName);
- CHttpConnection* pConnect = sess.GetHttpConnection(csServer, nPort, csUserName, csPassword);
- if (pConnect == NULL)
- return FALSE;
-
- DWORD dwRequestFlags=INTERNET_FLAG_EXISTING_CONNECT;
- if ( IsHTTPS== TRUE)
- dwRequestFlags |= INTERNET_FLAG_SECURE;
- CHttpFile* pHttpFile = pConnect->OpenRequest(CHttpConnection::HTTP_VERB_PUT, csObject,NULL,1,NULL,NULL,dwRequestFlags);
- if (pHttpFile != NULL)
- {
-resend:
- CString strData = csData;
- DWORD dwTotalLength = strData.GetLength();
-
- bRet = pHttpFile->SendRequestEx(dwTotalLength);
- pHttpFile->Write(csData, dwTotalLength);
- bRet = pHttpFile->EndRequest();
- if (bRet)
- {
- // Handle any authentication dialogs.
- if (NeedAuth(pHttpFile))
- {
- DWORD dwErr;
- dwErr = pHttpFile->ErrorDlg(GetDesktopWindow(),
- bRet ? ERROR_SUCCESS : GetLastError(),
- FLAGS_ERROR_UI_FILTER_FOR_ERRORS |
- FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS |
- FLAGS_ERROR_UI_FLAGS_GENERATE_DATA,
- NULL
- );
- if (dwErr == ERROR_INTERNET_FORCE_RETRY)
- {
- goto resend;
- }
- else if(dwErr == 0)
- {
- bRet = FALSE;
- }
- }
- }
- pHttpFile->QueryInfoStatusCode( retCode );
- if (retCode != HTTP_STATUS_OK)
- {
- bRet = FALSE;
- }
- else
- bRet = TRUE;
-
- pHttpFile->Close();
- delete pHttpFile;
- }
- pConnect->Close();
- delete pConnect;
- sess.Close();
- }
- CATCH_ALL(e)
- {
- return FALSE;
- }
- END_CATCH_ALL
- return bRet;
-}
-
-BOOL CReaderVCView::NeedAuth(CHttpFile *pHttpFile)
-{
- // Get status code.
- DWORD dwStatus;
- DWORD cbStatus = sizeof(dwStatus);
- pHttpFile->QueryInfo
- (
- HTTP_QUERY_FLAG_NUMBER | HTTP_QUERY_STATUS_CODE,
- &dwStatus,
- &cbStatus,
- NULL
- );
- // fprintf (stderr, "Status: %d\n", dwStatus);
- // Look for 401 or 407.
- DWORD dwFlags;
- switch (dwStatus)
- {
- case HTTP_STATUS_DENIED:
- dwFlags = HTTP_QUERY_WWW_AUTHENTICATE;
- break;
- case HTTP_STATUS_PROXY_AUTH_REQ:
- dwFlags = HTTP_QUERY_PROXY_AUTHENTICATE;
- break;
- default:
- return FALSE;
- }
- // Enumerate the authentication types.
- BOOL fRet;
- char szScheme[64];
- DWORD dwIndex = 0;
- do
- {
- DWORD cbScheme = sizeof(szScheme);
- fRet = pHttpFile->QueryInfo
- (dwFlags, szScheme, &cbScheme, &dwIndex);
-
- //if (fRet)
- //fprintf (stderr, "Found auth scheme: %s\n", szScheme);
- }
- while (fRet);
- return TRUE;
-} \ No newline at end of file
diff --git a/xfa_test/FormFiller_Test/ReaderVCView.h b/xfa_test/FormFiller_Test/ReaderVCView.h
deleted file mode 100644
index 9e4e71b313..0000000000
--- a/xfa_test/FormFiller_Test/ReaderVCView.h
+++ /dev/null
@@ -1,375 +0,0 @@
-// ReaderVCView.h : interface of the CReaderVCView class
-//
-/////////////////////////////////////////////////////////////////////////////
-
-#if !defined(AFX_READERVCVIEW_H__9AFC449C_26D0_4906_ABAE_1298871862E2__INCLUDED_)
-#define AFX_READERVCVIEW_H__9AFC449C_26D0_4906_ABAE_1298871862E2__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-
-#include "ExportPage.h"
-#include "afxtempl.h"
-#include <wininet.h>
-#include <afxinet.h>
-#include <afxctl.h>
-
-typedef struct
-{
- CString m_strFind;
- int m_nFlag;
- int m_nDirection;
- BOOL m_bFirst;
- wchar_t *m_pCurFindBuf; //unicode code
- int m_nStartPageIndex; // the page index for starting find
- int m_nStartCharIndex; //start index
-}FindInfo;
-
-typedef struct
-{
- double m_dbLeft;
- double m_dbTop;
- double m_dbRight;
- double m_dbBottom;
-}PDFRect;
-
-#define IsALTpressed() (GetKeyState(VK_MENU) < 0)
-#define IsCTRLpressed() (GetKeyState(VK_CONTROL) < 0)
-#define IsSHIFTpressed() (GetKeyState(VK_SHIFT)&0x8000)
-#define IsINSERTpressed() (GetKeyState(VK_INSERT) & 0x01)
-// void Sample_PageToDevice(struct _FPDF_FORMFILLINFO* pThis,FPDF_PAGE page,double page_x,double page_y, int* device_x, int* device_y);
-//
-// void Sample_Invalidate(struct _FPDF_FORMFILLINFO* pThis,FPDF_PAGE page, double left, double top, double right, double bottom);
-//
-// void Sample_DeviceToPage(struct _FPDF_FORMFILLINFO* pThis,FPDF_PAGE page,int device_x, int device_y, double* page_x, double* page_y);
-//
-// void Sample_SetCaret(struct _FPDF_FORMFILLINFO* pThis,FPDF_PAGE page,double page_x, double page_y, int nWidth, int nHeight);
-//
-// void Sample_Release(struct _FPDF_FORMFILLINFO* pThis);
-//
-//
-// int Sample_SetTimer(struct _FPDF_FORMFILLINFO* pThis, int uElapse, TimerCallback lpTimerFunc);
-//
-// void Sample_KillTimer(struct _FPDF_FORMFILLINFO* pThis,int nID);
-//
-// void Sample_SetCursor(struct _FPDF_FORMFILLINFO* pThis,int nCursorType);
-//
-// void Sample_OnChange(struct _FPDF_FORMFILLINFO* pThis);
-//
-// FPDF_BOOL Sample_IsSHIFTKeyDown(struct _FPDF_FORMFILLINFO* pThis);
-//
-// FPDF_BOOL Sample_IsCTRLKeyDown(struct _FPDF_FORMFILLINFO* pThis);
-//
-// FPDF_BOOL Sample_IsALTKeyDown(struct _FPDF_FORMFILLINFO* pThis) ;
-//
-// FPDF_BOOL Sample_IsINSERTKeyDown(struct _FPDF_FORMFILLINFO* pThis) ;
-class CReaderVCDoc;
-
-typedef unsigned long FX_DWORD;
-static int CALLBACK FontEnumProc(const LOGFONTA *plf, const TEXTMETRICA *lpntme, FX_DWORD FontType, LPARAM lParam)
-{
- FPDF_AddInstalledFont((void*)lParam, plf->lfFaceName, plf->lfCharSet);
- return 1;
-}
-#define FXDWORD_FROM_MSBFIRST2(i) (((unsigned char)(i) << 24) | ((unsigned char)((i) >> 8) << 16) | ((unsigned char)((i) >> 16) << 8) | (unsigned char)((i) >> 24))
-class CSampleFontInfo : public FPDF_SYSFONTINFO
-{
-public:
- CSampleFontInfo()
- {
- m_hDC = CreateDCA("DISPLAY", NULL, NULL, NULL);
- }
-
- HDC m_hDC;
-
- void ReleaseImpl()
- {
- DeleteDC(m_hDC);
- delete this;
- }
-
- void EnumFontsImpl(void* pMapper)
- {
- LOGFONTA lf;
- lf.lfCharSet = DEFAULT_CHARSET;
- lf.lfFaceName[0] = 0;
- lf.lfPitchAndFamily = 0;
- ::EnumFontFamiliesExA(m_hDC, &lf, FontEnumProc, (LPARAM)pMapper, 0);
- }
-
- void* MapFontImpl(int weight, int bItalic, int charset, int pitch_family, const char* face, int* bExact)
- {
- return ::CreateFontA(-10, 0, 0, 0, weight, bItalic, 0, 0,
- charset, OUT_TT_ONLY_PRECIS, 0, 0, pitch_family, face);
- }
-
- unsigned long GetFontDataImpl(void* hFont, unsigned int table, unsigned char* buffer, unsigned long buf_size)
- {
- HFONT hOldFont = (HFONT)::SelectObject(m_hDC, (HFONT)hFont);
- buf_size = ::GetFontData(m_hDC, FXDWORD_FROM_MSBFIRST2(table), 0, buffer, buf_size);
- ::SelectObject(m_hDC, hOldFont);
- if (buf_size == GDI_ERROR) return 0;
- return buf_size;
- }
-
- unsigned long GetFaceNameImpl(void* hFont, char* buffer, unsigned long buf_size)
- {
- HFONT hOldFont = (HFONT)::SelectObject(m_hDC, (HFONT)hFont);
- unsigned long ret = ::GetTextFaceA(m_hDC, buf_size, buffer);
- ::SelectObject(m_hDC, hOldFont);
- if (buf_size == GDI_ERROR) return 0;
- return ret;
- }
-
- int GetFontCharsetImpl(void* hFont)
- {
- TEXTMETRIC tm;
- HFONT hOldFont = (HFONT)::SelectObject(m_hDC, (HFONT)hFont);
- ::GetTextMetrics(m_hDC, &tm);
- ::SelectObject(m_hDC, hOldFont);
- return tm.tmCharSet;
- }
-
- void DeleteFontImpl(void* hFont)
- {
- ::DeleteObject(hFont);
- }
-};
-
-typedef struct _FPDF_FILE
-{
- FPDF_FILEHANDLER fileHandler;
- FILE* file;
-}FPDF_FILE;
-
-class CReaderVCView : public CView, public FPDF_FORMFILLINFO
-{
-protected: // create from serialization only
- CReaderVCView();
- DECLARE_DYNCREATE(CReaderVCView)
-
-// Attributes
-public:
- CReaderVCDoc* GetDocument();
- CChildFrame *m_pFram;
-// Operations
-public:
-
-// Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CReaderVCView)
- public:
- virtual void OnDraw(CDC* pDC); // overridden to draw this view
- virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
- virtual void OnInitialUpdate();
- virtual BOOL PreTranslateMessage(MSG* pMsg);
- protected:
- virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
- virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
- virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
- virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
- //}}AFX_VIRTUAL
-
-// Implementation
-public:
- CExportPage* m_pExportPageDlg;
- FPDF_PAGE GetPage(){ return m_pPage;}
- void SyncScroll();
- CRect SelectSegment(CPoint pt_lt, CPoint pt_rb);
- void GetRects(int nStart, int nEnd);
- void CreateCaret(CPoint pt);
- BOOL GetCharIndexByPoint(CPoint pt, int &nIndex);
- void LoadMyCursor(int nflag = 0);
- void DeleteAllRect();
- void DrawAllRect(CDC *pDC);
- void DrawReverse(CDC *pDC, CRect rect);
- void FindNext(int nDirection);
- void FindText(CString strFind, BOOL bCase, BOOL bWholeword, int Direction);
- void ScalPage(double dbScal);
- void GotoPage(int index);
- BOOL SetPDFDocument(FPDF_DOCUMENT pDoc, int nPageNum);
- void DrawPage(int nRotate, CDC *pDC);
- void SetPageMetrics(FPDF_PAGE pPage);
-
- void SetScalFactor(double dbScal);
- void GetNewPageSize(int &nsizeX, int &nsizeY);
- BOOL LoadPDFPage(FPDF_DOCUMENT doc, int nIndex, CPoint pos = CPoint(0,0));
-
- FPDF_DOCUMENT GetPDFDoc(){ return m_pDoc;}
- int GetTotalPages(){ return m_nTotalPage;}
- BOOL DeviceToPage(CPoint pt, double& page_x, double& page_y);
- BOOL PageToDevice(double page_x, double page_y, CPoint& pt);
- int GetCurrentPageIndex() { return m_nPageIndex; }
- static BOOL HttpDataPut(CString csData, CString csAppName, CString csObject, CString csServer,
- CString csUserName, CString csPassword, INTERNET_PORT nPort, BOOL IsHTTPS);
- static BOOL NeedAuth(CHttpFile *pHttpFile);
- static BOOL HttpDataPost(CString csData, CString csAppName, CString csObject, CString csServer, CString csUserName,
- CString csPassword, INTERNET_PORT nPort , BOOL IsHTTPS, CString csContentType, CString csAddHeader, CString &csResponse);
- static void CreateLocalPath(CString &csPath);
-
- virtual ~CReaderVCView();
-#ifdef _DEBUG
- virtual void AssertValid() const;
- virtual void Dump(CDumpContext& dc) const;
-#endif
-
-protected:
-public:
- void PageToDeviceImpl(FPDF_PAGE page,double page_x,double page_y, int* device_x, int* device_y);
- void DeviceToPageImpl(FPDF_PAGE page,int device_x, int device_y, double* page_x, double* page_y);
- void InvalidateImpl(FPDF_PAGE page, double left, double top, double right, double bottom);
- void OutputSelectedRectImpl(FPDF_PAGE page, double left, double top, double right, double bottom);
- void SetCaretImpl(FPDF_PAGE page,double page_x, double page_y, int nWidth, int nHeight);
- void ReleaseImpl();
- int SetTimerImpl(int uElapse, TimerCallback lpTimerFunc);
- void KillTimerImpl(int nID);
- FPDF_SYSTEMTIME GetLocalTimeImpl();
- void SetCurorImpl(int nCursorType);
- void ExecuteNamedActionImpl(FPDF_BYTESTRING namedaction);
- void OnChangeImpl();
- bool IsSHIFTKeyDownImpl();
- bool IsCTRLKeyDownImpl();
- bool IsALTKeyDownImpl();
- bool IsINSERTKeyDownImpl();
- BOOL SubmitFormImpl(void* pBuffer, int nLength, CString strURL);
- FPDF_PAGE GetPageImpl(FPDF_DOCUMENT document,int nPageIndex);
- int GetRotationImpl(FPDF_PAGE page);
- CString GetFilePath();
- FPDF_PAGE GetCurrentPageImpl(FPDF_DOCUMENT document);
-// friend FPDF_DOCUMENT _FPDF_GetCurDocument(struct _FPDF_FORMFILLINFO* pThis);
-// friend FPDF_PAGE _FPDF_GetCurPage(struct _FPDF_FORMFILLINFO* pThis);
-private:
-// FPDF_APP m_App;
-// FPDF_FORMFILLINFO m_formFiledInfo;
-private:
-// FPDF_APP GetFPDFApp() {return m_App;}
- unsigned int ComposeFlag();
-private:
- CMap<int, int, FPDF_PAGE, FPDF_PAGE> m_pageMap;
- FPDF_FORMHANDLE m_pApp;
- FPDF_BITMAP m_bmp;
- //for render pdf
- FPDF_DOCUMENT m_pDoc;
- FPDF_PAGE m_pPage;
- int m_nTotalPage;
- int m_nRotateFlag;
- double m_dbScaleFactor;
- int m_nPageIndex;
- double m_dbPageWidth;
- double m_dbPageHeight;
- int m_nStartX;
- int m_nStartY;
- int m_nActualSizeX;
- int m_nActualSizeY;
-
- //for search text
- FPDF_TEXTPAGE m_pTextPage;
- FindInfo m_FindInfo;
- FPDF_SCHHANDLE m_pSCHHandle;
- PDFRect * m_rtFind;
- int m_nRectNum;
-
- //for select text
- BOOL m_bSelect;
- BOOL m_bHand;
- BOOL m_bSnap;
- BOOL m_bHasChar; //whether can get a char when left button be clicked
- CPoint m_ptLBDown;
- CPoint m_ptLBUp;
- CPoint m_ptOld;
-
- int m_nStartIndex; //char index
- int m_nOldIndex;
- int m_nEndIndex;
- CArray <PDFRect, PDFRect> m_rtArray;
- CRect m_rtOld;
-
- //
- int m_nPosH;
- int m_nPosV;
-
- // for links
- FPDF_PAGELINK m_pLink;
-
- BOOL m_bBookmark;
-
-public:
- wchar_t* m_pwsResponse;
-
-private:
-
- CArray<CRect, CRect&> m_SelectArray;
- static CMap<int, int,TimerCallback, TimerCallback> m_mapTimerFuns;
-public:
- static void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime )
- {
- TimerCallback callback = NULL;
- m_mapTimerFuns.Lookup(idEvent, callback);
- if(callback)
- (*callback)(idEvent);
- }
-// Generated message map functions
-protected:
- //{{AFX_MSG(CReaderVCView)
- afx_msg void OnDocFirstpage();
- afx_msg void OnDocGotopage();
- afx_msg void OnDocLastpage();
- afx_msg void OnDocNextpage();
- afx_msg void OnDocPrepage();
- afx_msg void OnClockwise();
- afx_msg void OnCounterclockwise();
- afx_msg void OnViewActualSize();
- afx_msg void OnViewFitPage();
- afx_msg void OnViewFitWidth();
- afx_msg void OnViewZoomIn();
- afx_msg void OnViewZoomOut();
- afx_msg void OnViewZoomTo();
- afx_msg void OnEditFind();
- afx_msg void OnFilePrint();
- afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
- afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
- afx_msg void OnMouseMove(UINT nFlags, CPoint point);
- afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
- afx_msg void OnToolSnapshot();
- afx_msg void OnToolSelect();
- afx_msg void OnToolHand();
- afx_msg void OnToolPdf2txt();
- afx_msg void OnSize(UINT nType, int cx, int cy);
- afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
- afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
- afx_msg void OnToolExtractlinks();
- afx_msg void OnDestroy();
- afx_msg void OnUpdateDocFirstpage(CCmdUI* pCmdUI);
- afx_msg void OnUpdateDocLastpage(CCmdUI* pCmdUI);
- afx_msg void OnUpdateDocNextpage(CCmdUI* pCmdUI);
- afx_msg void OnUpdateDocPrepage(CCmdUI* pCmdUI);
- afx_msg void OnUpdateToolHand(CCmdUI* pCmdUI);
- afx_msg void OnUpdateToolSnapshot(CCmdUI* pCmdUI);
- afx_msg void OnUpdateToolSelect(CCmdUI* pCmdUI);
- afx_msg void OnViewBookmark();
- afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
- afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
- afx_msg void OnEditCopy();
- afx_msg void OnRenderbitmap();
- afx_msg void OnExportPdfToBitmap();
- afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
- afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
- afx_msg void OnFileSave();
- afx_msg void OnTestJS();
- afx_msg void OnPrintMetalfile();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
-};
-
-#ifndef _DEBUG // debug version in ReaderVCView.cpp
-inline CReaderVCDoc* CReaderVCView::GetDocument()
- { return (CReaderVCDoc*)m_pDocument; }
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-
-//{{AFX_INSERT_LOCATION}}
-// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
-
-#endif // !defined(AFX_READERVCVIEW_H__9AFC449C_26D0_4906_ABAE_1298871862E2__INCLUDED_)
diff --git a/xfa_test/FormFiller_Test/StdAfx.cpp b/xfa_test/FormFiller_Test/StdAfx.cpp
deleted file mode 100644
index c358cc0c6d..0000000000
--- a/xfa_test/FormFiller_Test/StdAfx.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-// stdafx.cpp : source file that includes just the standard includes
-// ReaderVC.pch will be the pre-compiled header
-// stdafx.obj will contain the pre-compiled type information
-
-#include "stdafx.h"
-
-
-
diff --git a/xfa_test/FormFiller_Test/StdAfx.h b/xfa_test/FormFiller_Test/StdAfx.h
deleted file mode 100644
index 7df16092d5..0000000000
--- a/xfa_test/FormFiller_Test/StdAfx.h
+++ /dev/null
@@ -1,99 +0,0 @@
-// stdafx.h : include file for standard system include files,
-// or project specific include files that are used frequently, but
-// are changed infrequently
-//
-
-#if !defined(AFX_STDAFX_H__2BC4C1DE_4165_4967_AC3E_AE2EA2A4D2FD__INCLUDED_)
-#define AFX_STDAFX_H__2BC4C1DE_4165_4967_AC3E_AE2EA2A4D2FD__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-
-#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
-
-#include <afxwin.h> // MFC core and standard components
-#include <afxext.h> // MFC extensions
-#include <afxdisp.h> // MFC Automation classes
-#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
-#include <afxinet.h>
-#ifndef _AFX_NO_AFXCMN_SUPPORT
-#include <afxcmn.h> // MFC support for Windows Common Controls
-#endif // _AFX_NO_AFXCMN_SUPPORT
-
-
-#include "../../include/fpdfview.h"
-#include "../../include/fpdfdoc.h"
-#include "../../include/fpdftext.h"
-#include "../../include/fpdfformfill.h"
-#include "../../include/fpdf_sysfontinfo.h"
-#include "../../include/fpdfsave.h"
-#include <afxcview.h>
-#include "afxtempl.h"
-
-#include "../../include/fpdfedit.h"
-
-#ifdef _DEBUG
- #pragma comment(lib, "../../lib/dbg_w32_vc10/formfiller[dbg,w32,vc10].lib")
- #pragma comment(lib, "../../lib/dbg_w32_vc10/fpdfsdk[dbg,w32,vc10].lib")
- #pragma comment(lib, "../../lib/dbg_w32_vc10/fxedit[dbg,w32,vc10].lib")
- #pragma comment(lib, "../../lib/dbg_w32_vc10/javascript[dbg,w32,vc10].lib")
- #pragma comment(lib, "../../lib/dbg_w32_vc10/jsapi[dbg,w32,vc10].lib")
- #pragma comment(lib, "../../lib/dbg_w32_vc10/pdfwindow[dbg,w32,vc10].lib")
-// #pragma comment(lib, "../../lib/dbg_w32_vc10/foxitopenpdf.lib")
-
-// #pragma comment(lib, "../../../../../../v8/build/Debug/lib/icui18n.lib")
-// #pragma comment(lib, "../../../../../../v8/build/Debug/lib/icuuc.lib")
-// #pragma comment(lib, "../../../../../../v8/build/Debug/lib/v8_base.ia32.lib")
-// #pragma comment(lib, "../../../../../../v8/build/Debug/lib/v8_nosnapshot.ia32.lib")
-// #pragma comment(lib, "../../../../../../v8/build/Debug/lib/v8_snapshot.lib")
- #pragma comment(lib, "../../../v8/build/Debug/lib/icui18n.lib")
- #pragma comment(lib, "../../../v8/build/Debug/lib/icuuc.lib")
- #pragma comment(lib, "../../../v8/build/Debug/lib/v8_base.ia32.lib")
- #pragma comment(lib, "../../../v8/build/Debug/lib/v8_nosnapshot.ia32.lib")
- #pragma comment(lib, "../../../v8/build/Debug/lib/v8_snapshot.lib")
-
- #pragma comment(lib, "../../../fxlib/fxcore/lib/dbg/x86_vc10/fxcrt[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fxcore/lib/dbg/x86_vc10/fxge[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fxcore/lib/dbg/x86_vc10/fpdfdoc[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fxcore/lib/dbg/x86_vc10/fpdfapi[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fxcore/lib/dbg/x86_vc10/fxcodec[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fxcore/lib/dbg/x86_vc10/fpdftext[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fxcore/lib/dbg/x86_vc10/fdrm[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fxcore/lib/dbg/x86_vc10/fxmath[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fxcore/lib/dbg/x86_vc10/fxbarcode[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fxcore/lib/dbg/x86_vc10/fxhal[dbg_x86_vc10].lib")
-
- #pragma comment(lib, "../../../fxlib/fxjse/lib/dbg/x86_vc10/fxjse_bare[dbg_x86_vc10].lib")
-
- #pragma comment(lib, "../../../fxlib/fwl/lib/dbg/x86_vc10/fwlbasewidget[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fwl/lib/dbg/x86_vc10/fwlcore[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fwl/lib/dbg/x86_vc10/fwltheme[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fwl/lib/dbg/x86_vc10/fwllightwidget[dbg_x86_vc10].lib")
-
- #pragma comment(lib, "../../../fxlib/fxgraphics/lib/dbg/x86_vc10/fxgraphics[dbg_x86_vc10].lib")
-
- #pragma comment(lib, "../../../fxlib/fgas/lib/dbg/x86_vc10/fgas[dbg_x86_vc10].lib")
-
- #pragma comment(lib, "../../../fxlib/fee/lib/dbg/x86_vc10/fees[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fee/lib/dbg/x86_vc10/fx_wordbreaks[dbg_x86_vc10].lib")
-
- #pragma comment(lib, "../../../fxlib/fdp/lib/dbg/x86_vc10/fde[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fdp/lib/dbg/x86_vc10/fdetto[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fdp/lib/dbg/x86_vc10/fdexml[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fdp/lib/dbg/x86_vc10/fdecss[dbg_x86_vc10].lib")
-
- #pragma comment(lib, "../../../fxlib/fxfa/lib/dbg/x86_vc10/fxfa_app[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fxfa/lib/dbg/x86_vc10/fxfa_fm2js[dbg_x86_vc10].lib")
- #pragma comment(lib, "../../../fxlib/fxfa/lib/dbg/x86_vc10/fxfa_parser[dbg_x86_vc10].lib")
-
-#else
- #pragma comment(lib, "../../lib/rel_w32_vc6/fpdfsdk.lib")
-#endif
-//#pragma comment(lib, "../../lib/fpdfsdk.dll")
-
-//#include "fpdfsdk_ext_wh.h"
-//{{AFX_INSERT_LOCATION}}
-// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
-
-#endif // !defined(AFX_STDAFX_H__2BC4C1DE_4165_4967_AC3E_AE2EA2A4D2FD__INCLUDED_)
diff --git a/xfa_test/FormFiller_Test/TestJsDlg.cpp b/xfa_test/FormFiller_Test/TestJsDlg.cpp
deleted file mode 100644
index 30fb3a2efb..0000000000
--- a/xfa_test/FormFiller_Test/TestJsDlg.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-// TestJsDlg.cpp : implementation file
-//
-
-#include "stdafx.h"
-#include "readervc.h"
-#include "TestJsDlg.h"
-#include "../../include/fpdfformfill.h"
-
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-// CTestJsDlg dialog
-
-
-CTestJsDlg::CTestJsDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CTestJsDlg::IDD, pParent)
-{
- //{{AFX_DATA_INIT(CTestJsDlg)
- m_js = _T("");
- //}}AFX_DATA_INIT
-}
-
-
-void CTestJsDlg::DoDataExchange(CDataExchange* pDX)
-{
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CTestJsDlg)
- DDX_Text(pDX, IDC_EDIT1, m_js);
- //}}AFX_DATA_MAP
-}
-
-
-BEGIN_MESSAGE_MAP(CTestJsDlg, CDialog)
- //{{AFX_MSG_MAP(CTestJsDlg)
- ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
- //}}AFX_MSG_MAP
-END_MESSAGE_MAP()
-
-/////////////////////////////////////////////////////////////////////////////
-// CTestJsDlg message handlers
-
-void CTestJsDlg::OnButton1()
-{
- // TODO: Add your control notification handler code here
- UpdateData(TRUE);
- LPCTSTR lpStr = m_js.GetBuffer(m_js.GetLength());
- int nLen = MultiByteToWideChar(CP_ACP, 0, lpStr, m_js.GetLength(), NULL, 0);
- wchar_t* pbuf = new wchar_t[nLen+1];
- MultiByteToWideChar(CP_ACP, 0, lpStr, m_js.GetLength(), pbuf, nLen);
- pbuf[nLen] = 0;
- m_js.ReleaseBuffer();
-// RunJS(m_handle,pbuf);
- delete[] pbuf;
-}
diff --git a/xfa_test/FormFiller_Test/TestJsDlg.h b/xfa_test/FormFiller_Test/TestJsDlg.h
deleted file mode 100644
index b642937abe..0000000000
--- a/xfa_test/FormFiller_Test/TestJsDlg.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#if !defined(AFX_TESTJSDLG_H__084897F0_A03A_4D55_BDA2_98D40FB98A4F__INCLUDED_)
-#define AFX_TESTJSDLG_H__084897F0_A03A_4D55_BDA2_98D40FB98A4F__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-// TestJsDlg.h : header file
-//
-
-/////////////////////////////////////////////////////////////////////////////
-// CTestJsDlg dialog
-
-class CTestJsDlg : public CDialog
-{
-// Construction
-public:
- CTestJsDlg(CWnd* pParent = NULL); // standard constructor
- void init(void* handle) {m_handle = handle;}
-// Dialog Data
- //{{AFX_DATA(CTestJsDlg)
- enum { IDD = IDD_TEST_JS };
- CString m_js;
- //}}AFX_DATA
-
-
-// Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CTestJsDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
-
-// Implementation
-protected:
- void * m_handle;
- // Generated message map functions
- //{{AFX_MSG(CTestJsDlg)
- afx_msg void OnButton1();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
-};
-
-//{{AFX_INSERT_LOCATION}}
-// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
-
-#endif // !defined(AFX_TESTJSDLG_H__084897F0_A03A_4D55_BDA2_98D40FB98A4F__INCLUDED_)
diff --git a/xfa_test/FormFiller_Test/ZoomDlg.cpp b/xfa_test/FormFiller_Test/ZoomDlg.cpp
deleted file mode 100644
index 65a19fe6f9..0000000000
--- a/xfa_test/FormFiller_Test/ZoomDlg.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-// ZoomDlg.cpp : implementation file
-//
-
-#include "stdafx.h"
-#include "ReaderVC.h"
-#include "ZoomDlg.h"
-
-#include "MainFrm.h"
-#include "ChildFrm.h"
-#include "ReaderVCView.h"
-
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-// CZoomDlg dialog
-
-
-CZoomDlg::CZoomDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CZoomDlg::IDD, pParent)
-{
- //{{AFX_DATA_INIT(CZoomDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
-}
-
-
-void CZoomDlg::DoDataExchange(CDataExchange* pDX)
-{
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CZoomDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
-}
-
-
-BEGIN_MESSAGE_MAP(CZoomDlg, CDialog)
- //{{AFX_MSG_MAP(CZoomDlg)
- //}}AFX_MSG_MAP
-END_MESSAGE_MAP()
-
-/////////////////////////////////////////////////////////////////////////////
-// CZoomDlg message handlers
-
-void CZoomDlg::OnCancel()
-{
- // TODO: Add extra cleanup here
-
- CDialog::OnCancel();
-}
-
-void CZoomDlg::OnOK()
-{
- // TODO: Add extra validation here
- CComboBox *pCmb = (CComboBox *)GetDlgItem(IDC_COMBO1);
- int i = pCmb->GetCurSel();
- int nScal = pCmb->GetItemData(i);
- double dbScal = nScal / 100.0f;
- m_pView->ScalPage(dbScal);
- CDialog::OnOK();
-}
-
-BOOL CZoomDlg::OnInitDialog()
-{
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- m_pView = (CReaderVCView *)(((CChildFrame *)((CMainFrame *)AfxGetMainWnd())->GetActiveFrame())->GetActiveView());
- CComboBox *pCmb = (CComboBox *)GetDlgItem(IDC_COMBO1);
- pCmb->AddString("-----25%-----");
- pCmb->SetItemData(0, 25);
- pCmb->AddString("-----50%-----");
- pCmb->SetItemData(1, 50);
- pCmb->AddString("-----75%-----");
- pCmb->SetItemData(3, 75);
- pCmb->AddString("-----100%----");
- pCmb->SetItemData(3, 100);
- pCmb->AddString("-----125%----");
- pCmb->SetItemData(4, 125);
- pCmb->AddString("-----200%----");
- pCmb->SetItemData(5, 200);
- pCmb->AddString("-----300%----");
- pCmb->SetItemData(6, 300);
- pCmb->AddString("-----400%----");
- pCmb->SetItemData(7, 400);
- pCmb->AddString("-----600%----");
- pCmb->SetItemData(8, 600);
- pCmb->AddString("-----800%----");
- pCmb->SetItemData(9, 800);
- pCmb->AddString("-----1200%----");
- pCmb->SetItemData(10, 1200);
- pCmb->AddString("-----1600%---");
- pCmb->SetItemData(11, 160);
- pCmb->AddString("-----3200%---");
- pCmb->SetItemData(12, 3200);
- pCmb->AddString("-----6400%----");
- pCmb->SetItemData(13, 6400);
- this->SetDlgItemTextA(IDC_COMBO1, "Select Zoom Factor");
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
-}
diff --git a/xfa_test/FormFiller_Test/ZoomDlg.h b/xfa_test/FormFiller_Test/ZoomDlg.h
deleted file mode 100644
index 15521c605e..0000000000
--- a/xfa_test/FormFiller_Test/ZoomDlg.h
+++ /dev/null
@@ -1,48 +0,0 @@
-#if !defined(AFX_ZOOMDLG_H__B244E9E1_5278_4244_9D19_7307E1B76C15__INCLUDED_)
-#define AFX_ZOOMDLG_H__B244E9E1_5278_4244_9D19_7307E1B76C15__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-// ZoomDlg.h : header file
-//
-
-/////////////////////////////////////////////////////////////////////////////
-// CZoomDlg dialog
-class CReaderVCView;
-class CZoomDlg : public CDialog
-{
-// Construction
-public:
- CZoomDlg(CWnd* pParent = NULL); // standard constructor
-
-// Dialog Data
- //{{AFX_DATA(CZoomDlg)
- enum { IDD = IDD_DLG_ZOOMTO };
- // NOTE: the ClassWizard will add data members here
- //}}AFX_DATA
-
-
-// Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CZoomDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
-
-// Implementation
-protected:
- CReaderVCView *m_pView;
- // Generated message map functions
- //{{AFX_MSG(CZoomDlg)
- virtual void OnCancel();
- virtual void OnOK();
- virtual BOOL OnInitDialog();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
-};
-
-//{{AFX_INSERT_LOCATION}}
-// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
-
-#endif // !defined(AFX_ZOOMDLG_H__B244E9E1_5278_4244_9D19_7307E1B76C15__INCLUDED_)
diff --git a/xfa_test/FormFiller_Test/res/BigHandCursor.cur b/xfa_test/FormFiller_Test/res/BigHandCursor.cur
deleted file mode 100644
index c03bff08bd..0000000000
--- a/xfa_test/FormFiller_Test/res/BigHandCursor.cur
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/Rd_SelText_Icon.bmp b/xfa_test/FormFiller_Test/res/Rd_SelText_Icon.bmp
deleted file mode 100644
index 0a2b2f4858..0000000000
--- a/xfa_test/FormFiller_Test/res/Rd_SelText_Icon.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/Rd_SelText_Icon_Dis.bmp b/xfa_test/FormFiller_Test/res/Rd_SelText_Icon_Dis.bmp
deleted file mode 100644
index 6e0e6742c3..0000000000
--- a/xfa_test/FormFiller_Test/res/Rd_SelText_Icon_Dis.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/ReaderVC.ico b/xfa_test/FormFiller_Test/res/ReaderVC.ico
deleted file mode 100644
index 7eef0bcbe6..0000000000
--- a/xfa_test/FormFiller_Test/res/ReaderVC.ico
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/ReaderVC.rc2 b/xfa_test/FormFiller_Test/res/ReaderVC.rc2
deleted file mode 100644
index c81833479a..0000000000
--- a/xfa_test/FormFiller_Test/res/ReaderVC.rc2
+++ /dev/null
@@ -1,13 +0,0 @@
-//
-// READERVC.RC2 - resources Microsoft Visual C++ does not edit directly
-//
-
-#ifdef APSTUDIO_INVOKED
- #error this file is not editable by Microsoft Visual C++
-#endif //APSTUDIO_INVOKED
-
-
-/////////////////////////////////////////////////////////////////////////////
-// Add manually edited resources here...
-
-/////////////////////////////////////////////////////////////////////////////
diff --git a/xfa_test/FormFiller_Test/res/ReaderVCDoc.ico b/xfa_test/FormFiller_Test/res/ReaderVCDoc.ico
deleted file mode 100644
index 2a1f1ae6ef..0000000000
--- a/xfa_test/FormFiller_Test/res/ReaderVCDoc.ico
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/SmallHandCursor.cur b/xfa_test/FormFiller_Test/res/SmallHandCursor.cur
deleted file mode 100644
index 7bdff73ab3..0000000000
--- a/xfa_test/FormFiller_Test/res/SmallHandCursor.cur
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/Toolbar.bmp b/xfa_test/FormFiller_Test/res/Toolbar.bmp
deleted file mode 100644
index 9598028a77..0000000000
--- a/xfa_test/FormFiller_Test/res/Toolbar.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/bookmark.bmp b/xfa_test/FormFiller_Test/res/bookmark.bmp
deleted file mode 100644
index c4a109cc7c..0000000000
--- a/xfa_test/FormFiller_Test/res/bookmark.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/bound.cur b/xfa_test/FormFiller_Test/res/bound.cur
deleted file mode 100644
index acb7f7a4bf..0000000000
--- a/xfa_test/FormFiller_Test/res/bound.cur
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/point.cur b/xfa_test/FormFiller_Test/res/point.cur
deleted file mode 100644
index deed42a4ed..0000000000
--- a/xfa_test/FormFiller_Test/res/point.cur
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_actual_size.bmp b/xfa_test/FormFiller_Test/res/tool_actual_size.bmp
deleted file mode 100644
index ae66eec0b5..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_actual_size.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_bookmark1.bmp b/xfa_test/FormFiller_Test/res/tool_bookmark1.bmp
deleted file mode 100644
index f8097551a9..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_bookmark1.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_clockwise.bmp b/xfa_test/FormFiller_Test/res/tool_clockwise.bmp
deleted file mode 100644
index 2dc70bf8ca..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_clockwise.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_counterclockwise.bmp b/xfa_test/FormFiller_Test/res/tool_counterclockwise.bmp
deleted file mode 100644
index 3b35661051..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_counterclockwise.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_first.bmp b/xfa_test/FormFiller_Test/res/tool_first.bmp
deleted file mode 100644
index 30601ae878..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_first.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_fit_page.bmp b/xfa_test/FormFiller_Test/res/tool_fit_page.bmp
deleted file mode 100644
index 04eaeb9240..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_fit_page.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_fit_width.bmp b/xfa_test/FormFiller_Test/res/tool_fit_width.bmp
deleted file mode 100644
index bd21478aba..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_fit_width.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hand1.bmp b/xfa_test/FormFiller_Test/res/tool_hand1.bmp
deleted file mode 100644
index 9b15294df1..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hand1.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_about2.bmp b/xfa_test/FormFiller_Test/res/tool_hot_about2.bmp
deleted file mode 100644
index af274d42fa..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_about2.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_actual_size.bmp b/xfa_test/FormFiller_Test/res/tool_hot_actual_size.bmp
deleted file mode 100644
index 6465e2158f..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_actual_size.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_bookmark1.bmp b/xfa_test/FormFiller_Test/res/tool_hot_bookmark1.bmp
deleted file mode 100644
index f73dd35999..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_bookmark1.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_clockwise.bmp b/xfa_test/FormFiller_Test/res/tool_hot_clockwise.bmp
deleted file mode 100644
index d48f3aab48..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_clockwise.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_counterclockwise.bmp b/xfa_test/FormFiller_Test/res/tool_hot_counterclockwise.bmp
deleted file mode 100644
index 3539366bce..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_counterclockwise.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_first.bmp b/xfa_test/FormFiller_Test/res/tool_hot_first.bmp
deleted file mode 100644
index 266018a79a..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_first.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_first.xpm b/xfa_test/FormFiller_Test/res/tool_hot_first.xpm
deleted file mode 100644
index f89ac29059..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_first.xpm
+++ /dev/null
@@ -1,109 +0,0 @@
-/* XPM */
-static char *tool_hot_first[] = {
-/* columns rows colors chars-per-pixel */
-"24 24 79 1",
-" c #3c659e",
-". c #3e689e",
-"X c #3b65a0",
-"o c #3e69a3",
-"O c #42679d",
-"+ c #466b9e",
-"@ c #4c6c9c",
-"# c #466ea3",
-"$ c #486da2",
-"% c #4473aa",
-"& c #4c74a6",
-"* c #4874ab",
-"= c #4b7aaf",
-"- c #4f7cb1",
-"; c #5072a3",
-": c #5678a7",
-"> c #527caf",
-", c #5c7da8",
-"< c green",
-"1 c #5d80ab",
-"2 c #5785b4",
-"3 c #5d88b6",
-"4 c #6487b0",
-"5 c #648db6",
-"6 c #678fba",
-"7 c #6c8eb5",
-"8 c #6593be",
-"9 c #6e90b5",
-"0 c #6e96bc",
-"q c #738aab",
-"w c #7b8da9",
-"e c #738cb0",
-"r c #7294b7",
-"t c #729abd",
-"y c #7a93b6",
-"u c #7e98ba",
-"i c #6694c0",
-"p c #759cc1",
-"a c #7c9fc3",
-"s c #74a1c6",
-"d c #76a4ca",
-"f c #7aa1c3",
-"g c #7ba7c9",
-"h c #7fa9cb",
-"j c #7faed0",
-"k c #8694ac",
-"l c #879db6",
-"z c #8a9db6",
-"x c #939daf",
-"c c #959fb1",
-"v c #8aa1b9",
-"b c #9ca4b3",
-"n c #a6acb6",
-"m c #b2b5ba",
-"M c #b8babd",
-"N c #87afcd",
-"B c #89b2cf",
-"V c #84b4d3",
-"C c #88b6d5",
-"Z c #91abc7",
-"A c #97b1cd",
-"S c #90bdda",
-"D c #a8b6cb",
-"F c #92c2dd",
-"G c #9cc8e0",
-"H c #a0c0d7",
-"J c #a6cfe6",
-"K c #a6d3e8",
-"L c #aad5ea",
-"P c #b0cfe2",
-"I c #b9dbeb",
-"U c #cac8c4",
-"Y c #c3dfed",
-"T c #c5e1ef",
-"R c #cbe2ef",
-"E c #d5e4ef",
-"W c #d2e7f2",
-"Q c #e8f6fa",
-"! c #feffff",
-/* pixels */
-"<<<<<<<<<<<<<<<<<<<<<<<<",
-"<<<<<<<<<<<<<<<<<<<<<<<<",
-"<<<<<<<<<<<<<<<<<<<<<<<<",
-"<<<<<<<<<<<<<<<<<<<<<<<<",
-"<<<<zlvz<<<<<<<<<<D<<<<<",
-"<<<<7NKp<<<<<<<<<k,<<<<<",
-"<<<<rCLa<<<<<<<<wNN<<<<<",
-"<<<<9hGt<<<<<<MqBKf<<<<<",
-"<<<<7gF0<<<<<nePJS0<<<<<",
-"<<<<7sV5<<<<xuWICV5<<<<<",
-"<<<<40d><<UkZQYVjd1<<<<<",
-"<<<<138><<kA!RVVd8><<<<<",
-"<<<<:>3&<<nyETVd83&<<<<<",
-"<<<<;*-$<<<mqHSi2>#<<<<<",
-"<<<<&#*+<<<<<q68-*#<<<<<",
-"<<<<@o%+<<<<<Uw&=%#<<<<<",
-"<<<<+X%+<<<<<<<k#%#<<<<<",
-"<<<<OX%.<<<<<<<<c+ <<<<<",
-"<<<<@ +@<<<<<<<<<b@<<<<<",
-"<<<<<<<<<<<<<<<<<<<<<<<<",
-"<<<<<<<<<<<<<<<<<<<<<<<<",
-"<<<<<<<<<<<<<<<<<<<<<<<<",
-"<<<<<<<<<<<<<<<<<<<<<<<<",
-"<<<<<<<<<<<<<<<<<<<<<<<<"
-};
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_fit_page.bmp b/xfa_test/FormFiller_Test/res/tool_hot_fit_page.bmp
deleted file mode 100644
index 062cfcd90a..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_fit_page.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_fit_width.bmp b/xfa_test/FormFiller_Test/res/tool_hot_fit_width.bmp
deleted file mode 100644
index 07028eed44..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_fit_width.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_hand1.bmp b/xfa_test/FormFiller_Test/res/tool_hot_hand1.bmp
deleted file mode 100644
index d9d4a13a6a..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_hand1.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_last.bmp b/xfa_test/FormFiller_Test/res/tool_hot_last.bmp
deleted file mode 100644
index 9e63f72541..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_last.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_next.bmp b/xfa_test/FormFiller_Test/res/tool_hot_next.bmp
deleted file mode 100644
index 494058444e..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_next.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_open1.bmp b/xfa_test/FormFiller_Test/res/tool_hot_open1.bmp
deleted file mode 100644
index 353fade330..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_open1.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_prev.bmp b/xfa_test/FormFiller_Test/res/tool_hot_prev.bmp
deleted file mode 100644
index e83f29e338..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_prev.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_print.bmp b/xfa_test/FormFiller_Test/res/tool_hot_print.bmp
deleted file mode 100644
index e25ef8075a..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_print.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_search.bmp b/xfa_test/FormFiller_Test/res/tool_hot_search.bmp
deleted file mode 100644
index a86b8d46da..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_search.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_snap_shot.bmp b/xfa_test/FormFiller_Test/res/tool_hot_snap_shot.bmp
deleted file mode 100644
index 1552272429..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_snap_shot.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_zoomin.bmp b/xfa_test/FormFiller_Test/res/tool_hot_zoomin.bmp
deleted file mode 100644
index 48cb3c958d..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_zoomin.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_hot_zoomout.bmp b/xfa_test/FormFiller_Test/res/tool_hot_zoomout.bmp
deleted file mode 100644
index 02c37e468a..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_hot_zoomout.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_last.bmp b/xfa_test/FormFiller_Test/res/tool_last.bmp
deleted file mode 100644
index 4ac5be89fc..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_last.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_next.bmp b/xfa_test/FormFiller_Test/res/tool_next.bmp
deleted file mode 100644
index b77cc70dde..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_next.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_prev.bmp b/xfa_test/FormFiller_Test/res/tool_prev.bmp
deleted file mode 100644
index c2b2e377ec..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_prev.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_print.bmp b/xfa_test/FormFiller_Test/res/tool_print.bmp
deleted file mode 100644
index 257f650adb..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_print.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_search.bmp b/xfa_test/FormFiller_Test/res/tool_search.bmp
deleted file mode 100644
index aad8b91f03..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_search.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_snap_shot.bmp b/xfa_test/FormFiller_Test/res/tool_snap_shot.bmp
deleted file mode 100644
index 419efe4547..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_snap_shot.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_zoomin.bmp b/xfa_test/FormFiller_Test/res/tool_zoomin.bmp
deleted file mode 100644
index ddcf4c2ed8..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_zoomin.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/res/tool_zoomout.bmp b/xfa_test/FormFiller_Test/res/tool_zoomout.bmp
deleted file mode 100644
index 6fbd1de184..0000000000
--- a/xfa_test/FormFiller_Test/res/tool_zoomout.bmp
+++ /dev/null
Binary files differ
diff --git a/xfa_test/FormFiller_Test/resource.h b/xfa_test/FormFiller_Test/resource.h
deleted file mode 100644
index fab1e6b28a..0000000000
--- a/xfa_test/FormFiller_Test/resource.h
+++ /dev/null
@@ -1,113 +0,0 @@
-//{{NO_DEPENDENCIES}}
-// Microsoft Developer Studio generated include file.
-// Used by ReaderVC.rc
-//
-#define IDD_ABOUTBOX 100
-#define IDR_MAINFRAME 128
-#define IDR_READERTYPE 129
-#define IDD_DLG_GOTOPAGE 130
-#define IDD_DLG_ZOOMTO 131
-#define IDD_DLG_FIND 132
-#define IDC_CURSOR1 133
-#define IDC_CURSOR2 134
-#define IDC_CURSOR3 135
-#define IDC_CURSOR4 136
-#define IDB_BITMAP1 215
-#define IDB_BITMAP2 216
-#define IDB_BITMAP3 217
-#define IDB_BITMAP4 218
-#define IDB_BITMAP5 219
-#define IDB_BITMAP6 220
-#define IDB_BITMAP7 221
-#define IDB_BITMAP8 222
-#define IDB_BITMAP9 223
-#define IDB_BITMAP10 224
-#define IDB_BITMAP11 225
-#define IDB_BITMAP12 226
-#define IDB_BITMAP13 227
-#define IDB_BITMAP14 228
-#define IDB_BITMAP15 229
-#define IDB_BITMAP16 230
-#define IDB_BITMAP17 231
-#define IDB_BITMAP18 232
-#define IDB_BITMAP19 233
-#define IDB_BITMAP20 234
-#define IDB_BITMAP21 235
-#define IDB_BITMAP22 236
-#define IDB_BITMAP23 237
-#define IDB_BITMAP24 238
-#define IDB_BITMAP26 240
-#define IDB_BITMAP27 241
-#define IDB_BITMAP28 242
-#define IDB_BITMAP29 243
-#define IDB_BITMAP30 244
-#define IDB_BITMAP31 245
-#define IDB_BITMAP32 246
-#define IDB_BITMAP33 247
-#define IDB_BITMAP34 248
-#define IDB_BITMAP25 249
-#define IDB_BITMAP35 250
-#define IDB_BITMAP36 251
-#define IDD_DLG_CONVERT 252
-#define IDD_EXPORT_PAGE 253
-#define IDD_DLG_RESPONSE 255
-#define IDD_TEST_JS 256
-#define IDC_EDIT1 1000
-#define IDC_COMBO1 1002
-#define IDC_CHECK_MATCHCASE 1003
-#define IDC_CHECK_MATCHWHOLE 1004
-#define IDC_RADIO_Down 1005
-#define IDC_RADIO_UP 1006
-#define IDC_RADIO_Stream 1007
-#define IDC_RADIO_Appearance 1008
-#define IDC_Rander_Page 1009
-#define IDC_Save 1010
-#define IDC_EDIT_PAGE_HEIGHT 1011
-#define IDC_EDIT_ROTATE 1012
-#define IDC_EDIT_WIDTH 1013
-#define IDC_EDIT_HEIGHT 1014
-#define IDC_EDIT_PAGE_WIDTH 1015
-#define IDC_STATIC_BITMAP 1016
-#define ID_JS_OK 1017
-#define ID_JS_CANCEL 1018
-#define IDC_JS_QUESTION 1019
-#define IDC_JS_ANSWER 1020
-#define IDC_BUTTON1 1021
-#define ID_VIEW_ZOOMIN 32772
-#define ID_VIEW_ZOOMOUT 32773
-#define ID_VIEW_ZOOMTO 32774
-#define ID_VIEW_ACTUALSIZE 32775
-#define ID_VIEW_FITPAGE 32776
-#define ID_VIEW_FITWIDTH 32777
-#define ID_DOC_FIRSTPAGE 32778
-#define ID_DOC_PREPAGE 32779
-#define ID_DOC_NEXTPAGE 32780
-#define ID_DOC_LASTPAGE 32781
-#define ID_DOC_GOTOPAGE 32782
-#define ID_VIEW_CLOCKWISE 32784
-#define ID_VIEW_COUNTERCLOCKWISE 32785
-#define ID_TOOL_HAND 32788
-#define ID_TOOL_SELECT 32789
-#define ID_TOOL_SNAPSHOT 32790
-#define ID_TOOL_PDF2TXT 32791
-#define ID_TOOL_EXTRACTLINKS 32792
-#define ID_DOC_EDITGOTO 32793
-#define ID_VIEW_BOOKMARK 32794
-#define ID_TOOL_PAGETOTEXT 32795
-#define ID_RENDERBITMAP 32799
-#define ID_EXPORT_PDF_TO_BITMAP 32800
-#define IDM_Test_JS 32801
-#define IDC_JS_EDIT 32802
-#define TEST_PRINT_METALFILE 32803
-
-// Next default values for new objects
-//
-#ifdef APSTUDIO_INVOKED
-#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_3D_CONTROLS 1
-#define _APS_NEXT_RESOURCE_VALUE 257
-#define _APS_NEXT_COMMAND_VALUE 32803
-#define _APS_NEXT_CONTROL_VALUE 1022
-#define _APS_NEXT_SYMED_VALUE 101
-#endif
-#endif
diff --git a/xfa_test/pdf/BUILD.gn b/xfa_test/pdf/BUILD.gn
deleted file mode 100644
index 5e1f165b1c..0000000000
--- a/xfa_test/pdf/BUILD.gn
+++ /dev/null
@@ -1,99 +0,0 @@
-# Copyright 2014 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.
-
-pdf_engine = 0 # 0 PDFium
-
-# TODO(GYP) need support for loadable modules
-shared_library("pdf") {
- sources = [
- "button.h",
- "button.cc",
- "chunk_stream.h",
- "chunk_stream.cc",
- "control.h",
- "control.cc",
- "document_loader.h",
- "document_loader.cc",
- "draw_utils.cc",
- "draw_utils.h",
- "fading_control.cc",
- "fading_control.h",
- "fading_controls.cc",
- "fading_controls.h",
- "instance.cc",
- "instance.h",
- "number_image_generator.cc",
- "number_image_generator.h",
- "out_of_process_instance.cc",
- "out_of_process_instance.h",
- "page_indicator.cc",
- "page_indicator.h",
- "paint_aggregator.cc",
- "paint_aggregator.h",
- "paint_manager.cc",
- "paint_manager.h",
- "pdf.cc",
- "pdf.h",
- "pdf.rc",
- "progress_control.cc",
- "progress_control.h",
- "pdf_engine.h",
- "preview_mode_client.cc",
- "preview_mode_client.h",
- "resource.h",
- "resource_consts.h",
- "thumbnail_control.cc",
- "thumbnail_control.h",
- "../chrome/browser/chrome_page_zoom_constants.cc",
- "../content/common/page_zoom.cc",
- ]
-
- if (pdf_engine == 0) {
- sources += [
- "pdfium/pdfium_assert_matching_enums.cc",
- "pdfium/pdfium_engine.cc",
- "pdfium/pdfium_engine.h",
- "pdfium/pdfium_mem_buffer_file_read.cc",
- "pdfium/pdfium_mem_buffer_file_read.h",
- "pdfium/pdfium_mem_buffer_file_write.cc",
- "pdfium/pdfium_mem_buffer_file_write.h",
- "pdfium/pdfium_page.cc",
- "pdfium/pdfium_page.h",
- "pdfium/pdfium_range.cc",
- "pdfium/pdfium_range.h",
- ]
- }
-
- if (is_win) {
- defines = [ "COMPILE_CONTENT_STATICALLY" ]
- cflags = [ "/wd4267" ] # TODO(jschuh) size_t to int truncations.
- }
-
- if (is_mac) {
- # TODO(GYP)
- #'mac_bundle': 1,
- #'product_name': 'PDF',
- #'product_extension': 'plugin',
- ## Strip the shipping binary of symbols so "Foxit" doesn't appear in
- ## the binary. Symbols are stored in a separate .dSYM.
- #'variables': {
- # 'mac_real_dsym': 1,
- #},
- #'sources+': [
- # 'Info.plist'
- #]
- #'xcode_settings': {
- # 'INFOPLIST_FILE': 'Info.plist',
- #},
- }
-
- deps = [
- "//base",
- "//net",
- "//ppapi:ppapi_cpp",
- "//third_party/pdfium",
- ]
-}
-
-# TODO(GYP) pdf_linux_symbols target.
diff --git a/xfa_test/pdf/DEPS b/xfa_test/pdf/DEPS
deleted file mode 100644
index 73f2f8f44d..0000000000
--- a/xfa_test/pdf/DEPS
+++ /dev/null
@@ -1,9 +0,0 @@
-include_rules = [
- "!chrome/browser/chrome_page_zoom_constants.h",
- "!chrome/common/content_restriction.h",
- "!content/public/common/page_zoom.h",
- "+net",
- "+ppapi",
- "+third_party/pdfium/fpdfsdk/include",
- "+ui/events/keycodes/keyboard_codes.h",
-]
diff --git a/xfa_test/pdf/Info.plist b/xfa_test/pdf/Info.plist
deleted file mode 100644
index 9f3dfdf834..0000000000
--- a/xfa_test/pdf/Info.plist
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
- <key>CFBundleDevelopmentRegion</key>
- <string>English</string>
- <key>CFBundleExecutable</key>
- <string>${EXECUTABLE_NAME}</string>
- <key>CFBundleIdentifier</key>
- <string>org.chromium.pdf_plugin</string>
- <key>CFBundleInfoDictionaryVersion</key>
- <string>6.0</string>
- <key>CFBundleName</key>
- <string>${PRODUCT_NAME}</string>
- <key>CFBundlePackageType</key>
- <string>BRPL</string>
- <key>CFBundleShortVersionString</key>
- <string>1.0</string>
- <key>CFBundleSignature</key>
- <string>????</string>
- <key>CFBundleVersion</key>
- <string>1.0</string>
- <key>CFPlugInDynamicRegisterFunction</key>
- <string></string>
- <key>CFPlugInDynamicRegistration</key>
- <string>NO</string>
- <key>WebPluginDescription</key>
- <string>Chrome PDF Viewer</string>
- <key>WebPluginMIMETypes</key>
- <dict>
- <key>application/pdf</key>
- <dict>
- <key>WebPluginExtensions</key>
- <array>
- <string>pdf</string>
- </array>
- <key>WebPluginTypeDescription</key>
- <string>Acrobat Portable Document Format</string>
- </dict>
- </dict>
- <key>WebPluginName</key>
- <string>Chrome PDF Viewer</string>
-</dict>
-</plist>
diff --git a/xfa_test/pdf/OWNERS b/xfa_test/pdf/OWNERS
deleted file mode 100644
index 4b408bc7c9..0000000000
--- a/xfa_test/pdf/OWNERS
+++ /dev/null
@@ -1,4 +0,0 @@
-gene@chromium.org
-jam@chromium.org
-raymes@chromium.org
-thestig@chromium.org \ No newline at end of file
diff --git a/xfa_test/pdf/button.cc b/xfa_test/pdf/button.cc
deleted file mode 100644
index 3a30164c14..0000000000
--- a/xfa_test/pdf/button.cc
+++ /dev/null
@@ -1,179 +0,0 @@
-// Copyright (c) 2010 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 "pdf/button.h"
-
-#include "base/logging.h"
-#include "pdf/draw_utils.h"
-#include "ppapi/cpp/input_event.h"
-
-namespace chrome_pdf {
-
-Button::Button()
- : style_(BUTTON_CLICKABLE), state_(BUTTON_NORMAL), is_pressed_(false) {
-}
-
-Button::~Button() {
-}
-
-bool Button::CreateButton(uint32 id,
- const pp::Point& origin,
- bool visible,
- Control::Owner* owner,
- ButtonStyle style,
- const pp::ImageData& face_normal,
- const pp::ImageData& face_highlighted,
- const pp::ImageData& face_pressed) {
- DCHECK(face_normal.size().GetArea());
- DCHECK(face_normal.size() == face_highlighted.size());
- DCHECK(face_normal.size() == face_pressed.size());
-
- pp::Rect rc(origin, face_normal.size());
- if (!Control::Create(id, rc, visible, owner))
- return false;
-
- style_ = style;
-
- normal_ = face_normal;
- highlighted_ = face_highlighted;
- pressed_ = face_pressed;
-
- return true;
-}
-
-
-void Button::Paint(pp::ImageData* image_data, const pp::Rect& rc) {
- if (!visible())
- return;
-
- pp::Rect draw_rc = rc.Intersect(rect());
- if (draw_rc.IsEmpty())
- return;
-
- pp::Point origin = draw_rc.point();
- draw_rc.Offset(-rect().x(), -rect().y());
-
- AlphaBlend(GetCurrentImage(), draw_rc, image_data, origin, transparency());
-}
-
-bool Button::HandleEvent(const pp::InputEvent& event) {
- if (!visible())
- return false;
-
- // Button handles mouse events only.
- pp::MouseInputEvent mouse_event(event);
- if (mouse_event.is_null())
- return false;
-
- pp::Point pt = mouse_event.GetPosition();
- if (!rect().Contains(pt) ||
- event.GetType() == PP_INPUTEVENT_TYPE_MOUSELEAVE) {
- ChangeState(BUTTON_NORMAL, false);
- owner()->SetEventCapture(id(), false);
- return false;
- }
-
- owner()->SetCursor(id(), PP_CURSORTYPE_POINTER);
- owner()->SetEventCapture(id(), true);
-
- bool handled = true;
- switch (event.GetType()) {
- case PP_INPUTEVENT_TYPE_MOUSEMOVE:
- if (state_ == BUTTON_NORMAL)
- ChangeState(BUTTON_HIGHLIGHTED, false);
- break;
- case PP_INPUTEVENT_TYPE_MOUSEDOWN:
- if (mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) {
- ChangeState(BUTTON_PRESSED, false);
- is_pressed_ = true;
- }
- break;
- case PP_INPUTEVENT_TYPE_MOUSEUP:
- if (mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT &&
- is_pressed_) {
- OnButtonClicked();
- is_pressed_ = false;
- } else {
- // Since button has not been pressed, return false to allow other
- // controls (scrollbar) to process mouse button up.
- return false;
- }
- break;
- default:
- handled = false;
- break;
- }
-
- return handled;
-}
-
-void Button::OnEventCaptureReleased() {
- ChangeState(BUTTON_NORMAL, false);
-}
-
-void Button::Show(bool visible, bool invalidate) {
- // If button become invisible, remove pressed flag.
- if (!visible)
- is_pressed_ = false;
- Control::Show(visible, invalidate);
-}
-
-void Button::AdjustTransparency(uint8 transparency, bool invalidate) {
- // If button become invisible, remove pressed flag.
- if (transparency == kTransparentAlpha)
- is_pressed_ = false;
- Control::AdjustTransparency(transparency, invalidate);
-}
-
-void Button::SetPressedState(bool pressed) {
- if (style_ == BUTTON_STATE) {
- if (IsPressed() != pressed)
- ChangeState(pressed ? BUTTON_PRESSED_STICKY : BUTTON_NORMAL, true);
- }
-}
-
-const pp::ImageData& Button::GetCurrentImage() {
- switch (state_) {
- case BUTTON_NORMAL: return normal_;
- case BUTTON_HIGHLIGHTED: return highlighted_;
- case BUTTON_PRESSED:
- case BUTTON_PRESSED_STICKY: return pressed_;
- }
- NOTREACHED();
- return normal_;
-}
-
-void Button::ChangeState(ButtonState new_state, bool force) {
- if (style_ == BUTTON_STATE && !force) {
- // If button is a state button and pressed state is sticky,
- // user have to click on this button again to unpress it.
- if ((state_ == BUTTON_PRESSED_STICKY && new_state != BUTTON_PRESSED_STICKY)
- ||
- (state_ != BUTTON_PRESSED_STICKY && new_state == BUTTON_PRESSED_STICKY))
- return;
- }
-
- if (state_ != new_state) {
- state_ = new_state;
- owner()->Invalidate(id(), rect());
- }
-}
-
-void Button::OnButtonClicked() {
- switch (style_) {
- case BUTTON_CLICKABLE:
- ChangeState(BUTTON_HIGHLIGHTED, true);
- owner()->OnEvent(id(), EVENT_ID_BUTTON_CLICKED, NULL);
- break;
- case BUTTON_STATE:
- SetPressedState(!IsPressed());
- owner()->OnEvent(id(), EVENT_ID_BUTTON_STATE_CHANGED, NULL);
- break;
- default:
- NOTREACHED();
- }
-}
-
-} // namespace chrome_pdf
-
diff --git a/xfa_test/pdf/button.h b/xfa_test/pdf/button.h
deleted file mode 100644
index fa2517d62b..0000000000
--- a/xfa_test/pdf/button.h
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright (c) 2010 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.
-
-#ifndef PDF_BUTTON_H_
-#define PDF_BUTTON_H_
-
-#include "pdf/control.h"
-#include "ppapi/cpp/image_data.h"
-#include "ppapi/cpp/rect.h"
-
-namespace chrome_pdf {
-
-class Button : public Control {
- public:
- enum ButtonEventIds {
- EVENT_ID_BUTTON_CLICKED,
- EVENT_ID_BUTTON_STATE_CHANGED,
- };
-
- enum ButtonStyle {
- BUTTON_CLICKABLE,
- BUTTON_STATE
- };
-
- enum ButtonState {
- BUTTON_NORMAL,
- BUTTON_HIGHLIGHTED,
- BUTTON_PRESSED,
- BUTTON_PRESSED_STICKY,
- };
-
- Button();
- virtual ~Button();
- virtual bool CreateButton(uint32 id,
- const pp::Point& origin,
- bool visible,
- Control::Owner* delegate,
- ButtonStyle style,
- const pp::ImageData& face_normal,
- const pp::ImageData& face_highlighted,
- const pp::ImageData& face_pressed);
-
- virtual void Paint(pp::ImageData* image_data, const pp::Rect& rc);
- virtual bool HandleEvent(const pp::InputEvent& event);
- virtual void OnEventCaptureReleased();
- virtual void Show(bool visible, bool invalidate);
- virtual void AdjustTransparency(uint8 transparency, bool invalidate);
-
- ButtonState state() const { return state_; }
- bool IsPressed() const { return state() == BUTTON_PRESSED_STICKY; }
- void SetPressedState(bool pressed);
-
- private:
- void OnButtonClicked();
-
- const pp::ImageData& GetCurrentImage();
- void ChangeState(ButtonState new_state, bool force);
-
- ButtonStyle style_;
- ButtonState state_;
- bool is_pressed_;
-
- pp::ImageData normal_;
- pp::ImageData highlighted_;
- pp::ImageData pressed_;
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_BUTTON_H_
diff --git a/xfa_test/pdf/chunk_stream.cc b/xfa_test/pdf/chunk_stream.cc
deleted file mode 100644
index 7ac8f974a5..0000000000
--- a/xfa_test/pdf/chunk_stream.cc
+++ /dev/null
@@ -1,172 +0,0 @@
-// Copyright (c) 2010 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 "pdf/chunk_stream.h"
-
-#define __STDC_LIMIT_MACROS
-#ifdef _WIN32
-#include <limits.h>
-#else
-#include <stdint.h>
-#endif
-
-#include <algorithm>
-
-#include "base/basictypes.h"
-
-namespace chrome_pdf {
-
-ChunkStream::ChunkStream() {
-}
-
-ChunkStream::~ChunkStream() {
-}
-
-void ChunkStream::Clear() {
- chunks_.clear();
- data_.clear();
-}
-
-void ChunkStream::Preallocate(size_t stream_size) {
- data_.reserve(stream_size);
-}
-
-size_t ChunkStream::GetSize() {
- return data_.size();
-}
-
-bool ChunkStream::WriteData(size_t offset, void* buffer, size_t size) {
- if (SIZE_MAX - size < offset)
- return false;
-
- if (data_.size() < offset + size)
- data_.resize(offset + size);
-
- memcpy(&data_[offset], buffer, size);
-
- if (chunks_.empty()) {
- chunks_[offset] = size;
- return true;
- }
-
- std::map<size_t, size_t>::iterator start = chunks_.upper_bound(offset);
- if (start != chunks_.begin())
- --start; // start now points to the key equal or lower than offset.
- if (start->first + start->second < offset)
- ++start; // start element is entirely before current chunk, skip it.
-
- std::map<size_t, size_t>::iterator end = chunks_.upper_bound(offset + size);
- if (start == end) { // No chunks to merge.
- chunks_[offset] = size;
- return true;
- }
-
- --end;
-
- size_t new_offset = std::min<size_t>(start->first, offset);
- size_t new_size =
- std::max<size_t>(end->first + end->second, offset + size) - new_offset;
-
- chunks_.erase(start, ++end);
-
- chunks_[new_offset] = new_size;
-
- return true;
-}
-
-bool ChunkStream::ReadData(size_t offset, size_t size, void* buffer) const {
- if (!IsRangeAvailable(offset, size))
- return false;
-
- memcpy(buffer, &data_[offset], size);
- return true;
-}
-
-bool ChunkStream::GetMissedRanges(
- size_t offset, size_t size,
- std::vector<std::pair<size_t, size_t> >* ranges) const {
- if (IsRangeAvailable(offset, size))
- return false;
-
- ranges->clear();
- if (chunks_.empty()) {
- ranges->push_back(std::pair<size_t, size_t>(offset, size));
- return true;
- }
-
- std::map<size_t, size_t>::const_iterator start = chunks_.upper_bound(offset);
- if (start != chunks_.begin())
- --start; // start now points to the key equal or lower than offset.
- if (start->first + start->second < offset)
- ++start; // start element is entirely before current chunk, skip it.
-
- std::map<size_t, size_t>::const_iterator end =
- chunks_.upper_bound(offset + size);
- if (start == end) { // No data in the current range available.
- ranges->push_back(std::pair<size_t, size_t>(offset, size));
- return true;
- }
-
- size_t cur_offset = offset;
- std::map<size_t, size_t>::const_iterator it;
- for (it = start; it != end; ++it) {
- if (cur_offset < it->first) {
- size_t new_size = it->first - cur_offset;
- ranges->push_back(std::pair<size_t, size_t>(cur_offset, new_size));
- cur_offset = it->first + it->second;
- } else if (cur_offset < it->first + it->second) {
- cur_offset = it->first + it->second;
- }
- }
-
- // Add last chunk.
- if (cur_offset < offset + size)
- ranges->push_back(std::pair<size_t, size_t>(cur_offset,
- offset + size - cur_offset));
-
- return true;
-}
-
-bool ChunkStream::IsRangeAvailable(size_t offset, size_t size) const {
- if (chunks_.empty())
- return false;
-
- if (SIZE_MAX - size < offset)
- return false;
-
- std::map<size_t, size_t>::const_iterator it = chunks_.upper_bound(offset);
- if (it == chunks_.begin())
- return false; // No chunks includes offset byte.
-
- --it; // Now it starts equal or before offset.
- return (it->first + it->second) >= (offset + size);
-}
-
-size_t ChunkStream::GetFirstMissingByte() const {
- if (chunks_.empty())
- return 0;
- std::map<size_t, size_t>::const_iterator begin = chunks_.begin();
- return begin->first > 0 ? 0 : begin->second;
-}
-
-size_t ChunkStream::GetLastByteBefore(size_t offset) const {
- if (chunks_.empty())
- return 0;
- std::map<size_t, size_t>::const_iterator it = chunks_.upper_bound(offset);
- if (it == chunks_.begin())
- return 0;
- --it;
- return it->first + it->second;
-}
-
-size_t ChunkStream::GetFirstByteAfter(size_t offset) const {
- if (chunks_.empty())
- return 0;
- std::map<size_t, size_t>::const_iterator it = chunks_.upper_bound(offset);
- if (it == chunks_.end())
- return data_.size();
- return it->first;
-}
-
-} // namespace chrome_pdf
diff --git a/xfa_test/pdf/chunk_stream.h b/xfa_test/pdf/chunk_stream.h
deleted file mode 100644
index fac1ec644d..0000000000
--- a/xfa_test/pdf/chunk_stream.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (c) 2010 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.
-
-#ifndef PDF_CHUNK_STREAM_H_
-#define PDF_CHUNK_STREAM_H_
-
-#include <stddef.h>
-
-#include <map>
-#include <vector>
-
-namespace chrome_pdf {
-
-// This class collects a chunks of data into one data stream. Client can check
-// if data in certain range is available, and get missing chunks of data.
-class ChunkStream {
- public:
- ChunkStream();
- ~ChunkStream();
-
- void Clear();
-
- void Preallocate(size_t stream_size);
- size_t GetSize();
-
- bool WriteData(size_t offset, void* buffer, size_t size);
- bool ReadData(size_t offset, size_t size, void* buffer) const;
-
- // Returns vector of pairs where first is an offset, second is a size.
- bool GetMissedRanges(size_t offset, size_t size,
- std::vector<std::pair<size_t, size_t> >* ranges) const;
- bool IsRangeAvailable(size_t offset, size_t size) const;
- size_t GetFirstMissingByte() const;
-
- size_t GetLastByteBefore(size_t offset) const;
- size_t GetFirstByteAfter(size_t offset) const;
-
- private:
- std::vector<unsigned char> data_;
-
- // Pair, first - begining of the chunk, second - size of the chunk.
- std::map<size_t, size_t> chunks_;
-};
-
-}; // namespace chrome_pdf
-
-#endif
diff --git a/xfa_test/pdf/control.cc b/xfa_test/pdf/control.cc
deleted file mode 100644
index ed911b6b95..0000000000
--- a/xfa_test/pdf/control.cc
+++ /dev/null
@@ -1,117 +0,0 @@
-// 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 "pdf/control.h"
-
-#include "base/logging.h"
-#include "pdf/draw_utils.h"
-
-namespace chrome_pdf {
-
-Control::Control()
- : id_(kInvalidControlId),
- visible_(false),
- owner_(NULL),
- transparency_(kOpaqueAlpha) {
-}
-
-Control::~Control() {
-}
-
-bool Control::Create(uint32 id, const pp::Rect& rc,
- bool visible, Owner* owner) {
- DCHECK(owner);
- if (owner_ || id == kInvalidControlId)
- return false; // Already created or id is invalid.
- id_ = id;
- rc_ = rc;
- visible_ = visible;
- owner_ = owner;
- return true;
-}
-
-bool Control::HandleEvent(const pp::InputEvent& event) {
- return false;
-}
-
-void Control::PaintMultipleRects(pp::ImageData* image_data,
- const std::list<pp::Rect>& rects) {
- DCHECK(rects.size() > 0);
- if (rects.size() == 1) {
- Paint(image_data, rects.front());
- return;
- }
-
- // Some rects in the input list may overlap. To prevent double
- // painting (causes problems with semi-transparent controls) we'll
- // paint control into buffer image data only once and copy requested
- // rectangles.
- pp::ImageData buffer(owner()->GetInstance(), image_data->format(),
- rect().size(), false);
- if (buffer.is_null())
- return;
-
- pp::Rect draw_rc = pp::Rect(image_data->size()).Intersect(rect());
- pp::Rect ctrl_rc = pp::Rect(draw_rc.point() - rect().point(), draw_rc.size());
- CopyImage(*image_data, draw_rc, &buffer, ctrl_rc, false);
-
- // Temporary move control to origin (0,0) and draw it into temp buffer.
- // Move to the original position afterward. Since this is going on temp
- // buffer, we don't need to invalidate here.
- pp::Rect temp = rect();
- MoveTo(pp::Point(0, 0), false);
- Paint(&buffer, ctrl_rc);
- MoveTo(temp.point(), false);
-
- std::list<pp::Rect>::const_iterator iter;
- for (iter = rects.begin(); iter != rects.end(); ++iter) {
- pp::Rect draw_rc = rect().Intersect(*iter);
- if (!draw_rc.IsEmpty()) {
- // Copy requested rect from the buffer image.
- pp::Rect src_rc = draw_rc;
- src_rc.Offset(-rect().x(), -rect().y());
- CopyImage(buffer, src_rc, image_data, draw_rc, false);
- }
- }
-}
-
-void Control::Show(bool visible, bool invalidate) {
- if (visible_ != visible) {
- visible_ = visible;
- if (invalidate)
- owner_->Invalidate(id_, rc_);
- }
-}
-
-void Control::AdjustTransparency(uint8 transparency, bool invalidate) {
- if (transparency_ != transparency) {
- transparency_ = transparency;
- if (invalidate && visible_)
- owner_->Invalidate(id_, rc_);
- }
-}
-
-void Control::MoveBy(const pp::Point& offset, bool invalidate) {
- pp::Rect old_rc = rc_;
- rc_.Offset(offset);
- if (invalidate && visible_) {
- owner()->Invalidate(id(), old_rc);
- owner()->Invalidate(id(), rect());
- }
-}
-
-void Control::SetRect(const pp::Rect& rc, bool invalidate) {
- pp::Rect old_rc = rc_;
- rc_ = rc;
- if (invalidate && visible_) {
- owner()->Invalidate(id(), old_rc);
- owner()->Invalidate(id(), rect());
- }
-}
-
-void Control::MoveTo(const pp::Point& origin, bool invalidate) {
- MoveBy(origin - rc_.point(), invalidate);
-}
-
-} // namespace chrome_pdf
diff --git a/xfa_test/pdf/control.h b/xfa_test/pdf/control.h
deleted file mode 100644
index babb37a2c0..0000000000
--- a/xfa_test/pdf/control.h
+++ /dev/null
@@ -1,77 +0,0 @@
-// 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.
-
-#ifndef PDF_CONTROL_H_
-#define PDF_CONTROL_H_
-
-#include <list>
-
-#include "base/basictypes.h"
-#include "ppapi/c/dev/pp_cursor_type_dev.h"
-#include "ppapi/cpp/rect.h"
-
-namespace pp {
-class ImageData;
-class InputEvent;
-class Instance;
-}
-
-namespace chrome_pdf {
-
-const uint32 kInvalidControlId = 0;
-
-class Control {
- public:
- class Owner {
- public:
- virtual ~Owner() {}
- virtual void OnEvent(uint32 control_id, uint32 event_id, void* data) = 0;
- virtual void Invalidate(uint32 control_id, const pp::Rect& rc) = 0;
- virtual uint32 ScheduleTimer(uint32 control_id, uint32 timeout_ms) = 0;
- virtual void SetEventCapture(uint32 control_id, bool set_capture) = 0;
- virtual void SetCursor(uint32 control_id,
- PP_CursorType_Dev cursor_type) = 0;
- virtual pp::Instance* GetInstance() = 0;
- };
-
- Control();
- virtual ~Control();
- virtual bool Create(uint32 id, const pp::Rect& rc,
- bool visible, Owner* owner);
-
- virtual void Paint(pp::ImageData* image_data, const pp::Rect& rc) {}
- virtual bool HandleEvent(const pp::InputEvent& event);
- virtual void OnTimerFired(uint32 timer_id) {}
- virtual void EventCaptureReleased() {}
-
- // Paint control into multiple destination rects.
- virtual void PaintMultipleRects(pp::ImageData* image_data,
- const std::list<pp::Rect>& rects);
-
- virtual void Show(bool visible, bool invalidate);
- virtual void AdjustTransparency(uint8 transparency, bool invalidate);
- virtual void MoveBy(const pp::Point& offset, bool invalidate);
- virtual void SetRect(const pp::Rect& rc, bool invalidate);
-
- void MoveTo(const pp::Point& origin, bool invalidate);
-
- uint32 id() const { return id_; }
- const pp::Rect& rect() const { return rc_; }
- bool visible() const { return visible_; }
- Owner* owner() { return owner_; }
- uint8 transparency() const { return transparency_; }
-
- private:
- uint32 id_;
- pp::Rect rc_;
- bool visible_;
- Owner* owner_;
- uint8 transparency_;
-};
-
-typedef Control::Owner ControlOwner;
-
-} // namespace chrome_pdf
-
-#endif // PDF_CONTROL_H_
diff --git a/xfa_test/pdf/document_loader.cc b/xfa_test/pdf/document_loader.cc
deleted file mode 100644
index b2628a6271..0000000000
--- a/xfa_test/pdf/document_loader.cc
+++ /dev/null
@@ -1,513 +0,0 @@
-// Copyright (c) 2010 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 "pdf/document_loader.h"
-
-#include "base/logging.h"
-#include "base/strings/string_util.h"
-#include "net/http/http_util.h"
-#include "ppapi/c/pp_errors.h"
-#include "ppapi/cpp/url_loader.h"
-#include "ppapi/cpp/url_request_info.h"
-#include "ppapi/cpp/url_response_info.h"
-
-namespace chrome_pdf {
-
-// Document below size will be downloaded in one chunk.
-const uint32 kMinFileSize = 64*1024;
-
-DocumentLoader::DocumentLoader(Client* client)
- : client_(client), partial_document_(false), request_pending_(false),
- current_pos_(0), current_chunk_size_(0), current_chunk_read_(0),
- document_size_(0), header_request_(true), is_multipart_(false) {
- loader_factory_.Initialize(this);
-}
-
-DocumentLoader::~DocumentLoader() {
-}
-
-bool DocumentLoader::Init(const pp::URLLoader& loader,
- const std::string& url,
- const std::string& headers) {
- DCHECK(url_.empty());
- url_ = url;
- loader_ = loader;
-
- std::string response_headers;
- if (!headers.empty()) {
- response_headers = headers;
- } else {
- pp::URLResponseInfo response = loader_.GetResponseInfo();
- pp::Var headers_var = response.GetHeaders();
-
- if (headers_var.is_string()) {
- response_headers = headers_var.AsString();
- }
- }
-
- bool accept_ranges_bytes = false;
- bool content_encoded = false;
- uint32 content_length = 0;
- std::string type;
- std::string disposition;
- if (!response_headers.empty()) {
- net::HttpUtil::HeadersIterator it(response_headers.begin(),
- response_headers.end(), "\n");
- while (it.GetNext()) {
- if (LowerCaseEqualsASCII(it.name(), "content-length")) {
- content_length = atoi(it.values().c_str());
- } else if (LowerCaseEqualsASCII(it.name(), "accept-ranges")) {
- accept_ranges_bytes = LowerCaseEqualsASCII(it.values(), "bytes");
- } else if (LowerCaseEqualsASCII(it.name(), "content-encoding")) {
- content_encoded = true;
- } else if (LowerCaseEqualsASCII(it.name(), "content-type")) {
- type = it.values();
- size_t semi_colon_pos = type.find(';');
- if (semi_colon_pos != std::string::npos) {
- type = type.substr(0, semi_colon_pos);
- }
- TrimWhitespace(type, base::TRIM_ALL, &type);
- } else if (LowerCaseEqualsASCII(it.name(), "content-disposition")) {
- disposition = it.values();
- }
- }
- }
- if (!type.empty() &&
- !EndsWith(type, "/pdf", false) &&
- !EndsWith(type, ".pdf", false) &&
- !EndsWith(type, "/x-pdf", false) &&
- !EndsWith(type, "/*", false) &&
- !EndsWith(type, "/acrobat", false) &&
- !EndsWith(type, "/unknown", false)) {
- return false;
- }
- if (StartsWithASCII(disposition, "attachment", false)) {
- return false;
- }
-
- if (content_length > 0)
- chunk_stream_.Preallocate(content_length);
-
- document_size_ = content_length;
- requests_count_ = 0;
-
- // Enable partial loading only if file size is above the threshold.
- // It will allow avoiding latency for multiple requests.
- if (content_length > kMinFileSize &&
- accept_ranges_bytes &&
- !content_encoded) {
- LoadPartialDocument();
- } else {
- LoadFullDocument();
- }
- return true;
-}
-
-void DocumentLoader::LoadPartialDocument() {
- partial_document_ = true;
- // Force the main request to be cancelled, since if we're a full-frame plugin
- // there could be other references to the loader.
- loader_.Close();
- loader_ = pp::URLLoader();
- // Download file header.
- header_request_ = true;
- RequestData(0, std::min(GetRequestSize(), document_size_));
-}
-
-void DocumentLoader::LoadFullDocument() {
- partial_document_ = false;
- chunk_buffer_.clear();
- ReadMore();
-}
-
-bool DocumentLoader::IsDocumentComplete() const {
- if (document_size_ == 0) // Document size unknown.
- return false;
- return IsDataAvailable(0, document_size_);
-}
-
-uint32 DocumentLoader::GetAvailableData() const {
- if (document_size_ == 0) { // If document size is unknown.
- return current_pos_;
- }
-
- std::vector<std::pair<size_t, size_t> > ranges;
- chunk_stream_.GetMissedRanges(0, document_size_, &ranges);
- uint32 available = document_size_;
- std::vector<std::pair<size_t, size_t> >::iterator it;
- for (it = ranges.begin(); it != ranges.end(); ++it) {
- available -= it->second;
- }
- return available;
-}
-
-void DocumentLoader::ClearPendingRequests() {
- // The first item in the queue is pending (need to keep it in the queue).
- if (pending_requests_.size() > 1) {
- // Remove all elements except the first one.
- pending_requests_.erase(++pending_requests_.begin(),
- pending_requests_.end());
- }
-}
-
-bool DocumentLoader::GetBlock(uint32 position, uint32 size, void* buf) const {
- return chunk_stream_.ReadData(position, size, buf);
-}
-
-bool DocumentLoader::IsDataAvailable(uint32 position, uint32 size) const {
- return chunk_stream_.IsRangeAvailable(position, size);
-}
-
-void DocumentLoader::RequestData(uint32 position, uint32 size) {
- DCHECK(partial_document_);
-
- // We have some artefact request from
- // PDFiumEngine::OnDocumentComplete() -> FPDFAvail_IsPageAvail after
- // document is complete.
- // We need this fix in PDFIum. Adding this as a work around.
- // Bug: http://code.google.com/p/chromium/issues/detail?id=79996
- // Test url:
- // http://www.icann.org/en/correspondence/holtzman-to-jeffrey-02mar11-en.pdf
- if (IsDocumentComplete())
- return;
-
- pending_requests_.push_back(std::pair<size_t, size_t>(position, size));
- DownloadPendingRequests();
-}
-
-void DocumentLoader::DownloadPendingRequests() {
- if (request_pending_ || pending_requests_.empty())
- return;
-
- // Remove already completed requests.
- // By design DownloadPendingRequests() should have at least 1 request in the
- // queue. ReadComplete() will remove the last pending comment from the queue.
- while (pending_requests_.size() > 1) {
- if (IsDataAvailable(pending_requests_.front().first,
- pending_requests_.front().second)) {
- pending_requests_.pop_front();
- } else {
- break;
- }
- }
-
- uint32 pos = pending_requests_.front().first;
- uint32 size = pending_requests_.front().second;
- if (IsDataAvailable(pos, size)) {
- ReadComplete();
- return;
- }
-
- // If current request has been partially downloaded already, split it into
- // a few smaller requests.
- std::vector<std::pair<size_t, size_t> > ranges;
- chunk_stream_.GetMissedRanges(pos, size, &ranges);
- if (ranges.size() > 0) {
- pending_requests_.pop_front();
- pending_requests_.insert(pending_requests_.begin(),
- ranges.begin(), ranges.end());
- pos = pending_requests_.front().first;
- size = pending_requests_.front().second;
- }
-
- uint32 cur_request_size = GetRequestSize();
- // If size is less than default request, try to expand download range for
- // more optimal download.
- if (size < cur_request_size && partial_document_) {
- // First, try to expand block towards the end of the file.
- uint32 new_pos = pos;
- uint32 new_size = cur_request_size;
- if (pos + new_size > document_size_)
- new_size = document_size_ - pos;
-
- std::vector<std::pair<size_t, size_t> > ranges;
- if (chunk_stream_.GetMissedRanges(new_pos, new_size, &ranges)) {
- new_pos = ranges[0].first;
- new_size = ranges[0].second;
- }
-
- // Second, try to expand block towards the beginning of the file.
- if (new_size < cur_request_size) {
- uint32 block_end = new_pos + new_size;
- if (block_end > cur_request_size) {
- new_pos = block_end - cur_request_size;
- } else {
- new_pos = 0;
- }
- new_size = block_end - new_pos;
-
- if (chunk_stream_.GetMissedRanges(new_pos, new_size, &ranges)) {
- new_pos = ranges.back().first;
- new_size = ranges.back().second;
- }
- }
- pos = new_pos;
- size = new_size;
- }
-
- size_t last_byte_before = chunk_stream_.GetLastByteBefore(pos);
- size_t first_byte_after = chunk_stream_.GetFirstByteAfter(pos + size - 1);
- if (pos - last_byte_before < cur_request_size) {
- size = pos + size - last_byte_before;
- pos = last_byte_before;
- }
-
- if ((pos + size < first_byte_after) &&
- (pos + size + cur_request_size >= first_byte_after))
- size = first_byte_after - pos;
-
- request_pending_ = true;
-
- // Start downloading first pending request.
- loader_.Close();
- loader_ = client_->CreateURLLoader();
- pp::CompletionCallback callback =
- loader_factory_.NewCallback(&DocumentLoader::DidOpen);
- pp::URLRequestInfo request = GetRequest(pos, size);
- requests_count_++;
- int rv = loader_.Open(request, callback);
- if (rv != PP_OK_COMPLETIONPENDING)
- callback.Run(rv);
-}
-
-pp::URLRequestInfo DocumentLoader::GetRequest(uint32 position,
- uint32 size) const {
- pp::URLRequestInfo request(client_->GetPluginInstance());
- request.SetURL(url_.c_str());
- request.SetMethod("GET");
- request.SetFollowRedirects(true);
-
- const size_t kBufSize = 100;
- char buf[kBufSize];
- // According to rfc2616, byte range specifies position of the first and last
- // bytes in the requested range inclusively. Therefore we should subtract 1
- // from the position + size, to get index of the last byte that needs to be
- // downloaded.
- base::snprintf(buf, kBufSize, "Range: bytes=%d-%d", position,
- position + size - 1);
- pp::Var header(buf);
- request.SetHeaders(header);
-
- return request;
-}
-
-void DocumentLoader::DidOpen(int32_t result) {
- if (result != PP_OK) {
- NOTREACHED();
- return;
- }
-
- int32_t http_code = loader_.GetResponseInfo().GetStatusCode();
- if (http_code >= 400 && http_code < 500) {
- // Error accessing resource. 4xx error indicate subsequent requests
- // will fail too.
- // E.g. resource has been removed from the server while loading it.
- // https://code.google.com/p/chromium/issues/detail?id=414827
- return;
- }
-
- is_multipart_ = false;
- current_chunk_size_ = 0;
- current_chunk_read_ = 0;
-
- pp::Var headers_var = loader_.GetResponseInfo().GetHeaders();
- std::string headers;
- if (headers_var.is_string())
- headers = headers_var.AsString();
-
- std::string boundary = GetMultiPartBoundary(headers);
- if (boundary.size()) {
- // Leave position untouched for now, when we read the data we'll get it.
- is_multipart_ = true;
- multipart_boundary_ = boundary;
- } else {
- // Need to make sure that the server returned a byte-range, since it's
- // possible for a server to just ignore our bye-range request and just
- // return the entire document even if it supports byte-range requests.
- // i.e. sniff response to
- // http://www.act.org/compass/sample/pdf/geometry.pdf
- current_pos_ = 0;
- uint32 start_pos, end_pos;
- if (GetByteRange(headers, &start_pos, &end_pos)) {
- current_pos_ = start_pos;
- if (end_pos && end_pos > start_pos)
- current_chunk_size_ = end_pos - start_pos + 1;
- }
- }
-
- ReadMore();
-}
-
-bool DocumentLoader::GetByteRange(const std::string& headers, uint32* start,
- uint32* end) {
- net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n");
- while (it.GetNext()) {
- if (LowerCaseEqualsASCII(it.name(), "content-range")) {
- std::string range = it.values().c_str();
- if (StartsWithASCII(range, "bytes", false)) {
- range = range.substr(strlen("bytes"));
- std::string::size_type pos = range.find('-');
- std::string range_end;
- if (pos != std::string::npos)
- range_end = range.substr(pos + 1);
- TrimWhitespaceASCII(range, base::TRIM_LEADING, &range);
- TrimWhitespaceASCII(range_end, base::TRIM_LEADING, &range_end);
- *start = atoi(range.c_str());
- *end = atoi(range_end.c_str());
- return true;
- }
- }
- }
- return false;
-}
-
-std::string DocumentLoader::GetMultiPartBoundary(const std::string& headers) {
- net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\n");
- while (it.GetNext()) {
- if (LowerCaseEqualsASCII(it.name(), "content-type")) {
- std::string type = base::StringToLowerASCII(it.values());
- if (StartsWithASCII(type, "multipart/", true)) {
- const char* boundary = strstr(type.c_str(), "boundary=");
- if (!boundary) {
- NOTREACHED();
- break;
- }
-
- return std::string(boundary + 9);
- }
- }
- }
- return std::string();
-}
-
-void DocumentLoader::ReadMore() {
- pp::CompletionCallback callback =
- loader_factory_.NewCallback(&DocumentLoader::DidRead);
- int rv = loader_.ReadResponseBody(buffer_, sizeof(buffer_), callback);
- if (rv != PP_OK_COMPLETIONPENDING)
- callback.Run(rv);
-}
-
-void DocumentLoader::DidRead(int32_t result) {
- if (result > 0) {
- char* start = buffer_;
- size_t length = result;
- if (is_multipart_ && result > 2) {
- for (int i = 2; i < result; ++i) {
- if ((buffer_[i - 1] == '\n' && buffer_[i - 2] == '\n') ||
- (i >= 4 &&
- buffer_[i - 1] == '\n' && buffer_[i - 2] == '\r' &&
- buffer_[i - 3] == '\n' && buffer_[i - 4] == '\r')) {
- uint32 start_pos, end_pos;
- if (GetByteRange(std::string(buffer_, i), &start_pos, &end_pos)) {
- current_pos_ = start_pos;
- start += i;
- length -= i;
- if (end_pos && end_pos > start_pos)
- current_chunk_size_ = end_pos - start_pos + 1;
- }
- break;
- }
- }
-
- // Reset this flag so we don't look inside the buffer in future calls of
- // DidRead for this response. Note that this code DOES NOT handle multi-
- // part responses with more than one part (we don't issue them at the
- // moment, so they shouldn't arrive).
- is_multipart_ = false;
- }
-
- if (current_chunk_size_ &&
- current_chunk_read_ + length > current_chunk_size_)
- length = current_chunk_size_ - current_chunk_read_;
-
- if (length) {
- if (document_size_ > 0) {
- chunk_stream_.WriteData(current_pos_, start, length);
- } else {
- // If we did not get content-length in the response, we can't
- // preallocate buffer for the entire document. Resizing array causing
- // memory fragmentation issues on the large files and OOM exceptions.
- // To fix this, we collect all chunks of the file to the list and
- // concatenate them together after request is complete.
- chunk_buffer_.push_back(std::vector<unsigned char>());
- chunk_buffer_.back().resize(length);
- memcpy(&(chunk_buffer_.back()[0]), start, length);
- }
- current_pos_ += length;
- current_chunk_read_ += length;
- client_->OnNewDataAvailable();
- }
- ReadMore();
- } else if (result == PP_OK) {
- ReadComplete();
- } else {
- NOTREACHED();
- }
-}
-
-void DocumentLoader::ReadComplete() {
- if (!partial_document_) {
- if (document_size_ == 0) {
- // For the document with no 'content-length" specified we've collected all
- // the chunks already. Let's allocate final document buffer and copy them
- // over.
- chunk_stream_.Preallocate(current_pos_);
- uint32 pos = 0;
- std::list<std::vector<unsigned char> >::iterator it;
- for (it = chunk_buffer_.begin(); it != chunk_buffer_.end(); ++it) {
- chunk_stream_.WriteData(pos, &((*it)[0]), it->size());
- pos += it->size();
- }
- chunk_buffer_.clear();
- }
- document_size_ = current_pos_;
- client_->OnDocumentComplete();
- return;
- }
-
- request_pending_ = false;
- pending_requests_.pop_front();
-
- // If there are more pending request - continue downloading.
- if (!pending_requests_.empty()) {
- DownloadPendingRequests();
- return;
- }
-
- if (IsDocumentComplete()) {
- client_->OnDocumentComplete();
- return;
- }
-
- if (header_request_)
- client_->OnPartialDocumentLoaded();
- else
- client_->OnPendingRequestComplete();
- header_request_ = false;
-
- // The OnPendingRequestComplete could have added more requests.
- if (!pending_requests_.empty()) {
- DownloadPendingRequests();
- } else {
- // Document is not complete and we have no outstanding requests.
- // Let's keep downloading PDF file in small chunks.
- uint32 pos = chunk_stream_.GetFirstMissingByte();
- std::vector<std::pair<size_t, size_t> > ranges;
- chunk_stream_.GetMissedRanges(pos, GetRequestSize(), &ranges);
- DCHECK(ranges.size() > 0);
- RequestData(ranges[0].first, ranges[0].second);
- }
-}
-
-uint32 DocumentLoader::GetRequestSize() const {
- // Document loading strategy:
- // For first 10 requests, we use 32k chunk sizes, for the next 10 requests we
- // double the size (64k), and so on, until we cap max request size at 2M for
- // 71 or more requests.
- uint32 limited_count = std::min(std::max(requests_count_, 10u), 70u);
- return 32*1024 * (1 << ((limited_count - 1) / 10u));
-}
-
-} // namespace chrome_pdf
diff --git a/xfa_test/pdf/document_loader.h b/xfa_test/pdf/document_loader.h
deleted file mode 100644
index c09dba2ddd..0000000000
--- a/xfa_test/pdf/document_loader.h
+++ /dev/null
@@ -1,124 +0,0 @@
-// Copyright (c) 2010 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.
-
-#ifndef PDF_DOCUMENT_LOADER_H_
-#define PDF_DOCUMENT_LOADER_H_
-
-#include <list>
-#include <string>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "pdf/chunk_stream.h"
-#include "ppapi/cpp/url_loader.h"
-#include "ppapi/utility/completion_callback_factory.h"
-
-#define kDefaultRequestSize 32768u
-
-namespace chrome_pdf {
-
-class DocumentLoader {
- public:
- class Client {
- public:
- // Gets the pp::Instance object.
- virtual pp::Instance* GetPluginInstance() = 0;
- // Creates new URLLoader based on client settings.
- virtual pp::URLLoader CreateURLLoader() = 0;
- // Notification called when partial information about document is available.
- // Only called for urls that returns full content size and supports byte
- // range requests.
- virtual void OnPartialDocumentLoaded() = 0;
- // Notification called when all outstanding pending requests are complete.
- virtual void OnPendingRequestComplete() = 0;
- // Notification called when new data is available.
- virtual void OnNewDataAvailable() = 0;
- // Notification called when document is fully loaded.
- virtual void OnDocumentComplete() = 0;
- };
-
- explicit DocumentLoader(Client* client);
- virtual ~DocumentLoader();
-
- bool Init(const pp::URLLoader& loader,
- const std::string& url,
- const std::string& headers);
-
- // Data access interface. Return true is sucessful.
- bool GetBlock(uint32 position, uint32 size, void* buf) const;
-
- // Data availability interface. Return true data avaialble.
- bool IsDataAvailable(uint32 position, uint32 size) const;
-
- // Data availability interface. Return true data avaialble.
- void RequestData(uint32 position, uint32 size);
-
- bool IsDocumentComplete() const;
- uint32 document_size() const { return document_size_; }
-
- // Return number of bytes available.
- uint32 GetAvailableData() const;
-
- // Clear pending requests from the queue.
- void ClearPendingRequests();
-
- bool is_partial_document() { return partial_document_; }
-
- private:
- // Called by the completion callback of the document's URLLoader.
- void DidOpen(int32_t result);
- // Call to read data from the document's URLLoader.
- void ReadMore();
- // Called by the completion callback of the document's URLLoader.
- void DidRead(int32_t result);
-
- // If the headers have a byte-range response, writes the start and end
- // positions and returns true if at least the start position was parsed.
- // The end position will be set to 0 if it was not found or parsed from the
- // response.
- // Returns false if not even a start position could be parsed.
- static bool GetByteRange(const std::string& headers, uint32* start,
- uint32* end);
-
- // If the headers have a multi-part response, returns the boundary name.
- // Otherwise returns an empty string.
- static std::string GetMultiPartBoundary(const std::string& headers);
-
- // Called when we detect that partial document load is possible.
- void LoadPartialDocument();
- // Called when we have to load full document.
- void LoadFullDocument();
- // Download pending requests.
- void DownloadPendingRequests();
- // Called when we complete server request and read all data from it.
- void ReadComplete();
- // Creates request to download size byte of data data starting from position.
- pp::URLRequestInfo GetRequest(uint32 position, uint32 size) const;
- // Returns current request size in bytes.
- uint32 GetRequestSize() const;
-
- Client* client_;
- std::string url_;
- pp::URLLoader loader_;
- pp::CompletionCallbackFactory<DocumentLoader> loader_factory_;
- ChunkStream chunk_stream_;
- bool partial_document_;
- bool request_pending_;
- typedef std::list<std::pair<size_t, size_t> > PendingRequests;
- PendingRequests pending_requests_;
- char buffer_[kDefaultRequestSize];
- uint32 current_pos_;
- uint32 current_chunk_size_;
- uint32 current_chunk_read_;
- uint32 document_size_;
- bool header_request_;
- bool is_multipart_;
- std::string multipart_boundary_;
- uint32 requests_count_;
- std::list<std::vector<unsigned char> > chunk_buffer_;
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_DOCUMENT_LOADER_H_
diff --git a/xfa_test/pdf/draw_utils.cc b/xfa_test/pdf/draw_utils.cc
deleted file mode 100644
index d38be52aef..0000000000
--- a/xfa_test/pdf/draw_utils.cc
+++ /dev/null
@@ -1,343 +0,0 @@
-// Copyright (c) 2011 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 "pdf/draw_utils.h"
-
-#include <algorithm>
-#include <math.h>
-#include <vector>
-
-#include "base/logging.h"
-#include "base/numerics/safe_math.h"
-
-namespace chrome_pdf {
-
-inline uint8 GetBlue(const uint32& pixel) {
- return static_cast<uint8>(pixel & 0xFF);
-}
-
-inline uint8 GetGreen(const uint32& pixel) {
- return static_cast<uint8>((pixel >> 8) & 0xFF);
-}
-
-inline uint8 GetRed(const uint32& pixel) {
- return static_cast<uint8>((pixel >> 16) & 0xFF);
-}
-
-inline uint8 GetAlpha(const uint32& pixel) {
- return static_cast<uint8>((pixel >> 24) & 0xFF);
-}
-
-inline uint32_t MakePixel(uint8 red, uint8 green, uint8 blue, uint8 alpha) {
- return (static_cast<uint32_t>(alpha) << 24) |
- (static_cast<uint32_t>(red) << 16) |
- (static_cast<uint32_t>(green) << 8) |
- static_cast<uint32_t>(blue);
-}
-
-inline uint8 GradientChannel(uint8 start, uint8 end, double ratio) {
- double new_channel = start - (static_cast<double>(start) - end) * ratio;
- if (new_channel < 0)
- return 0;
- if (new_channel > 255)
- return 255;
- return static_cast<uint8>(new_channel + 0.5);
-}
-
-inline uint8 ProcessColor(uint8 src_color, uint8 dest_color, uint8 alpha) {
- uint32 processed = static_cast<uint32>(src_color) * alpha +
- static_cast<uint32>(dest_color) * (0xFF - alpha);
- return static_cast<uint8>((processed / 0xFF) & 0xFF);
-}
-
-inline bool ImageDataContainsRect(const pp::ImageData& image_data,
- const pp::Rect& rect) {
- return rect.width() >= 0 && rect.height() >= 0 &&
- pp::Rect(image_data.size()).Contains(rect);
-}
-
-void AlphaBlend(const pp::ImageData& src, const pp::Rect& src_rc,
- pp::ImageData* dest, const pp::Point& dest_origin,
- uint8 alpha_adjustment) {
- if (src_rc.IsEmpty() || !ImageDataContainsRect(src, src_rc))
- return;
-
- pp::Rect dest_rc(dest_origin, src_rc.size());
- if (dest_rc.IsEmpty() || !ImageDataContainsRect(*dest, dest_rc))
- return;
-
- const uint32_t* src_origin_pixel = src.GetAddr32(src_rc.point());
- uint32_t* dest_origin_pixel = dest->GetAddr32(dest_origin);
-
- int height = src_rc.height();
- int width = src_rc.width();
- for (int y = 0; y < height; y++) {
- const uint32_t* src_pixel = src_origin_pixel;
- uint32_t* dest_pixel = dest_origin_pixel;
- for (int x = 0; x < width; x++) {
- uint8 alpha = static_cast<uint8>(static_cast<uint32_t>(alpha_adjustment) *
- GetAlpha(*src_pixel) / 0xFF);
- uint8 red = ProcessColor(GetRed(*src_pixel), GetRed(*dest_pixel), alpha);
- uint8 green = ProcessColor(GetGreen(*src_pixel),
- GetGreen(*dest_pixel), alpha);
- uint8 blue = ProcessColor(GetBlue(*src_pixel),
- GetBlue(*dest_pixel), alpha);
- *dest_pixel = MakePixel(red, green, blue, GetAlpha(*dest_pixel));
-
- src_pixel++;
- dest_pixel++;
- }
- src_origin_pixel = reinterpret_cast<const uint32_t*>(
- reinterpret_cast<const char*>(src_origin_pixel) + src.stride());
- dest_origin_pixel = reinterpret_cast<uint32_t*>(
- reinterpret_cast<char*>(dest_origin_pixel) + dest->stride());
- }
-}
-
-void GradientFill(pp::ImageData* image, const pp::Rect& rc,
- uint32 start_color, uint32 end_color, bool horizontal) {
- std::vector<uint32> colors;
- colors.resize(horizontal ? rc.width() : rc.height());
- for (size_t i = 0; i < colors.size(); ++i) {
- double ratio = static_cast<double>(i) / colors.size();
- colors[i] = MakePixel(
- GradientChannel(GetRed(start_color), GetRed(end_color), ratio),
- GradientChannel(GetGreen(start_color), GetGreen(end_color), ratio),
- GradientChannel(GetBlue(start_color), GetBlue(end_color), ratio),
- GradientChannel(GetAlpha(start_color), GetAlpha(end_color), ratio));
- }
-
- if (horizontal) {
- const void* data = &(colors[0]);
- size_t size = colors.size() * 4;
- uint32_t* origin_pixel = image->GetAddr32(rc.point());
- for (int y = 0; y < rc.height(); y++) {
- memcpy(origin_pixel, data, size);
- origin_pixel = reinterpret_cast<uint32_t*>(
- reinterpret_cast<char*>(origin_pixel) + image->stride());
- }
- } else {
- uint32_t* origin_pixel = image->GetAddr32(rc.point());
- for (int y = 0; y < rc.height(); y++) {
- uint32_t* pixel = origin_pixel;
- for (int x = 0; x < rc.width(); x++) {
- *pixel = colors[y];
- pixel++;
- }
- origin_pixel = reinterpret_cast<uint32_t*>(
- reinterpret_cast<char*>(origin_pixel) + image->stride());
- }
- }
-}
-
-void GradientFill(pp::Instance* instance,
- pp::ImageData* image,
- const pp::Rect& dirty_rc,
- const pp::Rect& gradient_rc,
- uint32 start_color,
- uint32 end_color,
- bool horizontal,
- uint8 transparency) {
- pp::Rect draw_rc = gradient_rc.Intersect(dirty_rc);
- if (draw_rc.IsEmpty())
- return;
-
- pp::ImageData gradient(instance, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
- gradient_rc.size(), false);
-
- GradientFill(&gradient, pp::Rect(pp::Point(), gradient_rc.size()),
- start_color, end_color, horizontal);
-
- pp::Rect copy_rc(draw_rc);
- copy_rc.Offset(-gradient_rc.x(), -gradient_rc.y());
- AlphaBlend(gradient, copy_rc, image, draw_rc.point(), transparency);
-}
-
-void CopyImage(const pp::ImageData& src, const pp::Rect& src_rc,
- pp::ImageData* dest, const pp::Rect& dest_rc,
- bool stretch) {
- if (src_rc.IsEmpty() || !ImageDataContainsRect(src, src_rc))
- return;
-
- pp::Rect stretched_rc(dest_rc.point(),
- stretch ? dest_rc.size() : src_rc.size());
- if (stretched_rc.IsEmpty() || !ImageDataContainsRect(*dest, stretched_rc))
- return;
-
- const uint32_t* src_origin_pixel = src.GetAddr32(src_rc.point());
- uint32_t* dest_origin_pixel = dest->GetAddr32(dest_rc.point());
- if (stretch) {
- double x_ratio = static_cast<double>(src_rc.width()) / dest_rc.width();
- double y_ratio = static_cast<double>(src_rc.height()) / dest_rc.height();
- int32_t height = dest_rc.height();
- int32_t width = dest_rc.width();
- for (int32_t y = 0; y < height; ++y) {
- uint32_t* dest_pixel = dest_origin_pixel;
- for (int32_t x = 0; x < width; ++x) {
- uint32 src_x = static_cast<uint32>(x * x_ratio);
- uint32 src_y = static_cast<uint32>(y * y_ratio);
- const uint32_t* src_pixel = src.GetAddr32(
- pp::Point(src_rc.x() + src_x, src_rc.y() + src_y));
- *dest_pixel = *src_pixel;
- dest_pixel++;
- }
- dest_origin_pixel = reinterpret_cast<uint32_t*>(
- reinterpret_cast<char*>(dest_origin_pixel) + dest->stride());
- }
- } else {
- int32_t height = src_rc.height();
- base::CheckedNumeric<int32_t> width_bytes = src_rc.width();
- width_bytes *= 4;
- for (int32_t y = 0; y < height; ++y) {
- memcpy(dest_origin_pixel, src_origin_pixel, width_bytes.ValueOrDie());
- src_origin_pixel = reinterpret_cast<const uint32_t*>(
- reinterpret_cast<const char*>(src_origin_pixel) + src.stride());
- dest_origin_pixel = reinterpret_cast<uint32_t*>(
- reinterpret_cast<char*>(dest_origin_pixel) + dest->stride());
- }
- }
-}
-
-void FillRect(pp::ImageData* image, const pp::Rect& rc, uint32 color) {
- int height = rc.height();
- if (height == 0)
- return;
-
- // Fill in first row.
- uint32_t* top_line = image->GetAddr32(rc.point());
- int width = rc.width();
- for (int x = 0; x < width; x++)
- top_line[x] = color;
-
- // Fill in the rest of the rectangle.
- int byte_width = width * 4;
- uint32_t* cur_line = reinterpret_cast<uint32_t*>(
- reinterpret_cast<char*>(top_line) + image->stride());
- for (int y = 1; y < height; y++) {
- memcpy(cur_line, top_line, byte_width);
- cur_line = reinterpret_cast<uint32_t*>(
- reinterpret_cast<char*>(cur_line) + image->stride());
- }
-}
-
-ShadowMatrix::ShadowMatrix(uint32 depth, double factor, uint32 background)
- : depth_(depth), factor_(factor), background_(background) {
- DCHECK(depth_ > 0);
- matrix_.resize(depth_ * depth_);
-
- // pv - is a rounding power factor for smoothing corners.
- // pv = 2.0 will make corners completely round.
- const double pv = 4.0;
- // pow_pv - cache to avoid recalculating pow(x, pv) every time.
- std::vector<double> pow_pv(depth_, 0.0);
-
- double r = static_cast<double>(depth_);
- double coef = 256.0 / pow(r, factor);
-
- for (uint32 y = 0; y < depth_; y++) {
- // Since matrix is symmetrical, we can reduce the number of calculations
- // by mirroring results.
- for (uint32 x = 0; x <= y; x++) {
- // Fill cache if needed.
- if (pow_pv[x] == 0.0)
- pow_pv[x] = pow(x, pv);
- if (pow_pv[y] == 0.0)
- pow_pv[y] = pow(y, pv);
-
- // v - is a value for the smoothing function.
- // If x == 0 simplify calculations.
- double v = (x == 0) ? y : pow(pow_pv[x] + pow_pv[y], 1 / pv);
-
- // Smoothing function.
- // If factor == 1, smoothing will be linear from 0 to the end,
- // if 0 < factor < 1, smoothing will drop faster near 0.
- // if factor > 1, smoothing will drop faster near the end (depth).
- double f = 256.0 - coef * pow(v, factor);
-
- uint8 alpha = 0;
- if (f > kOpaqueAlpha)
- alpha = kOpaqueAlpha;
- else if (f < kTransparentAlpha)
- alpha = kTransparentAlpha;
- else
- alpha = static_cast<uint8>(f);
-
- uint8 red = ProcessColor(0, GetRed(background), alpha);
- uint8 green = ProcessColor(0, GetGreen(background), alpha);
- uint8 blue = ProcessColor(0, GetBlue(background), alpha);
- uint32 pixel = MakePixel(red, green, blue, GetAlpha(background));
-
- // Mirror matrix.
- matrix_[y * depth_ + x] = pixel;
- matrix_[x * depth_ + y] = pixel;
- }
- }
-}
-
-ShadowMatrix::~ShadowMatrix() {
-}
-
-void PaintShadow(pp::ImageData* image,
- const pp::Rect& clip_rc,
- const pp::Rect& shadow_rc,
- const ShadowMatrix& matrix) {
- pp::Rect draw_rc = shadow_rc.Intersect(clip_rc);
- if (draw_rc.IsEmpty())
- return;
-
- int32 depth = static_cast<int32>(matrix.depth());
- for (int32_t y = draw_rc.y(); y < draw_rc.bottom(); y++) {
- for (int32_t x = draw_rc.x(); x < draw_rc.right(); x++) {
- int32_t matrix_x = std::max(depth + shadow_rc.x() - x - 1,
- depth - shadow_rc.right() + x);
- int32_t matrix_y = std::max(depth + shadow_rc.y() - y - 1,
- depth - shadow_rc.bottom() + y);
- uint32_t* pixel = image->GetAddr32(pp::Point(x, y));
-
- if (matrix_x < 0)
- matrix_x = 0;
- else if (matrix_x >= static_cast<int32>(depth))
- matrix_x = depth - 1;
-
- if (matrix_y < 0)
- matrix_y = 0;
- else if (matrix_y >= static_cast<int32>(depth))
- matrix_y = depth - 1;
-
- *pixel = matrix.GetValue(matrix_x, matrix_y);
- }
- }
-}
-
-void DrawShadow(pp::ImageData* image,
- const pp::Rect& shadow_rc,
- const pp::Rect& object_rc,
- const pp::Rect& clip_rc,
- const ShadowMatrix& matrix) {
- if (shadow_rc == object_rc)
- return; // Nothing to paint.
-
- // Fill top part.
- pp::Rect rc(shadow_rc.point(),
- pp::Size(shadow_rc.width(), object_rc.y() - shadow_rc.y()));
- PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix);
-
- // Fill bottom part.
- rc = pp::Rect(shadow_rc.x(), object_rc.bottom(),
- shadow_rc.width(), shadow_rc.bottom() - object_rc.bottom());
- PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix);
-
- // Fill left part.
- rc = pp::Rect(shadow_rc.x(), object_rc.y(),
- object_rc.x() - shadow_rc.x(), object_rc.height());
- PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix);
-
- // Fill right part.
- rc = pp::Rect(object_rc.right(), object_rc.y(),
- shadow_rc.right() - object_rc.right(), object_rc.height());
- PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix);
-}
-
-} // namespace chrome_pdf
-
diff --git a/xfa_test/pdf/draw_utils.h b/xfa_test/pdf/draw_utils.h
deleted file mode 100644
index eedf24f27d..0000000000
--- a/xfa_test/pdf/draw_utils.h
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright (c) 2011 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.
-
-#ifndef PDF_DRAW_UTILS_H_
-#define PDF_DRAW_UTILS_H_
-
-#include <vector>
-
-#include "base/basictypes.h"
-#include "ppapi/cpp/image_data.h"
-#include "ppapi/cpp/rect.h"
-
-namespace chrome_pdf {
-
-const uint8 kOpaqueAlpha = 0xFF;
-const uint8 kTransparentAlpha = 0x00;
-
-void AlphaBlend(const pp::ImageData& src, const pp::Rect& src_rc,
- pp::ImageData* dest, const pp::Point& dest_origin,
- uint8 alpha_adjustment);
-
-// Fill rectangle with gradient horizontally or vertically. Start is a color of
-// top-left point of the rectangle, end color is a color of
-// top-right (horizontal==true) or bottom-left (horizontal==false) point.
-void GradientFill(pp::ImageData* image,
- const pp::Rect& rc,
- uint32 start_color,
- uint32 end_color,
- bool horizontal);
-
-// Fill dirty rectangle with gradient, where gradient color set for corners of
-// gradient rectangle. Parts of the dirty rect outside of gradient rect will
-// be unchanged.
-void GradientFill(pp::Instance* instance,
- pp::ImageData* image,
- const pp::Rect& dirty_rc,
- const pp::Rect& gradient_rc,
- uint32 start_color,
- uint32 end_color,
- bool horizontal,
- uint8 transparency);
-
-// Copy one image into another. If stretch is true, the result occupy the entire
-// dest_rc. If stretch is false, dest_rc.point will be used as an origin of the
-// result image. Copy will ignore all pixels with transparent alpha from the
-// source image.
-void CopyImage(const pp::ImageData& src, const pp::Rect& src_rc,
- pp::ImageData* dest, const pp::Rect& dest_rc,
- bool stretch);
-
-// Fill in rectangle with specified color.
-void FillRect(pp::ImageData* image, const pp::Rect& rc, uint32 color);
-
-// Shadow Matrix contains matrix for shadow rendering. To reduce amount of
-// calculations user may choose to cache matrix and reuse it if nothing changed.
-class ShadowMatrix {
- public:
- // Matrix parameters.
- // depth - how big matrix should be. Shadow will go smoothly across the
- // entire matrix from black to background color.
- // If factor == 1, smoothing will be linear from 0 to the end (depth),
- // if 0 < factor < 1, smoothing will drop faster near 0.
- // if factor > 1, smoothing will drop faster near the end (depth).
- ShadowMatrix(uint32 depth, double factor, uint32 background);
-
- ~ShadowMatrix();
-
- uint32 GetValue(int32 x, int32 y) const { return matrix_[y * depth_ + x]; }
-
- uint32 depth() const { return depth_; }
- double factor() const { return factor_; }
- uint32 background() const { return background_; }
-
- private:
- uint32 depth_;
- double factor_;
- uint32 background_;
- std::vector<uint32> matrix_;
-};
-
-// Draw shadow on the image using provided ShadowMatrix.
-// shadow_rc - rectangle occupied by shadow
-// object_rc - rectangle that drops the shadow
-// clip_rc - clipping region
-void DrawShadow(pp::ImageData* image,
- const pp::Rect& shadow_rc,
- const pp::Rect& object_rc,
- const pp::Rect& clip_rc,
- const ShadowMatrix& matrix);
-
-} // namespace chrome_pdf
-
-#endif // PDF_DRAW_UTILS_H_
diff --git a/xfa_test/pdf/fading_control.cc b/xfa_test/pdf/fading_control.cc
deleted file mode 100644
index 7e4d8ef63e..0000000000
--- a/xfa_test/pdf/fading_control.cc
+++ /dev/null
@@ -1,75 +0,0 @@
-// 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 "pdf/fading_control.h"
-
-#include <math.h>
-
-#include "base/logging.h"
-#include "pdf/draw_utils.h"
-#include "pdf/resource_consts.h"
-
-namespace chrome_pdf {
-
-FadingControl::FadingControl()
- : alpha_shift_(0), timer_id_(0) {
-}
-
-FadingControl::~FadingControl() {
-}
-
-void FadingControl::OnTimerFired(uint32 timer_id) {
- if (timer_id == timer_id_) {
- int32 new_alpha = transparency() + alpha_shift_;
- if (new_alpha <= kTransparentAlpha) {
- Show(false, true);
- OnFadeOutComplete();
- return;
- }
- if (new_alpha >= kOpaqueAlpha) {
- AdjustTransparency(kOpaqueAlpha, true);
- OnFadeInComplete();
- return;
- }
-
- AdjustTransparency(static_cast<uint8>(new_alpha), true);
- timer_id_ = owner()->ScheduleTimer(id(), kFadingTimeoutMs);
- }
-}
-
-// Fade In/Out control depending on visible flag over the time of time_ms.
-void FadingControl::Fade(bool show, uint32 time_ms) {
- DCHECK(time_ms != 0);
- // Check if we already in the same state.
- if (!visible() && !show)
- return;
- if (!visible() && show) {
- Show(show, false);
- AdjustTransparency(kTransparentAlpha, false);
- OnFadeOutComplete();
- }
- if (transparency() == kOpaqueAlpha && show) {
- OnFadeInComplete();
- return;
- }
-
- int delta = show ? kOpaqueAlpha - transparency() : transparency();
- double shift =
- static_cast<double>(delta) * kFadingTimeoutMs / time_ms;
- if (shift > delta)
- alpha_shift_ = delta;
- else
- alpha_shift_ = static_cast<int>(ceil(shift));
-
- if (alpha_shift_ == 0)
- alpha_shift_ = 1;
-
- // If disabling, make alpha shift negative.
- if (!show)
- alpha_shift_ = -alpha_shift_;
-
- timer_id_ = owner()->ScheduleTimer(id(), kFadingTimeoutMs);
-}
-
-} // namespace chrome_pdf
diff --git a/xfa_test/pdf/fading_control.h b/xfa_test/pdf/fading_control.h
deleted file mode 100644
index 03ac134698..0000000000
--- a/xfa_test/pdf/fading_control.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// 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.
-
-#ifndef PDF_FADING_CONTROL_H_
-#define PDF_FADING_CONTROL_H_
-
-#include "pdf/control.h"
-
-namespace chrome_pdf {
-
-class FadingControl : public Control {
- public:
- FadingControl();
- virtual ~FadingControl();
-
- virtual void OnTimerFired(uint32 timer_id);
-
- // Fade In/Out control depending on visible flag over the time of time_ms.
- virtual void Fade(bool visible, uint32 time_ms);
-
- virtual void OnFadeInComplete() {}
- virtual void OnFadeOutComplete() {}
-
- private:
- int alpha_shift_;
- uint32 timer_id_;
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_FADING_CONTROL_H_
diff --git a/xfa_test/pdf/fading_controls.cc b/xfa_test/pdf/fading_controls.cc
deleted file mode 100644
index 8a9fd89510..0000000000
--- a/xfa_test/pdf/fading_controls.cc
+++ /dev/null
@@ -1,316 +0,0 @@
-// 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 "pdf/fading_controls.h"
-
-#include "base/logging.h"
-#include "base/stl_util.h"
-#include "pdf/draw_utils.h"
-#include "pdf/resource_consts.h"
-#include "ppapi/cpp/input_event.h"
-
-namespace chrome_pdf {
-
-const uint32 kFadingAlphaShift = 64;
-const uint32 kSplashFadingAlphaShift = 16;
-
-FadingControls::FadingControls()
- : state_(NONE), current_transparency_(kOpaqueAlpha), fading_timer_id_(0),
- current_capture_control_(kInvalidControlId),
- fading_timeout_(kFadingTimeoutMs), alpha_shift_(kFadingAlphaShift),
- splash_(false), splash_timeout_(0) {
-}
-
-FadingControls::~FadingControls() {
- STLDeleteElements(&controls_);
-}
-
-bool FadingControls::CreateFadingControls(
- uint32 id, const pp::Rect& rc, bool visible,
- Control::Owner* owner, uint8 transparency) {
- current_transparency_ = transparency;
- return Control::Create(id, rc, visible, owner);
-}
-
-void FadingControls::Paint(pp::ImageData* image_data, const pp::Rect& rc) {
- // When this control is set to invisible the individual controls are not.
- // So we need to check for visible() here.
- if (!visible())
- return;
-
- std::list<Control*>::iterator iter;
- for (iter = controls_.begin(); iter != controls_.end(); ++iter) {
- (*iter)->Paint(image_data, rc);
- }
-}
-
-bool FadingControls::HandleEvent(const pp::InputEvent& event) {
- if (!visible())
- return false;
-
- pp::MouseInputEvent mouse_event(event);
- if (mouse_event.is_null())
- return NotifyControls(event);
-
- pp::Point pt = mouse_event.GetPosition();
-
- bool is_mouse_click =
- mouse_event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN ||
- mouse_event.GetType() == PP_INPUTEVENT_TYPE_MOUSEUP;
-
- if (rect().Contains(pt)) {
- CancelSplashMode();
- FadeIn();
-
- // Eat mouse click if are invisible or just fading in.
- // That prevents accidental clicks on the controls for touch devices.
- bool eat_mouse_click =
- (state_ == FADING_IN || current_transparency_ == kTransparentAlpha);
- if (eat_mouse_click && is_mouse_click &&
- mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT)
- return true; // Eat this event here.
- }
-
- if ((!rect().Contains(pt)) ||
- event.GetType() == PP_INPUTEVENT_TYPE_MOUSELEAVE) {
- if (!splash_)
- FadeOut();
- pp::MouseInputEvent event_leave(pp::MouseInputEvent(
- owner()->GetInstance(),
- PP_INPUTEVENT_TYPE_MOUSELEAVE,
- event.GetTimeStamp(),
- event.GetModifiers(),
- mouse_event.GetButton(),
- mouse_event.GetPosition(),
- mouse_event.GetClickCount(),
- mouse_event.GetMovement()));
- return NotifyControls(event_leave);
- }
-
- return NotifyControls(event);
-}
-
-void FadingControls::OnTimerFired(uint32 timer_id) {
- if (timer_id == fading_timer_id_) {
- int32 current_alpha = static_cast<int32>(current_transparency_);
- if (state_ == FADING_IN)
- current_alpha += alpha_shift_;
- else if (state_ == FADING_OUT)
- current_alpha -= alpha_shift_;
-
- if (current_alpha >= kOpaqueAlpha) {
- state_ = NONE;
- current_alpha = kOpaqueAlpha;
- } else if (current_alpha <= kTransparentAlpha) {
- state_ = NONE;
- current_alpha = kTransparentAlpha;
- }
- current_transparency_ = static_cast<uint8>(current_alpha);
-
- // Invalidate controls with new alpha transparency.
- std::list<Control*>::iterator iter;
- for (iter = controls_.begin(); iter != controls_.end(); ++iter) {
- // We are going to invalidate the whole FadingControls area, to
- // allow simultaneous drawing.
- (*iter)->AdjustTransparency(current_transparency_, false);
- }
- owner()->Invalidate(id(), GetControlsRect());
-
- if (state_ != NONE) // Fading still in progress.
- fading_timer_id_ = owner()->ScheduleTimer(id(), fading_timeout_);
- else
- OnFadingComplete();
- } else {
- // Dispatch timer to controls.
- std::list<Control*>::iterator iter;
- for (iter = controls_.begin(); iter != controls_.end(); ++iter) {
- (*iter)->OnTimerFired(timer_id);
- }
- }
-}
-
-void FadingControls::EventCaptureReleased() {
- if (current_capture_control_ != kInvalidControlId) {
- // Remove previous catpure.
- Control* ctrl = GetControl(current_capture_control_);
- if (ctrl)
- ctrl->EventCaptureReleased();
- }
-}
-
-void FadingControls::MoveBy(const pp::Point& offset, bool invalidate) {
- std::list<Control*>::iterator iter;
- for (iter = controls_.begin(); iter != controls_.end(); ++iter) {
- // We invalidate entire FadingControl later if needed.
- (*iter)->MoveBy(offset, false);
- }
- Control::MoveBy(offset, invalidate);
-}
-
-void FadingControls::OnEvent(uint32 control_id, uint32 event_id, void* data) {
- owner()->OnEvent(control_id, event_id, data);
-}
-
-void FadingControls::Invalidate(uint32 control_id, const pp::Rect& rc) {
- owner()->Invalidate(control_id, rc);
-}
-
-uint32 FadingControls::ScheduleTimer(uint32 control_id, uint32 timeout_ms) {
- // TODO(gene): implement timer routine properly.
- NOTIMPLEMENTED();
- //owner()->ScheduleTimer(control_id);
- return 0;
-}
-
-void FadingControls::SetEventCapture(uint32 control_id, bool set_capture) {
- if (control_id == current_capture_control_) {
- if (!set_capture) // Remove event capture.
- current_capture_control_ = kInvalidControlId;
- } else {
- EventCaptureReleased();
- current_capture_control_ = control_id;
- }
-}
-
-void FadingControls::SetCursor(uint32 control_id,
- PP_CursorType_Dev cursor_type) {
- owner()->SetCursor(control_id, cursor_type);
-}
-
-pp::Instance* FadingControls::GetInstance() {
- return owner()->GetInstance();
-}
-
-bool FadingControls::AddControl(Control* control) {
- DCHECK(control);
- if (control->owner() != this)
- return false;
- if (!rect().Contains(control->rect()))
- return false;
-
- control->AdjustTransparency(current_transparency_, false);
- controls_.push_back(control);
- return true;
-}
-
-void FadingControls::RemoveControl(uint32 control_id) {
- if (current_capture_control_ == control_id) {
- current_capture_control_ = kInvalidControlId;
- }
- std::list<Control*>::iterator iter;
- for (iter = controls_.begin(); iter != controls_.end(); ++iter) {
- if ((*iter)->id() == control_id) {
- delete (*iter);
- controls_.erase(iter);
- break;
- }
- }
-}
-
-Control* FadingControls::GetControl(uint32 id) {
- std::list<Control*>::iterator iter;
- for (iter = controls_.begin(); iter != controls_.end(); ++iter) {
- if ((*iter)->id() == id)
- return *iter;
- }
- return NULL;
-}
-
-pp::Rect FadingControls::GetControlsRect() {
- pp::Rect rc;
- std::list<Control*>::iterator iter;
- for (iter = controls_.begin(); iter != controls_.end(); ++iter) {
- rc = rc.Union((*iter)->rect());
- }
- return rc;
-}
-
-bool FadingControls::ExpandLeft(int offset) {
- pp::Rect rc = rect();
- rc.set_width(rc.width() + offset);
- rc.set_x(rc.x() - offset);
- if (!rc.Contains(GetControlsRect()))
- return false;
- // No need to invalidate since we are expanding triggering area only.
- SetRect(rc, false);
- return true;
-}
-
-void FadingControls::Splash(uint32 time_ms) {
- splash_ = true;
- splash_timeout_ = time_ms;
- alpha_shift_ = kSplashFadingAlphaShift;
- FadeIn();
-}
-
-bool FadingControls::NotifyControls(const pp::InputEvent& event) {
- // First pass event to a control that current capture is set to.
- Control* ctrl = GetControl(current_capture_control_);
- if (ctrl) {
- if (ctrl->HandleEvent(event))
- return true;
- }
-
- std::list<Control*>::iterator iter;
- for (iter = controls_.begin(); iter != controls_.end(); ++iter) {
- // Now pass event to all control except control with capture,
- // since we already passed to it above.
- if ((*iter) != ctrl && (*iter)->HandleEvent(event))
- return true;
- }
- return false;
-}
-
-void FadingControls::FadeIn() {
- bool already_visible =
- (state_ == NONE && current_transparency_ == kOpaqueAlpha);
- if (state_ != FADING_IN && !already_visible) {
- state_ = FADING_IN;
- fading_timer_id_ = owner()->ScheduleTimer(id(), fading_timeout_);
- }
- if (already_visible)
- OnFadingComplete();
-}
-
-void FadingControls::FadeOut() {
- bool already_invisible =
- (state_ == NONE && current_transparency_ == kTransparentAlpha);
- if (state_ != FADING_OUT && !already_invisible) {
- state_ = FADING_OUT;
- fading_timer_id_ = owner()->ScheduleTimer(id(), fading_timeout_);
- }
- if (already_invisible)
- OnFadingComplete();
-}
-
-void FadingControls::OnFadingComplete() {
- DCHECK(current_transparency_ == kOpaqueAlpha ||
- current_transparency_ == kTransparentAlpha);
- // In the splash mode following states are possible:
- // Fade-in complete: splash_==true, splash_timeout_ != 0
- // We need to schedule timer for splash_timeout_.
- // Splash timeout complete: splash_==true, splash_timeout_ == 0
- // We need to fade out still using splash settings.
- // Fade-out complete: current_transparency_ == kTransparentAlpha
- // We need to cancel splash mode and go back to normal settings.
- if (splash_) {
- if (current_transparency_ == kOpaqueAlpha) {
- if (splash_timeout_) {
- fading_timer_id_ = owner()->ScheduleTimer(id(), splash_timeout_);
- splash_timeout_ = 0;
- } else {
- FadeOut();
- }
- } else {
- CancelSplashMode();
- }
- }
-}
-
-void FadingControls::CancelSplashMode() {
- splash_ = false;
- alpha_shift_ = kFadingAlphaShift;
-}
-
-} // namespace chrome_pdf
diff --git a/xfa_test/pdf/fading_controls.h b/xfa_test/pdf/fading_controls.h
deleted file mode 100644
index 532464b473..0000000000
--- a/xfa_test/pdf/fading_controls.h
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright (c) 2010 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.
-
-#ifndef PDF_FADING_CONTROLS_H_
-#define PDF_FADING_CONTROLS_H_
-
-#include <list>
-
-#include "pdf/control.h"
-
-namespace chrome_pdf {
-
-class FadingControls : public Control,
- public ControlOwner {
- public:
- enum FadingState {
- NONE,
- FADING_IN,
- FADING_OUT
- };
-
- FadingControls();
- virtual ~FadingControls();
- virtual bool CreateFadingControls(
- uint32 id, const pp::Rect& rc, bool visible,
- Control::Owner* delegate, uint8 transparency);
-
- // Control interface.
- virtual void Paint(pp::ImageData* image_data, const pp::Rect& rc);
- virtual bool HandleEvent(const pp::InputEvent& event);
- virtual void OnTimerFired(uint32 timer_id);
- virtual void EventCaptureReleased();
- virtual void MoveBy(const pp::Point& offset, bool invalidate);
-
- // ControlOwner interface.
- virtual void OnEvent(uint32 control_id, uint32 event_id, void* data);
- virtual void Invalidate(uint32 control_id, const pp::Rect& rc);
- virtual uint32 ScheduleTimer(uint32 control_id, uint32 timeout_ms);
- virtual void SetEventCapture(uint32 control_id, bool set_capture);
- virtual void SetCursor(uint32 control_id, PP_CursorType_Dev cursor_type);
- virtual pp::Instance* GetInstance();
-
- // FadingControls interface
- // This function takes ownership of the control, and will destoy it
- // when control is destroyed.
- // Input control MUST be located inside FadingControls boundaries, and has
- // this instance of FadingControls as a delegate.
- virtual bool AddControl(Control* control);
- virtual void RemoveControl(uint32 control_id);
- virtual Control* GetControl(uint32 id);
- virtual pp::Rect GetControlsRect();
-
- // Expand/Shrink area which triggers inner control appearance to the left.
- virtual bool ExpandLeft(int offset);
-
- // Fade-in, then show controls for time_ms, and then fade-out. Any mouse
- // event in this control area will interrupt splash mode.
- virtual void Splash(uint32 time_ms);
-
- uint8 current_transparency() const { return current_transparency_; }
-
- private:
- bool NotifyControls(const pp::InputEvent& event);
- void FadeIn();
- void FadeOut();
- void OnFadingComplete();
- void CancelSplashMode();
-
- std::list<Control*> controls_;
- FadingState state_;
- uint8 current_transparency_;
- uint32 fading_timer_id_;
- uint32 current_capture_control_;
- uint32 fading_timeout_;
- uint32 alpha_shift_;
- bool splash_;
- uint32 splash_timeout_;
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_FADING_CONTROLS_H_
-
diff --git a/xfa_test/pdf/instance.cc b/xfa_test/pdf/instance.cc
deleted file mode 100644
index 4bd2f787df..0000000000
--- a/xfa_test/pdf/instance.cc
+++ /dev/null
@@ -1,2778 +0,0 @@
-// 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 "pdf/instance.h"
-
-#include <algorithm> // for min()
-#define _USE_MATH_DEFINES // for M_PI
-#include <cmath> // for log() and pow()
-#include <math.h>
-#include <list>
-
-#include "base/json/json_reader.h"
-#include "base/json/json_writer.h"
-#include "base/logging.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_split.h"
-#include "base/strings/string_util.h"
-#include "base/values.h"
-#include "chrome/browser/chrome_page_zoom_constants.h"
-#include "chrome/common/content_restriction.h"
-#include "content/public/common/page_zoom.h"
-#include "net/base/escape.h"
-#include "pdf/draw_utils.h"
-#include "pdf/number_image_generator.h"
-#include "pdf/pdf.h"
-#include "pdf/resource_consts.h"
-#include "ppapi/c/dev/ppb_cursor_control_dev.h"
-#include "ppapi/c/pp_errors.h"
-#include "ppapi/c/pp_rect.h"
-#include "ppapi/c/private/ppp_pdf.h"
-#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
-#include "ppapi/cpp/core.h"
-#include "ppapi/cpp/dev/font_dev.h"
-#include "ppapi/cpp/dev/memory_dev.h"
-#include "ppapi/cpp/dev/text_input_dev.h"
-#include "ppapi/cpp/module.h"
-#include "ppapi/cpp/point.h"
-#include "ppapi/cpp/private/pdf.h"
-#include "ppapi/cpp/rect.h"
-#include "ppapi/cpp/resource.h"
-#include "ppapi/cpp/url_request_info.h"
-#include "ui/events/keycodes/keyboard_codes.h"
-
-#if defined(OS_MACOSX)
-#include "base/mac/mac_util.h"
-#endif
-
-namespace chrome_pdf {
-
-struct ToolbarButtonInfo {
- uint32 id;
- Button::ButtonStyle style;
- PP_ResourceImage normal;
- PP_ResourceImage highlighted;
- PP_ResourceImage pressed;
-};
-
-namespace {
-
-// Uncomment following #define to enable thumbnails.
-// #define ENABLE_THUMBNAILS
-
-const uint32 kToolbarSplashTimeoutMs = 6000;
-const uint32 kMessageTextColor = 0xFF575757;
-const uint32 kMessageTextSize = 22;
-const uint32 kProgressFadeTimeoutMs = 250;
-const uint32 kProgressDelayTimeoutMs = 1000;
-const uint32 kAutoScrollTimeoutMs = 50;
-const double kAutoScrollFactor = 0.2;
-
-// Javascript methods.
-const char kJSAccessibility[] = "accessibility";
-const char kJSDocumentLoadComplete[] = "documentLoadComplete";
-const char kJSGetHeight[] = "getHeight";
-const char kJSGetHorizontalScrollbarThickness[] =
- "getHorizontalScrollbarThickness";
-const char kJSGetPageLocationNormalized[] = "getPageLocationNormalized";
-const char kJSGetSelectedText[] = "getSelectedText";
-const char kJSGetVerticalScrollbarThickness[] = "getVerticalScrollbarThickness";
-const char kJSGetWidth[] = "getWidth";
-const char kJSGetZoomLevel[] = "getZoomLevel";
-const char kJSGoToPage[] = "goToPage";
-const char kJSGrayscale[] = "grayscale";
-const char kJSLoadPreviewPage[] = "loadPreviewPage";
-const char kJSOnLoad[] = "onload";
-const char kJSOnPluginSizeChanged[] = "onPluginSizeChanged";
-const char kJSOnScroll[] = "onScroll";
-const char kJSPageXOffset[] = "pageXOffset";
-const char kJSPageYOffset[] = "pageYOffset";
-const char kJSPrintPreviewPageCount[] = "printPreviewPageCount";
-const char kJSReload[] = "reload";
-const char kJSRemovePrintButton[] = "removePrintButton";
-const char kJSResetPrintPreviewUrl[] = "resetPrintPreviewUrl";
-const char kJSSendKeyEvent[] = "sendKeyEvent";
-const char kJSSetPageNumbers[] = "setPageNumbers";
-const char kJSSetPageXOffset[] = "setPageXOffset";
-const char kJSSetPageYOffset[] = "setPageYOffset";
-const char kJSSetZoomLevel[] = "setZoomLevel";
-const char kJSZoomFitToHeight[] = "fitToHeight";
-const char kJSZoomFitToWidth[] = "fitToWidth";
-const char kJSZoomIn[] = "zoomIn";
-const char kJSZoomOut[] = "zoomOut";
-
-// URL reference parameters.
-// For more possible parameters, see RFC 3778 and the "PDF Open Parameters"
-// document from Adobe.
-const char kDelimiters[] = "#&";
-const char kNamedDest[] = "nameddest";
-const char kPage[] = "page";
-
-const char kChromePrint[] = "chrome://print/";
-
-// Dictionary Value key names for the document accessibility info
-const char kAccessibleNumberOfPages[] = "numberOfPages";
-const char kAccessibleLoaded[] = "loaded";
-const char kAccessibleCopyable[] = "copyable";
-
-const ToolbarButtonInfo kPDFToolbarButtons[] = {
- { kFitToPageButtonId, Button::BUTTON_STATE,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTP,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTP_HOVER,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTP_PRESSED },
- { kFitToWidthButtonId, Button::BUTTON_STATE,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTW,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTW_HOVER,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTW_PRESSED },
- { kZoomOutButtonId, Button::BUTTON_CLICKABLE,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_HOVER,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_PRESSED },
- { kZoomInButtonId, Button::BUTTON_CLICKABLE,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_HOVER,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_PRESSED },
- { kSaveButtonId, Button::BUTTON_CLICKABLE,
- PP_RESOURCEIMAGE_PDF_BUTTON_SAVE,
- PP_RESOURCEIMAGE_PDF_BUTTON_SAVE_HOVER,
- PP_RESOURCEIMAGE_PDF_BUTTON_SAVE_PRESSED },
- { kPrintButtonId, Button::BUTTON_CLICKABLE,
- PP_RESOURCEIMAGE_PDF_BUTTON_PRINT,
- PP_RESOURCEIMAGE_PDF_BUTTON_PRINT_HOVER,
- PP_RESOURCEIMAGE_PDF_BUTTON_PRINT_PRESSED },
-};
-
-const ToolbarButtonInfo kPDFNoPrintToolbarButtons[] = {
- { kFitToPageButtonId, Button::BUTTON_STATE,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTP,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTP_HOVER,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTP_PRESSED },
- { kFitToWidthButtonId, Button::BUTTON_STATE,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTW,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTW_HOVER,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTW_PRESSED },
- { kZoomOutButtonId, Button::BUTTON_CLICKABLE,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_HOVER,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_PRESSED },
- { kZoomInButtonId, Button::BUTTON_CLICKABLE,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_HOVER,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_PRESSED },
- { kSaveButtonId, Button::BUTTON_CLICKABLE,
- PP_RESOURCEIMAGE_PDF_BUTTON_SAVE,
- PP_RESOURCEIMAGE_PDF_BUTTON_SAVE_HOVER,
- PP_RESOURCEIMAGE_PDF_BUTTON_SAVE_PRESSED },
- { kPrintButtonId, Button::BUTTON_CLICKABLE,
- PP_RESOURCEIMAGE_PDF_BUTTON_PRINT_DISABLED,
- PP_RESOURCEIMAGE_PDF_BUTTON_PRINT_DISABLED,
- PP_RESOURCEIMAGE_PDF_BUTTON_PRINT_DISABLED }
-};
-
-const ToolbarButtonInfo kPrintPreviewToolbarButtons[] = {
- { kFitToPageButtonId, Button::BUTTON_STATE,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTP,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTP_HOVER,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTP_PRESSED },
- { kFitToWidthButtonId, Button::BUTTON_STATE,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTW,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTW_HOVER,
- PP_RESOURCEIMAGE_PDF_BUTTON_FTW_PRESSED },
- { kZoomOutButtonId, Button::BUTTON_CLICKABLE,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_HOVER,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMOUT_PRESSED },
- { kZoomInButtonId, Button::BUTTON_CLICKABLE,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END_HOVER,
- PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN_END_PRESSED },
-};
-
-static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1;
-
-PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) {
- pp::Var var;
- void* object =
- pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface);
- if (object)
- var = static_cast<Instance*>(object)->GetLinkAtPosition(pp::Point(point));
- return var.Detach();
-}
-
-void Transform(PP_Instance instance, PP_PrivatePageTransformType type) {
- void* object =
- pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface);
- if (object) {
- Instance* obj_instance = static_cast<Instance*>(object);
- switch (type) {
- case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW:
- obj_instance->RotateClockwise();
- break;
- case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW:
- obj_instance->RotateCounterclockwise();
- break;
- }
- }
-}
-
-const PPP_Pdf ppp_private = {
- &GetLinkAtPosition,
- &Transform
-};
-
-int ExtractPrintPreviewPageIndex(const std::string& src_url) {
- // Sample |src_url| format: chrome://print/id/page_index/print.pdf
- std::vector<std::string> url_substr;
- base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr);
- if (url_substr.size() != 3)
- return -1;
-
- if (url_substr[2] != "print.pdf")
- return -1;
-
- int page_index = 0;
- if (!base::StringToInt(url_substr[1], &page_index))
- return -1;
- return page_index;
-}
-
-bool IsPrintPreviewUrl(const std::string& url) {
- return url.substr(0, strlen(kChromePrint)) == kChromePrint;
-}
-
-void ScalePoint(float scale, pp::Point* point) {
- point->set_x(static_cast<int>(point->x() * scale));
- point->set_y(static_cast<int>(point->y() * scale));
-}
-
-void ScaleRect(float scale, pp::Rect* rect) {
- int left = static_cast<int>(floorf(rect->x() * scale));
- int top = static_cast<int>(floorf(rect->y() * scale));
- int right = static_cast<int>(ceilf((rect->x() + rect->width()) * scale));
- int bottom = static_cast<int>(ceilf((rect->y() + rect->height()) * scale));
- rect->SetRect(left, top, right - left, bottom - top);
-}
-
-template<class T>
-T ClipToRange(T value, T lower_boundary, T upper_boundary) {
- DCHECK(lower_boundary <= upper_boundary);
- return std::max<T>(lower_boundary, std::min<T>(value, upper_boundary));
-}
-
-} // namespace
-
-Instance::Instance(PP_Instance instance)
- : pp::InstancePrivate(instance),
- pp::Find_Private(this),
- pp::Printing_Dev(this),
- pp::Selection_Dev(this),
- pp::WidgetClient_Dev(this),
- pp::Zoom_Dev(this),
- cursor_(PP_CURSORTYPE_POINTER),
- timer_pending_(false),
- current_timer_id_(0),
- zoom_(1.0),
- device_scale_(1.0),
- printing_enabled_(true),
- hidpi_enabled_(false),
- full_(IsFullFrame()),
- zoom_mode_(full_ ? ZOOM_AUTO : ZOOM_SCALE),
- did_call_start_loading_(false),
- is_autoscroll_(false),
- scrollbar_thickness_(-1),
- scrollbar_reserved_thickness_(-1),
- current_tb_info_(NULL),
- current_tb_info_size_(0),
- paint_manager_(this, this, true),
- delayed_progress_timer_id_(0),
- first_paint_(true),
- painted_first_page_(false),
- show_page_indicator_(false),
- document_load_state_(LOAD_STATE_LOADING),
- preview_document_load_state_(LOAD_STATE_COMPLETE),
- told_browser_about_unsupported_feature_(false),
- print_preview_page_count_(0) {
- loader_factory_.Initialize(this);
- timer_factory_.Initialize(this);
- form_factory_.Initialize(this);
- callback_factory_.Initialize(this);
- engine_.reset(PDFEngine::Create(this));
- pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private);
- AddPerInstanceObject(kPPPPdfInterface, this);
-
- RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
- RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_WHEEL);
- RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
- RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_TOUCH);
-}
-
-Instance::~Instance() {
- if (timer_pending_) {
- timer_factory_.CancelAll();
- timer_pending_ = false;
- }
- // The engine may try to access this instance during its destruction.
- // Make sure this happens early while the instance is still intact.
- engine_.reset();
- RemovePerInstanceObject(kPPPPdfInterface, this);
-}
-
-bool Instance::Init(uint32_t argc, const char* argn[], const char* argv[]) {
- // For now, we hide HiDPI support behind a flag.
- if (pp::PDF::IsFeatureEnabled(this, PP_PDFFEATURE_HIDPI))
- hidpi_enabled_ = true;
-
- printing_enabled_ = pp::PDF::IsFeatureEnabled(this, PP_PDFFEATURE_PRINTING);
- if (printing_enabled_) {
- CreateToolbar(kPDFToolbarButtons, arraysize(kPDFToolbarButtons));
- } else {
- CreateToolbar(kPDFNoPrintToolbarButtons,
- arraysize(kPDFNoPrintToolbarButtons));
- }
-
- CreateProgressBar();
-
- // Load autoscroll anchor image.
- autoscroll_anchor_ =
- CreateResourceImage(PP_RESOURCEIMAGE_PDF_PAN_SCROLL_ICON);
-
-#ifdef ENABLE_THUMBNAILS
- CreateThumbnails();
-#endif
- const char* url = NULL;
- for (uint32_t i = 0; i < argc; ++i) {
- if (strcmp(argn[i], "src") == 0) {
- url = argv[i];
- break;
- }
- }
-
- if (!url)
- return false;
-
- CreatePageIndicator(IsPrintPreviewUrl(url));
-
- if (!full_) {
- // For PDFs embedded in a frame, we don't get the data automatically like we
- // do for full-frame loads. Start loading the data manually.
- LoadUrl(url);
- } else {
- DCHECK(!did_call_start_loading_);
- pp::PDF::DidStartLoading(this);
- did_call_start_loading_ = true;
- }
-
- ZoomLimitsChanged(kMinZoom, kMaxZoom);
-
- text_input_.reset(new pp::TextInput_Dev(this));
-
- url_ = url;
- return engine_->New(url);
-}
-
-bool Instance::HandleDocumentLoad(const pp::URLLoader& loader) {
- delayed_progress_timer_id_ = ScheduleTimer(kProgressBarId,
- kProgressDelayTimeoutMs);
- return engine_->HandleDocumentLoad(loader);
-}
-
-bool Instance::HandleInputEvent(const pp::InputEvent& event) {
- // To simplify things, convert the event into device coordinates if it is
- // a mouse event.
- pp::InputEvent event_device_res(event);
- {
- pp::MouseInputEvent mouse_event(event);
- if (!mouse_event.is_null()) {
- pp::Point point = mouse_event.GetPosition();
- pp::Point movement = mouse_event.GetMovement();
- ScalePoint(device_scale_, &point);
- ScalePoint(device_scale_, &movement);
- mouse_event = pp::MouseInputEvent(
- this,
- event.GetType(),
- event.GetTimeStamp(),
- event.GetModifiers(),
- mouse_event.GetButton(),
- point,
- mouse_event.GetClickCount(),
- movement);
- event_device_res = mouse_event;
- }
- }
-
- // Check if we need to go to autoscroll mode.
- if (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEMOVE &&
- (event.GetModifiers() & PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN)) {
- pp::MouseInputEvent mouse_event(event_device_res);
- pp::Point pos = mouse_event.GetPosition();
- EnableAutoscroll(pos);
- UpdateCursor(CalculateAutoscroll(pos));
- return true;
- } else {
- // Quit autoscrolling on any other event.
- DisableAutoscroll();
- }
-
-#ifdef ENABLE_THUMBNAILS
- if (event.GetType() == PP_INPUTEVENT_TYPE_MOUSELEAVE)
- thumbnails_.SlideOut();
-
- if (thumbnails_.HandleEvent(event_device_res))
- return true;
-#endif
-
- if (toolbar_->HandleEvent(event_device_res))
- return true;
-
-#ifdef ENABLE_THUMBNAILS
- if (v_scrollbar_.get() && event.GetType() == PP_INPUTEVENT_TYPE_MOUSEMOVE) {
- pp::MouseInputEvent mouse_event(event);
- pp::Point pt = mouse_event.GetPosition();
- pp::Rect v_scrollbar_rc;
- v_scrollbar_->GetLocation(&v_scrollbar_rc);
- // There is a bug (https://bugs.webkit.org/show_bug.cgi?id=45208)
- // in the webkit that makes event.u.mouse.button
- // equal to PP_INPUTEVENT_MOUSEBUTTON_LEFT, even when no button is pressed.
- // To work around this issue we use modifier for now, and will switch
- // to button once the bug is fixed and webkit got merged back to our tree.
- if (v_scrollbar_rc.Contains(pt) &&
- (event.GetModifiers() & PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN)) {
- thumbnails_.SlideIn();
- }
-
- // When scrollbar is in the scrolling mode we should display thumbnails
- // even the mouse is outside the thumbnail and scrollbar areas.
- // If mouse is outside plugin area, we are still getting mouse move events
- // while scrolling. See bug description for details:
- // http://code.google.com/p/chromium/issues/detail?id=56444
- if (!v_scrollbar_rc.Contains(pt) && thumbnails_.visible() &&
- !(event.GetModifiers() & PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN) &&
- !thumbnails_.rect().Contains(pt)) {
- thumbnails_.SlideOut();
- }
- }
-#endif
-
- // Need to pass the event to the engine first, since if we're over an edit
- // control we want it to get keyboard events (like space) instead of the
- // scrollbar.
- // TODO: will have to offset the mouse coordinates once we support bidi and
- // there could be scrollbars on the left.
- pp::InputEvent offset_event(event_device_res);
- bool try_engine_first = true;
- switch (offset_event.GetType()) {
- case PP_INPUTEVENT_TYPE_MOUSEDOWN:
- case PP_INPUTEVENT_TYPE_MOUSEUP:
- case PP_INPUTEVENT_TYPE_MOUSEMOVE:
- case PP_INPUTEVENT_TYPE_MOUSEENTER:
- case PP_INPUTEVENT_TYPE_MOUSELEAVE: {
- pp::MouseInputEvent mouse_event(event_device_res);
- pp::MouseInputEvent mouse_event_dip(event);
- pp::Point point = mouse_event.GetPosition();
- point.set_x(point.x() - available_area_.x());
- offset_event = pp::MouseInputEvent(
- this,
- event.GetType(),
- event.GetTimeStamp(),
- event.GetModifiers(),
- mouse_event.GetButton(),
- point,
- mouse_event.GetClickCount(),
- mouse_event.GetMovement());
- if (!engine_->IsSelecting()) {
- if (!IsOverlayScrollbar() &&
- !available_area_.Contains(mouse_event.GetPosition())) {
- try_engine_first = false;
- } else if (IsOverlayScrollbar()) {
- pp::Rect temp;
- if ((v_scrollbar_.get() && v_scrollbar_->GetLocation(&temp) &&
- temp.Contains(mouse_event_dip.GetPosition())) ||
- (h_scrollbar_.get() && h_scrollbar_->GetLocation(&temp) &&
- temp.Contains(mouse_event_dip.GetPosition()))) {
- try_engine_first = false;
- }
- }
- }
- break;
- }
- default:
- break;
- }
- if (try_engine_first && engine_->HandleEvent(offset_event))
- return true;
-
- // Left/Right arrows should scroll to the beginning of the Prev/Next page if
- // there is no horizontal scroll bar.
- // If fit-to-height, PgDown/PgUp should scroll to the beginning of the
- // Prev/Next page. Spacebar / shift+spacebar should do the same.
- if (v_scrollbar_.get() && event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN) {
- pp::KeyboardInputEvent keyboard_event(event);
- bool no_h_scrollbar = !h_scrollbar_.get();
- uint32_t key_code = keyboard_event.GetKeyCode();
- bool page_down = no_h_scrollbar && key_code == ui::VKEY_RIGHT;
- bool page_up = no_h_scrollbar && key_code == ui::VKEY_LEFT;
- if (zoom_mode_ == ZOOM_FIT_TO_PAGE) {
- bool has_shift =
- keyboard_event.GetModifiers() & PP_INPUTEVENT_MODIFIER_SHIFTKEY;
- bool key_is_space = key_code == ui::VKEY_SPACE;
- page_down |= key_is_space || key_code == ui::VKEY_NEXT;
- page_up |= (key_is_space && has_shift) || (key_code == ui::VKEY_PRIOR);
- }
- if (page_down) {
- int page = engine_->GetFirstVisiblePage();
- if (page == -1)
- return true;
- // Engine calculates visible page including delimiter to the page size.
- // We need to check here if the page itself is completely out of view and
- // scroll to the next one in that case.
- if (engine_->GetPageRect(page).bottom() * zoom_ <=
- v_scrollbar_->GetValue())
- page++;
- ScrollToPage(page + 1);
- UpdateCursor(PP_CURSORTYPE_POINTER);
- return true;
- } else if (page_up) {
- int page = engine_->GetFirstVisiblePage();
- if (page == -1)
- return true;
- if (engine_->GetPageRect(page).y() * zoom_ >= v_scrollbar_->GetValue())
- page--;
- ScrollToPage(page);
- UpdateCursor(PP_CURSORTYPE_POINTER);
- return true;
- }
- }
-
- if (v_scrollbar_.get() && v_scrollbar_->HandleEvent(event)) {
- UpdateCursor(PP_CURSORTYPE_POINTER);
- return true;
- }
-
- if (h_scrollbar_.get() && h_scrollbar_->HandleEvent(event)) {
- UpdateCursor(PP_CURSORTYPE_POINTER);
- return true;
- }
-
- if (timer_pending_ &&
- (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEUP ||
- event.GetType() == PP_INPUTEVENT_TYPE_MOUSEMOVE)) {
- timer_factory_.CancelAll();
- timer_pending_ = false;
- } else if (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEMOVE &&
- engine_->IsSelecting()) {
- bool set_timer = false;
- pp::MouseInputEvent mouse_event(event);
- if (v_scrollbar_.get() &&
- (mouse_event.GetPosition().y() <= 0 ||
- mouse_event.GetPosition().y() >= (plugin_dip_size_.height() - 1))) {
- v_scrollbar_->ScrollBy(
- PP_SCROLLBY_LINE, mouse_event.GetPosition().y() >= 0 ? 1: -1);
- set_timer = true;
- }
- if (h_scrollbar_.get() &&
- (mouse_event.GetPosition().x() <= 0 ||
- mouse_event.GetPosition().x() >= (plugin_dip_size_.width() - 1))) {
- h_scrollbar_->ScrollBy(PP_SCROLLBY_LINE,
- mouse_event.GetPosition().x() >= 0 ? 1: -1);
- set_timer = true;
- }
-
- if (set_timer) {
- last_mouse_event_ = pp::MouseInputEvent(event);
-
- pp::CompletionCallback callback =
- timer_factory_.NewCallback(&Instance::OnTimerFired);
- pp::Module::Get()->core()->CallOnMainThread(kDragTimerMs, callback);
- timer_pending_ = true;
- }
- }
-
- if (event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN) {
- pp::KeyboardInputEvent keyboard_event(event);
- const uint32 modifier = event.GetModifiers();
- if (modifier & kDefaultKeyModifier) {
- switch (keyboard_event.GetKeyCode()) {
- case 'A':
- engine_->SelectAll();
- return true;
- }
- } else if (modifier & PP_INPUTEVENT_MODIFIER_CONTROLKEY) {
- switch (keyboard_event.GetKeyCode()) {
- case ui::VKEY_OEM_4:
- // Left bracket.
- engine_->RotateCounterclockwise();
- return true;
- case ui::VKEY_OEM_6:
- // Right bracket.
- engine_->RotateClockwise();
- return true;
- }
- }
- }
-
- // Return true for unhandled clicks so the plugin takes focus.
- return (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN);
-}
-
-void Instance::DidChangeView(const pp::View& view) {
- pp::Rect view_rect(view.GetRect());
- float device_scale = 1.0f;
- float old_device_scale = device_scale_;
- if (hidpi_enabled_)
- device_scale = view.GetDeviceScale();
- pp::Size view_device_size(view_rect.width() * device_scale,
- view_rect.height() * device_scale);
- if (view_device_size == plugin_size_ && device_scale == device_scale_)
- return; // We don't care about the position, only the size.
-
- image_data_ = pp::ImageData();
- device_scale_ = device_scale;
- plugin_dip_size_ = view_rect.size();
- plugin_size_ = view_device_size;
-
- paint_manager_.SetSize(view_device_size, device_scale_);
-
- image_data_ = pp::ImageData(this,
- PP_IMAGEDATAFORMAT_BGRA_PREMUL,
- plugin_size_,
- false);
- if (image_data_.is_null()) {
- DCHECK(plugin_size_.IsEmpty());
- return;
- }
-
- // View dimensions changed, disable autoscroll (if it was enabled).
- DisableAutoscroll();
-
- OnGeometryChanged(zoom_, old_device_scale);
-}
-
-pp::Var Instance::GetInstanceObject() {
- if (instance_object_.is_undefined()) {
- PDFScriptableObject* object = new PDFScriptableObject(this);
- // The pp::Var takes ownership of object here.
- instance_object_ = pp::VarPrivate(this, object);
- }
-
- return instance_object_;
-}
-
-pp::Var Instance::GetLinkAtPosition(const pp::Point& point) {
- pp::Point offset_point(point);
- ScalePoint(device_scale_, &offset_point);
- offset_point.set_x(offset_point.x() - available_area_.x());
- return engine_->GetLinkAtPosition(offset_point);
-}
-
-pp::Var Instance::GetSelectedText(bool html) {
- if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY))
- return pp::Var();
- return engine_->GetSelectedText();
-}
-
-void Instance::InvalidateWidget(pp::Widget_Dev widget,
- const pp::Rect& dirty_rect) {
- if (v_scrollbar_.get() && *v_scrollbar_ == widget) {
- if (!image_data_.is_null())
- v_scrollbar_->Paint(dirty_rect.pp_rect(), &image_data_);
- } else if (h_scrollbar_.get() && *h_scrollbar_ == widget) {
- if (!image_data_.is_null())
- h_scrollbar_->Paint(dirty_rect.pp_rect(), &image_data_);
- } else {
- // Possible to hit this condition since sometimes the scrollbar codes posts
- // a task to do something later, and we could have deleted our reference in
- // the meantime.
- return;
- }
-
- pp::Rect dirty_rect_scaled = dirty_rect;
- ScaleRect(device_scale_, &dirty_rect_scaled);
- paint_manager_.InvalidateRect(dirty_rect_scaled);
-}
-
-void Instance::ScrollbarValueChanged(pp::Scrollbar_Dev scrollbar,
- uint32_t value) {
- value = GetScaled(value);
- if (v_scrollbar_.get() && *v_scrollbar_ == scrollbar) {
- engine_->ScrolledToYPosition(value);
- pp::Rect rc;
- v_scrollbar_->GetLocation(&rc);
- int32 doc_height = GetDocumentPixelHeight();
- doc_height -= GetScaled(rc.height());
-#ifdef ENABLE_THUMBNAILS
- if (thumbnails_.visible()) {
- thumbnails_.SetPosition(value, doc_height, true);
- }
-#endif
- pp::Point origin(
- plugin_size_.width() - page_indicator_.rect().width() -
- GetScaled(GetScrollbarReservedThickness()),
- page_indicator_.GetYPosition(value, doc_height, plugin_size_.height()));
- page_indicator_.MoveTo(origin, page_indicator_.visible());
- } else if (h_scrollbar_.get() && *h_scrollbar_ == scrollbar) {
- engine_->ScrolledToXPosition(value);
- }
-}
-
-void Instance::ScrollbarOverlayChanged(pp::Scrollbar_Dev scrollbar,
- bool overlay) {
- scrollbar_reserved_thickness_ = overlay ? 0 : scrollbar_thickness_;
- OnGeometryChanged(zoom_, device_scale_);
-}
-
-uint32_t Instance::QuerySupportedPrintOutputFormats() {
- return engine_->QuerySupportedPrintOutputFormats();
-}
-
-int32_t Instance::PrintBegin(const PP_PrintSettings_Dev& print_settings) {
- // For us num_pages is always equal to the number of pages in the PDF
- // document irrespective of the printable area.
- int32_t ret = engine_->GetNumberOfPages();
- if (!ret)
- return 0;
-
- uint32_t supported_formats = engine_->QuerySupportedPrintOutputFormats();
- if ((print_settings.format & supported_formats) == 0)
- return 0;
-
- print_settings_.is_printing = true;
- print_settings_.pepper_print_settings = print_settings;
- engine_->PrintBegin();
- return ret;
-}
-
-pp::Resource Instance::PrintPages(
- const PP_PrintPageNumberRange_Dev* page_ranges,
- uint32_t page_range_count) {
- if (!print_settings_.is_printing)
- return pp::Resource();
-
- print_settings_.print_pages_called_ = true;
- return engine_->PrintPages(page_ranges, page_range_count,
- print_settings_.pepper_print_settings);
-}
-
-void Instance::PrintEnd() {
- if (print_settings_.print_pages_called_)
- UserMetricsRecordAction("PDF.PrintPage");
- print_settings_.Clear();
- engine_->PrintEnd();
-}
-
-bool Instance::IsPrintScalingDisabled() {
- return !engine_->GetPrintScaling();
-}
-
-bool Instance::StartFind(const std::string& text, bool case_sensitive) {
- engine_->StartFind(text.c_str(), case_sensitive);
- return true;
-}
-
-void Instance::SelectFindResult(bool forward) {
- engine_->SelectFindResult(forward);
-}
-
-void Instance::StopFind() {
- engine_->StopFind();
-}
-
-void Instance::Zoom(double scale, bool text_only) {
- UserMetricsRecordAction("PDF.ZoomFromBrowser");
-
- // If the zoom level doesn't change it means that this zoom change might have
- // been initiated by the plugin. In that case, we don't want to change the
- // zoom mode to ZOOM_SCALE as it may have been intentionally set to
- // ZOOM_FIT_TO_PAGE or some other value when the zoom was last changed.
- if (scale == zoom_)
- return;
-
- SetZoom(ZOOM_SCALE, scale);
-}
-
-void Instance::ZoomChanged(double factor) {
- if (full_)
- Zoom_Dev::ZoomChanged(factor);
-}
-
-void Instance::OnPaint(const std::vector<pp::Rect>& paint_rects,
- std::vector<PaintManager::ReadyRect>* ready,
- std::vector<pp::Rect>* pending) {
- if (image_data_.is_null()) {
- DCHECK(plugin_size_.IsEmpty());
- return;
- }
- if (first_paint_) {
- first_paint_ = false;
- pp::Rect rect = pp::Rect(pp::Point(), plugin_size_);
- FillRect(rect, kBackgroundColor);
- ready->push_back(PaintManager::ReadyRect(rect, image_data_, true));
- *pending = paint_rects;
- return;
- }
-
- engine_->PrePaint();
-
- for (size_t i = 0; i < paint_rects.size(); i++) {
- // Intersect with plugin area since there could be pending invalidates from
- // when the plugin area was larger.
- pp::Rect rect =
- paint_rects[i].Intersect(pp::Rect(pp::Point(), plugin_size_));
- if (rect.IsEmpty())
- continue;
-
- pp::Rect pdf_rect = available_area_.Intersect(rect);
- if (!pdf_rect.IsEmpty()) {
- pdf_rect.Offset(available_area_.x() * -1, 0);
-
- std::vector<pp::Rect> pdf_ready;
- std::vector<pp::Rect> pdf_pending;
- engine_->Paint(pdf_rect, &image_data_, &pdf_ready, &pdf_pending);
- for (size_t j = 0; j < pdf_ready.size(); ++j) {
- pdf_ready[j].Offset(available_area_.point());
- ready->push_back(
- PaintManager::ReadyRect(pdf_ready[j], image_data_, false));
- }
- for (size_t j = 0; j < pdf_pending.size(); ++j) {
- pdf_pending[j].Offset(available_area_.point());
- pending->push_back(pdf_pending[j]);
- }
- }
-
- for (size_t j = 0; j < background_parts_.size(); ++j) {
- pp::Rect intersection = background_parts_[j].location.Intersect(rect);
- if (!intersection.IsEmpty()) {
- FillRect(intersection, background_parts_[j].color);
- ready->push_back(
- PaintManager::ReadyRect(intersection, image_data_, false));
- }
- }
-
- if (document_load_state_ == LOAD_STATE_FAILED) {
- pp::Point top_center;
- top_center.set_x(plugin_size_.width() / 2);
- top_center.set_y(plugin_size_.height() / 2);
- DrawText(top_center, PP_RESOURCESTRING_PDFLOAD_FAILED);
- }
-
-#ifdef ENABLE_THUMBNAILS
- thumbnails_.Paint(&image_data_, rect);
-#endif
- }
-
- engine_->PostPaint();
-
- // Must paint scrollbars after the background parts, in case we have an
- // overlay scrollbar that's over the background. We also do this in a separate
- // loop because the scrollbar painting logic uses the signal of whether there
- // are pending paints or not to figure out if it should draw right away or
- // not.
- for (size_t i = 0; i < paint_rects.size(); i++) {
- PaintIfWidgetIntersects(h_scrollbar_.get(), paint_rects[i], ready, pending);
- PaintIfWidgetIntersects(v_scrollbar_.get(), paint_rects[i], ready, pending);
- }
-
- if (progress_bar_.visible())
- PaintOverlayControl(&progress_bar_, &image_data_, ready);
-
- if (page_indicator_.visible())
- PaintOverlayControl(&page_indicator_, &image_data_, ready);
-
- if (toolbar_->current_transparency() != kTransparentAlpha)
- PaintOverlayControl(toolbar_.get(), &image_data_, ready);
-
- // Paint autoscroll anchor if needed.
- if (is_autoscroll_) {
- size_t limit = ready->size();
- for (size_t i = 0; i < limit; i++) {
- pp::Rect anchor_rect = autoscroll_rect_.Intersect((*ready)[i].rect);
- if (!anchor_rect.IsEmpty()) {
- pp::Rect draw_rc = pp::Rect(
- pp::Point(anchor_rect.x() - autoscroll_rect_.x(),
- anchor_rect.y() - autoscroll_rect_.y()),
- anchor_rect.size());
- // Paint autoscroll anchor.
- AlphaBlend(autoscroll_anchor_, draw_rc,
- &image_data_, anchor_rect.point(), kOpaqueAlpha);
- }
- }
- }
-}
-
-void Instance::PaintOverlayControl(
- Control* ctrl,
- pp::ImageData* image_data,
- std::vector<PaintManager::ReadyRect>* ready) {
- // Make sure that we only paint overlay controls over an area that's ready,
- // i.e. not pending. Otherwise we'll mark the control rect as ready and
- // it'll overwrite the pdf region.
- std::list<pp::Rect> ctrl_rects;
- for (size_t i = 0; i < ready->size(); i++) {
- pp::Rect rc = ctrl->rect().Intersect((*ready)[i].rect);
- if (!rc.IsEmpty())
- ctrl_rects.push_back(rc);
- }
-
- if (!ctrl_rects.empty()) {
- ctrl->PaintMultipleRects(image_data, ctrl_rects);
-
- std::list<pp::Rect>::iterator iter;
- for (iter = ctrl_rects.begin(); iter != ctrl_rects.end(); ++iter) {
- ready->push_back(PaintManager::ReadyRect(*iter, *image_data, false));
- }
- }
-}
-
-void Instance::DidOpen(int32_t result) {
- if (result == PP_OK) {
- engine_->HandleDocumentLoad(embed_loader_);
- } else if (result != PP_ERROR_ABORTED) { // Can happen in tests.
- NOTREACHED();
- }
-}
-
-void Instance::DidOpenPreview(int32_t result) {
- if (result == PP_OK) {
- preview_engine_.reset(PDFEngine::Create(new PreviewModeClient(this)));
- preview_engine_->HandleDocumentLoad(embed_preview_loader_);
- } else {
- NOTREACHED();
- }
-}
-
-void Instance::PaintIfWidgetIntersects(
- pp::Widget_Dev* widget,
- const pp::Rect& rect,
- std::vector<PaintManager::ReadyRect>* ready,
- std::vector<pp::Rect>* pending) {
- if (!widget)
- return;
-
- pp::Rect location;
- if (!widget->GetLocation(&location))
- return;
-
- ScaleRect(device_scale_, &location);
- location = location.Intersect(rect);
- if (location.IsEmpty())
- return;
-
- if (IsOverlayScrollbar()) {
- // If we're using overlay scrollbars, and there are pending paints under the
- // scrollbar, don't update the scrollbar instantly. While it would be nice,
- // we would need to double buffer the plugin area in order to make this
- // work. This is because we'd need to always have a copy of what the pdf
- // under the scrollbar looks like, and additionally we couldn't paint the
- // pdf under the scrollbar if it's ready until we got the preceding flush.
- // So in practice, it would make painting slower and introduce extra buffer
- // copies for the general case.
- for (size_t i = 0; i < pending->size(); ++i) {
- if ((*pending)[i].Intersects(location))
- return;
- }
-
- // Even if none of the pending paints are under the scrollbar, we never want
- // to paint it if it's over the pdf if there are other pending paints.
- // Otherwise different parts of the pdf plugin would display at different
- // scroll offsets.
- if (!pending->empty() && available_area_.Intersects(rect)) {
- pending->push_back(location);
- return;
- }
- }
-
- pp::Rect location_dip = location;
- ScaleRect(1.0f / device_scale_, &location_dip);
-
- DCHECK(!image_data_.is_null());
- widget->Paint(location_dip, &image_data_);
-
- ready->push_back(PaintManager::ReadyRect(location, image_data_, true));
-}
-
-void Instance::OnTimerFired(int32_t) {
- HandleInputEvent(last_mouse_event_);
-}
-
-void Instance::OnClientTimerFired(int32_t id) {
- engine_->OnCallback(id);
-}
-
-void Instance::OnControlTimerFired(int32_t,
- const uint32& control_id,
- const uint32& timer_id) {
- if (control_id == toolbar_->id()) {
- toolbar_->OnTimerFired(timer_id);
- } else if (control_id == progress_bar_.id()) {
- if (timer_id == delayed_progress_timer_id_) {
- if (document_load_state_ == LOAD_STATE_LOADING &&
- !progress_bar_.visible()) {
- progress_bar_.Fade(true, kProgressFadeTimeoutMs);
- }
- delayed_progress_timer_id_ = 0;
- } else {
- progress_bar_.OnTimerFired(timer_id);
- }
- } else if (control_id == kAutoScrollId) {
- if (is_autoscroll_) {
- if (autoscroll_x_ != 0 && h_scrollbar_.get()) {
- h_scrollbar_->ScrollBy(PP_SCROLLBY_PIXEL, autoscroll_x_);
- }
- if (autoscroll_y_ != 0 && v_scrollbar_.get()) {
- v_scrollbar_->ScrollBy(PP_SCROLLBY_PIXEL, autoscroll_y_);
- }
-
- // Reschedule timer.
- ScheduleTimer(kAutoScrollId, kAutoScrollTimeoutMs);
- }
- } else if (control_id == kPageIndicatorId) {
- page_indicator_.OnTimerFired(timer_id);
- }
-#ifdef ENABLE_THUMBNAILS
- else if (control_id == thumbnails_.id()) {
- thumbnails_.OnTimerFired(timer_id);
- }
-#endif
-}
-
-void Instance::CalculateBackgroundParts() {
- background_parts_.clear();
- int v_scrollbar_thickness =
- GetScaled(v_scrollbar_.get() ? GetScrollbarReservedThickness() : 0);
- int h_scrollbar_thickness =
- GetScaled(h_scrollbar_.get() ? GetScrollbarReservedThickness() : 0);
- int width_without_scrollbar = std::max(
- plugin_size_.width() - v_scrollbar_thickness, 0);
- int height_without_scrollbar = std::max(
- plugin_size_.height() - h_scrollbar_thickness, 0);
- int left_width = available_area_.x();
- int right_start = available_area_.right();
- int right_width = abs(width_without_scrollbar - available_area_.right());
- int bottom = std::min(available_area_.bottom(), height_without_scrollbar);
-
- // Add the left, right, and bottom rectangles. Note: we assume only
- // horizontal centering.
- BackgroundPart part = {
- pp::Rect(0, 0, left_width, bottom),
- kBackgroundColor
- };
- if (!part.location.IsEmpty())
- background_parts_.push_back(part);
- part.location = pp::Rect(right_start, 0, right_width, bottom);
- if (!part.location.IsEmpty())
- background_parts_.push_back(part);
- part.location = pp::Rect(
- 0, bottom, width_without_scrollbar, height_without_scrollbar - bottom);
- if (!part.location.IsEmpty())
- background_parts_.push_back(part);
-
- if (h_scrollbar_thickness
-#if defined(OS_MACOSX)
- ||
-#else
- &&
-#endif
- v_scrollbar_thickness) {
- part.color = 0xFFFFFFFF;
- part.location = pp::Rect(plugin_size_.width() - v_scrollbar_thickness,
- plugin_size_.height() - h_scrollbar_thickness,
- h_scrollbar_thickness,
- v_scrollbar_thickness);
- background_parts_.push_back(part);
- }
-}
-
-int Instance::GetDocumentPixelWidth() const {
- return static_cast<int>(ceil(document_size_.width() * zoom_ * device_scale_));
-}
-
-int Instance::GetDocumentPixelHeight() const {
- return static_cast<int>(ceil(document_size_.height() *
- zoom_ *
- device_scale_));
-}
-
-void Instance::FillRect(const pp::Rect& rect, uint32 color) {
- DCHECK(!image_data_.is_null() || rect.IsEmpty());
- uint32* buffer_start = static_cast<uint32*>(image_data_.data());
- int stride = image_data_.stride();
- uint32* ptr = buffer_start + rect.y() * stride / 4 + rect.x();
- int height = rect.height();
- int width = rect.width();
- for (int y = 0; y < height; ++y) {
- for (int x = 0; x < width; ++x)
- *(ptr + x) = color;
- ptr += stride / 4;
- }
-}
-
-void Instance::DocumentSizeUpdated(const pp::Size& size) {
- document_size_ = size;
-
- OnGeometryChanged(zoom_, device_scale_);
-}
-
-void Instance::Invalidate(const pp::Rect& rect) {
- pp::Rect offset_rect(rect);
- offset_rect.Offset(available_area_.point());
- paint_manager_.InvalidateRect(offset_rect);
-}
-
-void Instance::Scroll(const pp::Point& point) {
- pp::Rect scroll_area = available_area_;
- if (IsOverlayScrollbar()) {
- pp::Rect rc;
- if (h_scrollbar_.get()) {
- h_scrollbar_->GetLocation(&rc);
- ScaleRect(device_scale_, &rc);
- if (scroll_area.bottom() > rc.y()) {
- scroll_area.set_height(rc.y() - scroll_area.y());
- paint_manager_.InvalidateRect(rc);
- }
- }
- if (v_scrollbar_.get()) {
- v_scrollbar_->GetLocation(&rc);
- ScaleRect(device_scale_, &rc);
- if (scroll_area.right() > rc.x()) {
- scroll_area.set_width(rc.x() - scroll_area.x());
- paint_manager_.InvalidateRect(rc);
- }
- }
- }
- paint_manager_.ScrollRect(scroll_area, point);
-
- if (toolbar_->current_transparency() != kTransparentAlpha)
- paint_manager_.InvalidateRect(toolbar_->GetControlsRect());
-
- if (progress_bar_.visible())
- paint_manager_.InvalidateRect(progress_bar_.rect());
-
- if (is_autoscroll_)
- paint_manager_.InvalidateRect(autoscroll_rect_);
-
- if (show_page_indicator_) {
- page_indicator_.set_current_page(GetPageNumberToDisplay());
- page_indicator_.Splash();
- }
-
- if (page_indicator_.visible())
- paint_manager_.InvalidateRect(page_indicator_.rect());
-
- // Run the scroll callback asynchronously. This function can be invoked by a
- // layout change which should not re-enter into JS synchronously.
- pp::CompletionCallback callback =
- callback_factory_.NewCallback(&Instance::RunCallback,
- on_scroll_callback_);
- pp::Module::Get()->core()->CallOnMainThread(0, callback);
-}
-
-void Instance::ScrollToX(int position) {
- if (!h_scrollbar_.get()) {
- NOTREACHED();
- return;
- }
- int position_dip = static_cast<int>(position / device_scale_);
- h_scrollbar_->SetValue(position_dip);
-}
-
-void Instance::ScrollToY(int position) {
- if (!v_scrollbar_.get()) {
- NOTREACHED();
- return;
- }
- int position_dip = static_cast<int>(position / device_scale_);
- v_scrollbar_->SetValue(ClipToRange(position_dip, 0, valid_v_range_));
-}
-
-void Instance::ScrollToPage(int page) {
- if (!v_scrollbar_.get())
- return;
-
- if (engine_->GetNumberOfPages() == 0)
- return;
-
- int index = ClipToRange(page, 0, engine_->GetNumberOfPages() - 1);
- pp::Rect rect = engine_->GetPageRect(index);
- // If we are trying to scroll pass the last page,
- // scroll to the end of the last page.
- int position = index < page ? rect.bottom() : rect.y();
- ScrollToY(position * zoom_ * device_scale_);
-}
-
-void Instance::NavigateTo(const std::string& url, bool open_in_new_tab) {
- std::string url_copy(url);
-
- // Empty |url_copy| is ok, and will effectively be a reload.
- // Skip the code below so an empty URL does not turn into "http://", which
- // will cause GURL to fail a DCHECK.
- if (!url_copy.empty()) {
- // If |url_copy| starts with '#', then it's for the same URL with a
- // different URL fragment.
- if (url_copy[0] == '#') {
- url_copy = url_ + url_copy;
- // Changing the href does not actually do anything when navigating in the
- // same tab, so do the actual page scroll here. Then fall through so the
- // href gets updated.
- if (!open_in_new_tab) {
- int page_number = GetInitialPage(url_copy);
- if (page_number >= 0)
- ScrollToPage(page_number);
- }
- }
- // If there's no scheme, add http.
- if (url_copy.find("://") == std::string::npos &&
- url_copy.find("mailto:") == std::string::npos) {
- url_copy = "http://" + url_copy;
- }
- // Make sure |url_copy| starts with a valid scheme.
- if (url_copy.find("http://") != 0 &&
- url_copy.find("https://") != 0 &&
- url_copy.find("ftp://") != 0 &&
- url_copy.find("file://") != 0 &&
- url_copy.find("mailto:") != 0) {
- return;
- }
- // Make sure |url_copy| is not only a scheme.
- if (url_copy == "http://" ||
- url_copy == "https://" ||
- url_copy == "ftp://" ||
- url_copy == "file://" ||
- url_copy == "mailto:") {
- return;
- }
- }
- if (open_in_new_tab) {
- GetWindowObject().Call("open", url_copy);
- } else {
- GetWindowObject().GetProperty("top").GetProperty("location").
- SetProperty("href", url_copy);
- }
-}
-
-void Instance::UpdateCursor(PP_CursorType_Dev cursor) {
- if (cursor == cursor_)
- return;
- cursor_ = cursor;
-
- const PPB_CursorControl_Dev* cursor_interface =
- reinterpret_cast<const PPB_CursorControl_Dev*>(
- pp::Module::Get()->GetBrowserInterface(PPB_CURSOR_CONTROL_DEV_INTERFACE));
- if (!cursor_interface) {
- NOTREACHED();
- return;
- }
-
- cursor_interface->SetCursor(
- pp_instance(), cursor_, pp::ImageData().pp_resource(), NULL);
-}
-
-void Instance::UpdateTickMarks(const std::vector<pp::Rect>& tickmarks) {
- if (!v_scrollbar_.get())
- return;
-
- float inverse_scale = 1.0f / device_scale_;
- std::vector<pp::Rect> scaled_tickmarks = tickmarks;
- for (size_t i = 0; i < scaled_tickmarks.size(); i++) {
- ScaleRect(inverse_scale, &scaled_tickmarks[i]);
- }
-
- v_scrollbar_->SetTickMarks(
- scaled_tickmarks.empty() ? NULL : &scaled_tickmarks[0], tickmarks.size());
-}
-
-void Instance::NotifyNumberOfFindResultsChanged(int total, bool final_result) {
- NumberOfFindResultsChanged(total, final_result);
-}
-
-void Instance::NotifySelectedFindResultChanged(int current_find_index) {
- SelectedFindResultChanged(current_find_index);
-}
-
-void Instance::OnEvent(uint32 control_id, uint32 event_id, void* data) {
- if (event_id == Button::EVENT_ID_BUTTON_CLICKED ||
- event_id == Button::EVENT_ID_BUTTON_STATE_CHANGED) {
- switch (control_id) {
- case kFitToPageButtonId:
- UserMetricsRecordAction("PDF.FitToPageButton");
- SetZoom(ZOOM_FIT_TO_PAGE, 0);
- ZoomChanged(zoom_);
- break;
- case kFitToWidthButtonId:
- UserMetricsRecordAction("PDF.FitToWidthButton");
- SetZoom(ZOOM_FIT_TO_WIDTH, 0);
- ZoomChanged(zoom_);
- break;
- case kZoomOutButtonId:
- case kZoomInButtonId:
- UserMetricsRecordAction(control_id == kZoomOutButtonId ?
- "PDF.ZoomOutButton" : "PDF.ZoomInButton");
- SetZoom(ZOOM_SCALE, CalculateZoom(control_id));
- ZoomChanged(zoom_);
- break;
- case kSaveButtonId:
- UserMetricsRecordAction("PDF.SaveButton");
- SaveAs();
- break;
- case kPrintButtonId:
- UserMetricsRecordAction("PDF.PrintButton");
- Print();
- break;
- }
- }
- if (control_id == kThumbnailsId &&
- event_id == ThumbnailControl::EVENT_ID_THUMBNAIL_SELECTED) {
- int page = *static_cast<int*>(data);
- pp::Rect page_rc(engine_->GetPageRect(page));
- ScrollToY(static_cast<int>(page_rc.y() * zoom_ * device_scale_));
- }
-}
-
-void Instance::Invalidate(uint32 control_id, const pp::Rect& rc) {
- paint_manager_.InvalidateRect(rc);
-}
-
-uint32 Instance::ScheduleTimer(uint32 control_id, uint32 timeout_ms) {
- current_timer_id_++;
- pp::CompletionCallback callback =
- timer_factory_.NewCallback(&Instance::OnControlTimerFired,
- control_id,
- current_timer_id_);
- pp::Module::Get()->core()->CallOnMainThread(timeout_ms, callback);
- return current_timer_id_;
-}
-
-void Instance::SetEventCapture(uint32 control_id, bool set_capture) {
- // TODO(gene): set event capture here.
-}
-
-void Instance::SetCursor(uint32 control_id, PP_CursorType_Dev cursor_type) {
- UpdateCursor(cursor_type);
-}
-
-pp::Instance* Instance::GetInstance() {
- return this;
-}
-
-void Instance::GetDocumentPassword(
- pp::CompletionCallbackWithOutput<pp::Var> callback) {
- std::string message(GetLocalizedString(PP_RESOURCESTRING_PDFGETPASSWORD));
- pp::Var result = pp::PDF::ModalPromptForPassword(this, message);
- *callback.output() = result.pp_var();
- callback.Run(PP_OK);
-}
-
-void Instance::Alert(const std::string& message) {
- GetWindowObject().Call("alert", message);
-}
-
-bool Instance::Confirm(const std::string& message) {
- pp::Var result = GetWindowObject().Call("confirm", message);
- return result.is_bool() ? result.AsBool() : false;
-}
-
-std::string Instance::Prompt(const std::string& question,
- const std::string& default_answer) {
- pp::Var result = GetWindowObject().Call("prompt", question, default_answer);
- return result.is_string() ? result.AsString() : std::string();
-}
-
-std::string Instance::GetURL() {
- return url_;
-}
-
-void Instance::Email(const std::string& to,
- const std::string& cc,
- const std::string& bcc,
- const std::string& subject,
- const std::string& body) {
- std::string javascript =
- "var href = 'mailto:" + net::EscapeUrlEncodedData(to, false) +
- "?cc=" + net::EscapeUrlEncodedData(cc, false) +
- "&bcc=" + net::EscapeUrlEncodedData(bcc, false) +
- "&subject=" + net::EscapeUrlEncodedData(subject, false) +
- "&body=" + net::EscapeUrlEncodedData(body, false) +
- "';var temp = window.open(href, '_blank', " +
- "'width=1,height=1');if(temp) temp.close();";
- ExecuteScript(javascript);
-}
-
-void Instance::Print() {
- if (!printing_enabled_ ||
- (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) &&
- !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY))) {
- return;
- }
-
- pp::CompletionCallback callback =
- callback_factory_.NewCallback(&Instance::OnPrint);
- pp::Module::Get()->core()->CallOnMainThread(0, callback);
-}
-
-void Instance::OnPrint(int32_t) {
- pp::PDF::Print(this);
-}
-
-void Instance::SaveAs() {
- pp::PDF::SaveAs(this);
-}
-
-void Instance::SubmitForm(const std::string& url,
- const void* data,
- int length) {
- pp::URLRequestInfo request(this);
- request.SetURL(url);
- request.SetMethod("POST");
- request.AppendDataToBody(reinterpret_cast<const char*>(data), length);
-
- pp::CompletionCallback callback =
- form_factory_.NewCallback(&Instance::FormDidOpen);
- form_loader_ = CreateURLLoaderInternal();
- int rv = form_loader_.Open(request, callback);
- if (rv != PP_OK_COMPLETIONPENDING)
- callback.Run(rv);
-}
-
-void Instance::FormDidOpen(int32_t result) {
- // TODO: inform the user of success/failure.
- if (result != PP_OK) {
- NOTREACHED();
- }
-}
-
-std::string Instance::ShowFileSelectionDialog() {
- // Seems like very low priority to implement, since the pdf has no way to get
- // the file data anyways. Javascript doesn't let you do this synchronously.
- NOTREACHED();
- return std::string();
-}
-
-pp::URLLoader Instance::CreateURLLoader() {
- if (full_) {
- if (!did_call_start_loading_) {
- did_call_start_loading_ = true;
- pp::PDF::DidStartLoading(this);
- }
-
- // Disable save and print until the document is fully loaded, since they
- // would generate an incomplete document. Need to do this each time we
- // call DidStartLoading since that resets the content restrictions.
- pp::PDF::SetContentRestriction(this, CONTENT_RESTRICTION_SAVE |
- CONTENT_RESTRICTION_PRINT);
- }
-
- return CreateURLLoaderInternal();
-}
-
-void Instance::ScheduleCallback(int id, int delay_in_ms) {
- pp::CompletionCallback callback =
- timer_factory_.NewCallback(&Instance::OnClientTimerFired);
- pp::Module::Get()->core()->CallOnMainThread(delay_in_ms, callback, id);
-}
-
-void Instance::SearchString(const base::char16* string,
- const base::char16* term,
- bool case_sensitive,
- std::vector<SearchStringResult>* results) {
- if (!pp::PDF::IsAvailable()) {
- NOTREACHED();
- return;
- }
-
- PP_PrivateFindResult* pp_results;
- int count = 0;
- pp::PDF::SearchString(
- this,
- reinterpret_cast<const unsigned short*>(string),
- reinterpret_cast<const unsigned short*>(term),
- case_sensitive,
- &pp_results,
- &count);
-
- results->resize(count);
- for (int i = 0; i < count; ++i) {
- (*results)[i].start_index = pp_results[i].start_index;
- (*results)[i].length = pp_results[i].length;
- }
-
- pp::Memory_Dev memory;
- memory.MemFree(pp_results);
-}
-
-void Instance::DocumentPaintOccurred() {
- if (painted_first_page_)
- return;
-
- painted_first_page_ = true;
- UpdateToolbarPosition(false);
- toolbar_->Splash(kToolbarSplashTimeoutMs);
-
- if (engine_->GetNumberOfPages() > 1)
- show_page_indicator_ = true;
- else
- show_page_indicator_ = false;
-
- if (v_scrollbar_.get() && show_page_indicator_) {
- page_indicator_.set_current_page(GetPageNumberToDisplay());
- page_indicator_.Splash(kToolbarSplashTimeoutMs,
- kPageIndicatorInitialFadeTimeoutMs);
- }
-}
-
-void Instance::DocumentLoadComplete(int page_count) {
- // Clear focus state for OSK.
- FormTextFieldFocusChange(false);
-
- // Update progress control.
- if (progress_bar_.visible())
- progress_bar_.Fade(false, kProgressFadeTimeoutMs);
-
- DCHECK(document_load_state_ == LOAD_STATE_LOADING);
- document_load_state_ = LOAD_STATE_COMPLETE;
- UserMetricsRecordAction("PDF.LoadSuccess");
-
- if (did_call_start_loading_) {
- pp::PDF::DidStopLoading(this);
- did_call_start_loading_ = false;
- }
-
- if (on_load_callback_.is_string())
- ExecuteScript(on_load_callback_);
- // Note: If we are in print preview mode on_load_callback_ might call
- // ScrollTo{X|Y}() and we don't want to scroll again and override it.
- // #page=N is not supported in Print Preview.
- if (!IsPrintPreview()) {
- int initial_page = GetInitialPage(url_);
- if (initial_page >= 0)
- ScrollToPage(initial_page);
- }
-
- if (!full_)
- return;
- if (!pp::PDF::IsAvailable())
- return;
-
- int content_restrictions =
- CONTENT_RESTRICTION_CUT | CONTENT_RESTRICTION_PASTE;
- if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY))
- content_restrictions |= CONTENT_RESTRICTION_COPY;
-
- if (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) &&
- !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) {
- printing_enabled_ = false;
- if (current_tb_info_ == kPDFToolbarButtons) {
- // Remove Print button.
- CreateToolbar(kPDFNoPrintToolbarButtons,
- arraysize(kPDFNoPrintToolbarButtons));
- UpdateToolbarPosition(false);
- Invalidate(pp::Rect(plugin_size_));
- }
- }
-
- pp::PDF::SetContentRestriction(this, content_restrictions);
-
- pp::PDF::HistogramPDFPageCount(this, page_count);
-}
-
-void Instance::RotateClockwise() {
- engine_->RotateClockwise();
-}
-
-void Instance::RotateCounterclockwise() {
- engine_->RotateCounterclockwise();
-}
-
-void Instance::PreviewDocumentLoadComplete() {
- if (preview_document_load_state_ != LOAD_STATE_LOADING ||
- preview_pages_info_.empty()) {
- return;
- }
-
- preview_document_load_state_ = LOAD_STATE_COMPLETE;
-
- int dest_page_index = preview_pages_info_.front().second;
- int src_page_index =
- ExtractPrintPreviewPageIndex(preview_pages_info_.front().first);
- if (src_page_index > 0 && dest_page_index > -1 && preview_engine_.get())
- engine_->AppendPage(preview_engine_.get(), dest_page_index);
-
- preview_pages_info_.pop();
- // |print_preview_page_count_| is not updated yet. Do not load any
- // other preview pages till we get this information.
- if (print_preview_page_count_ == 0)
- return;
-
- if (preview_pages_info_.size())
- LoadAvailablePreviewPage();
-}
-
-void Instance::DocumentLoadFailed() {
- DCHECK(document_load_state_ == LOAD_STATE_LOADING);
- UserMetricsRecordAction("PDF.LoadFailure");
-
- // Hide progress control.
- progress_bar_.Fade(false, kProgressFadeTimeoutMs);
-
- if (did_call_start_loading_) {
- pp::PDF::DidStopLoading(this);
- did_call_start_loading_ = false;
- }
-
- document_load_state_ = LOAD_STATE_FAILED;
- paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_));
-}
-
-void Instance::PreviewDocumentLoadFailed() {
- UserMetricsRecordAction("PDF.PreviewDocumentLoadFailure");
- if (preview_document_load_state_ != LOAD_STATE_LOADING ||
- preview_pages_info_.empty()) {
- return;
- }
-
- preview_document_load_state_ = LOAD_STATE_FAILED;
- preview_pages_info_.pop();
-
- if (preview_pages_info_.size())
- LoadAvailablePreviewPage();
-}
-
-pp::Instance* Instance::GetPluginInstance() {
- return GetInstance();
-}
-
-void Instance::DocumentHasUnsupportedFeature(const std::string& feature) {
- std::string metric("PDF_Unsupported_");
- metric += feature;
- if (!unsupported_features_reported_.count(metric)) {
- unsupported_features_reported_.insert(metric);
- UserMetricsRecordAction(metric);
- }
-
- // Since we use an info bar, only do this for full frame plugins..
- if (!full_)
- return;
-
- if (told_browser_about_unsupported_feature_)
- return;
- told_browser_about_unsupported_feature_ = true;
-
- pp::PDF::HasUnsupportedFeature(this);
-}
-
-void Instance::DocumentLoadProgress(uint32 available, uint32 doc_size) {
- double progress = 0.0;
- if (doc_size == 0) {
- // Document size is unknown. Use heuristics.
- // We'll make progress logarithmic from 0 to 100M.
- static const double kFactor = log(100000000.0) / 100.0;
- if (available > 0) {
- progress = log(static_cast<double>(available)) / kFactor;
- if (progress > 100.0)
- progress = 100.0;
- }
- } else {
- progress = 100.0 * static_cast<double>(available) / doc_size;
- }
- progress_bar_.SetProgress(progress);
-}
-
-void Instance::FormTextFieldFocusChange(bool in_focus) {
- if (!text_input_.get())
- return;
- if (in_focus)
- text_input_->SetTextInputType(PP_TEXTINPUT_TYPE_DEV_TEXT);
- else
- text_input_->SetTextInputType(PP_TEXTINPUT_TYPE_DEV_NONE);
-}
-
-// Called by PDFScriptableObject.
-bool Instance::HasScriptableMethod(const pp::Var& method, pp::Var* exception) {
- std::string method_str = method.AsString();
- return (method_str == kJSAccessibility ||
- method_str == kJSDocumentLoadComplete ||
- method_str == kJSGetHeight ||
- method_str == kJSGetHorizontalScrollbarThickness ||
- method_str == kJSGetPageLocationNormalized ||
- method_str == kJSGetSelectedText ||
- method_str == kJSGetVerticalScrollbarThickness ||
- method_str == kJSGetWidth ||
- method_str == kJSGetZoomLevel ||
- method_str == kJSGoToPage ||
- method_str == kJSGrayscale ||
- method_str == kJSLoadPreviewPage ||
- method_str == kJSOnLoad ||
- method_str == kJSOnPluginSizeChanged ||
- method_str == kJSOnScroll ||
- method_str == kJSPageXOffset ||
- method_str == kJSPageYOffset ||
- method_str == kJSPrintPreviewPageCount ||
- method_str == kJSReload ||
- method_str == kJSRemovePrintButton ||
- method_str == kJSResetPrintPreviewUrl ||
- method_str == kJSSendKeyEvent ||
- method_str == kJSSetPageNumbers ||
- method_str == kJSSetPageXOffset ||
- method_str == kJSSetPageYOffset ||
- method_str == kJSSetZoomLevel ||
- method_str == kJSZoomFitToHeight ||
- method_str == kJSZoomFitToWidth ||
- method_str == kJSZoomIn ||
- method_str == kJSZoomOut);
-}
-
-pp::Var Instance::CallScriptableMethod(const pp::Var& method,
- const std::vector<pp::Var>& args,
- pp::Var* exception) {
- std::string method_str = method.AsString();
- if (method_str == kJSGrayscale) {
- if (args.size() == 1 && args[0].is_bool()) {
- engine_->SetGrayscale(args[0].AsBool());
- // Redraw
- paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_));
-#ifdef ENABLE_THUMBNAILS
- if (thumbnails_.visible())
- thumbnails_.Show(true, true);
-#endif
- return pp::Var(true);
- }
- return pp::Var(false);
- }
- if (method_str == kJSOnLoad) {
- if (args.size() == 1 && args[0].is_string()) {
- on_load_callback_ = args[0];
- return pp::Var(true);
- }
- return pp::Var(false);
- }
- if (method_str == kJSOnScroll) {
- if (args.size() == 1 && args[0].is_string()) {
- on_scroll_callback_ = args[0];
- return pp::Var(true);
- }
- return pp::Var(false);
- }
- if (method_str == kJSOnPluginSizeChanged) {
- if (args.size() == 1 && args[0].is_string()) {
- on_plugin_size_changed_callback_ = args[0];
- return pp::Var(true);
- }
- return pp::Var(false);
- }
- if (method_str == kJSReload) {
- document_load_state_ = LOAD_STATE_LOADING;
- if (!full_)
- LoadUrl(url_);
- preview_engine_.reset();
- print_preview_page_count_ = 0;
- engine_.reset(PDFEngine::Create(this));
- engine_->New(url_.c_str());
-#ifdef ENABLE_THUMBNAILS
- thumbnails_.ResetEngine(engine_.get());
-#endif
- return pp::Var();
- }
- if (method_str == kJSResetPrintPreviewUrl) {
- if (args.size() == 1 && args[0].is_string()) {
- url_ = args[0].AsString();
- preview_pages_info_ = std::queue<PreviewPageInfo>();
- preview_document_load_state_ = LOAD_STATE_COMPLETE;
- }
- return pp::Var();
- }
- if (method_str == kJSZoomFitToHeight) {
- SetZoom(ZOOM_FIT_TO_PAGE, 0);
- return pp::Var();
- }
- if (method_str == kJSZoomFitToWidth) {
- SetZoom(ZOOM_FIT_TO_WIDTH, 0);
- return pp::Var();
- }
- if (method_str == kJSZoomIn) {
- SetZoom(ZOOM_SCALE, CalculateZoom(kZoomInButtonId));
- return pp::Var();
- }
- if (method_str == kJSZoomOut) {
- SetZoom(ZOOM_SCALE, CalculateZoom(kZoomOutButtonId));
- return pp::Var();
- }
- if (method_str == kJSSetZoomLevel) {
- if (args.size() == 1 && args[0].is_number())
- SetZoom(ZOOM_SCALE, args[0].AsDouble());
- return pp::Var();
- }
- if (method_str == kJSGetZoomLevel) {
- return pp::Var(zoom_);
- }
- if (method_str == kJSGetHeight) {
- return pp::Var(plugin_size_.height());
- }
- if (method_str == kJSGetWidth) {
- return pp::Var(plugin_size_.width());
- }
- if (method_str == kJSGetHorizontalScrollbarThickness) {
- return pp::Var(
- h_scrollbar_.get() ? GetScrollbarReservedThickness() : 0);
- }
- if (method_str == kJSGetVerticalScrollbarThickness) {
- return pp::Var(
- v_scrollbar_.get() ? GetScrollbarReservedThickness() : 0);
- }
- if (method_str == kJSGetSelectedText) {
- return GetSelectedText(false);
- }
- if (method_str == kJSDocumentLoadComplete) {
- return pp::Var((document_load_state_ != LOAD_STATE_LOADING));
- }
- if (method_str == kJSPageYOffset) {
- return pp::Var(static_cast<int32_t>(
- v_scrollbar_.get() ? v_scrollbar_->GetValue() : 0));
- }
- if (method_str == kJSSetPageYOffset) {
- if (args.size() == 1 && args[0].is_number() && v_scrollbar_.get())
- ScrollToY(GetScaled(args[0].AsInt()));
- return pp::Var();
- }
- if (method_str == kJSPageXOffset) {
- return pp::Var(static_cast<int32_t>(
- h_scrollbar_.get() ? h_scrollbar_->GetValue() : 0));
- }
- if (method_str == kJSSetPageXOffset) {
- if (args.size() == 1 && args[0].is_number() && h_scrollbar_.get())
- ScrollToX(GetScaled(args[0].AsInt()));
- return pp::Var();
- }
- if (method_str == kJSRemovePrintButton) {
- CreateToolbar(kPrintPreviewToolbarButtons,
- arraysize(kPrintPreviewToolbarButtons));
- UpdateToolbarPosition(false);
- Invalidate(pp::Rect(plugin_size_));
- return pp::Var();
- }
- if (method_str == kJSGoToPage) {
- if (args.size() == 1 && args[0].is_string()) {
- ScrollToPage(atoi(args[0].AsString().c_str()));
- }
- return pp::Var();
- }
- if (method_str == kJSAccessibility) {
- if (args.size() == 0) {
- base::DictionaryValue node;
- node.SetInteger(kAccessibleNumberOfPages, engine_->GetNumberOfPages());
- node.SetBoolean(kAccessibleLoaded,
- document_load_state_ != LOAD_STATE_LOADING);
- bool has_permissions =
- engine_->HasPermission(PDFEngine::PERMISSION_COPY) ||
- engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE);
- node.SetBoolean(kAccessibleCopyable, has_permissions);
- std::string json;
- base::JSONWriter::Write(&node, &json);
- return pp::Var(json);
- } else if (args[0].is_number()) {
- return pp::Var(engine_->GetPageAsJSON(args[0].AsInt()));
- }
- }
- if (method_str == kJSPrintPreviewPageCount) {
- if (args.size() == 1 && args[0].is_number())
- SetPrintPreviewMode(args[0].AsInt());
- return pp::Var();
- }
- if (method_str == kJSLoadPreviewPage) {
- if (args.size() == 2 && args[0].is_string() && args[1].is_number())
- ProcessPreviewPageInfo(args[0].AsString(), args[1].AsInt());
- return pp::Var();
- }
- if (method_str == kJSGetPageLocationNormalized) {
- const size_t kMaxLength = 30;
- char location_info[kMaxLength];
- int page_idx = engine_->GetMostVisiblePage();
- if (page_idx < 0)
- return pp::Var(std::string());
- pp::Rect rect = engine_->GetPageContentsRect(page_idx);
- int v_scrollbar_reserved_thickness =
- v_scrollbar_.get() ? GetScaled(GetScrollbarReservedThickness()) : 0;
-
- rect.set_x(rect.x() + ((plugin_size_.width() -
- v_scrollbar_reserved_thickness - available_area_.width()) / 2));
- base::snprintf(location_info,
- kMaxLength,
- "%0.4f;%0.4f;%0.4f;%0.4f;",
- rect.x() / static_cast<float>(plugin_size_.width()),
- rect.y() / static_cast<float>(plugin_size_.height()),
- rect.width() / static_cast<float>(plugin_size_.width()),
- rect.height()/ static_cast<float>(plugin_size_.height()));
- return pp::Var(std::string(location_info));
- }
- if (method_str == kJSSetPageNumbers) {
- if (args.size() != 1 || !args[0].is_string())
- return pp::Var();
- const int num_pages_signed = engine_->GetNumberOfPages();
- if (num_pages_signed <= 0)
- return pp::Var();
- scoped_ptr<base::ListValue> page_ranges(static_cast<base::ListValue*>(
- base::JSONReader::Read(args[0].AsString(), false)));
- const size_t num_pages = static_cast<size_t>(num_pages_signed);
- if (!page_ranges.get() || page_ranges->GetSize() != num_pages)
- return pp::Var();
-
- std::vector<int> print_preview_page_numbers;
- for (size_t index = 0; index < num_pages; ++index) {
- int page_number = 0; // |page_number| is 1-based.
- if (!page_ranges->GetInteger(index, &page_number) || page_number < 1)
- return pp::Var();
- print_preview_page_numbers.push_back(page_number);
- }
- print_preview_page_numbers_ = print_preview_page_numbers;
- page_indicator_.set_current_page(GetPageNumberToDisplay());
- return pp::Var();
- }
- // This is here to work around https://bugs.webkit.org/show_bug.cgi?id=16735.
- // In JS, creating a synthetic keyboard event and dispatching it always
- // result in a keycode of 0.
- if (method_str == kJSSendKeyEvent) {
- if (args.size() == 1 && args[0].is_number()) {
- pp::KeyboardInputEvent event(
- this, // instance
- PP_INPUTEVENT_TYPE_KEYDOWN, // HandleInputEvent only care about this.
- 0, // timestamp, not used for kbd events.
- 0, // no modifiers.
- args[0].AsInt(), // keycode.
- pp::Var()); // no char text needed.
- HandleInputEvent(event);
- }
- }
- return pp::Var();
-}
-
-void Instance::OnGeometryChanged(double old_zoom, float old_device_scale) {
- bool force_no_horizontal_scrollbar = false;
- int scrollbar_thickness = GetScrollbarThickness();
-
- if (old_device_scale != device_scale_) {
- // Change in device scale forces us to recreate resources
- ConfigureNumberImageGenerator();
-
- CreateToolbar(current_tb_info_, current_tb_info_size_);
- // Load autoscroll anchor image.
- autoscroll_anchor_ =
- CreateResourceImage(PP_RESOURCEIMAGE_PDF_PAN_SCROLL_ICON);
-
- ConfigurePageIndicator();
- ConfigureProgressBar();
-
- pp::Point scroll_position = engine_->GetScrollPosition();
- ScalePoint(device_scale_ / old_device_scale, &scroll_position);
- engine_->SetScrollPosition(scroll_position);
- }
-
- UpdateZoomScale();
- if (zoom_ != old_zoom || device_scale_ != old_device_scale)
- engine_->ZoomUpdated(zoom_ * device_scale_);
- if (zoom_ != old_zoom)
- ZoomChanged(zoom_);
-
- available_area_ = pp::Rect(plugin_size_);
- if (GetDocumentPixelHeight() > plugin_size_.height()) {
- CreateVerticalScrollbar();
- } else {
- DestroyVerticalScrollbar();
- }
-
- int v_scrollbar_reserved_thickness =
- v_scrollbar_.get() ? GetScaled(GetScrollbarReservedThickness()) : 0;
-
- if (!force_no_horizontal_scrollbar &&
- GetDocumentPixelWidth() >
- (plugin_size_.width() - v_scrollbar_reserved_thickness)) {
- CreateHorizontalScrollbar();
-
- // Adding the horizontal scrollbar now might cause us to need vertical
- // scrollbars.
- if (GetDocumentPixelHeight() >
- plugin_size_.height() - GetScaled(GetScrollbarReservedThickness())) {
- CreateVerticalScrollbar();
- }
-
- } else {
- DestroyHorizontalScrollbar();
- }
-
-#ifdef ENABLE_THUMBNAILS
- int thumbnails_pos = 0, thumbnails_total = 0;
-#endif
- if (v_scrollbar_.get()) {
- v_scrollbar_->SetScale(device_scale_);
- available_area_.set_width(
- std::max(0, plugin_size_.width() - v_scrollbar_reserved_thickness));
-
-#ifdef ENABLE_THUMBNAILS
- int height = plugin_size_.height();
-#endif
- int height_dip = plugin_dip_size_.height();
-
-#if defined(OS_MACOSX)
- // Before Lion, Mac always had the resize at the bottom. After that, it
- // never did.
- if ((base::mac::IsOSSnowLeopard() && full_) ||
- (base::mac::IsOSLionOrLater() && h_scrollbar_.get())) {
-#else
- if (h_scrollbar_.get()) {
-#endif // defined(OS_MACOSX)
-#ifdef ENABLE_THUMBNAILS
- height -= GetScaled(GetScrollbarThickness());
-#endif
- height_dip -= GetScrollbarThickness();
- }
-#ifdef ENABLE_THUMBNAILS
- int32 doc_height = GetDocumentPixelHeight();
-#endif
- int32 doc_height_dip =
- static_cast<int32>(GetDocumentPixelHeight() / device_scale_);
-#if defined(OS_MACOSX)
- // On the Mac we always allow room for the resize button (whose width is
- // the same as that of the scrollbar) in full mode. However, if there is no
- // no horizontal scrollbar, the end of the scrollbar will scroll past the
- // end of the document. This is because the scrollbar assumes that its own
- // height (in the case of a vscroll bar) is the same as the height of the
- // viewport. Since the viewport is actually larger, we compensate by
- // adjusting the document height. Similar logic applies below for the
- // horizontal scrollbar.
- // For example, if the document size is 1000, and the viewport size is 200,
- // then the scrollbar position at the end will be 800. In this case the
- // viewport is actally 215 (assuming 15 as the scrollbar width) but the
- // scrollbar thinks it is 200. We want the scrollbar position at the end to
- // be 785. Making the document size 985 achieves this.
- if (full_ && !h_scrollbar_.get()) {
-#ifdef ENABLE_THUMBNAILS
- doc_height -= GetScaled(GetScrollbarThickness());
-#endif
- doc_height_dip -= GetScrollbarThickness();
- }
-#endif // defined(OS_MACOSX)
-
- int32 position;
- position = v_scrollbar_->GetValue();
- position = static_cast<int>(position * zoom_ / old_zoom);
- valid_v_range_ = doc_height_dip - height_dip;
- if (position > valid_v_range_)
- position = valid_v_range_;
-
- v_scrollbar_->SetValue(position);
-
- PP_Rect loc;
- loc.point.x = static_cast<int>(available_area_.right() / device_scale_);
- if (IsOverlayScrollbar())
- loc.point.x -= scrollbar_thickness;
- loc.point.y = 0;
- loc.size.width = scrollbar_thickness;
- loc.size.height = height_dip;
- v_scrollbar_->SetLocation(loc);
- v_scrollbar_->SetDocumentSize(doc_height_dip);
-
-#ifdef ENABLE_THUMBNAILS
- thumbnails_pos = position;
- thumbnails_total = doc_height - height;
-#endif
- }
-
- if (h_scrollbar_.get()) {
- h_scrollbar_->SetScale(device_scale_);
- available_area_.set_height(
- std::max(0, plugin_size_.height() -
- GetScaled(GetScrollbarReservedThickness())));
-
- int width_dip = plugin_dip_size_.width();
-
- // See note above.
-#if defined(OS_MACOSX)
- if ((base::mac::IsOSSnowLeopard() && full_) ||
- (base::mac::IsOSLionOrLater() && v_scrollbar_.get())) {
-#else
- if (v_scrollbar_.get()) {
-#endif
- width_dip -= GetScrollbarThickness();
- }
- int32 doc_width_dip =
- static_cast<int32>(GetDocumentPixelWidth() / device_scale_);
-#if defined(OS_MACOSX)
- // See comment in the above if (v_scrollbar_.get()) block.
- if (full_ && !v_scrollbar_.get())
- doc_width_dip -= GetScrollbarThickness();
-#endif // defined(OS_MACOSX)
-
- int32 position;
- position = h_scrollbar_->GetValue();
- position = static_cast<int>(position * zoom_ / old_zoom);
- position = std::min(position, doc_width_dip - width_dip);
-
- h_scrollbar_->SetValue(position);
-
- PP_Rect loc;
- loc.point.x = 0;
- loc.point.y = static_cast<int>(available_area_.bottom() / device_scale_);
- if (IsOverlayScrollbar())
- loc.point.y -= scrollbar_thickness;
- loc.size.width = width_dip;
- loc.size.height = scrollbar_thickness;
- h_scrollbar_->SetLocation(loc);
- h_scrollbar_->SetDocumentSize(doc_width_dip);
- }
-
- int doc_width = GetDocumentPixelWidth();
- if (doc_width < available_area_.width()) {
- available_area_.Offset((available_area_.width() - doc_width) / 2, 0);
- available_area_.set_width(doc_width);
- }
- int doc_height = GetDocumentPixelHeight();
- if (doc_height < available_area_.height()) {
- available_area_.set_height(doc_height);
- }
-
- // We'll invalidate the entire plugin anyways.
- UpdateToolbarPosition(false);
- UpdateProgressBarPosition(false);
- UpdatePageIndicatorPosition(false);
-
-#ifdef ENABLE_THUMBNAILS
- // Update thumbnail control position.
- thumbnails_.SetPosition(thumbnails_pos, thumbnails_total, false);
- pp::Rect thumbnails_rc(plugin_size_.width() - GetScaled(kThumbnailsWidth), 0,
- GetScaled(kThumbnailsWidth), plugin_size_.height());
- if (v_scrollbar_.get())
- thumbnails_rc.Offset(-v_scrollbar_reserved_thickness, 0);
- if (h_scrollbar_.get())
- thumbnails_rc.Inset(0, 0, 0, v_scrollbar_reserved_thickness);
- thumbnails_.SetRect(thumbnails_rc, false);
-#endif
-
- CalculateBackgroundParts();
- engine_->PageOffsetUpdated(available_area_.point());
- engine_->PluginSizeUpdated(available_area_.size());
-
- if (!document_size_.GetArea())
- return;
- paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_));
-
- // Run the plugin size change callback asynchronously. This function can be
- // invoked by a layout change which should not re-enter into JS synchronously.
- pp::CompletionCallback callback =
- callback_factory_.NewCallback(&Instance::RunCallback,
- on_plugin_size_changed_callback_);
- pp::Module::Get()->core()->CallOnMainThread(0, callback);
-}
-
-void Instance::RunCallback(int32_t, pp::Var callback) {
- if (callback.is_string())
- ExecuteScript(callback);
-}
-
-void Instance::CreateHorizontalScrollbar() {
- if (h_scrollbar_.get())
- return;
-
- h_scrollbar_.reset(new pp::Scrollbar_Dev(this, false));
-}
-
-void Instance::CreateVerticalScrollbar() {
- if (v_scrollbar_.get())
- return;
-
- v_scrollbar_.reset(new pp::Scrollbar_Dev(this, true));
-}
-
-void Instance::DestroyHorizontalScrollbar() {
- if (!h_scrollbar_.get())
- return;
- if (h_scrollbar_->GetValue())
- engine_->ScrolledToXPosition(0);
- h_scrollbar_.reset();
-}
-
-void Instance::DestroyVerticalScrollbar() {
- if (!v_scrollbar_.get())
- return;
- if (v_scrollbar_->GetValue())
- engine_->ScrolledToYPosition(0);
- v_scrollbar_.reset();
- page_indicator_.Show(false, true);
-}
-
-int Instance::GetScrollbarThickness() {
- if (scrollbar_thickness_ == -1) {
- pp::Scrollbar_Dev temp_scrollbar(this, false);
- scrollbar_thickness_ = temp_scrollbar.GetThickness();
- scrollbar_reserved_thickness_ =
- temp_scrollbar.IsOverlay() ? 0 : scrollbar_thickness_;
- }
-
- return scrollbar_thickness_;
-}
-
-int Instance::GetScrollbarReservedThickness() {
- GetScrollbarThickness();
- return scrollbar_reserved_thickness_;
-}
-
-bool Instance::IsOverlayScrollbar() {
- return GetScrollbarReservedThickness() == 0;
-}
-
-void Instance::CreateToolbar(const ToolbarButtonInfo* tb_info, size_t size) {
- toolbar_.reset(new FadingControls());
-
- DCHECK(tb_info);
- DCHECK(size >= 0);
-
- // Remember the current toolbar information in case we need to recreate the
- // images later.
- current_tb_info_ = tb_info;
- current_tb_info_size_ = size;
-
- int max_height = 0;
- pp::Point origin(kToolbarFadingOffsetLeft, kToolbarFadingOffsetTop);
- ScalePoint(device_scale_, &origin);
-
- std::list<Button*> buttons;
- for (size_t i = 0; i < size; i++) {
- Button* btn = new Button;
- pp::ImageData normal_face =
- CreateResourceImage(tb_info[i].normal);
- btn->CreateButton(tb_info[i].id,
- origin,
- true,
- toolbar_.get(),
- tb_info[i].style,
- normal_face,
- CreateResourceImage(tb_info[i].highlighted),
- CreateResourceImage(tb_info[i].pressed));
- buttons.push_back(btn);
-
- origin += pp::Point(normal_face.size().width(), 0);
- max_height = std::max(max_height, normal_face.size().height());
- }
-
- pp::Rect rc_toolbar(0, 0,
- origin.x() + GetToolbarRightOffset(),
- origin.y() + max_height + GetToolbarBottomOffset());
- toolbar_->CreateFadingControls(
- kToolbarId, rc_toolbar, false, this, kTransparentAlpha);
-
- std::list<Button*>::iterator iter;
- for (iter = buttons.begin(); iter != buttons.end(); ++iter) {
- toolbar_->AddControl(*iter);
- }
-}
-
-int Instance::GetToolbarRightOffset() {
- int scrollbar_thickness = GetScrollbarThickness();
- return GetScaled(kToolbarFadingOffsetRight) + 2 * scrollbar_thickness;
-}
-
-int Instance::GetToolbarBottomOffset() {
- int scrollbar_thickness = GetScrollbarThickness();
- return GetScaled(kToolbarFadingOffsetBottom) + scrollbar_thickness;
-}
-
-std::vector<pp::ImageData> Instance::GetThumbnailResources() {
- std::vector<pp::ImageData> num_images(10);
- num_images[0] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_0);
- num_images[1] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_1);
- num_images[2] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_2);
- num_images[3] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_3);
- num_images[4] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_4);
- num_images[5] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_5);
- num_images[6] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_6);
- num_images[7] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_7);
- num_images[8] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_8);
- num_images[9] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_9);
- return num_images;
-}
-
-std::vector<pp::ImageData> Instance::GetProgressBarResources(
- pp::ImageData* background) {
- std::vector<pp::ImageData> result(9);
- result[0] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_0);
- result[1] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_1);
- result[2] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_2);
- result[3] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_3);
- result[4] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_4);
- result[5] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_5);
- result[6] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_6);
- result[7] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_7);
- result[8] = CreateResourceImage(PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_8);
- *background = CreateResourceImage(
- PP_RESOURCEIMAGE_PDF_PROGRESS_BAR_BACKGROUND);
- return result;
-}
-
-void Instance::CreatePageIndicator(bool always_visible) {
- page_indicator_.CreatePageIndicator(kPageIndicatorId, false, this,
- number_image_generator(), always_visible);
- ConfigurePageIndicator();
-}
-
-void Instance::ConfigurePageIndicator() {
- pp::ImageData background =
- CreateResourceImage(PP_RESOURCEIMAGE_PDF_PAGE_INDICATOR_BACKGROUND);
- page_indicator_.Configure(pp::Point(), background);
-}
-
-void Instance::CreateProgressBar() {
- pp::ImageData background;
- std::vector<pp::ImageData> images = GetProgressBarResources(&background);
- std::string text = GetLocalizedString(PP_RESOURCESTRING_PDFPROGRESSLOADING);
- progress_bar_.CreateProgressControl(kProgressBarId, false, this, 0.0,
- device_scale_, images, background, text);
-}
-
-void Instance::ConfigureProgressBar() {
- pp::ImageData background;
- std::vector<pp::ImageData> images = GetProgressBarResources(&background);
- progress_bar_.Reconfigure(background, images, device_scale_);
-}
-
-void Instance::CreateThumbnails() {
- thumbnails_.CreateThumbnailControl(
- kThumbnailsId, pp::Rect(), false, this, engine_.get(),
- number_image_generator());
-}
-
-void Instance::LoadUrl(const std::string& url) {
- LoadUrlInternal(url, &embed_loader_, &Instance::DidOpen);
-}
-
-void Instance::LoadPreviewUrl(const std::string& url) {
- LoadUrlInternal(url, &embed_preview_loader_, &Instance::DidOpenPreview);
-}
-
-void Instance::LoadUrlInternal(const std::string& url, pp::URLLoader* loader,
- void (Instance::* method)(int32_t)) {
- pp::URLRequestInfo request(this);
- request.SetURL(url);
- request.SetMethod("GET");
-
- *loader = CreateURLLoaderInternal();
- pp::CompletionCallback callback = loader_factory_.NewCallback(method);
- int rv = loader->Open(request, callback);
- if (rv != PP_OK_COMPLETIONPENDING)
- callback.Run(rv);
-}
-
-pp::URLLoader Instance::CreateURLLoaderInternal() {
- pp::URLLoader loader(this);
-
- const PPB_URLLoaderTrusted* trusted_interface =
- reinterpret_cast<const PPB_URLLoaderTrusted*>(
- pp::Module::Get()->GetBrowserInterface(
- PPB_URLLOADERTRUSTED_INTERFACE));
- if (trusted_interface)
- trusted_interface->GrantUniversalAccess(loader.pp_resource());
- return loader;
-}
-
-int Instance::GetInitialPage(const std::string& url) {
- size_t found_idx = url.find('#');
- if (found_idx == std::string::npos)
- return -1;
-
- const std::string& ref = url.substr(found_idx + 1);
- std::vector<std::string> fragments;
- Tokenize(ref, kDelimiters, &fragments);
-
- // Page number to return, zero-based.
- int page = -1;
-
- // Handle the case of http://foo.com/bar#NAMEDDEST. This is not explicitly
- // mentioned except by example in the Adobe "PDF Open Parameters" document.
- if ((fragments.size() == 1) && (fragments[0].find('=') == std::string::npos))
- return engine_->GetNamedDestinationPage(fragments[0]);
-
- for (size_t i = 0; i < fragments.size(); ++i) {
- std::vector<std::string> key_value;
- base::SplitString(fragments[i], '=', &key_value);
- if (key_value.size() != 2)
- continue;
- const std::string& key = key_value[0];
- const std::string& value = key_value[1];
-
- if (base::strcasecmp(kPage, key.c_str()) == 0) {
- // |page_value| is 1-based.
- int page_value = -1;
- if (base::StringToInt(value, &page_value) && page_value > 0)
- page = page_value - 1;
- continue;
- }
- if (base::strcasecmp(kNamedDest, key.c_str()) == 0) {
- // |page_value| is 0-based.
- int page_value = engine_->GetNamedDestinationPage(value);
- if (page_value >= 0)
- page = page_value;
- continue;
- }
- }
- return page;
-}
-
-void Instance::UpdateToolbarPosition(bool invalidate) {
- pp::Rect ctrl_rc = toolbar_->GetControlsRect();
- int min_toolbar_width = ctrl_rc.width() + GetToolbarRightOffset() +
- GetScaled(kToolbarFadingOffsetLeft);
- int min_toolbar_height = ctrl_rc.width() + GetToolbarBottomOffset() +
- GetScaled(kToolbarFadingOffsetBottom);
-
- // Update toolbar position
- if (plugin_size_.width() < min_toolbar_width ||
- plugin_size_.height() < min_toolbar_height) {
- // Disable toolbar if it does not fit on the screen.
- toolbar_->Show(false, invalidate);
- } else {
- pp::Point offset(
- plugin_size_.width() - GetToolbarRightOffset() - ctrl_rc.right(),
- plugin_size_.height() - GetToolbarBottomOffset() - ctrl_rc.bottom());
- toolbar_->MoveBy(offset, invalidate);
-
- int toolbar_width = std::max(plugin_size_.width() / 2, min_toolbar_width);
- toolbar_->ExpandLeft(toolbar_width - toolbar_->rect().width());
- toolbar_->Show(painted_first_page_, invalidate);
- }
-}
-
-void Instance::UpdateProgressBarPosition(bool invalidate) {
- // TODO(gene): verify we don't overlap with toolbar.
- int scrollbar_thickness = GetScrollbarThickness();
- pp::Point progress_origin(
- scrollbar_thickness + GetScaled(kProgressOffsetLeft),
- plugin_size_.height() - progress_bar_.rect().height() -
- scrollbar_thickness - GetScaled(kProgressOffsetBottom));
- progress_bar_.MoveTo(progress_origin, invalidate);
-}
-
-void Instance::UpdatePageIndicatorPosition(bool invalidate) {
- int32 doc_height = static_cast<int>(document_size_.height() * zoom_);
- pp::Point origin(
- plugin_size_.width() - page_indicator_.rect().width() -
- GetScaled(GetScrollbarReservedThickness()),
- page_indicator_.GetYPosition(engine_->GetVerticalScrollbarYPosition(),
- doc_height, plugin_size_.height()));
- page_indicator_.MoveTo(origin, invalidate);
-}
-
-void Instance::SetZoom(ZoomMode zoom_mode, double scale) {
- double old_zoom = zoom_;
-
- zoom_mode_ = zoom_mode;
- if (zoom_mode_ == ZOOM_SCALE)
- zoom_ = scale;
- UpdateZoomScale();
-
- engine_->ZoomUpdated(zoom_ * device_scale_);
- OnGeometryChanged(old_zoom, device_scale_);
-
- // If fit-to-height, snap to the beginning of the most visible page.
- if (zoom_mode_ == ZOOM_FIT_TO_PAGE) {
- ScrollToPage(engine_->GetMostVisiblePage());
- }
-
- // Update sticky buttons to the current zoom style.
- Button* ftp_btn = static_cast<Button*>(
- toolbar_->GetControl(kFitToPageButtonId));
- Button* ftw_btn = static_cast<Button*>(
- toolbar_->GetControl(kFitToWidthButtonId));
- switch (zoom_mode_) {
- case ZOOM_FIT_TO_PAGE:
- ftp_btn->SetPressedState(true);
- ftw_btn->SetPressedState(false);
- break;
- case ZOOM_FIT_TO_WIDTH:
- ftw_btn->SetPressedState(true);
- ftp_btn->SetPressedState(false);
- break;
- default:
- ftw_btn->SetPressedState(false);
- ftp_btn->SetPressedState(false);
- }
-}
-
-void Instance::UpdateZoomScale() {
- switch (zoom_mode_) {
- case ZOOM_SCALE:
- break; // Keep current scale.
- case ZOOM_FIT_TO_PAGE: {
- int page_num = engine_->GetFirstVisiblePage();
- if (page_num == -1)
- break;
- pp::Rect rc = engine_->GetPageRect(page_num);
- if (!rc.height())
- break;
- // Calculate fit to width zoom level.
- double ftw_zoom = static_cast<double>(plugin_dip_size_.width() -
- GetScrollbarReservedThickness()) / document_size_.width();
- // Calculate fit to height zoom level. If document will not fit
- // horizontally, adjust zoom level to allow space for horizontal
- // scrollbar.
- double fth_zoom =
- static_cast<double>(plugin_dip_size_.height()) / rc.height();
- if (fth_zoom * document_size_.width() >
- plugin_dip_size_.width() - GetScrollbarReservedThickness())
- fth_zoom = static_cast<double>(plugin_dip_size_.height()
- - GetScrollbarReservedThickness()) / rc.height();
- zoom_ = std::min(ftw_zoom, fth_zoom);
- } break;
- case ZOOM_FIT_TO_WIDTH:
- case ZOOM_AUTO:
- if (!document_size_.width())
- break;
- zoom_ = static_cast<double>(plugin_dip_size_.width() -
- GetScrollbarReservedThickness()) / document_size_.width();
- if (zoom_mode_ == ZOOM_AUTO && zoom_ > 1.0)
- zoom_ = 1.0;
- break;
- }
- zoom_ = ClipToRange(zoom_, kMinZoom, kMaxZoom);
-}
-
-double Instance::CalculateZoom(uint32 control_id) const {
- if (control_id == kZoomInButtonId) {
- for (size_t i = 0; i < chrome_page_zoom::kPresetZoomFactorsSize; ++i) {
- double current_zoom = chrome_page_zoom::kPresetZoomFactors[i];
- if (current_zoom - content::kEpsilon > zoom_)
- return current_zoom;
- }
- } else {
- for (size_t i = chrome_page_zoom::kPresetZoomFactorsSize; i > 0; --i) {
- double current_zoom = chrome_page_zoom::kPresetZoomFactors[i - 1];
- if (current_zoom + content::kEpsilon < zoom_)
- return current_zoom;
- }
- }
- return zoom_;
-}
-
-pp::ImageData Instance::CreateResourceImage(PP_ResourceImage image_id) {
- pp::ImageData resource_data;
- if (hidpi_enabled_) {
- resource_data =
- pp::PDF::GetResourceImageForScale(this, image_id, device_scale_);
- }
-
- return resource_data.data() ? resource_data
- : pp::PDF::GetResourceImage(this, image_id);
-}
-
-std::string Instance::GetLocalizedString(PP_ResourceString id) {
- pp::Var rv(pp::PDF::GetLocalizedString(this, id));
- if (!rv.is_string())
- return std::string();
-
- return rv.AsString();
-}
-
-void Instance::DrawText(const pp::Point& top_center, PP_ResourceString id) {
- std::string str(GetLocalizedString(id));
-
- pp::FontDescription_Dev description;
- description.set_family(PP_FONTFAMILY_SANSSERIF);
- description.set_size(kMessageTextSize * device_scale_);
- pp::Font_Dev font(this, description);
- int length = font.MeasureSimpleText(str);
- pp::Point point(top_center);
- point.set_x(point.x() - length / 2);
- DCHECK(!image_data_.is_null());
- font.DrawSimpleText(&image_data_, str, point, kMessageTextColor);
-}
-
-void Instance::SetPrintPreviewMode(int page_count) {
- if (!IsPrintPreview() || page_count <= 0) {
- print_preview_page_count_ = 0;
- return;
- }
-
- print_preview_page_count_ = page_count;
- ScrollToPage(0);
- engine_->AppendBlankPages(print_preview_page_count_);
- if (preview_pages_info_.size() > 0)
- LoadAvailablePreviewPage();
-}
-
-bool Instance::IsPrintPreview() {
- return IsPrintPreviewUrl(url_);
-}
-
-int Instance::GetPageNumberToDisplay() {
- int page = engine_->GetMostVisiblePage();
- if (IsPrintPreview() && !print_preview_page_numbers_.empty()) {
- page = ClipToRange<int>(page, 0, print_preview_page_numbers_.size() - 1);
- return print_preview_page_numbers_[page];
- }
- return page + 1;
-}
-
-void Instance::ProcessPreviewPageInfo(const std::string& url,
- int dst_page_index) {
- if (!IsPrintPreview() || print_preview_page_count_ < 0)
- return;
-
- int src_page_index = ExtractPrintPreviewPageIndex(url);
- if (src_page_index < 1)
- return;
-
- preview_pages_info_.push(std::make_pair(url, dst_page_index));
- LoadAvailablePreviewPage();
-}
-
-void Instance::LoadAvailablePreviewPage() {
- if (preview_pages_info_.size() <= 0)
- return;
-
- std::string url = preview_pages_info_.front().first;
- int dst_page_index = preview_pages_info_.front().second;
- int src_page_index = ExtractPrintPreviewPageIndex(url);
- if (src_page_index < 1 ||
- dst_page_index >= print_preview_page_count_ ||
- preview_document_load_state_ == LOAD_STATE_LOADING) {
- return;
- }
-
- preview_document_load_state_ = LOAD_STATE_LOADING;
- LoadPreviewUrl(url);
-}
-
-void Instance::EnableAutoscroll(const pp::Point& origin) {
- if (is_autoscroll_)
- return;
-
- pp::Size client_size = plugin_size_;
- if (v_scrollbar_.get())
- client_size.Enlarge(-GetScrollbarThickness(), 0);
- if (h_scrollbar_.get())
- client_size.Enlarge(0, -GetScrollbarThickness());
-
- // Do not allow autoscroll if client area is too small.
- if (autoscroll_anchor_.size().width() > client_size.width() ||
- autoscroll_anchor_.size().height() > client_size.height())
- return;
-
- autoscroll_rect_ = pp::Rect(
- pp::Point(origin.x() - autoscroll_anchor_.size().width() / 2,
- origin.y() - autoscroll_anchor_.size().height() / 2),
- autoscroll_anchor_.size());
-
- // Make sure autoscroll anchor is in the client area.
- if (autoscroll_rect_.right() > client_size.width()) {
- autoscroll_rect_.set_x(
- client_size.width() - autoscroll_anchor_.size().width());
- }
- if (autoscroll_rect_.bottom() > client_size.height()) {
- autoscroll_rect_.set_y(
- client_size.height() - autoscroll_anchor_.size().height());
- }
-
- if (autoscroll_rect_.x() < 0)
- autoscroll_rect_.set_x(0);
- if (autoscroll_rect_.y() < 0)
- autoscroll_rect_.set_y(0);
-
- is_autoscroll_ = true;
- Invalidate(kAutoScrollId, autoscroll_rect_);
-
- ScheduleTimer(kAutoScrollId, kAutoScrollTimeoutMs);
-}
-
-void Instance::DisableAutoscroll() {
- if (is_autoscroll_) {
- is_autoscroll_ = false;
- Invalidate(kAutoScrollId, autoscroll_rect_);
- }
-}
-
-PP_CursorType_Dev Instance::CalculateAutoscroll(const pp::Point& mouse_pos) {
- // Scroll only if mouse pointer is outside of the anchor area.
- if (autoscroll_rect_.Contains(mouse_pos)) {
- autoscroll_x_ = 0;
- autoscroll_y_ = 0;
- return PP_CURSORTYPE_MIDDLEPANNING;
- }
-
- // Relative position to the center of anchor area.
- pp::Point rel_pos = mouse_pos - autoscroll_rect_.CenterPoint();
-
- // Calculate angle from the X axis. Angle is in range from -pi to pi.
- double angle = atan2(static_cast<double>(rel_pos.y()),
- static_cast<double>(rel_pos.x()));
-
- autoscroll_x_ = rel_pos.x() * kAutoScrollFactor;
- autoscroll_y_ = rel_pos.y() * kAutoScrollFactor;
-
- // Angle is from -pi to pi. Screen Y is increasing toward bottom,
- // so negative angle represent north direction.
- if (angle < - (M_PI * 7.0 / 8.0)) {
- // going west
- return PP_CURSORTYPE_WESTPANNING;
- } else if (angle < - (M_PI * 5.0 / 8.0)) {
- // going north-west
- return PP_CURSORTYPE_NORTHWESTPANNING;
- } else if (angle < - (M_PI * 3.0 / 8.0)) {
- // going north.
- return PP_CURSORTYPE_NORTHPANNING;
- } else if (angle < - (M_PI * 1.0 / 8.0)) {
- // going north-east
- return PP_CURSORTYPE_NORTHEASTPANNING;
- } else if (angle < M_PI * 1.0 / 8.0) {
- // going east.
- return PP_CURSORTYPE_EASTPANNING;
- } else if (angle < M_PI * 3.0 / 8.0) {
- // going south-east
- return PP_CURSORTYPE_SOUTHEASTPANNING;
- } else if (angle < M_PI * 5.0 / 8.0) {
- // going south.
- return PP_CURSORTYPE_SOUTHPANNING;
- } else if (angle < M_PI * 7.0 / 8.0) {
- // going south-west
- return PP_CURSORTYPE_SOUTHWESTPANNING;
- }
-
- // went around the circle, going west again
- return PP_CURSORTYPE_WESTPANNING;
-}
-
-void Instance::ConfigureNumberImageGenerator() {
- std::vector<pp::ImageData> num_images = GetThumbnailResources();
- pp::ImageData number_background = CreateResourceImage(
- PP_RESOURCEIMAGE_PDF_BUTTON_THUMBNAIL_NUM_BACKGROUND);
- number_image_generator_->Configure(number_background,
- num_images,
- device_scale_);
-}
-
-NumberImageGenerator* Instance::number_image_generator() {
- if (!number_image_generator_.get()) {
- number_image_generator_.reset(new NumberImageGenerator(this));
- ConfigureNumberImageGenerator();
- }
- return number_image_generator_.get();
-}
-
-int Instance::GetScaled(int x) const {
- return static_cast<int>(x * device_scale_);
-}
-
-void Instance::UserMetricsRecordAction(const std::string& action) {
- pp::PDF::UserMetricsRecordAction(this, pp::Var(action));
-}
-
-PDFScriptableObject::PDFScriptableObject(Instance* instance)
- : instance_(instance) {
-}
-
-PDFScriptableObject::~PDFScriptableObject() {
-}
-
-bool PDFScriptableObject::HasMethod(const pp::Var& name, pp::Var* exception) {
- return instance_->HasScriptableMethod(name, exception);
-}
-
-pp::Var PDFScriptableObject::Call(const pp::Var& method,
- const std::vector<pp::Var>& args,
- pp::Var* exception) {
- return instance_->CallScriptableMethod(method, args, exception);
-}
-
-} // namespace chrome_pdf
diff --git a/xfa_test/pdf/instance.h b/xfa_test/pdf/instance.h
deleted file mode 100644
index d39ba407c9..0000000000
--- a/xfa_test/pdf/instance.h
+++ /dev/null
@@ -1,531 +0,0 @@
-// 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.
-
-#ifndef PDF_INSTANCE_H_
-#define PDF_INSTANCE_H_
-
-#include <queue>
-#include <set>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "base/memory/scoped_ptr.h"
-#include "pdf/button.h"
-#include "pdf/fading_controls.h"
-#include "pdf/page_indicator.h"
-#include "pdf/paint_manager.h"
-#include "pdf/pdf_engine.h"
-#include "pdf/preview_mode_client.h"
-#include "pdf/progress_control.h"
-#include "pdf/thumbnail_control.h"
-
-#include "ppapi/c/private/ppb_pdf.h"
-#include "ppapi/cpp/dev/printing_dev.h"
-#include "ppapi/cpp/dev/scriptable_object_deprecated.h"
-#include "ppapi/cpp/dev/scrollbar_dev.h"
-#include "ppapi/cpp/dev/selection_dev.h"
-#include "ppapi/cpp/dev/widget_client_dev.h"
-#include "ppapi/cpp/dev/zoom_dev.h"
-#include "ppapi/cpp/graphics_2d.h"
-#include "ppapi/cpp/image_data.h"
-#include "ppapi/cpp/input_event.h"
-#include "ppapi/cpp/private/find_private.h"
-#include "ppapi/cpp/private/instance_private.h"
-#include "ppapi/cpp/private/var_private.h"
-#include "ppapi/cpp/url_loader.h"
-#include "ppapi/utility/completion_callback_factory.h"
-
-namespace pp {
-class TextInput_Dev;
-}
-
-namespace chrome_pdf {
-
-struct ToolbarButtonInfo;
-
-class Instance : public pp::InstancePrivate,
- public pp::Find_Private,
- public pp::Printing_Dev,
- public pp::Selection_Dev,
- public pp::WidgetClient_Dev,
- public pp::Zoom_Dev,
- public PaintManager::Client,
- public PDFEngine::Client,
- public PreviewModeClient::Client,
- public ControlOwner {
- public:
- explicit Instance(PP_Instance instance);
- virtual ~Instance();
-
- // pp::Instance implementation.
- virtual bool Init(uint32_t argc,
- const char* argn[],
- const char* argv[]) override;
- virtual bool HandleDocumentLoad(const pp::URLLoader& loader) override;
- virtual bool HandleInputEvent(const pp::InputEvent& event) override;
- virtual void DidChangeView(const pp::View& view) override;
- virtual pp::Var GetInstanceObject() override;
-
- // pp::Find_Private implementation.
- virtual bool StartFind(const std::string& text, bool case_sensitive) override;
- virtual void SelectFindResult(bool forward) override;
- virtual void StopFind() override;
-
- // pp::PaintManager::Client implementation.
- virtual void OnPaint(const std::vector<pp::Rect>& paint_rects,
- std::vector<PaintManager::ReadyRect>* ready,
- std::vector<pp::Rect>* pending) override;
-
- // pp::Printing_Dev implementation.
- virtual uint32_t QuerySupportedPrintOutputFormats() override;
- virtual int32_t PrintBegin(
- const PP_PrintSettings_Dev& print_settings) override;
- virtual pp::Resource PrintPages(
- const PP_PrintPageNumberRange_Dev* page_ranges,
- uint32_t page_range_count) override;
- virtual void PrintEnd() override;
- virtual bool IsPrintScalingDisabled() override;
-
- // pp::Private implementation.
- virtual pp::Var GetLinkAtPosition(const pp::Point& point);
-
- // PPP_Selection_Dev implementation.
- virtual pp::Var GetSelectedText(bool html) override;
-
- // WidgetClient_Dev implementation.
- virtual void InvalidateWidget(pp::Widget_Dev widget,
- const pp::Rect& dirty_rect) override;
- virtual void ScrollbarValueChanged(pp::Scrollbar_Dev scrollbar,
- uint32_t value) override;
- virtual void ScrollbarOverlayChanged(pp::Scrollbar_Dev scrollbar,
- bool overlay) override;
-
- // pp::Zoom_Dev implementation.
- virtual void Zoom(double scale, bool text_only) override;
- void ZoomChanged(double factor); // Override.
-
- void FlushCallback(int32_t result);
- void DidOpen(int32_t result);
- void DidOpenPreview(int32_t result);
- // If the given widget intersects the rectangle, paints it and adds the
- // rect to ready.
- void PaintIfWidgetIntersects(pp::Widget_Dev* widget,
- const pp::Rect& rect,
- std::vector<PaintManager::ReadyRect>* ready,
- std::vector<pp::Rect>* pending);
-
- // Called when the timer is fired.
- void OnTimerFired(int32_t);
- void OnClientTimerFired(int32_t id);
-
- // Called when the control timer is fired.
- void OnControlTimerFired(int32_t,
- const uint32& control_id,
- const uint32& timer_id);
-
- // Called to print without re-entrancy issues.
- void OnPrint(int32_t);
-
- // PDFEngine::Client implementation.
- virtual void DocumentSizeUpdated(const pp::Size& size);
- virtual void Invalidate(const pp::Rect& rect);
- virtual void Scroll(const pp::Point& point);
- virtual void ScrollToX(int position);
- virtual void ScrollToY(int position);
- virtual void ScrollToPage(int page);
- virtual void NavigateTo(const std::string& url, bool open_in_new_tab);
- virtual void UpdateCursor(PP_CursorType_Dev cursor);
- virtual void UpdateTickMarks(const std::vector<pp::Rect>& tickmarks);
- virtual void NotifyNumberOfFindResultsChanged(int total, bool final_result);
- virtual void NotifySelectedFindResultChanged(int current_find_index);
- virtual void GetDocumentPassword(
- pp::CompletionCallbackWithOutput<pp::Var> callback);
- virtual void Alert(const std::string& message);
- virtual bool Confirm(const std::string& message);
- virtual std::string Prompt(const std::string& question,
- const std::string& default_answer);
- virtual std::string GetURL();
- virtual void Email(const std::string& to,
- const std::string& cc,
- const std::string& bcc,
- const std::string& subject,
- const std::string& body);
- virtual void Print();
- virtual void SubmitForm(const std::string& url,
- const void* data,
- int length);
- virtual std::string ShowFileSelectionDialog();
- virtual pp::URLLoader CreateURLLoader();
- virtual void ScheduleCallback(int id, int delay_in_ms);
- virtual void SearchString(const base::char16* string,
- const base::char16* term,
- bool case_sensitive,
- std::vector<SearchStringResult>* results);
- virtual void DocumentPaintOccurred();
- virtual void DocumentLoadComplete(int page_count);
- virtual void DocumentLoadFailed();
- virtual pp::Instance* GetPluginInstance();
- virtual void DocumentHasUnsupportedFeature(const std::string& feature);
- virtual void DocumentLoadProgress(uint32 available, uint32 doc_size);
- virtual void FormTextFieldFocusChange(bool in_focus);
- virtual bool IsPrintPreview();
-
- // ControlOwner implementation.
- virtual void OnEvent(uint32 control_id, uint32 event_id, void* data);
- virtual void Invalidate(uint32 control_id, const pp::Rect& rc);
- virtual uint32 ScheduleTimer(uint32 control_id, uint32 timeout_ms);
- virtual void SetEventCapture(uint32 control_id, bool set_capture);
- virtual void SetCursor(uint32 control_id, PP_CursorType_Dev cursor_type);
- virtual pp::Instance* GetInstance();
-
- bool dont_paint() const { return dont_paint_; }
- void set_dont_paint(bool dont_paint) { dont_paint_ = dont_paint; }
-
- // Called by PDFScriptableObject.
- bool HasScriptableMethod(const pp::Var& method, pp::Var* exception);
- pp::Var CallScriptableMethod(const pp::Var& method,
- const std::vector<pp::Var>& args,
- pp::Var* exception);
-
- // PreviewModeClient::Client implementation.
- virtual void PreviewDocumentLoadComplete() override;
- virtual void PreviewDocumentLoadFailed() override;
-
- // Helper functions for implementing PPP_PDF.
- void RotateClockwise();
- void RotateCounterclockwise();
-
- private:
- // Called whenever the plugin geometry changes to update the location of the
- // scrollbars, background parts, and notifies the pdf engine.
- void OnGeometryChanged(double old_zoom, float old_device_scale);
-
- // Runs the given JS callback given in |callback|.
- void RunCallback(int32_t, pp::Var callback);
-
- void CreateHorizontalScrollbar();
- void CreateVerticalScrollbar();
- void DestroyHorizontalScrollbar();
- void DestroyVerticalScrollbar();
-
- // Returns the thickness of a scrollbar. This returns the thickness when it's
- // shown, so for overlay scrollbars it'll still be non-zero.
- int GetScrollbarThickness();
-
- // Returns the space we need to reserve for the scrollbar in the plugin area.
- // If overlay scrollbars are used, this will be 0.
- int GetScrollbarReservedThickness();
-
- // Returns true if overlay scrollbars are in use.
- bool IsOverlayScrollbar();
-
- // Figures out the location of any background rectangles (i.e. those that
- // aren't painted by the PDF engine).
- void CalculateBackgroundParts();
-
- // Computes document width/height in device pixels, based on current zoom and
- // device scale
- int GetDocumentPixelWidth() const;
- int GetDocumentPixelHeight() const;
-
- // Draws a rectangle with the specified dimensions and color in our buffer.
- void FillRect(const pp::Rect& rect, uint32 color);
-
- std::vector<pp::ImageData> GetThumbnailResources();
- std::vector<pp::ImageData> GetProgressBarResources(pp::ImageData* background);
-
- void CreateToolbar(const ToolbarButtonInfo* tb_info, size_t size);
- int GetToolbarRightOffset();
- int GetToolbarBottomOffset();
- void CreateProgressBar();
- void ConfigureProgressBar();
- void CreateThumbnails();
- void CreatePageIndicator(bool always_visible);
- void ConfigurePageIndicator();
-
- void PaintOverlayControl(Control* ctrl,
- pp::ImageData* image_data,
- std::vector<PaintManager::ReadyRect>* ready);
-
- void LoadUrl(const std::string& url);
- void LoadPreviewUrl(const std::string& url);
- void LoadUrlInternal(const std::string& url, pp::URLLoader* loader,
- void (Instance::* method)(int32_t));
-
- // Creates a URL loader and allows it to access all urls, i.e. not just the
- // frame's origin.
- pp::URLLoader CreateURLLoaderInternal();
-
- // Figure out the initial page to display based on #page=N and #nameddest=foo
- // in the |url_|.
- // Returns -1 if there is no valid fragment. The returned value is 0-based,
- // whereas page=N is 1-based.
- int GetInitialPage(const std::string& url);
-
- void UpdateToolbarPosition(bool invalidate);
- void UpdateProgressBarPosition(bool invalidate);
- void UpdatePageIndicatorPosition(bool invalidate);
-
- void FormDidOpen(int32_t result);
-
- std::string GetLocalizedString(PP_ResourceString id);
-
- void UserMetricsRecordAction(const std::string& action);
-
- void SaveAs();
-
- enum ZoomMode {
- ZOOM_SCALE, // Standard zooming mode, resize will not affect it.
- ZOOM_FIT_TO_WIDTH, // Maintain fit to width on resize.
- ZOOM_FIT_TO_PAGE, // Maintain fit to page on resize.
- ZOOM_AUTO // Maintain the default auto fitting mode on resize.
- };
-
- enum DocumentLoadState {
- LOAD_STATE_LOADING,
- LOAD_STATE_COMPLETE,
- LOAD_STATE_FAILED,
- };
-
- // Set new zoom mode and scale. Scale will be ignored if mode != ZOOM_SCALE.
- void SetZoom(ZoomMode zoom_mode, double scale);
-
- // Updates internal zoom scale based on the plugin/document geometry and
- // current mode.
- void UpdateZoomScale();
-
- // Simulates how Chrome "snaps" zooming up/down to the next nearest zoom level
- // when the previous zoom level wasn't an integer. We do this so that
- // pressing the zoom buttons has the same effect as the menu buttons, even if
- // we start from a non-standard zoom level because of fit-width or fit-height.
- double CalculateZoom(uint32 control_id) const;
-
- pp::ImageData CreateResourceImage(PP_ResourceImage image_id);
-
- void DrawText(const pp::Point& top_center, PP_ResourceString id);
-
- // Set print preview mode, where the current PDF document is reduced to
- // only one page, and then extended to |page_count| pages with
- // |page_count| - 1 blank pages.
- void SetPrintPreviewMode(int page_count);
-
- // Returns the page number to be displayed in the page indicator. If the
- // plugin is running within print preview, the displayed number might be
- // different from the index of the displayed page.
- int GetPageNumberToDisplay();
-
- // Process the preview page data information. |src_url| specifies the preview
- // page data location. The |src_url| is in the format:
- // chrome://print/id/page_number/print.pdf
- // |dst_page_index| specifies the blank page index that needs to be replaced
- // with the new page data.
- void ProcessPreviewPageInfo(const std::string& src_url, int dst_page_index);
- // Load the next available preview page into the blank page.
- void LoadAvailablePreviewPage();
-
- // Enables autoscroll using origin as a neutral (center) point.
- void EnableAutoscroll(const pp::Point& origin);
- // Disables autoscroll and returns to normal functionality.
- void DisableAutoscroll();
- // Calculate autoscroll info and return proper mouse pointer and scroll
- // andjustments.
- PP_CursorType_Dev CalculateAutoscroll(const pp::Point& mouse_pos);
-
- void ConfigureNumberImageGenerator();
-
- NumberImageGenerator* number_image_generator();
-
- int GetScaled(int x) const;
-
- pp::ImageData image_data_;
- // Used when the plugin is embedded in a page and we have to create the loader
- // ourself.
- pp::CompletionCallbackFactory<Instance> loader_factory_;
- pp::URLLoader embed_loader_;
- pp::URLLoader embed_preview_loader_;
-
- scoped_ptr<pp::Scrollbar_Dev> h_scrollbar_;
- scoped_ptr<pp::Scrollbar_Dev> v_scrollbar_;
- int32 valid_v_range_;
-
- PP_CursorType_Dev cursor_; // The current cursor.
-
- // Used when selecting and dragging beyond the visible portion, in which case
- // we want to scroll the document.
- bool timer_pending_;
- pp::MouseInputEvent last_mouse_event_;
- pp::CompletionCallbackFactory<Instance> timer_factory_;
- uint32 current_timer_id_;
-
- // Size, in pixels, of plugin rectangle.
- pp::Size plugin_size_;
- // Size, in DIPs, of plugin rectangle.
- pp::Size plugin_dip_size_;
- // Remaining area, in pixels, to render the pdf in after accounting for
- // scrollbars/toolbars and horizontal centering.
- pp::Rect available_area_;
- // Size of entire document in pixels (i.e. if each page is 800 pixels high and
- // there are 10 pages, the height will be 8000).
- pp::Size document_size_;
-
- double zoom_; // Current zoom factor.
-
- float device_scale_; // Current device scale factor.
- bool printing_enabled_;
- bool hidpi_enabled_;
- // True if the plugin is full-page.
- bool full_;
- // Zooming mode (none, fit to width, fit to height)
- ZoomMode zoom_mode_;
-
- // If true, this means we told the RenderView that we're starting a network
- // request so that it can start the throbber. We will tell it again once the
- // document finishes loading.
- bool did_call_start_loading_;
-
- // Hold off on painting invalidated requests while this flag is true.
- bool dont_paint_;
-
- // Indicates if plugin is in autoscroll mode.
- bool is_autoscroll_;
- // Rect for autoscroll anchor.
- pp::Rect autoscroll_rect_;
- // Image of the autoscroll anchor and its background.
- pp::ImageData autoscroll_anchor_;
- // Autoscrolling deltas in pixels.
- int autoscroll_x_;
- int autoscroll_y_;
-
- // Thickness of a scrollbar.
- int scrollbar_thickness_;
-
- // Reserved thickness of a scrollbar. This is how much space the scrollbar
- // takes from the available area. 0 for overlay.
- int scrollbar_reserved_thickness_;
-
- // Used to remember which toolbar is in use
- const ToolbarButtonInfo* current_tb_info_;
- size_t current_tb_info_size_;
-
- PaintManager paint_manager_;
-
- struct BackgroundPart {
- pp::Rect location;
- uint32 color;
- };
- std::vector<BackgroundPart> background_parts_;
-
- struct PrintSettings {
- PrintSettings() {
- Clear();
- }
- void Clear() {
- is_printing = false;
- print_pages_called_ = false;
- memset(&pepper_print_settings, 0, sizeof(pepper_print_settings));
- }
- // This is set to true when PrintBegin is called and false when PrintEnd is
- // called.
- bool is_printing;
- // To know whether this was an actual print operation, so we don't double
- // count UMA logging.
- bool print_pages_called_;
- PP_PrintSettings_Dev pepper_print_settings;
- };
-
- PrintSettings print_settings_;
-
- scoped_ptr<PDFEngine> engine_;
-
- // This engine is used to render the individual preview page data. This is
- // used only in print preview mode. This will use |PreviewModeClient|
- // interface which has very limited access to the pp::Instance.
- scoped_ptr<PDFEngine> preview_engine_;
-
- std::string url_;
-
- scoped_ptr<FadingControls> toolbar_;
- ThumbnailControl thumbnails_;
- ProgressControl progress_bar_;
- uint32 delayed_progress_timer_id_;
- PageIndicator page_indicator_;
-
- // Used for creating images from numbers.
- scoped_ptr<NumberImageGenerator> number_image_generator_;
-
- // Used for submitting forms.
- pp::CompletionCallbackFactory<Instance> form_factory_;
- pp::URLLoader form_loader_;
-
- // Used for generating callbacks.
- // TODO(raymes): We don't really need other callback factories we can just
- // fold them into this one.
- pp::CompletionCallbackFactory<Instance> callback_factory_;
-
- // True if we haven't painted the plugin viewport yet.
- bool first_paint_;
-
- // True when we've painted at least one page from the document.
- bool painted_first_page_;
-
- // True if we should display page indicator, false otherwise
- bool show_page_indicator_;
-
- // Callback when the document load completes.
- pp::Var on_load_callback_;
- pp::Var on_scroll_callback_;
- pp::Var on_plugin_size_changed_callback_;
-
- DocumentLoadState document_load_state_;
- DocumentLoadState preview_document_load_state_;
-
- // JavaScript interface to control this instance.
- // This wraps a PDFScriptableObject in a pp::Var.
- pp::VarPrivate instance_object_;
-
- // Used so that we only tell the browser once about an unsupported feature, to
- // avoid the infobar going up more than once.
- bool told_browser_about_unsupported_feature_;
-
- // Keeps track of which unsupported features we reported, so we avoid spamming
- // the stats if a feature shows up many times per document.
- std::set<std::string> unsupported_features_reported_;
-
- // Number of pages in print preview mode, 0 if not in print preview mode.
- int print_preview_page_count_;
- std::vector<int> print_preview_page_numbers_;
-
- // Used to manage loaded print preview page information. A |PreviewPageInfo|
- // consists of data source url string and the page index in the destination
- // document.
- typedef std::pair<std::string, int> PreviewPageInfo;
- std::queue<PreviewPageInfo> preview_pages_info_;
-
- // Used to signal the browser about focus changes to trigger the OSK.
- // TODO(abodenha@chromium.org) Implement full IME support in the plugin.
- // http://crbug.com/132565
- scoped_ptr<pp::TextInput_Dev> text_input_;
-};
-
-// This implements the JavaScript class entrypoint for the plugin instance.
-// This class is just a thin wrapper. It delegates relevant methods to Instance.
-class PDFScriptableObject : public pp::deprecated::ScriptableObject {
- public:
- explicit PDFScriptableObject(Instance* instance);
- virtual ~PDFScriptableObject();
-
- // pp::deprecated::ScriptableObject implementation.
- virtual bool HasMethod(const pp::Var& method, pp::Var* exception);
- virtual pp::Var Call(const pp::Var& method,
- const std::vector<pp::Var>& args,
- pp::Var* exception);
-
- private:
- Instance* instance_;
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_INSTANCE_H_
diff --git a/xfa_test/pdf/number_image_generator.cc b/xfa_test/pdf/number_image_generator.cc
deleted file mode 100644
index 289691513c..0000000000
--- a/xfa_test/pdf/number_image_generator.cc
+++ /dev/null
@@ -1,81 +0,0 @@
-// 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 "pdf/number_image_generator.h"
-
-#include "base/logging.h"
-#include "base/strings/string_util.h"
-#include "pdf/draw_utils.h"
-#include "pdf/instance.h"
-
-namespace chrome_pdf {
-
-const int kPageNumberSeparator = 0;
-const int kPageNumberOriginX = 8;
-const int kPageNumberOriginY = 4;
-
-NumberImageGenerator::NumberImageGenerator(Instance* instance)
- : instance_(instance),
- device_scale_(1.0f) {
-}
-
-NumberImageGenerator::~NumberImageGenerator() {
-}
-
-void NumberImageGenerator::Configure(const pp::ImageData& number_background,
- const std::vector<pp::ImageData>& number_images, float device_scale) {
- number_background_ = number_background;
- number_images_ = number_images;
- device_scale_ = device_scale;
-}
-
-void NumberImageGenerator::GenerateImage(
- int page_number, pp::ImageData* image) {
- char buffer[12];
- base::snprintf(buffer, sizeof(buffer), "%u", page_number);
- int extra_width = 0;
- DCHECK(number_images_.size() >= 10);
- DCHECK(!number_background_.is_null());
- for (size_t i = 1; i < strlen(buffer); ++i) {
- int index = buffer[i] - '0';
- extra_width += number_images_[index].size().width();
- extra_width += static_cast<int>(kPageNumberSeparator * device_scale_);
- }
-
- *image = pp::ImageData(
- instance_,
- PP_IMAGEDATAFORMAT_BGRA_PREMUL,
- pp::Size(number_background_.size().width() + extra_width,
- number_background_.size().height()),
- false);
-
- int stretch_point = number_background_.size().width() / 2;
-
- pp::Rect src_rc(0, 0, stretch_point, number_background_.size().height());
- pp::Rect dest_rc(src_rc);
- CopyImage(number_background_, src_rc, image, dest_rc, false);
- src_rc.Offset(number_background_.size().width() - stretch_point, 0);
- dest_rc.Offset(image->size().width() - stretch_point, 0);
- CopyImage(number_background_, src_rc, image, dest_rc, false);
- src_rc = pp::Rect(stretch_point, 0, 1, number_background_.size().height());
- dest_rc = src_rc;
- dest_rc.set_width(extra_width + 1);
- CopyImage(number_background_, src_rc, image, dest_rc, true);
-
- pp::Point origin(static_cast<int>(kPageNumberOriginX * device_scale_),
- static_cast<int>(kPageNumberOriginY * device_scale_));
- for (size_t i = 0; i < strlen(buffer); ++i) {
- int index = buffer[i] - '0';
- CopyImage(
- number_images_[index],
- pp::Rect(pp::Point(), number_images_[index].size()),
- image, pp::Rect(origin, number_images_[index].size()), false);
- origin += pp::Point(
- number_images_[index].size().width() +
- static_cast<int>(kPageNumberSeparator * device_scale_), 0);
- }
-}
-
-} // namespace chrome_pdf
-
diff --git a/xfa_test/pdf/number_image_generator.h b/xfa_test/pdf/number_image_generator.h
deleted file mode 100644
index 51ffd3ec3d..0000000000
--- a/xfa_test/pdf/number_image_generator.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// 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.
-
-#ifndef PDF_NUMBER_IMAGE_GENERATOR_H
-#define PDF_NUMBER_IMAGE_GENERATOR_H
-
-#include <vector>
-
-#include "ppapi/cpp/image_data.h"
-
-namespace chrome_pdf {
-
-class Instance;
-
-class NumberImageGenerator {
- public:
- explicit NumberImageGenerator(Instance* instance);
- virtual ~NumberImageGenerator();
-
- void Configure(const pp::ImageData& number_background,
- const std::vector<pp::ImageData>& number_images,
- float device_scale);
-
- void GenerateImage(int page_number, pp::ImageData* image);
-
- private:
- Instance* instance_;
- pp::ImageData number_background_;
- std::vector<pp::ImageData> number_images_;
- float device_scale_;
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_NUMBER_IMAGE_GENERATOR_H
-
diff --git a/xfa_test/pdf/out_of_process_instance.cc b/xfa_test/pdf/out_of_process_instance.cc
deleted file mode 100644
index d627dc2d79..0000000000
--- a/xfa_test/pdf/out_of_process_instance.cc
+++ /dev/null
@@ -1,1369 +0,0 @@
-// 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 "pdf/out_of_process_instance.h"
-
-#include <algorithm> // for min/max()
-#define _USE_MATH_DEFINES // for M_PI
-#include <cmath> // for log() and pow()
-#include <math.h>
-#include <list>
-
-#include "base/json/json_reader.h"
-#include "base/json/json_writer.h"
-#include "base/logging.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_split.h"
-#include "base/strings/string_util.h"
-#include "base/values.h"
-#include "chrome/common/content_restriction.h"
-#include "net/base/escape.h"
-#include "pdf/pdf.h"
-#include "ppapi/c/dev/ppb_cursor_control_dev.h"
-#include "ppapi/c/pp_errors.h"
-#include "ppapi/c/pp_rect.h"
-#include "ppapi/c/private/ppb_instance_private.h"
-#include "ppapi/c/private/ppp_pdf.h"
-#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
-#include "ppapi/cpp/core.h"
-#include "ppapi/cpp/dev/memory_dev.h"
-#include "ppapi/cpp/dev/text_input_dev.h"
-#include "ppapi/cpp/dev/url_util_dev.h"
-#include "ppapi/cpp/module.h"
-#include "ppapi/cpp/point.h"
-#include "ppapi/cpp/private/pdf.h"
-#include "ppapi/cpp/private/var_private.h"
-#include "ppapi/cpp/rect.h"
-#include "ppapi/cpp/resource.h"
-#include "ppapi/cpp/url_request_info.h"
-#include "ppapi/cpp/var_array.h"
-#include "ppapi/cpp/var_dictionary.h"
-#include "ui/events/keycodes/keyboard_codes.h"
-
-#if defined(OS_MACOSX)
-#include "base/mac/mac_util.h"
-#endif
-
-namespace chrome_pdf {
-
-const char kChromePrint[] = "chrome://print/";
-const char kChromeExtension[] =
- "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai";
-
-// Dictionary Value key names for the document accessibility info
-const char kAccessibleNumberOfPages[] = "numberOfPages";
-const char kAccessibleLoaded[] = "loaded";
-const char kAccessibleCopyable[] = "copyable";
-
-// Constants used in handling postMessage() messages.
-const char kType[] = "type";
-// Viewport message arguments. (Page -> Plugin).
-const char kJSViewportType[] = "viewport";
-const char kJSXOffset[] = "xOffset";
-const char kJSYOffset[] = "yOffset";
-const char kJSZoom[] = "zoom";
-// Stop scrolling message (Page -> Plugin)
-const char kJSStopScrollingType[] = "stopScrolling";
-// Document dimension arguments (Plugin -> Page).
-const char kJSDocumentDimensionsType[] = "documentDimensions";
-const char kJSDocumentWidth[] = "width";
-const char kJSDocumentHeight[] = "height";
-const char kJSPageDimensions[] = "pageDimensions";
-const char kJSPageX[] = "x";
-const char kJSPageY[] = "y";
-const char kJSPageWidth[] = "width";
-const char kJSPageHeight[] = "height";
-// Document load progress arguments (Plugin -> Page)
-const char kJSLoadProgressType[] = "loadProgress";
-const char kJSProgressPercentage[] = "progress";
-// Get password arguments (Plugin -> Page)
-const char kJSGetPasswordType[] = "getPassword";
-// Get password complete arguments (Page -> Plugin)
-const char kJSGetPasswordCompleteType[] = "getPasswordComplete";
-const char kJSPassword[] = "password";
-// Print (Page -> Plugin)
-const char kJSPrintType[] = "print";
-// Go to page (Plugin -> Page)
-const char kJSGoToPageType[] = "goToPage";
-const char kJSPageNumber[] = "page";
-// Reset print preview mode (Page -> Plugin)
-const char kJSResetPrintPreviewModeType[] = "resetPrintPreviewMode";
-const char kJSPrintPreviewUrl[] = "url";
-const char kJSPrintPreviewGrayscale[] = "grayscale";
-const char kJSPrintPreviewPageCount[] = "pageCount";
-// Load preview page (Page -> Plugin)
-const char kJSLoadPreviewPageType[] = "loadPreviewPage";
-const char kJSPreviewPageUrl[] = "url";
-const char kJSPreviewPageIndex[] = "index";
-// Set scroll position (Plugin -> Page)
-const char kJSSetScrollPositionType[] = "setScrollPosition";
-const char kJSPositionX[] = "x";
-const char kJSPositionY[] = "y";
-// Set translated strings (Plugin -> Page)
-const char kJSSetTranslatedStringsType[] = "setTranslatedStrings";
-const char kJSGetPasswordString[] = "getPasswordString";
-const char kJSLoadingString[] = "loadingString";
-const char kJSLoadFailedString[] = "loadFailedString";
-// Request accessibility JSON data (Page -> Plugin)
-const char kJSGetAccessibilityJSONType[] = "getAccessibilityJSON";
-const char kJSAccessibilityPageNumber[] = "page";
-// Reply with accessibility JSON data (Plugin -> Page)
-const char kJSGetAccessibilityJSONReplyType[] = "getAccessibilityJSONReply";
-const char kJSAccessibilityJSON[] = "json";
-// Cancel the stream URL request (Plugin -> Page)
-const char kJSCancelStreamUrlType[] = "cancelStreamUrl";
-// Navigate to the given URL (Plugin -> Page)
-const char kJSNavigateType[] = "navigate";
-const char kJSNavigateUrl[] = "url";
-const char kJSNavigateNewTab[] = "newTab";
-// Open the email editor with the given parameters (Plugin -> Page)
-const char kJSEmailType[] = "email";
-const char kJSEmailTo[] = "to";
-const char kJSEmailCc[] = "cc";
-const char kJSEmailBcc[] = "bcc";
-const char kJSEmailSubject[] = "subject";
-const char kJSEmailBody[] = "body";
-// Rotation (Page -> Plugin)
-const char kJSRotateClockwiseType[] = "rotateClockwise";
-const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise";
-// Select all text in the document (Page -> Plugin)
-const char kJSSelectAllType[] = "selectAll";
-
-const int kFindResultCooldownMs = 100;
-
-const double kMinZoom = 0.01;
-
-namespace {
-
-static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1;
-
-PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) {
- pp::Var var;
- void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface);
- if (object) {
- var = static_cast<OutOfProcessInstance*>(object)->GetLinkAtPosition(
- pp::Point(point));
- }
- return var.Detach();
-}
-
-void Transform(PP_Instance instance, PP_PrivatePageTransformType type) {
- void* object =
- pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface);
- if (object) {
- OutOfProcessInstance* obj_instance =
- static_cast<OutOfProcessInstance*>(object);
- switch (type) {
- case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW:
- obj_instance->RotateClockwise();
- break;
- case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW:
- obj_instance->RotateCounterclockwise();
- break;
- }
- }
-}
-
-const PPP_Pdf ppp_private = {
- &GetLinkAtPosition,
- &Transform
-};
-
-int ExtractPrintPreviewPageIndex(const std::string& src_url) {
- // Sample |src_url| format: chrome://print/id/page_index/print.pdf
- std::vector<std::string> url_substr;
- base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr);
- if (url_substr.size() != 3)
- return -1;
-
- if (url_substr[2] != "print.pdf")
- return -1;
-
- int page_index = 0;
- if (!base::StringToInt(url_substr[1], &page_index))
- return -1;
- return page_index;
-}
-
-bool IsPrintPreviewUrl(const std::string& url) {
- return url.substr(0, strlen(kChromePrint)) == kChromePrint;
-}
-
-void ScalePoint(float scale, pp::Point* point) {
- point->set_x(static_cast<int>(point->x() * scale));
- point->set_y(static_cast<int>(point->y() * scale));
-}
-
-void ScaleRect(float scale, pp::Rect* rect) {
- int left = static_cast<int>(floorf(rect->x() * scale));
- int top = static_cast<int>(floorf(rect->y() * scale));
- int right = static_cast<int>(ceilf((rect->x() + rect->width()) * scale));
- int bottom = static_cast<int>(ceilf((rect->y() + rect->height()) * scale));
- rect->SetRect(left, top, right - left, bottom - top);
-}
-
-// TODO(raymes): Remove this dependency on VarPrivate/InstancePrivate. It's
-// needed right now to do a synchronous call to JavaScript, but we could easily
-// replace this with a custom PPB_PDF function.
-pp::Var ModalDialog(const pp::Instance* instance,
- const std::string& type,
- const std::string& message,
- const std::string& default_answer) {
- const PPB_Instance_Private* interface =
- reinterpret_cast<const PPB_Instance_Private*>(
- pp::Module::Get()->GetBrowserInterface(
- PPB_INSTANCE_PRIVATE_INTERFACE));
- pp::VarPrivate window(pp::PASS_REF,
- interface->GetWindowObject(instance->pp_instance()));
- if (default_answer.empty())
- return window.Call(type, message);
- else
- return window.Call(type, message, default_answer);
-}
-
-} // namespace
-
-OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance)
- : pp::Instance(instance),
- pp::Find_Private(this),
- pp::Printing_Dev(this),
- pp::Selection_Dev(this),
- cursor_(PP_CURSORTYPE_POINTER),
- zoom_(1.0),
- device_scale_(1.0),
- printing_enabled_(true),
- full_(false),
- paint_manager_(this, this, true),
- first_paint_(true),
- document_load_state_(LOAD_STATE_LOADING),
- preview_document_load_state_(LOAD_STATE_COMPLETE),
- uma_(this),
- told_browser_about_unsupported_feature_(false),
- print_preview_page_count_(0),
- last_progress_sent_(0),
- recently_sent_find_update_(false),
- received_viewport_message_(false),
- did_call_start_loading_(false),
- stop_scrolling_(false) {
- loader_factory_.Initialize(this);
- timer_factory_.Initialize(this);
- form_factory_.Initialize(this);
- print_callback_factory_.Initialize(this);
- engine_.reset(PDFEngine::Create(this));
- pp::Module::Get()->AddPluginInterface(kPPPPdfInterface, &ppp_private);
- AddPerInstanceObject(kPPPPdfInterface, this);
-
- RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
- RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
- RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_TOUCH);
-}
-
-OutOfProcessInstance::~OutOfProcessInstance() {
- RemovePerInstanceObject(kPPPPdfInterface, this);
-}
-
-bool OutOfProcessInstance::Init(uint32_t argc,
- const char* argn[],
- const char* argv[]) {
- // Check if the PDF is being loaded in the PDF chrome extension. We only allow
- // the plugin to be put into "full frame" mode when it is being loaded in the
- // extension because this enables some features that we don't want pages
- // abusing outside of the extension.
- pp::Var document_url_var = pp::URLUtil_Dev::Get()->GetDocumentURL(this);
- std::string document_url = document_url_var.is_string() ?
- document_url_var.AsString() : std::string();
- std::string extension_url = std::string(kChromeExtension);
- bool in_extension =
- !document_url.compare(0, extension_url.size(), extension_url);
-
- if (in_extension) {
- // Check if the plugin is full frame. This is passed in from JS.
- for (uint32_t i = 0; i < argc; ++i) {
- if (strcmp(argn[i], "full-frame") == 0) {
- full_ = true;
- break;
- }
- }
- }
-
- // Only allow the plugin to handle find requests if it is full frame.
- if (full_)
- SetPluginToHandleFindRequests();
-
- // Send translated strings to the extension where they will be displayed.
- // TODO(raymes): It would be better to get these in the extension directly
- // through an API but no such API currently exists.
- pp::VarDictionary translated_strings;
- translated_strings.Set(kType, kJSSetTranslatedStringsType);
- translated_strings.Set(kJSGetPasswordString,
- GetLocalizedString(PP_RESOURCESTRING_PDFGETPASSWORD));
- translated_strings.Set(kJSLoadingString,
- GetLocalizedString(PP_RESOURCESTRING_PDFLOADING));
- translated_strings.Set(kJSLoadFailedString,
- GetLocalizedString(PP_RESOURCESTRING_PDFLOAD_FAILED));
- PostMessage(translated_strings);
-
- text_input_.reset(new pp::TextInput_Dev(this));
-
- const char* stream_url = NULL;
- const char* original_url = NULL;
- const char* headers = NULL;
- for (uint32_t i = 0; i < argc; ++i) {
- if (strcmp(argn[i], "src") == 0)
- original_url = argv[i];
- else if (strcmp(argn[i], "stream-url") == 0)
- stream_url = argv[i];
- else if (strcmp(argn[i], "headers") == 0)
- headers = argv[i];
- }
-
- // TODO(raymes): This is a hack to ensure that if no headers are passed in
- // then we get the right MIME type. When the in process plugin is removed we
- // can fix the document loader properly and remove this hack.
- if (!headers || strcmp(headers, "") == 0)
- headers = "content-type: application/pdf";
-
- if (!original_url)
- return false;
-
- if (!stream_url)
- stream_url = original_url;
-
- // If we're in print preview mode we don't need to load the document yet.
- // A |kJSResetPrintPreviewModeType| message will be sent to the plugin letting
- // it know the url to load. By not loading here we avoid loading the same
- // document twice.
- if (IsPrintPreviewUrl(original_url))
- return true;
-
- LoadUrl(stream_url);
- url_ = original_url;
- return engine_->New(original_url, headers);
-}
-
-void OutOfProcessInstance::HandleMessage(const pp::Var& message) {
- pp::VarDictionary dict(message);
- if (!dict.Get(kType).is_string()) {
- NOTREACHED();
- return;
- }
-
- std::string type = dict.Get(kType).AsString();
-
- if (type == kJSViewportType &&
- dict.Get(pp::Var(kJSXOffset)).is_int() &&
- dict.Get(pp::Var(kJSYOffset)).is_int() &&
- dict.Get(pp::Var(kJSZoom)).is_number()) {
- received_viewport_message_ = true;
- stop_scrolling_ = false;
- double zoom = dict.Get(pp::Var(kJSZoom)).AsDouble();
- pp::Point scroll_offset(dict.Get(pp::Var(kJSXOffset)).AsInt(),
- dict.Get(pp::Var(kJSYOffset)).AsInt());
-
- // Bound the input parameters.
- zoom = std::max(kMinZoom, zoom);
- SetZoom(zoom);
- scroll_offset = BoundScrollOffsetToDocument(scroll_offset);
- engine_->ScrolledToXPosition(scroll_offset.x() * device_scale_);
- engine_->ScrolledToYPosition(scroll_offset.y() * device_scale_);
- } else if (type == kJSGetPasswordCompleteType &&
- dict.Get(pp::Var(kJSPassword)).is_string()) {
- if (password_callback_) {
- pp::CompletionCallbackWithOutput<pp::Var> callback = *password_callback_;
- password_callback_.reset();
- *callback.output() = dict.Get(pp::Var(kJSPassword)).pp_var();
- callback.Run(PP_OK);
- } else {
- NOTREACHED();
- }
- } else if (type == kJSPrintType) {
- Print();
- } else if (type == kJSRotateClockwiseType) {
- RotateClockwise();
- } else if (type == kJSRotateCounterclockwiseType) {
- RotateCounterclockwise();
- } else if (type == kJSSelectAllType) {
- engine_->SelectAll();
- } else if (type == kJSResetPrintPreviewModeType &&
- dict.Get(pp::Var(kJSPrintPreviewUrl)).is_string() &&
- dict.Get(pp::Var(kJSPrintPreviewGrayscale)).is_bool() &&
- dict.Get(pp::Var(kJSPrintPreviewPageCount)).is_int()) {
- url_ = dict.Get(pp::Var(kJSPrintPreviewUrl)).AsString();
- preview_pages_info_ = std::queue<PreviewPageInfo>();
- preview_document_load_state_ = LOAD_STATE_COMPLETE;
- document_load_state_ = LOAD_STATE_LOADING;
- LoadUrl(url_);
- preview_engine_.reset();
- engine_.reset(PDFEngine::Create(this));
- engine_->SetGrayscale(dict.Get(pp::Var(kJSPrintPreviewGrayscale)).AsBool());
- engine_->New(url_.c_str());
-
- print_preview_page_count_ =
- std::max(dict.Get(pp::Var(kJSPrintPreviewPageCount)).AsInt(), 0);
-
- paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_));
- } else if (type == kJSLoadPreviewPageType &&
- dict.Get(pp::Var(kJSPreviewPageUrl)).is_string() &&
- dict.Get(pp::Var(kJSPreviewPageIndex)).is_int()) {
- ProcessPreviewPageInfo(dict.Get(pp::Var(kJSPreviewPageUrl)).AsString(),
- dict.Get(pp::Var(kJSPreviewPageIndex)).AsInt());
- } else if (type == kJSGetAccessibilityJSONType) {
- pp::VarDictionary reply;
- reply.Set(pp::Var(kType), pp::Var(kJSGetAccessibilityJSONReplyType));
- if (dict.Get(pp::Var(kJSAccessibilityPageNumber)).is_int()) {
- int page = dict.Get(pp::Var(kJSAccessibilityPageNumber)).AsInt();
- reply.Set(pp::Var(kJSAccessibilityJSON),
- pp::Var(engine_->GetPageAsJSON(page)));
- } else {
- base::DictionaryValue node;
- node.SetInteger(kAccessibleNumberOfPages, engine_->GetNumberOfPages());
- node.SetBoolean(kAccessibleLoaded,
- document_load_state_ != LOAD_STATE_LOADING);
- bool has_permissions =
- engine_->HasPermission(PDFEngine::PERMISSION_COPY) ||
- engine_->HasPermission(PDFEngine::PERMISSION_COPY_ACCESSIBLE);
- node.SetBoolean(kAccessibleCopyable, has_permissions);
- std::string json;
- base::JSONWriter::Write(&node, &json);
- reply.Set(pp::Var(kJSAccessibilityJSON), pp::Var(json));
- }
- PostMessage(reply);
- } else if (type == kJSStopScrollingType) {
- stop_scrolling_ = true;
- } else {
- NOTREACHED();
- }
-}
-
-bool OutOfProcessInstance::HandleInputEvent(
- const pp::InputEvent& event) {
- // To simplify things, convert the event into device coordinates if it is
- // a mouse event.
- pp::InputEvent event_device_res(event);
- {
- pp::MouseInputEvent mouse_event(event);
- if (!mouse_event.is_null()) {
- pp::Point point = mouse_event.GetPosition();
- pp::Point movement = mouse_event.GetMovement();
- ScalePoint(device_scale_, &point);
- ScalePoint(device_scale_, &movement);
- mouse_event = pp::MouseInputEvent(
- this,
- event.GetType(),
- event.GetTimeStamp(),
- event.GetModifiers(),
- mouse_event.GetButton(),
- point,
- mouse_event.GetClickCount(),
- movement);
- event_device_res = mouse_event;
- }
- }
-
- pp::InputEvent offset_event(event_device_res);
- switch (offset_event.GetType()) {
- case PP_INPUTEVENT_TYPE_MOUSEDOWN:
- case PP_INPUTEVENT_TYPE_MOUSEUP:
- case PP_INPUTEVENT_TYPE_MOUSEMOVE:
- case PP_INPUTEVENT_TYPE_MOUSEENTER:
- case PP_INPUTEVENT_TYPE_MOUSELEAVE: {
- pp::MouseInputEvent mouse_event(event_device_res);
- pp::MouseInputEvent mouse_event_dip(event);
- pp::Point point = mouse_event.GetPosition();
- point.set_x(point.x() - available_area_.x());
- offset_event = pp::MouseInputEvent(
- this,
- event.GetType(),
- event.GetTimeStamp(),
- event.GetModifiers(),
- mouse_event.GetButton(),
- point,
- mouse_event.GetClickCount(),
- mouse_event.GetMovement());
- break;
- }
- default:
- break;
- }
- if (engine_->HandleEvent(offset_event))
- return true;
-
- // TODO(raymes): Implement this scroll behavior in JS:
- // When click+dragging, scroll the document correctly.
-
- // Return true for unhandled clicks so the plugin takes focus.
- return (event.GetType() == PP_INPUTEVENT_TYPE_MOUSEDOWN);
-}
-
-void OutOfProcessInstance::DidChangeView(const pp::View& view) {
- pp::Rect view_rect(view.GetRect());
- float old_device_scale = device_scale_;
- float device_scale = view.GetDeviceScale();
- pp::Size view_device_size(view_rect.width() * device_scale,
- view_rect.height() * device_scale);
-
- if (view_device_size != plugin_size_ || device_scale != device_scale_) {
- device_scale_ = device_scale;
- plugin_dip_size_ = view_rect.size();
- plugin_size_ = view_device_size;
-
- paint_manager_.SetSize(view_device_size, device_scale_);
-
- pp::Size new_image_data_size = PaintManager::GetNewContextSize(
- image_data_.size(),
- plugin_size_);
- if (new_image_data_size != image_data_.size()) {
- image_data_ = pp::ImageData(this,
- PP_IMAGEDATAFORMAT_BGRA_PREMUL,
- new_image_data_size,
- false);
- first_paint_ = true;
- }
-
- if (image_data_.is_null()) {
- DCHECK(plugin_size_.IsEmpty());
- return;
- }
-
- OnGeometryChanged(zoom_, old_device_scale);
- }
-
- if (!stop_scrolling_) {
- pp::Point scroll_offset(
- BoundScrollOffsetToDocument(view.GetScrollOffset()));
- engine_->ScrolledToXPosition(scroll_offset.x() * device_scale_);
- engine_->ScrolledToYPosition(scroll_offset.y() * device_scale_);
- }
-}
-
-pp::Var OutOfProcessInstance::GetLinkAtPosition(
- const pp::Point& point) {
- pp::Point offset_point(point);
- ScalePoint(device_scale_, &offset_point);
- offset_point.set_x(offset_point.x() - available_area_.x());
- return engine_->GetLinkAtPosition(offset_point);
-}
-
-pp::Var OutOfProcessInstance::GetSelectedText(bool html) {
- if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY))
- return pp::Var();
- return engine_->GetSelectedText();
-}
-
-uint32_t OutOfProcessInstance::QuerySupportedPrintOutputFormats() {
- return engine_->QuerySupportedPrintOutputFormats();
-}
-
-int32_t OutOfProcessInstance::PrintBegin(
- const PP_PrintSettings_Dev& print_settings) {
- // For us num_pages is always equal to the number of pages in the PDF
- // document irrespective of the printable area.
- int32_t ret = engine_->GetNumberOfPages();
- if (!ret)
- return 0;
-
- uint32_t supported_formats = engine_->QuerySupportedPrintOutputFormats();
- if ((print_settings.format & supported_formats) == 0)
- return 0;
-
- print_settings_.is_printing = true;
- print_settings_.pepper_print_settings = print_settings;
- engine_->PrintBegin();
- return ret;
-}
-
-pp::Resource OutOfProcessInstance::PrintPages(
- const PP_PrintPageNumberRange_Dev* page_ranges,
- uint32_t page_range_count) {
- if (!print_settings_.is_printing)
- return pp::Resource();
-
- print_settings_.print_pages_called_ = true;
- return engine_->PrintPages(page_ranges, page_range_count,
- print_settings_.pepper_print_settings);
-}
-
-void OutOfProcessInstance::PrintEnd() {
- if (print_settings_.print_pages_called_)
- UserMetricsRecordAction("PDF.PrintPage");
- print_settings_.Clear();
- engine_->PrintEnd();
-}
-
-bool OutOfProcessInstance::IsPrintScalingDisabled() {
- return !engine_->GetPrintScaling();
-}
-
-bool OutOfProcessInstance::StartFind(const std::string& text,
- bool case_sensitive) {
- engine_->StartFind(text.c_str(), case_sensitive);
- return true;
-}
-
-void OutOfProcessInstance::SelectFindResult(bool forward) {
- engine_->SelectFindResult(forward);
-}
-
-void OutOfProcessInstance::StopFind() {
- engine_->StopFind();
- tickmarks_.clear();
- SetTickmarks(tickmarks_);
-}
-
-void OutOfProcessInstance::OnPaint(
- const std::vector<pp::Rect>& paint_rects,
- std::vector<PaintManager::ReadyRect>* ready,
- std::vector<pp::Rect>* pending) {
- if (image_data_.is_null()) {
- DCHECK(plugin_size_.IsEmpty());
- return;
- }
- if (first_paint_) {
- first_paint_ = false;
- pp::Rect rect = pp::Rect(pp::Point(), image_data_.size());
- FillRect(rect, kBackgroundColor);
- ready->push_back(PaintManager::ReadyRect(rect, image_data_, true));
- }
-
- if (!received_viewport_message_)
- return;
-
- engine_->PrePaint();
-
- for (size_t i = 0; i < paint_rects.size(); i++) {
- // Intersect with plugin area since there could be pending invalidates from
- // when the plugin area was larger.
- pp::Rect rect =
- paint_rects[i].Intersect(pp::Rect(pp::Point(), plugin_size_));
- if (rect.IsEmpty())
- continue;
-
- pp::Rect pdf_rect = available_area_.Intersect(rect);
- if (!pdf_rect.IsEmpty()) {
- pdf_rect.Offset(available_area_.x() * -1, 0);
-
- std::vector<pp::Rect> pdf_ready;
- std::vector<pp::Rect> pdf_pending;
- engine_->Paint(pdf_rect, &image_data_, &pdf_ready, &pdf_pending);
- for (size_t j = 0; j < pdf_ready.size(); ++j) {
- pdf_ready[j].Offset(available_area_.point());
- ready->push_back(
- PaintManager::ReadyRect(pdf_ready[j], image_data_, false));
- }
- for (size_t j = 0; j < pdf_pending.size(); ++j) {
- pdf_pending[j].Offset(available_area_.point());
- pending->push_back(pdf_pending[j]);
- }
- }
-
- for (size_t j = 0; j < background_parts_.size(); ++j) {
- pp::Rect intersection = background_parts_[j].location.Intersect(rect);
- if (!intersection.IsEmpty()) {
- FillRect(intersection, background_parts_[j].color);
- ready->push_back(
- PaintManager::ReadyRect(intersection, image_data_, false));
- }
- }
- }
-
- engine_->PostPaint();
-}
-
-void OutOfProcessInstance::DidOpen(int32_t result) {
- if (result == PP_OK) {
- if (!engine_->HandleDocumentLoad(embed_loader_)) {
- document_load_state_ = LOAD_STATE_LOADING;
- DocumentLoadFailed();
- }
- } else if (result != PP_ERROR_ABORTED) { // Can happen in tests.
- NOTREACHED();
- DocumentLoadFailed();
- }
-
- // If it's a progressive load, cancel the stream URL request so that requests
- // can be made on the original URL.
- // TODO(raymes): Make this clearer once the in-process plugin is deleted.
- if (engine_->IsProgressiveLoad()) {
- pp::VarDictionary message;
- message.Set(kType, kJSCancelStreamUrlType);
- PostMessage(message);
- }
-}
-
-void OutOfProcessInstance::DidOpenPreview(int32_t result) {
- if (result == PP_OK) {
- preview_engine_.reset(PDFEngine::Create(new PreviewModeClient(this)));
- preview_engine_->HandleDocumentLoad(embed_preview_loader_);
- } else {
- NOTREACHED();
- }
-}
-
-void OutOfProcessInstance::OnClientTimerFired(int32_t id) {
- engine_->OnCallback(id);
-}
-
-void OutOfProcessInstance::CalculateBackgroundParts() {
- background_parts_.clear();
- int left_width = available_area_.x();
- int right_start = available_area_.right();
- int right_width = abs(plugin_size_.width() - available_area_.right());
- int bottom = std::min(available_area_.bottom(), plugin_size_.height());
-
- // Add the left, right, and bottom rectangles. Note: we assume only
- // horizontal centering.
- BackgroundPart part = {
- pp::Rect(0, 0, left_width, bottom),
- kBackgroundColor
- };
- if (!part.location.IsEmpty())
- background_parts_.push_back(part);
- part.location = pp::Rect(right_start, 0, right_width, bottom);
- if (!part.location.IsEmpty())
- background_parts_.push_back(part);
- part.location = pp::Rect(
- 0, bottom, plugin_size_.width(), plugin_size_.height() - bottom);
- if (!part.location.IsEmpty())
- background_parts_.push_back(part);
-}
-
-int OutOfProcessInstance::GetDocumentPixelWidth() const {
- return static_cast<int>(ceil(document_size_.width() * zoom_ * device_scale_));
-}
-
-int OutOfProcessInstance::GetDocumentPixelHeight() const {
- return static_cast<int>(
- ceil(document_size_.height() * zoom_ * device_scale_));
-}
-
-void OutOfProcessInstance::FillRect(const pp::Rect& rect, uint32 color) {
- DCHECK(!image_data_.is_null() || rect.IsEmpty());
- uint32* buffer_start = static_cast<uint32*>(image_data_.data());
- int stride = image_data_.stride();
- uint32* ptr = buffer_start + rect.y() * stride / 4 + rect.x();
- int height = rect.height();
- int width = rect.width();
- for (int y = 0; y < height; ++y) {
- for (int x = 0; x < width; ++x)
- *(ptr + x) = color;
- ptr += stride /4;
- }
-}
-
-void OutOfProcessInstance::DocumentSizeUpdated(const pp::Size& size) {
- document_size_ = size;
-
- pp::VarDictionary dimensions;
- dimensions.Set(kType, kJSDocumentDimensionsType);
- dimensions.Set(kJSDocumentWidth, pp::Var(document_size_.width()));
- dimensions.Set(kJSDocumentHeight, pp::Var(document_size_.height()));
- pp::VarArray page_dimensions_array;
- int num_pages = engine_->GetNumberOfPages();
- for (int i = 0; i < num_pages; ++i) {
- pp::Rect page_rect = engine_->GetPageRect(i);
- pp::VarDictionary page_dimensions;
- page_dimensions.Set(kJSPageX, pp::Var(page_rect.x()));
- page_dimensions.Set(kJSPageY, pp::Var(page_rect.y()));
- page_dimensions.Set(kJSPageWidth, pp::Var(page_rect.width()));
- page_dimensions.Set(kJSPageHeight, pp::Var(page_rect.height()));
- page_dimensions_array.Set(i, page_dimensions);
- }
- dimensions.Set(kJSPageDimensions, page_dimensions_array);
- PostMessage(dimensions);
-
- OnGeometryChanged(zoom_, device_scale_);
-}
-
-void OutOfProcessInstance::Invalidate(const pp::Rect& rect) {
- pp::Rect offset_rect(rect);
- offset_rect.Offset(available_area_.point());
- paint_manager_.InvalidateRect(offset_rect);
-}
-
-void OutOfProcessInstance::Scroll(const pp::Point& point) {
- if (!image_data_.is_null())
- paint_manager_.ScrollRect(available_area_, point);
-}
-
-void OutOfProcessInstance::ScrollToX(int x) {
- pp::VarDictionary position;
- position.Set(kType, kJSSetScrollPositionType);
- position.Set(kJSPositionX, pp::Var(x / device_scale_));
- PostMessage(position);
-}
-
-void OutOfProcessInstance::ScrollToY(int y) {
- pp::VarDictionary position;
- position.Set(kType, kJSSetScrollPositionType);
- position.Set(kJSPositionY, pp::Var(y / device_scale_));
- PostMessage(position);
-}
-
-void OutOfProcessInstance::ScrollToPage(int page) {
- if (engine_->GetNumberOfPages() == 0)
- return;
-
- pp::VarDictionary message;
- message.Set(kType, kJSGoToPageType);
- message.Set(kJSPageNumber, pp::Var(page));
- PostMessage(message);
-}
-
-void OutOfProcessInstance::NavigateTo(const std::string& url,
- bool open_in_new_tab) {
- std::string url_copy(url);
-
- // Empty |url_copy| is ok, and will effectively be a reload.
- // Skip the code below so an empty URL does not turn into "http://", which
- // will cause GURL to fail a DCHECK.
- if (!url_copy.empty()) {
- // If |url_copy| starts with '#', then it's for the same URL with a
- // different URL fragment.
- if (url_copy[0] == '#') {
- url_copy = url_ + url_copy;
- }
- // If there's no scheme, add http.
- if (url_copy.find("://") == std::string::npos &&
- url_copy.find("mailto:") == std::string::npos) {
- url_copy = std::string("http://") + url_copy;
- }
- // Make sure |url_copy| starts with a valid scheme.
- if (url_copy.find("http://") != 0 &&
- url_copy.find("https://") != 0 &&
- url_copy.find("ftp://") != 0 &&
- url_copy.find("file://") != 0 &&
- url_copy.find("mailto:") != 0) {
- return;
- }
- // Make sure |url_copy| is not only a scheme.
- if (url_copy == "http://" ||
- url_copy == "https://" ||
- url_copy == "ftp://" ||
- url_copy == "file://" ||
- url_copy == "mailto:") {
- return;
- }
- }
- pp::VarDictionary message;
- message.Set(kType, kJSNavigateType);
- message.Set(kJSNavigateUrl, url_copy);
- message.Set(kJSNavigateNewTab, open_in_new_tab);
- PostMessage(message);
-}
-
-void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) {
- if (cursor == cursor_)
- return;
- cursor_ = cursor;
-
- const PPB_CursorControl_Dev* cursor_interface =
- reinterpret_cast<const PPB_CursorControl_Dev*>(
- pp::Module::Get()->GetBrowserInterface(PPB_CURSOR_CONTROL_DEV_INTERFACE));
- if (!cursor_interface) {
- NOTREACHED();
- return;
- }
-
- cursor_interface->SetCursor(
- pp_instance(), cursor_, pp::ImageData().pp_resource(), NULL);
-}
-
-void OutOfProcessInstance::UpdateTickMarks(
- const std::vector<pp::Rect>& tickmarks) {
- float inverse_scale = 1.0f / device_scale_;
- std::vector<pp::Rect> scaled_tickmarks = tickmarks;
- for (size_t i = 0; i < scaled_tickmarks.size(); i++)
- ScaleRect(inverse_scale, &scaled_tickmarks[i]);
- tickmarks_ = scaled_tickmarks;
-}
-
-void OutOfProcessInstance::NotifyNumberOfFindResultsChanged(int total,
- bool final_result) {
- // We don't want to spam the renderer with too many updates to the number of
- // find results. Don't send an update if we sent one too recently. If it's the
- // final update, we always send it though.
- if (final_result) {
- NumberOfFindResultsChanged(total, final_result);
- SetTickmarks(tickmarks_);
- return;
- }
-
- if (recently_sent_find_update_)
- return;
-
- NumberOfFindResultsChanged(total, final_result);
- SetTickmarks(tickmarks_);
- recently_sent_find_update_ = true;
- pp::CompletionCallback callback =
- timer_factory_.NewCallback(
- &OutOfProcessInstance::ResetRecentlySentFindUpdate);
- pp::Module::Get()->core()->CallOnMainThread(kFindResultCooldownMs,
- callback, 0);
-}
-
-void OutOfProcessInstance::NotifySelectedFindResultChanged(
- int current_find_index) {
- SelectedFindResultChanged(current_find_index);
-}
-
-void OutOfProcessInstance::GetDocumentPassword(
- pp::CompletionCallbackWithOutput<pp::Var> callback) {
- if (password_callback_) {
- NOTREACHED();
- return;
- }
-
- password_callback_.reset(
- new pp::CompletionCallbackWithOutput<pp::Var>(callback));
- pp::VarDictionary message;
- message.Set(pp::Var(kType), pp::Var(kJSGetPasswordType));
- PostMessage(message);
-}
-
-void OutOfProcessInstance::Alert(const std::string& message) {
- ModalDialog(this, "alert", message, std::string());
-}
-
-bool OutOfProcessInstance::Confirm(const std::string& message) {
- pp::Var result = ModalDialog(this, "confirm", message, std::string());
- return result.is_bool() ? result.AsBool() : false;
-}
-
-std::string OutOfProcessInstance::Prompt(const std::string& question,
- const std::string& default_answer) {
- pp::Var result = ModalDialog(this, "prompt", question, default_answer);
- return result.is_string() ? result.AsString() : std::string();
-}
-
-std::string OutOfProcessInstance::GetURL() {
- return url_;
-}
-
-void OutOfProcessInstance::Email(const std::string& to,
- const std::string& cc,
- const std::string& bcc,
- const std::string& subject,
- const std::string& body) {
- pp::VarDictionary message;
- message.Set(pp::Var(kType), pp::Var(kJSEmailType));
- message.Set(pp::Var(kJSEmailTo),
- pp::Var(net::EscapeUrlEncodedData(to, false)));
- message.Set(pp::Var(kJSEmailCc),
- pp::Var(net::EscapeUrlEncodedData(cc, false)));
- message.Set(pp::Var(kJSEmailBcc),
- pp::Var(net::EscapeUrlEncodedData(bcc, false)));
- message.Set(pp::Var(kJSEmailSubject),
- pp::Var(net::EscapeUrlEncodedData(subject, false)));
- message.Set(pp::Var(kJSEmailBody),
- pp::Var(net::EscapeUrlEncodedData(body, false)));
- PostMessage(message);
-}
-
-void OutOfProcessInstance::Print() {
- if (!printing_enabled_ ||
- (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) &&
- !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY))) {
- return;
- }
-
- pp::CompletionCallback callback =
- print_callback_factory_.NewCallback(&OutOfProcessInstance::OnPrint);
- pp::Module::Get()->core()->CallOnMainThread(0, callback);
-}
-
-void OutOfProcessInstance::OnPrint(int32_t) {
- pp::PDF::Print(this);
-}
-
-void OutOfProcessInstance::SubmitForm(const std::string& url,
- const void* data,
- int length) {
- pp::URLRequestInfo request(this);
- request.SetURL(url);
- request.SetMethod("POST");
- request.AppendDataToBody(reinterpret_cast<const char*>(data), length);
-
- pp::CompletionCallback callback =
- form_factory_.NewCallback(&OutOfProcessInstance::FormDidOpen);
- form_loader_ = CreateURLLoaderInternal();
- int rv = form_loader_.Open(request, callback);
- if (rv != PP_OK_COMPLETIONPENDING)
- callback.Run(rv);
-}
-
-void OutOfProcessInstance::FormDidOpen(int32_t result) {
- // TODO: inform the user of success/failure.
- if (result != PP_OK) {
- NOTREACHED();
- }
-}
-
-std::string OutOfProcessInstance::ShowFileSelectionDialog() {
- // Seems like very low priority to implement, since the pdf has no way to get
- // the file data anyways. Javascript doesn't let you do this synchronously.
- NOTREACHED();
- return std::string();
-}
-
-pp::URLLoader OutOfProcessInstance::CreateURLLoader() {
- if (full_) {
- if (!did_call_start_loading_) {
- did_call_start_loading_ = true;
- pp::PDF::DidStartLoading(this);
- }
-
- // Disable save and print until the document is fully loaded, since they
- // would generate an incomplete document. Need to do this each time we
- // call DidStartLoading since that resets the content restrictions.
- pp::PDF::SetContentRestriction(this, CONTENT_RESTRICTION_SAVE |
- CONTENT_RESTRICTION_PRINT);
- }
-
- return CreateURLLoaderInternal();
-}
-
-void OutOfProcessInstance::ScheduleCallback(int id, int delay_in_ms) {
- pp::CompletionCallback callback =
- timer_factory_.NewCallback(&OutOfProcessInstance::OnClientTimerFired);
- pp::Module::Get()->core()->CallOnMainThread(delay_in_ms, callback, id);
-}
-
-void OutOfProcessInstance::SearchString(const base::char16* string,
- const base::char16* term,
- bool case_sensitive,
- std::vector<SearchStringResult>* results) {
- PP_PrivateFindResult* pp_results;
- int count = 0;
- pp::PDF::SearchString(
- this,
- reinterpret_cast<const unsigned short*>(string),
- reinterpret_cast<const unsigned short*>(term),
- case_sensitive,
- &pp_results,
- &count);
-
- results->resize(count);
- for (int i = 0; i < count; ++i) {
- (*results)[i].start_index = pp_results[i].start_index;
- (*results)[i].length = pp_results[i].length;
- }
-
- pp::Memory_Dev memory;
- memory.MemFree(pp_results);
-}
-
-void OutOfProcessInstance::DocumentPaintOccurred() {
-}
-
-void OutOfProcessInstance::DocumentLoadComplete(int page_count) {
- // Clear focus state for OSK.
- FormTextFieldFocusChange(false);
-
- DCHECK(document_load_state_ == LOAD_STATE_LOADING);
- document_load_state_ = LOAD_STATE_COMPLETE;
- UserMetricsRecordAction("PDF.LoadSuccess");
-
- // Note: If we are in print preview mode the scroll location is retained
- // across document loads so we don't want to scroll again and override it.
- if (IsPrintPreview()) {
- AppendBlankPrintPreviewPages();
- OnGeometryChanged(0, 0);
- }
-
- pp::VarDictionary message;
- message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType));
- message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)) ;
- PostMessage(message);
-
- if (!full_)
- return;
-
- if (did_call_start_loading_) {
- pp::PDF::DidStopLoading(this);
- did_call_start_loading_ = false;
- }
-
- int content_restrictions =
- CONTENT_RESTRICTION_CUT | CONTENT_RESTRICTION_PASTE;
- if (!engine_->HasPermission(PDFEngine::PERMISSION_COPY))
- content_restrictions |= CONTENT_RESTRICTION_COPY;
-
- if (!engine_->HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY) &&
- !engine_->HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY)) {
- printing_enabled_ = false;
- }
-
- pp::PDF::SetContentRestriction(this, content_restrictions);
-
- uma_.HistogramCustomCounts("PDF.PageCount", page_count,
- 1, 1000000, 50);
-}
-
-void OutOfProcessInstance::RotateClockwise() {
- engine_->RotateClockwise();
-}
-
-void OutOfProcessInstance::RotateCounterclockwise() {
- engine_->RotateCounterclockwise();
-}
-
-void OutOfProcessInstance::PreviewDocumentLoadComplete() {
- if (preview_document_load_state_ != LOAD_STATE_LOADING ||
- preview_pages_info_.empty()) {
- return;
- }
-
- preview_document_load_state_ = LOAD_STATE_COMPLETE;
-
- int dest_page_index = preview_pages_info_.front().second;
- int src_page_index =
- ExtractPrintPreviewPageIndex(preview_pages_info_.front().first);
- if (src_page_index > 0 && dest_page_index > -1 && preview_engine_.get())
- engine_->AppendPage(preview_engine_.get(), dest_page_index);
-
- preview_pages_info_.pop();
- // |print_preview_page_count_| is not updated yet. Do not load any
- // other preview pages till we get this information.
- if (print_preview_page_count_ == 0)
- return;
-
- if (preview_pages_info_.size())
- LoadAvailablePreviewPage();
-}
-
-void OutOfProcessInstance::DocumentLoadFailed() {
- DCHECK(document_load_state_ == LOAD_STATE_LOADING);
- UserMetricsRecordAction("PDF.LoadFailure");
-
- if (did_call_start_loading_) {
- pp::PDF::DidStopLoading(this);
- did_call_start_loading_ = false;
- }
-
- document_load_state_ = LOAD_STATE_FAILED;
- paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_));
-
- // Send a progress value of -1 to indicate a failure.
- pp::VarDictionary message;
- message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType));
- message.Set(pp::Var(kJSProgressPercentage), pp::Var(-1)) ;
- PostMessage(message);
-}
-
-void OutOfProcessInstance::PreviewDocumentLoadFailed() {
- UserMetricsRecordAction("PDF.PreviewDocumentLoadFailure");
- if (preview_document_load_state_ != LOAD_STATE_LOADING ||
- preview_pages_info_.empty()) {
- return;
- }
-
- preview_document_load_state_ = LOAD_STATE_FAILED;
- preview_pages_info_.pop();
-
- if (preview_pages_info_.size())
- LoadAvailablePreviewPage();
-}
-
-pp::Instance* OutOfProcessInstance::GetPluginInstance() {
- return this;
-}
-
-void OutOfProcessInstance::DocumentHasUnsupportedFeature(
- const std::string& feature) {
- std::string metric("PDF_Unsupported_");
- metric += feature;
- if (!unsupported_features_reported_.count(metric)) {
- unsupported_features_reported_.insert(metric);
- UserMetricsRecordAction(metric);
- }
-
- // Since we use an info bar, only do this for full frame plugins..
- if (!full_)
- return;
-
- if (told_browser_about_unsupported_feature_)
- return;
- told_browser_about_unsupported_feature_ = true;
-
- pp::PDF::HasUnsupportedFeature(this);
-}
-
-void OutOfProcessInstance::DocumentLoadProgress(uint32 available,
- uint32 doc_size) {
- double progress = 0.0;
- if (doc_size == 0) {
- // Document size is unknown. Use heuristics.
- // We'll make progress logarithmic from 0 to 100M.
- static const double kFactor = log(100000000.0) / 100.0;
- if (available > 0) {
- progress = log(static_cast<double>(available)) / kFactor;
- if (progress > 100.0)
- progress = 100.0;
- }
- } else {
- progress = 100.0 * static_cast<double>(available) / doc_size;
- }
-
- // We send 100% load progress in DocumentLoadComplete.
- if (progress >= 100)
- return;
-
- // Avoid sending too many progress messages over PostMessage.
- if (progress > last_progress_sent_ + 1) {
- last_progress_sent_ = progress;
- pp::VarDictionary message;
- message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType));
- message.Set(pp::Var(kJSProgressPercentage), pp::Var(progress)) ;
- PostMessage(message);
- }
-}
-
-void OutOfProcessInstance::FormTextFieldFocusChange(bool in_focus) {
- if (!text_input_.get())
- return;
- if (in_focus)
- text_input_->SetTextInputType(PP_TEXTINPUT_TYPE_DEV_TEXT);
- else
- text_input_->SetTextInputType(PP_TEXTINPUT_TYPE_DEV_NONE);
-}
-
-void OutOfProcessInstance::ResetRecentlySentFindUpdate(int32_t /* unused */) {
- recently_sent_find_update_ = false;
-}
-
-void OutOfProcessInstance::OnGeometryChanged(double old_zoom,
- float old_device_scale) {
- if (zoom_ != old_zoom || device_scale_ != old_device_scale)
- engine_->ZoomUpdated(zoom_ * device_scale_);
-
- available_area_ = pp::Rect(plugin_size_);
- int doc_width = GetDocumentPixelWidth();
- if (doc_width < available_area_.width()) {
- available_area_.Offset((available_area_.width() - doc_width) / 2, 0);
- available_area_.set_width(doc_width);
- }
- int doc_height = GetDocumentPixelHeight();
- if (doc_height < available_area_.height()) {
- available_area_.set_height(doc_height);
- }
-
- CalculateBackgroundParts();
- engine_->PageOffsetUpdated(available_area_.point());
- engine_->PluginSizeUpdated(available_area_.size());
-
- if (!document_size_.GetArea())
- return;
- paint_manager_.InvalidateRect(pp::Rect(pp::Point(), plugin_size_));
-}
-
-void OutOfProcessInstance::LoadUrl(const std::string& url) {
- LoadUrlInternal(url, &embed_loader_, &OutOfProcessInstance::DidOpen);
-}
-
-void OutOfProcessInstance::LoadPreviewUrl(const std::string& url) {
- LoadUrlInternal(url, &embed_preview_loader_,
- &OutOfProcessInstance::DidOpenPreview);
-}
-
-void OutOfProcessInstance::LoadUrlInternal(
- const std::string& url,
- pp::URLLoader* loader,
- void (OutOfProcessInstance::* method)(int32_t)) {
- pp::URLRequestInfo request(this);
- request.SetURL(url);
- request.SetMethod("GET");
-
- *loader = CreateURLLoaderInternal();
- pp::CompletionCallback callback = loader_factory_.NewCallback(method);
- int rv = loader->Open(request, callback);
- if (rv != PP_OK_COMPLETIONPENDING)
- callback.Run(rv);
-}
-
-pp::URLLoader OutOfProcessInstance::CreateURLLoaderInternal() {
- pp::URLLoader loader(this);
-
- const PPB_URLLoaderTrusted* trusted_interface =
- reinterpret_cast<const PPB_URLLoaderTrusted*>(
- pp::Module::Get()->GetBrowserInterface(
- PPB_URLLOADERTRUSTED_INTERFACE));
- if (trusted_interface)
- trusted_interface->GrantUniversalAccess(loader.pp_resource());
- return loader;
-}
-
-void OutOfProcessInstance::SetZoom(double scale) {
- double old_zoom = zoom_;
- zoom_ = scale;
- OnGeometryChanged(old_zoom, device_scale_);
-}
-
-std::string OutOfProcessInstance::GetLocalizedString(PP_ResourceString id) {
- pp::Var rv(pp::PDF::GetLocalizedString(this, id));
- if (!rv.is_string())
- return std::string();
-
- return rv.AsString();
-}
-
-void OutOfProcessInstance::AppendBlankPrintPreviewPages() {
- if (print_preview_page_count_ == 0)
- return;
- engine_->AppendBlankPages(print_preview_page_count_);
- if (preview_pages_info_.size() > 0)
- LoadAvailablePreviewPage();
-}
-
-bool OutOfProcessInstance::IsPrintPreview() {
- return IsPrintPreviewUrl(url_);
-}
-
-void OutOfProcessInstance::ProcessPreviewPageInfo(const std::string& url,
- int dst_page_index) {
- if (!IsPrintPreview())
- return;
-
- int src_page_index = ExtractPrintPreviewPageIndex(url);
- if (src_page_index < 1)
- return;
-
- preview_pages_info_.push(std::make_pair(url, dst_page_index));
- LoadAvailablePreviewPage();
-}
-
-void OutOfProcessInstance::LoadAvailablePreviewPage() {
- if (preview_pages_info_.size() <= 0 ||
- document_load_state_ != LOAD_STATE_COMPLETE) {
- return;
- }
-
- std::string url = preview_pages_info_.front().first;
- int dst_page_index = preview_pages_info_.front().second;
- int src_page_index = ExtractPrintPreviewPageIndex(url);
- if (src_page_index < 1 ||
- dst_page_index >= print_preview_page_count_ ||
- preview_document_load_state_ == LOAD_STATE_LOADING) {
- return;
- }
-
- preview_document_load_state_ = LOAD_STATE_LOADING;
- LoadPreviewUrl(url);
-}
-
-void OutOfProcessInstance::UserMetricsRecordAction(
- const std::string& action) {
- // TODO(raymes): Move this function to PPB_UMA_Private.
- pp::PDF::UserMetricsRecordAction(this, pp::Var(action));
-}
-
-pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument(
- const pp::Point& scroll_offset) {
- int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
- int x = std::max(std::min(scroll_offset.x(), max_x), 0);
- int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
- int y = std::max(std::min(scroll_offset.y(), max_y), 0);
- return pp::Point(x, y);
-}
-
-} // namespace chrome_pdf
diff --git a/xfa_test/pdf/out_of_process_instance.h b/xfa_test/pdf/out_of_process_instance.h
deleted file mode 100644
index 355f050dc3..0000000000
--- a/xfa_test/pdf/out_of_process_instance.h
+++ /dev/null
@@ -1,345 +0,0 @@
-// 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.
-
-#ifndef PDF_OUT_OF_PROCESS_INSTANCE_H_
-#define PDF_OUT_OF_PROCESS_INSTANCE_H_
-
-#include <queue>
-#include <set>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "base/memory/scoped_ptr.h"
-#include "pdf/paint_manager.h"
-#include "pdf/pdf_engine.h"
-#include "pdf/preview_mode_client.h"
-
-#include "ppapi/c/private/ppb_pdf.h"
-#include "ppapi/cpp/dev/printing_dev.h"
-#include "ppapi/cpp/dev/scriptable_object_deprecated.h"
-#include "ppapi/cpp/dev/selection_dev.h"
-#include "ppapi/cpp/graphics_2d.h"
-#include "ppapi/cpp/image_data.h"
-#include "ppapi/cpp/input_event.h"
-#include "ppapi/cpp/instance.h"
-#include "ppapi/cpp/private/find_private.h"
-#include "ppapi/cpp/private/uma_private.h"
-#include "ppapi/cpp/url_loader.h"
-#include "ppapi/utility/completion_callback_factory.h"
-
-namespace pp {
-class TextInput_Dev;
-}
-
-namespace chrome_pdf {
-
-class OutOfProcessInstance : public pp::Instance,
- public pp::Find_Private,
- public pp::Printing_Dev,
- public pp::Selection_Dev,
- public PaintManager::Client,
- public PDFEngine::Client,
- public PreviewModeClient::Client {
- public:
- explicit OutOfProcessInstance(PP_Instance instance);
- virtual ~OutOfProcessInstance();
-
- // pp::Instance implementation.
- virtual bool Init(uint32_t argc,
- const char* argn[],
- const char* argv[]) override;
- virtual void HandleMessage(const pp::Var& message) override;
- virtual bool HandleInputEvent(const pp::InputEvent& event) override;
- virtual void DidChangeView(const pp::View& view) override;
-
- // pp::Find_Private implementation.
- virtual bool StartFind(const std::string& text, bool case_sensitive) override;
- virtual void SelectFindResult(bool forward) override;
- virtual void StopFind() override;
-
- // pp::PaintManager::Client implementation.
- virtual void OnPaint(const std::vector<pp::Rect>& paint_rects,
- std::vector<PaintManager::ReadyRect>* ready,
- std::vector<pp::Rect>* pending) override;
-
- // pp::Printing_Dev implementation.
- virtual uint32_t QuerySupportedPrintOutputFormats() override;
- virtual int32_t PrintBegin(
- const PP_PrintSettings_Dev& print_settings) override;
- virtual pp::Resource PrintPages(
- const PP_PrintPageNumberRange_Dev* page_ranges,
- uint32_t page_range_count) override;
- virtual void PrintEnd() override;
- virtual bool IsPrintScalingDisabled() override;
-
- // pp::Private implementation.
- virtual pp::Var GetLinkAtPosition(const pp::Point& point);
-
- // PPP_Selection_Dev implementation.
- virtual pp::Var GetSelectedText(bool html) override;
-
- void FlushCallback(int32_t result);
- void DidOpen(int32_t result);
- void DidOpenPreview(int32_t result);
-
- // Called when the timer is fired.
- void OnClientTimerFired(int32_t id);
-
- // Called to print without re-entrancy issues.
- void OnPrint(int32_t);
-
- // PDFEngine::Client implementation.
- virtual void DocumentSizeUpdated(const pp::Size& size);
- virtual void Invalidate(const pp::Rect& rect);
- virtual void Scroll(const pp::Point& point);
- virtual void ScrollToX(int position);
- virtual void ScrollToY(int position);
- virtual void ScrollToPage(int page);
- virtual void NavigateTo(const std::string& url, bool open_in_new_tab);
- virtual void UpdateCursor(PP_CursorType_Dev cursor);
- virtual void UpdateTickMarks(const std::vector<pp::Rect>& tickmarks);
- virtual void NotifyNumberOfFindResultsChanged(int total, bool final_result);
- virtual void NotifySelectedFindResultChanged(int current_find_index);
- virtual void GetDocumentPassword(
- pp::CompletionCallbackWithOutput<pp::Var> callback);
- virtual void Alert(const std::string& message);
- virtual bool Confirm(const std::string& message);
- virtual std::string Prompt(const std::string& question,
- const std::string& default_answer);
- virtual std::string GetURL();
- virtual void Email(const std::string& to,
- const std::string& cc,
- const std::string& bcc,
- const std::string& subject,
- const std::string& body);
- virtual void Print();
- virtual void SubmitForm(const std::string& url,
- const void* data,
- int length);
- virtual std::string ShowFileSelectionDialog();
- virtual pp::URLLoader CreateURLLoader();
- virtual void ScheduleCallback(int id, int delay_in_ms);
- virtual void SearchString(const base::char16* string,
- const base::char16* term,
- bool case_sensitive,
- std::vector<SearchStringResult>* results);
- virtual void DocumentPaintOccurred();
- virtual void DocumentLoadComplete(int page_count);
- virtual void DocumentLoadFailed();
- virtual pp::Instance* GetPluginInstance();
- virtual void DocumentHasUnsupportedFeature(const std::string& feature);
- virtual void DocumentLoadProgress(uint32 available, uint32 doc_size);
- virtual void FormTextFieldFocusChange(bool in_focus);
- virtual bool IsPrintPreview();
-
- // PreviewModeClient::Client implementation.
- virtual void PreviewDocumentLoadComplete() override;
- virtual void PreviewDocumentLoadFailed() override;
-
- // Helper functions for implementing PPP_PDF.
- void RotateClockwise();
- void RotateCounterclockwise();
-
- private:
- void ResetRecentlySentFindUpdate(int32_t);
-
- // Called whenever the plugin geometry changes to update the location of the
- // background parts, and notifies the pdf engine.
- void OnGeometryChanged(double old_zoom, float old_device_scale);
-
- // Figures out the location of any background rectangles (i.e. those that
- // aren't painted by the PDF engine).
- void CalculateBackgroundParts();
-
- // Computes document width/height in device pixels, based on current zoom and
- // device scale
- int GetDocumentPixelWidth() const;
- int GetDocumentPixelHeight() const;
-
- // Draws a rectangle with the specified dimensions and color in our buffer.
- void FillRect(const pp::Rect& rect, uint32 color);
-
- void LoadUrl(const std::string& url);
- void LoadPreviewUrl(const std::string& url);
- void LoadUrlInternal(const std::string& url, pp::URLLoader* loader,
- void (OutOfProcessInstance::* method)(int32_t));
-
- // Creates a URL loader and allows it to access all urls, i.e. not just the
- // frame's origin.
- pp::URLLoader CreateURLLoaderInternal();
-
- // Figure out the initial page to display based on #page=N and #nameddest=foo
- // in the |url_|.
- // Returns -1 if there is no valid fragment. The returned value is 0-based,
- // whereas page=N is 1-based.
- int GetInitialPage(const std::string& url);
-
- void FormDidOpen(int32_t result);
-
- std::string GetLocalizedString(PP_ResourceString id);
-
- void UserMetricsRecordAction(const std::string& action);
-
- enum DocumentLoadState {
- LOAD_STATE_LOADING,
- LOAD_STATE_COMPLETE,
- LOAD_STATE_FAILED,
- };
-
- // Set new zoom scale.
- void SetZoom(double scale);
-
- // Reduces the document to 1 page and appends |print_preview_page_count_|
- // blank pages to the document for print preview.
- void AppendBlankPrintPreviewPages();
-
- // Process the preview page data information. |src_url| specifies the preview
- // page data location. The |src_url| is in the format:
- // chrome://print/id/page_number/print.pdf
- // |dst_page_index| specifies the blank page index that needs to be replaced
- // with the new page data.
- void ProcessPreviewPageInfo(const std::string& src_url, int dst_page_index);
- // Load the next available preview page into the blank page.
- void LoadAvailablePreviewPage();
-
- // Bound the given scroll offset to the document.
- pp::Point BoundScrollOffsetToDocument(const pp::Point& scroll_offset);
-
- pp::ImageData image_data_;
- // Used when the plugin is embedded in a page and we have to create the loader
- // ourself.
- pp::CompletionCallbackFactory<OutOfProcessInstance> loader_factory_;
- pp::URLLoader embed_loader_;
- pp::URLLoader embed_preview_loader_;
-
- PP_CursorType_Dev cursor_; // The current cursor.
-
- pp::CompletionCallbackFactory<OutOfProcessInstance> timer_factory_;
-
- // Size, in pixels, of plugin rectangle.
- pp::Size plugin_size_;
- // Size, in DIPs, of plugin rectangle.
- pp::Size plugin_dip_size_;
- // Remaining area, in pixels, to render the pdf in after accounting for
- // horizontal centering.
- pp::Rect available_area_;
- // Size of entire document in pixels (i.e. if each page is 800 pixels high and
- // there are 10 pages, the height will be 8000).
- pp::Size document_size_;
-
- double zoom_; // Current zoom factor.
-
- float device_scale_; // Current device scale factor.
- bool printing_enabled_;
- // True if the plugin is full-page.
- bool full_;
-
- PaintManager paint_manager_;
-
- struct BackgroundPart {
- pp::Rect location;
- uint32 color;
- };
- std::vector<BackgroundPart> background_parts_;
-
- struct PrintSettings {
- PrintSettings() {
- Clear();
- }
- void Clear() {
- is_printing = false;
- print_pages_called_ = false;
- memset(&pepper_print_settings, 0, sizeof(pepper_print_settings));
- }
- // This is set to true when PrintBegin is called and false when PrintEnd is
- // called.
- bool is_printing;
- // To know whether this was an actual print operation, so we don't double
- // count UMA logging.
- bool print_pages_called_;
- PP_PrintSettings_Dev pepper_print_settings;
- };
-
- PrintSettings print_settings_;
-
- scoped_ptr<PDFEngine> engine_;
-
- // This engine is used to render the individual preview page data. This is
- // used only in print preview mode. This will use |PreviewModeClient|
- // interface which has very limited access to the pp::Instance.
- scoped_ptr<PDFEngine> preview_engine_;
-
- std::string url_;
-
- // Used for submitting forms.
- pp::CompletionCallbackFactory<OutOfProcessInstance> form_factory_;
- pp::URLLoader form_loader_;
-
- // Used for printing without re-entrancy issues.
- pp::CompletionCallbackFactory<OutOfProcessInstance> print_callback_factory_;
-
- // True if we haven't painted the plugin viewport yet.
- bool first_paint_;
-
- DocumentLoadState document_load_state_;
- DocumentLoadState preview_document_load_state_;
-
- // A UMA resource for histogram reporting.
- pp::UMAPrivate uma_;
-
- // Used so that we only tell the browser once about an unsupported feature, to
- // avoid the infobar going up more than once.
- bool told_browser_about_unsupported_feature_;
-
- // Keeps track of which unsupported features we reported, so we avoid spamming
- // the stats if a feature shows up many times per document.
- std::set<std::string> unsupported_features_reported_;
-
- // Number of pages in print preview mode, 0 if not in print preview mode.
- int print_preview_page_count_;
- std::vector<int> print_preview_page_numbers_;
-
- // Used to manage loaded print preview page information. A |PreviewPageInfo|
- // consists of data source url string and the page index in the destination
- // document.
- typedef std::pair<std::string, int> PreviewPageInfo;
- std::queue<PreviewPageInfo> preview_pages_info_;
-
- // Used to signal the browser about focus changes to trigger the OSK.
- // TODO(abodenha@chromium.org) Implement full IME support in the plugin.
- // http://crbug.com/132565
- scoped_ptr<pp::TextInput_Dev> text_input_;
-
- // The last document load progress value sent to the web page.
- double last_progress_sent_;
-
- // Whether an update to the number of find results found was sent less than
- // |kFindResultCooldownMs| milliseconds ago.
- bool recently_sent_find_update_;
-
- // The tickmarks.
- std::vector<pp::Rect> tickmarks_;
-
- // Whether the plugin has received a viewport changed message. Nothing should
- // be painted until this is received.
- bool received_viewport_message_;
-
- // If true, this means we told the RenderView that we're starting a network
- // request so that it can start the throbber. We will tell it again once the
- // document finishes loading.
- bool did_call_start_loading_;
-
- // If this is true, then don't scroll the plugin in response to DidChangeView
- // messages. This will be true when the extension page is in the process of
- // zooming the plugin so that flickering doesn't occur while zooming.
- bool stop_scrolling_;
-
- // The callback for receiving the password from the page.
- scoped_ptr<pp::CompletionCallbackWithOutput<pp::Var> > password_callback_;
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_OUT_OF_PROCESS_INSTANCE_H_
diff --git a/xfa_test/pdf/page_indicator.cc b/xfa_test/pdf/page_indicator.cc
deleted file mode 100644
index c4af1e07b7..0000000000
--- a/xfa_test/pdf/page_indicator.cc
+++ /dev/null
@@ -1,127 +0,0 @@
-// 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 "pdf/page_indicator.h"
-
-#include "base/logging.h"
-#include "base/strings/string_util.h"
-#include "pdf/draw_utils.h"
-#include "pdf/number_image_generator.h"
-#include "pdf/resource_consts.h"
-
-namespace chrome_pdf {
-
-
-PageIndicator::PageIndicator()
- : current_page_(0),
- fade_out_timer_id_(0),
- splash_timeout_(kPageIndicatorSplashTimeoutMs),
- fade_timeout_(kPageIndicatorScrollFadeTimeoutMs),
- always_visible_(false) {
-}
-
-PageIndicator::~PageIndicator() {
-}
-
-bool PageIndicator::CreatePageIndicator(
- uint32 id,
- bool visible,
- Control::Owner* delegate,
- NumberImageGenerator* number_image_generator,
- bool always_visible) {
- number_image_generator_ = number_image_generator;
- always_visible_ = always_visible;
-
- pp::Rect rc;
- bool res = Control::Create(id, rc, visible, delegate);
- return res;
-}
-
-void PageIndicator::Configure(const pp::Point& origin,
- const pp::ImageData& background) {
- background_ = background;
- pp::Rect rc(origin, background_.size());
- Control::SetRect(rc, false);
-}
-
-void PageIndicator::set_current_page(int current_page) {
- if (current_page_ < 0)
- return;
-
- current_page_ = current_page;
-}
-
-void PageIndicator::Paint(pp::ImageData* image_data, const pp::Rect& rc) {
- if (!visible())
- return;
-
- pp::Rect draw_rc = rc.Intersect(rect());
- if (draw_rc.IsEmpty())
- return;
-
- // Copying the background image to a temporary buffer.
- pp::ImageData buffer(owner()->GetInstance(), background_.format(),
- background_.size(), false);
- CopyImage(background_, pp::Rect(background_.size()),
- &buffer, pp::Rect(background_.size()), false);
-
- // Creating the page number image.
- pp::ImageData page_number_image;
- number_image_generator_->GenerateImage(current_page_, &page_number_image);
-
- pp::Point origin2(
- (buffer.size().width() - page_number_image.size().width()) / 2.5,
- (buffer.size().height() - page_number_image.size().height()) / 2);
-
- // Drawing page number image on the buffer.
- if (origin2.x() > 0 && origin2.y() > 0) {
- CopyImage(page_number_image,
- pp::Rect(pp::Point(), page_number_image.size()),
- &buffer,
- pp::Rect(origin2, page_number_image.size()),
- false);
- }
-
- // Drawing the buffer.
- pp::Point origin = draw_rc.point();
- draw_rc.Offset(-rect().x(), -rect().y());
- AlphaBlend(buffer, draw_rc, image_data, origin, transparency());
-}
-
-void PageIndicator::OnTimerFired(uint32 timer_id) {
- FadingControl::OnTimerFired(timer_id);
- if (timer_id == fade_out_timer_id_) {
- Fade(false, fade_timeout_);
- }
-}
-
-void PageIndicator::ResetFadeOutTimer() {
- fade_out_timer_id_ =
- owner()->ScheduleTimer(id(), splash_timeout_);
-}
-
-void PageIndicator::OnFadeInComplete() {
- if (!always_visible_)
- ResetFadeOutTimer();
-}
-
-void PageIndicator::Splash() {
- Splash(kPageIndicatorSplashTimeoutMs, kPageIndicatorScrollFadeTimeoutMs);
-}
-
-void PageIndicator::Splash(uint32 splash_timeout, uint32 fade_timeout) {
- splash_timeout_ = splash_timeout;
- fade_timeout_ = fade_timeout;
- if (!always_visible_)
- fade_out_timer_id_ = 0;
- Fade(true, fade_timeout_);
-}
-
-int PageIndicator::GetYPosition(
- int vertical_scrollbar_y, int document_height, int plugin_height) {
- double percent = static_cast<double>(vertical_scrollbar_y) / document_height;
- return (plugin_height - rect().height()) * percent;
-}
-
-} // namespace chrome_pdf
diff --git a/xfa_test/pdf/page_indicator.h b/xfa_test/pdf/page_indicator.h
deleted file mode 100644
index 0d06ee1a0b..0000000000
--- a/xfa_test/pdf/page_indicator.h
+++ /dev/null
@@ -1,72 +0,0 @@
-// 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.
-
-#ifndef PDF_PAGE_INDICATOR_H_
-#define PDF_PAGE_INDICATOR_H_
-
-#include <string>
-#include <vector>
-
-#include "pdf/control.h"
-#include "pdf/fading_control.h"
-#include "ppapi/cpp/image_data.h"
-#include "ppapi/cpp/point.h"
-#include "ppapi/cpp/rect.h"
-
-namespace chrome_pdf {
-
-class NumberImageGenerator;
-
-const uint32 kPageIndicatorScrollFadeTimeoutMs = 240;
-const uint32 kPageIndicatorInitialFadeTimeoutMs = 960;
-const uint32 kPageIndicatorSplashTimeoutMs = 2000;
-
-class PageIndicator : public FadingControl {
- public:
- PageIndicator();
- virtual ~PageIndicator();
- virtual bool CreatePageIndicator(
- uint32 id,
- bool visible,
- Control::Owner* delegate,
- NumberImageGenerator* number_image_generator,
- bool always_visible);
-
- void Configure(const pp::Point& origin, const pp::ImageData& background);
-
- int current_page() const { return current_page_; }
- void set_current_page(int current_page);
-
- virtual void Splash();
- void Splash(uint32 splash_timeout, uint32 page_timeout);
-
- // Returns the y position where the page indicator should be drawn given the
- // position of the scrollbar and the total document height and the plugin
- // height.
- int GetYPosition(
- int vertical_scrollbar_y, int document_height, int plugin_height);
-
- // Control interface.
- virtual void Paint(pp::ImageData* image_data, const pp::Rect& rc);
- virtual void OnTimerFired(uint32 timer_id);
-
- // FadingControl interface.
- virtual void OnFadeInComplete();
-
- private:
- void ResetFadeOutTimer();
-
- int current_page_;
- pp::ImageData background_;
- NumberImageGenerator* number_image_generator_;
- uint32 fade_out_timer_id_;
- uint32 splash_timeout_;
- uint32 fade_timeout_;
-
- bool always_visible_;
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_PAGE_INDICATOR_H_
diff --git a/xfa_test/pdf/paint_aggregator.cc b/xfa_test/pdf/paint_aggregator.cc
deleted file mode 100644
index 549cab6d09..0000000000
--- a/xfa_test/pdf/paint_aggregator.cc
+++ /dev/null
@@ -1,263 +0,0 @@
-// Copyright (c) 2010 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 "pdf/paint_aggregator.h"
-
-#include <algorithm>
-
-#include "base/logging.h"
-
-// ----------------------------------------------------------------------------
-// ALGORITHM NOTES
-//
-// We attempt to maintain a scroll rect in the presence of invalidations that
-// are contained within the scroll rect. If an invalidation crosses a scroll
-// rect, then we just treat the scroll rect as an invalidation rect.
-//
-// For invalidations performed prior to scrolling and contained within the
-// scroll rect, we offset the invalidation rects to account for the fact that
-// the consumer will perform scrolling before painting.
-//
-// We only support scrolling along one axis at a time. A diagonal scroll will
-// therefore be treated as an invalidation.
-// ----------------------------------------------------------------------------
-
-PaintAggregator::PaintUpdate::PaintUpdate() {
-}
-
-PaintAggregator::PaintUpdate::~PaintUpdate() {
-}
-
-PaintAggregator::InternalPaintUpdate::InternalPaintUpdate() :
- synthesized_scroll_damage_rect_(false) {
-}
-
-PaintAggregator::InternalPaintUpdate::~InternalPaintUpdate() {
-}
-
-pp::Rect PaintAggregator::InternalPaintUpdate::GetScrollDamage() const {
- // Should only be scrolling in one direction at a time.
- DCHECK(!(scroll_delta.x() && scroll_delta.y()));
-
- pp::Rect damaged_rect;
-
- // Compute the region we will expose by scrolling, and paint that into a
- // shared memory section.
- if (scroll_delta.x()) {
- int32_t dx = scroll_delta.x();
- damaged_rect.set_y(scroll_rect.y());
- damaged_rect.set_height(scroll_rect.height());
- if (dx > 0) {
- damaged_rect.set_x(scroll_rect.x());
- damaged_rect.set_width(dx);
- } else {
- damaged_rect.set_x(scroll_rect.right() + dx);
- damaged_rect.set_width(-dx);
- }
- } else {
- int32_t dy = scroll_delta.y();
- damaged_rect.set_x(scroll_rect.x());
- damaged_rect.set_width(scroll_rect.width());
- if (dy > 0) {
- damaged_rect.set_y(scroll_rect.y());
- damaged_rect.set_height(dy);
- } else {
- damaged_rect.set_y(scroll_rect.bottom() + dy);
- damaged_rect.set_height(-dy);
- }
- }
-
- // In case the scroll offset exceeds the width/height of the scroll rect
- return scroll_rect.Intersect(damaged_rect);
-}
-
-PaintAggregator::PaintAggregator() {
-}
-
-bool PaintAggregator::HasPendingUpdate() const {
- return !update_.scroll_rect.IsEmpty() || !update_.paint_rects.empty();
-}
-
-void PaintAggregator::ClearPendingUpdate() {
- update_ = InternalPaintUpdate();
-}
-
-PaintAggregator::PaintUpdate PaintAggregator::GetPendingUpdate() {
- // Convert the internal paint update to the external one, which includes a
- // bit more precomputed info for the caller.
- PaintUpdate ret;
- ret.scroll_delta = update_.scroll_delta;
- ret.scroll_rect = update_.scroll_rect;
- ret.has_scroll = ret.scroll_delta.x() != 0 || ret.scroll_delta.y() != 0;
-
- // Include the scroll damage (if any) in the paint rects.
- // Code invalidates damaged rect here, it pick it up from the list of paint
- // rects in the next block.
- if (ret.has_scroll && !update_.synthesized_scroll_damage_rect_) {
- update_.synthesized_scroll_damage_rect_ = true;
- pp::Rect scroll_damage = update_.GetScrollDamage();
- InvalidateRectInternal(scroll_damage, false);
- }
-
- ret.paint_rects.reserve(update_.paint_rects.size() + 1);
- for (size_t i = 0; i < update_.paint_rects.size(); i++)
- ret.paint_rects.push_back(update_.paint_rects[i]);
-
- return ret;
-}
-
-void PaintAggregator::SetIntermediateResults(
- const std::vector<ReadyRect>& ready,
- const std::vector<pp::Rect>& pending) {
- update_.ready_rects.insert(
- update_.ready_rects.end(), ready.begin(), ready.end());
- update_.paint_rects = pending;
-}
-
-std::vector<PaintAggregator::ReadyRect> PaintAggregator::GetReadyRects() const {
- return update_.ready_rects;
-}
-
-void PaintAggregator::InvalidateRect(const pp::Rect& rect) {
- InvalidateRectInternal(rect, true);
-}
-
-void PaintAggregator::ScrollRect(const pp::Rect& clip_rect,
- const pp::Point& amount) {
- // We only support scrolling along one axis at a time.
- if (amount.x() != 0 && amount.y() != 0) {
- InvalidateRect(clip_rect);
- return;
- }
-
- // We can only scroll one rect at a time.
- if (!update_.scroll_rect.IsEmpty() && update_.scroll_rect != clip_rect) {
- InvalidateRect(clip_rect);
- return;
- }
-
- // Again, we only support scrolling along one axis at a time. Make sure this
- // update doesn't scroll on a different axis than any existing one.
- if ((amount.x() && update_.scroll_delta.y()) ||
- (amount.y() && update_.scroll_delta.x())) {
- InvalidateRect(clip_rect);
- return;
- }
-
- // The scroll rect is new or isn't changing (though the scroll amount may
- // be changing).
- update_.scroll_rect = clip_rect;
- update_.scroll_delta += amount;
-
- // We might have just wiped out a pre-existing scroll.
- if (update_.scroll_delta == pp::Point()) {
- update_.scroll_rect = pp::Rect();
- return;
- }
-
- // Adjust any paint rects that intersect the scroll. For the portion of the
- // paint that is inside the scroll area, move it by the scroll amount and
- // replace the existing paint with it. For the portion (if any) that is
- // outside the scroll, just invalidate it.
- std::vector<pp::Rect> leftover_rects;
- for (size_t i = 0; i < update_.paint_rects.size(); ++i) {
- if (!update_.scroll_rect.Intersects(update_.paint_rects[i]))
- continue;
-
- pp::Rect intersection =
- update_.paint_rects[i].Intersect(update_.scroll_rect);
- pp::Rect rect = update_.paint_rects[i];
- while (!rect.IsEmpty()) {
- pp::Rect leftover = rect.Subtract(intersection);
- if (leftover.IsEmpty())
- break;
- // Don't want to call InvalidateRectInternal now since it'll modify
- // update_.paint_rects, so keep track of this and do it below.
- leftover_rects.push_back(leftover);
- rect = rect.Subtract(leftover);
- }
-
- update_.paint_rects[i] = ScrollPaintRect(intersection, amount);
-
- // The rect may have been scrolled out of view.
- if (update_.paint_rects[i].IsEmpty()) {
- update_.paint_rects.erase(update_.paint_rects.begin() + i);
- i--;
- }
- }
-
- for (size_t i = 0; i < leftover_rects.size(); ++i)
- InvalidateRectInternal(leftover_rects[i], false);
-
- for (size_t i = 0; i < update_.ready_rects.size(); ++i) {
- if (update_.scroll_rect.Contains(update_.ready_rects[i].rect)) {
- update_.ready_rects[i].rect =
- ScrollPaintRect(update_.ready_rects[i].rect, amount);
- }
- }
-
- if (update_.synthesized_scroll_damage_rect_) {
- pp::Rect damage = update_.GetScrollDamage();
- InvalidateRect(damage);
- }
-}
-
-pp::Rect PaintAggregator::ScrollPaintRect(const pp::Rect& paint_rect,
- const pp::Point& amount) const {
- pp::Rect result = paint_rect;
- result.Offset(amount);
- result = update_.scroll_rect.Intersect(result);
- return result;
-}
-
-void PaintAggregator::InvalidateScrollRect() {
- pp::Rect scroll_rect = update_.scroll_rect;
- update_.scroll_rect = pp::Rect();
- update_.scroll_delta = pp::Point();
- InvalidateRect(scroll_rect);
-}
-
-void PaintAggregator::InvalidateRectInternal(const pp::Rect& rect_old,
- bool check_scroll) {
- pp::Rect rect = rect_old;
- // Check if any rects that are ready to be painted overlap.
- for (size_t i = 0; i < update_.ready_rects.size(); ++i) {
- const pp::Rect& existing_rect = update_.ready_rects[i].rect;
- if (rect.Intersects(existing_rect)) {
- // Re-invalidate in case the union intersects other paint rects.
- rect = existing_rect.Union(rect);
- update_.ready_rects.erase(update_.ready_rects.begin() + i);
- break;
- }
- }
-
- bool add_paint = true;
-
- // Combine overlapping paints using smallest bounding box.
- for (size_t i = 0; i < update_.paint_rects.size(); ++i) {
- const pp::Rect& existing_rect = update_.paint_rects[i];
- if (existing_rect.Contains(rect)) // Optimize out redundancy.
- add_paint = false;
- if (rect.Intersects(existing_rect) || rect.SharesEdgeWith(existing_rect)) {
- // Re-invalidate in case the union intersects other paint rects.
- pp::Rect combined_rect = existing_rect.Union(rect);
- update_.paint_rects.erase(update_.paint_rects.begin() + i);
- InvalidateRectInternal(combined_rect, check_scroll);
- add_paint = false;
- }
- }
-
- if (add_paint) {
- // Add a non-overlapping paint.
- update_.paint_rects.push_back(rect);
- }
-
- // If the new paint overlaps with a scroll, then also invalidate the rect in
- // its new position.
- if (check_scroll &&
- !update_.scroll_rect.IsEmpty() &&
- update_.scroll_rect.Intersects(rect)) {
- InvalidateRectInternal(ScrollPaintRect(rect, update_.scroll_delta), false);
- }
-}
diff --git a/xfa_test/pdf/paint_aggregator.h b/xfa_test/pdf/paint_aggregator.h
deleted file mode 100644
index 96f61e0878..0000000000
--- a/xfa_test/pdf/paint_aggregator.h
+++ /dev/null
@@ -1,130 +0,0 @@
-// Copyright (c) 2010 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.
-
-#ifndef PDF_PAINT_AGGREGATOR_H_
-#define PDF_PAINT_AGGREGATOR_H_
-
-#include <vector>
-
-#include "ppapi/cpp/image_data.h"
-#include "ppapi/cpp/rect.h"
-#include "ppapi/cpp/rect.h"
-
-// This class is responsible for aggregating multiple invalidation and scroll
-// commands to produce a scroll and repaint sequence. You can use this manually
-// to track your updates, but most applications will use the PaintManager to
-// additionally handle the necessary callbacks on top of the PaintAggregator
-// functionality.
-//
-// See http://code.google.com/p/ppapi/wiki/2DPaintingModel
-class PaintAggregator {
- public:
- // Stores information about a rectangle that has finished painting. The
- // PaintManager will paint it only when everything else on the screen is also
- // ready.
- struct ReadyRect {
- pp::Point offset;
- pp::Rect rect;
- pp::ImageData image_data;
- };
-
- struct PaintUpdate {
- PaintUpdate();
- ~PaintUpdate();
-
- // True if there is a scroll applied. This indicates that the scroll delta
- // and scroll_rect are nonzero (just as a convenience).
- bool has_scroll;
-
- // The amount to scroll by. Either the X or Y may be nonzero to indicate a
- // scroll in that direction, but there will never be a scroll in both
- // directions at the same time (this will be converted to a paint of the
- // region instead).
- //
- // If there is no scroll, this will be (0, 0).
- pp::Point scroll_delta;
-
- // The rectangle that should be scrolled by the scroll_delta. If there is no
- // scroll, this will be (0, 0, 0, 0). We only track one scroll command at
- // once. If there are multiple ones, they will be converted to invalidates.
- pp::Rect scroll_rect;
-
- // A list of all the individual dirty rectangles. This is an aggregated list
- // of all invalidate calls. Different rectangles may be unified to produce a
- // minimal list with no overlap that is more efficient to paint. This list
- // also contains the region exposed by any scroll command.
- std::vector<pp::Rect> paint_rects;
- };
-
- PaintAggregator();
-
- // There is a PendingUpdate if InvalidateRect or ScrollRect were called and
- // ClearPendingUpdate was not called.
- bool HasPendingUpdate() const;
- void ClearPendingUpdate();
-
- PaintUpdate GetPendingUpdate();
-
- // Sets the result of a call to the plugin to paint. This includes rects that
- // are finished painting (ready), and ones that are still in-progress
- // (pending).
- void SetIntermediateResults(const std::vector<ReadyRect>& ready,
- const std::vector<pp::Rect>& pending);
-
- // Returns the rectangles that are ready to be painted.
- std::vector<ReadyRect> GetReadyRects() const;
-
- // The given rect should be repainted.
- void InvalidateRect(const pp::Rect& rect);
-
- // The given rect should be scrolled by the given amounts.
- void ScrollRect(const pp::Rect& clip_rect, const pp::Point& amount);
-
- private:
- // This structure is an internal version of PaintUpdate. It's different in
- // two respects:
- //
- // - The scroll damange (area exposed by the scroll operation, if any) is
- // maintained separately from the dirty rects generated by calling
- // InvalidateRect. We need to know this distinction for some operations.
- //
- // - The paint bounds union is computed on the fly so we don't have to keep
- // a rectangle up-to-date as we do different operations.
- class InternalPaintUpdate {
- public:
- InternalPaintUpdate();
- ~InternalPaintUpdate();
-
- // Computes the rect damaged by scrolling within |scroll_rect| by
- // |scroll_delta|. This rect must be repainted. It is not included in
- // paint_rects.
- pp::Rect GetScrollDamage() const;
-
- pp::Point scroll_delta;
- pp::Rect scroll_rect;
-
- // Does not include the scroll damage rect unless
- // synthesized_scroll_damage_rect_ is set.
- std::vector<pp::Rect> paint_rects;
-
- // Rectangles that are finished painting.
- std::vector<ReadyRect> ready_rects;
-
- // Whether we have added the scroll damage rect to paint_rects yet or not.
- bool synthesized_scroll_damage_rect_;
- };
-
- pp::Rect ScrollPaintRect(const pp::Rect& paint_rect,
- const pp::Point& amount) const;
- void InvalidateScrollRect();
-
- // Internal method used by InvalidateRect. If |check_scroll| is true, then the
- // method checks if there's a pending scroll and if so also invalidates |rect|
- // in the new scroll position.
- void InvalidateRectInternal(const pp::Rect& rect, bool check_scroll);
-
- InternalPaintUpdate update_;
-};
-
-#endif // PDF_PAINT_AGGREGATOR_H_
diff --git a/xfa_test/pdf/paint_manager.cc b/xfa_test/pdf/paint_manager.cc
deleted file mode 100644
index f452b37186..0000000000
--- a/xfa_test/pdf/paint_manager.cc
+++ /dev/null
@@ -1,302 +0,0 @@
-// Copyright (c) 2010 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 "pdf/paint_manager.h"
-
-#include <algorithm>
-
-#include "base/logging.h"
-#include "ppapi/c/pp_errors.h"
-#include "ppapi/cpp/instance.h"
-#include "ppapi/cpp/module.h"
-
-PaintManager::PaintManager(pp::Instance* instance,
- Client* client,
- bool is_always_opaque)
- : instance_(instance),
- client_(client),
- is_always_opaque_(is_always_opaque),
- callback_factory_(NULL),
- manual_callback_pending_(false),
- flush_pending_(false),
- has_pending_resize_(false),
- graphics_need_to_be_bound_(false),
- pending_device_scale_(1.0),
- device_scale_(1.0),
- in_paint_(false),
- first_paint_(true),
- view_size_changed_waiting_for_paint_(false) {
- // Set the callback object outside of the initializer list to avoid a
- // compiler warning about using "this" in an initializer list.
- callback_factory_.Initialize(this);
-
- // You can not use a NULL client pointer.
- DCHECK(client);
-}
-
-PaintManager::~PaintManager() {
-}
-
-// static
-pp::Size PaintManager::GetNewContextSize(const pp::Size& current_context_size,
- const pp::Size& plugin_size) {
- // The amount of additional space in pixels to allocate to the right/bottom of
- // the context.
- const int kBufferSize = 50;
-
- // Default to returning the same size.
- pp::Size result = current_context_size;
-
- // The minimum size of the plugin before resizing the context to ensure we
- // aren't wasting too much memory. We deduct twice the kBufferSize from the
- // current context size which gives a threshhold that is kBufferSize below
- // the plugin size when the context size was last computed.
- pp::Size min_size(
- std::max(current_context_size.width() - 2 * kBufferSize, 0),
- std::max(current_context_size.height() - 2 * kBufferSize, 0));
-
- // If the plugin size is bigger than the current context size, we need to
- // resize the context. If the plugin size is smaller than the current
- // context size by a given threshhold then resize the context so that we
- // aren't wasting too much memory.
- if (plugin_size.width() > current_context_size.width() ||
- plugin_size.height() > current_context_size.height() ||
- plugin_size.width() < min_size.width() ||
- plugin_size.height() < min_size.height()) {
- // Create a larger context than needed so that if we only resize by a
- // small margin, we don't need a new context.
- result = pp::Size(plugin_size.width() + kBufferSize,
- plugin_size.height() + kBufferSize);
- }
-
- return result;
-}
-
-void PaintManager::Initialize(pp::Instance* instance,
- Client* client,
- bool is_always_opaque) {
- DCHECK(!instance_ && !client_); // Can't initialize twice.
- instance_ = instance;
- client_ = client;
- is_always_opaque_ = is_always_opaque;
-}
-
-void PaintManager::SetSize(const pp::Size& new_size, float device_scale) {
- if (GetEffectiveSize() == new_size &&
- GetEffectiveDeviceScale() == device_scale)
- return;
-
- has_pending_resize_ = true;
- pending_size_ = new_size;
- pending_device_scale_ = device_scale;
-
- view_size_changed_waiting_for_paint_ = true;
-
- Invalidate();
-}
-
-void PaintManager::Invalidate() {
- // You must call SetSize before using.
- DCHECK(!graphics_.is_null() || has_pending_resize_);
-
- EnsureCallbackPending();
- aggregator_.InvalidateRect(pp::Rect(GetEffectiveSize()));
-}
-
-void PaintManager::InvalidateRect(const pp::Rect& rect) {
- DCHECK(!in_paint_);
-
- // You must call SetSize before using.
- DCHECK(!graphics_.is_null() || has_pending_resize_);
-
- // Clip the rect to the device area.
- pp::Rect clipped_rect = rect.Intersect(pp::Rect(GetEffectiveSize()));
- if (clipped_rect.IsEmpty())
- return; // Nothing to do.
-
- EnsureCallbackPending();
- aggregator_.InvalidateRect(clipped_rect);
-}
-
-void PaintManager::ScrollRect(const pp::Rect& clip_rect,
- const pp::Point& amount) {
- DCHECK(!in_paint_);
-
- // You must call SetSize before using.
- DCHECK(!graphics_.is_null() || has_pending_resize_);
-
- EnsureCallbackPending();
-
- aggregator_.ScrollRect(clip_rect, amount);
-}
-
-pp::Size PaintManager::GetEffectiveSize() const {
- return has_pending_resize_ ? pending_size_ : plugin_size_;
-}
-
-float PaintManager::GetEffectiveDeviceScale() const {
- return has_pending_resize_ ? pending_device_scale_ : device_scale_;
-}
-
-void PaintManager::EnsureCallbackPending() {
- // The best way for us to do the next update is to get a notification that
- // a previous one has completed. So if we're already waiting for one, we
- // don't have to do anything differently now.
- if (flush_pending_)
- return;
-
- // If no flush is pending, we need to do a manual call to get back to the
- // main thread. We may have one already pending, or we may need to schedule.
- if (manual_callback_pending_)
- return;
-
- pp::Module::Get()->core()->CallOnMainThread(
- 0,
- callback_factory_.NewCallback(&PaintManager::OnManualCallbackComplete),
- 0);
- manual_callback_pending_ = true;
-}
-
-void PaintManager::DoPaint() {
- in_paint_ = true;
-
- std::vector<ReadyRect> ready;
- std::vector<pp::Rect> pending;
-
- DCHECK(aggregator_.HasPendingUpdate());
-
- // Apply any pending resize. Setting the graphics to this class must happen
- // before asking the plugin to paint in case it requests invalides or resizes.
- // However, the bind must not happen until afterward since we don't want to
- // have an unpainted device bound. The needs_binding flag tells us whether to
- // do this later.
- if (has_pending_resize_) {
- plugin_size_ = pending_size_;
- // Only create a new graphics context if the current context isn't big
- // enough or if it is far too big. This avoids creating a new context if
- // we only resize by a small amount.
- pp::Size new_size = GetNewContextSize(graphics_.size(), pending_size_);
- if (graphics_.size() != new_size) {
- graphics_ = pp::Graphics2D(instance_, new_size, is_always_opaque_);
- graphics_need_to_be_bound_ = true;
-
- // Since we're binding a new one, all of the callbacks have been canceled.
- manual_callback_pending_ = false;
- flush_pending_ = false;
- callback_factory_.CancelAll();
- }
-
- if (pending_device_scale_ != 1.0)
- graphics_.SetScale(1.0 / pending_device_scale_);
- device_scale_ = pending_device_scale_;
-
- // This must be cleared before calling into the plugin since it may do
- // additional invalidation or sizing operations.
- has_pending_resize_ = false;
- pending_size_ = pp::Size();
- }
-
- PaintAggregator::PaintUpdate update = aggregator_.GetPendingUpdate();
- client_->OnPaint(update.paint_rects, &ready, &pending);
-
- if (ready.empty() && pending.empty()) {
- in_paint_ = false;
- return; // Nothing was painted, don't schedule a flush.
- }
-
- std::vector<PaintAggregator::ReadyRect> ready_now;
- if (pending.empty()) {
- std::vector<PaintAggregator::ReadyRect> temp_ready;
- for (size_t i = 0; i < ready.size(); ++i)
- temp_ready.push_back(ready[i]);
- aggregator_.SetIntermediateResults(temp_ready, pending);
- ready_now = aggregator_.GetReadyRects();
- aggregator_.ClearPendingUpdate();
-
- // Apply any scroll first.
- if (update.has_scroll)
- graphics_.Scroll(update.scroll_rect, update.scroll_delta);
-
- view_size_changed_waiting_for_paint_ = false;
- } else {
- std::vector<PaintAggregator::ReadyRect> ready_later;
- for (size_t i = 0; i < ready.size(); ++i) {
- // Don't flush any part (i.e. scrollbars) if we're resizing the browser,
- // as that'll lead to flashes. Until we flush, the browser will use the
- // previous image, but if we flush, it'll revert to using the blank image.
- // We make an exception for the first paint since we want to show the
- // default background color instead of the pepper default of black.
- if (ready[i].flush_now &&
- (!view_size_changed_waiting_for_paint_ || first_paint_)) {
- ready_now.push_back(ready[i]);
- } else {
- ready_later.push_back(ready[i]);
- }
- }
- // Take the rectangles, except the ones that need to be flushed right away,
- // and save them so that everything is flushed at once.
- aggregator_.SetIntermediateResults(ready_later, pending);
-
- if (ready_now.empty()) {
- in_paint_ = false;
- EnsureCallbackPending();
- return;
- }
- }
-
- for (size_t i = 0; i < ready_now.size(); ++i) {
- graphics_.PaintImageData(
- ready_now[i].image_data, ready_now[i].offset, ready_now[i].rect);
- }
-
- int32_t result = graphics_.Flush(
- callback_factory_.NewCallback(&PaintManager::OnFlushComplete));
-
- // If you trigger this assertion, then your plugin has called Flush()
- // manually. When using the PaintManager, you should not call Flush, it will
- // handle that for you because it needs to know when it can do the next paint
- // by implementing the flush callback.
- //
- // Another possible cause of this assertion is re-using devices. If you
- // use one device, swap it with another, then swap it back, we won't know
- // that we've already scheduled a Flush on the first device. It's best to not
- // re-use devices in this way.
- DCHECK(result != PP_ERROR_INPROGRESS);
-
- if (result == PP_OK_COMPLETIONPENDING) {
- flush_pending_ = true;
- } else {
- DCHECK(result == PP_OK); // Catch all other errors in debug mode.
- }
-
- in_paint_ = false;
- first_paint_ = false;
-
- if (graphics_need_to_be_bound_) {
- instance_->BindGraphics(graphics_);
- graphics_need_to_be_bound_ = false;
- }
-}
-
-void PaintManager::OnFlushComplete(int32_t) {
- DCHECK(flush_pending_);
- flush_pending_ = false;
-
- // If more paints were enqueued while we were waiting for the flush to
- // complete, execute them now.
- if (aggregator_.HasPendingUpdate())
- DoPaint();
-}
-
-void PaintManager::OnManualCallbackComplete(int32_t) {
- DCHECK(manual_callback_pending_);
- manual_callback_pending_ = false;
-
- // Just because we have a manual callback doesn't mean there are actually any
- // invalid regions. Even though we only schedule this callback when something
- // is pending, a Flush callback could have come in before this callback was
- // executed and that could have cleared the queue.
- if (aggregator_.HasPendingUpdate())
- DoPaint();
-}
diff --git a/xfa_test/pdf/paint_manager.h b/xfa_test/pdf/paint_manager.h
deleted file mode 100644
index 7755eb6829..0000000000
--- a/xfa_test/pdf/paint_manager.h
+++ /dev/null
@@ -1,205 +0,0 @@
-// Copyright (c) 2010 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.
-
-#ifndef PDF_PAINT_MANAGER_H_
-#define PDF_PAINT_MANAGER_H_
-
-#include <vector>
-
-#include "pdf/paint_aggregator.h"
-#include "ppapi/cpp/graphics_2d.h"
-#include "ppapi/utility/completion_callback_factory.h"
-
-namespace pp {
-class Graphics2D;
-class Instance;
-class Point;
-class Rect;
-};
-
-// Custom PaintManager for the PDF plugin. This is branched from the Pepper
-// version. The difference is that this supports progressive rendering of dirty
-// rects, where multiple calls to the rendering engine are needed. It also
-// supports having higher-priority rects flushing right away, i.e. the
-// scrollbars.
-//
-// The client's OnPaint
-class PaintManager {
- public:
- // Like PaintAggregator's version, but allows the plugin to tell us whether
- // it should be flushed to the screen immediately or when the rest of the
- // plugin viewport is ready.
- struct ReadyRect {
- pp::Point offset;
- pp::Rect rect;
- pp::ImageData image_data;
- bool flush_now;
-
- ReadyRect(const pp::Rect& r, const pp::ImageData& i, bool f)
- : rect(r), image_data(i), flush_now(f) {}
-
- operator PaintAggregator::ReadyRect() const {
- PaintAggregator::ReadyRect rv;
- rv.offset = offset;
- rv.rect = rect;
- rv.image_data = image_data;
- return rv;
- }
- };
- class Client {
- public:
- // Paints the given invalid area of the plugin to the given graphics
- // device. Returns true if anything was painted.
- //
- // You are given the list of rects to paint in |paint_rects|. You can
- // combine painting into less rectangles if it's more efficient. When a
- // rect is painted, information about that paint should be inserted into
- // |ready|. Otherwise if a paint needs more work, add the rect to
- // |pending|. If |pending| is not empty, your OnPaint function will get
- // called again. Once OnPaint is called and it returns no pending rects,
- // all the previously ready rects will be flushed on screen. The exception
- // is for ready rects that have |flush_now| set to true. These will be
- // flushed right away.
- //
- // Do not call Flush() on the graphics device, this will be done
- // automatically if you return true from this function since the
- // PaintManager needs to handle the callback.
- //
- // Calling Invalidate/Scroll is not allowed while inside an OnPaint
- virtual void OnPaint(const std::vector<pp::Rect>& paint_rects,
- std::vector<ReadyRect>* ready,
- std::vector<pp::Rect>* pending) = 0;
- protected:
- // You shouldn't be doing deleting through this interface.
- virtual ~Client() {}
- };
-
- // The instance is the plugin instance using this paint manager to do its
- // painting. Painting will automatically go to this instance and you don't
- // have to manually bind any device context (this is all handled by the
- // paint manager).
- //
- // The Client is a non-owning pointer and must remain valid (normally the
- // object implementing the Client interface will own the paint manager).
- //
- // The is_always_opaque flag will be passed to the device contexts that this
- // class creates. Set this to true if your plugin always draws an opaque
- // image to the device. This is used as a hint to the browser that it does
- // not need to do alpha blending, which speeds up painting. If you generate
- // non-opqaue pixels or aren't sure, set this to false for more general
- // blending.
- //
- // If you set is_always_opaque, your alpha channel should always be set to
- // 0xFF or there may be painting artifacts. Being opaque will allow the
- // browser to do a memcpy rather than a blend to paint the plugin, and this
- // means your alpha values will get set on the page backing store. If these
- // values are incorrect, it could mess up future blending. If you aren't
- // sure, it is always correct to specify that it it not opaque.
- //
- // You will need to call SetSize before this class will do anything. Normally
- // you do this from the ViewChanged method of your plugin instance.
- PaintManager(pp::Instance* instance, Client* client, bool is_always_opaque);
-
- ~PaintManager();
-
- // Returns the size of the graphics context to allocate for a given plugin
- // size. We may allocated a slightly larger buffer than required so that we
- // don't have to resize the context when scrollbars appear/dissapear due to
- // zooming (which can result in flickering).
- static pp::Size GetNewContextSize(const pp::Size& current_context_size,
- const pp::Size& plugin_size);
-
- // You must call this function before using if you use the 0-arg constructor.
- // See the constructor for what these arguments mean.
- void Initialize(pp::Instance* instance, Client* client,
- bool is_always_opaque);
-
- // Sets the size of the plugin. If the size is the same as the previous call,
- // this will be a NOP. If the size has changed, a new device will be
- // allocated to the given size and a paint to that device will be scheduled.
- //
- // This is intended to be called from ViewChanged with the size of the
- // plugin. Since it tracks the old size and only allocates when the size
- // changes, you can always call this function without worrying about whether
- // the size changed or ViewChanged is called for another reason (like the
- // position changed).
- void SetSize(const pp::Size& new_size, float new_device_scale);
-
- // Invalidate the entire plugin.
- void Invalidate();
-
- // Invalidate the given rect.
- void InvalidateRect(const pp::Rect& rect);
-
- // The given rect should be scrolled by the given amounts.
- void ScrollRect(const pp::Rect& clip_rect, const pp::Point& amount);
-
- // Returns the size of the graphics context for the next paint operation.
- // This is the pending size if a resize is pending (the plugin has called
- // SetSize but we haven't actually painted it yet), or the current size of
- // no resize is pending.
- pp::Size GetEffectiveSize() const;
- float GetEffectiveDeviceScale() const;
-
- private:
- // Disallow copy and assign (these are unimplemented).
- PaintManager(const PaintManager&);
- PaintManager& operator=(const PaintManager&);
-
- // Makes sure there is a callback that will trigger a paint at a later time.
- // This will be either a Flush callback telling us we're allowed to generate
- // more data, or, if there's no flush callback pending, a manual call back
- // to the message loop via ExecuteOnMainThread.
- void EnsureCallbackPending();
-
- // Does the client paint and executes a Flush if necessary.
- void DoPaint();
-
- // Callback for asynchronous completion of Flush.
- void OnFlushComplete(int32_t);
-
- // Callback for manual scheduling of paints when there is no flush callback
- // pending.
- void OnManualCallbackComplete(int32_t);
-
- pp::Instance* instance_;
-
- // Non-owning pointer. See the constructor.
- Client* client_;
-
- bool is_always_opaque_;
-
- pp::CompletionCallbackFactory<PaintManager> callback_factory_;
-
- // This graphics device will be is_null() if no graphics has been manually
- // set yet.
- pp::Graphics2D graphics_;
-
- PaintAggregator aggregator_;
-
- // See comment for EnsureCallbackPending for more on how these work.
- bool manual_callback_pending_;
- bool flush_pending_;
-
- // When we get a resize, we don't bind right away (see SetSize). The
- // has_pending_resize_ tells us that we need to do a resize for the next
- // paint operation. When true, the new size is in pending_size_.
- bool has_pending_resize_;
- bool graphics_need_to_be_bound_;
- pp::Size pending_size_;
- pp::Size plugin_size_;
- float pending_device_scale_;
- float device_scale_;
-
- // True iff we're in the middle of a paint.
- bool in_paint_;
-
- // True if we haven't painted the plugin viewport yet.
- bool first_paint_;
-
- // True when the view size just changed and we're waiting for a paint.
- bool view_size_changed_waiting_for_paint_;
-};
-
-#endif // PDF_PAINT_MANAGER_H_
diff --git a/xfa_test/pdf/pdf.cc b/xfa_test/pdf/pdf.cc
deleted file mode 100644
index 6a4507f4fc..0000000000
--- a/xfa_test/pdf/pdf.cc
+++ /dev/null
@@ -1,275 +0,0 @@
-// Copyright (c) 2010 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 "pdf/pdf.h"
-
-#if defined(OS_WIN)
-#include <windows.h>
-#endif
-
-#include "base/command_line.h"
-#include "base/logging.h"
-#include "pdf/instance.h"
-#include "pdf/out_of_process_instance.h"
-#include "ppapi/c/ppp.h"
-#include "ppapi/cpp/private/pdf.h"
-
-bool g_sdk_initialized_via_pepper = false;
-
-// The Mac release builds discard CreateModule and the entire PDFModule
-// definition because they are not referenced here. This causes the Pepper
-// exports (PPP_GetInterface etc) to not be exported. So we force the linker
-// to include this code by using __attribute__((used)).
-#if __GNUC__ >= 4
-#define PDF_USED __attribute__((used))
-#else
-#define PDF_USED
-#endif
-
-#if defined(OS_WIN)
-HMODULE g_hmodule;
-
-void HandleInvalidParameter(const wchar_t* expression,
- const wchar_t* function,
- const wchar_t* file,
- unsigned int line,
- uintptr_t reserved) {
- // Do the same as Chrome's CHECK(false) which is undefined.
- ::base::debug::BreakDebugger();
- return;
-}
-
-void HandlePureVirtualCall() {
- // Do the same as Chrome's CHECK(false) which is undefined.
- ::base::debug::BreakDebugger();
- return;
-}
-
-
-BOOL APIENTRY DllMain(HMODULE module, DWORD reason_for_call, LPVOID reserved) {
- g_hmodule = module;
- if (reason_for_call == DLL_PROCESS_ATTACH) {
- // On windows following handlers work only inside module. So breakpad in
- // chrome.dll does not catch that. To avoid linking related code or
- // duplication breakpad_win.cc::InitCrashReporter() just catch errors here
- // and crash in a way interceptable by breakpad of parent module.
- _set_invalid_parameter_handler(HandleInvalidParameter);
- _set_purecall_handler(HandlePureVirtualCall);
- }
- return TRUE;
-}
-
-#endif
-
-namespace pp {
-
-PDF_USED Module* CreateModule() {
- return new chrome_pdf::PDFModule();
-}
-
-} // namespace pp
-
-namespace chrome_pdf {
-
-PDFModule::PDFModule() {
-}
-
-PDFModule::~PDFModule() {
- if (g_sdk_initialized_via_pepper) {
- chrome_pdf::ShutdownSDK();
- g_sdk_initialized_via_pepper = false;
- }
-}
-
-bool PDFModule::Init() {
- return true;
-}
-
-pp::Instance* PDFModule::CreateInstance(PP_Instance instance) {
- if (!g_sdk_initialized_via_pepper) {
- void* data = NULL;
-#if defined(OS_WIN)
- data = g_hmodule;
-#endif
- if (!chrome_pdf::InitializeSDK(data))
- return NULL;
- g_sdk_initialized_via_pepper = true;
- }
-
- if (pp::PDF::IsOutOfProcess(pp::InstanceHandle(instance)))
- return new OutOfProcessInstance(instance);
- return new Instance(instance);
-}
-
-} // namespace chrome_pdf
-
-extern "C" {
-
-// TODO(sanjeevr): It might make sense to provide more stateful wrappers over
-// the internal PDF SDK (such as LoadDocument, LoadPage etc). Determine if we
-// need to provide this.
-// Wrapper exports over the PDF engine that can be used by an external module
-// such as Chrome (since Chrome cannot directly pull in PDFium sources).
-#if defined(OS_WIN)
-// |pdf_buffer| is the buffer that contains the entire PDF document to be
-// rendered.
-// |buffer_size| is the size of |pdf_buffer| in bytes.
-// |page_number| is the 0-based index of the page to be rendered.
-// |dc| is the device context to render into.
-// |dpi_x| and |dpi_y| are the x and y resolutions respectively. If either
-// value is -1, the dpi from the DC will be used.
-// |bounds_origin_x|, |bounds_origin_y|, |bounds_width| and |bounds_height|
-// specify a bounds rectangle within the DC in which to render the PDF
-// page.
-// |fit_to_bounds| specifies whether the output should be shrunk to fit the
-// supplied bounds if the page size is larger than the bounds in any
-// dimension. If this is false, parts of the PDF page that lie outside
-// the bounds will be clipped.
-// |stretch_to_bounds| specifies whether the output should be stretched to fit
-// the supplied bounds if the page size is smaller than the bounds in any
-// dimension.
-// If both |fit_to_bounds| and |stretch_to_bounds| are true, then
-// |fit_to_bounds| is honored first.
-// |keep_aspect_ratio| If any scaling is to be done is true, this flag
-// specifies whether the original aspect ratio of the page should be
-// preserved while scaling.
-// |center_in_bounds| specifies whether the final image (after any scaling is
-// done) should be centered within the given bounds.
-// |autorotate| specifies whether the final image should be rotated to match
-// the output bound.
-// Returns false if the document or the page number are not valid.
-PP_EXPORT bool RenderPDFPageToDC(const void* pdf_buffer,
- int buffer_size,
- int page_number,
- HDC dc,
- int dpi_x,
- int dpi_y,
- int bounds_origin_x,
- int bounds_origin_y,
- int bounds_width,
- int bounds_height,
- bool fit_to_bounds,
- bool stretch_to_bounds,
- bool keep_aspect_ratio,
- bool center_in_bounds,
- bool autorotate) {
- if (!g_sdk_initialized_via_pepper) {
- if (!chrome_pdf::InitializeSDK(g_hmodule)) {
- return false;
- }
- }
- scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports(
- chrome_pdf::PDFEngineExports::Create());
- chrome_pdf::PDFEngineExports::RenderingSettings settings(
- dpi_x, dpi_y, pp::Rect(bounds_origin_x, bounds_origin_y, bounds_width,
- bounds_height),
- fit_to_bounds, stretch_to_bounds, keep_aspect_ratio, center_in_bounds,
- autorotate);
- bool ret = engine_exports->RenderPDFPageToDC(pdf_buffer, buffer_size,
- page_number, settings, dc);
- if (!g_sdk_initialized_via_pepper) {
- chrome_pdf::ShutdownSDK();
- }
- return ret;
-}
-
-#endif // OS_WIN
-
-// |page_count| and |max_page_width| are optional and can be NULL.
-// Returns false if the document is not valid.
-PDF_USED PP_EXPORT
-bool GetPDFDocInfo(const void* pdf_buffer,
- int buffer_size, int* page_count,
- double* max_page_width) {
- if (!g_sdk_initialized_via_pepper) {
- void* data = NULL;
-#if defined(OS_WIN)
- data = g_hmodule;
-#endif
- if (!chrome_pdf::InitializeSDK(data))
- return false;
- }
- scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports(
- chrome_pdf::PDFEngineExports::Create());
- bool ret = engine_exports->GetPDFDocInfo(
- pdf_buffer, buffer_size, page_count, max_page_width);
- if (!g_sdk_initialized_via_pepper) {
- chrome_pdf::ShutdownSDK();
- }
- return ret;
-}
-
-// Gets the dimensions of a specific page in a document.
-// |pdf_buffer| is the buffer that contains the entire PDF document to be
-// rendered.
-// |pdf_buffer_size| is the size of |pdf_buffer| in bytes.
-// |page_number| is the page number that the function will get the dimensions
-// of.
-// |width| is the output for the width of the page in points.
-// |height| is the output for the height of the page in points.
-// Returns false if the document or the page number are not valid.
-PDF_USED PP_EXPORT
-bool GetPDFPageSizeByIndex(const void* pdf_buffer,
- int pdf_buffer_size, int page_number,
- double* width, double* height) {
- if (!g_sdk_initialized_via_pepper) {
- void* data = NULL;
-#if defined(OS_WIN)
- data = g_hmodule;
-#endif
- if (!chrome_pdf::InitializeSDK(data))
- return false;
- }
- scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports(
- chrome_pdf::PDFEngineExports::Create());
- bool ret = engine_exports->GetPDFPageSizeByIndex(
- pdf_buffer, pdf_buffer_size, page_number, width, height);
- if (!g_sdk_initialized_via_pepper)
- chrome_pdf::ShutdownSDK();
- return ret;
-}
-
-// Renders PDF page into 4-byte per pixel BGRA color bitmap.
-// |pdf_buffer| is the buffer that contains the entire PDF document to be
-// rendered.
-// |pdf_buffer_size| is the size of |pdf_buffer| in bytes.
-// |page_number| is the 0-based index of the page to be rendered.
-// |bitmap_buffer| is the output buffer for bitmap.
-// |bitmap_width| is the width of the output bitmap.
-// |bitmap_height| is the height of the output bitmap.
-// |dpi| is the resolutions.
-// |autorotate| specifies whether the final image should be rotated to match
-// the output bound.
-// Returns false if the document or the page number are not valid.
-PDF_USED PP_EXPORT
-bool RenderPDFPageToBitmap(const void* pdf_buffer,
- int pdf_buffer_size,
- int page_number,
- void* bitmap_buffer,
- int bitmap_width,
- int bitmap_height,
- int dpi,
- bool autorotate) {
- if (!g_sdk_initialized_via_pepper) {
- void* data = NULL;
-#if defined(OS_WIN)
- data = g_hmodule;
-#endif
- if (!chrome_pdf::InitializeSDK(data))
- return false;
- }
- scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports(
- chrome_pdf::PDFEngineExports::Create());
- chrome_pdf::PDFEngineExports::RenderingSettings settings(
- dpi, dpi, pp::Rect(bitmap_width, bitmap_height), true, false, true, true,
- autorotate);
- bool ret = engine_exports->RenderPDFPageToBitmap(
- pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer);
- if (!g_sdk_initialized_via_pepper) {
- chrome_pdf::ShutdownSDK();
- }
- return ret;
-}
-
-} // extern "C"
diff --git a/xfa_test/pdf/pdf.def b/xfa_test/pdf/pdf.def
deleted file mode 100644
index b36918bb27..0000000000
--- a/xfa_test/pdf/pdf.def
+++ /dev/null
@@ -1,7 +0,0 @@
-LIBRARY pdf
-
-EXPORTS
- NP_GetEntryPoints @1
- NP_Initialize @2
- NP_Shutdown @3
-
diff --git a/xfa_test/pdf/pdf.gyp b/xfa_test/pdf/pdf.gyp
deleted file mode 100644
index f1e8e3e658..0000000000
--- a/xfa_test/pdf/pdf.gyp
+++ /dev/null
@@ -1,200 +0,0 @@
-{
- 'variables': {
- 'chromium_code': 1,
- 'pdf_engine%': 0, # 0 PDFium
- },
- 'target_defaults': {
- 'cflags': [
- '-fPIC',
- ],
- },
- 'targets': [
- {
- 'target_name': 'pdf',
- 'type': 'loadable_module',
- 'msvs_guid': '647863C0-C7A3-469A-B1ED-AD7283C34BED',
- 'dependencies': [
- '../base/base.gyp:base',
- '../net/net.gyp:net',
- '../ppapi/ppapi.gyp:ppapi_cpp',
- '../third_party/pdfium/pdfium.gyp:pdfium',
- ],
- 'xcode_settings': {
- 'INFOPLIST_FILE': 'Info.plist',
- },
- 'mac_framework_dirs': [
- '$(SDKROOT)/System/Library/Frameworks/ApplicationServices.framework/Frameworks',
- ],
- 'ldflags': [ '-L<(PRODUCT_DIR)',],
- 'sources': [
- 'button.h',
- 'button.cc',
- 'chunk_stream.h',
- 'chunk_stream.cc',
- 'control.h',
- 'control.cc',
- 'document_loader.h',
- 'document_loader.cc',
- 'draw_utils.cc',
- 'draw_utils.h',
- 'fading_control.cc',
- 'fading_control.h',
- 'fading_controls.cc',
- 'fading_controls.h',
- 'instance.cc',
- 'instance.h',
- 'number_image_generator.cc',
- 'number_image_generator.h',
- 'out_of_process_instance.cc',
- 'out_of_process_instance.h',
- 'page_indicator.cc',
- 'page_indicator.h',
- 'paint_aggregator.cc',
- 'paint_aggregator.h',
- 'paint_manager.cc',
- 'paint_manager.h',
- 'pdf.cc',
- 'pdf.h',
- 'pdf.rc',
- 'progress_control.cc',
- 'progress_control.h',
- 'pdf_engine.h',
- 'preview_mode_client.cc',
- 'preview_mode_client.h',
- 'resource.h',
- 'resource_consts.h',
- 'thumbnail_control.cc',
- 'thumbnail_control.h',
- '../chrome/browser/chrome_page_zoom_constants.cc',
- '../content/common/page_zoom.cc',
- ],
- 'conditions': [
- ['pdf_engine==0', {
- 'sources': [
- 'pdfium/pdfium_assert_matching_enums.cc',
- 'pdfium/pdfium_engine.cc',
- 'pdfium/pdfium_engine.h',
- 'pdfium/pdfium_mem_buffer_file_read.cc',
- 'pdfium/pdfium_mem_buffer_file_read.h',
- 'pdfium/pdfium_mem_buffer_file_write.cc',
- 'pdfium/pdfium_mem_buffer_file_write.h',
- 'pdfium/pdfium_page.cc',
- 'pdfium/pdfium_page.h',
- 'pdfium/pdfium_range.cc',
- 'pdfium/pdfium_range.h',
- ],
- }],
- ['OS!="win"', {
- 'sources!': [
- 'pdf.rc',
- ],
- }],
- ['OS=="mac"', {
- 'mac_bundle': 1,
- 'product_name': 'PDF',
- 'product_extension': 'plugin',
- # Strip the shipping binary of symbols so "Foxit" doesn't appear in
- # the binary. Symbols are stored in a separate .dSYM.
- 'variables': {
- 'mac_real_dsym': 1,
- },
- 'sources+': [
- 'Info.plist'
- ],
- }],
- ['OS=="win"', {
- 'defines': [
- 'COMPILE_CONTENT_STATICALLY',
- ],
- # TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
- 'msvs_disabled_warnings': [ 4267, ],
- }],
- ['OS=="linux"', {
- 'configurations': {
- 'Release_Base': {
- #'cflags': [ '-fno-weak',], # get rid of symbols that strip doesn't remove.
- # Don't do this for now since official builder will take care of it. That
- # way symbols can still be uploaded to the crash server.
- #'ldflags': [ '-s',], # strip local symbols from binary.
- },
- },
- }],
- ],
- },
- ],
- 'conditions': [
- # CrOS has a separate step to do this.
- ['OS=="linux" and chromeos==0',
- { 'targets': [
- {
- 'target_name': 'pdf_linux_symbols',
- 'type': 'none',
- 'conditions': [
- ['linux_dump_symbols==1', {
- 'actions': [
- {
- 'action_name': 'dump_symbols',
- 'inputs': [
- '<(DEPTH)/build/linux/dump_app_syms',
- '<(PRODUCT_DIR)/dump_syms',
- '<(PRODUCT_DIR)/libpdf.so',
- ],
- 'outputs': [
- '<(PRODUCT_DIR)/libpdf.so.breakpad.<(target_arch)',
- ],
- 'action': ['<(DEPTH)/build/linux/dump_app_syms',
- '<(PRODUCT_DIR)/dump_syms',
- '<(linux_strip_binary)',
- '<(PRODUCT_DIR)/libpdf.so',
- '<@(_outputs)'],
- 'message': 'Dumping breakpad symbols to <(_outputs)',
- 'process_outputs_as_sources': 1,
- },
- ],
- 'dependencies': [
- 'pdf',
- '../breakpad/breakpad.gyp:dump_syms',
- ],
- }],
- ],
- },
- ],
- },], # OS=="linux" and chromeos==0
- ['OS=="win" and fastbuild==0 and target_arch=="ia32" and syzyasan==1', {
- 'variables': {
- 'dest_dir': '<(PRODUCT_DIR)/syzygy',
- },
- 'targets': [
- {
- 'target_name': 'pdf_syzyasan',
- 'type': 'none',
- 'sources' : [],
- 'dependencies': [
- 'pdf',
- ],
- # Instrument PDFium with SyzyAsan.
- 'actions': [
- {
- 'action_name': 'Instrument PDFium with SyzyAsan',
- 'inputs': [
- '<(PRODUCT_DIR)/pdf.dll',
- ],
- 'outputs': [
- '<(dest_dir)/pdf.dll',
- '<(dest_dir)/pdf.dll.pdb',
- ],
- 'action': [
- 'python',
- '<(DEPTH)/chrome/tools/build/win/syzygy_instrument.py',
- '--mode', 'asan',
- '--input_executable', '<(PRODUCT_DIR)/pdf.dll',
- '--input_symbol', '<(PRODUCT_DIR)/pdf.dll.pdb',
- '--destination_dir', '<(dest_dir)',
- ],
- },
- ],
- },
- ],
- }], # OS=="win" and fastbuild==0 and target_arch=="ia32" and syzyasan==1
- ],
-}
diff --git a/xfa_test/pdf/pdf.h b/xfa_test/pdf/pdf.h
deleted file mode 100644
index d797bbbaf5..0000000000
--- a/xfa_test/pdf/pdf.h
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (c) 2010 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.
-
-#ifndef PDF_PDF_H_
-#define PDF_PDF_H_
-
-#include "ppapi/cpp/module.h"
-
-namespace chrome_pdf {
-
-class PDFModule : public pp::Module {
- public:
- PDFModule();
- virtual ~PDFModule();
-
- // pp::Module implementation.
- virtual bool Init();
- virtual pp::Instance* CreateInstance(PP_Instance instance);
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_PDF_H_
diff --git a/xfa_test/pdf/pdf.rc b/xfa_test/pdf/pdf.rc
deleted file mode 100644
index cbc98e1e4b..0000000000
--- a/xfa_test/pdf/pdf.rc
+++ /dev/null
@@ -1,104 +0,0 @@
-// Microsoft Visual C++ generated resource script.
-//
-#include "resource.h"
-
-#define APSTUDIO_READONLY_SYMBOLS
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 2 resource.
-//
-#include "afxres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-#undef APSTUDIO_READONLY_SYMBOLS
-
-/////////////////////////////////////////////////////////////////////////////
-// English (U.S.) resources
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
-#ifdef _WIN32
-LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
-#pragma code_page(1252)
-#endif //_WIN32
-
-#ifdef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// TEXTINCLUDE
-//
-
-1 TEXTINCLUDE
-BEGIN
- "resource.h\0"
-END
-
-2 TEXTINCLUDE
-BEGIN
- "#include ""afxres.h""\r\n"
- "\0"
-END
-
-3 TEXTINCLUDE
-BEGIN
- "\r\n"
- "\0"
-END
-
-#endif // APSTUDIO_INVOKED
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Version
-//
-
-VS_VERSION_INFO VERSIONINFO
- FILEVERSION 1,0,0,1
- PRODUCTVERSION 1,0,0,1
- FILEFLAGSMASK 0x17L
-#ifdef _DEBUG
- FILEFLAGS 0x1L
-#else
- FILEFLAGS 0x0L
-#endif
- FILEOS 0x4L
- FILETYPE 0x2L
- FILESUBTYPE 0x0L
-BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "040904e4"
- BEGIN
- VALUE "FileDescription", "Chrome PDF Viewer"
- VALUE "FileVersion", "1, 0, 0, 1"
- VALUE "InternalName", "pdf"
- VALUE "LegalCopyright", "Copyright (C) 2010"
- VALUE "MIMEType", "application/pdf"
- VALUE "FileExtents", "pdf"
- VALUE "FileOpenName", "Acrobat Portable Document Format"
- VALUE "OriginalFilename", "pdf.dll"
- VALUE "ProductName", "Chrome PDF Viewer"
- VALUE "ProductVersion", "1, 0, 0, 1"
- END
- END
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x409, 1252
- END
-END
-
-#endif // English (U.S.) resources
-/////////////////////////////////////////////////////////////////////////////
-
-
-
-#ifndef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 3 resource.
-//
-
-
-/////////////////////////////////////////////////////////////////////////////
-#endif // not APSTUDIO_INVOKED
-
diff --git a/xfa_test/pdf/pdf_engine.h b/xfa_test/pdf/pdf_engine.h
deleted file mode 100644
index cc25a299d8..0000000000
--- a/xfa_test/pdf/pdf_engine.h
+++ /dev/null
@@ -1,321 +0,0 @@
-// 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.
-
-#ifndef PDF_PDF_ENGINE_H_
-#define PDF_PDF_ENGINE_H_
-
-#include "build/build_config.h"
-
-#if defined(OS_WIN)
-#include <windows.h>
-#endif
-
-#include <string>
-#include <vector>
-
-#include "base/strings/string16.h"
-
-#include "ppapi/c/dev/pp_cursor_type_dev.h"
-#include "ppapi/c/dev/ppp_printing_dev.h"
-#include "ppapi/c/ppb_input_event.h"
-#include "ppapi/cpp/completion_callback.h"
-#include "ppapi/cpp/image_data.h"
-#include "ppapi/cpp/rect.h"
-#include "ppapi/cpp/size.h"
-#include "ppapi/cpp/url_loader.h"
-
-namespace pp {
-class InputEvent;
-}
-
-const uint32 kBackgroundColor = 0xFFCCCCCC;
-
-namespace chrome_pdf {
-
-class Stream;
-
-#if defined(OS_MACOSX)
-const uint32 kDefaultKeyModifier = PP_INPUTEVENT_MODIFIER_METAKEY;
-#else // !OS_MACOSX
-const uint32 kDefaultKeyModifier = PP_INPUTEVENT_MODIFIER_CONTROLKEY;
-#endif // OS_MACOSX
-
-// Do one time initialization of the SDK. data is platform specific, on Windows
-// it's the instance of the DLL and it's unused on other platforms.
-bool InitializeSDK(void* data);
-// Tells the SDK that we're shutting down.
-void ShutdownSDK();
-
-// This class encapsulates a PDF rendering engine.
-class PDFEngine {
- public:
-
- enum DocumentPermission {
- PERMISSION_COPY,
- PERMISSION_COPY_ACCESSIBLE,
- PERMISSION_PRINT_LOW_QUALITY,
- PERMISSION_PRINT_HIGH_QUALITY,
- };
-
- // The interface that's provided to the rendering engine.
- class Client {
- public:
- // Informs the client about the document's size in pixels.
- virtual void DocumentSizeUpdated(const pp::Size& size) = 0;
-
- // Informs the client that the given rect needs to be repainted.
- virtual void Invalidate(const pp::Rect& rect) = 0;
-
- // Informs the client to scroll the plugin area by the given offset.
- virtual void Scroll(const pp::Point& point) = 0;
-
- // Scroll the horizontal/vertical scrollbars to a given position.
- virtual void ScrollToX(int position) = 0;
- virtual void ScrollToY(int position) = 0;
-
- // Scroll to the specified page.
- virtual void ScrollToPage(int page) = 0;
-
- // Navigate to the given url.
- virtual void NavigateTo(const std::string& url, bool open_in_new_tab) = 0;
-
- // Updates the cursor.
- virtual void UpdateCursor(PP_CursorType_Dev cursor) = 0;
-
- // Updates the tick marks in the vertical scrollbar.
- virtual void UpdateTickMarks(const std::vector<pp::Rect>& tickmarks) = 0;
-
- // Updates the number of find results for the current search term. If
- // there are no matches 0 should be passed in. Only when the plugin has
- // finished searching should it pass in the final count with final_result
- // set to true.
- virtual void NotifyNumberOfFindResultsChanged(int total,
- bool final_result) = 0;
-
- // Updates the index of the currently selected search item.
- virtual void NotifySelectedFindResultChanged(int current_find_index) = 0;
-
- // Prompts the user for a password to open this document. The callback is
- // called when the password is retrieved.
- virtual void GetDocumentPassword(
- pp::CompletionCallbackWithOutput<pp::Var> callback) = 0;
-
- // Puts up an alert with the given message.
- virtual void Alert(const std::string& message) = 0;
-
- // Puts up a confirm with the given message, and returns true if the user
- // presses OK, or false if they press cancel.
- virtual bool Confirm(const std::string& message) = 0;
-
- // Puts up a prompt with the given message and default answer and returns
- // the answer.
- virtual std::string Prompt(const std::string& question,
- const std::string& default_answer) = 0;
-
- // Returns the url of the pdf.
- virtual std::string GetURL() = 0;
-
- // Send an email.
- virtual void Email(const std::string& to,
- const std::string& cc,
- const std::string& bcc,
- const std::string& subject,
- const std::string& body) = 0;
- // Put up the print dialog.
- virtual void Print() = 0;
-
- // Submit the data using HTTP POST.
- virtual void SubmitForm(const std::string& url,
- const void* data,
- int length) = 0;
-
- // Pops up a file selection dialog and returns the result.
- virtual std::string ShowFileSelectionDialog() = 0;
-
- // Creates and returns new URL loader for partial document requests.
- virtual pp::URLLoader CreateURLLoader() = 0;
-
- // Calls the client's OnCallback() function in delay_in_ms with the given
- // id.
- virtual void ScheduleCallback(int id, int delay_in_ms) = 0;
-
- // Searches the given string for "term" and returns the results. Unicode-
- // aware.
- struct SearchStringResult {
- int start_index;
- int length;
- };
- virtual void SearchString(const base::char16* string,
- const base::char16* term,
- bool case_sensitive,
- std::vector<SearchStringResult>* results) = 0;
-
- // Notifies the client that the engine has painted a page from the document.
- virtual void DocumentPaintOccurred() = 0;
-
- // Notifies the client that the document has finished loading.
- virtual void DocumentLoadComplete(int page_count) = 0;
-
- // Notifies the client that the document has failed to load.
- virtual void DocumentLoadFailed() = 0;
-
- virtual pp::Instance* GetPluginInstance() = 0;
-
- // Notifies that an unsupported feature in the PDF was encountered.
- virtual void DocumentHasUnsupportedFeature(const std::string& feature) = 0;
-
- // Notifies the client about document load progress.
- virtual void DocumentLoadProgress(uint32 available, uint32 doc_size) = 0;
-
- // Notifies the client about focus changes for form text fields.
- virtual void FormTextFieldFocusChange(bool in_focus) = 0;
-
- // Returns true if the plugin has been opened within print preview.
- virtual bool IsPrintPreview() = 0;
- };
-
- // Factory method to create an instance of the PDF Engine.
- static PDFEngine* Create(Client* client);
-
- virtual ~PDFEngine() {}
- // Most of these functions are similar to the Pepper functions of the same
- // name, so not repeating the description here unless it's different.
- virtual bool New(const char* url) = 0;
- virtual bool New(const char* url,
- const char* headers) = 0;
- virtual void PageOffsetUpdated(const pp::Point& page_offset) = 0;
- virtual void PluginSizeUpdated(const pp::Size& size) = 0;
- virtual void ScrolledToXPosition(int position) = 0;
- virtual void ScrolledToYPosition(int position) = 0;
- // Paint is called a series of times. Before these n calls are made, PrePaint
- // is called once. After Paint is called n times, PostPaint is called once.
- virtual void PrePaint() = 0;
- virtual void Paint(const pp::Rect& rect,
- pp::ImageData* image_data,
- std::vector<pp::Rect>* ready,
- std::vector<pp::Rect>* pending) = 0;
- virtual void PostPaint() = 0;
- virtual bool HandleDocumentLoad(const pp::URLLoader& loader) = 0;
- virtual bool HandleEvent(const pp::InputEvent& event) = 0;
- virtual uint32_t QuerySupportedPrintOutputFormats() = 0;
- virtual void PrintBegin() = 0;
- virtual pp::Resource PrintPages(
- const PP_PrintPageNumberRange_Dev* page_ranges,
- uint32_t page_range_count,
- const PP_PrintSettings_Dev& print_settings) = 0;
- virtual void PrintEnd() = 0;
- virtual void StartFind(const char* text, bool case_sensitive) = 0;
- virtual bool SelectFindResult(bool forward) = 0;
- virtual void StopFind() = 0;
- virtual void ZoomUpdated(double new_zoom_level) = 0;
- virtual void RotateClockwise() = 0;
- virtual void RotateCounterclockwise() = 0;
- virtual std::string GetSelectedText() = 0;
- virtual std::string GetLinkAtPosition(const pp::Point& point) = 0;
- virtual bool IsSelecting() = 0;
- // Checks the permissions associated with this document.
- virtual bool HasPermission(DocumentPermission permission) const = 0;
- virtual void SelectAll() = 0;
- // Gets the number of pages in the document.
- virtual int GetNumberOfPages() = 0;
- // Gets the 0-based page number of |destination|, or -1 if it does not exist.
- virtual int GetNamedDestinationPage(const std::string& destination) = 0;
- // Gets the index of the first visible page, or -1 if none are visible.
- virtual int GetFirstVisiblePage() = 0;
- // Gets the index of the most visible page, or -1 if none are visible.
- virtual int GetMostVisiblePage() = 0;
- // Gets the rectangle of the page including shadow.
- virtual pp::Rect GetPageRect(int index) = 0;
- // Gets the rectangle of the page excluding any additional areas.
- virtual pp::Rect GetPageContentsRect(int index) = 0;
- // Gets the offset of the vertical scrollbar from the top in document
- // coordinates.
- virtual int GetVerticalScrollbarYPosition() = 0;
- // Paints page thumbnail to the ImageData.
- virtual void PaintThumbnail(pp::ImageData* image_data, int index) = 0;
- // Set color / grayscale rendering modes.
- virtual void SetGrayscale(bool grayscale) = 0;
- // Callback for timer that's set with ScheduleCallback().
- virtual void OnCallback(int id) = 0;
- // Gets the JSON representation of the PDF file
- virtual std::string GetPageAsJSON(int index) = 0;
- // Gets the PDF document's print scaling preference. True if the document can
- // be scaled to fit.
- virtual bool GetPrintScaling() = 0;
-
- // Append blank pages to make a 1-page document to a |num_pages| document.
- // Always retain the first page data.
- virtual void AppendBlankPages(int num_pages) = 0;
- // Append the first page of the document loaded with the |engine| to this
- // document at page |index|.
- virtual void AppendPage(PDFEngine* engine, int index) = 0;
-
- // Allow client to query and reset scroll positions in document coordinates.
- // Note that this is meant for cases where the device scale factor changes,
- // and not for general scrolling - the engine will not repaint due to this.
- virtual pp::Point GetScrollPosition() = 0;
- virtual void SetScrollPosition(const pp::Point& position) = 0;
-
- virtual bool IsProgressiveLoad() = 0;
-};
-
-// Interface for exports that wrap the PDF engine.
-class PDFEngineExports {
- public:
- struct RenderingSettings {
- RenderingSettings(int dpi_x,
- int dpi_y,
- const pp::Rect& bounds,
- bool fit_to_bounds,
- bool stretch_to_bounds,
- bool keep_aspect_ratio,
- bool center_in_bounds,
- bool autorotate)
- : dpi_x(dpi_x), dpi_y(dpi_y), bounds(bounds),
- fit_to_bounds(fit_to_bounds), stretch_to_bounds(stretch_to_bounds),
- keep_aspect_ratio(keep_aspect_ratio),
- center_in_bounds(center_in_bounds), autorotate(autorotate) {
- }
- int dpi_x;
- int dpi_y;
- pp::Rect bounds;
- bool fit_to_bounds;
- bool stretch_to_bounds;
- bool keep_aspect_ratio;
- bool center_in_bounds;
- bool autorotate;
- };
-
- PDFEngineExports() {}
- virtual ~PDFEngineExports() {}
- static PDFEngineExports* Create();
-#if defined(OS_WIN)
- // See the definition of RenderPDFPageToDC in pdf.cc for details.
- virtual bool RenderPDFPageToDC(const void* pdf_buffer,
- int buffer_size,
- int page_number,
- const RenderingSettings& settings,
- HDC dc) = 0;
-#endif // OS_WIN
- // See the definition of RenderPDFPageToBitmap in pdf.cc for details.
- virtual bool RenderPDFPageToBitmap(const void* pdf_buffer,
- int pdf_buffer_size,
- int page_number,
- const RenderingSettings& settings,
- void* bitmap_buffer) = 0;
-
- virtual bool GetPDFDocInfo(const void* pdf_buffer,
- int buffer_size,
- int* page_count,
- double* max_page_width) = 0;
-
- // See the definition of GetPDFPageSizeByIndex in pdf.cc for details.
- virtual bool GetPDFPageSizeByIndex(const void* pdf_buffer,
- int pdf_buffer_size, int page_number,
- double* width, double* height) = 0;
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_PDF_ENGINE_H_
diff --git a/xfa_test/pdf/pdfium/pdfium_assert_matching_enums.cc b/xfa_test/pdf/pdfium/pdfium_assert_matching_enums.cc
deleted file mode 100644
index ef140cf7c9..0000000000
--- a/xfa_test/pdf/pdfium/pdfium_assert_matching_enums.cc
+++ /dev/null
@@ -1,207 +0,0 @@
-// Copyright (c) 2010 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 "base/basictypes.h"
-#include "ppapi/c/pp_input_event.h"
-#include "ppapi/c/private/ppb_pdf.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdf_fwlevent.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdf_sysfontinfo.h"
-#include "ui/events/keycodes/keyboard_codes.h"
-
-#define COMPILE_ASSERT_MATCH(np_name, pdfium_name) \
- COMPILE_ASSERT(int(np_name) == int(pdfium_name), mismatching_enums)
-
-COMPILE_ASSERT_MATCH(PP_INPUTEVENT_MODIFIER_SHIFTKEY, FWL_EVENTFLAG_ShiftKey);
-COMPILE_ASSERT_MATCH(PP_INPUTEVENT_MODIFIER_CONTROLKEY,
- FWL_EVENTFLAG_ControlKey);
-COMPILE_ASSERT_MATCH(PP_INPUTEVENT_MODIFIER_ALTKEY, FWL_EVENTFLAG_AltKey);
-COMPILE_ASSERT_MATCH(PP_INPUTEVENT_MODIFIER_METAKEY, FWL_EVENTFLAG_MetaKey);
-COMPILE_ASSERT_MATCH(PP_INPUTEVENT_MODIFIER_ISKEYPAD, FWL_EVENTFLAG_KeyPad);
-COMPILE_ASSERT_MATCH(PP_INPUTEVENT_MODIFIER_ISAUTOREPEAT,
- FWL_EVENTFLAG_AutoRepeat);
-COMPILE_ASSERT_MATCH(PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN,
- FWL_EVENTFLAG_LeftButtonDown);
-COMPILE_ASSERT_MATCH(PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN,
- FWL_EVENTFLAG_MiddleButtonDown);
-COMPILE_ASSERT_MATCH(PP_INPUTEVENT_MODIFIER_RIGHTBUTTONDOWN,
- FWL_EVENTFLAG_RightButtonDown);
-
-COMPILE_ASSERT_MATCH(ui::VKEY_BACK, FWL_VKEY_Back);
-COMPILE_ASSERT_MATCH(ui::VKEY_TAB, FWL_VKEY_Tab);
-COMPILE_ASSERT_MATCH(ui::VKEY_CLEAR, FWL_VKEY_Clear);
-COMPILE_ASSERT_MATCH(ui::VKEY_RETURN, FWL_VKEY_Return);
-COMPILE_ASSERT_MATCH(ui::VKEY_SHIFT, FWL_VKEY_Shift);
-COMPILE_ASSERT_MATCH(ui::VKEY_CONTROL, FWL_VKEY_Control);
-COMPILE_ASSERT_MATCH(ui::VKEY_MENU, FWL_VKEY_Menu);
-COMPILE_ASSERT_MATCH(ui::VKEY_PAUSE, FWL_VKEY_Pause);
-COMPILE_ASSERT_MATCH(ui::VKEY_CAPITAL, FWL_VKEY_Capital);
-COMPILE_ASSERT_MATCH(ui::VKEY_KANA, FWL_VKEY_Kana);
-COMPILE_ASSERT_MATCH(ui::VKEY_HANGUL, FWL_VKEY_Hangul);
-COMPILE_ASSERT_MATCH(ui::VKEY_JUNJA, FWL_VKEY_Junja);
-COMPILE_ASSERT_MATCH(ui::VKEY_FINAL, FWL_VKEY_Final);
-COMPILE_ASSERT_MATCH(ui::VKEY_HANJA, FWL_VKEY_Hanja);
-COMPILE_ASSERT_MATCH(ui::VKEY_KANJI, FWL_VKEY_Kanji);
-COMPILE_ASSERT_MATCH(ui::VKEY_ESCAPE, FWL_VKEY_Escape);
-COMPILE_ASSERT_MATCH(ui::VKEY_CONVERT, FWL_VKEY_Convert);
-COMPILE_ASSERT_MATCH(ui::VKEY_NONCONVERT, FWL_VKEY_NonConvert);
-COMPILE_ASSERT_MATCH(ui::VKEY_ACCEPT, FWL_VKEY_Accept);
-COMPILE_ASSERT_MATCH(ui::VKEY_MODECHANGE, FWL_VKEY_ModeChange);
-COMPILE_ASSERT_MATCH(ui::VKEY_SPACE, FWL_VKEY_Space);
-COMPILE_ASSERT_MATCH(ui::VKEY_PRIOR, FWL_VKEY_Prior);
-COMPILE_ASSERT_MATCH(ui::VKEY_NEXT, FWL_VKEY_Next);
-COMPILE_ASSERT_MATCH(ui::VKEY_END, FWL_VKEY_End);
-COMPILE_ASSERT_MATCH(ui::VKEY_HOME, FWL_VKEY_Home);
-COMPILE_ASSERT_MATCH(ui::VKEY_LEFT, FWL_VKEY_Left);
-COMPILE_ASSERT_MATCH(ui::VKEY_UP, FWL_VKEY_Up);
-COMPILE_ASSERT_MATCH(ui::VKEY_RIGHT, FWL_VKEY_Right);
-COMPILE_ASSERT_MATCH(ui::VKEY_DOWN, FWL_VKEY_Down);
-COMPILE_ASSERT_MATCH(ui::VKEY_SELECT, FWL_VKEY_Select);
-COMPILE_ASSERT_MATCH(ui::VKEY_PRINT, FWL_VKEY_Print);
-COMPILE_ASSERT_MATCH(ui::VKEY_EXECUTE, FWL_VKEY_Execute);
-COMPILE_ASSERT_MATCH(ui::VKEY_SNAPSHOT, FWL_VKEY_Snapshot);
-COMPILE_ASSERT_MATCH(ui::VKEY_INSERT, FWL_VKEY_Insert);
-COMPILE_ASSERT_MATCH(ui::VKEY_DELETE, FWL_VKEY_Delete);
-COMPILE_ASSERT_MATCH(ui::VKEY_HELP, FWL_VKEY_Help);
-COMPILE_ASSERT_MATCH(ui::VKEY_0, FWL_VKEY_0);
-COMPILE_ASSERT_MATCH(ui::VKEY_1, FWL_VKEY_1);
-COMPILE_ASSERT_MATCH(ui::VKEY_2, FWL_VKEY_2);
-COMPILE_ASSERT_MATCH(ui::VKEY_3, FWL_VKEY_3);
-COMPILE_ASSERT_MATCH(ui::VKEY_4, FWL_VKEY_4);
-COMPILE_ASSERT_MATCH(ui::VKEY_5, FWL_VKEY_5);
-COMPILE_ASSERT_MATCH(ui::VKEY_6, FWL_VKEY_6);
-COMPILE_ASSERT_MATCH(ui::VKEY_7, FWL_VKEY_7);
-COMPILE_ASSERT_MATCH(ui::VKEY_8, FWL_VKEY_8);
-COMPILE_ASSERT_MATCH(ui::VKEY_9, FWL_VKEY_9);
-COMPILE_ASSERT_MATCH(ui::VKEY_A, FWL_VKEY_A);
-COMPILE_ASSERT_MATCH(ui::VKEY_B, FWL_VKEY_B);
-COMPILE_ASSERT_MATCH(ui::VKEY_C, FWL_VKEY_C);
-COMPILE_ASSERT_MATCH(ui::VKEY_D, FWL_VKEY_D);
-COMPILE_ASSERT_MATCH(ui::VKEY_E, FWL_VKEY_E);
-COMPILE_ASSERT_MATCH(ui::VKEY_F, FWL_VKEY_F);
-COMPILE_ASSERT_MATCH(ui::VKEY_G, FWL_VKEY_G);
-COMPILE_ASSERT_MATCH(ui::VKEY_H, FWL_VKEY_H);
-COMPILE_ASSERT_MATCH(ui::VKEY_I, FWL_VKEY_I);
-COMPILE_ASSERT_MATCH(ui::VKEY_J, FWL_VKEY_J);
-COMPILE_ASSERT_MATCH(ui::VKEY_K, FWL_VKEY_K);
-COMPILE_ASSERT_MATCH(ui::VKEY_L, FWL_VKEY_L);
-COMPILE_ASSERT_MATCH(ui::VKEY_M, FWL_VKEY_M);
-COMPILE_ASSERT_MATCH(ui::VKEY_N, FWL_VKEY_N);
-COMPILE_ASSERT_MATCH(ui::VKEY_O, FWL_VKEY_O);
-COMPILE_ASSERT_MATCH(ui::VKEY_P, FWL_VKEY_P);
-COMPILE_ASSERT_MATCH(ui::VKEY_Q, FWL_VKEY_Q);
-COMPILE_ASSERT_MATCH(ui::VKEY_R, FWL_VKEY_R);
-COMPILE_ASSERT_MATCH(ui::VKEY_S, FWL_VKEY_S);
-COMPILE_ASSERT_MATCH(ui::VKEY_T, FWL_VKEY_T);
-COMPILE_ASSERT_MATCH(ui::VKEY_U, FWL_VKEY_U);
-COMPILE_ASSERT_MATCH(ui::VKEY_V, FWL_VKEY_V);
-COMPILE_ASSERT_MATCH(ui::VKEY_W, FWL_VKEY_W);
-COMPILE_ASSERT_MATCH(ui::VKEY_X, FWL_VKEY_X);
-COMPILE_ASSERT_MATCH(ui::VKEY_Y, FWL_VKEY_Y);
-COMPILE_ASSERT_MATCH(ui::VKEY_Z, FWL_VKEY_Z);
-COMPILE_ASSERT_MATCH(ui::VKEY_LWIN, FWL_VKEY_LWin);
-COMPILE_ASSERT_MATCH(ui::VKEY_COMMAND, FWL_VKEY_Command);
-COMPILE_ASSERT_MATCH(ui::VKEY_RWIN, FWL_VKEY_RWin);
-COMPILE_ASSERT_MATCH(ui::VKEY_APPS, FWL_VKEY_Apps);
-COMPILE_ASSERT_MATCH(ui::VKEY_SLEEP, FWL_VKEY_Sleep);
-COMPILE_ASSERT_MATCH(ui::VKEY_NUMPAD0, FWL_VKEY_NumPad0);
-COMPILE_ASSERT_MATCH(ui::VKEY_NUMPAD1, FWL_VKEY_NumPad1);
-COMPILE_ASSERT_MATCH(ui::VKEY_NUMPAD2, FWL_VKEY_NumPad2);
-COMPILE_ASSERT_MATCH(ui::VKEY_NUMPAD3, FWL_VKEY_NumPad3);
-COMPILE_ASSERT_MATCH(ui::VKEY_NUMPAD4, FWL_VKEY_NumPad4);
-COMPILE_ASSERT_MATCH(ui::VKEY_NUMPAD5, FWL_VKEY_NumPad5);
-COMPILE_ASSERT_MATCH(ui::VKEY_NUMPAD6, FWL_VKEY_NumPad6);
-COMPILE_ASSERT_MATCH(ui::VKEY_NUMPAD7, FWL_VKEY_NumPad7);
-COMPILE_ASSERT_MATCH(ui::VKEY_NUMPAD8, FWL_VKEY_NumPad8);
-COMPILE_ASSERT_MATCH(ui::VKEY_NUMPAD9, FWL_VKEY_NumPad9);
-COMPILE_ASSERT_MATCH(ui::VKEY_MULTIPLY, FWL_VKEY_Multiply);
-COMPILE_ASSERT_MATCH(ui::VKEY_ADD, FWL_VKEY_Add);
-COMPILE_ASSERT_MATCH(ui::VKEY_SEPARATOR, FWL_VKEY_Separator);
-COMPILE_ASSERT_MATCH(ui::VKEY_SUBTRACT, FWL_VKEY_Subtract);
-COMPILE_ASSERT_MATCH(ui::VKEY_DECIMAL, FWL_VKEY_Decimal);
-COMPILE_ASSERT_MATCH(ui::VKEY_DIVIDE, FWL_VKEY_Divide);
-COMPILE_ASSERT_MATCH(ui::VKEY_F1, FWL_VKEY_F1);
-COMPILE_ASSERT_MATCH(ui::VKEY_F2, FWL_VKEY_F2);
-COMPILE_ASSERT_MATCH(ui::VKEY_F3, FWL_VKEY_F3);
-COMPILE_ASSERT_MATCH(ui::VKEY_F4, FWL_VKEY_F4);
-COMPILE_ASSERT_MATCH(ui::VKEY_F5, FWL_VKEY_F5);
-COMPILE_ASSERT_MATCH(ui::VKEY_F6, FWL_VKEY_F6);
-COMPILE_ASSERT_MATCH(ui::VKEY_F7, FWL_VKEY_F7);
-COMPILE_ASSERT_MATCH(ui::VKEY_F8, FWL_VKEY_F8);
-COMPILE_ASSERT_MATCH(ui::VKEY_F9, FWL_VKEY_F9);
-COMPILE_ASSERT_MATCH(ui::VKEY_F10, FWL_VKEY_F10);
-COMPILE_ASSERT_MATCH(ui::VKEY_F11, FWL_VKEY_F11);
-COMPILE_ASSERT_MATCH(ui::VKEY_F12, FWL_VKEY_F12);
-COMPILE_ASSERT_MATCH(ui::VKEY_F13, FWL_VKEY_F13);
-COMPILE_ASSERT_MATCH(ui::VKEY_F14, FWL_VKEY_F14);
-COMPILE_ASSERT_MATCH(ui::VKEY_F15, FWL_VKEY_F15);
-COMPILE_ASSERT_MATCH(ui::VKEY_F16, FWL_VKEY_F16);
-COMPILE_ASSERT_MATCH(ui::VKEY_F17, FWL_VKEY_F17);
-COMPILE_ASSERT_MATCH(ui::VKEY_F18, FWL_VKEY_F18);
-COMPILE_ASSERT_MATCH(ui::VKEY_F19, FWL_VKEY_F19);
-COMPILE_ASSERT_MATCH(ui::VKEY_F20, FWL_VKEY_F20);
-COMPILE_ASSERT_MATCH(ui::VKEY_F21, FWL_VKEY_F21);
-COMPILE_ASSERT_MATCH(ui::VKEY_F22, FWL_VKEY_F22);
-COMPILE_ASSERT_MATCH(ui::VKEY_F23, FWL_VKEY_F23);
-COMPILE_ASSERT_MATCH(ui::VKEY_F24, FWL_VKEY_F24);
-COMPILE_ASSERT_MATCH(ui::VKEY_NUMLOCK, FWL_VKEY_NunLock);
-COMPILE_ASSERT_MATCH(ui::VKEY_SCROLL, FWL_VKEY_Scroll);
-COMPILE_ASSERT_MATCH(ui::VKEY_LSHIFT, FWL_VKEY_LShift);
-COMPILE_ASSERT_MATCH(ui::VKEY_RSHIFT, FWL_VKEY_RShift);
-COMPILE_ASSERT_MATCH(ui::VKEY_LCONTROL, FWL_VKEY_LControl);
-COMPILE_ASSERT_MATCH(ui::VKEY_RCONTROL, FWL_VKEY_RControl);
-COMPILE_ASSERT_MATCH(ui::VKEY_LMENU, FWL_VKEY_LMenu);
-COMPILE_ASSERT_MATCH(ui::VKEY_RMENU, FWL_VKEY_RMenu);
-COMPILE_ASSERT_MATCH(ui::VKEY_BROWSER_BACK, FWL_VKEY_BROWSER_Back);
-COMPILE_ASSERT_MATCH(ui::VKEY_BROWSER_FORWARD, FWL_VKEY_BROWSER_Forward);
-COMPILE_ASSERT_MATCH(ui::VKEY_BROWSER_REFRESH, FWL_VKEY_BROWSER_Refresh);
-COMPILE_ASSERT_MATCH(ui::VKEY_BROWSER_STOP, FWL_VKEY_BROWSER_Stop);
-COMPILE_ASSERT_MATCH(ui::VKEY_BROWSER_SEARCH, FWL_VKEY_BROWSER_Search);
-COMPILE_ASSERT_MATCH(ui::VKEY_BROWSER_FAVORITES, FWL_VKEY_BROWSER_Favorites);
-COMPILE_ASSERT_MATCH(ui::VKEY_BROWSER_HOME, FWL_VKEY_BROWSER_Home);
-COMPILE_ASSERT_MATCH(ui::VKEY_VOLUME_MUTE, FWL_VKEY_VOLUME_Mute);
-COMPILE_ASSERT_MATCH(ui::VKEY_VOLUME_DOWN, FWL_VKEY_VOLUME_Down);
-COMPILE_ASSERT_MATCH(ui::VKEY_VOLUME_UP, FWL_VKEY_VOLUME_Up);
-COMPILE_ASSERT_MATCH(ui::VKEY_MEDIA_NEXT_TRACK, FWL_VKEY_MEDIA_NEXT_Track);
-COMPILE_ASSERT_MATCH(ui::VKEY_MEDIA_PREV_TRACK, FWL_VKEY_MEDIA_PREV_Track);
-COMPILE_ASSERT_MATCH(ui::VKEY_MEDIA_STOP, FWL_VKEY_MEDIA_Stop);
-COMPILE_ASSERT_MATCH(ui::VKEY_MEDIA_PLAY_PAUSE, FWL_VKEY_MEDIA_PLAY_Pause);
-COMPILE_ASSERT_MATCH(ui::VKEY_MEDIA_LAUNCH_MAIL, FWL_VKEY_MEDIA_LAUNCH_Mail);
-COMPILE_ASSERT_MATCH(ui::VKEY_MEDIA_LAUNCH_MEDIA_SELECT,
- FWL_VKEY_MEDIA_LAUNCH_MEDIA_Select);
-COMPILE_ASSERT_MATCH(ui::VKEY_MEDIA_LAUNCH_APP1, FWL_VKEY_MEDIA_LAUNCH_APP1);
-COMPILE_ASSERT_MATCH(ui::VKEY_MEDIA_LAUNCH_APP2, FWL_VKEY_MEDIA_LAUNCH_APP2);
-COMPILE_ASSERT_MATCH(ui::VKEY_OEM_1, FWL_VKEY_OEM_1);
-COMPILE_ASSERT_MATCH(ui::VKEY_OEM_PLUS, FWL_VKEY_OEM_Plus);
-COMPILE_ASSERT_MATCH(ui::VKEY_OEM_COMMA, FWL_VKEY_OEM_Comma);
-COMPILE_ASSERT_MATCH(ui::VKEY_OEM_MINUS, FWL_VKEY_OEM_Minus);
-COMPILE_ASSERT_MATCH(ui::VKEY_OEM_PERIOD, FWL_VKEY_OEM_Period);
-COMPILE_ASSERT_MATCH(ui::VKEY_OEM_2, FWL_VKEY_OEM_2);
-COMPILE_ASSERT_MATCH(ui::VKEY_OEM_3, FWL_VKEY_OEM_3);
-COMPILE_ASSERT_MATCH(ui::VKEY_OEM_4, FWL_VKEY_OEM_4);
-COMPILE_ASSERT_MATCH(ui::VKEY_OEM_5, FWL_VKEY_OEM_5);
-COMPILE_ASSERT_MATCH(ui::VKEY_OEM_6, FWL_VKEY_OEM_6);
-COMPILE_ASSERT_MATCH(ui::VKEY_OEM_7, FWL_VKEY_OEM_7);
-COMPILE_ASSERT_MATCH(ui::VKEY_OEM_8, FWL_VKEY_OEM_8);
-COMPILE_ASSERT_MATCH(ui::VKEY_OEM_102, FWL_VKEY_OEM_102);
-COMPILE_ASSERT_MATCH(ui::VKEY_PROCESSKEY, FWL_VKEY_ProcessKey);
-COMPILE_ASSERT_MATCH(ui::VKEY_PACKET, FWL_VKEY_Packet);
-COMPILE_ASSERT_MATCH(ui::VKEY_ATTN, FWL_VKEY_Attn);
-COMPILE_ASSERT_MATCH(ui::VKEY_CRSEL, FWL_VKEY_Crsel);
-COMPILE_ASSERT_MATCH(ui::VKEY_EXSEL, FWL_VKEY_Exsel);
-COMPILE_ASSERT_MATCH(ui::VKEY_EREOF, FWL_VKEY_Ereof);
-COMPILE_ASSERT_MATCH(ui::VKEY_PLAY, FWL_VKEY_Play);
-COMPILE_ASSERT_MATCH(ui::VKEY_ZOOM, FWL_VKEY_Zoom);
-COMPILE_ASSERT_MATCH(ui::VKEY_NONAME, FWL_VKEY_NoName);
-COMPILE_ASSERT_MATCH(ui::VKEY_PA1, FWL_VKEY_PA1);
-COMPILE_ASSERT_MATCH(ui::VKEY_OEM_CLEAR, FWL_VKEY_OEM_Clear);
-COMPILE_ASSERT_MATCH(ui::VKEY_UNKNOWN, FWL_VKEY_Unknown);
-
-COMPILE_ASSERT_MATCH(PP_PRIVATEFONTCHARSET_ANSI, FXFONT_ANSI_CHARSET);
-COMPILE_ASSERT_MATCH(PP_PRIVATEFONTCHARSET_DEFAULT, FXFONT_DEFAULT_CHARSET);
-COMPILE_ASSERT_MATCH(PP_PRIVATEFONTCHARSET_SYMBOL, FXFONT_SYMBOL_CHARSET);
-COMPILE_ASSERT_MATCH(PP_PRIVATEFONTCHARSET_SHIFTJIS, FXFONT_SHIFTJIS_CHARSET);
-COMPILE_ASSERT_MATCH(PP_PRIVATEFONTCHARSET_HANGUL, FXFONT_HANGEUL_CHARSET);
-COMPILE_ASSERT_MATCH(PP_PRIVATEFONTCHARSET_GB2312, FXFONT_GB2312_CHARSET);
-COMPILE_ASSERT_MATCH(PP_PRIVATEFONTCHARSET_CHINESEBIG5,
- FXFONT_CHINESEBIG5_CHARSET);
diff --git a/xfa_test/pdf/pdfium/pdfium_engine.cc b/xfa_test/pdf/pdfium/pdfium_engine.cc
deleted file mode 100644
index ff77d572ad..0000000000
--- a/xfa_test/pdf/pdfium/pdfium_engine.cc
+++ /dev/null
@@ -1,3883 +0,0 @@
-// 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 "pdf/pdfium/pdfium_engine.h"
-
-#include <math.h>
-
-#include "base/json/json_writer.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/stl_util.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_piece.h"
-#include "base/strings/string_util.h"
-#include "base/strings/utf_string_conversions.h"
-#include "base/values.h"
-#include "pdf/draw_utils.h"
-#include "pdf/pdfium/pdfium_mem_buffer_file_read.h"
-#include "pdf/pdfium/pdfium_mem_buffer_file_write.h"
-#include "ppapi/c/pp_errors.h"
-#include "ppapi/c/pp_input_event.h"
-#include "ppapi/c/ppb_core.h"
-#include "ppapi/c/private/ppb_pdf.h"
-#include "ppapi/cpp/dev/memory_dev.h"
-#include "ppapi/cpp/input_event.h"
-#include "ppapi/cpp/instance.h"
-#include "ppapi/cpp/module.h"
-#include "ppapi/cpp/private/pdf.h"
-#include "ppapi/cpp/trusted/browser_font_trusted.h"
-#include "ppapi/cpp/url_response_info.h"
-#include "ppapi/cpp/var.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdf_ext.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdf_flatten.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdf_searchex.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdf_sysfontinfo.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdf_transformpage.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdfedit.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdfoom.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdfppo.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdfsave.h"
-#include "third_party/pdfium/fpdfsdk/include/pdfwindow/PDFWindow.h"
-#include "third_party/pdfium/fpdfsdk/include/pdfwindow/PWL_FontMap.h"
-#include "ui/events/keycodes/keyboard_codes.h"
-
-namespace chrome_pdf {
-
-namespace {
-
-#define kPageShadowTop 3
-#define kPageShadowBottom 7
-#define kPageShadowLeft 5
-#define kPageShadowRight 5
-
-#define kPageSeparatorThickness 4
-#define kHighlightColorR 153
-#define kHighlightColorG 193
-#define kHighlightColorB 218
-
-const uint32 kPendingPageColor = 0xFFEEEEEE;
-
-#define kFormHighlightColor 0xFFE4DD
-#define kFormHighlightAlpha 100
-
-#define kMaxPasswordTries 3
-
-// See Table 3.20 in
-// http://www.adobe.com/devnet/acrobat/pdfs/pdf_reference_1-7.pdf
-#define kPDFPermissionPrintLowQualityMask 1 << 2
-#define kPDFPermissionPrintHighQualityMask 1 << 11
-#define kPDFPermissionCopyMask 1 << 4
-#define kPDFPermissionCopyAccessibleMask 1 << 9
-
-#define kLoadingTextVerticalOffset 50
-
-// The maximum amount of time we'll spend doing a paint before we give back
-// control of the thread.
-#define kMaxProgressivePaintTimeMs 50
-
-// The maximum amount of time we'll spend doing the first paint. This is less
-// than the above to keep things smooth if the user is scrolling quickly. We
-// try painting a little because with accelerated compositing, we get flushes
-// only every 16 ms. If we were to wait until the next flush to paint the rest
-// of the pdf, we would never get to draw the pdf and would only draw the
-// scrollbars. This value is picked to give enough time for gpu related code to
-// do its thing and still fit within the timelimit for 60Hz. For the
-// non-composited case, this doesn't make things worse since we're still
-// painting the scrollbars > 60 Hz.
-#define kMaxInitialProgressivePaintTimeMs 10
-
-// Copied from printing/units.cc because we don't want to depend on printing
-// since it brings in libpng which causes duplicate symbols with PDFium.
-const int kPointsPerInch = 72;
-const int kPixelsPerInch = 96;
-
-struct ClipBox {
- float left;
- float right;
- float top;
- float bottom;
-};
-
-int ConvertUnit(int value, int old_unit, int new_unit) {
- // With integer arithmetic, to divide a value with correct rounding, you need
- // to add half of the divisor value to the dividend value. You need to do the
- // reverse with negative number.
- if (value >= 0) {
- return ((value * new_unit) + (old_unit / 2)) / old_unit;
- } else {
- return ((value * new_unit) - (old_unit / 2)) / old_unit;
- }
-}
-
-std::vector<uint32_t> GetPageNumbersFromPrintPageNumberRange(
- const PP_PrintPageNumberRange_Dev* page_ranges,
- uint32_t page_range_count) {
- std::vector<uint32_t> page_numbers;
- for (uint32_t index = 0; index < page_range_count; ++index) {
- for (uint32_t page_number = page_ranges[index].first_page_number;
- page_number <= page_ranges[index].last_page_number; ++page_number) {
- page_numbers.push_back(page_number);
- }
- }
- return page_numbers;
-}
-
-#if defined(OS_LINUX)
-
-PP_Instance g_last_instance_id;
-
-struct PDFFontSubstitution {
- const char* pdf_name;
- const char* face;
- bool bold;
- bool italic;
-};
-
-PP_BrowserFont_Trusted_Weight WeightToBrowserFontTrustedWeight(int weight) {
- COMPILE_ASSERT(PP_BROWSERFONT_TRUSTED_WEIGHT_100 == 0,
- PP_BrowserFont_Trusted_Weight_Min);
- COMPILE_ASSERT(PP_BROWSERFONT_TRUSTED_WEIGHT_900 == 8,
- PP_BrowserFont_Trusted_Weight_Max);
- const int kMinimumWeight = 100;
- const int kMaximumWeight = 900;
- int normalized_weight =
- std::min(std::max(weight, kMinimumWeight), kMaximumWeight);
- normalized_weight = (normalized_weight / 100) - 1;
- return static_cast<PP_BrowserFont_Trusted_Weight>(normalized_weight);
-}
-
-// This list is for CPWL_FontMap::GetDefaultFontByCharset().
-// We pretend to have these font natively and let the browser (or underlying
-// fontconfig) to pick the proper font on the system.
-void EnumFonts(struct _FPDF_SYSFONTINFO* sysfontinfo, void* mapper) {
- FPDF_AddInstalledFont(mapper, "Arial", FXFONT_DEFAULT_CHARSET);
-
- int i = 0;
- while (CPWL_FontMap::defaultTTFMap[i].charset != -1) {
- FPDF_AddInstalledFont(mapper,
- CPWL_FontMap::defaultTTFMap[i].fontname,
- CPWL_FontMap::defaultTTFMap[i].charset);
- ++i;
- }
-}
-
-const PDFFontSubstitution PDFFontSubstitutions[] = {
- {"Courier", "Courier New", false, false},
- {"Courier-Bold", "Courier New", true, false},
- {"Courier-BoldOblique", "Courier New", true, true},
- {"Courier-Oblique", "Courier New", false, true},
- {"Helvetica", "Arial", false, false},
- {"Helvetica-Bold", "Arial", true, false},
- {"Helvetica-BoldOblique", "Arial", true, true},
- {"Helvetica-Oblique", "Arial", false, true},
- {"Times-Roman", "Times New Roman", false, false},
- {"Times-Bold", "Times New Roman", true, false},
- {"Times-BoldItalic", "Times New Roman", true, true},
- {"Times-Italic", "Times New Roman", false, true},
-
- // MS P?(Mincho|Gothic) are the most notable fonts in Japanese PDF files
- // without embedding the glyphs. Sometimes the font names are encoded
- // in Japanese Windows's locale (CP932/Shift_JIS) without space.
- // Most Linux systems don't have the exact font, but for outsourcing
- // fontconfig to find substitutable font in the system, we pass ASCII
- // font names to it.
- {"MS-PGothic", "MS PGothic", false, false},
- {"MS-Gothic", "MS Gothic", false, false},
- {"MS-PMincho", "MS PMincho", false, false},
- {"MS-Mincho", "MS Mincho", false, false},
- // MS PGothic in Shift_JIS encoding.
- {"\x82\x6C\x82\x72\x82\x6F\x83\x53\x83\x56\x83\x62\x83\x4E",
- "MS PGothic", false, false},
- // MS Gothic in Shift_JIS encoding.
- {"\x82\x6C\x82\x72\x83\x53\x83\x56\x83\x62\x83\x4E",
- "MS Gothic", false, false},
- // MS PMincho in Shift_JIS encoding.
- {"\x82\x6C\x82\x72\x82\x6F\x96\xBE\x92\xA9",
- "MS PMincho", false, false},
- // MS Mincho in Shift_JIS encoding.
- {"\x82\x6C\x82\x72\x96\xBE\x92\xA9",
- "MS Mincho", false, false},
-};
-
-void* MapFont(struct _FPDF_SYSFONTINFO*, int weight, int italic,
- int charset, int pitch_family, const char* face, int* exact) {
- // Do not attempt to map fonts if pepper is not initialized (for privet local
- // printing).
- // TODO(noamsml): Real font substitution (http://crbug.com/391978)
- if (!pp::Module::Get())
- return NULL;
-
- pp::BrowserFontDescription description;
-
- // Pretend the system does not have the Symbol font to force a fallback to
- // the built in Symbol font in CFX_FontMapper::FindSubstFont().
- if (strcmp(face, "Symbol") == 0)
- return NULL;
-
- if (pitch_family & FXFONT_FF_FIXEDPITCH) {
- description.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE);
- } else if (pitch_family & FXFONT_FF_ROMAN) {
- description.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_SERIF);
- }
-
- // Map from the standard PDF fonts to TrueType font names.
- size_t i;
- for (i = 0; i < arraysize(PDFFontSubstitutions); ++i) {
- if (strcmp(face, PDFFontSubstitutions[i].pdf_name) == 0) {
- description.set_face(PDFFontSubstitutions[i].face);
- if (PDFFontSubstitutions[i].bold)
- description.set_weight(PP_BROWSERFONT_TRUSTED_WEIGHT_BOLD);
- if (PDFFontSubstitutions[i].italic)
- description.set_italic(true);
- break;
- }
- }
-
- if (i == arraysize(PDFFontSubstitutions)) {
- // TODO(kochi): Pass the face in UTF-8. If face is not encoded in UTF-8,
- // convert to UTF-8 before passing.
- description.set_face(face);
-
- description.set_weight(WeightToBrowserFontTrustedWeight(weight));
- description.set_italic(italic > 0);
- }
-
- if (!pp::PDF::IsAvailable()) {
- NOTREACHED();
- return NULL;
- }
-
- PP_Resource font_resource = pp::PDF::GetFontFileWithFallback(
- pp::InstanceHandle(g_last_instance_id),
- &description.pp_font_description(),
- static_cast<PP_PrivateFontCharset>(charset));
- long res_id = font_resource;
- return reinterpret_cast<void*>(res_id);
-}
-
-unsigned long GetFontData(struct _FPDF_SYSFONTINFO*, void* font_id,
- unsigned int table, unsigned char* buffer,
- unsigned long buf_size) {
- if (!pp::PDF::IsAvailable()) {
- NOTREACHED();
- return 0;
- }
-
- uint32_t size = buf_size;
- long res_id = reinterpret_cast<long>(font_id);
- if (!pp::PDF::GetFontTableForPrivateFontFile(res_id, table, buffer, &size))
- return 0;
- return size;
-}
-
-void DeleteFont(struct _FPDF_SYSFONTINFO*, void* font_id) {
- long res_id = reinterpret_cast<long>(font_id);
- pp::Module::Get()->core()->ReleaseResource(res_id);
-}
-
-FPDF_SYSFONTINFO g_font_info = {
- 1,
- 0,
- EnumFonts,
- MapFont,
- 0,
- GetFontData,
- 0,
- 0,
- DeleteFont
-};
-#endif // defined(OS_LINUX)
-
-void OOM_Handler(_OOM_INFO*) {
- // Kill the process. This is important for security, since the code doesn't
- // NULL-check many memory allocations. If a malloc fails, returns NULL, and
- // the buffer is then used, it provides a handy mapping of memory starting at
- // address 0 for an attacker to utilize.
- abort();
-}
-
-OOM_INFO g_oom_info = {
- 1,
- OOM_Handler
-};
-
-PDFiumEngine* g_engine_for_unsupported;
-
-void Unsupported_Handler(UNSUPPORT_INFO*, int type) {
- if (!g_engine_for_unsupported) {
- NOTREACHED();
- return;
- }
-
- g_engine_for_unsupported->UnsupportedFeature(type);
-}
-
-UNSUPPORT_INFO g_unsuppored_info = {
- 1,
- Unsupported_Handler
-};
-
-// Set the destination page size and content area in points based on source
-// page rotation and orientation.
-//
-// |rotated| True if source page is rotated 90 degree or 270 degree.
-// |is_src_page_landscape| is true if the source page orientation is landscape.
-// |page_size| has the actual destination page size in points.
-// |content_rect| has the actual destination page printable area values in
-// points.
-void SetPageSizeAndContentRect(bool rotated,
- bool is_src_page_landscape,
- pp::Size* page_size,
- pp::Rect* content_rect) {
- bool is_dst_page_landscape = page_size->width() > page_size->height();
- bool page_orientation_mismatched = is_src_page_landscape !=
- is_dst_page_landscape;
- bool rotate_dst_page = rotated ^ page_orientation_mismatched;
- if (rotate_dst_page) {
- page_size->SetSize(page_size->height(), page_size->width());
- content_rect->SetRect(content_rect->y(), content_rect->x(),
- content_rect->height(), content_rect->width());
- }
-}
-
-// Calculate the scale factor between |content_rect| and a page of size
-// |src_width| x |src_height|.
-//
-// |scale_to_fit| is true, if we need to calculate the scale factor.
-// |content_rect| specifies the printable area of the destination page, with
-// origin at left-bottom. Values are in points.
-// |src_width| specifies the source page width in points.
-// |src_height| specifies the source page height in points.
-// |rotated| True if source page is rotated 90 degree or 270 degree.
-double CalculateScaleFactor(bool scale_to_fit,
- const pp::Rect& content_rect,
- double src_width, double src_height, bool rotated) {
- if (!scale_to_fit || src_width == 0 || src_height == 0)
- return 1.0;
-
- double actual_source_page_width = rotated ? src_height : src_width;
- double actual_source_page_height = rotated ? src_width : src_height;
- double ratio_x = static_cast<double>(content_rect.width()) /
- actual_source_page_width;
- double ratio_y = static_cast<double>(content_rect.height()) /
- actual_source_page_height;
- return std::min(ratio_x, ratio_y);
-}
-
-// Compute source clip box boundaries based on the crop box / media box of
-// source page and scale factor.
-//
-// |page| Handle to the source page. Returned by FPDF_LoadPage function.
-// |scale_factor| specifies the scale factor that should be applied to source
-// clip box boundaries.
-// |rotated| True if source page is rotated 90 degree or 270 degree.
-// |clip_box| out param to hold the computed source clip box values.
-void CalculateClipBoxBoundary(FPDF_PAGE page, double scale_factor, bool rotated,
- ClipBox* clip_box) {
- if (!FPDFPage_GetCropBox(page, &clip_box->left, &clip_box->bottom,
- &clip_box->right, &clip_box->top)) {
- if (!FPDFPage_GetMediaBox(page, &clip_box->left, &clip_box->bottom,
- &clip_box->right, &clip_box->top)) {
- // Make the default size to be letter size (8.5" X 11"). We are just
- // following the PDFium way of handling these corner cases. PDFium always
- // consider US-Letter as the default page size.
- float paper_width = 612;
- float paper_height = 792;
- clip_box->left = 0;
- clip_box->bottom = 0;
- clip_box->right = rotated ? paper_height : paper_width;
- clip_box->top = rotated ? paper_width : paper_height;
- }
- }
- clip_box->left *= scale_factor;
- clip_box->right *= scale_factor;
- clip_box->bottom *= scale_factor;
- clip_box->top *= scale_factor;
-}
-
-// Calculate the clip box translation offset for a page that does need to be
-// scaled. All parameters are in points.
-//
-// |content_rect| specifies the printable area of the destination page, with
-// origin at left-bottom.
-// |source_clip_box| specifies the source clip box positions, relative to
-// origin at left-bottom.
-// |offset_x| and |offset_y| will contain the final translation offsets for the
-// source clip box, relative to origin at left-bottom.
-void CalculateScaledClipBoxOffset(const pp::Rect& content_rect,
- const ClipBox& source_clip_box,
- double* offset_x, double* offset_y) {
- const float clip_box_width = source_clip_box.right - source_clip_box.left;
- const float clip_box_height = source_clip_box.top - source_clip_box.bottom;
-
- // Center the intended clip region to real clip region.
- *offset_x = (content_rect.width() - clip_box_width) / 2 + content_rect.x() -
- source_clip_box.left;
- *offset_y = (content_rect.height() - clip_box_height) / 2 + content_rect.y() -
- source_clip_box.bottom;
-}
-
-// Calculate the clip box offset for a page that does not need to be scaled.
-// All parameters are in points.
-//
-// |content_rect| specifies the printable area of the destination page, with
-// origin at left-bottom.
-// |rotation| specifies the source page rotation values which are N / 90
-// degrees.
-// |page_width| specifies the screen destination page width.
-// |page_height| specifies the screen destination page height.
-// |source_clip_box| specifies the source clip box positions, relative to origin
-// at left-bottom.
-// |offset_x| and |offset_y| will contain the final translation offsets for the
-// source clip box, relative to origin at left-bottom.
-void CalculateNonScaledClipBoxOffset(const pp::Rect& content_rect, int rotation,
- int page_width, int page_height,
- const ClipBox& source_clip_box,
- double* offset_x, double* offset_y) {
- // Align the intended clip region to left-top corner of real clip region.
- switch (rotation) {
- case 0:
- *offset_x = -1 * source_clip_box.left;
- *offset_y = page_height - source_clip_box.top;
- break;
- case 1:
- *offset_x = 0;
- *offset_y = -1 * source_clip_box.bottom;
- break;
- case 2:
- *offset_x = page_width - source_clip_box.right;
- *offset_y = 0;
- break;
- case 3:
- *offset_x = page_height - source_clip_box.right;
- *offset_y = page_width - source_clip_box.top;
- break;
- default:
- NOTREACHED();
- break;
- }
-}
-
-// This formats a string with special 0xfffe end-of-line hyphens the same way
-// as Adobe Reader. When a hyphen is encountered, the next non-CR/LF whitespace
-// becomes CR+LF and the hyphen is erased. If there is no whitespace between
-// two hyphens, the latter hyphen is erased and ignored.
-void FormatStringWithHyphens(base::string16* text) {
- // First pass marks all the hyphen positions.
- struct HyphenPosition {
- HyphenPosition() : position(0), next_whitespace_position(0) {}
- size_t position;
- size_t next_whitespace_position; // 0 for none
- };
- std::vector<HyphenPosition> hyphen_positions;
- HyphenPosition current_hyphen_position;
- bool current_hyphen_position_is_valid = false;
- const base::char16 kPdfiumHyphenEOL = 0xfffe;
-
- for (size_t i = 0; i < text->size(); ++i) {
- const base::char16& current_char = (*text)[i];
- if (current_char == kPdfiumHyphenEOL) {
- if (current_hyphen_position_is_valid)
- hyphen_positions.push_back(current_hyphen_position);
- current_hyphen_position = HyphenPosition();
- current_hyphen_position.position = i;
- current_hyphen_position_is_valid = true;
- } else if (IsWhitespace(current_char)) {
- if (current_hyphen_position_is_valid) {
- if (current_char != L'\r' && current_char != L'\n')
- current_hyphen_position.next_whitespace_position = i;
- hyphen_positions.push_back(current_hyphen_position);
- current_hyphen_position_is_valid = false;
- }
- }
- }
- if (current_hyphen_position_is_valid)
- hyphen_positions.push_back(current_hyphen_position);
-
- // With all the hyphen positions, do the search and replace.
- while (!hyphen_positions.empty()) {
- static const base::char16 kCr[] = {L'\r', L'\0'};
- const HyphenPosition& position = hyphen_positions.back();
- if (position.next_whitespace_position != 0) {
- (*text)[position.next_whitespace_position] = L'\n';
- text->insert(position.next_whitespace_position, kCr);
- }
- text->erase(position.position, 1);
- hyphen_positions.pop_back();
- }
-
- // Adobe Reader also get rid of trailing spaces right before a CRLF.
- static const base::char16 kSpaceCrCn[] = {L' ', L'\r', L'\n', L'\0'};
- static const base::char16 kCrCn[] = {L'\r', L'\n', L'\0'};
- ReplaceSubstringsAfterOffset(text, 0, kSpaceCrCn, kCrCn);
-}
-
-// Replace CR/LF with just LF on POSIX.
-void FormatStringForOS(base::string16* text) {
-#if defined(OS_POSIX)
- static const base::char16 kCr[] = {L'\r', L'\0'};
- static const base::char16 kBlank[] = {L'\0'};
- base::ReplaceChars(*text, kCr, kBlank, text);
-#elif defined(OS_WIN)
- // Do nothing
-#else
- NOTIMPLEMENTED();
-#endif
-}
-
-} // namespace
-
-bool InitializeSDK(void* data) {
- FPDF_InitLibrary(data);
-
-#if defined(OS_LINUX)
- // Font loading doesn't work in the renderer sandbox in Linux.
- FPDF_SetSystemFontInfo(&g_font_info);
-#endif
-
- FSDK_SetOOMHandler(&g_oom_info);
- FSDK_SetUnSpObjProcessHandler(&g_unsuppored_info);
-
- return true;
-}
-
-void ShutdownSDK() {
- FPDF_DestroyLibrary();
-}
-
-PDFEngine* PDFEngine::Create(PDFEngine::Client* client) {
- return new PDFiumEngine(client);
-}
-
-PDFiumEngine::PDFiumEngine(PDFEngine::Client* client)
- : client_(client),
- current_zoom_(1.0),
- current_rotation_(0),
- doc_loader_(this),
- password_tries_remaining_(0),
- doc_(NULL),
- form_(NULL),
- defer_page_unload_(false),
- selecting_(false),
- mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA,
- PDFiumPage::LinkTarget()),
- next_page_to_search_(-1),
- last_page_to_search_(-1),
- last_character_index_to_search_(-1),
- current_find_index_(-1),
- resume_find_index_(-1),
- permissions_(0),
- fpdf_availability_(NULL),
- next_timer_id_(0),
- last_page_mouse_down_(-1),
- first_visible_page_(-1),
- most_visible_page_(-1),
- called_do_document_action_(false),
- render_grayscale_(false),
- progressive_paint_timeout_(0),
- getting_password_(false) {
- find_factory_.Initialize(this);
- password_factory_.Initialize(this);
-
- file_access_.m_FileLen = 0;
- file_access_.m_GetBlock = &GetBlock;
- file_access_.m_Param = &doc_loader_;
-
- file_availability_.version = 1;
- file_availability_.IsDataAvail = &IsDataAvail;
- file_availability_.loader = &doc_loader_;
-
- download_hints_.version = 1;
- download_hints_.AddSegment = &AddSegment;
- download_hints_.loader = &doc_loader_;
-
- // Initialize FPDF_FORMFILLINFO member variables. Deriving from this struct
- // allows the static callbacks to be able to cast the FPDF_FORMFILLINFO in
- // callbacks to ourself instead of maintaining a map of them to
- // PDFiumEngine.
- FPDF_FORMFILLINFO::version = 1;
- FPDF_FORMFILLINFO::m_pJsPlatform = this;
- FPDF_FORMFILLINFO::Release = NULL;
- FPDF_FORMFILLINFO::FFI_Invalidate = Form_Invalidate;
- FPDF_FORMFILLINFO::FFI_OutputSelectedRect = Form_OutputSelectedRect;
- FPDF_FORMFILLINFO::FFI_SetCursor = Form_SetCursor;
- FPDF_FORMFILLINFO::FFI_SetTimer = Form_SetTimer;
- FPDF_FORMFILLINFO::FFI_KillTimer = Form_KillTimer;
- FPDF_FORMFILLINFO::FFI_GetLocalTime = Form_GetLocalTime;
- FPDF_FORMFILLINFO::FFI_OnChange = Form_OnChange;
- FPDF_FORMFILLINFO::FFI_GetPage = Form_GetPage;
- FPDF_FORMFILLINFO::FFI_GetCurrentPage = Form_GetCurrentPage;
- FPDF_FORMFILLINFO::FFI_GetRotation = Form_GetRotation;
- FPDF_FORMFILLINFO::FFI_ExecuteNamedAction = Form_ExecuteNamedAction;
- FPDF_FORMFILLINFO::FFI_SetTextFieldFocus = Form_SetTextFieldFocus;
- FPDF_FORMFILLINFO::FFI_DoURIAction = Form_DoURIAction;
- FPDF_FORMFILLINFO::FFI_DoGoToAction = Form_DoGoToAction;
-#ifdef _TEST_XFA
- FPDF_FORMFILLINFO::FFI_EmailTo = Form_EmailTo;
- FPDF_FORMFILLINFO::FFI_DisplayCaret = Form_DisplayCaret;
- //FPDF_FORMFILLINFO::FFI_GetCurDocumentIndex = Form_GetCurDocumentIndex;
- //FPDF_FORMFILLINFO::FFI_GetDocumentCount = Form_GetDocumentCount;
- FPDF_FORMFILLINFO::FFI_SetCurrentPage = Form_SetCurrentPage;
- FPDF_FORMFILLINFO::FFI_GetCurrentPageIndex = Form_GetCurrentPageIndex;
- FPDF_FORMFILLINFO::FFI_GetPageViewRect = Form_GetPageViewRect;
- FPDF_FORMFILLINFO::FFI_GetPlatform = Form_GetPlatform;
- FPDF_FORMFILLINFO::FFI_PopupMenu = Form_PopupMenu;
- FPDF_FORMFILLINFO::FFI_PostRequestURL = Form_PostRequestURL;
- FPDF_FORMFILLINFO::FFI_PutRequestURL = Form_PutRequestURL;
-// FPDF_FORMFILLINFO::FFI_ShowFileDialog = Form_ShowFileDialog;
- FPDF_FORMFILLINFO::FFI_UploadTo = Form_UploadTo;
- FPDF_FORMFILLINFO::FFI_DownloadFromURL = Form_DownloadFromURL;
- // FPDF_FORMFILLINFO::FFI_GetFilePath = MyForm_GetFilePath;
- FPDF_FORMFILLINFO::FFI_OpenFile = Form_OpenFile;
- FPDF_FORMFILLINFO::FFI_GotoURL = Form_GotoURL;
- FPDF_FORMFILLINFO::FFI_GetLanguage = Form_GetLanguage;
-#endif // _TEST_XFA
- IPDF_JSPLATFORM::version = 1;
- IPDF_JSPLATFORM::app_alert = Form_Alert;
- IPDF_JSPLATFORM::app_beep = Form_Beep;
- IPDF_JSPLATFORM::app_response = Form_Response;
- IPDF_JSPLATFORM::Doc_getFilePath = Form_GetFilePath;
- IPDF_JSPLATFORM::Doc_mail = Form_Mail;
- IPDF_JSPLATFORM::Doc_print = Form_Print;
- IPDF_JSPLATFORM::Doc_submitForm = Form_SubmitForm;
- IPDF_JSPLATFORM::Doc_gotoPage = Form_GotoPage;
- IPDF_JSPLATFORM::Field_browse = Form_Browse;
-
- IFSDK_PAUSE::version = 1;
- IFSDK_PAUSE::user = NULL;
- IFSDK_PAUSE::NeedToPauseNow = Pause_NeedToPauseNow;
-}
-
-PDFiumEngine::~PDFiumEngine() {
- for (size_t i = 0; i < pages_.size(); ++i)
- pages_[i]->Unload();
-
- if (doc_) {
- if (form_) {
- FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WC);
- }
- FPDF_CloseDocument(doc_);
- if (form_) {
- FPDFDOC_ExitFormFillEnviroument(form_);
- }
- }
-
- if (fpdf_availability_)
- FPDFAvail_Destroy(fpdf_availability_);
-
- STLDeleteElements(&pages_);
-}
-
-#ifdef _TEST_XFA
-
-typedef struct _FPDF_FILE {
- FPDF_FILEHANDLER fileHandler;
- FILE* file;
-}FPDF_FILE;
-
-
-void Sample_Release(FPDF_LPVOID clientData) {
- if (!clientData) return;
-
- fclose(((FPDF_FILE*)clientData)->file);
- delete ((FPDF_FILE*)clientData);
-}
-
-FPDF_DWORD Sample_GetSize(FPDF_LPVOID clientData) {
- if (!clientData) return 0;
-
- long curPos = ftell(((FPDF_FILE*)clientData)->file);
- fseek(((FPDF_FILE*)clientData)->file, 0, SEEK_END);
- long size = ftell(((FPDF_FILE*)clientData)->file);
- fseek(((FPDF_FILE*)clientData)->file, curPos, SEEK_SET);
-
- return (FPDF_DWORD)size;
-}
-
-FPDF_RESULT Sample_ReadBlock(FPDF_LPVOID clientData, FPDF_DWORD offset, FPDF_LPVOID buffer, FPDF_DWORD size) {
- if (!clientData) return -1;
-
- fseek(((FPDF_FILE*)clientData)->file, (long)offset, SEEK_SET);
- size_t readSize = fread(buffer, 1, size, ((FPDF_FILE*)clientData)->file);
- return readSize == size ? 0 : -1;
-}
-
-FPDF_RESULT Sample_WriteBlock(FPDF_LPVOID clientData, FPDF_DWORD offset, FPDF_LPCVOID buffer, FPDF_DWORD size) {
- if (!clientData) return -1;
-
- fseek(((FPDF_FILE*)clientData)->file, (long)offset, SEEK_SET);
- //Write data
- size_t writeSize = fwrite(buffer, 1, size, ((FPDF_FILE*)clientData)->file);
- return writeSize == size ? 0 : -1;
-}
-
-FPDF_RESULT Sample_Flush(FPDF_LPVOID clientData) {
- if (!clientData) return -1;
-
- //Flush file
- fflush(((FPDF_FILE*)clientData)->file);
-
- return 0;
-}
-
-FPDF_RESULT Sample_Truncate(FPDF_LPVOID clientData, FPDF_DWORD size) {
- return 0;
-}
-
-
-void PDFiumEngine::Form_EmailTo(FPDF_FORMFILLINFO* pThis,
- FPDF_FILEHANDLER* fileHandler,
- FPDF_WIDESTRING to,
- FPDF_WIDESTRING subject,
- FPDF_WIDESTRING cc,
- FPDF_WIDESTRING bcc,
- FPDF_WIDESTRING message) {
- std::string to_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to));
- std::string subject_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(subject));
- std::string cc_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(cc));
- std::string bcc_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(bcc));
- std::string message_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(message));
-
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis);
- engine->client_->Email(to_str, cc_str, bcc_str, subject_str, message_str);
-}
-
-void PDFiumEngine::Form_DisplayCaret(FPDF_FORMFILLINFO* pThis,
- FPDF_PAGE page, FPDF_BOOL bVisible,
- double left, double top, double right, double bottom) {
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis);
- engine->client_->UpdateCursor(PP_CURSORTYPE_IBEAM);
- std::vector<pp::Rect> tickmarks;
- pp::Rect rect(left, top, right, bottom);
- tickmarks.push_back(rect);
- engine->client_->UpdateTickMarks(tickmarks);
-}
-
-//int PDFiumEngine::Form_GetCurDocumentIndex(FPDF_FORMFILLINFO* pThis) {
-// PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis);
-// engine->client_->RunJSCmd("alert(\"GetCurDocumentIndex\")");
-// return 0;
-//}
-//
-//int PDFiumEngine::Form_GetDocumentCount(FPDF_FORMFILLINFO* pThis) {
-// PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis);
-// engine->client_->RunJSCmd("alert(\"GetCurDocumentCount\")");
-// return 0;
-//}
-
-void PDFiumEngine::Form_SetCurrentPage(FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document, int iCurPage) {
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis);
- pp::Rect pageViewRect = engine->GetPageContentsRect(iCurPage);
- engine->ScrolledToYPosition(pageViewRect.height());
- pp::Point pos(1, pageViewRect.height());
- engine->SetScrollPosition(pos);
-}
-
-int PDFiumEngine::Form_GetCurrentPageIndex(FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document) {
- //int pageCount = FPDF_GetPageCount(document);
- int pageIndex = -1;
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis);
- pageIndex = engine->GetMostVisiblePage();
- return pageIndex;
-}
-
-void PDFiumEngine::Form_GetPageViewRect(FPDF_FORMFILLINFO* pThis,
- FPDF_PAGE page,
- double* left, double* top, double* right, double* bottom) {
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis);
- int page_index = engine->GetMostVisiblePage();
- pp::Rect pageViewRect = engine->GetPageContentsRect(page_index);
-
- *left = pageViewRect.x();
- *right = pageViewRect.width() + pageViewRect.x();
- *top = pageViewRect.y();
- *bottom = pageViewRect.height();
-
- std::string javascript = "alert(\"PageViewRect:"
- + base::DoubleToString(*left) + ","
- + base::DoubleToString(*right) + ","
- + base::DoubleToString(*top) + ","
- + base::DoubleToString(*bottom) + ","
- + "\")";
-
-}
-
-int PDFiumEngine::Form_GetPlatform(FPDF_FORMFILLINFO* pThis,
- void* platform,
- int length) {
- int platform_flag = -1;
-#if defined(WIN32)
- platform_flag = 0;
-#elif defined(__linux__)
- platform_flag = 1;
-#else
- platform_flag = 2;
-#endif
- std::string javascript = "alert(\"Platform:"
- + base::DoubleToString(platform_flag)
- + "\")";
- //platform = new char[3];
- //char tem[10] = "WIN";
- //strncpy((char*)platform, tem, 3);
-
- return 3;
-}
-
-FPDF_BOOL PDFiumEngine::Form_PopupMenu(FPDF_FORMFILLINFO* pThis,
- FPDF_PAGE page,
- FPDF_WIDGET hWidget,
- int menuFlag, float x, float y) {
- return false;
-}
-
-FPDF_BOOL PDFiumEngine::Form_PostRequestURL(FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING wsURL,
- FPDF_WIDESTRING wsData, FPDF_WIDESTRING wsContentType,
- FPDF_WIDESTRING wsEncode, FPDF_WIDESTRING wsHeader, FPDF_BSTR* respone) {
- std::string url_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsURL));
- std::string data_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsData));
- std::string content_type_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsContentType));
- std::string encode_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsEncode));
- std::string header_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsHeader));
-
- std::string javascript = "alert(\"Post:"
- + url_str + "," + data_str + "," + content_type_str + ","
- + encode_str + "," + header_str
- + "\")";
- return true;
-}
-
-FPDF_BOOL PDFiumEngine::Form_PutRequestURL(FPDF_FORMFILLINFO* pThis,
- FPDF_WIDESTRING wsURL, FPDF_WIDESTRING wsData, FPDF_WIDESTRING wsEncode) {
- std::string url_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsURL));
- std::string data_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsData));
- std::string encode_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsEncode));
-
- std::string javascript = "alert(\"Put:"
- + url_str + "," + data_str + "," + encode_str
- + "\")";
-
- return true;
-}
-
-//FPDF_BOOL PDFiumEngine::Form_ShowFileDialog(FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING wsTitle, FPDF_WIDESTRING wsFilter, FPDF_BOOL isOpen, FPDF_STRINGHANDLE pathArr) {
-// int tem = 1;
-// tem++;
-// return false;
-//}
-
-void PDFiumEngine::Form_UploadTo(FPDF_FORMFILLINFO* pThis, FPDF_FILEHANDLER* fileHandler, int fileFlag, FPDF_WIDESTRING uploadTo) {
- std::string to_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(uploadTo));
-
-}
-
-FPDF_LPFILEHANDLER PDFiumEngine::Form_DownloadFromURL(FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING URL) {
- std::string url_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(URL));
-
-
- // Get URL data...
- FILE* file = fopen(FXQA_TESTFILE("downloadtest.tem"), "w");
- FPDF_FILE* pFileHander = new FPDF_FILE;
- pFileHander->file = file;
- pFileHander->fileHandler.clientData = pFileHander;
- pFileHander->fileHandler.Flush = Sample_Flush;
- pFileHander->fileHandler.GetSize = Sample_GetSize;
- pFileHander->fileHandler.ReadBlock = Sample_ReadBlock;
- pFileHander->fileHandler.Release = Sample_Release;
- pFileHander->fileHandler.Truncate = Sample_Truncate;
- pFileHander->fileHandler.WriteBlock = Sample_WriteBlock;
-
- return &pFileHander->fileHandler;
-}
-
-//FPDF_BOOL PDFiumEngine::MyForm_GetFilePath(FPDF_FORMFILLINFO* pThis, FPDF_FILEHANDLER* pFileHandler, void* filePath, int length) {
-// //std::string filePath = engine->client_->FileOpen(fileFlag);
-// if (filePath == NULL) {
-// std::string javascript = "alert(\"GetFilePath:NULL\")";
-// PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis);
-// engine->client_->RunJSCmd(javascript);
-// return false;
-// }
-// std::string filePath_str = (char*)filePath;
-//
-// std::string javascript = "alert(\"GetFilePath:" + filePath_str + "\")";
-// PDFiumEngine* engine = static_cast<PDFiumEngine*>(pThis);
-// engine->client_->RunJSCmd(javascript);
-//
-// FILE* file = fopen(FXQA_TESTFILE("tem.xdp"), "w");
-// FPDF_FILE* pFileHander = new FPDF_FILE;
-// pFileHander->file = file;
-// pFileHander->fileHandler.clientData = pFileHander;
-// pFileHander->fileHandler.Flush = Sample_Flush;
-// pFileHander->fileHandler.GetSize = Sample_GetSize;
-// pFileHander->fileHandler.ReadBlock = Sample_ReadBlock;
-// pFileHander->fileHandler.Release = Sample_Release;
-// pFileHander->fileHandler.Truncate = Sample_Truncate;
-// pFileHander->fileHandler.WriteBlock = Sample_WriteBlock;
-//
-// pFileHandler = &pFileHander->fileHandler;
-//
-// return true;
-//}
-
-FPDF_FILEHANDLER* PDFiumEngine::Form_OpenFile(FPDF_FORMFILLINFO* pThis, int fileFlag, FPDF_WIDESTRING wsURL, const char* mode) {
- std::string url_str = "NULL";
- if (wsURL == NULL) {
- url_str = "NULL";
- }
- else {
- url_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsURL));
- }
- if (strncmp(mode, "wb", 2) == 0) {
-
- FILE* file = fopen(FXQA_TESTFILE("tem.txt"), mode);
- FPDF_FILE* pFileHander = new FPDF_FILE;
- pFileHander->file = file;
- pFileHander->fileHandler.clientData = pFileHander;
- pFileHander->fileHandler.Flush = Sample_Flush;
- pFileHander->fileHandler.GetSize = Sample_GetSize;
- pFileHander->fileHandler.ReadBlock = Sample_ReadBlock;
- pFileHander->fileHandler.Release = Sample_Release;
- pFileHander->fileHandler.Truncate = Sample_Truncate;
- pFileHander->fileHandler.WriteBlock = Sample_WriteBlock;
- return &pFileHander->fileHandler;
- }
- else {
- url_str = base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsURL));
- }
- return NULL;
-}
-
-
-void PDFiumEngine::Form_GotoURL(FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document, FPDF_WIDESTRING wsURL) {
- std::string url_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(wsURL));
-}
-
-int PDFiumEngine::Form_GetLanguage(FPDF_FORMFILLINFO* pThis, void* language, int length) {
- return 0;
-}
-
-#endif // _TEST_XFA
-
-int PDFiumEngine::GetBlock(void* param, unsigned long position,
- unsigned char* buffer, unsigned long size) {
- DocumentLoader* loader = static_cast<DocumentLoader*>(param);
- return loader->GetBlock(position, size, buffer);
-}
-
-bool PDFiumEngine::IsDataAvail(FX_FILEAVAIL* param,
- size_t offset, size_t size) {
- PDFiumEngine::FileAvail* file_avail =
- static_cast<PDFiumEngine::FileAvail*>(param);
- return file_avail->loader->IsDataAvailable(offset, size);
-}
-
-void PDFiumEngine::AddSegment(FX_DOWNLOADHINTS* param,
- size_t offset, size_t size) {
- PDFiumEngine::DownloadHints* download_hints =
- static_cast<PDFiumEngine::DownloadHints*>(param);
- return download_hints->loader->RequestData(offset, size);
-}
-
-bool PDFiumEngine::New(const char* url) {
- url_ = url;
- headers_ = std::string();
- return true;
-}
-
-bool PDFiumEngine::New(const char* url,
- const char* headers) {
- url_ = url;
- if (!headers)
- headers_ = std::string();
- else
- headers_ = headers;
- return true;
-}
-
-void PDFiumEngine::PageOffsetUpdated(const pp::Point& page_offset) {
- page_offset_ = page_offset;
-}
-
-void PDFiumEngine::PluginSizeUpdated(const pp::Size& size) {
- CancelPaints();
-
- plugin_size_ = size;
- CalculateVisiblePages();
-}
-
-void PDFiumEngine::ScrolledToXPosition(int position) {
- CancelPaints();
-
- int old_x = position_.x();
- position_.set_x(position);
- CalculateVisiblePages();
- client_->Scroll(pp::Point(old_x - position, 0));
-}
-
-void PDFiumEngine::ScrolledToYPosition(int position) {
- CancelPaints();
-
- int old_y = position_.y();
- position_.set_y(position);
- CalculateVisiblePages();
- client_->Scroll(pp::Point(0, old_y - position));
-}
-
-void PDFiumEngine::PrePaint() {
- for (size_t i = 0; i < progressive_paints_.size(); ++i)
- progressive_paints_[i].painted_ = false;
-}
-
-void PDFiumEngine::Paint(const pp::Rect& rect,
- pp::ImageData* image_data,
- std::vector<pp::Rect>* ready,
- std::vector<pp::Rect>* pending) {
- pp::Rect leftover = rect;
- for (size_t i = 0; i < visible_pages_.size(); ++i) {
- int index = visible_pages_[i];
- pp::Rect page_rect = pages_[index]->rect();
- // Convert the current page's rectangle to screen rectangle. We do this
- // instead of the reverse (converting the dirty rectangle from screen to
- // page coordinates) because then we'd have to convert back to screen
- // coordinates, and the rounding errors sometime leave pixels dirty or even
- // move the text up or down a pixel when zoomed.
- pp::Rect page_rect_in_screen = GetPageScreenRect(index);
- pp::Rect dirty_in_screen = page_rect_in_screen.Intersect(leftover);
- if (dirty_in_screen.IsEmpty())
- continue;
-
- leftover = leftover.Subtract(dirty_in_screen);
-
- if (pages_[index]->available()) {
- int progressive = GetProgressiveIndex(index);
- if (progressive != -1 &&
- progressive_paints_[progressive].rect != dirty_in_screen) {
- // The PDFium code can only handle one progressive paint at a time, so
- // queue this up. Previously we used to merge the rects when this
- // happened, but it made scrolling up on complex PDFs very slow since
- // there would be a damaged rect at the top (from scroll) and at the
- // bottom (from toolbar).
- pending->push_back(dirty_in_screen);
- continue;
- }
-
- if (progressive == -1) {
- progressive = StartPaint(index, dirty_in_screen);
- progressive_paint_timeout_ = kMaxInitialProgressivePaintTimeMs;
- } else {
- progressive_paint_timeout_ = kMaxProgressivePaintTimeMs;
- }
-
- progressive_paints_[progressive].painted_ = true;
- if (ContinuePaint(progressive, image_data)) {
- FinishPaint(progressive, image_data);
- ready->push_back(dirty_in_screen);
- } else {
- pending->push_back(dirty_in_screen);
- }
- } else {
- PaintUnavailablePage(index, dirty_in_screen, image_data);
- ready->push_back(dirty_in_screen);
- }
- }
-}
-
-void PDFiumEngine::PostPaint() {
- for (size_t i = 0; i < progressive_paints_.size(); ++i) {
- if (progressive_paints_[i].painted_)
- continue;
-
- // This rectangle must have been merged with another one, that's why we
- // weren't asked to paint it. Remove it or otherwise we'll never finish
- // painting.
- FPDF_RenderPage_Close(
- pages_[progressive_paints_[i].page_index]->GetPage());
- FPDFBitmap_Destroy(progressive_paints_[i].bitmap);
- progressive_paints_.erase(progressive_paints_.begin() + i);
- --i;
- }
-}
-
-bool PDFiumEngine::HandleDocumentLoad(const pp::URLLoader& loader) {
- password_tries_remaining_ = kMaxPasswordTries;
- return doc_loader_.Init(loader, url_, headers_);
-}
-
-pp::Instance* PDFiumEngine::GetPluginInstance() {
- return client_->GetPluginInstance();
-}
-
-pp::URLLoader PDFiumEngine::CreateURLLoader() {
- return client_->CreateURLLoader();
-}
-
-void PDFiumEngine::AppendPage(PDFEngine* engine, int index) {
- // Unload and delete the blank page before appending.
- pages_[index]->Unload();
- pages_[index]->set_calculated_links(false);
- pp::Size curr_page_size = GetPageSize(index);
- FPDFPage_Delete(doc_, index);
- FPDF_ImportPages(doc_,
- static_cast<PDFiumEngine*>(engine)->doc(),
- "1",
- index);
- pp::Size new_page_size = GetPageSize(index);
- if (curr_page_size != new_page_size)
- LoadPageInfo(true);
- client_->Invalidate(GetPageScreenRect(index));
-}
-
-pp::Point PDFiumEngine::GetScrollPosition() {
- return position_;
-}
-
-void PDFiumEngine::SetScrollPosition(const pp::Point& position) {
- position_ = position;
-}
-
-bool PDFiumEngine::IsProgressiveLoad() {
- return doc_loader_.is_partial_document();
-}
-
-void PDFiumEngine::OnPartialDocumentLoaded() {
- file_access_.m_FileLen = doc_loader_.document_size();
- fpdf_availability_ = FPDFAvail_Create(&file_availability_, &file_access_);
- DCHECK(fpdf_availability_);
-
- // Currently engine does not deal efficiently with some non-linearized files.
- // See http://code.google.com/p/chromium/issues/detail?id=59400
- // To improve user experience we download entire file for non-linearized PDF.
- if (!FPDFAvail_IsLinearized(fpdf_availability_)) {
- doc_loader_.RequestData(0, doc_loader_.document_size());
- return;
- }
-
- LoadDocument();
-}
-
-void PDFiumEngine::OnPendingRequestComplete() {
- if (!doc_ || !form_) {
- LoadDocument();
- return;
- }
-
- // LoadDocument() will result in |pending_pages_| being reset so there's no
- // need to run the code below in that case.
- bool update_pages = false;
- std::vector<int> still_pending;
- for (size_t i = 0; i < pending_pages_.size(); ++i) {
- if (CheckPageAvailable(pending_pages_[i], &still_pending)) {
- update_pages = true;
- if (IsPageVisible(pending_pages_[i]))
- client_->Invalidate(GetPageScreenRect(pending_pages_[i]));
- }
- }
- pending_pages_.swap(still_pending);
- if (update_pages)
- LoadPageInfo(true);
-}
-
-void PDFiumEngine::OnNewDataAvailable() {
- client_->DocumentLoadProgress(doc_loader_.GetAvailableData(),
- doc_loader_.document_size());
-}
-
-void PDFiumEngine::OnDocumentComplete() {
- if (!doc_ || !form_) {
- file_access_.m_FileLen = doc_loader_.document_size();
- LoadDocument();
- return;
- }
-
- bool need_update = false;
- for (size_t i = 0; i < pages_.size(); ++i) {
- if (pages_[i]->available())
- continue;
-
- pages_[i]->set_available(true);
- // We still need to call IsPageAvail() even if the whole document is
- // already downloaded.
- FPDFAvail_IsPageAvail(fpdf_availability_, i, &download_hints_);
- need_update = true;
- if (IsPageVisible(i))
- client_->Invalidate(GetPageScreenRect(i));
- }
- if (need_update)
- LoadPageInfo(true);
-
- FinishLoadingDocument();
-}
-
-void PDFiumEngine::FinishLoadingDocument() {
- DCHECK(doc_loader_.IsDocumentComplete() && doc_);
- if (called_do_document_action_)
- return;
- called_do_document_action_ = true;
-
- // These can only be called now, as the JS might end up needing a page.
- FORM_DoDocumentJSAction(form_);
- FORM_DoDocumentOpenAction(form_);
- if (most_visible_page_ != -1) {
- FPDF_PAGE new_page = pages_[most_visible_page_]->GetPage();
- FORM_DoPageAAction(new_page, form_, FPDFPAGE_AACTION_OPEN);
- }
-
- if (doc_) // This can only happen if loading |doc_| fails.
- client_->DocumentLoadComplete(pages_.size());
-}
-
-void PDFiumEngine::UnsupportedFeature(int type) {
- std::string feature;
- switch (type) {
- case FPDF_UNSP_DOC_XFAFORM:
- //feature = "XFA";
- break;
- case FPDF_UNSP_DOC_PORTABLECOLLECTION:
- feature = "Portfolios_Packages";
- break;
- case FPDF_UNSP_DOC_ATTACHMENT:
- case FPDF_UNSP_ANNOT_ATTACHMENT:
- feature = "Attachment";
- break;
- case FPDF_UNSP_DOC_SECURITY:
- feature = "Rights_Management";
- break;
- case FPDF_UNSP_DOC_SHAREDREVIEW:
- feature = "Shared_Review";
- break;
- case FPDF_UNSP_DOC_SHAREDFORM_ACROBAT:
- case FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM:
- case FPDF_UNSP_DOC_SHAREDFORM_EMAIL:
- feature = "Shared_Form";
- break;
- case FPDF_UNSP_ANNOT_3DANNOT:
- feature = "3D";
- break;
- case FPDF_UNSP_ANNOT_MOVIE:
- feature = "Movie";
- break;
- case FPDF_UNSP_ANNOT_SOUND:
- feature = "Sound";
- break;
- case FPDF_UNSP_ANNOT_SCREEN_MEDIA:
- case FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA:
- feature = "Screen";
- break;
- case FPDF_UNSP_ANNOT_SIG:
- feature = "Digital_Signature";
- break;
- }
- client_->DocumentHasUnsupportedFeature(feature);
-}
-
-void PDFiumEngine::ContinueFind(int32_t result) {
- StartFind(current_find_text_.c_str(), !!result);
-}
-
-bool PDFiumEngine::HandleEvent(const pp::InputEvent& event) {
- DCHECK(!defer_page_unload_);
- defer_page_unload_ = true;
- bool rv = false;
- switch (event.GetType()) {
- case PP_INPUTEVENT_TYPE_MOUSEDOWN:
- rv = OnMouseDown(pp::MouseInputEvent(event));
- break;
- case PP_INPUTEVENT_TYPE_MOUSEUP:
- rv = OnMouseUp(pp::MouseInputEvent(event));
- break;
- case PP_INPUTEVENT_TYPE_MOUSEMOVE:
- rv = OnMouseMove(pp::MouseInputEvent(event));
- break;
- case PP_INPUTEVENT_TYPE_KEYDOWN:
- rv = OnKeyDown(pp::KeyboardInputEvent(event));
- break;
- case PP_INPUTEVENT_TYPE_KEYUP:
- rv = OnKeyUp(pp::KeyboardInputEvent(event));
- break;
- case PP_INPUTEVENT_TYPE_CHAR:
- rv = OnChar(pp::KeyboardInputEvent(event));
- break;
- default:
- break;
- }
-
- DCHECK(defer_page_unload_);
- defer_page_unload_ = false;
- for (size_t i = 0; i < deferred_page_unloads_.size(); ++i)
- pages_[deferred_page_unloads_[i]]->Unload();
- deferred_page_unloads_.clear();
- return rv;
-}
-
-uint32_t PDFiumEngine::QuerySupportedPrintOutputFormats() {
- if (!HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY))
- return 0;
- return PP_PRINTOUTPUTFORMAT_PDF;
-}
-
-void PDFiumEngine::PrintBegin() {
- FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_WP);
-}
-
-pp::Resource PDFiumEngine::PrintPages(
- const PP_PrintPageNumberRange_Dev* page_ranges, uint32_t page_range_count,
- const PP_PrintSettings_Dev& print_settings) {
- if (HasPermission(PDFEngine::PERMISSION_PRINT_HIGH_QUALITY))
- return PrintPagesAsPDF(page_ranges, page_range_count, print_settings);
- else if (HasPermission(PDFEngine::PERMISSION_PRINT_LOW_QUALITY))
- return PrintPagesAsRasterPDF(page_ranges, page_range_count, print_settings);
- return pp::Resource();
-}
-
-FPDF_DOCUMENT PDFiumEngine::CreateSinglePageRasterPdf(
- double source_page_width,
- double source_page_height,
- const PP_PrintSettings_Dev& print_settings,
- PDFiumPage* page_to_print) {
- FPDF_DOCUMENT temp_doc = FPDF_CreateNewDocument();
- if (!temp_doc)
- return temp_doc;
-
- const pp::Size& bitmap_size(page_to_print->rect().size());
-
- FPDF_PAGE temp_page =
- FPDFPage_New(temp_doc, 0, source_page_width, source_page_height);
-
- pp::ImageData image = pp::ImageData(client_->GetPluginInstance(),
- PP_IMAGEDATAFORMAT_BGRA_PREMUL,
- bitmap_size,
- false);
-
- FPDF_BITMAP bitmap = FPDFBitmap_CreateEx(bitmap_size.width(),
- bitmap_size.height(),
- FPDFBitmap_BGRx,
- image.data(),
- image.stride());
-
- // Clear the bitmap
- FPDFBitmap_FillRect(
- bitmap, 0, 0, bitmap_size.width(), bitmap_size.height(), 0xFFFFFFFF);
-
- pp::Rect page_rect = page_to_print->rect();
- FPDF_RenderPageBitmap(bitmap,
- page_to_print->GetPrintPage(),
- page_rect.x(),
- page_rect.y(),
- page_rect.width(),
- page_rect.height(),
- print_settings.orientation,
- FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH);
-
- double ratio_x = (static_cast<double>(bitmap_size.width()) * kPointsPerInch) /
- print_settings.dpi;
- double ratio_y =
- (static_cast<double>(bitmap_size.height()) * kPointsPerInch) /
- print_settings.dpi;
-
- // Add the bitmap to an image object and add the image object to the output
- // page.
- FPDF_PAGEOBJECT temp_img = FPDFPageObj_NewImgeObj(temp_doc);
- FPDFImageObj_SetBitmap(&temp_page, 1, temp_img, bitmap);
- FPDFImageObj_SetMatrix(temp_img, ratio_x, 0, 0, ratio_y, 0, 0);
- FPDFPage_InsertObject(temp_page, temp_img);
- FPDFPage_GenerateContent(temp_page);
- FPDF_ClosePage(temp_page);
-
- page_to_print->ClosePrintPage();
- FPDFBitmap_Destroy(bitmap);
-
- return temp_doc;
-}
-
-pp::Buffer_Dev PDFiumEngine::PrintPagesAsRasterPDF(
- const PP_PrintPageNumberRange_Dev* page_ranges, uint32_t page_range_count,
- const PP_PrintSettings_Dev& print_settings) {
- if (!page_range_count)
- return pp::Buffer_Dev();
-
- // If document is not downloaded yet, disable printing.
- if (doc_ && !doc_loader_.IsDocumentComplete())
- return pp::Buffer_Dev();
-
- FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument();
- if (!output_doc)
- return pp::Buffer_Dev();
-
- SaveSelectedFormForPrint();
-
- std::vector<PDFiumPage> pages_to_print;
- // width and height of source PDF pages.
- std::vector<std::pair<double, double> > source_page_sizes;
- // Collect pages to print and sizes of source pages.
- std::vector<uint32_t> page_numbers =
- GetPageNumbersFromPrintPageNumberRange(page_ranges, page_range_count);
- for (size_t i = 0; i < page_numbers.size(); ++i) {
- uint32_t page_number = page_numbers[i];
- FPDF_PAGE pdf_page = FPDF_LoadPage(doc_, page_number);
- double source_page_width = FPDF_GetPageWidth(pdf_page);
- double source_page_height = FPDF_GetPageHeight(pdf_page);
- source_page_sizes.push_back(std::make_pair(source_page_width,
- source_page_height));
-
- int width_in_pixels = ConvertUnit(source_page_width,
- static_cast<int>(kPointsPerInch),
- print_settings.dpi);
- int height_in_pixels = ConvertUnit(source_page_height,
- static_cast<int>(kPointsPerInch),
- print_settings.dpi);
-
- pp::Rect rect(width_in_pixels, height_in_pixels);
- pages_to_print.push_back(PDFiumPage(this, page_number, rect, true));
- FPDF_ClosePage(pdf_page);
- }
-
-#if defined(OS_LINUX)
- g_last_instance_id = client_->GetPluginInstance()->pp_instance();
-#endif
-
- size_t i = 0;
- for (; i < pages_to_print.size(); ++i) {
- double source_page_width = source_page_sizes[i].first;
- double source_page_height = source_page_sizes[i].second;
-
- // Use temp_doc to compress image by saving PDF to buffer.
- FPDF_DOCUMENT temp_doc = CreateSinglePageRasterPdf(source_page_width,
- source_page_height,
- print_settings,
- &pages_to_print[i]);
-
- if (!temp_doc)
- break;
-
- pp::Buffer_Dev buffer = GetFlattenedPrintData(temp_doc);
- FPDF_CloseDocument(temp_doc);
-
- PDFiumMemBufferFileRead file_read(buffer.data(), buffer.size());
- temp_doc = FPDF_LoadCustomDocument(&file_read, NULL);
-
- FPDF_BOOL imported = FPDF_ImportPages(output_doc, temp_doc, "1", i);
- FPDF_CloseDocument(temp_doc);
- if (!imported)
- break;
- }
-
- pp::Buffer_Dev buffer;
- if (i == pages_to_print.size()) {
- FPDF_CopyViewerPreferences(output_doc, doc_);
- FitContentsToPrintableAreaIfRequired(output_doc, print_settings);
- // Now flatten all the output pages.
- buffer = GetFlattenedPrintData(output_doc);
- }
- FPDF_CloseDocument(output_doc);
- return buffer;
-}
-
-pp::Buffer_Dev PDFiumEngine::GetFlattenedPrintData(const FPDF_DOCUMENT& doc) {
- int page_count = FPDF_GetPageCount(doc);
- bool flatten_succeeded = true;
- for (int i = 0; i < page_count; ++i) {
- FPDF_PAGE page = FPDF_LoadPage(doc, i);
- DCHECK(page);
- if (page) {
- int flatten_ret = FPDFPage_Flatten(page, FLAT_PRINT);
- FPDF_ClosePage(page);
- if (flatten_ret == FLATTEN_FAIL) {
- flatten_succeeded = false;
- break;
- }
- } else {
- flatten_succeeded = false;
- break;
- }
- }
- if (!flatten_succeeded) {
- FPDF_CloseDocument(doc);
- return pp::Buffer_Dev();
- }
-
- pp::Buffer_Dev buffer;
- PDFiumMemBufferFileWrite output_file_write;
- if (FPDF_SaveAsCopy(doc, &output_file_write, 0)) {
- buffer = pp::Buffer_Dev(
- client_->GetPluginInstance(), output_file_write.size());
- if (!buffer.is_null()) {
- memcpy(buffer.data(), output_file_write.buffer().c_str(),
- output_file_write.size());
- }
- }
- return buffer;
-}
-
-pp::Buffer_Dev PDFiumEngine::PrintPagesAsPDF(
- const PP_PrintPageNumberRange_Dev* page_ranges, uint32_t page_range_count,
- const PP_PrintSettings_Dev& print_settings) {
- if (!page_range_count)
- return pp::Buffer_Dev();
-
- DCHECK(doc_);
- FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument();
- if (!output_doc)
- return pp::Buffer_Dev();
-
- SaveSelectedFormForPrint();
-
- std::string page_number_str;
- for (uint32_t index = 0; index < page_range_count; ++index) {
- if (!page_number_str.empty())
- page_number_str.append(",");
- page_number_str.append(
- base::IntToString(page_ranges[index].first_page_number + 1));
- if (page_ranges[index].first_page_number !=
- page_ranges[index].last_page_number) {
- page_number_str.append("-");
- page_number_str.append(
- base::IntToString(page_ranges[index].last_page_number + 1));
- }
- }
-
- std::vector<uint32_t> page_numbers =
- GetPageNumbersFromPrintPageNumberRange(page_ranges, page_range_count);
- for (size_t i = 0; i < page_numbers.size(); ++i) {
- uint32_t page_number = page_numbers[i];
- pages_[page_number]->GetPage();
- if (!IsPageVisible(page_numbers[i]))
- pages_[page_number]->Unload();
- }
-
- FPDF_CopyViewerPreferences(output_doc, doc_);
- if (!FPDF_ImportPages(output_doc, doc_, page_number_str.c_str(), 0)) {
- FPDF_CloseDocument(output_doc);
- return pp::Buffer_Dev();
- }
-
- FitContentsToPrintableAreaIfRequired(output_doc, print_settings);
-
- // Now flatten all the output pages.
- pp::Buffer_Dev buffer = GetFlattenedPrintData(output_doc);
- FPDF_CloseDocument(output_doc);
- return buffer;
-}
-
-void PDFiumEngine::FitContentsToPrintableAreaIfRequired(
- const FPDF_DOCUMENT& doc, const PP_PrintSettings_Dev& print_settings) {
- // Check to see if we need to fit pdf contents to printer paper size.
- if (print_settings.print_scaling_option !=
- PP_PRINTSCALINGOPTION_SOURCE_SIZE) {
- int num_pages = FPDF_GetPageCount(doc);
- // In-place transformation is more efficient than creating a new
- // transformed document from the source document. Therefore, transform
- // every page to fit the contents in the selected printer paper.
- for (int i = 0; i < num_pages; ++i) {
- FPDF_PAGE page = FPDF_LoadPage(doc, i);
- TransformPDFPageForPrinting(page, print_settings);
- FPDF_ClosePage(page);
- }
- }
-}
-
-void PDFiumEngine::SaveSelectedFormForPrint() {
- FORM_ForceToKillFocus(form_);
- client_->FormTextFieldFocusChange(false);
-}
-
-void PDFiumEngine::PrintEnd() {
- FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP);
-}
-
-PDFiumPage::Area PDFiumEngine::GetCharIndex(
- const pp::MouseInputEvent& event, int* page_index,
- int* char_index, PDFiumPage::LinkTarget* target) {
- // First figure out which page this is in.
- pp::Point mouse_point = event.GetPosition();
- pp::Point point(
- static_cast<int>((mouse_point.x() + position_.x()) / current_zoom_),
- static_cast<int>((mouse_point.y() + position_.y()) / current_zoom_));
- return GetCharIndex(point, page_index, char_index, target);
-}
-
-PDFiumPage::Area PDFiumEngine::GetCharIndex(
- const pp::Point& point,
- int* page_index,
- int* char_index,
- PDFiumPage::LinkTarget* target) {
- int page = -1;
- for (size_t i = 0; i < visible_pages_.size(); ++i) {
- if (pages_[visible_pages_[i]]->rect().Contains(point)) {
- page = visible_pages_[i];
- break;
- }
- }
- if (page == -1)
- return PDFiumPage::NONSELECTABLE_AREA;
-
- // If the page hasn't finished rendering, calling into the page sometimes
- // leads to hangs.
- for (size_t i = 0; i < progressive_paints_.size(); ++i) {
- if (progressive_paints_[i].page_index == page)
- return PDFiumPage::NONSELECTABLE_AREA;
- }
-
- *page_index = page;
- return pages_[page]->GetCharIndex(point, current_rotation_, char_index,
- target);
-}
-
-bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) {
- if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT)
- return false;
-
- SelectionChangeInvalidator selection_invalidator(this);
- selection_.clear();
-
- int page_index = -1;
- int char_index = -1;
- PDFiumPage::LinkTarget target;
- PDFiumPage::Area area = GetCharIndex(event, &page_index,
- &char_index, &target);
- mouse_down_state_.Set(area, target);
-
- // Decide whether to open link or not based on user action in mouse up and
- // mouse move events.
- if (area == PDFiumPage::WEBLINK_AREA)
- return true;
-
- if (area == PDFiumPage::DOCLINK_AREA) {
- client_->ScrollToPage(target.page);
- client_->FormTextFieldFocusChange(false);
- return true;
- }
-
- if (page_index != -1) {
- last_page_mouse_down_ = page_index;
- double page_x, page_y;
- pp::Point point = event.GetPosition();
- DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y);
-
- FORM_OnLButtonDown(form_, pages_[page_index]->GetPage(), 0, page_x, page_y);
- int control = FPDPage_HasFormFieldAtPoint(
- form_, pages_[page_index]->GetPage(), page_x, page_y);
- if (control > FPDF_FORMFIELD_UNKNOWN) { // returns -1 sometimes...
-#ifdef _TEST_XFA
- client_->FormTextFieldFocusChange(control == FPDF_FORMFIELD_TEXTFIELD ||
- control == FPDF_FORMFIELD_COMBOBOX ||
- control == FPDF_FORMFIELD_XFA);
-#else
- client_->FormTextFieldFocusChange(control == FPDF_FORMFIELD_TEXTFIELD ||
- control == FPDF_FORMFIELD_COMBOBOX);
-#endif
- return true; // Return now before we get into the selection code.
- }
- }
-
- client_->FormTextFieldFocusChange(false);
-
- if (area != PDFiumPage::TEXT_AREA)
- return true; // Return true so WebKit doesn't do its own highlighting.
-
- if (event.GetClickCount() == 1) {
- OnSingleClick(page_index, char_index);
- } else if (event.GetClickCount() == 2 ||
- event.GetClickCount() == 3) {
- OnMultipleClick(event.GetClickCount(), page_index, char_index);
- }
-
- return true;
-}
-
-void PDFiumEngine::OnSingleClick(int page_index, int char_index) {
- selecting_ = true;
- selection_.push_back(PDFiumRange(pages_[page_index], char_index, 0));
-}
-
-void PDFiumEngine::OnMultipleClick(int click_count,
- int page_index,
- int char_index) {
- // It would be more efficient if the SDK could support finding a space, but
- // now it doesn't.
- int start_index = char_index;
- do {
- base::char16 cur = pages_[page_index]->GetCharAtIndex(start_index);
- // For double click, we want to select one word so we look for whitespace
- // boundaries. For triple click, we want the whole line.
- if (cur == '\n' || (click_count == 2 && (cur == ' ' || cur == '\t')))
- break;
- } while (--start_index >= 0);
- if (start_index)
- start_index++;
-
- int end_index = char_index;
- int total = pages_[page_index]->GetCharCount();
- while (end_index++ <= total) {
- base::char16 cur = pages_[page_index]->GetCharAtIndex(end_index);
- if (cur == '\n' || (click_count == 2 && (cur == ' ' || cur == '\t')))
- break;
- }
-
- selection_.push_back(PDFiumRange(
- pages_[page_index], start_index, end_index - start_index));
-}
-
-bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) {
- if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT)
- return false;
-
- int page_index = -1;
- int char_index = -1;
- PDFiumPage::LinkTarget target;
- PDFiumPage::Area area =
- GetCharIndex(event, &page_index, &char_index, &target);
-
- // Open link on mouse up for same link for which mouse down happened earlier.
- if (mouse_down_state_.Matches(area, target)) {
- if (area == PDFiumPage::WEBLINK_AREA) {
- bool open_in_new_tab = !!(event.GetModifiers() & kDefaultKeyModifier);
- client_->NavigateTo(target.url, open_in_new_tab);
- client_->FormTextFieldFocusChange(false);
- return true;
- }
- }
-
- if (page_index != -1) {
- double page_x, page_y;
- pp::Point point = event.GetPosition();
- DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y);
- FORM_OnLButtonUp(
- form_, pages_[page_index]->GetPage(), 0, page_x, page_y);
- }
-
- if (!selecting_)
- return false;
-
- selecting_ = false;
- return true;
-}
-
-bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) {
- int page_index = -1;
- int char_index = -1;
- PDFiumPage::LinkTarget target;
- PDFiumPage::Area area =
- GetCharIndex(event, &page_index, &char_index, &target);
-
- // Clear |mouse_down_state_| if mouse moves away from where the mouse down
- // happened.
- if (!mouse_down_state_.Matches(area, target))
- mouse_down_state_.Reset();
-
- if (!selecting_) {
- PP_CursorType_Dev cursor;
- switch (area) {
- case PDFiumPage::TEXT_AREA:
- cursor = PP_CURSORTYPE_IBEAM;
- break;
- case PDFiumPage::WEBLINK_AREA:
- case PDFiumPage::DOCLINK_AREA:
- cursor = PP_CURSORTYPE_HAND;
- break;
- case PDFiumPage::NONSELECTABLE_AREA:
- default:
- cursor = PP_CURSORTYPE_POINTER;
- break;
- }
-
- if (page_index != -1) {
- double page_x, page_y;
- pp::Point point = event.GetPosition();
- DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y);
-
- FORM_OnMouseMove(form_, pages_[page_index]->GetPage(), 0, page_x, page_y);
- int control = FPDPage_HasFormFieldAtPoint(
- form_, pages_[page_index]->GetPage(), page_x, page_y);
- switch (control) {
- case FPDF_FORMFIELD_PUSHBUTTON:
- case FPDF_FORMFIELD_CHECKBOX:
- case FPDF_FORMFIELD_RADIOBUTTON:
- case FPDF_FORMFIELD_COMBOBOX:
- case FPDF_FORMFIELD_LISTBOX:
- cursor = PP_CURSORTYPE_HAND;
- break;
- case FPDF_FORMFIELD_TEXTFIELD:
- cursor = PP_CURSORTYPE_IBEAM;
- break;
- default:
- break;
- }
- }
-
- client_->UpdateCursor(cursor);
- pp::Point point = event.GetPosition();
- std::string url = GetLinkAtPosition(event.GetPosition());
- if (url != link_under_cursor_) {
- link_under_cursor_ = url;
- pp::PDF::SetLinkUnderCursor(GetPluginInstance(), url.c_str());
- }
- // No need to swallow the event, since this might interfere with the
- // scrollbars if the user is dragging them.
- return false;
- }
-
- // We're selecting but right now we're not over text, so don't change the
- // current selection.
- if (area != PDFiumPage::TEXT_AREA && area != PDFiumPage::WEBLINK_AREA &&
- area != PDFiumPage::DOCLINK_AREA) {
- return false;
- }
-
- SelectionChangeInvalidator selection_invalidator(this);
-
- // Check if the user has descreased their selection area and we need to remove
- // pages from selection_.
- for (size_t i = 0; i < selection_.size(); ++i) {
- if (selection_[i].page_index() == page_index) {
- // There should be no other pages after this.
- selection_.erase(selection_.begin() + i + 1, selection_.end());
- break;
- }
- }
-
- if (selection_.size() == 0)
- return false;
-
- int last = selection_.size() - 1;
- if (selection_[last].page_index() == page_index) {
- // Selecting within a page.
- int count;
- if (char_index >= selection_[last].char_index()) {
- // Selecting forward.
- count = char_index - selection_[last].char_index() + 1;
- } else {
- count = char_index - selection_[last].char_index() - 1;
- }
- selection_[last].SetCharCount(count);
- } else if (selection_[last].page_index() < page_index) {
- // Selecting into the next page.
-
- // First make sure that there are no gaps in selection, i.e. if mousedown on
- // page one but we only get mousemove over page three, we want page two.
- for (int i = selection_[last].page_index() + 1; i < page_index; ++i) {
- selection_.push_back(PDFiumRange(pages_[i], 0,
- pages_[i]->GetCharCount()));
- }
-
- int count = pages_[selection_[last].page_index()]->GetCharCount();
- selection_[last].SetCharCount(count - selection_[last].char_index());
- selection_.push_back(PDFiumRange(pages_[page_index], 0, char_index));
- } else {
- // Selecting into the previous page.
- selection_[last].SetCharCount(-selection_[last].char_index());
-
- // First make sure that there are no gaps in selection, i.e. if mousedown on
- // page three but we only get mousemove over page one, we want page two.
- for (int i = selection_[last].page_index() - 1; i > page_index; --i) {
- selection_.push_back(PDFiumRange(pages_[i], 0,
- pages_[i]->GetCharCount()));
- }
-
- int count = pages_[page_index]->GetCharCount();
- selection_.push_back(
- PDFiumRange(pages_[page_index], count, count - char_index));
- }
-
- return true;
-}
-
-bool PDFiumEngine::OnKeyDown(const pp::KeyboardInputEvent& event) {
- if (last_page_mouse_down_ == -1)
- return false;
-
- bool rv = !!FORM_OnKeyDown(
- form_, pages_[last_page_mouse_down_]->GetPage(),
- event.GetKeyCode(), event.GetModifiers());
-
- if (event.GetKeyCode() == ui::VKEY_BACK ||
- event.GetKeyCode() == ui::VKEY_ESCAPE) {
- // Chrome doesn't send char events for backspace or escape keys, see
- // PlatformKeyboardEventBuilder::isCharacterKey() and
- // http://chrome-corpsvn.mtv.corp.google.com/viewvc?view=rev&root=chrome&revision=31805
- // for more information. So just fake one since PDFium uses it.
- std::string str;
- str.push_back(event.GetKeyCode());
- pp::KeyboardInputEvent synthesized(pp::KeyboardInputEvent(
- client_->GetPluginInstance(),
- PP_INPUTEVENT_TYPE_CHAR,
- event.GetTimeStamp(),
- event.GetModifiers(),
- event.GetKeyCode(),
- str));
- OnChar(synthesized);
- }
-
- return rv;
-}
-
-bool PDFiumEngine::OnKeyUp(const pp::KeyboardInputEvent& event) {
- if (last_page_mouse_down_ == -1)
- return false;
-
- return !!FORM_OnKeyUp(
- form_, pages_[last_page_mouse_down_]->GetPage(),
- event.GetKeyCode(), event.GetModifiers());
-}
-
-bool PDFiumEngine::OnChar(const pp::KeyboardInputEvent& event) {
- if (last_page_mouse_down_ == -1)
- return false;
-
- base::string16 str = base::UTF8ToUTF16(event.GetCharacterText().AsString());
- return !!FORM_OnChar(
- form_, pages_[last_page_mouse_down_]->GetPage(),
- str[0],
- event.GetModifiers());
-}
-
-void PDFiumEngine::StartFind(const char* text, bool case_sensitive) {
- // We can get a call to StartFind before we have any page information (i.e.
- // before the first call to LoadDocument has happened). Handle this case.
- if (pages_.empty())
- return;
-
- bool first_search = false;
- int character_to_start_searching_from = 0;
- if (current_find_text_ != text) { // First time we search for this text.
- first_search = true;
- std::vector<PDFiumRange> old_selection = selection_;
- StopFind();
- current_find_text_ = text;
-
- if (old_selection.empty()) {
- // Start searching from the beginning of the document.
- next_page_to_search_ = 0;
- last_page_to_search_ = pages_.size() - 1;
- last_character_index_to_search_ = -1;
- } else {
- // There's a current selection, so start from it.
- next_page_to_search_ = old_selection[0].page_index();
- last_character_index_to_search_ = old_selection[0].char_index();
- character_to_start_searching_from = old_selection[0].char_index();
- last_page_to_search_ = next_page_to_search_;
- }
- }
-
- int current_page = next_page_to_search_;
-
- if (pages_[current_page]->available()) {
- base::string16 str = base::UTF8ToUTF16(text);
- // Don't use PDFium to search for now, since it doesn't support unicode text.
- // Leave the code for now to avoid bit-rot, in case it's fixed later.
- if (0) {
- SearchUsingPDFium(
- str, case_sensitive, first_search, character_to_start_searching_from,
- current_page);
- } else {
- SearchUsingICU(
- str, case_sensitive, first_search, character_to_start_searching_from,
- current_page);
- }
-
- if (!IsPageVisible(current_page))
- pages_[current_page]->Unload();
- }
-
- if (next_page_to_search_ != last_page_to_search_ ||
- (first_search && last_character_index_to_search_ != -1)) {
- ++next_page_to_search_;
- }
-
- if (next_page_to_search_ == static_cast<int>(pages_.size()))
- next_page_to_search_ = 0;
- // If there's only one page in the document and we start searching midway,
- // then we'll want to search the page one more time.
- bool end_of_search =
- next_page_to_search_ == last_page_to_search_ &&
- // Only one page but didn't start midway.
- ((pages_.size() == 1 && last_character_index_to_search_ == -1) ||
- // Started midway, but only 1 page and we already looped around.
- (pages_.size() == 1 && !first_search) ||
- // Started midway, and we've just looped around.
- (pages_.size() > 1 && current_page == next_page_to_search_));
-
- if (end_of_search) {
- // Send the final notification.
- client_->NotifyNumberOfFindResultsChanged(find_results_.size(), true);
-
- // When searching is complete, resume finding at a particular index.
- if (resume_find_index_ != -1) {
- current_find_index_ = resume_find_index_;
- resume_find_index_ = -1;
- }
- } else {
- pp::CompletionCallback callback =
- find_factory_.NewCallback(&PDFiumEngine::ContinueFind);
- pp::Module::Get()->core()->CallOnMainThread(
- 0, callback, case_sensitive ? 1 : 0);
- }
-}
-
-void PDFiumEngine::SearchUsingPDFium(const base::string16& term,
- bool case_sensitive,
- bool first_search,
- int character_to_start_searching_from,
- int current_page) {
- // Find all the matches in the current page.
- unsigned long flags = case_sensitive ? FPDF_MATCHCASE : 0;
- FPDF_SCHHANDLE find = FPDFText_FindStart(
- pages_[current_page]->GetTextPage(),
- reinterpret_cast<const unsigned short*>(term.c_str()),
- flags, character_to_start_searching_from);
-
- // Note: since we search one page at a time, we don't find matches across
- // page boundaries. We could do this manually ourself, but it seems low
- // priority since Reader itself doesn't do it.
- while (FPDFText_FindNext(find)) {
- PDFiumRange result(pages_[current_page],
- FPDFText_GetSchResultIndex(find),
- FPDFText_GetSchCount(find));
-
- if (!first_search &&
- last_character_index_to_search_ != -1 &&
- result.page_index() == last_page_to_search_ &&
- result.char_index() >= last_character_index_to_search_) {
- break;
- }
-
- AddFindResult(result);
- }
-
- FPDFText_FindClose(find);
-}
-
-void PDFiumEngine::SearchUsingICU(const base::string16& term,
- bool case_sensitive,
- bool first_search,
- int character_to_start_searching_from,
- int current_page) {
- base::string16 page_text;
- int text_length = pages_[current_page]->GetCharCount();
- if (character_to_start_searching_from) {
- text_length -= character_to_start_searching_from;
- } else if (!first_search &&
- last_character_index_to_search_ != -1 &&
- current_page == last_page_to_search_) {
- text_length = last_character_index_to_search_;
- }
- if (text_length <= 0)
- return;
- unsigned short* data =
- reinterpret_cast<unsigned short*>(WriteInto(&page_text, text_length + 1));
- FPDFText_GetText(pages_[current_page]->GetTextPage(),
- character_to_start_searching_from,
- text_length,
- data);
- std::vector<PDFEngine::Client::SearchStringResult> results;
- client_->SearchString(
- page_text.c_str(), term.c_str(), case_sensitive, &results);
- for (size_t i = 0; i < results.size(); ++i) {
- // Need to map the indexes from the page text, which may have generated
- // characters like space etc, to character indices from the page.
- int temp_start = results[i].start_index + character_to_start_searching_from;
- int start = FPDFText_GetCharIndexFromTextIndex(
- pages_[current_page]->GetTextPage(), temp_start);
- int end = FPDFText_GetCharIndexFromTextIndex(
- pages_[current_page]->GetTextPage(),
- temp_start + results[i].length);
- AddFindResult(PDFiumRange(pages_[current_page], start, end - start));
- }
-}
-
-void PDFiumEngine::AddFindResult(const PDFiumRange& result) {
- // Figure out where to insert the new location, since we could have
- // started searching midway and now we wrapped.
- size_t i;
- int page_index = result.page_index();
- int char_index = result.char_index();
- for (i = 0; i < find_results_.size(); ++i) {
- if (find_results_[i].page_index() > page_index ||
- (find_results_[i].page_index() == page_index &&
- find_results_[i].char_index() > char_index)) {
- break;
- }
- }
- find_results_.insert(find_results_.begin() + i, result);
- UpdateTickMarks();
-
- if (current_find_index_ == -1 && resume_find_index_ == -1) {
- // Select the first match.
- SelectFindResult(true);
- } else if (static_cast<int>(i) <= current_find_index_) {
- // Update the current match index
- current_find_index_++;
- client_->NotifySelectedFindResultChanged(current_find_index_);
- }
- client_->NotifyNumberOfFindResultsChanged(find_results_.size(), false);
-}
-
-bool PDFiumEngine::SelectFindResult(bool forward) {
- if (find_results_.empty()) {
- NOTREACHED();
- return false;
- }
-
- SelectionChangeInvalidator selection_invalidator(this);
-
- // Move back/forward through the search locations we previously found.
- if (forward) {
- if (++current_find_index_ == static_cast<int>(find_results_.size()))
- current_find_index_ = 0;
- } else {
- if (--current_find_index_ < 0) {
- current_find_index_ = find_results_.size() - 1;
- }
- }
-
- // Update the selection before telling the client to scroll, since it could
- // paint then.
- selection_.clear();
- selection_.push_back(find_results_[current_find_index_]);
-
- // If the result is not in view, scroll to it.
- size_t i;
- pp::Rect bounding_rect;
- pp::Rect visible_rect = GetVisibleRect();
- // Use zoom of 1.0 since visible_rect is without zoom.
- std::vector<pp::Rect> rects = find_results_[current_find_index_].
- GetScreenRects(pp::Point(), 1.0, current_rotation_);
- for (i = 0; i < rects.size(); ++i)
- bounding_rect = bounding_rect.Union(rects[i]);
- if (!visible_rect.Contains(bounding_rect)) {
- pp::Point center = bounding_rect.CenterPoint();
- // Make the page centered.
- int new_y = static_cast<int>(center.y() * current_zoom_) -
- static_cast<int>(visible_rect.height() * current_zoom_ / 2);
- if (new_y < 0)
- new_y = 0;
- client_->ScrollToY(new_y);
-
- // Only move horizontally if it's not visible.
- if (center.x() < visible_rect.x() || center.x() > visible_rect.right()) {
- int new_x = static_cast<int>(center.x() * current_zoom_) -
- static_cast<int>(visible_rect.width() * current_zoom_ / 2);
- if (new_x < 0)
- new_x = 0;
- client_->ScrollToX(new_x);
- }
- }
-
- client_->NotifySelectedFindResultChanged(current_find_index_);
-
- return true;
-}
-
-void PDFiumEngine::StopFind() {
- SelectionChangeInvalidator selection_invalidator(this);
-
- selection_.clear();
- selecting_ = false;
- find_results_.clear();
- next_page_to_search_ = -1;
- last_page_to_search_ = -1;
- last_character_index_to_search_ = -1;
- current_find_index_ = -1;
- current_find_text_.clear();
- UpdateTickMarks();
- find_factory_.CancelAll();
-}
-
-void PDFiumEngine::UpdateTickMarks() {
- std::vector<pp::Rect> tickmarks;
- for (size_t i = 0; i < find_results_.size(); ++i) {
- pp::Rect rect;
- // Always use an origin of 0,0 since scroll positions don't affect tickmark.
- std::vector<pp::Rect> rects = find_results_[i].GetScreenRects(
- pp::Point(0, 0), current_zoom_, current_rotation_);
- for (size_t j = 0; j < rects.size(); ++j)
- rect = rect.Union(rects[j]);
- tickmarks.push_back(rect);
- }
-
- client_->UpdateTickMarks(tickmarks);
-}
-
-void PDFiumEngine::ZoomUpdated(double new_zoom_level) {
- CancelPaints();
-
- current_zoom_ = new_zoom_level;
-
- CalculateVisiblePages();
- UpdateTickMarks();
-}
-
-void PDFiumEngine::RotateClockwise() {
- current_rotation_ = (current_rotation_ + 1) % 4;
-
- // Store the current find index so that we can resume finding at that
- // particular index after we have recomputed the find results.
- std::string current_find_text = current_find_text_;
- resume_find_index_ = current_find_index_;
-
- InvalidateAllPages();
-
- if (!current_find_text.empty())
- StartFind(current_find_text.c_str(), false);
-}
-
-void PDFiumEngine::RotateCounterclockwise() {
- current_rotation_ = (current_rotation_ - 1) % 4;
-
- // Store the current find index so that we can resume finding at that
- // particular index after we have recomputed the find results.
- std::string current_find_text = current_find_text_;
- resume_find_index_ = current_find_index_;
-
- InvalidateAllPages();
-
- if (!current_find_text.empty())
- StartFind(current_find_text.c_str(), false);
-}
-
-void PDFiumEngine::InvalidateAllPages() {
- CancelPaints();
- StopFind();
- LoadPageInfo(true);
- client_->Invalidate(pp::Rect(plugin_size_));
-}
-
-std::string PDFiumEngine::GetSelectedText() {
- base::string16 result;
- for (size_t i = 0; i < selection_.size(); ++i) {
- if (i > 0 &&
- selection_[i - 1].page_index() > selection_[i].page_index()) {
- result = selection_[i].GetText() + result;
- } else {
- result.append(selection_[i].GetText());
- }
- }
-
- FormatStringWithHyphens(&result);
- FormatStringForOS(&result);
- return base::UTF16ToUTF8(result);
-}
-
-std::string PDFiumEngine::GetLinkAtPosition(const pp::Point& point) {
- int temp;
- PDFiumPage::LinkTarget target;
- pp::Point point_in_page(
- static_cast<int>((point.x() + position_.x()) / current_zoom_),
- static_cast<int>((point.y() + position_.y()) / current_zoom_));
- PDFiumPage::Area area = GetCharIndex(point_in_page, &temp, &temp, &target);
- if (area == PDFiumPage::WEBLINK_AREA)
- return target.url;
- return std::string();
-}
-
-bool PDFiumEngine::IsSelecting() {
- return selecting_;
-}
-
-bool PDFiumEngine::HasPermission(DocumentPermission permission) const {
- switch (permission) {
- case PERMISSION_COPY:
- return (permissions_ & kPDFPermissionCopyMask) != 0;
- case PERMISSION_COPY_ACCESSIBLE:
- return (permissions_ & kPDFPermissionCopyAccessibleMask) != 0;
- case PERMISSION_PRINT_LOW_QUALITY:
- return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0;
- case PERMISSION_PRINT_HIGH_QUALITY:
- return (permissions_ & kPDFPermissionPrintLowQualityMask) != 0 &&
- (permissions_ & kPDFPermissionPrintHighQualityMask) != 0;
- default:
- return true;
- };
-}
-
-void PDFiumEngine::SelectAll() {
- SelectionChangeInvalidator selection_invalidator(this);
-
- selection_.clear();
- for (size_t i = 0; i < pages_.size(); ++i)
- if (pages_[i]->available()) {
- selection_.push_back(PDFiumRange(pages_[i], 0,
- pages_[i]->GetCharCount()));
- }
-}
-
-int PDFiumEngine::GetNumberOfPages() {
- return pages_.size();
-}
-
-int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) {
- // Look for the destination.
- FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str());
- if (!dest) {
- // Look for a bookmark with the same name.
- base::string16 destination_wide = base::UTF8ToUTF16(destination);
- FPDF_WIDESTRING destination_pdf_wide =
- reinterpret_cast<FPDF_WIDESTRING>(destination_wide.c_str());
- FPDF_BOOKMARK bookmark = FPDFBookmark_Find(doc_, destination_pdf_wide);
- if (!bookmark)
- return -1;
- dest = FPDFBookmark_GetDest(doc_, bookmark);
- }
- return dest ? FPDFDest_GetPageIndex(doc_, dest) : -1;
-}
-
-int PDFiumEngine::GetFirstVisiblePage() {
- CalculateVisiblePages();
- return first_visible_page_;
-}
-
-int PDFiumEngine::GetMostVisiblePage() {
- CalculateVisiblePages();
- return most_visible_page_;
-}
-
-pp::Rect PDFiumEngine::GetPageRect(int index) {
- pp::Rect rc(pages_[index]->rect());
- rc.Inset(-kPageShadowLeft, -kPageShadowTop,
- -kPageShadowRight, -kPageShadowBottom);
- return rc;
-}
-
-pp::Rect PDFiumEngine::GetPageContentsRect(int index) {
- return GetScreenRect(pages_[index]->rect());
-}
-
-void PDFiumEngine::PaintThumbnail(pp::ImageData* image_data, int index) {
- FPDF_BITMAP bitmap = FPDFBitmap_CreateEx(
- image_data->size().width(), image_data->size().height(),
- FPDFBitmap_BGRx, image_data->data(), image_data->stride());
-
- if (pages_[index]->available()) {
- FPDFBitmap_FillRect(bitmap, 0, 0, image_data->size().width(),
- image_data->size().height(), 0xFFFFFFFF);
-
- FPDF_RenderPageBitmap(
- bitmap, pages_[index]->GetPage(), 0, 0, image_data->size().width(),
- image_data->size().height(), 0, GetRenderingFlags());
- } else {
- FPDFBitmap_FillRect(bitmap, 0, 0, image_data->size().width(),
- image_data->size().height(), kPendingPageColor);
- }
-
- FPDFBitmap_Destroy(bitmap);
-}
-
-void PDFiumEngine::SetGrayscale(bool grayscale) {
- render_grayscale_ = grayscale;
-}
-
-void PDFiumEngine::OnCallback(int id) {
- if (!timers_.count(id))
- return;
-
- timers_[id].second(id);
- if (timers_.count(id)) // The callback might delete the timer.
- client_->ScheduleCallback(id, timers_[id].first);
-}
-
-std::string PDFiumEngine::GetPageAsJSON(int index) {
- if (!(HasPermission(PERMISSION_COPY) ||
- HasPermission(PERMISSION_COPY_ACCESSIBLE))) {
- return "{}";
- }
-
- if (index < 0 || static_cast<size_t>(index) > pages_.size() - 1)
- return "{}";
-
- scoped_ptr<base::Value> node(
- pages_[index]->GetAccessibleContentAsValue(current_rotation_));
- std::string page_json;
- base::JSONWriter::Write(node.get(), &page_json);
- return page_json;
-}
-
-bool PDFiumEngine::GetPrintScaling() {
- return !!FPDF_VIEWERREF_GetPrintScaling(doc_);
-}
-
-void PDFiumEngine::AppendBlankPages(int num_pages) {
- DCHECK(num_pages != 0);
-
- if (!doc_)
- return;
-
- selection_.clear();
- pending_pages_.clear();
-
- // Delete all pages except the first one.
- while (pages_.size() > 1) {
- delete pages_.back();
- pages_.pop_back();
- FPDFPage_Delete(doc_, pages_.size());
- }
-
- // Calculate document size and all page sizes.
- std::vector<pp::Rect> page_rects;
- pp::Size page_size = GetPageSize(0);
- page_size.Enlarge(kPageShadowLeft + kPageShadowRight,
- kPageShadowTop + kPageShadowBottom);
- pp::Size old_document_size = document_size_;
- document_size_ = pp::Size(page_size.width(), 0);
- for (int i = 0; i < num_pages; ++i) {
- if (i != 0) {
- // Add space for horizontal separator.
- document_size_.Enlarge(0, kPageSeparatorThickness);
- }
-
- pp::Rect rect(pp::Point(0, document_size_.height()), page_size);
- page_rects.push_back(rect);
-
- document_size_.Enlarge(0, page_size.height());
- }
-
- // Create blank pages.
- for (int i = 1; i < num_pages; ++i) {
- pp::Rect page_rect(page_rects[i]);
- page_rect.Inset(kPageShadowLeft, kPageShadowTop,
- kPageShadowRight, kPageShadowBottom);
- double width_in_points =
- page_rect.width() * kPointsPerInch / kPixelsPerInch;
- double height_in_points =
- page_rect.height() * kPointsPerInch / kPixelsPerInch;
- FPDFPage_New(doc_, i, width_in_points, height_in_points);
- pages_.push_back(new PDFiumPage(this, i, page_rect, true));
- }
-
- CalculateVisiblePages();
- if (document_size_ != old_document_size)
- client_->DocumentSizeUpdated(document_size_);
-}
-
-void PDFiumEngine::LoadDocument() {
- // Check if the document is ready for loading. If it isn't just bail for now,
- // we will call LoadDocument() again later.
- if (!doc_ && !doc_loader_.IsDocumentComplete() &&
- !FPDFAvail_IsDocAvail(fpdf_availability_, &download_hints_)) {
- return;
- }
-
- // If we're in the middle of getting a password, just return. We will retry
- // loading the document after we get the password anyway.
- if (getting_password_)
- return;
-
- ScopedUnsupportedFeature scoped_unsupported_feature(this);
- bool needs_password = false;
- if (TryLoadingDoc(false, std::string(), &needs_password)) {
- ContinueLoadingDocument(false, std::string());
- return;
- }
- if (needs_password)
- GetPasswordAndLoad();
- else
- client_->DocumentLoadFailed();
-}
-
-bool PDFiumEngine::TryLoadingDoc(bool with_password,
- const std::string& password,
- bool* needs_password) {
- *needs_password = false;
- if (doc_)
- return true;
-
- const char* password_cstr = NULL;
- if (with_password) {
- password_cstr = password.c_str();
- password_tries_remaining_--;
- }
- if (doc_loader_.IsDocumentComplete())
- doc_ = FPDF_LoadCustomDocument(&file_access_, password_cstr);
- else
- doc_ = FPDFAvail_GetDocument(fpdf_availability_, password_cstr);
-
- if (!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD)
- *needs_password = true;
-
- return doc_ != NULL;
-}
-
-void PDFiumEngine::GetPasswordAndLoad() {
- getting_password_ = true;
- DCHECK(!doc_ && FPDF_GetLastError() == FPDF_ERR_PASSWORD);
- client_->GetDocumentPassword(password_factory_.NewCallbackWithOutput(
- &PDFiumEngine::OnGetPasswordComplete));
-}
-
-void PDFiumEngine::OnGetPasswordComplete(int32_t result,
- const pp::Var& password) {
- getting_password_ = false;
-
- bool password_given = false;
- std::string password_text;
- if (result == PP_OK && password.is_string()) {
- password_text = password.AsString();
- if (!password_text.empty())
- password_given = true;
- }
- ContinueLoadingDocument(password_given, password_text);
-}
-
-void PDFiumEngine::ContinueLoadingDocument(
- bool has_password,
- const std::string& password) {
- ScopedUnsupportedFeature scoped_unsupported_feature(this);
-
- bool needs_password = false;
- bool loaded = TryLoadingDoc(has_password, password, &needs_password);
- bool password_incorrect = !loaded && has_password && needs_password;
- if (password_incorrect && password_tries_remaining_ > 0) {
- GetPasswordAndLoad();
- return;
- }
-
- if (!doc_) {
- client_->DocumentLoadFailed();
- return;
- }
-
- if (FPDFDoc_GetPageMode(doc_) == PAGEMODE_USEOUTLINES)
- client_->DocumentHasUnsupportedFeature("Bookmarks");
-
- permissions_ = FPDF_GetDocPermissions(doc_);
-
- if (!form_) {
- // Only returns 0 when data isn't available. If form data is downloaded, or
- // if this isn't a form, returns positive values.
- if (!doc_loader_.IsDocumentComplete() &&
- !FPDFAvail_IsFormAvail(fpdf_availability_, &download_hints_)) {
- return;
- }
-
- form_ = FPDFDOC_InitFormFillEnviroument(
- doc_, static_cast<FPDF_FORMFILLINFO*>(this));
-#ifdef _TEST_XFA
- FPDF_LoadXFA(doc_);
-#endif
-
- FPDF_SetFormFieldHighlightColor(form_, 0, kFormHighlightColor);
- FPDF_SetFormFieldHighlightAlpha(form_, kFormHighlightAlpha);
- }
-
- if (!doc_loader_.IsDocumentComplete()) {
- // Check if the first page is available. In a linearized PDF, that is not
- // always page 0. Doing this gives us the default page size, since when the
- // document is available, the first page is available as well.
- CheckPageAvailable(FPDFAvail_GetFirstPageNum(doc_), &pending_pages_);
- }
-
- LoadPageInfo(false);
-
- if (doc_loader_.IsDocumentComplete())
- FinishLoadingDocument();
-}
-
-void PDFiumEngine::LoadPageInfo(bool reload) {
- pending_pages_.clear();
- pp::Size old_document_size = document_size_;
- document_size_ = pp::Size();
- std::vector<pp::Rect> page_rects;
- int page_count = FPDF_GetPageCount(doc_);
- bool doc_complete = doc_loader_.IsDocumentComplete();
- for (int i = 0; i < page_count; ++i) {
- if (i != 0) {
- // Add space for horizontal separator.
- document_size_.Enlarge(0, kPageSeparatorThickness);
- }
-
- // Get page availability. If reload==false, and document is not loaded yet
- // (we are using async loading) - mark all pages as unavailable.
- // If reload==true (we have document constructed already), get page
- // availability flag from already existing PDFiumPage class.
- bool page_available = reload ? pages_[i]->available() : doc_complete;
-
- pp::Size size = page_available ? GetPageSize(i) : default_page_size_;
- size.Enlarge(kPageShadowLeft + kPageShadowRight,
- kPageShadowTop + kPageShadowBottom);
- pp::Rect rect(pp::Point(0, document_size_.height()), size);
- page_rects.push_back(rect);
-
- if (size.width() > document_size_.width())
- document_size_.set_width(size.width());
-
- document_size_.Enlarge(0, size.height());
- }
-
- for (int i = 0; i < page_count; ++i) {
- // Center pages relative to the entire document.
- page_rects[i].set_x((document_size_.width() - page_rects[i].width()) / 2);
- pp::Rect page_rect(page_rects[i]);
- page_rect.Inset(kPageShadowLeft, kPageShadowTop,
- kPageShadowRight, kPageShadowBottom);
- if (reload) {
- pages_[i]->set_rect(page_rect);
- } else {
- pages_.push_back(new PDFiumPage(this, i, page_rect, doc_complete));
- }
- }
-
- CalculateVisiblePages();
- if (document_size_ != old_document_size)
- client_->DocumentSizeUpdated(document_size_);
-}
-
-void PDFiumEngine::CalculateVisiblePages() {
- // Clear pending requests queue, since it may contain requests to the pages
- // that are already invisible (after scrolling for example).
- pending_pages_.clear();
- doc_loader_.ClearPendingRequests();
-
- visible_pages_.clear();
- pp::Rect visible_rect(plugin_size_);
- for (size_t i = 0; i < pages_.size(); ++i) {
- // Check an entire PageScreenRect, since we might need to repaint side
- // borders and shadows even if the page itself is not visible.
- // For example, when user use pdf with different page sizes and zoomed in
- // outside page area.
- if (visible_rect.Intersects(GetPageScreenRect(i))) {
- visible_pages_.push_back(i);
- CheckPageAvailable(i, &pending_pages_);
- } else {
- // Need to unload pages when we're not using them, since some PDFs use a
- // lot of memory. See http://crbug.com/48791
- if (defer_page_unload_) {
- deferred_page_unloads_.push_back(i);
- } else {
- pages_[i]->Unload();
- }
-
- // If the last mouse down was on a page that's no longer visible, reset
- // that variable so that we don't send keyboard events to it (the focus
- // will be lost when the page is first closed anyways).
- if (static_cast<int>(i) == last_page_mouse_down_)
- last_page_mouse_down_ = -1;
- }
- }
-
- // Any pending highlighting of form fields will be invalid since these are in
- // screen coordinates.
- form_highlights_.clear();
-
- if (visible_pages_.size() == 0)
- first_visible_page_ = -1;
- else
- first_visible_page_ = visible_pages_.front();
-
- int most_visible_page = first_visible_page_;
- // Check if the next page is more visible than the first one.
- if (most_visible_page != -1 &&
- pages_.size() > 0 &&
- most_visible_page < static_cast<int>(pages_.size()) - 1) {
- pp::Rect rc_first =
- visible_rect.Intersect(GetPageScreenRect(most_visible_page));
- pp::Rect rc_next =
- visible_rect.Intersect(GetPageScreenRect(most_visible_page + 1));
- if (rc_next.height() > rc_first.height())
- most_visible_page++;
- }
-
- SetCurrentPage(most_visible_page);
-}
-
-bool PDFiumEngine::IsPageVisible(int index) const {
- for (size_t i = 0; i < visible_pages_.size(); ++i) {
- if (visible_pages_[i] == index)
- return true;
- }
-
- return false;
-}
-
-bool PDFiumEngine::CheckPageAvailable(int index, std::vector<int>* pending) {
- if (!doc_ || !form_)
- return false;
-
- if (static_cast<int>(pages_.size()) > index && pages_[index]->available())
- return true;
-
- if (!FPDFAvail_IsPageAvail(fpdf_availability_, index, &download_hints_)) {
- size_t j;
- for (j = 0; j < pending->size(); ++j) {
- if ((*pending)[j] == index)
- break;
- }
-
- if (j == pending->size())
- pending->push_back(index);
- return false;
- }
-
- if (static_cast<int>(pages_.size()) > index)
- pages_[index]->set_available(true);
- if (!default_page_size_.GetArea())
- default_page_size_ = GetPageSize(index);
- return true;
-}
-
-pp::Size PDFiumEngine::GetPageSize(int index) {
- pp::Size size;
- double width_in_points = 0;
- double height_in_points = 0;
- int rv = FPDF_GetPageSizeByIndex(
- doc_, index, &width_in_points, &height_in_points);
-
- if (rv) {
- int width_in_pixels = static_cast<int>(
- width_in_points * kPixelsPerInch / kPointsPerInch);
- int height_in_pixels = static_cast<int>(
- height_in_points * kPixelsPerInch / kPointsPerInch);
- if (current_rotation_ % 2 == 1)
- std::swap(width_in_pixels, height_in_pixels);
- size = pp::Size(width_in_pixels, height_in_pixels);
- }
- return size;
-}
-
-int PDFiumEngine::StartPaint(int page_index, const pp::Rect& dirty) {
- // For the first time we hit paint, do nothing and just record the paint for
- // the next callback. This keeps the UI responsive in case the user is doing
- // a lot of scrolling.
- ProgressivePaint progressive;
- progressive.rect = dirty;
- progressive.page_index = page_index;
- progressive.bitmap = NULL;
- progressive.painted_ = false;
- progressive_paints_.push_back(progressive);
- return progressive_paints_.size() - 1;
-}
-
-bool PDFiumEngine::ContinuePaint(int progressive_index,
- pp::ImageData* image_data) {
-#if defined(OS_LINUX)
- g_last_instance_id = client_->GetPluginInstance()->pp_instance();
-#endif
-
- int rv;
- int page_index = progressive_paints_[progressive_index].page_index;
- last_progressive_start_time_ = base::Time::Now();
- if (progressive_paints_[progressive_index].bitmap) {
- rv = FPDF_RenderPage_Continue(
- pages_[page_index]->GetPage(), static_cast<IFSDK_PAUSE*>(this));
- } else {
- pp::Rect dirty = progressive_paints_[progressive_index].rect;
- progressive_paints_[progressive_index].bitmap = CreateBitmap(dirty,
- image_data);
- int start_x, start_y, size_x, size_y;
- GetPDFiumRect(
- page_index, dirty, &start_x, &start_y, &size_x, &size_y);
- FPDFBitmap_FillRect(progressive_paints_[progressive_index].bitmap, start_x,
- start_y, size_x, size_y, 0xFFFFFFFF);
- rv = FPDF_RenderPageBitmap_Start(
- progressive_paints_[progressive_index].bitmap,
- pages_[page_index]->GetPage(), start_x, start_y, size_x, size_y,
- current_rotation_,
- GetRenderingFlags(), static_cast<IFSDK_PAUSE*>(this));
- }
- return rv != FPDF_RENDER_TOBECOUNTINUED;
-}
-
-void PDFiumEngine::FinishPaint(int progressive_index,
- pp::ImageData* image_data) {
- int page_index = progressive_paints_[progressive_index].page_index;
- pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect;
- FPDF_BITMAP bitmap = progressive_paints_[progressive_index].bitmap;
- int start_x, start_y, size_x, size_y;
- GetPDFiumRect(
- page_index, dirty_in_screen, &start_x, &start_y, &size_x, &size_y);
-
- // Draw the forms.
- FPDF_FFLDraw(
- form_, bitmap, pages_[page_index]->GetPage(), start_x, start_y, size_x,
- size_y, current_rotation_, GetRenderingFlags());
-
- FillPageSides(progressive_index);
-
- // Paint the page shadows.
- PaintPageShadow(progressive_index, image_data);
-
- DrawSelections(progressive_index, image_data);
-
- FPDF_RenderPage_Close(pages_[page_index]->GetPage());
- FPDFBitmap_Destroy(bitmap);
- progressive_paints_.erase(progressive_paints_.begin() + progressive_index);
-
- client_->DocumentPaintOccurred();
-}
-
-void PDFiumEngine::CancelPaints() {
- for (size_t i = 0; i < progressive_paints_.size(); ++i) {
- FPDF_RenderPage_Close(pages_[progressive_paints_[i].page_index]->GetPage());
- FPDFBitmap_Destroy(progressive_paints_[i].bitmap);
- }
- progressive_paints_.clear();
-}
-
-void PDFiumEngine::FillPageSides(int progressive_index) {
- int page_index = progressive_paints_[progressive_index].page_index;
- pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect;
- FPDF_BITMAP bitmap = progressive_paints_[progressive_index].bitmap;
-
- pp::Rect page_rect = pages_[page_index]->rect();
- if (page_rect.x() > 0) {
- pp::Rect left(0,
- page_rect.y() - kPageShadowTop,
- page_rect.x() - kPageShadowLeft,
- page_rect.height() + kPageShadowTop +
- kPageShadowBottom + kPageSeparatorThickness);
- left = GetScreenRect(left).Intersect(dirty_in_screen);
-
- FPDFBitmap_FillRect(bitmap, left.x() - dirty_in_screen.x(),
- left.y() - dirty_in_screen.y(), left.width(),
- left.height(), kBackgroundColor);
- }
-
- if (page_rect.right() < document_size_.width()) {
- pp::Rect right(page_rect.right() + kPageShadowRight,
- page_rect.y() - kPageShadowTop,
- document_size_.width() - page_rect.right() -
- kPageShadowRight,
- page_rect.height() + kPageShadowTop +
- kPageShadowBottom + kPageSeparatorThickness);
- right = GetScreenRect(right).Intersect(dirty_in_screen);
-
- FPDFBitmap_FillRect(bitmap, right.x() - dirty_in_screen.x(),
- right.y() - dirty_in_screen.y(), right.width(),
- right.height(), kBackgroundColor);
- }
-
- // Paint separator.
- pp::Rect bottom(page_rect.x() - kPageShadowLeft,
- page_rect.bottom() + kPageShadowBottom,
- page_rect.width() + kPageShadowLeft + kPageShadowRight,
- kPageSeparatorThickness);
- bottom = GetScreenRect(bottom).Intersect(dirty_in_screen);
-
- FPDFBitmap_FillRect(bitmap, bottom.x() - dirty_in_screen.x(),
- bottom.y() - dirty_in_screen.y(), bottom.width(),
- bottom.height(), kBackgroundColor);
-}
-
-void PDFiumEngine::PaintPageShadow(int progressive_index,
- pp::ImageData* image_data) {
- int page_index = progressive_paints_[progressive_index].page_index;
- pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect;
- pp::Rect page_rect = pages_[page_index]->rect();
- pp::Rect shadow_rect(page_rect);
- shadow_rect.Inset(-kPageShadowLeft, -kPageShadowTop,
- -kPageShadowRight, -kPageShadowBottom);
-
- // Due to the rounding errors of the GetScreenRect it is possible to get
- // different size shadows on the left and right sides even they are defined
- // the same. To fix this issue let's calculate shadow rect and then shrink
- // it by the size of the shadows.
- shadow_rect = GetScreenRect(shadow_rect);
- page_rect = shadow_rect;
-
- page_rect.Inset(static_cast<int>(ceil(kPageShadowLeft * current_zoom_)),
- static_cast<int>(ceil(kPageShadowTop * current_zoom_)),
- static_cast<int>(ceil(kPageShadowRight * current_zoom_)),
- static_cast<int>(ceil(kPageShadowBottom * current_zoom_)));
-
- DrawPageShadow(page_rect, shadow_rect, dirty_in_screen, image_data);
-}
-
-void PDFiumEngine::DrawSelections(int progressive_index,
- pp::ImageData* image_data) {
- int page_index = progressive_paints_[progressive_index].page_index;
- pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect;
-
- void* region = NULL;
- int stride;
- GetRegion(dirty_in_screen.point(), image_data, &region, &stride);
-
- std::vector<pp::Rect> highlighted_rects;
- pp::Rect visible_rect = GetVisibleRect();
- for (size_t k = 0; k < selection_.size(); ++k) {
- if (selection_[k].page_index() != page_index)
- continue;
- std::vector<pp::Rect> rects = selection_[k].GetScreenRects(
- visible_rect.point(), current_zoom_, current_rotation_);
- for (size_t j = 0; j < rects.size(); ++j) {
- pp::Rect visible_selection = rects[j].Intersect(dirty_in_screen);
- if (visible_selection.IsEmpty())
- continue;
-
- visible_selection.Offset(
- -dirty_in_screen.point().x(), -dirty_in_screen.point().y());
- Highlight(region, stride, visible_selection, &highlighted_rects);
- }
- }
-
- for (size_t k = 0; k < form_highlights_.size(); ++k) {
- pp::Rect visible_selection = form_highlights_[k].Intersect(dirty_in_screen);
- if (visible_selection.IsEmpty())
- continue;
-
- visible_selection.Offset(
- -dirty_in_screen.point().x(), -dirty_in_screen.point().y());
- Highlight(region, stride, visible_selection, &highlighted_rects);
- }
- form_highlights_.clear();
-}
-
-void PDFiumEngine::PaintUnavailablePage(int page_index,
- const pp::Rect& dirty,
- pp::ImageData* image_data) {
- int start_x, start_y, size_x, size_y;
- GetPDFiumRect(page_index, dirty, &start_x, &start_y, &size_x, &size_y);
- FPDF_BITMAP bitmap = CreateBitmap(dirty, image_data);
- FPDFBitmap_FillRect(bitmap, start_x, start_y, size_x, size_y,
- kPendingPageColor);
-
- pp::Rect loading_text_in_screen(
- pages_[page_index]->rect().width() / 2,
- pages_[page_index]->rect().y() + kLoadingTextVerticalOffset, 0, 0);
- loading_text_in_screen = GetScreenRect(loading_text_in_screen);
- FPDFBitmap_Destroy(bitmap);
-}
-
-int PDFiumEngine::GetProgressiveIndex(int page_index) const {
- for (size_t i = 0; i < progressive_paints_.size(); ++i) {
- if (progressive_paints_[i].page_index == page_index)
- return i;
- }
- return -1;
-}
-
-FPDF_BITMAP PDFiumEngine::CreateBitmap(const pp::Rect& rect,
- pp::ImageData* image_data) const {
- void* region;
- int stride;
- GetRegion(rect.point(), image_data, &region, &stride);
- if (!region)
- return NULL;
- return FPDFBitmap_CreateEx(
- rect.width(), rect.height(), FPDFBitmap_BGRx, region, stride);
-}
-
-void PDFiumEngine::GetPDFiumRect(
- int page_index, const pp::Rect& rect, int* start_x, int* start_y,
- int* size_x, int* size_y) const {
- pp::Rect page_rect = GetScreenRect(pages_[page_index]->rect());
- page_rect.Offset(-rect.x(), -rect.y());
-
- *start_x = page_rect.x();
- *start_y = page_rect.y();
- *size_x = page_rect.width();
- *size_y = page_rect.height();
-}
-
-int PDFiumEngine::GetRenderingFlags() const {
- int flags = FPDF_LCD_TEXT | FPDF_NO_CATCH;
- if (render_grayscale_)
- flags |= FPDF_GRAYSCALE;
- if (client_->IsPrintPreview())
- flags |= FPDF_PRINTING;
- return flags;
-}
-
-pp::Rect PDFiumEngine::GetVisibleRect() const {
- pp::Rect rv;
- rv.set_x(static_cast<int>(position_.x() / current_zoom_));
- rv.set_y(static_cast<int>(position_.y() / current_zoom_));
- rv.set_width(static_cast<int>(ceil(plugin_size_.width() / current_zoom_)));
- rv.set_height(static_cast<int>(ceil(plugin_size_.height() / current_zoom_)));
- return rv;
-}
-
-pp::Rect PDFiumEngine::GetPageScreenRect(int page_index) const {
- // Since we use this rect for creating the PDFium bitmap, also include other
- // areas around the page that we might need to update such as the page
- // separator and the sides if the page is narrower than the document.
- return GetScreenRect(pp::Rect(
- 0,
- pages_[page_index]->rect().y() - kPageShadowTop,
- document_size_.width(),
- pages_[page_index]->rect().height() + kPageShadowTop +
- kPageShadowBottom + kPageSeparatorThickness));
-}
-
-pp::Rect PDFiumEngine::GetScreenRect(const pp::Rect& rect) const {
- pp::Rect rv;
- int right =
- static_cast<int>(ceil(rect.right() * current_zoom_ - position_.x()));
- int bottom =
- static_cast<int>(ceil(rect.bottom() * current_zoom_ - position_.y()));
-
- rv.set_x(static_cast<int>(rect.x() * current_zoom_ - position_.x()));
- rv.set_y(static_cast<int>(rect.y() * current_zoom_ - position_.y()));
- rv.set_width(right - rv.x());
- rv.set_height(bottom - rv.y());
- return rv;
-}
-
-void PDFiumEngine::Highlight(void* buffer,
- int stride,
- const pp::Rect& rect,
- std::vector<pp::Rect>* highlighted_rects) {
- if (!buffer)
- return;
-
- pp::Rect new_rect = rect;
- for (size_t i = 0; i < highlighted_rects->size(); ++i)
- new_rect = new_rect.Subtract((*highlighted_rects)[i]);
-
- highlighted_rects->push_back(new_rect);
- int l = new_rect.x();
- int t = new_rect.y();
- int w = new_rect.width();
- int h = new_rect.height();
-
- for (int y = t; y < t + h; ++y) {
- for (int x = l; x < l + w; ++x) {
- uint8* pixel = static_cast<uint8*>(buffer) + y * stride + x * 4;
- // This is our highlight color.
- pixel[0] = static_cast<uint8>(
- pixel[0] * (kHighlightColorB / 255.0));
- pixel[1] = static_cast<uint8>(
- pixel[1] * (kHighlightColorG / 255.0));
- pixel[2] = static_cast<uint8>(
- pixel[2] * (kHighlightColorR / 255.0));
- }
- }
-}
-
-PDFiumEngine::SelectionChangeInvalidator::SelectionChangeInvalidator(
- PDFiumEngine* engine) : engine_(engine) {
- previous_origin_ = engine_->GetVisibleRect().point();
- GetVisibleSelectionsScreenRects(&old_selections_);
-}
-
-PDFiumEngine::SelectionChangeInvalidator::~SelectionChangeInvalidator() {
- // Offset the old selections if the document scrolled since we recorded them.
- pp::Point offset = previous_origin_ - engine_->GetVisibleRect().point();
- for (size_t i = 0; i < old_selections_.size(); ++i)
- old_selections_[i].Offset(offset);
-
- std::vector<pp::Rect> new_selections;
- GetVisibleSelectionsScreenRects(&new_selections);
- for (size_t i = 0; i < new_selections.size(); ++i) {
- for (size_t j = 0; j < old_selections_.size(); ++j) {
- if (!old_selections_[j].IsEmpty() &&
- new_selections[i] == old_selections_[j]) {
- // Rectangle was selected before and after, so no need to invalidate it.
- // Mark the rectangles by setting them to empty.
- new_selections[i] = old_selections_[j] = pp::Rect();
- break;
- }
- }
- }
-
- for (size_t i = 0; i < old_selections_.size(); ++i) {
- if (!old_selections_[i].IsEmpty())
- engine_->client_->Invalidate(old_selections_[i]);
- }
- for (size_t i = 0; i < new_selections.size(); ++i) {
- if (!new_selections[i].IsEmpty())
- engine_->client_->Invalidate(new_selections[i]);
- }
- engine_->OnSelectionChanged();
-}
-
-void
-PDFiumEngine::SelectionChangeInvalidator::GetVisibleSelectionsScreenRects(
- std::vector<pp::Rect>* rects) {
- pp::Rect visible_rect = engine_->GetVisibleRect();
- for (size_t i = 0; i < engine_->selection_.size(); ++i) {
- int page_index = engine_->selection_[i].page_index();
- if (!engine_->IsPageVisible(page_index))
- continue; // This selection is on a page that's not currently visible.
-
- std::vector<pp::Rect> selection_rects =
- engine_->selection_[i].GetScreenRects(
- visible_rect.point(),
- engine_->current_zoom_,
- engine_->current_rotation_);
- rects->insert(rects->end(), selection_rects.begin(), selection_rects.end());
- }
-}
-
-PDFiumEngine::MouseDownState::MouseDownState(
- const PDFiumPage::Area& area,
- const PDFiumPage::LinkTarget& target)
- : area_(area), target_(target) {
-}
-
-PDFiumEngine::MouseDownState::~MouseDownState() {
-}
-
-void PDFiumEngine::MouseDownState::Set(const PDFiumPage::Area& area,
- const PDFiumPage::LinkTarget& target) {
- area_ = area;
- target_ = target;
-}
-
-void PDFiumEngine::MouseDownState::Reset() {
- area_ = PDFiumPage::NONSELECTABLE_AREA;
- target_ = PDFiumPage::LinkTarget();
-}
-
-bool PDFiumEngine::MouseDownState::Matches(
- const PDFiumPage::Area& area,
- const PDFiumPage::LinkTarget& target) const {
- if (area_ == area) {
- if (area == PDFiumPage::WEBLINK_AREA)
- return target_.url == target.url;
- if (area == PDFiumPage::DOCLINK_AREA)
- return target_.page == target.page;
- return true;
- }
- return false;
-}
-
-void PDFiumEngine::DeviceToPage(int page_index,
- float device_x,
- float device_y,
- double* page_x,
- double* page_y) {
- *page_x = *page_y = 0;
- int temp_x = static_cast<int>((device_x + position_.x())/ current_zoom_ -
- pages_[page_index]->rect().x());
- int temp_y = static_cast<int>((device_y + position_.y())/ current_zoom_ -
- pages_[page_index]->rect().y());
- FPDF_DeviceToPage(
- pages_[page_index]->GetPage(), 0, 0,
- pages_[page_index]->rect().width(), pages_[page_index]->rect().height(),
- current_rotation_, temp_x, temp_y, page_x, page_y);
-}
-
-int PDFiumEngine::GetVisiblePageIndex(FPDF_PAGE page) {
- for (size_t i = 0; i < visible_pages_.size(); ++i) {
- if (pages_[visible_pages_[i]]->GetPage() == page)
- return visible_pages_[i];
- }
- return -1;
-}
-
-void PDFiumEngine::SetCurrentPage(int index) {
- if (index == most_visible_page_ || !form_)
- return;
- if (most_visible_page_ != -1 && called_do_document_action_) {
- FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage();
- FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE);
- }
- most_visible_page_ = index;
-#if defined(OS_LINUX)
- g_last_instance_id = client_->GetPluginInstance()->pp_instance();
-#endif
- if (most_visible_page_ != -1 && called_do_document_action_) {
- FPDF_PAGE new_page = pages_[most_visible_page_]->GetPage();
- FORM_DoPageAAction(new_page, form_, FPDFPAGE_AACTION_OPEN);
- }
-}
-
-void PDFiumEngine::TransformPDFPageForPrinting(
- FPDF_PAGE page,
- const PP_PrintSettings_Dev& print_settings) {
- // Get the source page width and height in points.
- const double src_page_width = FPDF_GetPageWidth(page);
- const double src_page_height = FPDF_GetPageHeight(page);
-
- const int src_page_rotation = FPDFPage_GetRotation(page);
- const bool fit_to_page = print_settings.print_scaling_option ==
- PP_PRINTSCALINGOPTION_FIT_TO_PRINTABLE_AREA;
-
- pp::Size page_size(print_settings.paper_size);
- pp::Rect content_rect(print_settings.printable_area);
- const bool rotated = (src_page_rotation % 2 == 1);
- SetPageSizeAndContentRect(rotated,
- src_page_width > src_page_height,
- &page_size,
- &content_rect);
-
- // Compute the screen page width and height in points.
- const int actual_page_width =
- rotated ? page_size.height() : page_size.width();
- const int actual_page_height =
- rotated ? page_size.width() : page_size.height();
-
- const double scale_factor = CalculateScaleFactor(fit_to_page, content_rect,
- src_page_width,
- src_page_height, rotated);
-
- // Calculate positions for the clip box.
- ClipBox source_clip_box;
- CalculateClipBoxBoundary(page, scale_factor, rotated, &source_clip_box);
-
- // Calculate the translation offset values.
- double offset_x = 0;
- double offset_y = 0;
- if (fit_to_page) {
- CalculateScaledClipBoxOffset(content_rect, source_clip_box, &offset_x,
- &offset_y);
- } else {
- CalculateNonScaledClipBoxOffset(content_rect, src_page_rotation,
- actual_page_width, actual_page_height,
- source_clip_box, &offset_x, &offset_y);
- }
-
- // Reset the media box and crop box. When the page has crop box and media box,
- // the plugin will display the crop box contents and not the entire media box.
- // If the pages have different crop box values, the plugin will display a
- // document of multiple page sizes. To give better user experience, we
- // decided to have same crop box and media box values. Hence, the user will
- // see a list of uniform pages.
- FPDFPage_SetMediaBox(page, 0, 0, page_size.width(), page_size.height());
- FPDFPage_SetCropBox(page, 0, 0, page_size.width(), page_size.height());
-
- // Transformation is not required, return. Do this check only after updating
- // the media box and crop box. For more detailed information, please refer to
- // the comment block right before FPDF_SetMediaBox and FPDF_GetMediaBox calls.
- if (scale_factor == 1.0 && offset_x == 0 && offset_y == 0)
- return;
-
-
- // All the positions have been calculated, now manipulate the PDF.
- FS_MATRIX matrix = {static_cast<float>(scale_factor),
- 0,
- 0,
- static_cast<float>(scale_factor),
- static_cast<float>(offset_x),
- static_cast<float>(offset_y)};
- FS_RECTF cliprect = {static_cast<float>(source_clip_box.left+offset_x),
- static_cast<float>(source_clip_box.top+offset_y),
- static_cast<float>(source_clip_box.right+offset_x),
- static_cast<float>(source_clip_box.bottom+offset_y)};
- FPDFPage_TransFormWithClip(page, &matrix, &cliprect);
- FPDFPage_TransformAnnots(page, scale_factor, 0, 0, scale_factor,
- offset_x, offset_y);
-}
-
-void PDFiumEngine::DrawPageShadow(const pp::Rect& page_rc,
- const pp::Rect& shadow_rc,
- const pp::Rect& clip_rc,
- pp::ImageData* image_data) {
- pp::Rect page_rect(page_rc);
- page_rect.Offset(page_offset_);
-
- pp::Rect shadow_rect(shadow_rc);
- shadow_rect.Offset(page_offset_);
-
- pp::Rect clip_rect(clip_rc);
- clip_rect.Offset(page_offset_);
-
- // Page drop shadow parameters.
- const double factor = 0.5;
- uint32 depth = std::max(
- std::max(page_rect.x() - shadow_rect.x(),
- page_rect.y() - shadow_rect.y()),
- std::max(shadow_rect.right() - page_rect.right(),
- shadow_rect.bottom() - page_rect.bottom()));
- depth = static_cast<uint32>(depth * 1.5) + 1;
-
- // We need to check depth only to verify our copy of shadow matrix is correct.
- if (!page_shadow_.get() || page_shadow_->depth() != depth)
- page_shadow_.reset(new ShadowMatrix(depth, factor, kBackgroundColor));
-
- DCHECK(!image_data->is_null());
- DrawShadow(image_data, shadow_rect, page_rect, clip_rect, *page_shadow_);
-}
-
-void PDFiumEngine::GetRegion(const pp::Point& location,
- pp::ImageData* image_data,
- void** region,
- int* stride) const {
- if (image_data->is_null()) {
- DCHECK(plugin_size_.IsEmpty());
- *stride = 0;
- *region = NULL;
- return;
- }
- char* buffer = static_cast<char*>(image_data->data());
- *stride = image_data->stride();
-
- pp::Point offset_location = location + page_offset_;
- // TODO: update this when we support BIDI and scrollbars can be on the left.
- if (!buffer ||
- !pp::Rect(page_offset_, plugin_size_).Contains(offset_location)) {
- *region = NULL;
- return;
- }
-
- buffer += location.y() * (*stride);
- buffer += (location.x() + page_offset_.x()) * 4;
- *region = buffer;
-}
-
-void PDFiumEngine::OnSelectionChanged() {
- if (HasPermission(PDFEngine::PERMISSION_COPY))
- pp::PDF::SetSelectedText(GetPluginInstance(), GetSelectedText().c_str());
-}
-
-void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param,
- FPDF_PAGE page,
- double left,
- double top,
- double right,
- double bottom) {
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- int page_index = engine->GetVisiblePageIndex(page);
- if (page_index == -1) {
- // This can sometime happen when the page is closed because it went off
- // screen, and PDFium invalidates the control as it's being deleted.
- return;
- }
-
- pp::Rect rect = engine->pages_[page_index]->PageToScreen(
- engine->GetVisibleRect().point(), engine->current_zoom_, left, top, right,
- bottom, engine->current_rotation_);
- engine->client_->Invalidate(rect);
-}
-
-void PDFiumEngine::Form_OutputSelectedRect(FPDF_FORMFILLINFO* param,
- FPDF_PAGE page,
- double left,
- double top,
- double right,
- double bottom) {
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- int page_index = engine->GetVisiblePageIndex(page);
- if (page_index == -1) {
- NOTREACHED();
- return;
- }
- pp::Rect rect = engine->pages_[page_index]->PageToScreen(
- engine->GetVisibleRect().point(), engine->current_zoom_, left, top, right,
- bottom, engine->current_rotation_);
- engine->form_highlights_.push_back(rect);
-}
-
-void PDFiumEngine::Form_SetCursor(FPDF_FORMFILLINFO* param, int cursor_type) {
- // We don't need this since it's not enough to change the cursor in all
- // scenarios. Instead, we check which form field we're under in OnMouseMove.
-}
-
-int PDFiumEngine::Form_SetTimer(FPDF_FORMFILLINFO* param,
- int elapse,
- TimerCallback timer_func) {
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- engine->timers_[++engine->next_timer_id_] =
- std::pair<int, TimerCallback>(elapse, timer_func);
- engine->client_->ScheduleCallback(engine->next_timer_id_, elapse);
- return engine->next_timer_id_;
-}
-
-void PDFiumEngine::Form_KillTimer(FPDF_FORMFILLINFO* param, int timer_id) {
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- engine->timers_.erase(timer_id);
-}
-
-FPDF_SYSTEMTIME PDFiumEngine::Form_GetLocalTime(FPDF_FORMFILLINFO* param) {
- base::Time time = base::Time::Now();
- base::Time::Exploded exploded;
- time.LocalExplode(&exploded);
-
- FPDF_SYSTEMTIME rv;
- rv.wYear = exploded.year;
- rv.wMonth = exploded.month;
- rv.wDayOfWeek = exploded.day_of_week;
- rv.wDay = exploded.day_of_month;
- rv.wHour = exploded.hour;
- rv.wMinute = exploded.minute;
- rv.wSecond = exploded.second;
- rv.wMilliseconds = exploded.millisecond;
- return rv;
-}
-
-void PDFiumEngine::Form_OnChange(FPDF_FORMFILLINFO* param) {
- // Don't care about.
-}
-
-FPDF_PAGE PDFiumEngine::Form_GetPage(FPDF_FORMFILLINFO* param,
- FPDF_DOCUMENT document,
- int page_index) {
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- if (page_index < 0 || page_index >= static_cast<int>(engine->pages_.size()))
- return NULL;
- return engine->pages_[page_index]->GetPage();
-}
-
-FPDF_PAGE PDFiumEngine::Form_GetCurrentPage(FPDF_FORMFILLINFO* param,
- FPDF_DOCUMENT document) {
- // TODO(jam): find out what this is used for.
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- int index = engine->last_page_mouse_down_;
- if (index == -1) {
- index = engine->GetMostVisiblePage();
- if (index == -1) {
- NOTREACHED();
- return NULL;
- }
- }
-
- return engine->pages_[index]->GetPage();
-}
-
-int PDFiumEngine::Form_GetRotation(FPDF_FORMFILLINFO* param, FPDF_PAGE page) {
- return 0;
-}
-
-void PDFiumEngine::Form_ExecuteNamedAction(FPDF_FORMFILLINFO* param,
- FPDF_BYTESTRING named_action) {
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- std::string action(named_action);
- if (action == "Print") {
- engine->client_->Print();
- return;
- }
-
- int index = engine->last_page_mouse_down_;
- /* Don't try to calculate the most visible page if we don't have a left click
- before this event (this code originally copied Form_GetCurrentPage which of
- course needs to do that and which doesn't have recursion). This can end up
- causing infinite recursion. See http://crbug.com/240413 for more
- information. Either way, it's not necessary for the spec'd list of named
- actions.
- if (index == -1)
- index = engine->GetMostVisiblePage();
- */
- if (index == -1)
- return;
-
- // This is the only list of named actions per the spec (see 12.6.4.11). Adobe
- // Reader supports more, like FitWidth, but since they're not part of the spec
- // and we haven't got bugs about them, no need to now.
- if (action == "NextPage") {
- engine->client_->ScrollToPage(index + 1);
- } else if (action == "PrevPage") {
- engine->client_->ScrollToPage(index - 1);
- } else if (action == "FirstPage") {
- engine->client_->ScrollToPage(0);
- } else if (action == "LastPage") {
- engine->client_->ScrollToPage(engine->pages_.size() - 1);
- }
-}
-
-void PDFiumEngine::Form_SetTextFieldFocus(FPDF_FORMFILLINFO* param,
- FPDF_WIDESTRING value,
- FPDF_DWORD valueLen,
- FPDF_BOOL is_focus) {
- // Do nothing for now.
- // TODO(gene): use this signal to trigger OSK.
-}
-
-void PDFiumEngine::Form_DoURIAction(FPDF_FORMFILLINFO* param,
- FPDF_BYTESTRING uri) {
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- engine->client_->NavigateTo(std::string(uri), false);
-}
-
-void PDFiumEngine::Form_DoGoToAction(FPDF_FORMFILLINFO* param,
- int page_index,
- int zoom_mode,
- float* position_array,
- int size_of_array) {
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- engine->client_->ScrollToPage(page_index);
-}
-
-int PDFiumEngine::Form_Alert(IPDF_JSPLATFORM* param,
- FPDF_WIDESTRING message,
- FPDF_WIDESTRING title,
- int type,
- int icon) {
- // See fpdfformfill.h for these values.
- enum AlertType {
- ALERT_TYPE_OK = 0,
- ALERT_TYPE_OK_CANCEL,
- ALERT_TYPE_YES_ON,
- ALERT_TYPE_YES_NO_CANCEL
- };
-
- enum AlertResult {
- ALERT_RESULT_OK = 1,
- ALERT_RESULT_CANCEL,
- ALERT_RESULT_NO,
- ALERT_RESULT_YES
- };
-
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- std::string message_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(message));
- if (type == ALERT_TYPE_OK) {
- engine->client_->Alert(message_str);
- return ALERT_RESULT_OK;
- }
-
- bool rv = engine->client_->Confirm(message_str);
- if (type == ALERT_TYPE_OK_CANCEL)
- return rv ? ALERT_RESULT_OK : ALERT_RESULT_CANCEL;
- return rv ? ALERT_RESULT_YES : ALERT_RESULT_NO;
-}
-
-void PDFiumEngine::Form_Beep(IPDF_JSPLATFORM* param, int type) {
- // Beeps are annoying, and not possible using javascript, so ignore for now.
-}
-
-int PDFiumEngine::Form_Response(IPDF_JSPLATFORM* param,
- FPDF_WIDESTRING question,
- FPDF_WIDESTRING title,
- FPDF_WIDESTRING default_response,
- FPDF_WIDESTRING label,
- FPDF_BOOL password,
- void* response,
- int length) {
- std::string question_str = base::UTF16ToUTF8(
- reinterpret_cast<const base::char16*>(question));
- std::string default_str = base::UTF16ToUTF8(
- reinterpret_cast<const base::char16*>(default_response));
-
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- std::string rv = engine->client_->Prompt(question_str, default_str);
- base::string16 rv_16 = base::UTF8ToUTF16(rv);
- int rv_bytes = rv_16.size() * sizeof(base::char16);
- if (response) {
- int bytes_to_copy = rv_bytes < length ? rv_bytes : length;
- memcpy(response, rv_16.c_str(), bytes_to_copy);
- }
- return rv_bytes;
-}
-
-int PDFiumEngine::Form_GetFilePath(IPDF_JSPLATFORM* param,
- void* file_path,
- int length) {
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- std::string rv = engine->client_->GetURL();
- if (file_path && rv.size() <= static_cast<size_t>(length))
- memcpy(file_path, rv.c_str(), rv.size());
- return rv.size();
-}
-
-void PDFiumEngine::Form_Mail(IPDF_JSPLATFORM* param,
- void* mail_data,
- int length,
- FPDF_BOOL ui,
- FPDF_WIDESTRING to,
- FPDF_WIDESTRING subject,
- FPDF_WIDESTRING cc,
- FPDF_WIDESTRING bcc,
- FPDF_WIDESTRING message) {
- DCHECK(length == 0); // Don't handle attachments; no way with mailto.
- std::string to_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(to));
- std::string cc_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(cc));
- std::string bcc_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(bcc));
- std::string subject_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(subject));
- std::string message_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(message));
-
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- engine->client_->Email(to_str, cc_str, bcc_str, subject_str, message_str);
-}
-
-void PDFiumEngine::Form_Print(IPDF_JSPLATFORM* param,
- FPDF_BOOL ui,
- int start,
- int end,
- FPDF_BOOL silent,
- FPDF_BOOL shrink_to_fit,
- FPDF_BOOL print_as_image,
- FPDF_BOOL reverse,
- FPDF_BOOL annotations) {
- // No way to pass the extra information to the print dialog using JavaScript.
- // Just opening it is fine for now.
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- engine->client_->Print();
-}
-
-void PDFiumEngine::Form_SubmitForm(IPDF_JSPLATFORM* param,
- void* form_data,
- int length,
- FPDF_WIDESTRING url) {
- std::string url_str =
- base::UTF16ToUTF8(reinterpret_cast<const base::char16*>(url));
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- engine->client_->SubmitForm(url_str, form_data, length);
-}
-
-void PDFiumEngine::Form_GotoPage(IPDF_JSPLATFORM* param,
- int page_number) {
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- engine->client_->ScrollToPage(page_number);
-}
-
-int PDFiumEngine::Form_Browse(IPDF_JSPLATFORM* param,
- void* file_path,
- int length) {
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- std::string path = engine->client_->ShowFileSelectionDialog();
- if (path.size() + 1 <= static_cast<size_t>(length))
- memcpy(file_path, &path[0], path.size() + 1);
- return path.size() + 1;
-}
-
-FPDF_BOOL PDFiumEngine::Pause_NeedToPauseNow(IFSDK_PAUSE* param) {
- PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
- return (base::Time::Now() - engine->last_progressive_start_time_).
- InMilliseconds() > engine->progressive_paint_timeout_;
-}
-
-ScopedUnsupportedFeature::ScopedUnsupportedFeature(PDFiumEngine* engine)
- : engine_(engine), old_engine_(g_engine_for_unsupported) {
- g_engine_for_unsupported = engine_;
-}
-
-ScopedUnsupportedFeature::~ScopedUnsupportedFeature() {
- g_engine_for_unsupported = old_engine_;
-}
-
-PDFEngineExports* PDFEngineExports::Create() {
- return new PDFiumEngineExports;
-}
-
-namespace {
-
-int CalculatePosition(FPDF_PAGE page,
- const PDFiumEngineExports::RenderingSettings& settings,
- pp::Rect* dest) {
- int page_width = static_cast<int>(
- FPDF_GetPageWidth(page) * settings.dpi_x / kPointsPerInch);
- int page_height = static_cast<int>(
- FPDF_GetPageHeight(page) * settings.dpi_y / kPointsPerInch);
-
- // Start by assuming that we will draw exactly to the bounds rect
- // specified.
- *dest = settings.bounds;
-
- int rotate = 0; // normal orientation.
-
- // Auto-rotate landscape pages to print correctly.
- if (settings.autorotate &&
- (dest->width() > dest->height()) != (page_width > page_height)) {
- rotate = 3; // 90 degrees counter-clockwise.
- std::swap(page_width, page_height);
- }
-
- // See if we need to scale the output
- bool scale_to_bounds = false;
- if (settings.fit_to_bounds &&
- ((page_width > dest->width()) || (page_height > dest->height()))) {
- scale_to_bounds = true;
- } else if (settings.stretch_to_bounds &&
- ((page_width < dest->width()) || (page_height < dest->height()))) {
- scale_to_bounds = true;
- }
-
- if (scale_to_bounds) {
- // If we need to maintain aspect ratio, calculate the actual width and
- // height.
- if (settings.keep_aspect_ratio) {
- double scale_factor_x = page_width;
- scale_factor_x /= dest->width();
- double scale_factor_y = page_height;
- scale_factor_y /= dest->height();
- if (scale_factor_x > scale_factor_y) {
- dest->set_height(page_height / scale_factor_x);
- } else {
- dest->set_width(page_width / scale_factor_y);
- }
- }
- } else {
- // We are not scaling to bounds. Draw in the actual page size. If the
- // actual page size is larger than the bounds, the output will be
- // clipped.
- dest->set_width(page_width);
- dest->set_height(page_height);
- }
-
- if (settings.center_in_bounds) {
- pp::Point offset((settings.bounds.width() - dest->width()) / 2,
- (settings.bounds.height() - dest->height()) / 2);
- dest->Offset(offset);
- }
- return rotate;
-}
-
-} // namespace
-
-#if defined(OS_WIN)
-bool PDFiumEngineExports::RenderPDFPageToDC(const void* pdf_buffer,
- int buffer_size,
- int page_number,
- const RenderingSettings& settings,
- HDC dc) {
- FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, buffer_size, NULL);
- if (!doc)
- return false;
- FPDF_PAGE page = FPDF_LoadPage(doc, page_number);
- if (!page) {
- FPDF_CloseDocument(doc);
- return false;
- }
- RenderingSettings new_settings = settings;
- // calculate the page size
- if (new_settings.dpi_x == -1)
- new_settings.dpi_x = GetDeviceCaps(dc, LOGPIXELSX);
- if (new_settings.dpi_y == -1)
- new_settings.dpi_y = GetDeviceCaps(dc, LOGPIXELSY);
-
- pp::Rect dest;
- int rotate = CalculatePosition(page, new_settings, &dest);
-
- int save_state = SaveDC(dc);
- // The caller wanted all drawing to happen within the bounds specified.
- // Based on scale calculations, our destination rect might be larger
- // than the bounds. Set the clip rect to the bounds.
- IntersectClipRect(dc, settings.bounds.x(), settings.bounds.y(),
- settings.bounds.x() + settings.bounds.width(),
- settings.bounds.y() + settings.bounds.height());
-
- // A temporary hack. PDFs generated by Cairo (used by Chrome OS to generate
- // a PDF output from a webpage) result in very large metafiles and the
- // rendering using FPDF_RenderPage is incorrect. In this case, render as a
- // bitmap. Note that this code does not kick in for PDFs printed from Chrome
- // because in that case we create a temp PDF first before printing and this
- // temp PDF does not have a creator string that starts with "cairo".
- base::string16 creator;
- size_t buffer_bytes = FPDF_GetMetaText(doc, "Creator", NULL, 0);
- if (buffer_bytes > 1) {
- FPDF_GetMetaText(
- doc, "Creator", WriteInto(&creator, buffer_bytes + 1), buffer_bytes);
- }
- bool use_bitmap = false;
- if (StartsWith(creator, L"cairo", false))
- use_bitmap = true;
-
- // Another temporary hack. Some PDFs seems to render very slowly if
- // FPDF_RenderPage is directly used on a printer DC. I suspect it is
- // because of the code to talk Postscript directly to the printer if
- // the printer supports this. Need to discuss this with PDFium. For now,
- // render to a bitmap and then blit the bitmap to the DC if we have been
- // supplied a printer DC.
- int device_type = GetDeviceCaps(dc, TECHNOLOGY);
- if (use_bitmap ||
- (device_type == DT_RASPRINTER) || (device_type == DT_PLOTTER)) {
- FPDF_BITMAP bitmap = FPDFBitmap_Create(dest.width(), dest.height(),
- FPDFBitmap_BGRx);
- // Clear the bitmap
- FPDFBitmap_FillRect(bitmap, 0, 0, dest.width(), dest.height(), 0xFFFFFFFF);
- FPDF_RenderPageBitmap(
- bitmap, page, 0, 0, dest.width(), dest.height(), rotate,
- FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH);
- int stride = FPDFBitmap_GetStride(bitmap);
- BITMAPINFO bmi;
- memset(&bmi, 0, sizeof(bmi));
- bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bmi.bmiHeader.biWidth = dest.width();
- bmi.bmiHeader.biHeight = -dest.height(); // top-down image
- bmi.bmiHeader.biPlanes = 1;
- bmi.bmiHeader.biBitCount = 32;
- bmi.bmiHeader.biCompression = BI_RGB;
- bmi.bmiHeader.biSizeImage = stride * dest.height();
- StretchDIBits(dc, dest.x(), dest.y(), dest.width(), dest.height(),
- 0, 0, dest.width(), dest.height(),
- FPDFBitmap_GetBuffer(bitmap), &bmi, DIB_RGB_COLORS, SRCCOPY);
- FPDFBitmap_Destroy(bitmap);
- } else {
- FPDF_RenderPage(dc, page, dest.x(), dest.y(), dest.width(), dest.height(),
- rotate, FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH);
- }
- RestoreDC(dc, save_state);
- FPDF_ClosePage(page);
- FPDF_CloseDocument(doc);
- return true;
-}
-#endif // OS_WIN
-
-bool PDFiumEngineExports::RenderPDFPageToBitmap(
- const void* pdf_buffer,
- int pdf_buffer_size,
- int page_number,
- const RenderingSettings& settings,
- void* bitmap_buffer) {
- FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
- if (!doc)
- return false;
- FPDF_PAGE page = FPDF_LoadPage(doc, page_number);
- if (!page) {
- FPDF_CloseDocument(doc);
- return false;
- }
-
- pp::Rect dest;
- int rotate = CalculatePosition(page, settings, &dest);
-
- FPDF_BITMAP bitmap =
- FPDFBitmap_CreateEx(settings.bounds.width(), settings.bounds.height(),
- FPDFBitmap_BGRA, bitmap_buffer,
- settings.bounds.width() * 4);
- // Clear the bitmap
- FPDFBitmap_FillRect(bitmap, 0, 0, settings.bounds.width(),
- settings.bounds.height(), 0xFFFFFFFF);
- // Shift top-left corner of bounds to (0, 0) if it's not there.
- dest.set_point(dest.point() - settings.bounds.point());
- FPDF_RenderPageBitmap(
- bitmap, page, dest.x(), dest.y(), dest.width(), dest.height(), rotate,
- FPDF_ANNOT | FPDF_PRINTING | FPDF_NO_CATCH);
- FPDFBitmap_Destroy(bitmap);
- FPDF_ClosePage(page);
- FPDF_CloseDocument(doc);
- return true;
-}
-
-bool PDFiumEngineExports::GetPDFDocInfo(const void* pdf_buffer,
- int buffer_size,
- int* page_count,
- double* max_page_width) {
- FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, buffer_size, NULL);
- if (!doc)
- return false;
- int page_count_local = FPDF_GetPageCount(doc);
- if (page_count) {
- *page_count = page_count_local;
- }
- if (max_page_width) {
- *max_page_width = 0;
- for (int page_number = 0; page_number < page_count_local; page_number++) {
- double page_width = 0;
- double page_height = 0;
- FPDF_GetPageSizeByIndex(doc, page_number, &page_width, &page_height);
- if (page_width > *max_page_width) {
- *max_page_width = page_width;
- }
- }
- }
- FPDF_CloseDocument(doc);
- return true;
-}
-
-bool PDFiumEngineExports::GetPDFPageSizeByIndex(
- const void* pdf_buffer,
- int pdf_buffer_size,
- int page_number,
- double* width,
- double* height) {
- FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
- if (!doc)
- return false;
- bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
- FPDF_CloseDocument(doc);
- return success;
-}
-
-} // namespace chrome_pdf
diff --git a/xfa_test/pdf/pdfium/pdfium_engine.h b/xfa_test/pdf/pdfium/pdfium_engine.h
deleted file mode 100644
index 242c33df27..0000000000
--- a/xfa_test/pdf/pdfium/pdfium_engine.h
+++ /dev/null
@@ -1,687 +0,0 @@
-// 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.
-
-#ifndef PDF_PDFIUM_PDFIUM_ENGINE_H_
-#define PDF_PDFIUM_PDFIUM_ENGINE_H_
-
-#include <map>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "base/memory/scoped_ptr.h"
-#include "base/time/time.h"
-#include "pdf/document_loader.h"
-#include "pdf/pdf_engine.h"
-#include "pdf/pdfium/pdfium_page.h"
-#include "pdf/pdfium/pdfium_range.h"
-#include "ppapi/cpp/completion_callback.h"
-#include "ppapi/cpp/dev/buffer_dev.h"
-#include "ppapi/cpp/image_data.h"
-#include "ppapi/cpp/point.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdf_dataavail.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdf_progressive.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdfformfill.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdfview.h"
-
-#define _TEST_XFA
-#ifdef _TEST_XFA
-# if defined(WIN32)
-# define FXQA_TESTFILE(filename) "E:/"#filename
-# else
-# define FXQA_TESTFILE(filename) "/home/"#filename
-# endif
-#endif
-
-namespace pp {
-class KeyboardInputEvent;
-class MouseInputEvent;
-}
-
-namespace chrome_pdf {
-
-class ShadowMatrix;
-
-class PDFiumEngine : public PDFEngine,
- public DocumentLoader::Client,
- public FPDF_FORMFILLINFO,
- public IPDF_JSPLATFORM,
- public IFSDK_PAUSE {
- public:
- explicit PDFiumEngine(PDFEngine::Client* client);
- virtual ~PDFiumEngine();
-
- // PDFEngine implementation.
- virtual bool New(const char* url);
- virtual bool New(const char* url,
- const char* headers);
- virtual void PageOffsetUpdated(const pp::Point& page_offset);
- virtual void PluginSizeUpdated(const pp::Size& size);
- virtual void ScrolledToXPosition(int position);
- virtual void ScrolledToYPosition(int position);
- virtual void PrePaint();
- virtual void Paint(const pp::Rect& rect,
- pp::ImageData* image_data,
- std::vector<pp::Rect>* ready,
- std::vector<pp::Rect>* pending);
- virtual void PostPaint();
- virtual bool HandleDocumentLoad(const pp::URLLoader& loader);
- virtual bool HandleEvent(const pp::InputEvent& event);
- virtual uint32_t QuerySupportedPrintOutputFormats();
- virtual void PrintBegin();
- virtual pp::Resource PrintPages(
- const PP_PrintPageNumberRange_Dev* page_ranges,
- uint32_t page_range_count,
- const PP_PrintSettings_Dev& print_settings);
- virtual void PrintEnd();
- virtual void StartFind(const char* text, bool case_sensitive);
- virtual bool SelectFindResult(bool forward);
- virtual void StopFind();
- virtual void ZoomUpdated(double new_zoom_level);
- virtual void RotateClockwise();
- virtual void RotateCounterclockwise();
- virtual std::string GetSelectedText();
- virtual std::string GetLinkAtPosition(const pp::Point& point);
- virtual bool IsSelecting();
- virtual bool HasPermission(DocumentPermission permission) const;
- virtual void SelectAll();
- virtual int GetNumberOfPages();
- virtual int GetNamedDestinationPage(const std::string& destination);
- virtual int GetFirstVisiblePage();
- virtual int GetMostVisiblePage();
- virtual pp::Rect GetPageRect(int index);
- virtual pp::Rect GetPageContentsRect(int index);
- virtual int GetVerticalScrollbarYPosition() { return position_.y(); }
- virtual void PaintThumbnail(pp::ImageData* image_data, int index);
- virtual void SetGrayscale(bool grayscale);
- virtual void OnCallback(int id);
- virtual std::string GetPageAsJSON(int index);
- virtual bool GetPrintScaling();
- virtual void AppendBlankPages(int num_pages);
- virtual void AppendPage(PDFEngine* engine, int index);
- virtual pp::Point GetScrollPosition();
- virtual void SetScrollPosition(const pp::Point& position);
- virtual bool IsProgressiveLoad();
-
- // DocumentLoader::Client implementation.
- virtual pp::Instance* GetPluginInstance();
- virtual pp::URLLoader CreateURLLoader();
- virtual void OnPartialDocumentLoaded();
- virtual void OnPendingRequestComplete();
- virtual void OnNewDataAvailable();
- virtual void OnDocumentComplete();
-
- void UnsupportedFeature(int type);
-
- std::string current_find_text() const { return current_find_text_; }
-
- FPDF_DOCUMENT doc() { return doc_; }
- FPDF_FORMHANDLE form() { return form_; }
-
- private:
- // This helper class is used to detect the difference in selection between
- // construction and destruction. At destruction, it invalidates all the
- // parts that are newly selected, along with all the parts that used to be
- // selected but are not anymore.
- class SelectionChangeInvalidator {
- public:
- explicit SelectionChangeInvalidator(PDFiumEngine* engine);
- ~SelectionChangeInvalidator();
- private:
- // Sets the given container to the all the currently visible selection
- // rectangles, in screen coordinates.
- void GetVisibleSelectionsScreenRects(std::vector<pp::Rect>* rects);
-
- PDFiumEngine* engine_;
- // Screen rectangles that were selected on construction.
- std::vector<pp::Rect> old_selections_;
- // The origin at the time this object was constructed.
- pp::Point previous_origin_;
- };
-
- // Used to store mouse down state to handle it in other mouse event handlers.
- class MouseDownState {
- public:
- MouseDownState(const PDFiumPage::Area& area,
- const PDFiumPage::LinkTarget& target);
- ~MouseDownState();
-
- void Set(const PDFiumPage::Area& area,
- const PDFiumPage::LinkTarget& target);
- void Reset();
- bool Matches(const PDFiumPage::Area& area,
- const PDFiumPage::LinkTarget& target) const;
-
- private:
- PDFiumPage::Area area_;
- PDFiumPage::LinkTarget target_;
-
- DISALLOW_COPY_AND_ASSIGN(MouseDownState);
- };
-
- friend class SelectionChangeInvalidator;
-
- struct FileAvail : public FX_FILEAVAIL {
- DocumentLoader* loader;
- };
-
- struct DownloadHints : public FX_DOWNLOADHINTS {
- DocumentLoader* loader;
- };
-
- // PDFium interface to get block of data.
- static int GetBlock(void* param, unsigned long position,
- unsigned char* buffer, unsigned long size);
-
- // PDFium interface to check is block of data is available.
- static bool IsDataAvail(FX_FILEAVAIL* param,
- size_t offset, size_t size);
-
- // PDFium interface to request download of the block of data.
- static void AddSegment(FX_DOWNLOADHINTS* param,
- size_t offset, size_t size);
-
- // We finished getting the pdf file, so load it. This will complete
- // asynchronously (due to password fetching) and may be run multiple times.
- void LoadDocument();
-
- // Try loading the document. Returns true if the document is successfully
- // loaded or is already loaded otherwise it will return false. If
- // |with_password| is set to true, the document will be loaded with
- // |password|. If the document could not be loaded and needs a password,
- // |needs_password| will be set to true.
- bool TryLoadingDoc(bool with_password,
- const std::string& password,
- bool* needs_password);
-
- // Ask the user for the document password and then continue loading the
- // document.
- void GetPasswordAndLoad();
-
- // Called when the password has been retrieved.
- void OnGetPasswordComplete(int32_t result,
- const pp::Var& password);
-
- // Continues loading the document when the password has been retrieved, or if
- // there is no password.
- void ContinueLoadingDocument(bool has_password,
- const std::string& password);
-
- // Finish loading the document and notify the client that the document has
- // been loaded. This should only be run after |doc_| has been loaded and the
- // document is fully downloaded. If this has been run once, it will result in
- // a no-op.
- void FinishLoadingDocument();
-
- // Loads information about the pages in the document and calculate the
- // document size.
- void LoadPageInfo(bool reload);
-
- // Calculate which pages should be displayed right now.
- void CalculateVisiblePages();
-
- // Returns true iff the given page index is visible. CalculateVisiblePages
- // must have been called first.
- bool IsPageVisible(int index) const;
-
- // Checks if a page is now available, and if so marks it as such and returns
- // true. Otherwise, it will return false and will add the index to the given
- // array if it's not already there.
- bool CheckPageAvailable(int index, std::vector<int>* pending);
-
- // Helper function to get a given page's size in pixels. This is not part of
- // PDFiumPage because we might not have that structure when we need this.
- pp::Size GetPageSize(int index);
-
- void UpdateTickMarks();
-
- // Called to continue searching so we don't block the main thread.
- void ContinueFind(int32_t result);
-
- // Inserts a find result into find_results_, which is sorted.
- void AddFindResult(const PDFiumRange& result);
-
- // Search a page using PDFium's methods. Doesn't work with unicode. This
- // function is just kept arount in case PDFium code is fixed.
- void SearchUsingPDFium(const base::string16& term,
- bool case_sensitive,
- bool first_search,
- int character_to_start_searching_from,
- int current_page);
-
- // Search a page ourself using ICU.
- void SearchUsingICU(const base::string16& term,
- bool case_sensitive,
- bool first_search,
- int character_to_start_searching_from,
- int current_page);
-
- // Input event handlers.
- bool OnMouseDown(const pp::MouseInputEvent& event);
- bool OnMouseUp(const pp::MouseInputEvent& event);
- bool OnMouseMove(const pp::MouseInputEvent& event);
- bool OnKeyDown(const pp::KeyboardInputEvent& event);
- bool OnKeyUp(const pp::KeyboardInputEvent& event);
- bool OnChar(const pp::KeyboardInputEvent& event);
-
- FPDF_DOCUMENT CreateSinglePageRasterPdf(
- double source_page_width,
- double source_page_height,
- const PP_PrintSettings_Dev& print_settings,
- PDFiumPage* page_to_print);
-
- pp::Buffer_Dev PrintPagesAsRasterPDF(
- const PP_PrintPageNumberRange_Dev* page_ranges,
- uint32_t page_range_count,
- const PP_PrintSettings_Dev& print_settings);
-
- pp::Buffer_Dev PrintPagesAsPDF(const PP_PrintPageNumberRange_Dev* page_ranges,
- uint32_t page_range_count,
- const PP_PrintSettings_Dev& print_settings);
-
- pp::Buffer_Dev GetFlattenedPrintData(const FPDF_DOCUMENT& doc);
- void FitContentsToPrintableAreaIfRequired(
- const FPDF_DOCUMENT& doc,
- const PP_PrintSettings_Dev& print_settings);
- void SaveSelectedFormForPrint();
-
- // Given a mouse event, returns which page and character location it's closest
- // to.
- PDFiumPage::Area GetCharIndex(const pp::MouseInputEvent& event,
- int* page_index,
- int* char_index,
- PDFiumPage::LinkTarget* target);
- PDFiumPage::Area GetCharIndex(const pp::Point& point,
- int* page_index,
- int* char_index,
- PDFiumPage::LinkTarget* target);
-
- void OnSingleClick(int page_index, int char_index);
- void OnMultipleClick(int click_count, int page_index, int char_index);
-
- // Starts a progressive paint operation given a rectangle in screen
- // coordinates. Returns the index in progressive_rects_.
- int StartPaint(int page_index, const pp::Rect& dirty);
-
- // Continues a paint operation that was started earlier. Returns true if the
- // paint is done, or false if it needs to be continued.
- bool ContinuePaint(int progressive_index, pp::ImageData* image_data);
-
- // Called once PDFium is finished rendering a page so that we draw our
- // borders, highlighting etc.
- void FinishPaint(int progressive_index, pp::ImageData* image_data);
-
- // Stops any paints that are in progress.
- void CancelPaints();
-
- // Invalidates all pages. Use this when some global parameter, such as page
- // orientation, has changed.
- void InvalidateAllPages();
-
- // If the page is narrower than the document size, paint the extra space
- // with the page background.
- void FillPageSides(int progressive_index);
-
- void PaintPageShadow(int progressive_index, pp::ImageData* image_data);
-
- // Highlight visible find results and selections.
- void DrawSelections(int progressive_index, pp::ImageData* image_data);
-
- // Paints an page that hasn't finished downloading.
- void PaintUnavailablePage(int page_index,
- const pp::Rect& dirty,
- pp::ImageData* image_data);
-
- // Given a page index, returns the corresponding index in progressive_rects_,
- // or -1 if it doesn't exist.
- int GetProgressiveIndex(int page_index) const;
-
- // Creates a FPDF_BITMAP from a rectangle in screen coordinates.
- FPDF_BITMAP CreateBitmap(const pp::Rect& rect,
- pp::ImageData* image_data) const;
-
- // Given a rectangle in screen coordinates, returns the coordinates in the
- // units that PDFium rendering functions expect.
- void GetPDFiumRect(int page_index, const pp::Rect& rect, int* start_x,
- int* start_y, int* size_x, int* size_y) const;
-
- // Returns the rendering flags to pass to PDFium.
- int GetRenderingFlags() const;
-
- // Returns the currently visible rectangle in document coordinates.
- pp::Rect GetVisibleRect() const;
-
- // Returns a page's rect in screen coordinates, as well as its surrounding
- // border areas and bottom separator.
- pp::Rect GetPageScreenRect(int page_index) const;
-
- // Given a rectangle in document coordinates, returns the rectange into screen
- // coordinates (i.e. 0,0 is top left corner of plugin area). If it's not
- // visible, an empty rectangle is returned.
- pp::Rect GetScreenRect(const pp::Rect& rect) const;
-
- // Highlights the given rectangle.
- void Highlight(void* buffer,
- int stride,
- const pp::Rect& rect,
- std::vector<pp::Rect>* highlighted_rects);
-
- // Helper function to convert a device to page coordinates. If the page is
- // not yet loaded, page_x and page_y will be set to 0.
- void DeviceToPage(int page_index,
- float device_x,
- float device_y,
- double* page_x,
- double* page_y);
-
- // Helper function to get the index of a given FPDF_PAGE. Returns -1 if not
- // found.
- int GetVisiblePageIndex(FPDF_PAGE page);
-
- // Helper function to change the current page, running page open/close
- // triggers as necessary.
- void SetCurrentPage(int index);
-
- // Transform |page| contents to fit in the selected printer paper size.
- void TransformPDFPageForPrinting(FPDF_PAGE page,
- const PP_PrintSettings_Dev& print_settings);
-
- void DrawPageShadow(const pp::Rect& page_rect,
- const pp::Rect& shadow_rect,
- const pp::Rect& clip_rect,
- pp::ImageData* image_data);
-
- void GetRegion(const pp::Point& location,
- pp::ImageData* image_data,
- void** region,
- int* stride) const;
-
- // Called when the selection changes.
- void OnSelectionChanged();
-
- // FPDF_FORMFILLINFO callbacks.
- static void Form_Invalidate(FPDF_FORMFILLINFO* param,
- FPDF_PAGE page,
- double left,
- double top,
- double right,
- double bottom);
- static void Form_OutputSelectedRect(FPDF_FORMFILLINFO* param,
- FPDF_PAGE page,
- double left,
- double top,
- double right,
- double bottom);
- static void Form_SetCursor(FPDF_FORMFILLINFO* param, int cursor_type);
- static int Form_SetTimer(FPDF_FORMFILLINFO* param,
- int elapse,
- TimerCallback timer_func);
- static void Form_KillTimer(FPDF_FORMFILLINFO* param, int timer_id);
- static FPDF_SYSTEMTIME Form_GetLocalTime(FPDF_FORMFILLINFO* param);
- static void Form_OnChange(FPDF_FORMFILLINFO* param);
- static FPDF_PAGE Form_GetPage(FPDF_FORMFILLINFO* param,
- FPDF_DOCUMENT document,
- int page_index);
- static FPDF_PAGE Form_GetCurrentPage(FPDF_FORMFILLINFO* param,
- FPDF_DOCUMENT document);
- static int Form_GetRotation(FPDF_FORMFILLINFO* param, FPDF_PAGE page);
- static void Form_ExecuteNamedAction(FPDF_FORMFILLINFO* param,
- FPDF_BYTESTRING named_action);
- static void Form_SetTextFieldFocus(FPDF_FORMFILLINFO* param,
- FPDF_WIDESTRING value,
- FPDF_DWORD valueLen,
- FPDF_BOOL is_focus);
- static void Form_DoURIAction(FPDF_FORMFILLINFO* param, FPDF_BYTESTRING uri);
- static void Form_DoGoToAction(FPDF_FORMFILLINFO* param,
- int page_index,
- int zoom_mode,
- float* position_array,
- int size_of_array);
-
- // IPDF_JSPLATFORM callbacks.
- static int Form_Alert(IPDF_JSPLATFORM* param,
- FPDF_WIDESTRING message,
- FPDF_WIDESTRING title,
- int type,
- int icon);
- static void Form_Beep(IPDF_JSPLATFORM* param, int type);
- static int Form_Response(IPDF_JSPLATFORM* param,
- FPDF_WIDESTRING question,
- FPDF_WIDESTRING title,
- FPDF_WIDESTRING default_response,
- FPDF_WIDESTRING label,
- FPDF_BOOL password,
- void* response,
- int length);
- static int Form_GetFilePath(IPDF_JSPLATFORM* param,
- void* file_path,
- int length);
- static void Form_Mail(IPDF_JSPLATFORM* param,
- void* mail_data,
- int length,
- FPDF_BOOL ui,
- FPDF_WIDESTRING to,
- FPDF_WIDESTRING subject,
- FPDF_WIDESTRING cc,
- FPDF_WIDESTRING bcc,
- FPDF_WIDESTRING message);
- static void Form_Print(IPDF_JSPLATFORM* param,
- FPDF_BOOL ui,
- int start,
- int end,
- FPDF_BOOL silent,
- FPDF_BOOL shrink_to_fit,
- FPDF_BOOL print_as_image,
- FPDF_BOOL reverse,
- FPDF_BOOL annotations);
- static void Form_SubmitForm(IPDF_JSPLATFORM* param,
- void* form_data,
- int length,
- FPDF_WIDESTRING url);
- static void Form_GotoPage(IPDF_JSPLATFORM* param, int page_number);
- static int Form_Browse(IPDF_JSPLATFORM* param, void* file_path, int length);
-#ifdef _TEST_XFA
- static void Form_EmailTo(FPDF_FORMFILLINFO* pThis, FPDF_FILEHANDLER* fileHandler,
- FPDF_WIDESTRING to, FPDF_WIDESTRING subject, FPDF_WIDESTRING cc, FPDF_WIDESTRING bcc, FPDF_WIDESTRING message);
- static void Form_DisplayCaret(FPDF_FORMFILLINFO* pThis, FPDF_PAGE page, FPDF_BOOL bVisible, double left, double top, double right, double bottom);
- //static int Form_GetCurDocumentIndex(FPDF_FORMFILLINFO* pThis);
- //static int Form_GetDocumentCount(FPDF_FORMFILLINFO* pThis);
- static void Form_SetCurrentPage(FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document, int iCurPage);
- static int Form_GetCurrentPageIndex(FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document);
- static void Form_GetPageViewRect(FPDF_FORMFILLINFO* pThis, FPDF_PAGE page, double* left, double* top, double* right, double* bottom);
- static int Form_GetPlatform(FPDF_FORMFILLINFO* pThis, void* platform, int length);
- static FPDF_BOOL Form_PopupMenu(FPDF_FORMFILLINFO* pThis, FPDF_PAGE page, FPDF_WIDGET hWidget, int menuFlag, float x, float y);
- static FPDF_BOOL Form_PostRequestURL(FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING wsURL, FPDF_WIDESTRING wsData, FPDF_WIDESTRING wsContentType, FPDF_WIDESTRING wsEncode, FPDF_WIDESTRING wsHeader, FPDF_BSTR* respone);
- static FPDF_BOOL Form_PutRequestURL(FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING wsURL, FPDF_WIDESTRING wsData, FPDF_WIDESTRING wsEncode);
- //static FPDF_BOOL Form_ShowFileDialog(FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING wsTitle, FPDF_WIDESTRING wsFilter, FPDF_BOOL isOpen, FPDF_STRINGHANDLE pathArr);
- static void Form_UploadTo(FPDF_FORMFILLINFO* pThis, FPDF_FILEHANDLER* fileHandler, int fileFlag, FPDF_WIDESTRING uploadTo);
- static FPDF_LPFILEHANDLER Form_DownloadFromURL(FPDF_FORMFILLINFO* pThis, FPDF_WIDESTRING URL);
- //static FPDF_BOOL MyForm_GetFilePath(FPDF_FORMFILLINFO* pThis, FPDF_FILEHANDLER* pFileHandler, void* filePath, int length);
- static FPDF_FILEHANDLER* Form_OpenFile(FPDF_FORMFILLINFO* pThis, int fileFlag, FPDF_WIDESTRING wsURL, const char* mode);
- static void Form_GotoURL(FPDF_FORMFILLINFO* pThis, FPDF_DOCUMENT document, FPDF_WIDESTRING wsURL);
- static int Form_GetLanguage(FPDF_FORMFILLINFO* pThis, void* language, int length);
-#endif // _TEST_XFA
- // IFSDK_PAUSE callbacks
- static FPDF_BOOL Pause_NeedToPauseNow(IFSDK_PAUSE* param);
-
- PDFEngine::Client* client_;
- pp::Size document_size_; // Size of document in pixels.
-
- // The scroll position in screen coordinates.
- pp::Point position_;
- // The offset of the page into the viewport.
- pp::Point page_offset_;
- // The plugin size in screen coordinates.
- pp::Size plugin_size_;
- double current_zoom_;
- unsigned int current_rotation_;
-
- DocumentLoader doc_loader_; // Main document's loader.
- std::string url_;
- std::string headers_;
- pp::CompletionCallbackFactory<PDFiumEngine> find_factory_;
-
- pp::CompletionCallbackFactory<PDFiumEngine> password_factory_;
- int32_t password_tries_remaining_;
-
- // The current text used for searching.
- std::string current_find_text_;
-
- // The PDFium wrapper object for the document.
- FPDF_DOCUMENT doc_;
-
- // The PDFium wrapper for form data. Used even if there are no form controls
- // on the page.
- FPDF_FORMHANDLE form_;
-
- // The page(s) of the document. Store a vector of pointers so that when the
- // vector is resized we don't close the pages that are used in pending
- // paints.
- std::vector<PDFiumPage*> pages_;
-
- // The indexes of the pages currently visible.
- std::vector<int> visible_pages_;
-
- // The indexes of the pages pending download.
- std::vector<int> pending_pages_;
-
- // During handling of input events we don't want to unload any pages in
- // callbacks to us from PDFium, since the current page can change while PDFium
- // code still has a pointer to it.
- bool defer_page_unload_;
- std::vector<int> deferred_page_unloads_;
-
- // Used for selection. There could be more than one range if selection spans
- // more than one page.
- std::vector<PDFiumRange> selection_;
- // True if we're in the middle of selection.
- bool selecting_;
-
- MouseDownState mouse_down_state_;
-
- // Used for searching.
- typedef std::vector<PDFiumRange> FindResults;
- FindResults find_results_;
- // Which page to search next.
- int next_page_to_search_;
- // Where to stop searching.
- int last_page_to_search_;
- int last_character_index_to_search_; // -1 if search until end of page.
- // Which result the user has currently selected.
- int current_find_index_;
- // Where to resume searching.
- int resume_find_index_;
-
- // Permissions bitfield.
- unsigned long permissions_;
-
- // Interface structure to provide access to document stream.
- FPDF_FILEACCESS file_access_;
- // Interface structure to check data availability in the document stream.
- FileAvail file_availability_;
- // Interface structure to request data chunks from the document stream.
- DownloadHints download_hints_;
- // Pointer to the document availability interface.
- FPDF_AVAIL fpdf_availability_;
-
- pp::Size default_page_size_;
-
- // Used to manage timers that form fill API needs. The pair holds the timer
- // period, in ms, and the callback function.
- std::map<int, std::pair<int, TimerCallback> > timers_;
- int next_timer_id_;
-
- // Holds the page index of the last page that the mouse clicked on.
- int last_page_mouse_down_;
-
- // Holds the page index of the first visible page; refreshed by calling
- // CalculateVisiblePages()
- int first_visible_page_;
-
- // Holds the page index of the most visible page; refreshed by calling
- // CalculateVisiblePages()
- int most_visible_page_;
-
- // Set to true after FORM_DoDocumentJSAction/FORM_DoDocumentOpenAction have
- // been called. Only after that can we call FORM_DoPageAAction.
- bool called_do_document_action_;
-
- // Records parts of form fields that need to be highlighted at next paint, in
- // screen coordinates.
- std::vector<pp::Rect> form_highlights_;
-
- // Whether to render in grayscale or in color.
- bool render_grayscale_;
-
- // The link currently under the cursor.
- std::string link_under_cursor_;
-
- // Pending progressive paints.
- struct ProgressivePaint {
- pp::Rect rect; // In screen coordinates.
- FPDF_BITMAP bitmap;
- int page_index;
- // Temporary used to figure out if in a series of Paint() calls whether this
- // pending paint was updated or not.
- int painted_;
- };
- std::vector<ProgressivePaint> progressive_paints_;
-
- // Keeps track of when we started the last progressive paint, so that in our
- // callback we can determine if we need to pause.
- base::Time last_progressive_start_time_;
-
- // The timeout to use for the current progressive paint.
- int progressive_paint_timeout_;
-
- // Shadow matrix for generating the page shadow bitmap.
- scoped_ptr<ShadowMatrix> page_shadow_;
-
- // Set to true if the user is being prompted for their password. Will be set
- // to false after the user finishes getting their password.
- bool getting_password_;
-};
-
-// Create a local variable of this when calling PDFium functions which can call
-// our global callback when an unsupported feature is reached.
-class ScopedUnsupportedFeature {
- public:
- explicit ScopedUnsupportedFeature(PDFiumEngine* engine);
- ~ScopedUnsupportedFeature();
- private:
- PDFiumEngine* engine_;
- PDFiumEngine* old_engine_;
-};
-
-class PDFiumEngineExports : public PDFEngineExports {
- public:
- PDFiumEngineExports() {}
-#if defined(OS_WIN)
- // See the definition of RenderPDFPageToDC in pdf.cc for details.
- virtual bool RenderPDFPageToDC(const void* pdf_buffer,
- int buffer_size,
- int page_number,
- const RenderingSettings& settings,
- HDC dc);
-#endif // OS_WIN
- virtual bool RenderPDFPageToBitmap(const void* pdf_buffer,
- int pdf_buffer_size,
- int page_number,
- const RenderingSettings& settings,
- void* bitmap_buffer);
-
- virtual bool GetPDFDocInfo(const void* pdf_buffer,
- int buffer_size,
- int* page_count,
- double* max_page_width);
-
- // See the definition of GetPDFPageSizeByIndex in pdf.cc for details.
- virtual bool GetPDFPageSizeByIndex(const void* pdf_buffer,
- int pdf_buffer_size, int page_number,
- double* width, double* height);
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_PDFIUM_PDFIUM_ENGINE_H_
diff --git a/xfa_test/pdf/pdfium/pdfium_mem_buffer_file_read.cc b/xfa_test/pdf/pdfium/pdfium_mem_buffer_file_read.cc
deleted file mode 100644
index b2371b42ff..0000000000
--- a/xfa_test/pdf/pdfium/pdfium_mem_buffer_file_read.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-// 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 "pdf/pdfium/pdfium_mem_buffer_file_read.h"
-
-#include <string.h>
-
-namespace chrome_pdf {
-
-PDFiumMemBufferFileRead::PDFiumMemBufferFileRead(const void* data,
- size_t size) {
- m_FileLen = size;
- m_Param = this;
- m_GetBlock = &GetBlock;
- data_ = reinterpret_cast<const unsigned char*>(data);
-}
-
-PDFiumMemBufferFileRead::~PDFiumMemBufferFileRead() {
-}
-
-int PDFiumMemBufferFileRead::GetBlock(void* param,
- unsigned long position,
- unsigned char* buf,
- unsigned long size) {
- const PDFiumMemBufferFileRead* data =
- reinterpret_cast<const PDFiumMemBufferFileRead*>(param);
- if (!data || position + size > data->m_FileLen)
- return 0;
- memcpy(buf, data->data_ + position, size);
- return 1;
-}
-
-} // namespace chrome_pdf
diff --git a/xfa_test/pdf/pdfium/pdfium_mem_buffer_file_read.h b/xfa_test/pdf/pdfium/pdfium_mem_buffer_file_read.h
deleted file mode 100644
index 88ec410a6c..0000000000
--- a/xfa_test/pdf/pdfium/pdfium_mem_buffer_file_read.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// 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.
-
-#ifndef PDF_PDFIUM_PDFIUM_MEM_BUFFER_FILE_READ_H_
-#define PDF_PDFIUM_PDFIUM_MEM_BUFFER_FILE_READ_H_
-
-#include <stdlib.h>
-
-#include "third_party/pdfium/fpdfsdk/include/fpdfview.h"
-
-namespace chrome_pdf {
-
-// Implementation of FPDF_FILEACCESS from a memory buffer.
-class PDFiumMemBufferFileRead : public FPDF_FILEACCESS {
- public:
- PDFiumMemBufferFileRead(const void* data, size_t size);
- ~PDFiumMemBufferFileRead();
-
- private:
- static int GetBlock(void* param,
- unsigned long position,
- unsigned char* buf,
- unsigned long size);
- const unsigned char* data_;
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_PDFIUM_PDFIUM_MEM_BUFFER_FILE_READ_H_
diff --git a/xfa_test/pdf/pdfium/pdfium_mem_buffer_file_write.cc b/xfa_test/pdf/pdfium/pdfium_mem_buffer_file_write.cc
deleted file mode 100644
index 45e564b67b..0000000000
--- a/xfa_test/pdf/pdfium/pdfium_mem_buffer_file_write.cc
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (c) 2010 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 "pdf/pdfium/pdfium_mem_buffer_file_write.h"
-
-namespace chrome_pdf {
-
-PDFiumMemBufferFileWrite::PDFiumMemBufferFileWrite() {
- version = 1;
- WriteBlock = &WriteBlockImpl;
-}
-
-PDFiumMemBufferFileWrite::~PDFiumMemBufferFileWrite() {
-}
-
-int PDFiumMemBufferFileWrite::WriteBlockImpl(FPDF_FILEWRITE* this_file_write,
- const void* data,
- unsigned long size) {
- PDFiumMemBufferFileWrite* mem_buffer_file_write =
- static_cast<PDFiumMemBufferFileWrite*>(this_file_write);
- return mem_buffer_file_write->DoWriteBlock(data, size);
-}
-
-int PDFiumMemBufferFileWrite::DoWriteBlock(const void* data,
- unsigned long size) {
- buffer_.append(static_cast<const unsigned char*>(data), size);
- return 1;
-}
-
-
-} // namespace chrome_pdf
-
diff --git a/xfa_test/pdf/pdfium/pdfium_mem_buffer_file_write.h b/xfa_test/pdf/pdfium/pdfium_mem_buffer_file_write.h
deleted file mode 100644
index 1795c83e89..0000000000
--- a/xfa_test/pdf/pdfium/pdfium_mem_buffer_file_write.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) 2010 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.
-
-#ifndef PDF_PDFIUM_PDFIUM_MEM_BUFFER_FILE_WRITE_
-#define PDF_PDFIUM_PDFIUM_MEM_BUFFER_FILE_WRITE_
-
-#include <string>
-
-#include "third_party/pdfium/fpdfsdk/include/fpdfsave.h"
-
-namespace chrome_pdf {
-
-// Implementation of FPDF_FILEWRITE into a memory buffer.
-class PDFiumMemBufferFileWrite : public FPDF_FILEWRITE {
- public:
- PDFiumMemBufferFileWrite();
- ~PDFiumMemBufferFileWrite();
-
- const std::basic_string<unsigned char>& buffer() { return buffer_; }
- size_t size() { return buffer_.size(); }
-
- private:
- int DoWriteBlock(const void* data, unsigned long size);
- static int WriteBlockImpl(FPDF_FILEWRITE* this_file_write, const void* data,
- unsigned long size);
-
- std::basic_string<unsigned char> buffer_;
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_PDFIUM_PDFIUM_MEM_BUFFER_FILE_WRITE_
-
diff --git a/xfa_test/pdf/pdfium/pdfium_page.cc b/xfa_test/pdf/pdfium/pdfium_page.cc
deleted file mode 100644
index d8a5dce5a2..0000000000
--- a/xfa_test/pdf/pdfium/pdfium_page.cc
+++ /dev/null
@@ -1,477 +0,0 @@
-// Copyright (c) 2010 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 "pdf/pdfium/pdfium_page.h"
-
-#include <math.h>
-
-#include "base/logging.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_util.h"
-#include "base/strings/utf_string_conversions.h"
-#include "base/values.h"
-#include "pdf/pdfium/pdfium_engine.h"
-
-// Used when doing hit detection.
-#define kTolerance 20.0
-
-// Dictionary Value key names for returning the accessible page content as JSON.
-const char kPageWidth[] = "width";
-const char kPageHeight[] = "height";
-const char kPageTextBox[] = "textBox";
-const char kTextBoxLeft[] = "left";
-const char kTextBoxTop[] = "top";
-const char kTextBoxWidth[] = "width";
-const char kTextBoxHeight[] = "height";
-const char kTextBoxFontSize[] = "fontSize";
-const char kTextBoxNodes[] = "textNodes";
-const char kTextNodeType[] = "type";
-const char kTextNodeText[] = "text";
-const char kTextNodeURL[] = "url";
-const char kTextNodeTypeText[] = "text";
-const char kTextNodeTypeURL[] = "url";
-const char kDocLinkURLPrefix[] = "#page";
-
-namespace chrome_pdf {
-
-PDFiumPage::PDFiumPage(PDFiumEngine* engine,
- int i,
- const pp::Rect& r,
- bool available)
- : engine_(engine),
- page_(NULL),
- text_page_(NULL),
- index_(i),
- rect_(r),
- calculated_links_(false),
- available_(available) {
-}
-
-PDFiumPage::~PDFiumPage() {
-}
-
-void PDFiumPage::Unload() {
- if (text_page_) {
- FPDFText_ClosePage(text_page_);
- text_page_ = NULL;
- }
-
- if (page_) {
- if (engine_->form()) {
- FORM_OnBeforeClosePage(page_, engine_->form());
- }
- FPDF_ClosePage(page_);
- page_ = NULL;
- }
-}
-
-FPDF_PAGE PDFiumPage::GetPage() {
- ScopedUnsupportedFeature scoped_unsupported_feature(engine_);
- if (!available_)
- return NULL;
- if (!page_) {
- page_ = FPDF_LoadPage(engine_->doc(), index_);
- if (page_ && engine_->form()) {
- FORM_OnAfterLoadPage(page_, engine_->form());
- }
- }
- return page_;
-}
-
-FPDF_PAGE PDFiumPage::GetPrintPage() {
- ScopedUnsupportedFeature scoped_unsupported_feature(engine_);
- if (!available_)
- return NULL;
- if (!page_)
- page_ = FPDF_LoadPage(engine_->doc(), index_);
- return page_;
-}
-
-void PDFiumPage::ClosePrintPage() {
- if (page_) {
- FPDF_ClosePage(page_);
- page_ = NULL;
- }
-}
-
-FPDF_TEXTPAGE PDFiumPage::GetTextPage() {
- if (!available_)
- return NULL;
- if (!text_page_)
- text_page_ = FPDFText_LoadPage(GetPage());
- return text_page_;
-}
-
-base::Value* PDFiumPage::GetAccessibleContentAsValue(int rotation) {
- base::DictionaryValue* node = new base::DictionaryValue();
-
- if (!available_)
- return node;
-
- double width = FPDF_GetPageWidth(GetPage());
- double height = FPDF_GetPageHeight(GetPage());
-
- base::ListValue* text = new base::ListValue();
- int box_count = FPDFText_CountRects(GetTextPage(), 0, GetCharCount());
- for (int i = 0; i < box_count; i++) {
- double left, top, right, bottom;
- FPDFText_GetRect(GetTextPage(), i, &left, &top, &right, &bottom);
- text->Append(
- GetTextBoxAsValue(height, left, top, right, bottom, rotation));
- }
-
- node->SetDouble(kPageWidth, width);
- node->SetDouble(kPageHeight, height);
- node->Set(kPageTextBox, text); // Takes ownership of |text|
-
- return node;
-}
-
-base::Value* PDFiumPage::GetTextBoxAsValue(double page_height,
- double left, double top,
- double right, double bottom,
- int rotation) {
- base::string16 text_utf16;
- int char_count =
- FPDFText_GetBoundedText(GetTextPage(), left, top, right, bottom, NULL, 0);
- if (char_count > 0) {
- unsigned short* data = reinterpret_cast<unsigned short*>(
- WriteInto(&text_utf16, char_count + 1));
- FPDFText_GetBoundedText(GetTextPage(),
- left, top, right, bottom,
- data, char_count);
- }
- std::string text_utf8 = base::UTF16ToUTF8(text_utf16);
-
- FPDF_LINK link = FPDFLink_GetLinkAtPoint(GetPage(), left, top);
- Area area;
- std::vector<LinkTarget> targets;
- if (link) {
- targets.push_back(LinkTarget());
- area = GetLinkTarget(link, &targets[0]);
- } else {
- pp::Rect rect(
- PageToScreen(pp::Point(), 1.0, left, top, right, bottom, rotation));
- GetLinks(rect, &targets);
- area = targets.size() == 0 ? TEXT_AREA : WEBLINK_AREA;
- }
-
- int char_index = FPDFText_GetCharIndexAtPos(GetTextPage(), left, top,
- kTolerance, kTolerance);
- double font_size = FPDFText_GetFontSize(GetTextPage(), char_index);
-
- base::DictionaryValue* node = new base::DictionaryValue();
- node->SetDouble(kTextBoxLeft, left);
- node->SetDouble(kTextBoxTop, page_height - top);
- node->SetDouble(kTextBoxWidth, right - left);
- node->SetDouble(kTextBoxHeight, top - bottom);
- node->SetDouble(kTextBoxFontSize, font_size);
-
- base::ListValue* text_nodes = new base::ListValue();
-
- if (area == DOCLINK_AREA) {
- std::string url = kDocLinkURLPrefix + base::IntToString(targets[0].page);
- text_nodes->Append(CreateURLNode(text_utf8, url));
- } else if (area == WEBLINK_AREA && link) {
- text_nodes->Append(CreateURLNode(text_utf8, targets[0].url));
- } else if (area == WEBLINK_AREA && !link) {
- size_t start = 0;
- for (size_t i = 0; i < targets.size(); ++i) {
- // Remove the extra NULL character at end.
- // Otherwise, find() will not return any matches.
- if (targets[i].url.size() > 0 &&
- targets[i].url[targets[i].url.size() - 1] == '\0') {
- targets[i].url.resize(targets[i].url.size() - 1);
- }
- // There should only ever be one NULL character
- DCHECK(targets[i].url[targets[i].url.size() - 1] != '\0');
-
- // PDFium may change the case of generated links.
- std::string lowerCaseURL = base::StringToLowerASCII(targets[i].url);
- std::string lowerCaseText = base::StringToLowerASCII(text_utf8);
- size_t pos = lowerCaseText.find(lowerCaseURL, start);
- size_t length = targets[i].url.size();
- if (pos == std::string::npos) {
- // Check if the link is a "mailto:" URL
- if (lowerCaseURL.compare(0, 7, "mailto:") == 0) {
- pos = lowerCaseText.find(lowerCaseURL.substr(7), start);
- length -= 7;
- }
-
- if (pos == std::string::npos) {
- // No match has been found. This should never happen.
- continue;
- }
- }
-
- std::string before_text = text_utf8.substr(start, pos - start);
- if (before_text.size() > 0)
- text_nodes->Append(CreateTextNode(before_text));
- std::string link_text = text_utf8.substr(pos, length);
- text_nodes->Append(CreateURLNode(link_text, targets[i].url));
-
- start = pos + length;
- }
- std::string before_text = text_utf8.substr(start);
- if (before_text.size() > 0)
- text_nodes->Append(CreateTextNode(before_text));
- } else {
- text_nodes->Append(CreateTextNode(text_utf8));
- }
-
- node->Set(kTextBoxNodes, text_nodes); // Takes ownership of |text_nodes|.
- return node;
-}
-
-base::Value* PDFiumPage::CreateTextNode(std::string text) {
- base::DictionaryValue* node = new base::DictionaryValue();
- node->SetString(kTextNodeType, kTextNodeTypeText);
- node->SetString(kTextNodeText, text);
- return node;
-}
-
-base::Value* PDFiumPage::CreateURLNode(std::string text, std::string url) {
- base::DictionaryValue* node = new base::DictionaryValue();
- node->SetString(kTextNodeType, kTextNodeTypeURL);
- node->SetString(kTextNodeText, text);
- node->SetString(kTextNodeURL, url);
- return node;
-}
-
-PDFiumPage::Area PDFiumPage::GetCharIndex(const pp::Point& point,
- int rotation,
- int* char_index,
- LinkTarget* target) {
- if (!available_)
- return NONSELECTABLE_AREA;
- pp::Point point2 = point - rect_.point();
- double new_x, new_y;
- FPDF_DeviceToPage(GetPage(), 0, 0, rect_.width(), rect_.height(),
- rotation, point2.x(), point2.y(), &new_x, &new_y);
-
- int rv = FPDFText_GetCharIndexAtPos(
- GetTextPage(), new_x, new_y, kTolerance, kTolerance);
- *char_index = rv;
-
- FPDF_LINK link = FPDFLink_GetLinkAtPoint(GetPage(), new_x, new_y);
- if (link) {
- // We don't handle all possible link types of the PDF. For example,
- // launch actions, cross-document links, etc.
- // In that case, GetLinkTarget() will return NONSELECTABLE_AREA
- // and we should proceed with area detection.
- PDFiumPage::Area area = GetLinkTarget(link, target);
- if (area != PDFiumPage::NONSELECTABLE_AREA)
- return area;
- }
-
- if (rv < 0)
- return NONSELECTABLE_AREA;
-
- return GetLink(*char_index, target) != -1 ? WEBLINK_AREA : TEXT_AREA;
-}
-
-base::char16 PDFiumPage::GetCharAtIndex(int index) {
- if (!available_)
- return L'\0';
- return static_cast<base::char16>(FPDFText_GetUnicode(GetTextPage(), index));
-}
-
-int PDFiumPage::GetCharCount() {
- if (!available_)
- return 0;
- return FPDFText_CountChars(GetTextPage());
-}
-
-PDFiumPage::Area PDFiumPage::GetLinkTarget(
- FPDF_LINK link, PDFiumPage::LinkTarget* target) {
- FPDF_DEST dest = FPDFLink_GetDest(engine_->doc(), link);
- if (dest != NULL)
- return GetDestinationTarget(dest, target);
-
- FPDF_ACTION action = FPDFLink_GetAction(link);
- if (action) {
- switch (FPDFAction_GetType(action)) {
- case PDFACTION_GOTO: {
- FPDF_DEST dest = FPDFAction_GetDest(engine_->doc(), action);
- if (dest)
- return GetDestinationTarget(dest, target);
- // TODO(gene): We don't fully support all types of the in-document
- // links. Need to implement that. There is a bug to track that:
- // http://code.google.com/p/chromium/issues/detail?id=55776
- } break;
- case PDFACTION_URI: {
- if (target) {
- size_t buffer_size =
- FPDFAction_GetURIPath(engine_->doc(), action, NULL, 0);
- if (buffer_size > 1) {
- void* data = WriteInto(&target->url, buffer_size + 1);
- FPDFAction_GetURIPath(engine_->doc(), action, data, buffer_size);
- }
- }
- return WEBLINK_AREA;
- } break;
- // TODO(gene): We don't support PDFACTION_REMOTEGOTO and PDFACTION_LAUNCH
- // at the moment.
- }
- }
-
- return NONSELECTABLE_AREA;
-}
-
-PDFiumPage::Area PDFiumPage::GetDestinationTarget(
- FPDF_DEST destination, PDFiumPage::LinkTarget* target) {
- int page_index = FPDFDest_GetPageIndex(engine_->doc(), destination);
- if (target) {
- target->page = page_index;
- }
- return DOCLINK_AREA;
-}
-
-int PDFiumPage::GetLink(int char_index, PDFiumPage::LinkTarget* target) {
- if (!available_)
- return -1;
-
- CalculateLinks();
-
- // Get the bounding box of the rect again, since it might have moved because
- // of the tolerance above.
- double left, right, bottom, top;
- FPDFText_GetCharBox(GetTextPage(), char_index, &left, &right, &bottom, &top);
-
- pp::Point origin(
- PageToScreen(pp::Point(), 1.0, left, top, right, bottom, 0).point());
- for (size_t i = 0; i < links_.size(); ++i) {
- for (size_t j = 0; j < links_[i].rects.size(); ++j) {
- if (links_[i].rects[j].Contains(origin)) {
- if (target)
- target->url = links_[i].url;
- return i;
- }
- }
- }
- return -1;
-}
-
-std::vector<int> PDFiumPage::GetLinks(pp::Rect text_area,
- std::vector<LinkTarget>* targets) {
- if (!available_)
- return std::vector<int>();
-
- CalculateLinks();
-
- std::vector<int> links;
-
- for (size_t i = 0; i < links_.size(); ++i) {
- for (size_t j = 0; j < links_[i].rects.size(); ++j) {
- if (links_[i].rects[j].Intersects(text_area)) {
- if (targets) {
- LinkTarget target;
- target.url = links_[i].url;
- targets->push_back(target);
- }
- links.push_back(i);
- }
- }
- }
- return links;
-}
-
-void PDFiumPage::CalculateLinks() {
- if (calculated_links_)
- return;
-
- calculated_links_ = true;
- FPDF_PAGELINK links = FPDFLink_LoadWebLinks(GetTextPage());
- int count = FPDFLink_CountWebLinks(links);
- for (int i = 0; i < count; ++i) {
- base::string16 url;
- int url_length = FPDFLink_GetURL(links, i, NULL, 0);
- if (url_length > 1) { // WriteInto needs at least 2 characters.
- unsigned short* data =
- reinterpret_cast<unsigned short*>(WriteInto(&url, url_length + 1));
- FPDFLink_GetURL(links, i, data, url_length);
- }
- Link link;
- link.url = base::UTF16ToUTF8(url);
-
- // If the link cannot be converted to a pp::Var, then it is not possible to
- // pass it to JS. In this case, ignore the link like other PDF viewers.
- // See http://crbug.com/312882 for an example.
- pp::Var link_var(link.url);
- if (!link_var.is_string())
- continue;
-
- // Make sure all the characters in the URL are valid per RFC 1738.
- // http://crbug.com/340326 has a sample bad PDF.
- // GURL does not work correctly, e.g. it just strips \t \r \n.
- bool is_invalid_url = false;
- for (size_t j = 0; j < link.url.length(); ++j) {
- // Control characters are not allowed.
- // 0x7F is also a control character.
- // 0x80 and above are not in US-ASCII.
- if (link.url[j] < ' ' || link.url[j] >= '\x7F') {
- is_invalid_url = true;
- break;
- }
- }
- if (is_invalid_url)
- continue;
-
- int rect_count = FPDFLink_CountRects(links, i);
- for (int j = 0; j < rect_count; ++j) {
- double left, top, right, bottom;
- FPDFLink_GetRect(links, i, j, &left, &top, &right, &bottom);
- link.rects.push_back(
- PageToScreen(pp::Point(), 1.0, left, top, right, bottom, 0));
- }
- links_.push_back(link);
- }
- FPDFLink_CloseWebLinks(links);
-}
-
-pp::Rect PDFiumPage::PageToScreen(const pp::Point& offset,
- double zoom,
- double left,
- double top,
- double right,
- double bottom,
- int rotation) {
- if (!available_)
- return pp::Rect();
-
- int new_left, new_top, new_right, new_bottom;
- FPDF_PageToDevice(
- page_,
- static_cast<int>((rect_.x() - offset.x()) * zoom),
- static_cast<int>((rect_.y() - offset.y()) * zoom),
- static_cast<int>(ceil(rect_.width() * zoom)),
- static_cast<int>(ceil(rect_.height() * zoom)),
- rotation, left, top, &new_left, &new_top);
- FPDF_PageToDevice(
- page_,
- static_cast<int>((rect_.x() - offset.x()) * zoom),
- static_cast<int>((rect_.y() - offset.y()) * zoom),
- static_cast<int>(ceil(rect_.width() * zoom)),
- static_cast<int>(ceil(rect_.height() * zoom)),
- rotation, right, bottom, &new_right, &new_bottom);
-
- // If the PDF is rotated, the horizontal/vertical coordinates could be
- // flipped. See
- // http://www.netl.doe.gov/publications/proceedings/03/ubc/presentations/Goeckner-pres.pdf
- if (new_right < new_left)
- std::swap(new_right, new_left);
- if (new_bottom < new_top)
- std::swap(new_bottom, new_top);
-
- return pp::Rect(
- new_left, new_top, new_right - new_left + 1, new_bottom - new_top + 1);
-}
-
-PDFiumPage::Link::Link() {
-}
-
-PDFiumPage::Link::~Link() {
-}
-
-} // namespace chrome_pdf
diff --git a/xfa_test/pdf/pdfium/pdfium_page.h b/xfa_test/pdf/pdfium/pdfium_page.h
deleted file mode 100644
index 22ea142988..0000000000
--- a/xfa_test/pdf/pdfium/pdfium_page.h
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright (c) 2010 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.
-
-#ifndef PDF_PDFIUM_PDFIUM_PAGE_H_
-#define PDF_PDFIUM_PDFIUM_PAGE_H_
-
-#include <string>
-#include <vector>
-
-#include "base/strings/string16.h"
-#include "ppapi/cpp/rect.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdfdoc.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdfformfill.h"
-#include "third_party/pdfium/fpdfsdk/include/fpdftext.h"
-
-namespace base {
-class Value;
-}
-
-namespace chrome_pdf {
-
-class PDFiumEngine;
-
-// Wrapper around a page from the document.
-class PDFiumPage {
- public:
- PDFiumPage(PDFiumEngine* engine,
- int i,
- const pp::Rect& r,
- bool available);
- ~PDFiumPage();
- // Unloads the PDFium data for this page from memory.
- void Unload();
- // Gets the FPDF_PAGE for this page, loading and parsing it if necessary.
- FPDF_PAGE GetPage();
- //Get the FPDF_PAGE for printing.
- FPDF_PAGE GetPrintPage();
- //Close the printing page.
- void ClosePrintPage();
-
- // Returns FPDF_TEXTPAGE for the page, loading and parsing it if necessary.
- FPDF_TEXTPAGE GetTextPage();
-
- // Returns a DictionaryValue version of the page.
- base::Value* GetAccessibleContentAsValue(int rotation);
-
- enum Area {
- NONSELECTABLE_AREA,
- TEXT_AREA,
- WEBLINK_AREA, // Area is a hyperlink.
- DOCLINK_AREA, // Area is a link to a different part of the same document.
- };
-
- struct LinkTarget {
- // We are using std::string here which have a copy contructor.
- // That prevents us from using union here.
- std::string url; // Valid for WEBLINK_AREA only.
- int page; // Valid for DOCLINK_AREA only.
- };
-
- // Given a point in the document that's in this page, returns its character
- // index if it's near a character, and also the type of text.
- // Target is optional. It will be filled in for WEBLINK_AREA or
- // DOCLINK_AREA only.
- Area GetCharIndex(const pp::Point& point, int rotation, int* char_index,
- LinkTarget* target);
-
- // Gets the character at the given index.
- base::char16 GetCharAtIndex(int index);
-
- // Gets the number of characters in the page.
- int GetCharCount();
-
- // Converts from page coordinates to screen coordinates.
- pp::Rect PageToScreen(const pp::Point& offset,
- double zoom,
- double left,
- double top,
- double right,
- double bottom,
- int rotation);
-
- int index() const { return index_; }
- pp::Rect rect() const { return rect_; }
- void set_rect(const pp::Rect& r) { rect_ = r; }
- bool available() const { return available_; }
- void set_available(bool available) { available_ = available; }
- void set_calculated_links(bool calculated_links) {
- calculated_links_ = calculated_links;
- }
-
- private:
- // Returns a link index if the given character index is over a link, or -1
- // otherwise.
- int GetLink(int char_index, LinkTarget* target);
- // Returns the link indices if the given rect intersects a link rect, or an
- // empty vector otherwise.
- std::vector<int> GetLinks(pp::Rect text_area,
- std::vector<LinkTarget>* targets);
- // Calculate the locations of any links on the page.
- void CalculateLinks();
- // Returns link type and target associated with a link. Returns
- // NONSELECTABLE_AREA if link detection failed.
- Area GetLinkTarget(FPDF_LINK link, LinkTarget* target);
- // Returns target associated with a destination.
- Area GetDestinationTarget(FPDF_DEST destination, LinkTarget* target);
- // Returns the text in the supplied box as a Value Node
- base::Value* GetTextBoxAsValue(double page_height, double left, double top,
- double right, double bottom, int rotation);
- // Helper functions for JSON generation
- base::Value* CreateTextNode(std::string text);
- base::Value* CreateURLNode(std::string text, std::string url);
-
- struct Link {
- Link();
- ~Link();
-
- std::string url;
- // Bounding rectangles of characters.
- std::vector<pp::Rect> rects;
- };
-
- PDFiumEngine* engine_;
- FPDF_PAGE page_;
- FPDF_TEXTPAGE text_page_;
- int index_;
- pp::Rect rect_;
- bool calculated_links_;
- std::vector<Link> links_;
- bool available_;
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_PDFIUM_PDFIUM_PAGE_H_
diff --git a/xfa_test/pdf/pdfium/pdfium_range.cc b/xfa_test/pdf/pdfium/pdfium_range.cc
deleted file mode 100644
index c77d5906dd..0000000000
--- a/xfa_test/pdf/pdfium/pdfium_range.cc
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (c) 2010 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 "pdf/pdfium/pdfium_range.h"
-
-#include "base/logging.h"
-#include "base/strings/string_util.h"
-
-namespace chrome_pdf {
-
-PDFiumRange::PDFiumRange(PDFiumPage* page, int char_index, int char_count)
- : page_(page),
- char_index_(char_index),
- char_count_(char_count),
- cached_screen_rects_zoom_(0) {
-}
-
-PDFiumRange::~PDFiumRange() {
-}
-
-void PDFiumRange::SetCharCount(int char_count) {
- char_count_ = char_count;
-
- cached_screen_rects_offset_ = pp::Point();
- cached_screen_rects_zoom_ = 0;
-}
-
-std::vector<pp::Rect> PDFiumRange::GetScreenRects(const pp::Point& offset,
- double zoom,
- int rotation) {
- if (offset == cached_screen_rects_offset_ &&
- zoom == cached_screen_rects_zoom_) {
- return cached_screen_rects_;
- }
-
- cached_screen_rects_.clear();
- cached_screen_rects_offset_ = offset;
- cached_screen_rects_zoom_ = zoom;
-
- int char_index = char_index_;
- int char_count = char_count_;
- if (char_count < 0) {
- char_count *= -1;
- char_index -= char_count - 1;
- }
-
- int count = FPDFText_CountRects(page_->GetTextPage(), char_index, char_count);
- for (int i = 0; i < count; ++i) {
- double left, top, right, bottom;
- FPDFText_GetRect(page_->GetTextPage(), i, &left, &top, &right, &bottom);
- cached_screen_rects_.push_back(
- page_->PageToScreen(offset, zoom, left, top, right, bottom, rotation));
- }
-
- return cached_screen_rects_;
-}
-
-base::string16 PDFiumRange::GetText() {
- int index = char_index_;
- int count = char_count_;
- if (!count)
- return base::string16();
- if (count < 0) {
- count *= -1;
- index -= count - 1;
- }
-
- base::string16 rv;
- unsigned short* data =
- reinterpret_cast<unsigned short*>(WriteInto(&rv, count + 1));
- if (data) {
- int written = FPDFText_GetText(page_->GetTextPage(), index, count, data);
- rv.reserve(written);
- }
- return rv;
-}
-
-} // namespace chrome_pdf
diff --git a/xfa_test/pdf/pdfium/pdfium_range.h b/xfa_test/pdf/pdfium/pdfium_range.h
deleted file mode 100644
index ed8daf65bb..0000000000
--- a/xfa_test/pdf/pdfium/pdfium_range.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright (c) 2010 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.
-
-#ifndef PDF_PDFIUM_PDFIUM_RANGE_H_
-#define PDF_PDFIUM_PDFIUM_RANGE_H_
-
-#include <string>
-#include <vector>
-
-#include "base/strings/string16.h"
-#include "pdf/pdfium/pdfium_page.h"
-#include "ppapi/cpp/rect.h"
-
-namespace chrome_pdf {
-
-// Describes location of a string of characters.
-class PDFiumRange {
- public:
- PDFiumRange(PDFiumPage* page, int char_index, int char_count);
- ~PDFiumRange();
-
- // Update how many characters are in the selection. Could be negative if
- // backwards.
- void SetCharCount(int char_count);
-
- int page_index() const { return page_->index(); }
- int char_index() const { return char_index_; }
- int char_count() const { return char_count_; }
-
- // Gets bounding rectangles of range in screen coordinates.
- std::vector<pp::Rect> GetScreenRects(const pp::Point& offset,
- double zoom,
- int rotation);
-
- // Gets the string of characters in this range.
- base::string16 GetText();
-
- private:
- PDFiumPage* page_;
- // Index of first character.
- int char_index_;
- // How many characters are part of this range (negative if backwards).
- int char_count_;
-
- // Cache of ScreenRect, and the associated variables used when caching it.
- std::vector<pp::Rect> cached_screen_rects_;
- pp::Point cached_screen_rects_offset_;
- double cached_screen_rects_zoom_;
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_PDFIUM_PDFIUM_RANGE_H_
diff --git a/xfa_test/pdf/preview_mode_client.cc b/xfa_test/pdf/preview_mode_client.cc
deleted file mode 100644
index 8b9919b46e..0000000000
--- a/xfa_test/pdf/preview_mode_client.cc
+++ /dev/null
@@ -1,162 +0,0 @@
-// Copyright (c) 2011 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 "pdf/preview_mode_client.h"
-
-#include "base/logging.h"
-#include "pdf/instance.h"
-
-namespace chrome_pdf {
-
-PreviewModeClient::PreviewModeClient(Client* client)
- : client_(client) {
-}
-
-void PreviewModeClient::DocumentSizeUpdated(const pp::Size& size) {
-}
-
-void PreviewModeClient::Invalidate(const pp::Rect& rect) {
- NOTREACHED();
-}
-
-void PreviewModeClient::Scroll(const pp::Point& point) {
- NOTREACHED();
-}
-
-void PreviewModeClient::ScrollToX(int position) {
- NOTREACHED();
-}
-
-void PreviewModeClient::ScrollToY(int position) {
- NOTREACHED();
-}
-
-void PreviewModeClient::ScrollToPage(int page) {
- NOTREACHED();
-}
-
-void PreviewModeClient::NavigateTo(const std::string& url,
- bool open_in_new_tab) {
- NOTREACHED();
-}
-
-void PreviewModeClient::UpdateCursor(PP_CursorType_Dev cursor) {
- NOTREACHED();
-}
-
-void PreviewModeClient::UpdateTickMarks(
- const std::vector<pp::Rect>& tickmarks) {
- NOTREACHED();
-}
-
-void PreviewModeClient::NotifyNumberOfFindResultsChanged(int total,
- bool final_result) {
- NOTREACHED();
-}
-
-void PreviewModeClient::NotifySelectedFindResultChanged(
- int current_find_index) {
- NOTREACHED();
-}
-
-void PreviewModeClient::GetDocumentPassword(
- pp::CompletionCallbackWithOutput<pp::Var> callback) {
- callback.Run(PP_ERROR_FAILED);
-}
-
-void PreviewModeClient::Alert(const std::string& message) {
- NOTREACHED();
-}
-
-bool PreviewModeClient::Confirm(const std::string& message) {
- NOTREACHED();
- return false;
-}
-
-std::string PreviewModeClient::Prompt(const std::string& question,
- const std::string& default_answer) {
- NOTREACHED();
- return std::string();
-}
-
-std::string PreviewModeClient::GetURL() {
- NOTREACHED();
- return std::string();
-}
-
-void PreviewModeClient::Email(const std::string& to,
- const std::string& cc,
- const std::string& bcc,
- const std::string& subject,
- const std::string& body) {
- NOTREACHED();
-}
-
-void PreviewModeClient::Print() {
- NOTREACHED();
-}
-
-void PreviewModeClient::SubmitForm(const std::string& url,
- const void* data,
- int length) {
- NOTREACHED();
-}
-
-std::string PreviewModeClient::ShowFileSelectionDialog() {
- NOTREACHED();
- return std::string();
-}
-
-pp::URLLoader PreviewModeClient::CreateURLLoader() {
- NOTREACHED();
- return pp::URLLoader();
-}
-
-void PreviewModeClient::ScheduleCallback(int id, int delay_in_ms) {
- NOTREACHED();
-}
-
-void PreviewModeClient::SearchString(const base::char16* string,
- const base::char16* term,
- bool case_sensitive,
- std::vector<SearchStringResult>* results) {
- NOTREACHED();
-}
-
-void PreviewModeClient::DocumentPaintOccurred() {
- NOTREACHED();
-}
-
-void PreviewModeClient::DocumentLoadComplete(int page_count) {
- client_->PreviewDocumentLoadComplete();
-}
-
-void PreviewModeClient::DocumentLoadFailed() {
- client_->PreviewDocumentLoadFailed();
-}
-
-pp::Instance* PreviewModeClient::GetPluginInstance() {
- NOTREACHED();
- return NULL;
-}
-
-void PreviewModeClient::DocumentHasUnsupportedFeature(
- const std::string& feature) {
- NOTREACHED();
-}
-
-void PreviewModeClient::DocumentLoadProgress(uint32 available,
- uint32 doc_size) {
-}
-
-void PreviewModeClient::FormTextFieldFocusChange(bool in_focus) {
- NOTREACHED();
-}
-
-bool PreviewModeClient::IsPrintPreview() {
- NOTREACHED();
- return false;
-}
-
-} // namespace chrome_pdf
diff --git a/xfa_test/pdf/preview_mode_client.h b/xfa_test/pdf/preview_mode_client.h
deleted file mode 100644
index 0e766f949f..0000000000
--- a/xfa_test/pdf/preview_mode_client.h
+++ /dev/null
@@ -1,77 +0,0 @@
-// Copyright (c) 2011 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.
-
-#ifndef PDF_PREVIEW_MODE_CLIENT_H_
-#define PDF_PREVIEW_MODE_CLIENT_H_
-
-#include <string>
-#include <vector>
-
-#include "pdf/pdf_engine.h"
-
-namespace chrome_pdf {
-
-// The interface that's provided to the print preview rendering engine.
-class PreviewModeClient : public PDFEngine::Client {
- public:
- class Client {
- public:
- virtual void PreviewDocumentLoadFailed() = 0;
- virtual void PreviewDocumentLoadComplete() = 0;
- };
- explicit PreviewModeClient(Client* client);
- virtual ~PreviewModeClient() {}
-
- // PDFEngine::Client implementation.
- virtual void DocumentSizeUpdated(const pp::Size& size);
- virtual void Invalidate(const pp::Rect& rect);
- virtual void Scroll(const pp::Point& point);
- virtual void ScrollToX(int position);
- virtual void ScrollToY(int position);
- virtual void ScrollToPage(int page);
- virtual void NavigateTo(const std::string& url, bool open_in_new_tab);
- virtual void UpdateCursor(PP_CursorType_Dev cursor);
- virtual void UpdateTickMarks(const std::vector<pp::Rect>& tickmarks);
- virtual void NotifyNumberOfFindResultsChanged(int total,
- bool final_result);
- virtual void NotifySelectedFindResultChanged(int current_find_index);
- virtual void GetDocumentPassword(
- pp::CompletionCallbackWithOutput<pp::Var> callback);
- virtual void Alert(const std::string& message);
- virtual bool Confirm(const std::string& message);
- virtual std::string Prompt(const std::string& question,
- const std::string& default_answer);
- virtual std::string GetURL();
- virtual void Email(const std::string& to,
- const std::string& cc,
- const std::string& bcc,
- const std::string& subject,
- const std::string& body);
- virtual void Print();
- virtual void SubmitForm(const std::string& url,
- const void* data,
- int length);
- virtual std::string ShowFileSelectionDialog();
- virtual pp::URLLoader CreateURLLoader();
- virtual void ScheduleCallback(int id, int delay_in_ms);
- virtual void SearchString(const base::char16* string,
- const base::char16* term,
- bool case_sensitive,
- std::vector<SearchStringResult>* results);
- virtual void DocumentPaintOccurred();
- virtual void DocumentLoadComplete(int page_count);
- virtual void DocumentLoadFailed();
- virtual pp::Instance* GetPluginInstance();
- virtual void DocumentHasUnsupportedFeature(const std::string& feature);
- virtual void DocumentLoadProgress(uint32 available, uint32 doc_size);
- virtual void FormTextFieldFocusChange(bool in_focus);
- virtual bool IsPrintPreview();
-
- private:
- Client* client_;
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_PREVIEW_MODE_CLIENT_H_
diff --git a/xfa_test/pdf/progress_control.cc b/xfa_test/pdf/progress_control.cc
deleted file mode 100644
index 2c2bca4e42..0000000000
--- a/xfa_test/pdf/progress_control.cc
+++ /dev/null
@@ -1,283 +0,0 @@
-// Copyright (c) 2011 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 "pdf/progress_control.h"
-
-#include <algorithm>
-
-#include "base/logging.h"
-#include "pdf/draw_utils.h"
-#include "pdf/resource_consts.h"
-#include "ppapi/cpp/dev/font_dev.h"
-
-namespace chrome_pdf {
-
-const double ProgressControl::kCompleted = 100.0;
-
-// There is a bug outputting text with alpha 0xFF (opaque) to an intermediate
-// image. It outputs alpha channgel of the text pixels to 0xFF (transparent).
-// And it breaks next alpha blending.
-// For now, let's use alpha 0xFE to work around this bug.
-// TODO(gene): investigate this bug.
-const uint32 kProgressTextColor = 0xFEDDE6FC;
-const uint32 kProgressTextSize = 16;
-const uint32 kImageTextSpacing = 8;
-const uint32 kTopPadding = 8;
-const uint32 kBottomPadding = 12;
-const uint32 kLeftPadding = 10;
-const uint32 kRightPadding = 10;
-
-int ScaleInt(int val, float scale) {
- return static_cast<int>(val * scale);
-}
-
-ProgressControl::ProgressControl()
- : progress_(0.0),
- device_scale_(1.0) {
-}
-
-ProgressControl::~ProgressControl() {
-}
-
-bool ProgressControl::CreateProgressControl(
- uint32 id,
- bool visible,
- Control::Owner* delegate,
- double progress,
- float device_scale,
- const std::vector<pp::ImageData>& images,
- const pp::ImageData& background,
- const std::string& text) {
- progress_ = progress;
- text_ = text;
- bool res = Control::Create(id, pp::Rect(), visible, delegate);
- if (res)
- Reconfigure(background, images, device_scale);
- return res;
-}
-
-void ProgressControl::Reconfigure(const pp::ImageData& background,
- const std::vector<pp::ImageData>& images,
- float device_scale) {
- DCHECK(images.size() != 0);
- images_ = images;
- background_ = background;
- device_scale_ = device_scale;
- pp::Size ctrl_size;
- CalculateLayout(owner()->GetInstance(), images_, background_, text_,
- device_scale_, &ctrl_size, &image_rc_, &text_rc_);
- pp::Rect rc(pp::Point(), ctrl_size);
- Control::SetRect(rc, false);
- PrepareBackground();
-}
-
-// static
-void ProgressControl::CalculateLayout(pp::Instance* instance,
- const std::vector<pp::ImageData>& images,
- const pp::ImageData& background,
- const std::string& text,
- float device_scale,
- pp::Size* ctrl_size,
- pp::Rect* image_rc,
- pp::Rect* text_rc) {
- DCHECK(images.size() != 0);
- int image_width = 0;
- int image_height = 0;
- for (size_t i = 0; i < images.size(); i++) {
- image_width = std::max(image_width, images[i].size().width());
- image_height = std::max(image_height, images[i].size().height());
- }
-
- pp::FontDescription_Dev description;
- description.set_family(PP_FONTFAMILY_SANSSERIF);
- description.set_size(ScaleInt(kProgressTextSize, device_scale));
- description.set_weight(PP_FONTWEIGHT_BOLD);
- pp::Font_Dev font(instance, description);
- int text_length = font.MeasureSimpleText(text);
-
- pp::FontDescription_Dev desc;
- PP_FontMetrics_Dev metrics;
- font.Describe(&desc, &metrics);
- int text_height = metrics.height;
-
- *ctrl_size = pp::Size(
- image_width + text_length +
- ScaleInt(kImageTextSpacing + kLeftPadding + kRightPadding, device_scale),
- std::max(image_height, text_height) +
- ScaleInt(kTopPadding + kBottomPadding, device_scale));
-
- int offset_x = 0;
- int offset_y = 0;
- if (ctrl_size->width() < background.size().width()) {
- offset_x += (background.size().width() - ctrl_size->width()) / 2;
- ctrl_size->set_width(background.size().width());
- }
- if (ctrl_size->height() < background.size().height()) {
- offset_y += (background.size().height() - ctrl_size->height()) / 2;
- ctrl_size->set_height(background.size().height());
- }
-
- *image_rc = pp::Rect(ScaleInt(kLeftPadding, device_scale) + offset_x,
- ScaleInt(kTopPadding, device_scale) + offset_y,
- image_width,
- image_height);
-
- *text_rc = pp::Rect(
- ctrl_size->width() - text_length -
- ScaleInt(kRightPadding, device_scale) - offset_x,
- (ctrl_size->height() - text_height) / 2,
- text_length,
- text_height);
-}
-
-size_t ProgressControl::GetImageIngex() const {
- return static_cast<size_t>((progress_ / 100.0) * images_.size());
-}
-
-void ProgressControl::Paint(pp::ImageData* image_data, const pp::Rect& rc) {
- if (!visible())
- return;
-
- pp::Rect draw_rc = rect().Intersect(rc);
- if (draw_rc.IsEmpty())
- return;
-
- pp::ImageData buffer(owner()->GetInstance(), ctrl_background_.format(),
- ctrl_background_.size(), false);
- CopyImage(ctrl_background_, pp::Rect(ctrl_background_.size()),
- &buffer, pp::Rect(ctrl_background_.size()), false);
-
- size_t index = GetImageIngex();
- if (index >= images_.size())
- index = images_.size() - 1;
-
- AlphaBlend(images_[index],
- pp::Rect(images_[index].size()),
- &buffer,
- image_rc_.point(),
- kOpaqueAlpha);
-
- pp::Rect image_draw_rc(draw_rc);
- image_draw_rc.Offset(-rect().x(), -rect().y());
- AlphaBlend(buffer,
- image_draw_rc,
- image_data,
- draw_rc.point(),
- transparency());
-}
-
-void ProgressControl::SetProgress(double progress) {
- size_t old_index = GetImageIngex();
- progress_ = progress;
- size_t new_index = GetImageIngex();
- if (progress_ >= kCompleted) {
- progress_ = kCompleted;
- owner()->OnEvent(id(), EVENT_ID_PROGRESS_COMPLETED, NULL);
- }
- if (visible() && old_index != new_index)
- owner()->Invalidate(id(), rect());
-}
-
-void ProgressControl::PrepareBackground() {
- AdjustBackground();
-
- pp::FontDescription_Dev description;
- description.set_family(PP_FONTFAMILY_SANSSERIF);
- description.set_size(ScaleInt(kProgressTextSize, device_scale_));
- description.set_weight(PP_FONTWEIGHT_BOLD);
- pp::Font_Dev font(owner()->GetInstance(), description);
-
- pp::FontDescription_Dev desc;
- PP_FontMetrics_Dev metrics;
- font.Describe(&desc, &metrics);
-
- pp::Point text_origin = pp::Point(text_rc_.x(),
- (text_rc_.y() + text_rc_.bottom() + metrics.x_height) / 2);
- font.DrawTextAt(&ctrl_background_, pp::TextRun_Dev(text_), text_origin,
- kProgressTextColor, pp::Rect(ctrl_background_.size()), false);
-}
-
-void ProgressControl::AdjustBackground() {
- ctrl_background_ = pp::ImageData(owner()->GetInstance(),
- PP_IMAGEDATAFORMAT_BGRA_PREMUL,
- rect().size(),
- false);
-
- if (rect().size() == background_.size()) {
- CopyImage(background_, pp::Rect(background_.size()),
- &ctrl_background_, pp::Rect(ctrl_background_.size()), false);
- return;
- }
-
- // We need to stretch background to new dimentions. To do so, we split
- // background into 9 different parts. We copy corner rects (1,3,7,9) as is,
- // stretch rectangles between corners (2,4,6,8) in 1 dimention, and
- // stretch center rect (5) in 2 dimentions.
- // |---|---|---|
- // | 1 | 2 | 3 |
- // |---|---|---|
- // | 4 | 5 | 6 |
- // |---|---|---|
- // | 7 | 8 | 9 |
- // |---|---|---|
- int slice_x = background_.size().width() / 3;
- int slice_y = background_.size().height() / 3;
-
- // Copy rect 1
- pp::Rect src_rc(0, 0, slice_x, slice_y);
- pp::Rect dest_rc(0, 0, slice_x, slice_y);
- CopyImage(background_, src_rc, &ctrl_background_, dest_rc, false);
-
- // Copy rect 3
- src_rc.set_x(background_.size().width() - slice_x);
- dest_rc.set_x(ctrl_background_.size().width() - slice_x);
- CopyImage(background_, src_rc, &ctrl_background_, dest_rc, false);
-
- // Copy rect 9
- src_rc.set_y(background_.size().height() - slice_y);
- dest_rc.set_y(ctrl_background_.size().height() - slice_y);
- CopyImage(background_, src_rc, &ctrl_background_, dest_rc, false);
-
- // Copy rect 7
- src_rc.set_x(0);
- dest_rc.set_x(0);
- CopyImage(background_, src_rc, &ctrl_background_, dest_rc, false);
-
- // Stretch rect 2
- src_rc = pp::Rect(
- slice_x, 0, background_.size().width() - 2 * slice_x, slice_y);
- dest_rc = pp::Rect(
- slice_x, 0, ctrl_background_.size().width() - 2 * slice_x, slice_y);
- CopyImage(background_, src_rc, &ctrl_background_, dest_rc, true);
-
- // Copy rect 8
- src_rc.set_y(background_.size().height() - slice_y);
- dest_rc.set_y(ctrl_background_.size().height() - slice_y);
- CopyImage(background_, src_rc, &ctrl_background_, dest_rc, true);
-
- // Stretch rect 4
- src_rc = pp::Rect(
- 0, slice_y, slice_x, background_.size().height() - 2 * slice_y);
- dest_rc = pp::Rect(
- 0, slice_y, slice_x, ctrl_background_.size().height() - 2 * slice_y);
- CopyImage(background_, src_rc, &ctrl_background_, dest_rc, true);
-
- // Copy rect 6
- src_rc.set_x(background_.size().width() - slice_x);
- dest_rc.set_x(ctrl_background_.size().width() - slice_x);
- CopyImage(background_, src_rc, &ctrl_background_, dest_rc, true);
-
- // Stretch rect 5
- src_rc = pp::Rect(slice_x,
- slice_y,
- background_.size().width() - 2 * slice_x,
- background_.size().height() - 2 * slice_y);
- dest_rc = pp::Rect(slice_x,
- slice_y,
- ctrl_background_.size().width() - 2 * slice_x,
- ctrl_background_.size().height() - 2 * slice_y);
- CopyImage(background_, src_rc, &ctrl_background_, dest_rc, true);
-}
-
-} // namespace chrome_pdf
diff --git a/xfa_test/pdf/progress_control.h b/xfa_test/pdf/progress_control.h
deleted file mode 100644
index 96d5da1ce9..0000000000
--- a/xfa_test/pdf/progress_control.h
+++ /dev/null
@@ -1,72 +0,0 @@
-// 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.
-
-#ifndef PDF_PROGRESS_CONTROL_H_
-#define PDF_PROGRESS_CONTROL_H_
-
-#include <string>
-#include <vector>
-
-#include "pdf/control.h"
-#include "pdf/fading_control.h"
-#include "ppapi/cpp/image_data.h"
-
-namespace chrome_pdf {
-
-class ProgressControl : public FadingControl {
- public:
- static const double kCompleted;
-
- enum ProgressEventIds {
- EVENT_ID_PROGRESS_COMPLETED,
- };
-
- ProgressControl();
- virtual ~ProgressControl();
- virtual bool CreateProgressControl(uint32 id,
- bool visible,
- Control::Owner* delegate,
- double progress,
- float device_scale,
- const std::vector<pp::ImageData>& images,
- const pp::ImageData& background,
- const std::string& text);
- void Reconfigure(const pp::ImageData& background,
- const std::vector<pp::ImageData>& images,
- float device_scale);
-
- static void CalculateLayout(pp::Instance* instance,
- const std::vector<pp::ImageData>& images,
- const pp::ImageData& background,
- const std::string& text,
- float device_scale,
- pp::Size* ctrl_size,
- pp::Rect* image_rc,
- pp::Rect* text_rc);
-
- // Control interface.
- virtual void Paint(pp::ImageData* image_data, const pp::Rect& rc);
-
- // ProgressControl interface
- // Set progress indicator in percents from 0% to 100%.
- virtual void SetProgress(double progress);
-
- private:
- void PrepareBackground();
- void AdjustBackground();
- size_t GetImageIngex() const;
-
- double progress_;
- float device_scale_;
- std::vector<pp::ImageData> images_;
- pp::ImageData background_;
- pp::ImageData ctrl_background_;
- std::string text_;
- pp::Rect image_rc_;
- pp::Rect text_rc_;
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_PROGRESS_CONTROL_H_
diff --git a/xfa_test/pdf/resource.h b/xfa_test/pdf/resource.h
deleted file mode 100644
index 9fdbea758b..0000000000
--- a/xfa_test/pdf/resource.h
+++ /dev/null
@@ -1,14 +0,0 @@
-//{{NO_DEPENDENCIES}}
-// Microsoft Visual C++ generated include file.
-// Used by pdf.rc
-
-// Next default values for new objects
-//
-#ifdef APSTUDIO_INVOKED
-#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 101
-#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1001
-#define _APS_NEXT_SYMED_VALUE 101
-#endif
-#endif
diff --git a/xfa_test/pdf/resource_consts.h b/xfa_test/pdf/resource_consts.h
deleted file mode 100644
index f12efd61be..0000000000
--- a/xfa_test/pdf/resource_consts.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright (c) 2010 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.
-
-#ifndef PDF_RESOURCE_RESOURCE_CONSTS_H_
-#define PDF_RESOURCE_RESOURCE_CONSTS_H_
-
-#include "base/basictypes.h"
-
-namespace chrome_pdf {
-
-const int kDragTimerMs = 50;
-const double kMinZoom = 0.1;
-const double kMaxZoom = 10.0;
-const double kZoomStep = 1.2;
-
-const uint32 kFadingTimeoutMs = 50;
-
-const uint32 kToolbarId = 10;
-const uint32 kThumbnailsId = 11;
-const uint32 kProgressBarId = 12;
-const uint32 kPageIndicatorId = 13;
-const uint32 kFitToPageButtonId = 100;
-const uint32 kFitToWidthButtonId = 101;
-const uint32 kZoomOutButtonId = 102;
-const uint32 kZoomInButtonId = 103;
-const uint32 kSaveButtonId = 104;
-const uint32 kPrintButtonId = 105;
-
-const uint32 kAutoScrollId = 200;
-
-// fading_rect.left = button_rect.left - kToolbarFadingOffsetLeft
-const int32 kToolbarFadingOffsetLeft = 40;
-// fading_rect.top = button_rect.top - kToolbarFadingOffsetTop
-const int32 kToolbarFadingOffsetTop = 40;
-// fading_rect.right = button_rect.right + kToolbarFadingOffsetRight
-const int32 kToolbarFadingOffsetRight = 10;
-// fading_rect.bottom = button_rect.bottom + kToolbarFadingOffsetBottom
-const int32 kToolbarFadingOffsetBottom = 8;
-
-const int32 kProgressOffsetLeft = 8;
-const int32 kProgressOffsetBottom = 8;
-
-// Width of the thumbnails control.
-const int32 kThumbnailsWidth = 196;
-
-} // namespace chrome_pdf
-
-#endif // PDF_RESOURCE_RESOURCE_CONSTS_H_
diff --git a/xfa_test/pdf/thumbnail_control.cc b/xfa_test/pdf/thumbnail_control.cc
deleted file mode 100644
index 9a779b2912..0000000000
--- a/xfa_test/pdf/thumbnail_control.cc
+++ /dev/null
@@ -1,301 +0,0 @@
-// 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 "pdf/thumbnail_control.h"
-
-#include <algorithm>
-
-#include "base/logging.h"
-#include "base/strings/string_util.h"
-#include "pdf/draw_utils.h"
-#include "pdf/number_image_generator.h"
-
-namespace chrome_pdf {
-
-const int kLeftBorderSize = 52;
-const int kBorderSize = 12;
-const int kHighlightBorderSize = 2;
-
-const uint32 kLeftColor = 0x003F537B;
-const uint32 kRightColor = 0x990D1626;
-
-const uint32 kTopHighlightColor = 0xFF426DC9;
-const uint32 kBottomHighlightColor = 0xFF6391DE;
-const uint32 kThumbnailBackgroundColor = 0xFF000000;
-
-const uint32 kSlidingTimeoutMs = 50;
-const int32 kSlidingShift = 50;
-
-const double kNonSelectedThumbnailAlpha = 0.91;
-
-ThumbnailControl::ThumbnailControl()
- : engine_(NULL), sliding_width_(0), sliding_shift_(kSlidingShift),
- sliding_timeout_(kSlidingTimeoutMs), sliding_timer_id_(0) {
-}
-
-ThumbnailControl::~ThumbnailControl() {
- ClearCache();
-}
-
-bool ThumbnailControl::CreateThumbnailControl(
- uint32 id, const pp::Rect& rc,
- bool visible, Owner* owner, PDFEngine* engine,
- NumberImageGenerator* number_image_generator) {
- engine_ = engine;
- number_image_generator_ = number_image_generator;
- sliding_width_ = rc.width();
-
- return Control::Create(id, rc, visible, owner);
-}
-
-void ThumbnailControl::SetPosition(int position, int total, bool invalidate) {
- visible_rect_ = pp::Rect();
- visible_pages_.clear();
-
- if (rect().width() < kLeftBorderSize + kBorderSize) {
- return; // control is too narrow to show thumbnails.
- }
-
- int num_pages = engine_->GetNumberOfPages();
-
- int max_doc_width = 0, total_doc_height = 0;
- std::vector<pp::Rect> page_sizes(num_pages);
- for (int i = 0; i < num_pages; ++i) {
- page_sizes[i] = engine_->GetPageRect(i);
- max_doc_width = std::max(max_doc_width, page_sizes[i].width());
- total_doc_height += page_sizes[i].height();
- }
-
- if (!max_doc_width)
- return;
-
- int max_thumbnail_width = rect().width() - kLeftBorderSize - kBorderSize;
- double thumbnail_ratio =
- max_thumbnail_width / static_cast<double>(max_doc_width);
-
- int total_thumbnail_height = 0;
- for (int i = 0; i < num_pages; ++i) {
- total_thumbnail_height += kBorderSize;
- int thumbnail_width =
- static_cast<int>(page_sizes[i].width() * thumbnail_ratio);
- int thumbnail_height =
- static_cast<int>(page_sizes[i].height() * thumbnail_ratio);
- int x = (max_thumbnail_width - thumbnail_width) / 2;
- page_sizes[i] =
- pp::Rect(x, total_thumbnail_height, thumbnail_width, thumbnail_height);
- total_thumbnail_height += thumbnail_height;
- }
- total_thumbnail_height += kBorderSize;
-
- int visible_y = 0;
- if (total > 0) {
- double range = total_thumbnail_height - rect().height();
- if (range < 0)
- range = 0;
- visible_y = static_cast<int>(range * position / total);
- }
- visible_rect_ = pp::Rect(0, visible_y, max_thumbnail_width, rect().height());
-
- for (int i = 0; i < num_pages; ++i) {
- if (page_sizes[i].Intersects(visible_rect_)) {
- PageInfo page_info;
- page_info.index = i;
- page_info.rect = page_sizes[i];
- page_info.rect.Offset(kLeftBorderSize, -visible_rect_.y());
- visible_pages_.push_back(page_info);
- }
- }
-
- if (invalidate)
- owner()->Invalidate(id(), rect());
-}
-
-void ThumbnailControl::Show(bool visible, bool invalidate) {
- if (!visible || invalidate)
- ClearCache();
- sliding_width_ = rect().width();
- Control::Show(visible, invalidate);
-}
-
-void ThumbnailControl::SlideIn() {
- if (visible())
- return;
-
- Show(true, false);
- sliding_width_ = 0;
- sliding_shift_ = kSlidingShift;
-
- sliding_timer_id_ = owner()->ScheduleTimer(id(), sliding_timeout_);
- owner()->Invalidate(id(), rect());
-}
-
-void ThumbnailControl::SlideOut() {
- if (!visible())
- return;
- sliding_shift_ = -kSlidingShift;
- sliding_timer_id_ = owner()->ScheduleTimer(id(), sliding_timeout_);
-}
-
-void ThumbnailControl::Paint(pp::ImageData* image_data, const pp::Rect& rc) {
- if (!visible())
- return;
-
- pp::Rect control_rc(rect());
- control_rc.Offset(control_rc.width() - sliding_width_, 0);
- control_rc.set_width(sliding_width_);
-
- pp::Rect draw_rc = rc.Intersect(control_rc);
- if (draw_rc.IsEmpty())
- return;
-
- pp::Rect gradient_rc(control_rc.x(), draw_rc.y(),
- control_rc.width(), draw_rc.height());
- GradientFill(owner()->GetInstance(),
- image_data,
- draw_rc,
- gradient_rc,
- kLeftColor,
- kRightColor,
- true,
- transparency());
-
- int selected_page = engine_->GetMostVisiblePage();
- for (size_t i = 0; i < visible_pages_.size(); ++i) {
- pp::Rect page_rc = visible_pages_[i].rect;
- page_rc.Offset(control_rc.point());
-
- if (visible_pages_[i].index == selected_page) {
- pp::Rect highlight_rc = page_rc;
- highlight_rc.Inset(-kHighlightBorderSize, -kHighlightBorderSize);
- GradientFill(owner()->GetInstance(),
- image_data,
- draw_rc,
- highlight_rc,
- kTopHighlightColor,
- kBottomHighlightColor,
- false,
- transparency());
- }
-
- pp::Rect draw_page_rc = page_rc.Intersect(draw_rc);
- if (draw_page_rc.IsEmpty())
- continue;
-
- // First search page image in the cache.
- pp::ImageData* thumbnail = NULL;
- std::map<int, pp::ImageData*>::iterator it =
- image_cache_.find(visible_pages_[i].index);
- if (it != image_cache_.end()) {
- if (it->second->size() == page_rc.size())
- thumbnail = image_cache_[visible_pages_[i].index];
- else
- image_cache_.erase(it);
- }
-
- // If page is not found in the cache, create new one.
- if (thumbnail == NULL) {
- thumbnail = new pp::ImageData(owner()->GetInstance(),
- PP_IMAGEDATAFORMAT_BGRA_PREMUL,
- page_rc.size(),
- false);
- engine_->PaintThumbnail(thumbnail, visible_pages_[i].index);
-
- pp::ImageData page_number;
- number_image_generator_->GenerateImage(
- visible_pages_[i].index + 1, &page_number);
- pp::Point origin(
- (thumbnail->size().width() - page_number.size().width()) / 2,
- (thumbnail->size().height() - page_number.size().height()) / 2);
-
- if (origin.x() > 0 && origin.y() > 0) {
- AlphaBlend(page_number, pp::Rect(pp::Point(), page_number.size()),
- thumbnail, origin, kOpaqueAlpha);
- }
-
- image_cache_[visible_pages_[i].index] = thumbnail;
- }
-
- uint8 alpha = transparency();
- if (visible_pages_[i].index != selected_page)
- alpha = static_cast<uint8>(alpha * kNonSelectedThumbnailAlpha);
- FillRect(image_data, draw_page_rc, kThumbnailBackgroundColor);
- draw_page_rc.Offset(-page_rc.x(), -page_rc.y());
- AlphaBlend(*thumbnail, draw_page_rc, image_data,
- draw_page_rc.point() + page_rc.point(), alpha);
- }
-}
-
-bool ThumbnailControl::HandleEvent(const pp::InputEvent& event) {
- if (!visible())
- return false;
-
- pp::MouseInputEvent mouse_event(event);
- if (mouse_event.is_null())
- return false;
- pp::Point pt = mouse_event.GetPosition();
- if (!rect().Contains(pt))
- return false;
-
- int over_page = -1;
- for (size_t i = 0; i < visible_pages_.size(); ++i) {
- pp::Rect page_rc = visible_pages_[i].rect;
- page_rc.Offset(rect().point());
- if (page_rc.Contains(pt)) {
- over_page = i;
- break;
- }
- }
-
- bool handled = false;
- switch (event.GetType()) {
- case PP_INPUTEVENT_TYPE_MOUSEMOVE:
- owner()->SetCursor(id(),
- over_page == -1 ? PP_CURSORTYPE_POINTER : PP_CURSORTYPE_HAND);
- break;
- case PP_INPUTEVENT_TYPE_MOUSEDOWN:
- if (over_page != -1) {
- owner()->Invalidate(id(), rect());
- owner()->OnEvent(id(), EVENT_ID_THUMBNAIL_SELECTED,
- &visible_pages_[over_page].index);
- }
- handled = true;
- break;
- default:
- break;
- }
-
- return handled;
-}
-
-void ThumbnailControl::OnTimerFired(uint32 timer_id) {
- if (timer_id == sliding_timer_id_) {
- sliding_width_ += sliding_shift_;
- if (sliding_width_ <= 0) {
- // We completely slided out. Make control invisible now.
- Show(false, false);
- } else if (sliding_width_ >= rect().width()) {
- // We completely slided in. Make sliding width to full control width.
- sliding_width_ = rect().width();
- } else {
- // We have not completed sliding yet. Keep sliding.
- sliding_timer_id_ = owner()->ScheduleTimer(id(), sliding_timeout_);
- }
- owner()->Invalidate(id(), rect());
- }
-}
-
-void ThumbnailControl::ResetEngine(PDFEngine* engine) {
- engine_ = engine;
- ClearCache();
-}
-
-void ThumbnailControl::ClearCache() {
- std::map<int, pp::ImageData*>::iterator it;
- for (it = image_cache_.begin(); it != image_cache_.end(); ++it) {
- delete it->second;
- }
- image_cache_.clear();
-}
-
-} // namespace chrome_pdf
diff --git a/xfa_test/pdf/thumbnail_control.h b/xfa_test/pdf/thumbnail_control.h
deleted file mode 100644
index d10a32896d..0000000000
--- a/xfa_test/pdf/thumbnail_control.h
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright (c) 2010 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.
-
-#ifndef PDF_THUMBNAIL_CONTROL_H_
-#define PDF_THUMBNAIL_CONTROL_H_
-
-#include <map>
-#include <vector>
-
-#include "pdf/control.h"
-#include "pdf/pdf_engine.h"
-#include "ppapi/cpp/input_event.h"
-
-namespace chrome_pdf {
-
-class NumberImageGenerator;
-
-class ThumbnailControl : public Control {
- public:
- enum ThumbnailEventIds {
- EVENT_ID_THUMBNAIL_SELECTED = 100,
- };
-
- explicit ThumbnailControl();
- virtual ~ThumbnailControl();
-
- // Sets current position of the thumnail control.
- void SetPosition(int position, int total, bool invalidate);
- void SlideIn();
- void SlideOut();
-
- virtual bool CreateThumbnailControl(
- uint32 id, const pp::Rect& rc,
- bool visible, Owner* owner, PDFEngine* engine,
- NumberImageGenerator* number_image_generator);
-
- // Control interface.
- virtual void Show(bool visible, bool invalidate);
- virtual void Paint(pp::ImageData* image_data, const pp::Rect& rc);
- virtual bool HandleEvent(const pp::InputEvent& event);
- virtual void OnTimerFired(uint32 timer_id);
-
- virtual void ResetEngine(PDFEngine* engine);
-
- private:
- void ClearCache();
-
- struct PageInfo {
- int index;
- pp::Rect rect;
- };
-
- PDFEngine* engine_;
- pp::Rect visible_rect_;
- std::vector<PageInfo> visible_pages_;
- std::map<int, pp::ImageData*> image_cache_;
- int sliding_width_;
- int sliding_shift_;
- int sliding_timeout_;
- uint32 sliding_timer_id_;
- NumberImageGenerator* number_image_generator_;
-};
-
-} // namespace chrome_pdf
-
-#endif // PDF_THUMBNAIL_CONTROL_H_
diff --git a/xfa_test/process/process.cc b/xfa_test/process/process.cc
deleted file mode 100644
index c8f96db240..0000000000
--- a/xfa_test/process/process.cc
+++ /dev/null
@@ -1,712 +0,0 @@
-// Copyright 2012 the V8 project authors. All rights reserved.
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <v8.h>
-
-#include <string>
-#include <map>
-
-#ifdef COMPRESS_STARTUP_DATA_BZ2
-#error Using compressed startup data is not supported for this sample
-#endif
-
-using namespace std;
-using namespace v8;
-
-// These interfaces represent an existing request processing interface.
-// The idea is to imagine a real application that uses these interfaces
-// and then add scripting capabilities that allow you to interact with
-// the objects through JavaScript.
-
-/**
- * A simplified http request.
- */
-class HttpRequest {
- public:
- virtual ~HttpRequest() { }
- virtual const string& Path() = 0;
- virtual const string& Referrer() = 0;
- virtual const string& Host() = 0;
- virtual const string& UserAgent() = 0;
-};
-
-
-/**
- * The abstract superclass of http request processors.
- */
-class HttpRequestProcessor {
- public:
- virtual ~HttpRequestProcessor() { }
-
- // Initialize this processor. The map contains options that control
- // how requests should be processed.
- virtual bool Initialize(map<string, string>* options,
- map<string, string>* output) = 0;
-
- // Process a single request.
- virtual bool Process(HttpRequest* req) = 0;
-
- static void Log(const char* event);
-};
-
-
-/**
- * An http request processor that is scriptable using JavaScript.
- */
-class JsHttpRequestProcessor : public HttpRequestProcessor {
- public:
- // Creates a new processor that processes requests by invoking the
- // Process function of the JavaScript script given as an argument.
- JsHttpRequestProcessor(Isolate* isolate, Handle<String> script)
- : isolate_(isolate), script_(script) { }
- virtual ~JsHttpRequestProcessor();
-
- virtual bool Initialize(map<string, string>* opts,
- map<string, string>* output);
- virtual bool Process(HttpRequest* req);
-
- private:
- // Execute the script associated with this processor and extract the
- // Process function. Returns true if this succeeded, otherwise false.
- bool ExecuteScript(Handle<String> script);
-
- // Wrap the options and output map in a JavaScript objects and
- // install it in the global namespace as 'options' and 'output'.
- bool InstallMaps(map<string, string>* opts, map<string, string>* output);
-
- // Constructs the template that describes the JavaScript wrapper
- // type for requests.
- static Handle<ObjectTemplate> MakeRequestTemplate(Isolate* isolate);
- static Handle<ObjectTemplate> MakeMapTemplate(Isolate* isolate);
-
- // Callbacks that access the individual fields of request objects.
- static void GetPath(Local<String> name,
- const PropertyCallbackInfo<Value>& info);
- static void GetReferrer(Local<String> name,
- const PropertyCallbackInfo<Value>& info);
- static void GetHost(Local<String> name,
- const PropertyCallbackInfo<Value>& info);
- static void GetUserAgent(Local<String> name,
- const PropertyCallbackInfo<Value>& info);
-
- // Callbacks that access maps
- static void MapGet(Local<String> name,
- const PropertyCallbackInfo<Value>& info);
- static void MapSet(Local<String> name,
- Local<Value> value,
- const PropertyCallbackInfo<Value>& info);
-
- // Utility methods for wrapping C++ objects as JavaScript objects,
- // and going back again.
- Handle<Object> WrapMap(map<string, string>* obj);
- static map<string, string>* UnwrapMap(Handle<Object> obj);
- Handle<Object> WrapRequest(HttpRequest* obj);
- static HttpRequest* UnwrapRequest(Handle<Object> obj);
-
- Isolate* GetIsolate() { return isolate_; }
-
- Isolate* isolate_;
- Handle<String> script_;
- Persistent<Context> context_;
- Persistent<Function> process_;
- static Persistent<ObjectTemplate> request_template_;
- static Persistent<ObjectTemplate> map_template_;
-};
-
-
-// -------------------------
-// --- P r o c e s s o r ---
-// -------------------------
-
-
-static void LogCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
- if (args.Length() < 1) return;
- HandleScope scope(args.GetIsolate());
- Handle<Value> arg = args[0];
- String::Utf8Value value(arg);
- HttpRequestProcessor::Log(*value);
-}
-
-static void MethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
- if (args.Length() < 1) return;
- HandleScope scope(args.GetIsolate());
- Handle<Value> arg = args[0];
- String::Utf8Value value(arg);
- HttpRequestProcessor::Log(*value);
-}
-
-static void MyJSObjectCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
-
- HandleScope scope(args.GetIsolate());
- if(args.IsConstructCall())
- {
- //args.GetReturnValue().Set(String::NewFromUtf8(
- // args.GetIsolate(), "HelloWorld", String::kNormalString,
- // static_cast<int>(10)));
- args.This();
- }
-}
-
-void Getter(
- Local<String> property,
- const PropertyCallbackInfo<Value>& info)
-{
-// info.GetReturnValue().Set(String::NewFromUtf8(
-// info.GetIsolate(), "HelloWorld", String::kNormalString,
-// static_cast<int>(10)));
-}
-
-
-// Execute the script and fetch the Process method.
-bool JsHttpRequestProcessor::Initialize(map<string, string>* opts,
- map<string, string>* output) {
- // Create a handle scope to hold the temporary references.
- HandleScope handle_scope(GetIsolate());
-
- // Create a template for the global object where we set the
- // built-in global functions.
- Handle<ObjectTemplate> global = ObjectTemplate::New(GetIsolate());
- global->Set(String::NewFromUtf8(GetIsolate(), "log"),
- FunctionTemplate::New(GetIsolate(), LogCallback));
-
-
-// Local<FunctionTemplate> funJSObj = FunctionTemplate::New(GetIsolate(), MyJSObjectCallback);
-// funJSObj->InstanceTemplate()->SetAccessor(String::NewFromUtf8(GetIsolate(), "activeDocs"), Getter, 0, Handle<Value>(), ALL_CAN_READ|PROHIBITS_OVERWRITING);
-// funJSObj->InstanceTemplate()->Set(String::NewFromUtf8(GetIsolate(), "method1"),FunctionTemplate::New(GetIsolate(), MethodCallback));
-//
-// global->Set(String::NewFromUtf8(GetIsolate(), "app"), funJSObj);
-
- // Each processor gets its own context so different processors don't
- // affect each other. Context::New returns a persistent handle which
- // is what we need for the reference to remain after we return from
- // this method. That persistent handle has to be disposed in the
- // destructor.
- v8::Handle<v8::Context> context = Context::New(GetIsolate(), NULL, global);
- context_.Reset(GetIsolate(), context);
-
- // Enter the new context so all the following operations take place
- // within it.
- Context::Scope context_scope(context);
-
- Local<ObjectTemplate> ObjTemp = ObjectTemplate::New(GetIsolate());
- ObjTemp->SetAccessor(String::NewFromUtf8(GetIsolate(), "activeDocs"), Getter, 0, Handle<Value>(), PROHIBITS_OVERWRITING);
- Local<Object> ins = ObjTemp->NewInstance();
- context->Global()->Set(String::NewFromUtf8(GetIsolate(), "app"), ins);
-
-
- // Make the options mapping available within the context
- if (!InstallMaps(opts, output))
- return false;
-
- // Compile and run the script
- if (!ExecuteScript(script_))
- return false;
-
- // The script compiled and ran correctly. Now we fetch out the
- // Process function from the global object.
- Handle<String> process_name = String::NewFromUtf8(GetIsolate(), "Process");
- Handle<Value> process_val = context->Global()->Get(process_name);
-
- // If there is no Process function, or if it is not a function,
- // bail out
- if (!process_val->IsFunction()) return false;
-
- // It is a function; cast it to a Function
- Handle<Function> process_fun = Handle<Function>::Cast(process_val);
-
- // Store the function in a Persistent handle, since we also want
- // that to remain after this call returns
- process_.Reset(GetIsolate(), process_fun);
-
- // All done; all went well
- return true;
-}
-
-
-bool JsHttpRequestProcessor::ExecuteScript(Handle<String> script) {
- HandleScope handle_scope(GetIsolate());
-
- // We're just about to compile the script; set up an error handler to
- // catch any exceptions the script might throw.
- TryCatch try_catch;
-
- // Compile the script and check for errors.
- Handle<Script> compiled_script = Script::Compile(script);
- if (compiled_script.IsEmpty()) {
- String::Utf8Value error(try_catch.Exception());
- Log(*error);
- // The script failed to compile; bail out.
- return false;
- }
-
- // Run the script!
- Handle<Value> result = compiled_script->Run();
- if (result.IsEmpty()) {
- // The TryCatch above is still in effect and will have caught the error.
- String::Utf8Value error(try_catch.Exception());
- Log(*error);
- // Running the script failed; bail out.
- return false;
- }
- return true;
-}
-
-
-bool JsHttpRequestProcessor::InstallMaps(map<string, string>* opts,
- map<string, string>* output) {
- HandleScope handle_scope(GetIsolate());
-
- // Wrap the map object in a JavaScript wrapper
- Handle<Object> opts_obj = WrapMap(opts);
-
- v8::Local<v8::Context> context =
- v8::Local<v8::Context>::New(GetIsolate(), context_);
-
- // Set the options object as a property on the global object.
- context->Global()->Set(String::NewFromUtf8(GetIsolate(), "options"),
- opts_obj);
-
- Handle<Object> output_obj = WrapMap(output);
- context->Global()->Set(String::NewFromUtf8(GetIsolate(), "output"),
- output_obj);
-
- return true;
-}
-
-
-bool JsHttpRequestProcessor::Process(HttpRequest* request) {
- // Create a handle scope to keep the temporary object references.
- HandleScope handle_scope(GetIsolate());
-
- v8::Local<v8::Context> context =
- v8::Local<v8::Context>::New(GetIsolate(), context_);
-
- // Enter this processor's context so all the remaining operations
- // take place there
- Context::Scope context_scope(context);
-
- // Wrap the C++ request object in a JavaScript wrapper
- Handle<Object> request_obj = WrapRequest(request);
-
- // Set up an exception handler before calling the Process function
- TryCatch try_catch;
-
- // Invoke the process function, giving the global object as 'this'
- // and one argument, the request.
- const int argc = 1;
- Handle<Value> argv[argc] = { request_obj };
- v8::Local<v8::Function> process =
- v8::Local<v8::Function>::New(GetIsolate(), process_);
- Handle<Value> result = process->Call(context->Global(), argc, argv);
- if (result.IsEmpty()) {
- String::Utf8Value error(try_catch.Exception());
- Log(*error);
- return false;
- } else {
- return true;
- }
-}
-
-
-JsHttpRequestProcessor::~JsHttpRequestProcessor() {
- // Dispose the persistent handles. When noone else has any
- // references to the objects stored in the handles they will be
- // automatically reclaimed.
- context_.Reset();
- process_.Reset();
-}
-
-
-Persistent<ObjectTemplate> JsHttpRequestProcessor::request_template_;
-Persistent<ObjectTemplate> JsHttpRequestProcessor::map_template_;
-
-
-// -----------------------------------
-// --- A c c e s s i n g M a p s ---
-// -----------------------------------
-
-// Utility function that wraps a C++ http request object in a
-// JavaScript object.
-Handle<Object> JsHttpRequestProcessor::WrapMap(map<string, string>* obj) {
- // Handle scope for temporary handles.
- EscapableHandleScope handle_scope(GetIsolate());
-
- // Fetch the template for creating JavaScript map wrappers.
- // It only has to be created once, which we do on demand.
- if (map_template_.IsEmpty()) {
- Handle<ObjectTemplate> raw_template = MakeMapTemplate(GetIsolate());
- map_template_.Reset(GetIsolate(), raw_template);
- }
- Handle<ObjectTemplate> templ =
- Local<ObjectTemplate>::New(GetIsolate(), map_template_);
-
- // Create an empty map wrapper.
- Local<Object> result = templ->NewInstance();
-
- // Wrap the raw C++ pointer in an External so it can be referenced
- // from within JavaScript.
- Handle<External> map_ptr = External::New(GetIsolate(), obj);
-
- // Store the map pointer in the JavaScript wrapper.
- result->SetInternalField(0, map_ptr);
-
- // Return the result through the current handle scope. Since each
- // of these handles will go away when the handle scope is deleted
- // we need to call Close to let one, the result, escape into the
- // outer handle scope.
- return handle_scope.Escape(result);
-}
-
-
-// Utility function that extracts the C++ map pointer from a wrapper
-// object.
-map<string, string>* JsHttpRequestProcessor::UnwrapMap(Handle<Object> obj) {
- Handle<External> field = Handle<External>::Cast(obj->GetInternalField(0));
- void* ptr = field->Value();
- return static_cast<map<string, string>*>(ptr);
-}
-
-
-// Convert a JavaScript string to a std::string. To not bother too
-// much with string encodings we just use ascii.
-string ObjectToString(Local<Value> value) {
- String::Utf8Value utf8_value(value);
- return string(*utf8_value);
-}
-
-
-void JsHttpRequestProcessor::MapGet(Local<String> name,
- const PropertyCallbackInfo<Value>& info) {
- // Fetch the map wrapped by this object.
- map<string, string>* obj = UnwrapMap(info.Holder());
-
- // Convert the JavaScript string to a std::string.
- string key = ObjectToString(name);
-
- // Look up the value if it exists using the standard STL ideom.
- map<string, string>::iterator iter = obj->find(key);
-
- // If the key is not present return an empty handle as signal
- if (iter == obj->end()) return;
-
- // Otherwise fetch the value and wrap it in a JavaScript string
- const string& value = (*iter).second;
- info.GetReturnValue().Set(String::NewFromUtf8(
- info.GetIsolate(), value.c_str(), String::kNormalString,
- static_cast<int>(value.length())));
-}
-
-
-void JsHttpRequestProcessor::MapSet(Local<String> name,
- Local<Value> value_obj,
- const PropertyCallbackInfo<Value>& info) {
- // Fetch the map wrapped by this object.
- map<string, string>* obj = UnwrapMap(info.Holder());
-
- // Convert the key and value to std::strings.
- string key = ObjectToString(name);
- string value = ObjectToString(value_obj);
-
- // Update the map.
- (*obj)[key] = value;
-
- // Return the value; any non-empty handle will work.
- info.GetReturnValue().Set(value_obj);
-}
-
-
-Handle<ObjectTemplate> JsHttpRequestProcessor::MakeMapTemplate(
- Isolate* isolate) {
- EscapableHandleScope handle_scope(isolate);
-
- Local<ObjectTemplate> result = ObjectTemplate::New(isolate);
- result->SetInternalFieldCount(1);
- result->SetNamedPropertyHandler(MapGet, MapSet);
-
- // Again, return the result through the current handle scope.
- return handle_scope.Escape(result);
-}
-
-
-// -------------------------------------------
-// --- A c c e s s i n g R e q u e s t s ---
-// -------------------------------------------
-
-/**
- * Utility function that wraps a C++ http request object in a
- * JavaScript object.
- */
-Handle<Object> JsHttpRequestProcessor::WrapRequest(HttpRequest* request) {
- // Handle scope for temporary handles.
- EscapableHandleScope handle_scope(GetIsolate());
-
- // Fetch the template for creating JavaScript http request wrappers.
- // It only has to be created once, which we do on demand.
- if (request_template_.IsEmpty()) {
- Handle<ObjectTemplate> raw_template = MakeRequestTemplate(GetIsolate());
- request_template_.Reset(GetIsolate(), raw_template);
- }
- Handle<ObjectTemplate> templ =
- Local<ObjectTemplate>::New(GetIsolate(), request_template_);
-
- // Create an empty http request wrapper.
- Local<Object> result = templ->NewInstance();
-
- // Wrap the raw C++ pointer in an External so it can be referenced
- // from within JavaScript.
- Handle<External> request_ptr = External::New(GetIsolate(), request);
-
- // Store the request pointer in the JavaScript wrapper.
- result->SetInternalField(0, request_ptr);
-
- // Return the result through the current handle scope. Since each
- // of these handles will go away when the handle scope is deleted
- // we need to call Close to let one, the result, escape into the
- // outer handle scope.
- return handle_scope.Escape(result);
-}
-
-
-/**
- * Utility function that extracts the C++ http request object from a
- * wrapper object.
- */
-HttpRequest* JsHttpRequestProcessor::UnwrapRequest(Handle<Object> obj) {
- Handle<External> field = Handle<External>::Cast(obj->GetInternalField(0));
- void* ptr = field->Value();
- return static_cast<HttpRequest*>(ptr);
-}
-
-
-void JsHttpRequestProcessor::GetPath(Local<String> name,
- const PropertyCallbackInfo<Value>& info) {
- // Extract the C++ request object from the JavaScript wrapper.
- HttpRequest* request = UnwrapRequest(info.Holder());
-
- // Fetch the path.
- const string& path = request->Path();
-
- // Wrap the result in a JavaScript string and return it.
- info.GetReturnValue().Set(String::NewFromUtf8(
- info.GetIsolate(), path.c_str(), String::kNormalString,
- static_cast<int>(path.length())));
-}
-
-
-void JsHttpRequestProcessor::GetReferrer(
- Local<String> name,
- const PropertyCallbackInfo<Value>& info) {
- HttpRequest* request = UnwrapRequest(info.Holder());
- const string& path = request->Referrer();
- info.GetReturnValue().Set(String::NewFromUtf8(
- info.GetIsolate(), path.c_str(), String::kNormalString,
- static_cast<int>(path.length())));
-}
-
-
-void JsHttpRequestProcessor::GetHost(Local<String> name,
- const PropertyCallbackInfo<Value>& info) {
- HttpRequest* request = UnwrapRequest(info.Holder());
- const string& path = request->Host();
- info.GetReturnValue().Set(String::NewFromUtf8(
- info.GetIsolate(), path.c_str(), String::kNormalString,
- static_cast<int>(path.length())));
-}
-
-
-void JsHttpRequestProcessor::GetUserAgent(
- Local<String> name,
- const PropertyCallbackInfo<Value>& info) {
- HttpRequest* request = UnwrapRequest(info.Holder());
- const string& path = request->UserAgent();
- info.GetReturnValue().Set(String::NewFromUtf8(
- info.GetIsolate(), path.c_str(), String::kNormalString,
- static_cast<int>(path.length())));
-}
-
-
-Handle<ObjectTemplate> JsHttpRequestProcessor::MakeRequestTemplate(
- Isolate* isolate) {
- EscapableHandleScope handle_scope(isolate);
-
- Local<ObjectTemplate> result = ObjectTemplate::New(isolate);
- result->SetInternalFieldCount(1);
-
- // Add accessors for each of the fields of the request.
- result->SetAccessor(
- String::NewFromUtf8(isolate, "path", String::kInternalizedString),
- GetPath);
- result->SetAccessor(
- String::NewFromUtf8(isolate, "referrer", String::kInternalizedString),
- GetReferrer);
- result->SetAccessor(
- String::NewFromUtf8(isolate, "host", String::kInternalizedString),
- GetHost);
- result->SetAccessor(
- String::NewFromUtf8(isolate, "userAgent", String::kInternalizedString),
- GetUserAgent);
-
- // Again, return the result through the current handle scope.
- return handle_scope.Escape(result);
-}
-
-
-// --- Test ---
-
-
-void HttpRequestProcessor::Log(const char* event) {
- printf("Logged: %s\n", event);
-}
-
-
-/**
- * A simplified http request.
- */
-class StringHttpRequest : public HttpRequest {
- public:
- StringHttpRequest(const string& path,
- const string& referrer,
- const string& host,
- const string& user_agent);
- virtual const string& Path() { return path_; }
- virtual const string& Referrer() { return referrer_; }
- virtual const string& Host() { return host_; }
- virtual const string& UserAgent() { return user_agent_; }
- private:
- string path_;
- string referrer_;
- string host_;
- string user_agent_;
-};
-
-
-StringHttpRequest::StringHttpRequest(const string& path,
- const string& referrer,
- const string& host,
- const string& user_agent)
- : path_(path),
- referrer_(referrer),
- host_(host),
- user_agent_(user_agent) { }
-
-
-void ParseOptions(int argc,
- char* argv[],
- map<string, string>& options,
- string* file) {
- for (int i = 1; i < argc; i++) {
- string arg = argv[i];
- size_t index = arg.find('=', 0);
- if (index == string::npos) {
- *file = arg;
- } else {
- string key = arg.substr(0, index);
- string value = arg.substr(index+1);
- options[key] = value;
- }
- }
-}
-
-
-// Reads a file into a v8 string.
-Handle<String> ReadFile(Isolate* isolate, const string& name) {
- FILE* file = fopen(name.c_str(), "rb");
- if (file == NULL) return Handle<String>();
-
- fseek(file, 0, SEEK_END);
- int size = ftell(file);
- rewind(file);
-
- char* chars = new char[size + 1];
- chars[size] = '\0';
- for (int i = 0; i < size;) {
- int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
- i += read;
- }
- fclose(file);
- Handle<String> result =
- String::NewFromUtf8(isolate, chars, String::kNormalString, size);
- delete[] chars;
- return result;
-}
-
-
-const int kSampleSize = 6;
-StringHttpRequest kSampleRequests[kSampleSize] = {
- StringHttpRequest("/process.cc", "localhost", "google.com", "firefox"),
- StringHttpRequest("/", "localhost", "google.net", "firefox"),
- StringHttpRequest("/", "localhost", "google.org", "safari"),
- StringHttpRequest("/", "localhost", "yahoo.com", "ie"),
- StringHttpRequest("/", "localhost", "yahoo.com", "safari"),
- StringHttpRequest("/", "localhost", "yahoo.com", "firefox")
-};
-
-
-bool ProcessEntries(HttpRequestProcessor* processor, int count,
- StringHttpRequest* reqs) {
- for (int i = 0; i < count; i++) {
- if (!processor->Process(&reqs[i]))
- return false;
- }
- return true;
-}
-
-
-void PrintMap(map<string, string>* m) {
- for (map<string, string>::iterator i = m->begin(); i != m->end(); i++) {
- pair<string, string> entry = *i;
- printf("%s: %s\n", entry.first.c_str(), entry.second.c_str());
- }
-}
-
-
-int main(int argc, char* argv[]) {
- v8::V8::InitializeICU();
- map<string, string> options;
- string file;
- ParseOptions(argc, argv, options, &file);
- if (file.empty()) {
- fprintf(stderr, "No script was specified.\n");
- return 1;
- }
- Isolate* isolate = Isolate::GetCurrent();
- HandleScope scope(isolate);
- Handle<String> source = ReadFile(isolate, file);
- if (source.IsEmpty()) {
- fprintf(stderr, "Error reading '%s'.\n", file.c_str());
- return 1;
- }
- JsHttpRequestProcessor processor(isolate, source);
- map<string, string> output;
- if (!processor.Initialize(&options, &output)) {
- fprintf(stderr, "Error initializing processor.\n");
- return 1;
- }
- if (!ProcessEntries(&processor, kSampleSize, kSampleRequests))
- return 1;
- PrintMap(&output);
-}
diff --git a/xfa_test/process/script.txt b/xfa_test/process/script.txt
deleted file mode 100644
index aceb48c505..0000000000
--- a/xfa_test/process/script.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-function Process(request)
-{
-
-//var c = new MyJSObject();
-
-//this.log(c.property1);
-
-var c = app.activeDocs;
-
-
-if(options["param1"] != "x")
-{
- this.output["hello"] = 1;
- log(request.host);
-}
-else
-{
- this.output["hello"] = 2;
- log(request.host);
-}
-} \ No newline at end of file