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); 61 void updateHandleScale(float handleScale); 62 public: 63 float m_inverseScale; // inverse scale, x, y used for drawing select path 64 int m_selectX; 65 int m_selectY; 66 private: 67 int m_controlWidth; 68 int m_controlHeight; 69 class FirstCheck; 70 class EdgeCheck; 71 void drawSelectionPointer(SkCanvas* , IntRect* ); 72 void drawSelectionRegion(SkCanvas* , IntRect* ); 73 SkIRect findClosest(FirstCheck& , const SkPicture& , int* base); 74 SkIRect findEdge(const SkPicture& , const SkIRect& area, 75 int x, int y, bool left, int* base); 76 SkIRect findLeft(const SkPicture& picture, const SkIRect& area, 77 int x, int y, int* base); 78 SkIRect findRight(const SkPicture& picture, const SkIRect& area, 79 int x, int y, int* base); 80 static void getSelectionArrow(SkPath* ); 81 void getSelectionCaret(SkPath* ); 82 bool hitCorner(int cx, int cy, int x, int y) const; 83 bool hitStartHandle(int x, int y) const; 84 bool hitEndHandle(int x, int y) const; 85 void setVisibleRect(const IntRect& ); 86 void swapAsNeeded(); 87 SkIPoint m_original; // computed start of extend selection 88 SkIPoint m_startOffset; // difference from global to layer 89 SkIRect m_selStart; 90 SkIRect m_selEnd; 91 SkIRect m_lastStart; 92 SkIRect m_lastEnd; 93 SkIRect m_lastDrawnStart; 94 SkIRect m_lastDrawnEnd; 95 SkIRect m_wordBounds; 96 int m_startBase; 97 int m_endBase; 98 int m_layerId; 99 SkIRect m_visibleRect; // constrains picture computations to visible area 100 SkRegion m_lastSelRegion; 101 SkRegion m_selRegion; // computed from sel start, end 102 SkPicture m_startControl; 103 SkPicture m_endControl; 104 const SkPicture* m_picture; 105 bool m_drawPointer; 106 bool m_extendSelection; // false when trackball is moving pointer 107 bool m_flipped; 108 bool m_hitTopLeft; 109 bool m_startSelection; 110 bool m_wordSelection; 111 bool m_outsideWord; 112 }; 113 114 } 115 116 namespace WebCore { 117 118 void ReverseBidi(UChar* chars, int len); 119 120 } 121 122 #endif 123