7#include "fpdfsdk/pwl/cpwl_edit.h"
14#include "constants/ascii.h"
15#include "core/fpdfapi/font/cpdf_font.h"
16#include "core/fpdfdoc/cpvt_word.h"
17#include "core/fpdfdoc/ipvt_fontmap.h"
18#include "core/fxcrt/fx_safe_types.h"
19#include "core/fxge/cfx_fillrenderoptions.h"
20#include "core/fxge/cfx_graphstatedata.h"
21#include "core/fxge/cfx_path.h"
22#include "core/fxge/cfx_renderdevice.h"
23#include "core/fxge/fx_font.h"
24#include "fpdfsdk/pwl/cpwl_caret.h"
25#include "fpdfsdk/pwl/cpwl_edit_impl.h"
26#include "fpdfsdk/pwl/cpwl_scroll_bar.h"
27#include "fpdfsdk/pwl/cpwl_wnd.h"
28#include "fpdfsdk/pwl/ipwl_fillernotify.h"
29#include "public/fpdf_fwlevent.h"
30#include "third_party/base/check.h"
34 std::unique_ptr<IPWL_FillerNotify::PerWindowData> pAttachedData)
44void CPWL_Edit::
SetText(
const WideString& csText) {
45 m_pEditImpl->SetText(csText);
56 ObservedPtr<CPWL_Edit> this_observed(
this);
57 pVSB
->Move(rcVScroll,
true,
false);
70 m_pCaret->SetClipRect(rect);
73 m_pEditImpl->SetPlateRect(GetClientRect());
88 m_pEditImpl->SetAlignmentV(
static_cast<int32_t>(PEAV_CENTER));
93 return GetSelectWordRange() != m_pEditImpl->GetWholeWordRange();
97 return !HasFlag(
PES_PASSWORD) && m_pEditImpl->IsSelected();
107 m_pEditImpl->ClearSelection();
112 m_pEditImpl->SetFontMap(GetFontMap());
113 m_pEditImpl->SetNotify(
this);
114 m_pEditImpl->Initialize();
125void CPWL_Edit::SetParamByFlag() {
127 m_pEditImpl->SetAlignmentH(2);
129 m_pEditImpl->SetAlignmentH(1);
131 m_pEditImpl->SetAlignmentH(0);
135 m_pEditImpl->SetAlignmentV(1);
137 m_pEditImpl->SetAlignmentV(0);
141 m_pEditImpl->SetPasswordChar(
'*');
148 m_pEditImpl->EnableUndo(HasFlag(
PES_UNDO));
152 m_pEditImpl->SetTextOverflow(
true);
161 m_pCaret->SetClipRect(rect);
172 const int32_t nCharArray = m_pEditImpl->GetCharArray();
176 FX_SAFE_INT32 nCharArraySafe = nCharArray;
179 draw_border = nCharArraySafe.IsValid();
186 gsd.m_DashArray = {
static_cast<
float>(
GetBorderDash().nDash),
191 const float width = (rcClient
.right - rcClient
.left) / nCharArray;
193 CFX_PointF bottom(0, rcClient.bottom);
194 CFX_PointF top(0, rcClient.top);
195 for (int32_t i = 0; i < nCharArray - 1; ++i) {
196 bottom.x = rcClient
.left + width * (i + 1);
201 if (!path.GetPoints().empty()) {
215 m_pEditImpl->DrawEdit(
216 pDevice, mtUser2Device, GetTextColor().ToFXColor(GetTransparency()),
217 rcClip, CFX_PointF(), pRange, GetFillerNotify(), GetAttachedData());
221 ObservedPtr<CPWL_Edit> observed_ptr(
this);
238 ObservedPtr<CPWL_Edit> observed_ptr(
this);
247 if (!
Move(m_rcOldWindow,
true,
true)) {
252 m_pEditImpl->SelectNone();
264 if (!m_pEditImpl->IsSelected())
269 std::tie(nStart, nEnd) = m_pEditImpl->GetSelection();
271 CPVT_WordPlace wpStart = m_pEditImpl->WordIndexToWordPlace(nStart);
277 return m_pEditImpl->IsTextFull();
282 int32_t nCharArray) {
292 return xdiv < ydiv ? xdiv : ydiv;
299 m_pEditImpl->SetCharArray(nCharArray);
300 m_pEditImpl->SetTextOverflow(
true);
301 m_pEditImpl->Paint();
312 if (fFontSize <= 0.0f)
315 m_pEditImpl->SetAutoFontSize(
false);
316 m_pEditImpl->SetFontSize(fFontSize);
317 m_pEditImpl->Paint();
321 m_pEditImpl->SetLimitChar(nLimitChar);
322 m_pEditImpl->Paint();
329bool CPWL_Edit::IsVScrollBarVisible()
const {
334bool CPWL_Edit::
OnKeyDown(FWL_VKEYCODE nKeyCode,
Mask<FWL_EVENTFLAG> nFlag) {
339 WideString strChange;
340 WideString strChangeEx;
346 if (nSelStart == nSelEnd)
347 nSelEnd = nSelStart + 1;
349 ObservedPtr<
CPWL_Wnd> this_observed(
this);
353 strChangeEx, nSelStart, nSelEnd,
356 if (!this_observed) {
367 bool bRet = OnKeyDownInternal(nKeyCode, nFlag);
370 if (IsProceedtoOnChar(nKeyCode, nFlag))
377bool CPWL_Edit::IsProceedtoOnChar(FWL_VKEYCODE nKeyCode,
378 Mask<FWL_EVENTFLAG> nFlag) {
381 if (bCtrl && !bAlt) {
406bool CPWL_Edit::
OnChar(uint16_t nChar,
Mask<FWL_EVENTFLAG> nFlag) {
418 if (nSelStart == nSelEnd)
419 nSelStart = nSelEnd - 1;
428 ObservedPtr<
CPWL_Wnd> this_observed(
this);
430 WideString strChangeEx;
433 strChangeEx, nSelStart, nSelEnd,
436 if (!this_observed) {
451 if (nOldCharSet != nNewCharSet) {
456 return OnCharInternal(nChar, nFlag);
460 const CFX_PointF& point,
461 const CFX_Vector& delta) {
465 CFX_PointF ptScroll = GetScrollPos();
475 m_pCaret.ExtractAsDangling();
478bool CPWL_Edit::IsWndHorV()
const {
492 return m_pEditImpl->GetSelectedText();
496 m_pEditImpl->ReplaceAndKeepSelection(text);
500 m_pEditImpl->ReplaceSelection(text);
504 m_pEditImpl->SelectAll();
519 m_pEditImpl->SetScrollPos(CFX_PointF(m_pEditImpl->GetScrollPos().x, pos));
527void CPWL_Edit::CreateEditCaret(
const CreateParams& cp) {
537 auto pCaret = std::make_unique<CPWL_Caret>(ecp, CloneAttachedData());
538 m_pCaret = pCaret.get();
539 m_pCaret->SetInvalidRect(GetClientRect());
540 AddChild(std::move(pCaret));
545 m_pEditImpl->SetFontSize(fFontSize);
546 m_pEditImpl->Paint();
550 return m_pEditImpl->GetFontSize();
553bool CPWL_Edit::OnKeyDownInternal(FWL_VKEYCODE nKeyCode,
554 Mask<FWL_EVENTFLAG> nFlag) {
580 if (nKeyCode == FWL_VKEY_Delete && m_pEditImpl->IsSelected())
592 m_pEditImpl->OnVK_UP(IsSHIFTKeyDown(nFlag));
595 m_pEditImpl->OnVK_DOWN(IsSHIFTKeyDown(nFlag));
598 m_pEditImpl->OnVK_LEFT(IsSHIFTKeyDown(nFlag));
601 m_pEditImpl->OnVK_RIGHT(IsSHIFTKeyDown(nFlag));
604 m_pEditImpl->OnVK_HOME(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
607 m_pEditImpl->OnVK_END(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
622bool CPWL_Edit::OnCharInternal(uint16_t nChar,
Mask<FWL_EVENTFLAG> nFlag) {
641 uint16_t word = nChar;
643 if (bCtrl && !bAlt) {
672 if (m_pEditImpl->IsSelected() && word == pdfium::ascii::kBackspace)
695 const CFX_PointF& point) {
703 m_pEditImpl->OnMouseDown(point, IsSHIFTKeyDown(nFlag),
704 IsCTRLKeyDown(nFlag));
710 const CFX_PointF& point) {
718 m_bMouseDown =
false;
724 const CFX_PointF& point) {
727 m_pEditImpl->SelectAll();
733 const CFX_PointF& point) {
746 const CFX_PointF& point) {
750 m_pEditImpl->OnMouseMove(point,
false,
false);
755void CPWL_Edit::SetEditCaret(
bool bVisible) {
759 GetCaretInfo(&ptHead, &ptFoot);
766void CPWL_Edit::GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot)
const {
768 pIterator->SetAt(m_pEditImpl->GetCaret());
772 ptHead->x = word.ptWord.x + word
.fWidth;
773 ptHead->y = word.ptWord.y + word
.fAscent;
774 ptFoot->x = word.ptWord.x + word
.fWidth;
775 ptFoot->y = word.ptWord.y + word
.fDescent;
777 ptHead->x = line.ptLine.x;
779 ptFoot->x = line.ptLine.x;
785 const CFX_PointF& ptHead,
786 const CFX_PointF& ptFoot) {
790 if (!IsFocused() || m_pEditImpl->IsSelected())
793 ObservedPtr<CPWL_Edit> this_observed(
this);
794 m_pCaret->SetCaret(bVisible, ptHead, ptFoot);
795 if (!this_observed) {
803 return m_pEditImpl->GetText();
807 m_pEditImpl->SetSelection(nStartChar, nEndChar);
811 return m_pEditImpl->GetSelection();
816 m_pEditImpl->ClearSelection();
820 m_pEditImpl->SetScrollPos(point);
824 return m_pEditImpl->GetScrollPos();
827void CPWL_Edit::CopyText() {}
829void CPWL_Edit::PasteText() {}
831void CPWL_Edit::InsertWord(uint16_t word,
FX_Charset nCharset) {
833 m_pEditImpl->InsertWord(word, nCharset);
836void CPWL_Edit::InsertReturn() {
838 m_pEditImpl->InsertReturn();
841void CPWL_Edit::Delete() {
843 m_pEditImpl->Delete();
846void CPWL_Edit::Backspace() {
848 m_pEditImpl->Backspace();
852 return !IsReadOnly() && m_pEditImpl->CanUndo();
856 return !IsReadOnly() && m_pEditImpl->CanRedo();
860 return CanUndo() && m_pEditImpl->Undo();
864 return CanRedo() && m_pEditImpl->Redo();
870 m_bMouseDown =
false;
constexpr CFX_FloatRect(float l, float b, float r, float t)
constexpr CFX_FloatRect()=default
void Inflate(float x, float y)
CFX_FloatRect & operator=(const CFX_FloatRect &that)=default
CFX_PointF Transform(const CFX_PointF &point) const
void AppendPoint(const CFX_PointF &point, Point::Type type)
bool DrawPath(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_GraphStateData *pGraphState, uint32_t fill_color, uint32_t stroke_color, const CFX_FillRenderOptions &fill_options)
const FX_RECT & GetFontBBox() const
bool IsStandardFont() const
bool GetWord(CPVT_Word &word) const
bool GetLine(CPVT_Line &line) const
static float GetCharArrayAutoFontSize(const CPDF_Font *pFont, const CFX_FloatRect &rcPlate, int32_t nCharArray)
void SetScrollInfo(const PWL_SCROLL_INFO &info) override
void SetFontSize(float fFontSize) override
bool SetCaret(bool bVisible, const CFX_PointF &ptHead, const CFX_PointF &ptFoot)
bool SelectAllText() override
bool OnLButtonUp(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point) override
bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask< FWL_EVENTFLAG > nFlag) override
CPWL_Edit(const CreateParams &cp, std::unique_ptr< IPWL_FillerNotify::PerWindowData > pAttachedData)
CFX_FloatRect GetFocusRect() const override
bool RepositionChildWnd() override
void SetScrollPosition(float pos) override
void SetAlignFormatVerticalCenter()
void SetCursor() override
WideString GetText() override
void SetCharSet(FX_Charset nCharSet)
bool OnLButtonDblClk(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point) override
void OnSetFocus() override
void ReplaceAndKeepSelection(const WideString &text) override
void ScrollWindowVertically(float pos) override
void SetCharArray(int32_t nCharArray)
void SetSelection(int32_t nStartChar, int32_t nEndChar)
std::pair< int32_t, int32_t > GetSelection() const
void OnKillFocus() override
void SetScrollPos(const CFX_PointF &point)
void SetText(const WideString &csText)
bool OnMouseMove(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point) override
void ReplaceSelection(const WideString &text) override
CFX_FloatRect GetClientRect() const override
bool OnMouseWheel(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point, const CFX_Vector &delta) override
void DrawThisAppearance(CFX_RenderDevice *pDevice, const CFX_Matrix &mtUser2Device) override
bool OnChar(uint16_t nChar, Mask< FWL_EVENTFLAG > nFlag) override
void OnCreated() override
WideString GetSelectedText() override
float GetFontSize() const override
void SetLimitChar(int32_t nLimitChar)
FX_Charset GetCharSet() const
bool OnLButtonDown(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point) override
CFX_PointF GetScrollPos() const
bool OnRButtonUp(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point) override
void CreateChildWnd(const CreateParams &cp) override
void OnDestroy() override
bool CanSelectAll() const
virtual void OnSetFocusForEdit(CPWL_Edit *pEdit)=0
CFX_Matrix GetWindowMatrix() const
static bool IsPlatformShortcutKey(Mask< FWL_EVENTFLAG > nFlag)
static bool IsCTRLKeyDown(Mask< FWL_EVENTFLAG > nFlag)
bool ClientHitTest(const CFX_PointF &point) const
static bool IsALTKeyDown(Mask< FWL_EVENTFLAG > nFlag)
CFX_Color GetBorderColor() const
BorderStyle GetBorderStyle() const
virtual bool OnChar(uint16_t nChar, Mask< FWL_EVENTFLAG > nFlag)
void RemoveFlag(uint32_t dwFlags)
IPWL_FillerNotify * GetFillerNotify() const
bool HasFlag(uint32_t dwFlags) const
CFX_FloatRect GetWindowRect() const
IPVT_FontMap * GetFontMap() const
void SetTransparency(int32_t nTransparency)
virtual bool OnLButtonUp(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
virtual bool OnMouseMove(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
static bool IsSHIFTKeyDown(Mask< FWL_EVENTFLAG > nFlag)
virtual bool OnRButtonUp(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
virtual bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask< FWL_EVENTFLAG > nFlag)
int32_t GetBorderWidth() const
CreateParams * GetCreationParams()
virtual void SetScrollInfo(const PWL_SCROLL_INFO &info)
virtual bool InvalidateRect(const CFX_FloatRect *pRect)
virtual bool SetVisible(bool bVisible)
IPWL_FillerNotify::PerWindowData * GetAttachedData() const
const CPWL_Dash & GetBorderDash() const
int32_t GetInnerBorderWidth() const
virtual void SetScrollPosition(float pos)
virtual void DrawThisAppearance(CFX_RenderDevice *pDevice, const CFX_Matrix &mtUser2Device)
ProviderIface * GetProvider() const
bool Move(const CFX_FloatRect &rcNew, bool bReset, bool bRefresh)
void SetClipRect(const CFX_FloatRect &rect)
virtual bool OnLButtonDblClk(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
CPWL_ScrollBar * GetVScrollBar() const
virtual bool OnLButtonDown(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
virtual RetainPtr< CPDF_Font > GetPDFFont(int32_t nFontIndex)=0
virtual FX_Charset CharSetFromUnicode(uint16_t word, FX_Charset nOldCharset)=0
WideString & operator+=(wchar_t ch)
#define PWS_AUTOTRANSPARENT
#define PWS_NOREFRESHCLIP
constexpr uint8_t kEscape
constexpr uint8_t kReturn
constexpr uint8_t kControlC
constexpr uint8_t kControlZ
constexpr uint8_t kBackspace
constexpr uint8_t kControlX
constexpr uint8_t kNewline
constexpr uint8_t kControlV
constexpr uint8_t kControlA
static constexpr CFX_FillRenderOptions EvenOddOptions()
CPVT_WordRange(const CPVT_WordPlace &begin, const CPVT_WordPlace &end)