unit uCEFTextfield; {$IFDEF FPC} {$MODE OBJFPC}{$H+} {$ENDIF} {$I cef.inc} {$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF} {$MINENUMSIZE 4} interface uses {$IFDEF DELPHI16_UP} System.Classes, System.SysUtils, {$ELSE} Classes, SysUtils, {$ENDIF} uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes, uCEFView; type /// /// A Textfield supports editing of text. This control is custom rendered with /// no platform-specific code. Methods must be called on the browser process UI /// thread unless otherwise indicated. /// /// /// CEF source file: /include/capi/views/cef_textfield_capi.h (cef_textfield_t) /// TCefTextfieldRef = class(TCefViewRef, ICefTextfield) protected /// /// Sets whether the text will be displayed as asterisks. /// procedure SetPasswordInput(password_input: boolean); /// /// Returns true (1) if the text will be displayed as asterisks. /// function IsPasswordInput : boolean; /// /// Sets whether the text will read-only. /// procedure SetReadOnly(read_only: boolean); /// /// Returns true (1) if the text is read-only. /// function IsReadOnly : boolean; /// /// Returns the currently displayed text. /// function GetText : ustring; /// /// Sets the contents to |text|. The cursor will be moved to end of the text /// if the current position is outside of the text range. /// procedure SetText(const text_: ustring); /// /// Appends |text| to the previously-existing text. /// procedure AppendText(const text_: ustring); /// /// Inserts |text| at the current cursor position replacing any selected text. /// procedure InsertOrReplaceText(const text_: ustring); /// /// Returns true (1) if there is any selected text. /// function HasSelection : boolean; /// /// Returns the currently selected text. /// function GetSelectedText : ustring; /// /// Selects all text. If |reversed| is true (1) the range will end at the /// logical beginning of the text; this generally shows the leading portion of /// text that overflows its display area. /// procedure SelectAll(reversed: boolean); /// /// Clears the text selection and sets the caret to the end. /// procedure ClearSelection; /// /// Returns the selected logical text range. /// function GetSelectedRange : TCefRange; /// /// Selects the specified logical text range. /// procedure SelectRange(const range: TCefRange); /// /// Returns the current cursor position. /// function GetCursorPosition : NativeUInt; /// /// Sets the text color. /// procedure SetTextColor(color: TCefColor); /// /// Returns the text color. /// function GetTextColor : TCefColor; /// /// Sets the selection text color. /// procedure SetSelectionTextColor(color: TCefColor); /// /// Returns the selection text color. /// function GetSelectionTextColor : TCefColor; /// /// Sets the selection background color. /// procedure SetSelectionBackgroundColor(color: TCefColor); /// /// Returns the selection background color. /// function GetSelectionBackgroundColor : TCefColor; /// /// Sets the font list. The format is ",[STYLES] ", /// where: /// - FONT_FAMILY_LIST is a comma-separated list of font family names, /// - STYLES is an optional space-separated list of style names (case-sensitive /// "Bold" and "Italic" are supported), and /// - SIZE is an integer font size in pixels with the suffix "px". /// /// Here are examples of valid font description strings: /// - "Arial, Helvetica, Bold Italic 14px" /// - "Arial, 14px" /// procedure SetFontList(const font_list: ustring); /// /// Applies |color| to the specified |range| without changing the default /// color. If |range| is NULL the color will be set on the complete text /// contents. /// procedure ApplyTextColor(color: TCefColor; const range: TCefRange); /// /// Applies |style| to the specified |range| without changing the default /// style. If |add| is true (1) the style will be added, otherwise the style /// will be removed. If |range| is NULL the style will be set on the complete /// text contents. /// procedure ApplyTextStyle(style: TCefTextStyle; add: boolean; const range: TCefRange); /// /// Returns true (1) if the action associated with the specified command id is /// enabled. See additional comments on execute_command(). /// function IsCommandEnabled(command_id: TCefTextFieldCommands): boolean; /// /// Performs the action associated with the specified command id. /// procedure ExecuteCommand(command_id: TCefTextFieldCommands); /// /// Clears Edit history. /// procedure ClearEditHistory; /// /// Sets the placeholder text that will be displayed when the Textfield is /// NULL. /// procedure SetPlaceholderText(const text_: ustring); /// /// Returns the placeholder text that will be displayed when the Textfield is /// NULL. /// function GetPlaceholderText : ustring; /// /// Sets the placeholder text color. /// procedure SetPlaceholderTextColor(color: TCefColor); /// /// Set the accessible name that will be exposed to assistive technology (AT). /// procedure SetAccessibleName(const name: ustring); public /// /// Returns a ICefTextfield instance using a PCefTextfield data pointer. /// class function UnWrap(data: Pointer): ICefTextfield; /// /// Create a new Textfield. /// class function CreateTextField(const delegate: ICefTextfieldDelegate): ICefTextfield; end; implementation uses uCEFLibFunctions, uCEFMiscFunctions; procedure TCefTextfieldRef.SetPasswordInput(password_input: boolean); begin PCefTextfield(FData)^.set_password_input(PCefTextfield(FData), ord(password_input)); end; function TCefTextfieldRef.IsPasswordInput : boolean; begin Result := (PCefTextfield(FData)^.is_password_input(PCefTextfield(FData)) <> 0); end; procedure TCefTextfieldRef.SetReadOnly(read_only: boolean); begin PCefTextfield(FData)^.set_read_only(PCefTextfield(FData), ord(read_only)); end; function TCefTextfieldRef.IsReadOnly : boolean; begin Result := (PCefTextfield(FData)^.is_read_only(PCefTextfield(FData)) <> 0); end; function TCefTextfieldRef.GetText : ustring; begin Result := CefStringFreeAndGet(PCefTextfield(FData)^.get_text(PCefTextfield(FData))); end; procedure TCefTextfieldRef.SetText(const text_: ustring); var TempText : TCefString; begin TempText := CefString(text_); PCefTextfield(FData)^.set_text(PCefTextfield(FData), @TempText); end; procedure TCefTextfieldRef.AppendText(const text_: ustring); var TempText : TCefString; begin TempText := CefString(text_); PCefTextfield(FData)^.append_text(PCefTextfield(FData), @TempText); end; procedure TCefTextfieldRef.InsertOrReplaceText(const text_: ustring); var TempText : TCefString; begin TempText := CefString(text_); PCefTextfield(FData)^.insert_or_replace_text(PCefTextfield(FData), @TempText); end; function TCefTextfieldRef.HasSelection : boolean; begin Result := (PCefTextfield(FData)^.has_selection(PCefTextfield(FData)) <> 0); end; function TCefTextfieldRef.GetSelectedText : ustring; begin Result := CefStringFreeAndGet(PCefTextfield(FData)^.get_selected_text(PCefTextfield(FData))); end; procedure TCefTextfieldRef.SelectAll(reversed: boolean); begin PCefTextfield(FData)^.select_all(PCefTextfield(FData), ord(reversed)); end; procedure TCefTextfieldRef.ClearSelection; begin PCefTextfield(FData)^.clear_selection(PCefTextfield(FData)); end; function TCefTextfieldRef.GetSelectedRange : TCefRange; begin Result := PCefTextfield(FData)^.get_selected_range(PCefTextfield(FData)); end; procedure TCefTextfieldRef.SelectRange(const range: TCefRange); begin PCefTextfield(FData)^.select_range(PCefTextfield(FData), @range); end; function TCefTextfieldRef.GetCursorPosition : NativeUInt; begin Result := PCefTextfield(FData)^.get_cursor_position(PCefTextfield(FData)); end; procedure TCefTextfieldRef.SetTextColor(color: TCefColor); begin PCefTextfield(FData)^.set_text_color(PCefTextfield(FData), color); end; function TCefTextfieldRef.GetTextColor : TCefColor; begin Result := PCefTextfield(FData)^.get_text_color(PCefTextfield(FData)); end; procedure TCefTextfieldRef.SetSelectionTextColor(color: TCefColor); begin PCefTextfield(FData)^.set_selection_text_color(PCefTextfield(FData), color); end; function TCefTextfieldRef.GetSelectionTextColor : TCefColor; begin Result := PCefTextfield(FData)^.get_selection_text_color(PCefTextfield(FData)); end; procedure TCefTextfieldRef.SetSelectionBackgroundColor(color: TCefColor); begin PCefTextfield(FData)^.set_selection_background_color(PCefTextfield(FData), color); end; function TCefTextfieldRef.GetSelectionBackgroundColor : TCefColor; begin Result := PCefTextfield(FData)^.get_selection_background_color(PCefTextfield(FData)); end; procedure TCefTextfieldRef.SetFontList(const font_list: ustring); var TempFontList : TCefString; begin TempFontList := CefString(font_list); PCefTextfield(FData)^.set_font_list(PCefTextfield(FData), @TempFontList); end; procedure TCefTextfieldRef.ApplyTextColor(color: TCefColor; const range: TCefRange); begin PCefTextfield(FData)^.apply_text_color(PCefTextfield(FData), color, @range); end; procedure TCefTextfieldRef.ApplyTextStyle(style: TCefTextStyle; add: boolean; const range: TCefRange); begin PCefTextfield(FData)^.apply_text_style(PCefTextfield(FData), style, ord(add), @range); end; function TCefTextfieldRef.IsCommandEnabled(command_id: TCefTextFieldCommands): boolean; begin Result := (PCefTextfield(FData)^.is_command_enabled(PCefTextfield(FData), command_id) <> 0); end; procedure TCefTextfieldRef.ExecuteCommand(command_id: TCefTextFieldCommands); begin PCefTextfield(FData)^.execute_command(PCefTextfield(FData), command_id); end; procedure TCefTextfieldRef.ClearEditHistory; begin PCefTextfield(FData)^.clear_edit_history(PCefTextfield(FData)); end; procedure TCefTextfieldRef.SetPlaceholderText(const text_: ustring); var TempText : TCefString; begin TempText := CefString(text_); PCefTextfield(FData)^.set_placeholder_text(PCefTextfield(FData), @TempText); end; function TCefTextfieldRef.GetPlaceholderText : ustring; begin Result := CefStringFreeAndGet(PCefTextfield(FData)^.get_placeholder_text(PCefTextfield(FData))); end; procedure TCefTextfieldRef.SetPlaceholderTextColor(color: TCefColor); begin PCefTextfield(FData)^.set_placeholder_text_color(PCefTextfield(FData), color); end; procedure TCefTextfieldRef.SetAccessibleName(const name: ustring); var TempName : TCefString; begin TempName := CefString(name); PCefTextfield(FData)^.set_accessible_name(PCefTextfield(FData), @TempName); end; class function TCefTextfieldRef.UnWrap(data: Pointer): ICefTextfield; begin if (data <> nil) then Result := Create(data) as ICefTextfield else Result := nil; end; class function TCefTextfieldRef.CreateTextField(const delegate: ICefTextfieldDelegate): ICefTextfield; var TempTextfield : PCefTextfield; begin Result := nil; if (delegate <> nil) then begin TempTextfield := cef_textfield_create(CefGetData(delegate)); if (TempTextfield <> nil) then Result := Create(TempTextfield) as ICefTextfield; end; end; end.