diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2018-01-29 21:34:56 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-01-29 21:34:56 +0000 |
commit | 8308b8c3dfad425942d4aba19a6b85049beff6f4 (patch) | |
tree | ada0bf0c19f846b1f45ac4eba165c6dcadaa5063 | |
parent | c30eb662f8a8ea20564e887182e422fd5c4e2099 (diff) | |
download | pdfium-8308b8c3dfad425942d4aba19a6b85049beff6f4.tar.xz |
Add common base class between CXFA_FFComboBox and CXFA_FFListBox
This CL adds a CXFA_FFDropDown to serve as a base class for the
CXFA_FFComboBox and CXFA_FFListBox and adds a virtual InsertItem and
DeleteItem methods.
Change-Id: I325ffc579ed42a4755bae0c4d18667f8a9458950
Reviewed-on: https://pdfium-review.googlesource.com/24550
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r-- | BUILD.gn | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffcombobox.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffcombobox.h | 12 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffdropdown.cpp | 11 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffdropdown.h | 23 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_fflistbox.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_fflistbox.h | 10 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffnotify.cpp | 20 |
8 files changed, 57 insertions, 25 deletions
@@ -2023,6 +2023,8 @@ if (pdf_enable_xfa) { "xfa/fxfa/cxfa_ffdoc.h", "xfa/fxfa/cxfa_ffdocview.cpp", "xfa/fxfa/cxfa_ffdocview.h", + "xfa/fxfa/cxfa_ffdropdown.cpp", + "xfa/fxfa/cxfa_ffdropdown.h", "xfa/fxfa/cxfa_ffexclgroup.cpp", "xfa/fxfa/cxfa_ffexclgroup.h", "xfa/fxfa/cxfa_fffield.cpp", diff --git a/xfa/fxfa/cxfa_ffcombobox.cpp b/xfa/fxfa/cxfa_ffcombobox.cpp index 45ba63ccf8..f3d4d22f50 100644 --- a/xfa/fxfa/cxfa_ffcombobox.cpp +++ b/xfa/fxfa/cxfa_ffcombobox.cpp @@ -25,7 +25,7 @@ CFWL_ComboBox* ToComboBox(CFWL_Widget* widget) { } // namespace CXFA_FFComboBox::CXFA_FFComboBox(CXFA_Node* pNode) - : CXFA_FFField(pNode), m_pOldDelegate(nullptr) {} + : CXFA_FFDropDown(pNode), m_pOldDelegate(nullptr) {} CXFA_FFComboBox::~CXFA_FFComboBox() {} diff --git a/xfa/fxfa/cxfa_ffcombobox.h b/xfa/fxfa/cxfa_ffcombobox.h index b7d0081bdc..5daab781a6 100644 --- a/xfa/fxfa/cxfa_ffcombobox.h +++ b/xfa/fxfa/cxfa_ffcombobox.h @@ -7,11 +7,11 @@ #ifndef XFA_FXFA_CXFA_FFCOMBOBOX_H_ #define XFA_FXFA_CXFA_FFCOMBOBOX_H_ -#include "xfa/fxfa/cxfa_fffield.h" +#include "xfa/fxfa/cxfa_ffdropdown.h" class CXFA_EventParam; -class CXFA_FFComboBox : public CXFA_FFField { +class CXFA_FFComboBox : public CXFA_FFDropDown { public: explicit CXFA_FFComboBox(CXFA_Node* pNode); ~CXFA_FFComboBox() override; @@ -45,15 +45,17 @@ class CXFA_FFComboBox : public CXFA_FFField { void OnDrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override; - virtual void OpenDropDownList(); + // CXFA_FFDropDown + void InsertItem(const WideStringView& wsLabel, int32_t nIndex) override; + void DeleteItem(int32_t nIndex) override; + + void OpenDropDownList(); void OnTextChanged(CFWL_Widget* pWidget, const WideString& wsChanged); void OnSelectChanged(CFWL_Widget* pWidget, bool bLButtonUp); void OnPreOpen(CFWL_Widget* pWidget); void OnPostOpen(CFWL_Widget* pWidget); void SetItemState(int32_t nIndex, bool bSelected); - void InsertItem(const WideStringView& wsLabel, int32_t nIndex); - void DeleteItem(int32_t nIndex); private: // CXFA_FFField diff --git a/xfa/fxfa/cxfa_ffdropdown.cpp b/xfa/fxfa/cxfa_ffdropdown.cpp new file mode 100644 index 0000000000..5175929e12 --- /dev/null +++ b/xfa/fxfa/cxfa_ffdropdown.cpp @@ -0,0 +1,11 @@ +// Copyright 2018 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 "xfa/fxfa/cxfa_ffdropdown.h" + +CXFA_FFDropDown::CXFA_FFDropDown(CXFA_Node* node) : CXFA_FFField(node) {} + +CXFA_FFDropDown::~CXFA_FFDropDown() = default; diff --git a/xfa/fxfa/cxfa_ffdropdown.h b/xfa/fxfa/cxfa_ffdropdown.h new file mode 100644 index 0000000000..20ed76640b --- /dev/null +++ b/xfa/fxfa/cxfa_ffdropdown.h @@ -0,0 +1,23 @@ +// Copyright 2018 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 XFA_FXFA_CXFA_FFDROPDOWN_H_ +#define XFA_FXFA_CXFA_FFDROPDOWN_H_ + +#include "xfa/fxfa/cxfa_fffield.h" + +class CXFA_FFDropDown : public CXFA_FFField { + public: + ~CXFA_FFDropDown() override; + + virtual void InsertItem(const WideStringView& wsLabel, int32_t nIndex) = 0; + virtual void DeleteItem(int32_t nIndex) = 0; + + protected: + explicit CXFA_FFDropDown(CXFA_Node* pNode); +}; + +#endif // XFA_FXFA_CXFA_FFDROPDOWN_H_ diff --git a/xfa/fxfa/cxfa_fflistbox.cpp b/xfa/fxfa/cxfa_fflistbox.cpp index f4e7a5e6c4..92543e3e6b 100644 --- a/xfa/fxfa/cxfa_fflistbox.cpp +++ b/xfa/fxfa/cxfa_fflistbox.cpp @@ -25,7 +25,7 @@ CFWL_ListBox* ToListBox(CFWL_Widget* widget) { } // namespace CXFA_FFListBox::CXFA_FFListBox(CXFA_Node* pNode) - : CXFA_FFField(pNode), m_pOldDelegate(nullptr) {} + : CXFA_FFDropDown(pNode), m_pOldDelegate(nullptr) {} CXFA_FFListBox::~CXFA_FFListBox() { if (!m_pNormalWidget) diff --git a/xfa/fxfa/cxfa_fflistbox.h b/xfa/fxfa/cxfa_fflistbox.h index 27f1cdb8a4..feff0b7cbb 100644 --- a/xfa/fxfa/cxfa_fflistbox.h +++ b/xfa/fxfa/cxfa_fflistbox.h @@ -7,9 +7,9 @@ #ifndef XFA_FXFA_CXFA_FFLISTBOX_H_ #define XFA_FXFA_CXFA_FFLISTBOX_H_ -#include "xfa/fxfa/cxfa_fffield.h" +#include "xfa/fxfa/cxfa_ffdropdown.h" -class CXFA_FFListBox : public CXFA_FFField { +class CXFA_FFListBox : public CXFA_FFDropDown { public: explicit CXFA_FFListBox(CXFA_Node* pNode); ~CXFA_FFListBox() override; @@ -23,10 +23,12 @@ class CXFA_FFListBox : public CXFA_FFField { const CFX_Matrix& matrix) override; FormFieldType GetFormFieldType() override; + // CXFA_FFDropDown + void InsertItem(const WideStringView& wsLabel, int32_t nIndex) override; + void DeleteItem(int32_t nIndex) override; + void OnSelectChanged(CFWL_Widget* pWidget); void SetItemState(int32_t nIndex, bool bSelected); - void InsertItem(const WideStringView& wsLabel, int32_t nIndex); - void DeleteItem(int32_t nIndex); private: bool CommitData() override; diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp index 36f860199a..a7cb91185b 100644 --- a/xfa/fxfa/cxfa_ffnotify.cpp +++ b/xfa/fxfa/cxfa_ffnotify.cpp @@ -41,8 +41,8 @@ namespace { -CXFA_FFListBox* ToListBox(CXFA_FFWidget* widget) { - return static_cast<CXFA_FFListBox*>(widget); +CXFA_FFDropDown* ToDropDown(CXFA_FFWidget* widget) { + return static_cast<CXFA_FFDropDown*>(widget); } CXFA_FFComboBox* ToComboBox(CXFA_FFWidget* widget) { @@ -71,12 +71,8 @@ void CXFA_FFNotify::OnWidgetListItemAdded(CXFA_Node* pSender, CXFA_FFWidget* pWidget = m_pDoc->GetDocView()->GetWidgetForNode(pSender); for (; pWidget; pWidget = pSender->GetNextWidget(pWidget)) { - if (pWidget->IsLoaded()) { - if (pSender->IsListBox()) - ToListBox(pWidget)->InsertItem(pLabel, iIndex); - else - ToComboBox(pWidget)->InsertItem(pLabel, iIndex); - } + if (pWidget->IsLoaded()) + ToDropDown(pWidget)->InsertItem(pLabel, iIndex); } } @@ -87,12 +83,8 @@ void CXFA_FFNotify::OnWidgetListItemRemoved(CXFA_Node* pSender, CXFA_FFWidget* pWidget = m_pDoc->GetDocView()->GetWidgetForNode(pSender); for (; pWidget; pWidget = pSender->GetNextWidget(pWidget)) { - if (pWidget->IsLoaded()) { - if (pSender->IsListBox()) - ToListBox(pWidget)->DeleteItem(iIndex); - else - ToComboBox(pWidget)->DeleteItem(iIndex); - } + if (pWidget->IsLoaded()) + ToDropDown(pWidget)->DeleteItem(iIndex); } } |