1 // Copyright 2021 Google LLC. 2 #ifndef Editor_DEFINED 3 #define Editor_DEFINED 4 #include <sstream> 5 #include "experimental/sktext/editor/Cursor.h" 6 #include "experimental/sktext/editor/Defaults.h" 7 #include "experimental/sktext/editor/Mouse.h" 8 #include "experimental/sktext/editor/Selection.h" 9 #include "experimental/sktext/editor/Texts.h" 10 #include "experimental/sktext/include/Text.h" 11 #include "experimental/sktext/include/Types.h" 12 #include "experimental/sktext/src/Paint.h" 13 #include "include/core/SkCanvas.h" 14 #include "include/core/SkSurface.h" 15 #include "include/core/SkTime.h" 16 #include "tools/sk_app/Application.h" 17 #include "tools/sk_app/Window.h" 18 #include "tools/skui/ModifierKey.h" 19 20 namespace skia { 21 namespace editor { 22 23 using namespace skia::text; 24 25 class Editor : public sk_app::Window::Layer { 26 public: 27 static std::unique_ptr<Editor> Make(std::u16string text, SkSize size); 28 static std::unique_ptr<Editor> MakeDemo(SkScalar width, SkScalar height); 29 30 Editor(std::u16string text, SkSize size); 31 ~Editor() override = default; 32 33 void paint(SkCanvas* canvas); blink()34 void blink() { fCursor->blink(); } 35 void onResize(int width, int height) override; 36 private: 37 38 void update(); 39 onAttach(sk_app::Window * w)40 void onAttach(sk_app::Window* w) override { fParent = w; } 41 void onPaint(SkSurface* surface) override; 42 43 bool onMouse(int x, int y, skui::InputState state, skui::ModifierKey modifiers) override; 44 bool onKey(skui::Key, skui::InputState, skui::ModifierKey) override; 45 bool onChar(SkUnichar c, skui::ModifierKey modifier) override; invalidate()46 void invalidate() { if (fParent) { fParent->inval(); } } 47 48 bool moveCursor(skui::Key key); 49 bool insertCodepoint(SkUnichar unichar); 50 bool deleteElement(skui::Key key); 51 52 std::unique_ptr<EditableText> fEditableText; 53 std::unique_ptr<DynamicText> fStatus; 54 55 std::unique_ptr<Cursor> fCursor; 56 std::unique_ptr<Mouse> fMouse; 57 58 sk_app::Window* fParent; 59 int fWidth; 60 int fHeight; 61 62 PositionType fDefaultPositionType; 63 bool fInsertMode; 64 }; 65 66 } // namespace editor 67 } // namespace skia 68 #endif // Editor_DEFINED 69