Title: [124887] trunk/Source/WebKit/blackberry
Revision
124887
Author
mifen...@rim.com
Date
2012-08-07 07:32:15 -0700 (Tue, 07 Aug 2012)

Log Message

[BlackBerry] Update API for spell checking suggestions.
https://bugs.webkit.org/show_bug.cgi?id=93356

Reviewed by Antonio Gomes.

PR 163283.

Add connections for updated spell checking options request API.  Move
all this logic into InputHandler.

Reviewed Internally by Gen Mak and Nima Ghanavatian.

* Api/WebPageClient.h:
* WebKitSupport/InputHandler.cpp:
(BlackBerry::WebKit::InputHandler::shouldRequestSpellCheckingOptionsForPoint):
(WebKit):
(BlackBerry::WebKit::InputHandler::requestSpellingCheckingOptions):
* WebKitSupport/InputHandler.h:
(Platform):
(InputHandler):
* WebKitSupport/TouchEventHandler.cpp:
(BlackBerry::WebKit::TouchEventHandler::handleTouchPoint):
* WebKitSupport/TouchEventHandler.h:
(TouchEventHandler):

Modified Paths

Diff

Modified: trunk/Source/WebKit/blackberry/Api/WebPageClient.h (124886 => 124887)


--- trunk/Source/WebKit/blackberry/Api/WebPageClient.h	2012-08-07 13:52:42 UTC (rev 124886)
+++ trunk/Source/WebKit/blackberry/Api/WebPageClient.h	2012-08-07 14:32:15 UTC (rev 124887)
@@ -26,6 +26,7 @@
 #include <BlackBerryPlatformInputEvents.h>
 #include <BlackBerryPlatformNavigationType.h>
 #include <BlackBerryPlatformPrimitives.h>
+#include <imf/events.h>
 #include <interaction/ScrollViewBase.h>
 #include <vector>
 
@@ -144,7 +145,7 @@
 
     virtual void showVirtualKeyboard(bool) = 0;
 
-    virtual void requestSpellingSuggestionsForString(unsigned start, unsigned end) = 0;
+    virtual void requestSpellingCheckingOptions(const imf_sp_text_t&) = 0;
     virtual int32_t checkSpellingOfStringAsync(wchar_t* text, int length) = 0;
 
     virtual void notifySelectionDetailsChanged(const Platform::IntRect& start, const Platform::IntRect& end, const Platform::IntRectRegion&, bool overrideTouchHandling = false) = 0;

Modified: trunk/Source/WebKit/blackberry/ChangeLog (124886 => 124887)


--- trunk/Source/WebKit/blackberry/ChangeLog	2012-08-07 13:52:42 UTC (rev 124886)
+++ trunk/Source/WebKit/blackberry/ChangeLog	2012-08-07 14:32:15 UTC (rev 124887)
@@ -1,3 +1,30 @@
+2012-08-07  Mike Fenton  <mifen...@rim.com>
+
+        [BlackBerry] Update API for spell checking suggestions.
+        https://bugs.webkit.org/show_bug.cgi?id=93356
+
+        Reviewed by Antonio Gomes.
+
+        PR 163283.
+
+        Add connections for updated spell checking options request API.  Move
+        all this logic into InputHandler.
+
+        Reviewed Internally by Gen Mak and Nima Ghanavatian.
+
+        * Api/WebPageClient.h:
+        * WebKitSupport/InputHandler.cpp:
+        (BlackBerry::WebKit::InputHandler::shouldRequestSpellCheckingOptionsForPoint):
+        (WebKit):
+        (BlackBerry::WebKit::InputHandler::requestSpellingCheckingOptions):
+        * WebKitSupport/InputHandler.h:
+        (Platform):
+        (InputHandler):
+        * WebKitSupport/TouchEventHandler.cpp:
+        (BlackBerry::WebKit::TouchEventHandler::handleTouchPoint):
+        * WebKitSupport/TouchEventHandler.h:
+        (TouchEventHandler):
+
 2012-08-06  Charles Wei  <charles....@torchmobile.com.cn>
 
         [BlackBerry] About: shows PAGE_CACHE not enabled.

Modified: trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp (124886 => 124887)


--- trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp	2012-08-07 13:52:42 UTC (rev 124886)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp	2012-08-07 14:32:15 UTC (rev 124887)
@@ -50,6 +50,7 @@
 #include "RenderText.h"
 #include "RenderTextControl.h"
 #include "RenderWidget.h"
+#include "RenderedDocumentMarker.h"
 #include "ScopePointer.h"
 #include "SelectPopupClient.h"
 #include "SelectionHandler.h"
@@ -64,11 +65,11 @@
 #include <BlackBerryPlatformLog.h>
 #include <BlackBerryPlatformMisc.h>
 #include <BlackBerryPlatformSettings.h>
-#include <imf/events.h>
 #include <sys/keycodes.h>
 
 #define ENABLE_INPUT_LOG 0
 #define ENABLE_FOCUS_LOG 0
