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 CachedHistory_h
     27 #define CachedHistory_h
     28 
     29 #include "CachedFrame.h"
     30 
     31 #define NAVIGATION_VISIT_DEPTH 8    // the number of nodes last visited -- used to detect ping-ponging (number should be tuned)
     32 
     33 namespace android {
     34 
     35 class CachedRoot;
     36 
     37 // CachedHistory is maintained even if DOM is rebuilt by running script.
     38 // It uses blind pointers for comparison in the previously visited nodes.
     39 class CachedHistory {
     40 public:
     41     CachedHistory();
     42     void addToVisited(const CachedNode* , CachedFrame::Direction );
     43     bool checkVisited(const CachedNode* , CachedFrame::Direction ) const;
     44     bool didFirstLayout() const { return mDidFirstLayout; }
     45     bool directionChange() const { return mDirectionChange; }
     46     int minWorkingHorizontal() const { return mMinWorkingHorizontal; }
     47     int minWorkingVertical() const { return mMinWorkingVertical; }
     48     int maxWorkingHorizontal() const { return mMaxWorkingHorizontal; }
     49     int maxWorkingVertical() const { return mMaxWorkingVertical; }
     50     const WebCore::IntRect& navBounds() const { return mNavBounds; }
     51     const WebCore::IntRect& priorBounds() const { return mPriorBounds; }
     52     void setDidFirstLayout(bool did) { mDidFirstLayout = did; }
     53     void setMouseBounds(const WebCore::IntRect& loc) { mMouseBounds = loc; }
     54     void setNavBounds(const WebCore::IntRect& loc) { mNavBounds = loc; }
     55     void setWorking(CachedFrame::Direction , const CachedFrame* ,
     56         const CachedNode* , const WebCore::IntRect& viewBounds);
     57     void reset();
     58 private:
     59     void pinMaxMin(const WebCore::IntRect& viewBounds);
     60     struct Visited {
     61         const CachedNode* mNode;
     62         CachedFrame::Direction mDirection;
     63     } mVisited[NAVIGATION_VISIT_DEPTH];
     64     WebCore::IntRect mMouseBounds; // constricted bounds, if cursor ring is partially visible
     65     WebCore::IntRect mNavBounds; // cursor ring bounds plus optional keystroke movement
     66     WebCore::IntRect mPriorBounds; // prior chosen cursor ring (for reversing narrowing)
     67     bool mDirectionChange;
     68     bool mDidFirstLayout; // set true when page is newly laid out
     69     CachedFrame::Direction mLastMove;
     70     CachedFrame::Direction mPriorMove;
     71     int mMinWorkingHorizontal;
     72     int mMaxWorkingHorizontal;
     73     int mMinWorkingVertical;
     74     int mMaxWorkingVertical;
     75     friend class CachedRoot;
     76 #if DUMP_NAV_CACHE
     77 public:
     78     class Debug {
     79 public:
     80         CachedHistory* base() const;
     81         const char* direction(CachedFrame::Direction d) const;
     82         void print(CachedRoot* ) const;
     83     } mDebug;
     84 #endif
     85 };
     86 
     87 }
     88 
     89 #endif
     90