7#ifndef XFA_FDE_CFDE_TEXTEDITENGINE_H_
8#define XFA_FDE_CFDE_TEXTEDITENGINE_H_
15#include "core/fxcrt/retain_ptr.h"
16#include "core/fxcrt/unowned_ptr.h"
17#include "core/fxcrt/widestring.h"
18#include "core/fxge/dib/fx_dib.h"
19#include "xfa/fgas/layout/cfgas_txtbreak.h"
41class CFDE_TextEditEngine
final :
public CFGAS_TxtBreak::
Engine {
45 explicit Iterator(
const CFDE_TextEditEngine* engine);
48 void Next(
bool bPrev);
50 void SetAt(size_t nIndex);
52 bool IsEOF(
bool bPrev)
const;
55 UnownedPtr<
const CFDE_TextEditEngine>
const engine_;
56 int32_t current_position_ = -1;
62 virtual void Redo()
const = 0;
63 virtual void Undo()
const = 0;
92 wchar_t GetChar(size_t idx)
const override;
99 const WideString& text,
155 return {selection_.start_idx, selection_.count};
181 return text_piece_info_;
194 static constexpr size_t kGapSize = 128;
195 static constexpr size_t kMaxEditOperations = 128;
196 static constexpr size_t kPageWidthMax = 0xffff;
198 void SetCombTextWidth();
199 void AdjustGap(size_t idx, size_t length);
200 void RebuildPieces();
201 size_t CountCharsExceedingSize(
const WideString& str, size_t num_to_check);
202 void AddOperationRecord(std::unique_ptr<Operation> op);
204 bool IsAlignedRight()
const {
208 bool IsAlignedCenter()
const {
215 std::vector<FDE_TEXTEDITPIECE> text_piece_info_;
216 std::vector<int32_t> char_widths_;
217 CFGAS_TxtBreak text_break_;
219 FX_ARGB font_color_ = 0xff000000;
220 float font_size_ = 10.0f;
221 float line_spacing_ = 10.0f;
222 std::vector<WideString::CharType> content_;
223 size_t text_length_ = 0;
226 size_t gap_position_ = 0;
227 size_t gap_size_ = kGapSize;
229 size_t available_width_ = kPageWidthMax;
230 size_t character_limit_ = std::numeric_limits<size_t>::max();
231 size_t visible_line_count_ = 1;
233 std::vector<std::unique_ptr<Operation>> operation_buffer_;
235 size_t next_operation_index_to_undo_ = kMaxEditOperations - 1;
237 size_t next_operation_index_to_insert_ = 0;
238 size_t max_edit_operations_ = kMaxEditOperations;
240 bool has_character_limit_ =
false;
241 bool is_comb_text_ =
false;
242 bool is_dirty_ =
false;
243 bool validation_enabled_ =
false;
244 bool is_multiline_ =
false;
245 bool is_linewrap_enabled_ =
false;
246 bool limit_horizontal_area_ =
false;
247 bool limit_vertical_area_ =
false;
248 bool password_mode_ =
false;
249 wchar_t password_alias_ = L'*';
250 bool has_selection_ =
false;
251 Selection selection_{0, 0};
WordBreakProperty FX_GetWordBreakProperty(wchar_t wcCodePoint)
bool FX_CheckStateChangeForWordBreak(WordBreakProperty from, WordBreakProperty to)
@ CFX_TxtLineAlignment_Right
@ CFX_TxtLineAlignment_Center
@ CFX_TxtLineAlignment_Left
#define FX_TXTCHARSTYLE_OddBidiLevel
bool CFX_BreakTypeNoneOrPiece(CFGAS_Char::BreakType type)
virtual void OnCaretChanged()=0
virtual bool OnValidate(const WideString &wsText)=0
virtual ~Delegate()=default
virtual void OnSelChanged()=0
virtual void OnTextWillChange(TextChange *change)=0
virtual void SetScrollOffset(float fScrollOffset)=0
virtual void OnTextChanged()=0
virtual void NotifyTextFull()=0
bool IsEOF(bool bPrev) const
Iterator(const CFDE_TextEditEngine *engine)
void SetAt(size_t nIndex)
size_t FindNextBreakPos(bool bPrev)
virtual void Undo() const =0
virtual void Redo() const =0
virtual ~Operation()=default
void SetAlignment(uint32_t alignment)
void SetCombText(bool enable)
size_t GetIndexAtStartOfLine(size_t pos) const
void Insert(size_t idx, const WideString &text, RecordOperation add_operation=RecordOperation::kInsertRecord)
std::pair< size_t, size_t > BoundsForWordAt(size_t idx) const
void SetAvailableWidth(size_t width)
void EnablePasswordMode(bool val)
WideString GetSelectedText() const
WideString GetText() const
size_t GetIndexAtEndOfLine(size_t pos) const
size_t GetIndexLeft(size_t pos) const
size_t GetIndexRight(size_t pos) const
void EnableValidation(bool val)
WideString Delete(size_t start_idx, size_t length, RecordOperation add_operation=RecordOperation::kInsertRecord)
~CFDE_TextEditEngine() override
void SetDelegate(Delegate *delegate)
void ClearOperationRecords()
std::pair< int32_t, CFX_RectF > GetCharacterInfo(int32_t start_idx)
void SetVisibleLineCount(size_t lines)
void SetFontSize(float size)
size_t GetIndexDown(size_t pos) const
void LimitHorizontalScroll(bool val)
void EnableLineWrap(bool val)
size_t GetIndexForPoint(const CFX_PointF &point)
FX_ARGB GetFontColor() const
void SetSelection(size_t start_idx, size_t count)
void SetFont(RetainPtr< CFGAS_GEFont > font)
void LimitVerticalScroll(bool val)
void SetHasCharacterLimit(bool limit)
std::vector< CFX_RectF > GetCharacterRectsInRange(int32_t start_idx, int32_t count)
int32_t GetWidthOfChar(size_t idx) override
void EnableMultiLine(bool val)
bool CanGenerateCharacterInfo() const
const std::vector< FDE_TEXTEDITPIECE > & GetTextPieces()
std::pair< size_t, size_t > GetSelection() const
std::vector< TextCharPos > GetDisplayPos(const FDE_TEXTEDITPIECE &info)
void SetCharacterLimit(size_t limit)
void SetAliasChar(wchar_t alias)
RetainPtr< CFGAS_GEFont > GetFont() const
wchar_t GetChar(size_t idx) const override
bool HasSelection() const
size_t GetIndexUp(size_t pos) const
float GetFontSize() const
void SetTabWidth(float width)
void SetMaxEditOperationsForTesting(size_t max)
void ReplaceSelectedText(const WideString &str)
WideString DeleteSelectedText(RecordOperation add_operation=RecordOperation::kInsertRecord)
CFX_RectF GetContentsBoundingBox()
void SetLineSpace(float space)
float GetLineSpace() const
void SetFontColor(FX_ARGB color)
int32_t GetCharCount() const
int32_t GetStartPos() const
uint32_t GetCharStyles() const
int32_t GetBidiLevel() const
void Offset(float dx, float dy)
constexpr CFX_RectF()=default
CFX_RectF & operator=(const CFX_RectF &other)=default
void Union(const CFX_RectF &rt)
WideString & operator+=(const WideString &str)
WideString & operator=(WideString &&that) noexcept
FDE_TEXTEDITPIECE(const FDE_TEXTEDITPIECE &that)