Home | History | Annotate | Download | only in nav
      1 /*
      2  * Copyright 2007, 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 CachedRoot_h
     27 #define CachedRoot_h
     28 
     29 #include "CachedFrame.h"
     30 #include "IntRect.h"
     31 #include "SkPicture.h"
     32 #include "SkRegion.h"
     33 #include "wtf/Vector.h"
     34 
     35 class SkRect;
     36 
     37 namespace WebCore {
     38     class LayerAndroid;
     39 }
     40 
     41 namespace android {
     42 
     43 class CachedHistory;
     44 class CachedNode;
     45 class FindCanvas;
     46 
     47 class CachedRoot : public CachedFrame {
     48 public:
     49     bool adjustForScroll(BestData* , Direction , WebCore::IntPoint* scrollPtr,
     50         bool findClosest);
     51     const SkRegion& baseUncovered() const { return mBaseUncovered; }
     52     void calcBitBounds(const IntRect& , IntRect* ) const;
     53     int checkForCenter(int x, int y) const;
     54     void checkForJiggle(int* ) const;
     55     bool checkRings(SkPicture* , const CachedNode* ,
     56         const WebCore::IntRect& testBounds) const;
     57     WebCore::IntPoint cursorLocation() const;
     58     int documentHeight() { return mContents.height(); }
     59     int documentWidth() { return mContents.width(); }
     60     void draw(FindCanvas& ) const;
     61     const CachedNode* findAt(const WebCore::IntRect& , const CachedFrame** ,
     62         int* x, int* y, bool checkForHidden) const;
     63     const WebCore::IntRect& focusBounds() const { return mFocusBounds; }
     64     WebCore::IntPoint focusLocation() const;
     65     int getAndResetSelectionEnd();
     66     int getAndResetSelectionStart();
     67     int getBlockLeftEdge(int x, int y, float scale) const;
     68     void getSimulatedMousePosition(WebCore::IntPoint* ) const;
     69     void init(WebCore::Frame* , CachedHistory* );
     70     bool innerDown(const CachedNode* , BestData* ) const;
     71     bool innerLeft(const CachedNode* , BestData* ) const;
     72     void innerMove(const CachedNode* ,BestData* bestData, Direction ,
     73         WebCore::IntPoint* scroll, bool firstCall);
     74     bool innerRight(const CachedNode* , BestData* ) const;
     75     bool innerUp(const CachedNode* , BestData* ) const;
     76     WTF::String imageURI(int x, int y) const;
     77     bool maskIfHidden(BestData* ) const;
     78     const CachedNode* moveCursor(Direction , const CachedFrame** , WebCore::IntPoint* scroll);
     79     /**
     80      * Find the next textfield/textarea
     81      * @param start         The textfield/textarea to search from.
     82      * @param framePtr      If non-zero, returns CachedFrame* containing result.
     83      * @return CachedNode*  Next textfield/textarea or null (0) if none.
     84      */
     85     const CachedNode* nextTextField(const CachedNode* start,
     86         const CachedFrame** framePtr) const;
     87     SkPicture* pictureAt(int* xPtr, int* yPtr, int* id) const;
     88     SkPicture* pictureAt(int* xPtr, int* yPtr) const {
     89         return pictureAt(xPtr, yPtr, 0); }
     90     void reset();
     91     CachedHistory* rootHistory() const { return mHistory; }
     92     WebCore::LayerAndroid* rootLayer() const { return mRootLayer; }
     93     bool scrollDelta(WebCore::IntRect& cursorRingBounds, Direction , int* delta);
     94     const WebCore::IntRect& scrolledBounds() const { return mScrolledBounds; }
     95     void setCursor(CachedFrame* , CachedNode* );
     96     void setCursorCache(int scrollX, int scrollY) const; // compute cached state used to find next cursor
     97     void setCachedFocus(CachedFrame* , CachedNode* );
     98     void setFocusBounds(const WebCore::IntRect& r) { mFocusBounds = r; }
     99     void setTextGeneration(int textGeneration) { mTextGeneration = textGeneration; }
    100     void setMaxScroll(int x, int y) { mMaxXScroll = x; mMaxYScroll = y; }
    101     void setPicture(SkPicture* picture) { mPicture = picture; }
    102     void setRootLayer(WebCore::LayerAndroid* layer) {
    103         mRootLayer = layer;
    104         resetLayers();
    105     }
    106     void setScrollOnly(bool state) { mScrollOnly = state; }
    107     void setSelection(int start, int end) { mSelectionStart = start; mSelectionEnd = end; }
    108     void setupScrolledBounds() const { mScrolledBounds = mViewBounds; }
    109     void setVisibleRect(const WebCore::IntRect& r) { mViewBounds = r; }
    110     int textGeneration() const { return mTextGeneration; }
    111     int width() const { return mPicture ? mPicture->width() : 0; }
    112 private:
    113     friend class CachedFrame;
    114     CachedHistory* mHistory;
    115     SkPicture* mPicture;
    116     WebCore::LayerAndroid* mRootLayer;
    117     WebCore::IntRect mFocusBounds; // dom text input focus node bounds
    118     mutable WebCore::IntRect mScrolledBounds; // view bounds + amount visible as result of scroll
    119     int mTextGeneration;
    120     int mMaxXScroll;
    121     int mMaxYScroll;
    122     // These two are ONLY used when the tree is rebuilt and the focus is a textfield/area
    123     int mSelectionStart;
    124     int mSelectionEnd;
    125     // these four set up as cache for use by frameDown/Up/Left/Right etc
    126     mutable WebCore::IntRect mCursorBounds;
    127     mutable const CachedNode* mCursor;
    128     mutable SkRegion mBaseUncovered;
    129     bool mScrollOnly;
    130 #if DUMP_NAV_CACHE
    131 public:
    132     class Debug {
    133 public:
    134         CachedRoot* base() const;
    135         void print() const;
    136     } mDebug;
    137 #endif
    138 };
    139 
    140 }
    141 
    142 #endif
    143