1 /* 2 * Copyright 2008, The Android Open Source Project 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef SelectText_h 27 #define SelectText_h 28 29 #include "DrawExtra.h" 30 #include "IntPoint.h" 31 #include "IntRect.h" 32 #include "PlatformString.h" 33 #include "SkPath.h" 34 #include "SkPicture.h" 35 #include "SkRect.h" 36 #include "SkRegion.h" 37 38 namespace android { 39 40 class CachedRoot; 41 42 class SelectText : public DrawExtra { 43 public: 44 SelectText(); 45 virtual ~SelectText(); 46 virtual void draw(SkCanvas* , LayerAndroid* , IntRect* ); 47 void extendSelection(const IntRect& vis, int x, int y); 48 const String getSelection(); 49 bool hitSelection(int x, int y) const; 50 void moveSelection(const IntRect& vis, int x, int y); 51 void reset(); 52 IntPoint selectableText(const CachedRoot* ); 53 void selectAll(); 54 int selectionX() const; 55 int selectionY() const; 56 void setDrawPointer(bool drawPointer) { m_drawPointer = drawPointer; } 57 void setExtendSelection(bool extend) { m_extendSelection = extend; } 58 bool startSelection(const CachedRoot* , const IntRect& vis, int x, int y); 59 bool wordSelection(const CachedRoot* , const IntRect& vis, int x, int y); 60 void getSelectionRegion(const IntRect& vis, SkRegion *region, LayerAndroid* root); 61 void updateHandleScale(float handleScale); 62 void getSelectionHandles(int* handles, LayerAndroid* root); 63 public: 64 float m_inverseScale; // inverse scale, x, y used for drawing select path 65 int m_selectX; 66 int m_selectY; 67 private: 68 int m_controlWidth; 69 int m_controlHeight; 70 int m_controlSlop; 71 class FirstCheck; 72 class EdgeCheck; 73 void drawSelectionPointer(SkCanvas* , IntRect* ); 74 void drawSelectionRegion(SkCanvas* , IntRect* ); 75 SkIRect findClosest(FirstCheck& , const SkPicture& , int* base); 76 SkIRect findEdge(const SkPicture& , const SkIRect& area, 77 int x, int y, bool left, int* base); 78 SkIRect findLeft(const SkPicture& picture, const SkIRect& area, 79 int x, int y, int* base); 80 SkIRect findRight(const SkPicture& picture, const SkIRect& area, 81 int x, int y, int* base); 82 static void getSelectionArrow(SkPath* ); 83 void getSelectionCaret(SkPath* ); 84 bool hitCorner(int cx, int cy, int x, int y) const; 85 bool hitStartHandle(int x, int y) const; 86 bool hitEndHandle(int x, int y) const; 87 void setVisibleRect(const IntRect& ); 88 void swapAsNeeded(); 89 SkIPoint m_original; // computed start of extend selection 90 SkIPoint m_startOffset; // difference from global to layer 91 SkIRect m_selStart; 92 SkIRect m_selEnd; 93 SkIRect m_lastStart; 94 SkIRect m_lastEnd; 95 SkIRect m_lastDrawnStart; 96 SkIRect m_lastDrawnEnd; 97 SkIRect m_wordBounds; 98 int m_startBase; 99 int m_endBase; 100 int m_layerId; 101 SkIRect m_visibleRect; // constrains picture computations to visible area 102 SkRegion m_lastSelRegion; 103 SkRegion m_selRegion; // computed from sel start, end 104 SkPicture m_startControl; 105 SkPicture m_endControl; 106 const SkPicture* m_picture; 107 bool m_drawPointer; 108 bool m_extendSelection; // false when trackball is moving pointer 109 bool m_flipped; 110 bool m_hitTopLeft; 111 bool m_startSelection; 112 bool m_wordSelection; 113 bool m_outsideWord; 114 }; 115 116 } 117 118 namespace WebCore { 119 120 void ReverseBidi(UChar* chars, int len); 121 122 } 123 124 #endif 125