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 "third_party/base/ptr_util.h" 12 #include "xfa/fwl/cfwl_edit.h" 13 #include "xfa/fwl/cfwl_notedriver.h" 14 #include "xfa/fxfa/cxfa_ffdoc.h" 15 #include "xfa/fxfa/parser/cxfa_node.h" 16 #include "xfa/fxfa/parser/cxfa_passwordedit.h" 17 CXFA_FFPasswordEdit(CXFA_Node * pNode,CXFA_PasswordEdit * password_node)18CXFA_FFPasswordEdit::CXFA_FFPasswordEdit(CXFA_Node* pNode, 19 CXFA_PasswordEdit* password_node) 20 : CXFA_FFTextEdit(pNode), password_node_(password_node) {} 21 22 CXFA_FFPasswordEdit::~CXFA_FFPasswordEdit() = default; 23 LoadWidget()24bool CXFA_FFPasswordEdit::LoadWidget() { 25 ASSERT(!IsLoaded()); 26 auto pNewEdit = pdfium::MakeUnique<CFWL_Edit>( 27 GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); 28 CFWL_Edit* pWidget = pNewEdit.get(); 29 SetNormalWidget(std::move(pNewEdit)); 30 pWidget->SetAdapterIface(this); 31 32 CFWL_NoteDriver* pNoteDriver = pWidget->GetOwnerApp()->GetNoteDriver(); 33 pNoteDriver->RegisterEventTarget(pWidget, pWidget); 34 m_pOldDelegate = pWidget->GetDelegate(); 35 pWidget->SetDelegate(this); 36 37 { 38 CFWL_Widget::ScopedUpdateLock update_lock(pWidget); 39 pWidget->SetText(m_pNode->GetValue(XFA_VALUEPICTURE_Display)); 40 UpdateWidgetProperty(); 41 } 42 43 return CXFA_FFField::LoadWidget(); 44 } 45 UpdateWidgetProperty()46void CXFA_FFPasswordEdit::UpdateWidgetProperty() { 47 CFWL_Edit* pWidget = static_cast<CFWL_Edit*>(GetNormalWidget()); 48 if (!pWidget) 49 return; 50 51 uint32_t dwExtendedStyle = FWL_STYLEEXT_EDT_ShowScrollbarFocus | 52 FWL_STYLEEXT_EDT_OuterScrollbar | 53 FWL_STYLEEXT_EDT_Password; 54 dwExtendedStyle |= UpdateUIProperty(); 55 56 WideString password = password_node_->GetPasswordChar(); 57 if (!password.IsEmpty()) 58 pWidget->SetAliasChar(password[0]); 59 if (!m_pNode->IsHorizontalScrollPolicyOff()) 60 dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; 61 if (!m_pNode->IsOpenAccess() || !GetDoc()->GetXFADoc()->IsInteractive()) 62 dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; 63 64 dwExtendedStyle |= GetAlignment(); 65 GetNormalWidget()->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); 66 } 67