+#define ENABLE_SPELLING_LOG 0
 
 static const unsigned MaxLearnTextDataSize = 500;
 
@@ -87,6 +88,12 @@
 #define FocusLog(severity, format, ...)
 #endif // ENABLE_FOCUS_LOG
 
+#if ENABLE_SPELLING_LOG
+#define SpellingLog(severity, format, ...) logAlways(severity, format, ## __VA_ARGS__)
+#else
+#define SpellingLog(severity, format, ...)
+#endif // ENABLE_SPELLING_LOG
+
 namespace BlackBerry {
 namespace WebKit {
 
@@ -648,6 +655,52 @@
     return 0;
 }
 
+bool InputHandler::shouldRequestSpellCheckingOptionsForPoint(Platform::IntPoint& point, const Element* touchedElement, imf_sp_text_t& spellCheckingOptionRequest)
+{
+    if (!isActiveTextEdit() || touchedElement != m_currentFocusElement)
+        return false;
+
+    LayoutPoint contentPos(m_webPage->mapFromViewportToContents(point));
+    contentPos = DOMSupport::convertPointToFrame(m_webPage->mainFrame(), m_webPage->focusedOrMainFrame(), roundedIntPoint(contentPos));
+
+    Document* document = m_currentFocusElement->document();
+    ASSERT(document);
+
+    RenderedDocumentMarker* marker = document->markers()->renderedMarkerContainingPoint(contentPos, DocumentMarker::Spelling);
+    if (!marker)
+        return false;
+
+    SpellingLog(LogLevelInfo, "InputHandler::shouldRequestSpellCheckingOptionsForPoint Found spelling marker at point %d, %d", point.x(), point.y());
+
+    // imf_sp_text_t should be generated in pixel viewport coordinates.
+    WebCore::IntRect rect = m_webPage->mapToTransformed(m_webPage->focusedOrMainFrame()->view()->contentsToWindow(enclosingIntRect(marker->renderedRect())));
+    m_webPage->clipToTransformedContentsRect(rect);
+
+    spellCheckingOptionRequest.text_rect.x = rect.x();
+    spellCheckingOptionRequest.text_rect.y = rect.y();
+    spellCheckingOptionRequest.text_rect.width = rect.width();
+    spellCheckingOptionRequest.text_rect.height = rect.height();
+    spellCheckingOptionRequest.text_rect.anchor_x = point.x();
+    spellCheckingOptionRequest.text_rect.anchor_y = point.y();
+    spellCheckingOptionRequest.startTextPosition = marker->startOffset();
+    spellCheckingOptionRequest.endTextPosition = marker->endOffset();
+
+    return true;
+}
+
+void InputHandler::requestSpellingCheckingOptions(const imf_sp_text_t& spellCheckingOptionRequest)
+{
+    SpellingLog(LogLevelInfo, "InputHandler::requestSpellingCheckingOptions Sending request:\ntext_rect.x = %d\ntext_rect.y = %d" \
+                              "\ntext_rect.width = %d\ntext_rect.height = %d\ntext_rect.anchor_x = %d\ntext_rect.anchor_y = %d" \
+                              "\nstartTextPosition = %d\nendTextPosition = %d", spellCheckingOptionRequest.text_rect.x,
+                              spellCheckingOptionRequest.text_rect.y, spellCheckingOptionRequest.text_rect.width, spellCheckingOptionRequest.text_rect.height,
+                              spellCheckingOptionRequest.text_rect.anchor_x, spellCheckingOptionRequest.text_rect.anchor_y,
+                              spellCheckingOptionRequest.startTextPosition, spellCheckingOptionRequest.endTextPosition);
+
+    if (spellCheckingOptionRequest.startTextPosition || spellCheckingOptionRequest.endTextPosition)
+        m_webPage->m_client->requestSpellingCheckingOptions(spellCheckingOptionRequest);
+}
+
 void InputHandler::setElementUnfocused(bool refocusOccuring)
 {
     if (isActiveTextEdit()) {

Modified: trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h (124886 => 124887)


--- trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h	2012-08-07 13:52:42 UTC (rev 124886)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/InputHandler.h	2012-08-07 14:32:15 UTC (rev 124887)
@@ -21,6 +21,7 @@
 
 #include <BlackBerryPlatformInputEvents.h>
 
+#include <imf/events.h>
 #include <imf/input_data.h>
 #include <map>
 #include <wtf/RefPtr.h>
@@ -44,6 +45,7 @@
 namespace BlackBerry {
 
 namespace Platform {
+class IntPoint;
 class KeyboardEvent;
 }
 
@@ -128,6 +130,9 @@
     void spellCheckingRequestProcessed(int32_t transactionId, spannable_string_t*);
     void spellCheckingRequestCancelled(int32_t id, bool isSequenceId = false);
 
+    bool shouldRequestSpellCheckingOptionsForPoint(Platform::IntPoint&, const WebCore::Element*, imf_sp_text_t&);
+    void requestSpellingCheckingOptions(const imf_sp_text_t&);
+
 private:
     enum PendingKeyboardStateChange { NoChange, Visible, NotVisible };
 

Modified: trunk/Source/WebKit/blackberry/WebKitSupport/TouchEventHandler.cpp (124886 => 124887)


--- trunk/Source/WebKit/blackberry/WebKitSupport/TouchEventHandler.cpp	2012-08-07 13:52:42 UTC (rev 124886)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/TouchEventHandler.cpp	2012-08-07 14:32:15 UTC (rev 124887)
@@ -41,7 +41,6 @@
 #include "RenderLayer.h"
 #include "RenderTheme.h"
 #include "RenderView.h"
-#include "RenderedDocumentMarker.h"
 #include "SelectionHandler.h"
 #include "WebPage_p.h"
 #include "WebTapHighlight.h"
@@ -213,7 +212,12 @@
         }
     case Platform::TouchPoint::TouchReleased:
         {
-            unsigned spellLength = spellCheck(point);
+            imf_sp_text_t spellCheckOptionRequest;
+            bool shouldRequestSpellCheckOptions = false;
+
+            if (m_lastFatFingersResult.isTextInput())
+                shouldRequestSpellCheckOptions = m_webPage->m_inputHandler->shouldRequestSpellCheckingOptionsForPoint(point.m_pos, m_lastFatFingersResult.nodeAsElementIfApplicable(), spellCheckOptionRequest);
+
             // Apply any suppressed changes. This does not eliminate the need
             // for the show after the handling of fat finger pressed as it may
             // have triggered a state change.
@@ -239,11 +243,8 @@
             PlatformMouseEvent mouseEvent(adjustedPoint, m_lastScreenPoint, PlatformEvent::MouseReleased, 1, LeftButton, TouchScreen);
             m_webPage->handleMouseEvent(mouseEvent);
             m_lastFatFingersResult.reset(); // Reset the fat finger result as its no longer valid when a user's finger is not on the screen.
-            if (spellLength) {
-                unsigned end = m_webPage->m_inputHandler->caretPosition();
-                unsigned start = end - spellLength;
-                m_webPage->m_client->requestSpellingSuggestionsForString(start, end);
-            }
+            if (shouldRequestSpellCheckOptions)
+                m_webPage->m_inputHandler->requestSpellingCheckingOptions(spellCheckOptionRequest);
             return true;
         }
     case Platform::TouchPoint::TouchMoved:
@@ -263,31 +264,6 @@
     return false;
 }
 
-unsigned TouchEventHandler::spellCheck(Platform::TouchPoint& touchPoint)
-{
-    Element* elementUnderFatFinger = m_lastFatFingersResult.nodeAsElementIfApplicable();
-    if (!m_lastFatFingersResult.isTextInput() || !elementUnderFatFinger)
-        return 0;
-
-    LayoutPoint contentPos(m_webPage->mapFromViewportToContents(touchPoint.m_pos));
-    contentPos = DOMSupport::convertPointToFrame(m_webPage->mainFrame(), m_webPage->focusedOrMainFrame(), contentPos);
-
-    Document* document = elementUnderFatFinger->document();
-    ASSERT(document);
-    RenderedDocumentMarker* marker = document->markers()->renderedMarkerContainingPoint(contentPos, DocumentMarker::Spelling);
-    if (!marker)
-        return 0;
-
-    IntRect rect = marker->renderedRect();
-    LayoutPoint newContentPos = LayoutPoint(rect.x() + rect.width(), rect.y() + rect.height() / 2);
-    Frame* frame = m_webPage->focusedOrMainFrame();
-    if (frame != m_webPage->mainFrame())
-        newContentPos = m_webPage->mainFrame()->view()->windowToContents(frame->view()->contentsToWindow(newContentPos));
-    m_lastFatFingersResult.m_adjustedPosition = newContentPos;
-    m_lastFatFingersResult.m_positionWasAdjusted = true;
-    return marker->endOffset() - marker->startOffset();
-}
-
 void TouchEventHandler::handleFatFingerPressed()
 {
     if (!m_didCancelTouch) {

Modified: trunk/Source/WebKit/blackberry/WebKitSupport/TouchEventHandler.h (124886 => 124887)


--- trunk/Source/WebKit/blackberry/WebKitSupport/TouchEventHandler.h	2012-08-07 13:52:42 UTC (rev 124886)
+++ trunk/Source/WebKit/blackberry/WebKitSupport/TouchEventHandler.h	2012-08-07 14:32:15 UTC (rev 124887)
@@ -45,7 +45,6 @@
     void resetLastFatFingersResult() { m_lastFatFingersResult.reset(); }
 
 private:
-    unsigned spellCheck(Platform::TouchPoint&);
     void handleFatFingerPressed();
 
     void drawTapHighlight();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to