OSDN Git Service

Merge "do a better job of finding closest selectable text"
authorCary Clark <cary@android.com>
Fri, 19 Nov 2010 17:19:21 +0000 (09:19 -0800)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Fri, 19 Nov 2010 17:19:21 +0000 (09:19 -0800)
WebKit/android/nav/CacheBuilder.cpp
WebKit/android/nav/CachedFrame.cpp
WebKit/android/nav/CachedFrame.h
WebKit/android/nav/FindCanvas.cpp
WebKit/android/nav/FindCanvas.h

index 22b449a..47c7c70 100644 (file)
@@ -1493,8 +1493,14 @@ bool CacheBuilder::CleanUpContainedNodes(CachedRoot* cachedRoot,
     if (onlyChildCached->parent() == lastCached)
         onlyChildCached->setParentIndex(lastCached->parentIndex());
     bool hasFocus = lastCached->isFocus() || onlyChildCached->isFocus();
-    if (outerIsMouseMoveOnly || onlyChild->isKeyboardFocusable(NULL))
+    if (outerIsMouseMoveOnly || onlyChild->isKeyboardFocusable(NULL)) {
+        int index = lastCached->index();
         *lastCached = *onlyChildCached;
+        lastCached->setIndex(index);
+        CachedFrame* frame = cachedFrame->hasFrame(lastCached);
+        if (frame)
+            frame->setIndexInParent(index);
+    }
     cachedFrame->removeLast();
     if (hasFocus)
         cachedRoot->setCachedFocus(cachedFrame, cachedFrame->lastNode());
index 8f0df7a..4f9ec06 100644 (file)
@@ -918,7 +918,7 @@ const CachedNode* CachedFrame::frameUp(const CachedNode* test,
     return bestData->mNode;
 }
 
-const CachedFrame* CachedFrame::hasFrame(const CachedNode* node) const
+CachedFrame* CachedFrame::hasFrame(const CachedNode* node)
 {
     return node->isFrame() ? &mCachedFrames[node->childFrameIndex()] : NULL;
 }
index fdee849..8ca73cf 100644 (file)
@@ -112,7 +112,10 @@ public:
     void* framePointer() const { return mFrame; }
     CachedNode* getIndex(int index) { return index >= 0 ?
         &mCachedNodes[index] : NULL; }
-    const CachedFrame* hasFrame(const CachedNode* node) const;
+    const CachedFrame* hasFrame(const CachedNode* node) const {
+        return const_cast<CachedFrame*>(this)->hasFrame(node);
+    }
+    CachedFrame* hasFrame(const CachedNode* node);
     void hideCursor();
     int indexInParent() const { return mIndexInParent; }
     void init(const CachedRoot* root, int index, WebCore::Frame* frame);
@@ -143,6 +146,7 @@ public:
     void setData();
     bool setFocus(WebCore::Frame* , WebCore::Node* , int x, int y);
     void setFocusIndex(int index) { mFocusIndex = index; }
+    void setIndexInParent(int index) { mIndexInParent = index; }
     void setLocalViewBounds(const WebCore::IntRect& bounds) { mLocalViewBounds = bounds; }
     int size() { return mCachedNodes.size(); }
     const CachedInput* textInput(const CachedNode* node) const {
index d60fffd..9f59877 100644 (file)
 #include "FindCanvas.h"
 #include "LayerAndroid.h"
 #include "IntRect.h"
+#include "SelectText.h"
 #include "SkBlurMaskFilter.h"
 #include "SkCornerPathEffect.h"
 #include "SkRect.h"
+#include "SkUtils.h"
 
 #include <utils/Log.h>
 
@@ -125,6 +127,27 @@ FindCanvas::FindCanvas(int width, int height, const UChar* lower,
         , mUpperText(upper)
         , mLength(byteLength)
         , mNumFound(0) {
+    // the text has been provided in read order. Reverse as needed so the
+    // result contains left-to-right characters.
+    const uint16_t* start = mLowerText;
+    size_t count = byteLength >> 1;
+    const uint16_t* end = mLowerText + count;
+    while (start < end) {
+        SkUnichar ch = SkUTF16_NextUnichar(&start);
+        WTF::Unicode::Direction charDirection = WTF::Unicode::direction(ch);
+        if (WTF::Unicode::RightToLeftArabic == charDirection
+                || WTF::Unicode::RightToLeft == charDirection) {
+            mLowerReversed.clear();
+            mLowerReversed.append(mLowerText, count);
+            WebCore::ReverseBidi(mLowerReversed.begin(), count);
+            mLowerText = mLowerReversed.begin();
+            mUpperReversed.clear();
+            mUpperReversed.append(mUpperText, count);
+            WebCore::ReverseBidi(mUpperReversed.begin(), count);
+            mUpperText = mUpperReversed.begin();
+            break;
+        }
+    }
 
     setBounder(&mBounder);
     mOutset = -SkIntToScalar(INTEGER_OUTSET);
index 2aba8e0..cbebfae 100644 (file)
@@ -198,6 +198,8 @@ private:
     WTF::Vector<MatchInfo>* mMatches;
     const UChar*            mLowerText;
     const UChar*            mUpperText;
+    Vector<UChar>           mLowerReversed;
+    Vector<UChar>           mUpperReversed;
     size_t                  mLength;
     FindBounder             mBounder;
     int                     mNumFound;