Fix find on web pages with -webkit-user-select: none
authorJinwoo Song <jinwoo7.song@samsung.com>
Mon, 25 Mar 2013 06:55:26 +0000 (15:55 +0900)
committerGerrit Code Review <gerrit2@kim11>
Tue, 26 Mar 2013 07:40:54 +0000 (16:40 +0900)
[Title] Fix find on web pages with -webkit-user-select: none
[Issue#] https://tizendev.org/bugs/browse/N_SE-25811
[Problem] Focus does not change to the matched string on web pages with -webkit-user-select: none
[Cause] frame selection returns NULL on web pages with -webkit-user-select: none and
        current WebKit2 find string algorithm is using the frame selection.
[Solution] Highlight the active matching string using the document's active marker function
           instead of frame selection. For this operation, findString() explictly index
           the current active matching string and scroll to the position.

Change-Id: I498c944c34be3b2c7bd76cd5ad506f7d11cc9b9e

Source/WTF/wtf/Platform.h
Source/WebKit2/WebProcess/WebPage/FindController.cpp
Source/WebKit2/WebProcess/WebPage/FindController.h

index 7613692..cf59bb4 100755 (executable)
@@ -791,6 +791,8 @@ com) : Patch to do not adjust cover rect as fixed pixel size*/
 
 #define ENABLE_TIZEN_SIGNAL_APP_BACK_FORWARD_LIST_CHANGED 1 /* Praveen(praveen.ks@samsung.com) : Add API to signal application for change in back forward list */
 
+#define ENABLE_TIZEN_FIND_STRING 1 /* Jinwoo Song(jinwoo7.song@samsung.com) : Fix the bug to enable searching the web page which has the 'webkit-user-select: none' CSS property and value. */
+
 #endif /* OS(TIZEN) */
 
 /* ==== OS() - underlying operating system; only to be used for mandated low-level services like 
index 405de24..2688357 100644 (file)
@@ -58,6 +58,9 @@ FindController::FindController(WebPage* webPage)
     : m_webPage(webPage)
     , m_findPageOverlay(0)
     , m_isShowingFindIndicator(false)
+#if ENABLE(TIZEN_FIND_STRING)
+    , m_activeMatchIndexInCurrentFrame(0)
+#endif
 {
 }
 
@@ -153,11 +156,66 @@ void FindController::updateFindUIAfterPageScroll(bool found, const String& strin
     }
 }
 
+#if ENABLE(TIZEN_FIND_STRING)
+void FindController::setActiveMatchHighlight(int activeMatchIndex)
+{
+    if (activeMatchIndex >= static_cast<int>(m_findMatches.size()))
+        m_activeMatchIndexInCurrentFrame = 0;
+    else if (activeMatchIndex < 0)
+        m_activeMatchIndexInCurrentFrame = m_findMatches.size() - 1;
+    else
+        m_activeMatchIndexInCurrentFrame = activeMatchIndex;
+
+    Frame* frame = m_findMatches[m_activeMatchIndexInCurrentFrame]->startContainer()->document()->frame();
+    if (!frame)
+        return;
+
+    m_activeMatch = m_findMatches[m_activeMatchIndexInCurrentFrame];
+
+    // Scroll to the position of the active matching text.
+    m_activeMatch->firstNode()->renderer()->scrollRectToVisible(m_activeMatch->boundingBox(),
+        ScrollAlignment::alignCenterIfNeeded, ScrollAlignment::alignCenterIfNeeded);
+
+    frame->document()->markers()->addTextMatchMarker(m_activeMatch.get(), true);
+    frame->document()->markers()->setMarkersActive(m_activeMatch.get(), true);
+}
+#endif
+
 void FindController::findString(const String& string, FindOptions options, unsigned maxMatchCount)
 {
+#if ENABLE(TIZEN_FIND_STRING)
+    m_findMatches.clear();
+    int indexForSelection;
+
+    m_webPage->corePage()->findStringMatchingRanges(string, core(options), maxMatchCount, &m_findMatches, indexForSelection);
+
+    bool found = !m_findMatches.isEmpty();
+
+    // highlight the text matches found.
+    m_webPage->drawingArea()->dispatchAfterEnsuringUpdatedScrollPosition(WTF::bind(&FindController::updateFindUIAfterPageScroll, this, found, string, options, maxMatchCount));
+
+    if (!found) {
+        m_activeMatchIndexInCurrentFrame = -1;
+        return;
+    }
+
+    if (!m_oldString || m_oldString != string) {
+        m_oldString = string;
+        if (options & FindOptionsBackwards)
+            setActiveMatchHighlight(m_findMatches.size() - 1); // Should we use m_lastMatchCount instead of m_findMatches.size()
+        else
+            setActiveMatchHighlight(0);
+    } else {
+        if (options & FindOptionsBackwards)
+            setActiveMatchHighlight(m_activeMatchIndexInCurrentFrame - 1);
+        else
+            setActiveMatchHighlight(m_activeMatchIndexInCurrentFrame + 1);
+    }
+#else
     bool found = m_webPage->corePage()->findString(string, core(options));
 
     m_webPage->drawingArea()->dispatchAfterEnsuringUpdatedScrollPosition(WTF::bind(&FindController::updateFindUIAfterPageScroll, this, found, string, options, maxMatchCount));
+#endif
 }
 
 void FindController::findStringMatches(const String& string, FindOptions options, unsigned maxMatchCount)
index ba5e771..cd78223 100644 (file)
@@ -77,6 +77,9 @@ private:
     bool updateFindIndicator(WebCore::Frame* selectedFrame, bool isShowingOverlay, bool shouldAnimate = true);
 
     void updateFindUIAfterPageScroll(bool found, const String&, FindOptions, unsigned maxMatchCount);
+#if ENABLE(TIZEN_FIND_STRING)
+    void setActiveMatchHighlight(int activeMatchIndex);
+#endif
 
     WebPage* m_webPage;
     PageOverlay* m_findPageOverlay;
@@ -86,6 +89,14 @@ private:
     bool m_isShowingFindIndicator;
     WebCore::IntRect m_findIndicatorRect;
     Vector<RefPtr<WebCore::Range> > m_findMatches;
+
+#if ENABLE(TIZEN_FIND_STRING)
+    String m_oldString;
+    // The range of the active match for the current frame.
+    RefPtr<WebCore::Range> m_activeMatch;
+    // The index of the active match for the current frame.
+    int m_activeMatchIndexInCurrentFrame;
+#endif
 };
 
 } // namespace WebKit