cztomczak / cefpython

Python bindings for the Chromium Embedded Framework (CEF)
Other
3.03k stars 470 forks source link

Spell checking support #274

Open cztomczak opened 7 years ago

cztomczak commented 7 years ago

Spell checking was implemented in upstream CEF as part of CEF Issue #137. Spell checking is already working in latest CEF Python v54 / v55. Tested on Linux with hello_world.py using the w3schools textarea example. Works out of the box. The "w3schools.com" word is underscored and when mouse right clicking on it, there appears "Add to dictionary" menu option along with a suggestion word to correct it.

Note that "Add to dictionary" creates "Custom dictionary.txt" file in cwd - needs to be figured out how to configure that.

So basically spell checking works in CEF Python, but there are still API functions that were not yet exposed to CEF Python. This will need additional work, read on further down.

Here are the features of spell checking support:

New command line flags that allow for configuration of spell checking:

There are new methods in CefBrowser class that are related to spell checking. These methods are yet to be exposed to CEF Python:

  ///
  // If a misspelled word is currently selected in an editable node calling
  // this method will replace it with the specified |word|.
  ///
  /*--cef()--*/
  virtual void ReplaceMisspelling(const CefString& word) =0;

  ///
  // Add the specified |word| to the spelling dictionary.
  ///
  /*--cef()--*/
  virtual void AddWordToDictionary(const CefString& word) =0;

There are also new methods in CefContextMenuParams. This object was not yet exposed to CEF Python. There was created Issue #56 ("Support creation and modification of mouse context menu") for that. Currently mouse context menu is configurable using ApplicationSettings.context_menu option. Below is a list of new context menu items and methods in CefContextMenuParams related to spell checking. These may be used to allow for more customization of context menu:

MENU_ID_SPELLCHECK_SUGGESTION_0        = 200,
MENU_ID_SPELLCHECK_SUGGESTION_1        = 201,
MENU_ID_SPELLCHECK_SUGGESTION_2        = 202,
MENU_ID_SPELLCHECK_SUGGESTION_3        = 203,
MENU_ID_SPELLCHECK_SUGGESTION_4        = 204,
MENU_ID_SPELLCHECK_SUGGESTION_LAST     = 204,
MENU_ID_NO_SPELLING_SUGGESTIONS        = 205,
MENU_ID_ADD_TO_DICTIONARY              = 206,

  ///
  // Returns the text of the misspelled word, if any, that the context menu was
  // invoked on.
  ///
  /*--cef()--*/
  virtual CefString GetMisspelledWord() =0;

  ///
  // Returns true if suggestions exist, false otherwise. Fills in |suggestions|
  // from the spell check service for the misspelled word if there is one.
  ///
  /*--cef()--*/
  virtual bool GetDictionarySuggestions(std::vector<CefString>& suggestions) =0;

  ///
  // Returns true if the context menu was invoked on an editable node where
  // spell-check is enabled.
  ///
  /*--cef()--*/
  virtual bool IsSpellCheckEnabled() =0;
cztomczak commented 7 years ago

New API exposed in the Browser object in commit 81a8558:

Keeping this issue Open as it contains useful information such as command line switches to configure spell checking support and thus was labeled as Knowledge Base.