• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "xfa/fxfa/cxfa_ffpasswordedit.h"
8 
9 #include <utility>
10 
11 #include "xfa/fwl/cfwl_edit.h"
12 #include "xfa/fwl/cfwl_notedriver.h"
13 #include "xfa/fxfa/cxfa_ffdoc.h"
14 #include "xfa/fxfa/parser/cxfa_node.h"
15 
CXFA_FFPasswordEdit(CXFA_Node * pNode)16 CXFA_FFPasswordEdit::CXFA_FFPasswordEdit(CXFA_Node* pNode)
17     : CXFA_FFTextEdit(pNode) {}
18 
~CXFA_FFPasswordEdit()19 CXFA_FFPasswordEdit::~CXFA_FFPasswordEdit() {}
20 
LoadWidget()21 bool CXFA_FFPasswordEdit::LoadWidget() {
22   auto pNewEdit = pdfium::MakeUnique<CFWL_Edit>(
23       GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr);
24   CFWL_Edit* pWidget = pNewEdit.get();
25   m_pNormalWidget = std::move(pNewEdit);
26   m_pNormalWidget->SetLayoutItem(this);
27 
28   CFWL_NoteDriver* pNoteDriver =
29       m_pNormalWidget->GetOwnerApp()->GetNoteDriver();
30   pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(),
31                                    m_pNormalWidget.get());
32   m_pOldDelegate = m_pNormalWidget->GetDelegate();
33   m_pNormalWidget->SetDelegate(this);
34   m_pNormalWidget->LockUpdate();
35 
36   pWidget->SetText(m_pNode->GetWidgetAcc()->GetValue(XFA_VALUEPICTURE_Display));
37   UpdateWidgetProperty();
38   m_pNormalWidget->UnlockUpdate();
39   return CXFA_FFField::LoadWidget();
40 }
41 
UpdateWidgetProperty()42 void CXFA_FFPasswordEdit::UpdateWidgetProperty() {
43   CFWL_Edit* pWidget = static_cast<CFWL_Edit*>(m_pNormalWidget.get());
44   if (!pWidget)
45     return;
46 
47   uint32_t dwExtendedStyle = FWL_STYLEEXT_EDT_ShowScrollbarFocus |
48                              FWL_STYLEEXT_EDT_OuterScrollbar |
49                              FWL_STYLEEXT_EDT_Password;
50   dwExtendedStyle |= UpdateUIProperty();
51 
52   WideString password = m_pNode->GetWidgetAcc()->GetPasswordChar();
53   if (!password.IsEmpty())
54     pWidget->SetAliasChar(password[0]);
55   if (!m_pNode->GetWidgetAcc()->IsHorizontalScrollPolicyOff())
56     dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll;
57   if (!m_pNode->IsOpenAccess() || !GetDoc()->GetXFADoc()->IsInteractive())
58     dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly;
59 
60   dwExtendedStyle |= GetAlignment();
61   m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);
62 }
63