// The output from all these methods matches what DumpRenderTree produces. bool NotificationPresenter::show(const WebNotification& notification) { WebString identifier = identifierForNotification(notification); if (!notification.replaceId().isEmpty()) { WTF::String replaceId(notification.replaceId().data(), notification.replaceId().length()); if (m_replacements.find(replaceId) != m_replacements.end()) printf("REPLACING NOTIFICATION %s\n", m_replacements.find(replaceId)->second.utf8().data()); m_replacements.set(replaceId, WTF::String(identifier.data(), identifier.length())); } if (notification.isHTML()) { printf("DESKTOP NOTIFICATION: contents at %s\n", notification.url().spec().data()); } else { printf("DESKTOP NOTIFICATION:%s icon %s, title %s, text %s\n", notification.direction() == WebTextDirectionRightToLeft ? "(RTL)" : "", notification.iconURL().isEmpty() ? "" : notification.iconURL().spec().data(), notification.title().isEmpty() ? "" : notification.title().utf8().data(), notification.body().isEmpty() ? "" : notification.body().utf8().data()); } WTF::String id(identifier.data(), identifier.length()); m_activeNotifications.set(id, notification); webKitClient()->callOnMainThread(deferredDisplayDispatch, new WebNotification(notification)); return true; }
bool MockSpellCheck::spellCheckWord(const WebString& text, int* misspelledOffset, int* misspelledLength) { ASSERT(misspelledOffset); ASSERT(misspelledLength); // Initialize this spellchecker. initializeIfNeeded(); // Reset the result values as our spellchecker does. *misspelledOffset = 0; *misspelledLength = 0; // Convert to a String because we store String instances in // m_misspelledWords and WebString has no find(). String stringText(text.data(), text.length()); int skippedLength = 0; while (!stringText.isEmpty()) { // Extract the first possible English word from the given string. // The given string may include non-ASCII characters or numbers. So, we // should filter out such characters before start looking up our // misspelled-word table. // (This is a simple version of our SpellCheckWordIterator class.) // If the given string doesn't include any ASCII characters, we can treat the // string as valid one. int wordOffset = stringText.find(isASCIIAlpha); if (wordOffset == -1) return true; int maxWordLength = static_cast<int>(stringText.length()) - wordOffset; int wordLength; String word; // Look up our misspelled-word table to check if the extracted word is a // known misspelled word, and return the offset and the length of the // extracted word if this word is a known misspelled word. // (See the comment in MockSpellCheck::initializeIfNeeded() why we use a // misspelled-word table.) for (size_t i = 0; i < m_misspelledWords.size(); ++i) { wordLength = static_cast<int>(m_misspelledWords.at(i).length()) > maxWordLength ? maxWordLength : static_cast<int>(m_misspelledWords.at(i).length()); word = stringText.substring(wordOffset, wordLength); if (word == m_misspelledWords.at(i) && (static_cast<int>(stringText.length()) == wordOffset + wordLength || isNotASCIIAlpha(stringText[wordOffset + wordLength]))) { *misspelledOffset = wordOffset + skippedLength; *misspelledLength = wordLength; break; } } if (*misspelledLength > 0) break; int wordEnd = stringText.find(isNotASCIIAlpha, wordOffset); wordLength = wordEnd == -1 ? static_cast<int>(stringText.length()) - wordOffset : wordEnd - wordOffset; ASSERT(0 < wordOffset + wordLength); stringText = stringText.substring(wordOffset + wordLength); skippedLength += wordOffset + wordLength; } return false; }
void SpellCheckClient::checkTextOfParagraph(const WebString& text, WebTextCheckingTypeMask mask, WebVector<WebTextCheckingResult>* webResults) { Vector<WebTextCheckingResult> results; if (mask & WebTextCheckingTypeSpelling) { size_t offset = 0; size_t length = text.length(); const WebUChar* data = text.data(); while (offset < length) { int misspelledPosition = 0; int misspelledLength = 0; m_spellcheck.spellCheckWord(WebString(&data[offset], length - offset), &misspelledPosition, &misspelledLength); if (!misspelledLength) break; WebTextCheckingResult result; result.type = WebTextCheckingTypeSpelling; result.location = offset + misspelledPosition; result.length = misspelledLength; results.append(result); offset += misspelledPosition + misspelledLength; } } if (mask & WebTextCheckingTypeGrammar) MockGrammarCheck::checkGrammarOfString(text, &results); webResults->assign(results); }
void NotificationPresenter::cancel(const WebNotification& notification) { WebString identifier = identifierForNotification(notification); printf("DESKTOP NOTIFICATION CLOSED: %s\n", identifier.utf8().data()); WebNotification eventTarget(notification); eventTarget.dispatchCloseEvent(false); WTF::String id(identifier.data(), identifier.length()); m_activeNotifications.remove(id); }
void clearLocalStorage(const WebString& pageGroupName) { WTF::String name(pageGroupName.characters(), pageGroupName.length()); WebCore::PageGroup* group = WebCore::PageGroup::pageGroup(name); if (!group) return; group->removeLocalStorage(); }
bool NotificationPresenter::simulateClick(const WebString& title) { WTF::String id(title.data(), title.length()); if (m_activeNotifications.find(id) == m_activeNotifications.end()) return false; const WebNotification& notification = m_activeNotifications.find(id)->second; WebNotification eventTarget(notification); eventTarget.dispatchClickEvent(); return true; }
bool MockSpellCheck::spellCheckWord(const WebString& text, int* misspelledOffset, int* misspelledLength) { ASSERT(misspelledOffset); ASSERT(misspelledLength); // Initialize this spellchecker. initializeIfNeeded(); // Reset the result values as our spellchecker does. *misspelledOffset = 0; *misspelledLength = 0; // Convert to a String because we store String instances in // m_misspelledWords and WebString has no find(). WTF::String stringText(text.data(), text.length()); int skippedLength = 0; while (!stringText.isEmpty()) { // Extract the first possible English word from the given string. // The given string may include non-ASCII characters or numbers. So, we // should filter out such characters before start looking up our // misspelled-word table. // (This is a simple version of our SpellCheckWordIterator class.) // If the given string doesn't include any ASCII characters, we can treat the // string as valid one. // Unfortunately, This implementation splits a contraction, i.e. "isn't" is // split into two pieces "isn" and "t". This is OK because webkit tests // don't have misspelled contractions. int wordOffset = stringText.find(isASCIIAlpha); if (wordOffset == -1) return true; int wordEnd = stringText.find(isNotASCIIAlpha, wordOffset); int wordLength = wordEnd == -1 ? static_cast<int>(stringText.length()) - wordOffset : wordEnd - wordOffset; // Look up our misspelled-word table to check if the extracted word is a // known misspelled word, and return the offset and the length of the // extracted word if this word is a known misspelled word. // (See the comment in MockSpellCheck::initializeIfNeeded() why we use a // misspelled-word table.) WTF::String word = stringText.substring(wordOffset, wordLength); if (m_misspelledWords.contains(word)) { *misspelledOffset = wordOffset + skippedLength; *misspelledLength = wordLength; break; } ASSERT(0 < wordOffset + wordLength); stringText = stringText.substring(wordOffset + wordLength); skippedLength += wordOffset + wordLength; } return false; }
void EditorClientImpl::doAutofill(Timer<EditorClientImpl>* timer) { OwnPtr<AutofillArgs> args(m_autofillArgs.release()); HTMLInputElement* inputElement = args->inputElement.get(); const String& value = inputElement->value(); // Enforce autofill_on_empty_value and caret_at_end. bool isCaretAtEnd = true; if (args->requireCaretAtEnd) isCaretAtEnd = inputElement->selectionStart() == inputElement->selectionEnd() && inputElement->selectionEnd() == static_cast<int>(value.length()); if ((!args->autofillOnEmptyValue && value.isEmpty()) || !isCaretAtEnd) { m_webView->hideAutoFillPopup(); return; } // First let's see if there is a password listener for that element. // We won't trigger form autofill in that case, as having both behavior on // a node would be confusing. WebFrameImpl* webframe = WebFrameImpl::fromFrame(inputElement->document()->frame()); if (!webframe) return; WebPasswordAutocompleteListener* listener = webframe->getPasswordListener(inputElement); if (listener) { if (args->autofillFormOnly) return; listener->performInlineAutocomplete(value, args->backspaceOrDeletePressed, true); return; } // Then trigger form autofill. WebString name = WebInputElement(inputElement).nameForAutofill(); ASSERT(static_cast<int>(name.length()) > 0); if (m_webView->client()) m_webView->client()->queryAutofillSuggestions(WebNode(inputElement), name, WebString(value)); }
bool WebLocalFrameImpl::executeCommand(const WebString& name, const WebNode& node) { ASSERT(frame()); if (name.length() <= 2) return false; // Since we don't have NSControl, we will convert the format of command // string and call the function on Editor directly. String command = name; // Make sure the first letter is upper case. command.replace(0, 1, command.substring(0, 1).upper()); // Remove the trailing ':' if existing. if (command[command.length() - 1] == UChar(':')) command = command.substring(0, command.length() - 1); return frame()->editor().executeCommand(command); }
void EventSender::keyDown(const CppArgumentList& arguments, CppVariant* result) { result->setNull(); if (arguments.size() < 1 || !arguments[0].isString()) return; bool generateChar = false; // FIXME: I'm not exactly sure how we should convert the string to a key // event. This seems to work in the cases I tested. // FIXME: Should we also generate a KEY_UP? string codeStr = arguments[0].toString(); // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when // Windows uses \r for "Enter". int code = 0; int text = 0; bool needsShiftKeyModifier = false; if ("\n" == codeStr) { generateChar = true; text = code = webkit_support::VKEY_RETURN; } else if ("rightArrow" == codeStr) code = webkit_support::VKEY_RIGHT; else if ("downArrow" == codeStr) code = webkit_support::VKEY_DOWN; else if ("leftArrow" == codeStr) code = webkit_support::VKEY_LEFT; else if ("upArrow" == codeStr) code = webkit_support::VKEY_UP; else if ("insert" == codeStr) code = webkit_support::VKEY_INSERT; else if ("delete" == codeStr) code = webkit_support::VKEY_DELETE; else if ("pageUp" == codeStr) code = webkit_support::VKEY_PRIOR; else if ("pageDown" == codeStr) code = webkit_support::VKEY_NEXT; else if ("home" == codeStr) code = webkit_support::VKEY_HOME; else if ("end" == codeStr) code = webkit_support::VKEY_END; else if ("printScreen" == codeStr) code = webkit_support::VKEY_SNAPSHOT; else if ("menu" == codeStr) // FIXME: Change this to webkit_support::VKEY_APPS. code = 0x5D; else { // Compare the input string with the function-key names defined by the // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key // name, set its key code. for (int i = 1; i <= 24; ++i) { char functionChars[10]; snprintf(functionChars, 10, "F%d", i); string functionKeyName(functionChars); if (functionKeyName == codeStr) { code = webkit_support::VKEY_F1 + (i - 1); break; } } if (!code) { WebString webCodeStr = WebString::fromUTF8(codeStr.data(), codeStr.size()); ASSERT(webCodeStr.length() == 1); text = code = webCodeStr.data()[0]; needsShiftKeyModifier = needsShiftModifier(code); if ((code & 0xFF) >= 'a' && (code & 0xFF) <= 'z') code -= 'a' - 'A'; generateChar = true; } } // For one generated keyboard event, we need to generate a keyDown/keyUp // pair; refer to EventSender.cpp in Tools/DumpRenderTree/win. // On Windows, we might also need to generate a char event to mimic the // Windows event flow; on other platforms we create a merged event and test // the event flow that that platform provides. WebKeyboardEvent eventDown, eventChar, eventUp; eventDown.type = WebInputEvent::RawKeyDown; eventDown.modifiers = 0; eventDown.windowsKeyCode = code; if (generateChar) { eventDown.text[0] = text; eventDown.unmodifiedText[0] = text; } eventDown.setKeyIdentifierFromWindowsKeyCode(); if (arguments.size() >= 2 && (arguments[1].isObject() || arguments[1].isString())) eventDown.isSystemKey = applyKeyModifiers(&(arguments[1]), &eventDown); if (needsShiftKeyModifier) eventDown.modifiers |= WebInputEvent::ShiftKey; // See if KeyLocation argument is given. if (arguments.size() >= 3 && arguments[2].isNumber()) { int location = arguments[2].toInt32(); if (location == DOMKeyLocationNumpad) eventDown.modifiers |= WebInputEvent::IsKeyPad; } eventChar = eventUp = eventDown; eventUp.type = WebInputEvent::KeyUp; // EventSender.m forces a layout here, with at least one // test (fast/forms/focus-control-to-page.html) relying on this. webview()->layout(); // In the browser, if a keyboard event corresponds to an editor command, // the command will be dispatched to the renderer just before dispatching // the keyboard event, and then it will be executed in the // RenderView::handleCurrentKeyboardEvent() method, which is called from // third_party/WebKit/Source/WebKit/chromium/src/EditorClientImpl.cpp. // We just simulate the same behavior here. string editCommand; if (getEditCommand(eventDown, &editCommand)) m_shell->webViewHost()->setEditCommand(editCommand, ""); webview()->handleInputEvent(eventDown); m_shell->webViewHost()->clearEditCommand(); if (generateChar) { eventChar.type = WebInputEvent::Char; eventChar.keyIdentifier[0] = '\0'; webview()->handleInputEvent(eventChar); } webview()->handleInputEvent(eventUp); }
void NotificationPresenter::objectDestroyed(const WebKit::WebNotification& notification) { WebString identifier = identifierForNotification(notification); WTF::String id(identifier.data(), identifier.length()); m_activeNotifications.remove(id); }
void clearDatabase(const WebString& pageGroupName) { WTF::String name(pageGroupName.characters(), pageGroupName.length()); WebCore::DatabaseTracker::tracker(name).deleteAllDatabases(); }
void clearAppCache(const WebString& pageGroupName) { WTF::String name(pageGroupName.characters(), pageGroupName.length()); WebCore::cacheStorage(name).empty(); }