diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-09-10 19:10:20 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-09-10 19:10:20 +0200 |
commit | 284837daa07b29d6a63a748544a90b1f5842ac5c (patch) | |
tree | ecd258180bde91fe741e0cfd2638beb3c6da7e8e /Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp | |
parent | 2e2ba8ff45915f40ed3e014101269c175f2a89a0 (diff) | |
download | qtwebkit-284837daa07b29d6a63a748544a90b1f5842ac5c.tar.gz |
Imported WebKit commit 68645295d2e3e09af2c942f092556f06aa5f8b0d (http://svn.webkit.org/repository/webkit/trunk@128073)
New snapshot
Diffstat (limited to 'Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp')
-rw-r--r-- | Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp b/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp index 77f8ada84..7e5d46262 100644 --- a/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp +++ b/Source/WebKit/blackberry/WebKitSupport/InputHandler.cpp @@ -22,8 +22,8 @@ #include "BackingStore.h" #include "BackingStoreClient.h" #include "CSSStyleDeclaration.h" -#include "CString.h" #include "Chrome.h" +#include "ColorPickerClient.h" #include "DOMSupport.h" #include "DatePickerClient.h" #include "Document.h" @@ -68,6 +68,7 @@ #include <BlackBerryPlatformMisc.h> #include <BlackBerryPlatformSettings.h> #include <sys/keycodes.h> +#include <wtf/text/CString.h> #define ENABLE_INPUT_LOG 0 #define ENABLE_FOCUS_LOG 0 @@ -135,6 +136,7 @@ InputHandler::InputHandler(WebPagePrivate* page) , m_pendingKeyboardVisibilityChange(NoChange) , m_delayKeyboardVisibilityChange(false) { + pthread_mutex_init(&m_sequenceMapMutex, 0); } InputHandler::~InputHandler() @@ -540,8 +542,8 @@ void InputHandler::requestCheckingOfString(PassRefPtr<WebCore::TextCheckingReque return; } - // Check if field explicitly asked for spellchecking. - if (DOMSupport::elementSupportsSpellCheck(m_currentFocusElement.get()) != DOMSupport::On) { + // Check if the field should be spellchecked. + if (!shouldSpellCheckElement(m_currentFocusElement.get())) { spellCheckingRequestCancelled(sequenceId, true /* isSequenceId */); return; } @@ -581,6 +583,7 @@ void InputHandler::requestCheckingOfString(PassRefPtr<WebCore::TextCheckingReque return; } + BlackBerry::Platform::MutexLocker lock(&m_sequenceMapMutex); int32_t transactionId = m_webPage->m_client->checkSpellingOfStringAsync(checkingString, paragraphLength); free(checkingString); @@ -598,6 +601,7 @@ void InputHandler::requestCheckingOfString(PassRefPtr<WebCore::TextCheckingReque int32_t InputHandler::convertTransactionIdToSequenceId(int32_t transactionId) { + BlackBerry::Platform::MutexLocker lock(&m_sequenceMapMutex); std::map<int32_t, int32_t>::iterator it = m_sequenceMap.find(transactionId); if (it == m_sequenceMap.end()) @@ -660,6 +664,7 @@ void InputHandler::spellCheckingRequestProcessed(int32_t transactionId, spannabl void InputHandler::cancelAllSpellCheckingRequests() { + BlackBerry::Platform::MutexLocker lock(&m_sequenceMapMutex); for (std::map<int32_t, int32_t>::iterator it = m_sequenceMap.begin(); it != m_sequenceMap.end(); ++it) spellCheckingRequestCancelled(it->second, true /* isSequenceId */); m_sequenceMap.clear(); @@ -672,7 +677,7 @@ void InputHandler::spellCheckingRequestCancelled(int32_t id, bool isSequenceId) int32_t sequenceId = isSequenceId ? id : convertTransactionIdToSequenceId(id); SpellChecker* spellChecker = getSpellChecker(); - if (!spellChecker) { + if (!spellChecker || !sequenceId) { SpellingLog(LogLevelWarn, "InputHandler::spellCheckingRequestCancelled failed to cancel the request with sequenceId %d", sequenceId); return; } @@ -838,8 +843,8 @@ void InputHandler::setElementFocused(Element* element) SpellingLog(LogLevelInfo, "InputHandler::setElementFocused Focusing the field took %f seconds.", timer.elapsed()); #endif - // Check if the field explicitly asks for spellchecking. - if (DOMSupport::elementSupportsSpellCheck(element) != DOMSupport::On) + // Check if the field should be spellchecked. + if (!shouldSpellCheckElement(element)) return; // Spellcheck the field in its entirety. @@ -851,19 +856,36 @@ void InputHandler::setElementFocused(Element* element) #endif } +bool InputHandler::shouldSpellCheckElement(const Element* element) const +{ + DOMSupport::AttributeState spellCheckAttr = DOMSupport::elementSupportsSpellCheck(element); + + // Explicitly set to off. + if (spellCheckAttr == DOMSupport::Off) + return false; + + // Undefined and part of a set of cases which we do not wish to check. This includes user names and email addresses, so we are piggybacking on NoAutocomplete cases. + if (spellCheckAttr == DOMSupport::Default && (m_currentFocusElementTextEditMask & NO_AUTO_TEXT)) + return false; + + return true; +} + void InputHandler::spellCheckBlock(VisibleSelection& visibleSelection, TextCheckingProcessType textCheckingProcessType) { if (!isActiveTextEdit()) return; + RefPtr<Range> rangeForSpellChecking = visibleSelection.toNormalizedRange(); + if (!rangeForSpellChecking || !rangeForSpellChecking->text() || !rangeForSpellChecking->text().length()) + return; + SpellChecker* spellChecker = getSpellChecker(); if (!spellChecker) { SpellingLog(LogLevelInfo, "InputHandler::spellCheckBlock Failed to spellcheck the current focused element."); return; } - RefPtr<Range> rangeForSpellChecking = visibleSelection.toNormalizedRange(); - // If we have a batch request, try to send off the entire block. if (textCheckingProcessType == TextCheckingProcessBatch) { // If total block text is under the limited amount, send the entire chunk. @@ -876,13 +898,16 @@ void InputHandler::spellCheckBlock(VisibleSelection& visibleSelection, TextCheck // Since we couldn't check the entire block at once, set up starting and ending markers to fire incrementally. VisiblePosition startPos = visibleSelection.visibleStart(); VisiblePosition startOfCurrentLine = startOfLine(startPos); - VisiblePosition endOfCurrentLine = endOfLine(startPos); + VisiblePosition endOfCurrentLine = endOfLine(startOfCurrentLine); - while (startOfCurrentLine != endOfCurrentLine) { + while (!isEndOfBlock(startOfCurrentLine)) { // Create a selection with the start and end points of the line, and convert to Range to create a SpellCheckRequest. rangeForSpellChecking = VisibleSelection(startOfCurrentLine, endOfCurrentLine).toNormalizedRange(); - if (rangeForSpellChecking->text().length() >= MaxSpellCheckingStringLength) { + if (rangeForSpellChecking->text().length() < MaxSpellCheckingStringLength) { + startOfCurrentLine = nextLinePosition(startOfCurrentLine, startOfCurrentLine.lineDirectionPointForBlockDirectionNavigation()); + endOfCurrentLine = endOfLine(startOfCurrentLine); + } else { // Iterate through words from the start of the line to the end. rangeForSpellChecking = getRangeForSpellCheckWithFineGranularity(startOfCurrentLine, endOfCurrentLine); if (!rangeForSpellChecking) { @@ -890,12 +915,6 @@ void InputHandler::spellCheckBlock(VisibleSelection& visibleSelection, TextCheck return; } startOfCurrentLine = VisiblePosition(rangeForSpellChecking->endPosition()); - } else { - startOfCurrentLine = nextLinePosition(startOfCurrentLine, startOfCurrentLine.lineDirectionPointForBlockDirectionNavigation()); - endOfCurrentLine = endOfLine(startOfCurrentLine); - // If we are at the last line, nextLinePosition will return the position at the end of the line. If we're not at the end, wrap with a call to startOfLine to be safe. - if (startOfCurrentLine != endOfCurrentLine) - startOfCurrentLine = startOfLine(startOfCurrentLine); } SpellingLog(LogLevelInfo, "InputHandler::spellCheckBlock Substring text is '%s', of size %d", rangeForSpellChecking->text().latin1().data(), rangeForSpellChecking->text().length()); @@ -941,11 +960,7 @@ bool InputHandler::openDatePopup(HTMLInputElement* element, BlackBerryInputType double step = element->getAttribute(HTMLNames::stepAttr).toDouble(); DatePickerClient* client = new DatePickerClient(type, value, min, max, step, m_webPage, element); - // Fail to create HTML popup, use the old path - if (!m_webPage->m_page->chrome()->client()->openPagePopup(client, WebCore::IntRect())) - m_webPage->m_client->openDateTimePopup(type, value, min, max, step); - - return true; + return m_webPage->m_page->chrome()->client()->openPagePopup(client, WebCore::IntRect()); } default: // Other types not supported return false; @@ -963,7 +978,10 @@ bool InputHandler::openColorPopup(HTMLInputElement* element) m_currentFocusElement = element; m_currentFocusElementType = TextPopup; - m_webPage->m_client->openColorPopup(element->value()); + // Check if popup already exists, close it if does. + m_webPage->m_page->chrome()->client()->closePagePopup(0); + ColorPickerClient* client = new ColorPickerClient(element->value(), m_webPage, element); + m_webPage->m_page->chrome()->client()->openPagePopup(client, WebCore::IntRect()); return true; } @@ -1642,6 +1660,9 @@ bool InputHandler::openSelectPopup(HTMLSelectElement* select) // Fail to create HTML popup, use the old path if (!m_webPage->m_page->chrome()->client()->openPagePopup(selectClient, elementRectInRootView)) m_webPage->m_client->openPopupList(multiple, size, labels, enableds, itemTypes, selecteds); + delete[] enableds; + delete[] itemTypes; + delete[] selecteds; return true; } |