1 // Copyright 2021 Google LLC. 2 #ifndef Selection_DEFINED 3 #define Selection_DEFINED 4 #include <sstream> 5 #include "experimental/sktext/editor/Defaults.h" 6 #include "experimental/sktext/include/Text.h" 7 #include "experimental/sktext/include/Types.h" 8 #include "experimental/sktext/src/Paint.h" 9 #include "include/core/SkCanvas.h" 10 #include "include/core/SkSurface.h" 11 #include "include/core/SkTime.h" 12 #include "tools/sk_app/Application.h" 13 #include "tools/sk_app/Window.h" 14 #include "tools/skui/ModifierKey.h" 15 16 namespace skia { 17 namespace editor { 18 19 using namespace skia::text; 20 21 class Selection { 22 public: Selection(SkColor color)23 Selection(SkColor color) : fTextRanges(), fGlyphRanges(), fGlyphBoxes() { 24 fBackground.setColor(color); 25 fBackground.setAlphaf(0.3f); 26 } 27 28 void select(TextRange range, SkRect rect); 29 clear()30 void clear() { 31 fGlyphBoxes.clear(); 32 fTextRanges.clear(); 33 } 34 isEmpty()35 bool isEmpty() const { return fTextRanges.empty(); } count()36 size_t count() const { return fTextRanges.size(); } selected(size_t index)37 DecoratedBlock selected(size_t index) const { return DecoratedBlock(fTextRanges[index].width(), fForeground, fBackground); } 38 39 void paint(SkCanvas* canvas, SkPoint xy); 40 41 private: 42 friend class EditableText; 43 SkPaint fForeground; 44 SkPaint fBackground; 45 std::vector<TextRange> fTextRanges; 46 std::vector<GlyphRange> fGlyphRanges; 47 std::vector<SkRect> fGlyphBoxes; 48 }; 49 50 } // namespace editor 51 } // namespace skia 52 #endif // Selection_DEFINED 53