From 5b47dbfe85e8db4122089afa6d00264f1e973af2 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 27 Feb 2015 13:48:38 -0800 Subject: Remove unused IDS_ constants from pdfium. Along the way, I noticed that one of these is used in a header file that isn't included anywhere and describes no actual code (JS_Console.h). Also add missing header guards, and IWYU to resources.h Also move a static function from a header to the new resources.cpp file. Also fix the grammar on some of the error messages. Most of these appear to be JS error messages destined for a JS error handler or (someday) a console (which can remain in english), and oddly, some appear to be about failed form validation, which smells user-facing. Also check that the message makes sense for the point the C++ code wants to use it, and reword accordingly. As it turns out, these currently don't make it back to JS due to the unimplemented JS_Error() function; this is an enabling step towards implementing it. R=thestig@chromium.org Review URL: https://codereview.chromium.org/955273003 --- BUILD.gn | 2 +- fpdfsdk/include/javascript/JS_Console.h | 239 -------------------------------- fpdfsdk/include/javascript/resource.h | 99 ++----------- fpdfsdk/src/javascript/resource.cpp | 47 +++++++ pdfium.gyp | 2 +- 5 files changed, 60 insertions(+), 329 deletions(-) delete mode 100644 fpdfsdk/include/javascript/JS_Console.h create mode 100644 fpdfsdk/src/javascript/resource.cpp diff --git a/BUILD.gn b/BUILD.gn index 3c6c74ab11..d51c563982 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -705,7 +705,6 @@ static_library("javascript") { "fpdfsdk/include/javascript/Icon.h", "fpdfsdk/include/javascript/IJavaScript.h", "fpdfsdk/include/javascript/JavaScript.h", - "fpdfsdk/include/javascript/JS_Console.h", "fpdfsdk/include/javascript/JS_Context.h", "fpdfsdk/include/javascript/JS_Define.h", "fpdfsdk/include/javascript/JS_EventHandler.h", @@ -735,6 +734,7 @@ static_library("javascript") { "fpdfsdk/src/javascript/JS_Value.cpp", "fpdfsdk/src/javascript/PublicMethods.cpp", "fpdfsdk/src/javascript/report.cpp", + "fpdfsdk/src/javascript/resource.cpp", "fpdfsdk/src/javascript/util.cpp", ] diff --git a/fpdfsdk/include/javascript/JS_Console.h b/fpdfsdk/include/javascript/JS_Console.h deleted file mode 100644 index f43513566c..0000000000 --- a/fpdfsdk/include/javascript/JS_Console.h +++ /dev/null @@ -1,239 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef _JS_CONSOLE_H_ -#define _JS_CONSOLE_H_ - -#include "../res/resource.h" - -#define WST_NONE 0x00 // No size changed -#define WST_LEFT 0x01 // size to left -#define WST_TOP 0x02 // size to top -#define WST_RIGHT 0x04 // size to right -#define WST_BOTTOM 0x08 // size to bottom -#define WST_TOPLEFT (WST_TOP|WST_LEFT) // size to top & left -#define WST_TOPRIGHT (WST_TOP|WST_RIGHT) // size to top & right -#define WST_BOTTOMRIGHT (WST_BOTTOM|WST_RIGHT) // size to bottom & right -#define WST_BOTTOMLEFT (WST_BOTTOM|WST_LEFT) // size to bottom & right - -#ifndef IDC_DLGSIZEBOX -#define IDC_DLGSIZEBOX 50 -#endif /* IDC_DLGSIZEBOX */ - -enum { m_idSizeIcon = IDC_DLGSIZEBOX }; -enum { // possible Control reSize Type - CST_NONE = 0, - CST_RESIZE, // NOMOVE + SIZE, add all delta-size of dlg to control - CST_REPOS, // MOVE(absolutely) + NOSIZE, move control's pos by delta-size - CST_RELATIVE, // MOVE(proportional) + NOSIZE, keep control always at a relative pos - CST_ZOOM, // MOVE + SIZE (both are automatically proportional) - CST_DELTA_ZOOM // MOVE(proportional, set manually) + SIZE(proportional, set manuall) -}; - -// contained class to hold item state -// -class CJS_ItemCtrl -{ -public: - UINT m_nID; - UINT m_stxLeft : 4; // when left resizing ... - UINT m_stxRight : 4; // when right resizing ... - UINT m_styTop : 4; // when top resizing ... - UINT m_styBottom : 4; // when bottom resizing ... - UINT m_bFlickerFree : 1; - UINT m_bInvalidate : 1; // Invalidate ctrl's rect(eg. no-automatical update for static when resize+move) - UINT m_r0 : 14; - CRect m_wRect; - double m_xRatio, m_cxRatio; - double m_yRatio, m_cyRatio; - -protected: - void Assign(const CJS_ItemCtrl& src); - -public: - CJS_ItemCtrl(); - CJS_ItemCtrl(const CJS_ItemCtrl& src); - - HDWP OnSize(HDWP hdwp, int sizeType, CRect *pnCltRect, CRect *poCltRect, CRect *pR0, CWnd *pDlg); - - CJS_ItemCtrl& operator=(const CJS_ItemCtrl& src); -}; - -class CJS_ResizeDlg : public CDialog -{ -// DECLARE_DYNAMIC(CJS_ResizeDlg) -public: - CJS_ResizeDlg(UINT nID,CWnd *pParentWnd = NULL); - virtual ~CJS_ResizeDlg(); - - -public: - std::vector m_Items; // array of controlled items - CRect m_cltRect, m_cltR0; - int m_xMin, m_yMin; - int m_xSt, m_ySt; //step? - UINT m_nDelaySide; //drag side of window - CStatic m_wndSizeIcon; // size icon window - -protected: - void AddControl( UINT nID, int xl, int xr, int yt, int yb, int bFlickerFree = 0, - double xRatio = -1.0, double cxRatio = -1.0, - double yRatio = -1.0, double cyRatio = -1.0 ); - void AllowSizing(int xst, int yst); - void HideSizeIcon(void); - virtual BOOL OnInitDialog(); - - void OnSizing(UINT nSide, LPRECT lpRect); - void OnSize(UINT nType, int cx, int cy); - void OnGetMinMaxInfo(MINMAXINFO *pmmi); - BOOL OnEraseBkgnd(CDC* pDC); - -public: - int UpdateControlRect(UINT nID, CRect *pnr); -}; - - -//------------------------CIconListBox for CWndElementList------------------------------------- - -class CIconListBox : public CListBox -{ -public: - CIconListBox(); - virtual ~CIconListBox(); - -public: - int InsertString(int nIndex, LPCWSTR lpszItem , int nImage); - virtual void ResetContent(); - virtual void GetText(int nIndex, CString& rString); - - virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); - void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct); - int CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct); - -protected: - // Generated message map functions - //{{AFX_MSG(CIconListBox) - afx_msg void OnMouseMove(UINT nFlags, CPoint point); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() - -protected: - struct ItemDatas - { - CString csText; - int nImage; - }; -}; -//----------------------------------CWndElementList-------------------------------------------- -#define IDC_LIST_JS_ELEMENT 10070 - -#define ELEMENT_LIST_WIDTH 140 -#define ELEMENT_LIST_HEIGHT 180 -#define ELEMENT_LIST_TOP_OFFSET 13 - -#define ELEMENT_TYPE_NAME 0 -#define ELEMENT_TYPE_CONST 1 -#define ELEMENT_TYPE_FUN 2 -#define ELEMENT_TYPE_PRO 3 - -class CWndElementList : public CWnd -{ -public: - CWndElementList(); - virtual ~CWndElementList(); - -public: - virtual void OnSize(UINT nType, int cx, int cy); - virtual BOOL Create(CWnd* pParentWnd); - virtual BOOL ShowWindow(int nCmdShow); - void RemoveAllElement(); - void SetElementList(LPCWSTR* pElement, int* pType , int iCount); - void AddElement(CFX_WideString csValue , int nType); - BOOL GetElementSel(CString &csElement); - BOOL SelectNext(); - BOOL SelectPrevious(); - BOOL SelectFirst(); - BOOL SelectLast(); - BOOL SelectNextPage(); - BOOL SelectPreviousPage(); - int GetListHeight(); - -protected: - // Generated message map functions - //{{AFX_MSG(CWndElementList) - afx_msg void OnPaint(); - afx_msg BOOL OnNcActivate(BOOL bActive); - afx_msg void OnSelJSElement(); - afx_msg void OnDblclkJSElement(); - afx_msg void OnDestroy(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -protected: - CIconListBox m_ListBox; - BOOL m_bBlock; -}; - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// CJS_ConsoleDlg ¶Ô»°¿ò -class CJS_ConsoleDlg : public CJS_ResizeDlg -{ - DECLARE_DYNAMIC(CJS_ConsoleDlg) - -public: - CJS_ConsoleDlg(CReader_App* pApp, CWnd* pParent); - virtual ~CJS_ConsoleDlg(); - - enum { IDD = IDD_JS_CONSOLE }; - - void Create(); - - void AppendConsoleText(const CFX_WideString& swText); - void SetConsoleText(const CFX_WideString& swText); - CFX_WideString GetConsoleText() const; - CFX_WideString GetScriptText() const; - - BOOL ResetElementList(LPCWSTR lpstrRef); - IFXJS_Runtime* GetJSRuntime(); - -protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV Ö§³Ö - -protected: - virtual BOOL OnInitDialog(); - virtual void OnCancel(); - - virtual BOOL PreTranslateMessage(MSG* pMsg); - -protected: - // Generated message map functions - //{{AFX_MSG(CJS_ConsoleDlg) - afx_msg void OnBnClickedClear(); - afx_msg void OnBnClickedOk(); - afx_msg void OnBnClickTips(); - afx_msg void OnSizing(UINT nSide, LPRECT lpRect); - afx_msg void OnSize(UINT nType, int cx, int cy); - afx_msg void OnGetMinMaxInfo(MINMAXINFO *pmmi); - afx_msg BOOL OnEraseBkgnd(CDC* pDC); - afx_msg void OnShowWindow(BOOL bShow, UINT nStatus); - - afx_msg void OnLButtonDown(UINT nFlags, CPoint point); - afx_msg void OnChangeScriptEdit(WPARAM wParam , LPARAM lParam); - afx_msg void OnMove(int x , int y); - public: - virtual int DoModal(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() - -public: - CGW_LineNumberEdit m_edtSC; - BOOL m_bTips; - const UINT m_uTextlimited; - FX_HGLOBAL m_hGlobal; - CReader_App * m_pApp; - CWndElementList m_WndElementList; -}; - -#endif //_JS_CONSOLE_H_ \ No newline at end of file diff --git a/fpdfsdk/include/javascript/resource.h b/fpdfsdk/include/javascript/resource.h index 710cc50754..058b5fd893 100644 --- a/fpdfsdk/include/javascript/resource.h +++ b/fpdfsdk/include/javascript/resource.h @@ -1,110 +1,33 @@ // Copyright 2014 PDFium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - + // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#define IDD_JS_MSGBOX 25600 -#define IDD_RESPONSE 25601 -#define IDC_JS_MSG_TEXT 25602 -#define ID_JS_MSG_OK 25603 -#define ID_JS_MSG_CANCEL 25604 -#define IDC_JS_MSG_ICON 25605 -#define ID_JS_MSG_YES 25606 -#define ID_JS_MSG_NO 25607 -#define IDC_JS_QUESTION 25608 -#define ID_JS_OK 25609 -#define ID_JS_CANCEL 25610 -#define IDC_JS_ANSWER 25611 -#define IDC_JS_EDIT 25612 +#ifndef FPDFSDK_INCLUDE_JAVASCRIPT_RESOURCE_H_ +#define FPDFSDK_INCLUDE_JAVASCRIPT_RESOURCE_H_ + +#include "../../../core/include/fxcrt/fx_basic.h" // For CFX_WideString. +#include "../fsdk_define.h" // For FX_UINT. + +class CJS_Context; + #define IDS_STRING_JSALERT 25613 #define IDS_STRING_JSPARAMERROR 25614 #define IDS_STRING_JSAFNUMBER_KEYSTROKE 25615 -#define IDS_STRING_JSINPUTERROR 25616 #define IDS_STRING_JSPARAM_TOOLONG 25617 #define IDS_STRING_JSPARSEDATE 25618 #define IDS_STRING_JSRANGE1 25619 #define IDS_STRING_JSRANGE2 25620 #define IDS_STRING_JSRANGE3 25621 -#define IDS_STRING_JSRANGE4 25622 -#define IDS_STRING_FILEOPENFAIL 25623 -#define IDS_STRING_JSATTENTION 25624 -#define IDS_STRING_JSSUBMITS 25625 -#define IDS_STRING_JSSUBMITF 25626 #define IDS_STRING_NOTSUPPORT 25627 #define IDS_STRING_JSBUSY 25628 #define IDS_STRING_JSEVENT 25629 #define IDS_STRING_RUN 25630 -#define IDS_STRING_UNHANDLED 25631 #define IDS_STRING_JSPRINT1 25632 #define IDS_STRING_JSPRINT2 25633 -#define IDS_STRING_LAUNCHURL 25634 #define IDS_JSPARAM_INCORRECT 25635 -#define IDD_JS_CONSOLE 25636 -#define IDS_STRING_SAFEMODEL 25636 -#define IDC_EDTSCRIPT 25637 -#define IDC_BTNCLEAR 25638 -#define IDC_EDTOUTPUT 25639 -#define IDC_CHECK_TIPS 25640 -#define IDC_BTNRUN 25641 - - - -static CFX_WideString JSGetStringFromID(CJS_Context* pContext, FX_UINT ID) -{ - switch(ID) - { - case IDS_STRING_JSALERT: - return L"Alert"; - case IDS_STRING_JSPARAMERROR: - return L"The amount of parameters is not correct !"; - case IDS_STRING_JSAFNUMBER_KEYSTROKE: - return L"The input value is invalid."; - case IDS_STRING_JSINPUTERROR: - return L"Input error !"; - case IDS_STRING_JSPARAM_TOOLONG: - return L"The value you are going to input is too long."; - case IDS_STRING_JSPARSEDATE: - return L"The input string can't be parsed to a valid date time (%s)."; - case IDS_STRING_JSRANGE1: - return L"Invalid value: must be greater or equal to %s and less than or equal to %s."; - case IDS_STRING_JSRANGE2: - return L"Invalid value: must be greater or equal to %s."; - case IDS_STRING_JSRANGE3: - return L"Invalid value: must be less than or equal to %s."; - case IDS_STRING_JSRANGE4: - return L"Range Error"; - case IDS_STRING_FILEOPENFAIL: - return L"Opening file failed."; - case IDS_STRING_JSATTENTION: - return L"Attention"; - case IDS_STRING_JSSUBMITS: - return L"Submit form successfully!"; - case IDS_STRING_JSSUBMITF: - return L"Submit form failed!"; - case IDS_STRING_NOTSUPPORT: - return L"Not supported."; - case IDS_STRING_JSBUSY: - return L"System is busy!"; - case IDS_STRING_JSEVENT: - return L"The event of the formfield exists!"; - case IDS_STRING_RUN: - return L"It runs successfully."; - case IDS_STRING_UNHANDLED: - return L"An unhandled error!"; - case IDS_STRING_JSPRINT1: - return L"The second parameter can't convert to Date!"; - case IDS_STRING_JSPRINT2: - return L"The second parameter isn't a valid Date!"; - case IDS_STRING_LAUNCHURL: - return L"The Document is trying to connect to \r\n%s\r\nIf you trust the site, choose OK. If you don't trust the site, choose Cancel."; - case IDS_JSPARAM_INCORRECT: - return L"The parameter you inputted is incorrect!"; - case IDS_STRING_SAFEMODEL: - return L"Secure reading mode"; - default: - return L""; - } -} +CFX_WideString JSGetStringFromID(CJS_Context* pContext, FX_UINT id); +#endif // FPDFSDK_INCLUDE_JAVASCRIPT_RESOURCE_H_ diff --git a/fpdfsdk/src/javascript/resource.cpp b/fpdfsdk/src/javascript/resource.cpp new file mode 100644 index 0000000000..1c453dcda7 --- /dev/null +++ b/fpdfsdk/src/javascript/resource.cpp @@ -0,0 +1,47 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "../../include/javascript/resource.h" + +CFX_WideString JSGetStringFromID(CJS_Context* pContext, FX_UINT id) +{ + switch (id) + { + case IDS_STRING_JSALERT: + return L"Alert"; + case IDS_STRING_JSPARAMERROR: + return L"Incorrect number of parameters passed to function."; + case IDS_STRING_JSAFNUMBER_KEYSTROKE: + return L"The input value is invalid."; + case IDS_STRING_JSPARAM_TOOLONG: + return L"The input value is too long."; + case IDS_STRING_JSPARSEDATE: + return L"The input value can't be parsed as a valid date/time (%s)."; + case IDS_STRING_JSRANGE1: + return L"The input value must be greater than or equal to %s" + L" and less than or equal to %s."; + case IDS_STRING_JSRANGE2: + return L"The input value must be greater than or equal to %s."; + case IDS_STRING_JSRANGE3: + return L"The input value must be less than or equal to %s."; + case IDS_STRING_NOTSUPPORT: + return L"Operation not supported."; + case IDS_STRING_JSBUSY: + return L"System is busy."; + case IDS_STRING_JSEVENT: + return L"Duplicate formfield event found."; + case IDS_STRING_RUN: + return L"Script ran successfully."; + case IDS_STRING_JSPRINT1: + return L"The second parameter can't be converted to a Date."; + case IDS_STRING_JSPRINT2: + return L"The second parameter is an invalid Date!"; + case IDS_JSPARAM_INCORRECT: + return L"Global value not found."; + default: + return L""; + } +} diff --git a/pdfium.gyp b/pdfium.gyp index 7b959bd45c..4134b49f8d 100644 --- a/pdfium.gyp +++ b/pdfium.gyp @@ -742,7 +742,6 @@ 'fpdfsdk/include/javascript/Icon.h', 'fpdfsdk/include/javascript/IJavaScript.h', 'fpdfsdk/include/javascript/JavaScript.h', - 'fpdfsdk/include/javascript/JS_Console.h', 'fpdfsdk/include/javascript/JS_Context.h', 'fpdfsdk/include/javascript/JS_Define.h', 'fpdfsdk/include/javascript/JS_EventHandler.h', @@ -772,6 +771,7 @@ 'fpdfsdk/src/javascript/JS_Value.cpp', 'fpdfsdk/src/javascript/PublicMethods.cpp', 'fpdfsdk/src/javascript/report.cpp', + 'fpdfsdk/src/javascript/resource.cpp', 'fpdfsdk/src/javascript/util.cpp', ], }, -- cgit v1.2.3