void HTMLTextAreaElement::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent* event) const { ASSERT(event); ASSERT(layoutObject()); int signedMaxLength = maxLength(); if (signedMaxLength < 0) return; unsigned unsignedMaxLength = static_cast<unsigned>(signedMaxLength); const String& currentValue = innerEditorValue(); unsigned currentLength = computeLengthForSubmission(currentValue); if (currentLength + computeLengthForSubmission(event->text()) < unsignedMaxLength) return; // selectionLength represents the selection length of this text field to be // removed by this insertion. // If the text field has no focus, we don't need to take account of the // selection length. The selection is the source of text drag-and-drop in // that case, and nothing in the text field will be removed. unsigned selectionLength = 0; if (focused()) { const EphemeralRange range = document().frame()->selection().selection().toNormalizedEphemeralRange(); selectionLength = computeLengthForSubmission(plainText(range)); } ASSERT(currentLength >= selectionLength); unsigned baseLength = currentLength - selectionLength; unsigned appendableLength = unsignedMaxLength > baseLength ? unsignedMaxLength - baseLength : 0; event->setText(sanitizeUserInputValue(event->text(), appendableLength)); }
void HistoryLogger::saveMessage(const Message* message) { if (message->flags() & MESSAGE_FLAG_ALARM) return; Xapian::Document doc; quint32 flags = message->flags(); std::string plainText(message->plainText().toUtf8()); std::string confUser(message->getConfUser().constData()); std::string data; if (flags & MESSAGE_FLAG_RTF) data = message->rtfText().constData(); else data = plainText; std::cout << "HistoryLogger::saveMessage data = " << data << std::endl; doc.set_data(data); Xapian::TermGenerator termGen; termGen.set_stemmer(Xapian::Stem("ru")); termGen.set_document(doc); termGen.index_text(plainText); doc.add_value(0, message->dateTime().toString("yyyyMMdd").toStdString()); doc.add_value(1, message->dateTime().toString("hhmmss").toStdString()); doc.add_value(2, QString::number(flags, 16).toStdString()); doc.add_value(3, message->type() == Message::Outgoing? "o" : "i"); doc.add_value(4, confUser); database->add_document(doc); database->flush(); }
const String& TextCheckingParagraph::text() const { ASSERT(m_checkingRange.isNotNull()); if (m_text.isEmpty()) m_text = plainText(paragraphRange()); return m_text; }
String DOMSelection::toString() { if (!m_frame) return String(); return plainText(m_frame->selection()->selection().toNormalizedRange().get()); }
int TKAction::plug(QWidget* widget, int index) { if ( widget->inherits("KToolBar") ) { KToolBar* bar = static_cast<KToolBar*>(widget); int id_ = KAction::getToolButtonID(); KInstance *instance; if ( parentCollection() ) instance = parentCollection()->instance(); else instance = KGlobal::instance(); TKToolBarButton* b = new TKToolBarButton(icon(),plainText(),bar,name(),instance); // we don't need clicked() and buttonClicked(), do we? // connect(b,SIGNAL(clicked()),SLOT(slotActivated())); b->setIconMode(m_imode); initToolBarButton(b); bar->insertWidget( id_, 100, b, index ); addContainer(bar,id_); connect( bar, SIGNAL(destroyed()), this, SLOT(slotDestroyed()) ); return containerCount() - 1; } return KAction::plug(widget,index); }
QString Fingering::accessibleInfo() const { QString rez = Element::accessibleInfo(); if (tid() == Tid::STRING_NUMBER) rez += " " + QObject::tr("String number"); return QString("%1: %2").arg(rez).arg(plainText()); }
// // CreateDataFromPrimitive // // Given a nsISupports* primitive and the flavor it represents, creates a new data // buffer with the data in it. This data will be null terminated, but the length // parameter does not reflect that. // void nsPrimitiveHelpers :: CreateDataFromPrimitive ( const char* aFlavor, nsISupports* aPrimitive, void** aDataBuff, uint32_t aDataLen ) { if ( !aDataBuff ) return; *aDataBuff = nullptr; if ( strcmp(aFlavor,kTextMime) == 0 || strcmp(aFlavor,kCustomTypesMime) == 0) { nsCOMPtr<nsISupportsCString> plainText ( do_QueryInterface(aPrimitive) ); if ( plainText ) { nsAutoCString data; plainText->GetData ( data ); *aDataBuff = ToNewCString(data); } } else { nsCOMPtr<nsISupportsString> doubleByteText ( do_QueryInterface(aPrimitive) ); if ( doubleByteText ) { nsAutoString data; doubleByteText->GetData ( data ); *aDataBuff = ToNewUnicode(data); } } }
QString TempoText::accessibleInfo() const { TDuration t1; TDuration t2; int len1; int len2; QString text = plainText(); QString firstPart = text.split(" = ").first(); QString secondPart = text.split(" = ").back(); int x1 = findTempoDuration(firstPart, len1, t1); int x2 = -1; if (_relative) x2 = findTempoDuration(secondPart, len2, t2); if (x1 != -1) { QString dots1; QString dots2; dots1 = duration2userName(t1); if (x2 != -1) { dots2 = duration2userName(t2); return QString("%1: %2 %3 = %4 %5").arg(Element::accessibleInfo()).arg(dots1).arg(tr("note")).arg(dots2).arg(tr("note")); } else return QString("%1: %2 %3 = %4").arg(Element::accessibleInfo()).arg(dots1).arg(tr("note")).arg(secondPart); } else return Text::accessibleInfo(); }
void HTMLTextAreaElement::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent* event) const { ASSERT(event); ASSERT(renderer()); int signedMaxLength = maxLength(); if (signedMaxLength < 0) return; unsigned unsignedMaxLength = static_cast<unsigned>(signedMaxLength); const String& currentValue = innerTextValue(); unsigned numberOfLineBreaksInCurrentValue = numberOfLineBreaks(currentValue); if (upperBoundForLengthForSubmission(currentValue, numberOfLineBreaksInCurrentValue) + upperBoundForLengthForSubmission(event->text(), numberOfLineBreaks(event->text())) < unsignedMaxLength) return; unsigned currentLength = computeLengthForSubmission(currentValue, numberOfLineBreaksInCurrentValue); // selectionLength represents the selection length of this text field to be // removed by this insertion. // If the text field has no focus, we don't need to take account of the // selection length. The selection is the source of text drag-and-drop in // that case, and nothing in the text field will be removed. unsigned selectionLength = focused() ? computeLengthForSubmission(plainText(document().frame()->selection().selection().toNormalizedRange().get())) : 0; ASSERT(currentLength >= selectionLength); unsigned baseLength = currentLength - selectionLength; unsigned appendableLength = unsignedMaxLength > baseLength ? unsignedMaxLength - baseLength : 0; event->setText(sanitizeUserInputValue(event->text(), appendableLength)); }
// static PassRefPtrWillBeRawPtr<SpellCheckRequest> SpellCheckRequest::create(TextCheckingTypeMask textCheckingOptions, TextCheckingProcessType processType, const EphemeralRange& checkingRange, const EphemeralRange& paragraphRange, int requestNumber) { if (checkingRange.isNull()) return nullptr; if (!checkingRange.startPosition().computeContainerNode()->rootEditableElement()) return nullptr; String text = plainText(checkingRange, TextIteratorEmitsObjectReplacementCharacter); if (text.isEmpty()) return nullptr; RefPtrWillBeRawPtr<Range> checkingRangeObject = createRange(checkingRange); RefPtrWillBeRawPtr<Range> paragraphRangeObject = nullptr; // Share identical Range objects. if (checkingRange == paragraphRange) paragraphRangeObject = checkingRangeObject; else paragraphRangeObject = createRange(paragraphRange); const DocumentMarkerVector& markers = checkingRangeObject->ownerDocument().markers().markersInRange(checkingRange, DocumentMarker::SpellCheckClientMarkers()); Vector<uint32_t> hashes(markers.size()); Vector<unsigned> offsets(markers.size()); for (size_t i = 0; i < markers.size(); ++i) { hashes[i] = markers[i]->hash(); offsets[i] = markers[i]->startOffset(); } return adoptRefWillBeNoop(new SpellCheckRequest(checkingRangeObject, paragraphRangeObject, text, textCheckingOptions, processType, hashes, offsets, requestNumber)); }
QString TextShow::selectedText() { QString res; int paraFrom, paraTo, indexFrom, indexTo; getSelection(¶From, &indexFrom, ¶To, &indexTo); return plainText(paraFrom, paraTo, indexFrom, indexTo); }
String WebFrame::contentsAsString() const { if (!m_coreFrame) return String(); if (isFrameSet()) { StringBuilder builder; for (Frame* child = m_coreFrame->tree()->firstChild(); child; child = child->tree()->nextSibling()) { if (!builder.isEmpty()) builder.append(' '); builder.append(static_cast<WebFrameLoaderClient*>(child->loader()->client())->webFrame()->contentsAsString()); } // FIXME: It may make sense to use toStringPreserveCapacity() here. return builder.toString(); } Document* document = m_coreFrame->document(); if (!document) return String(); RefPtr<Element> documentElement = document->documentElement(); if (!documentElement) return String(); RefPtr<Range> range = document->createRange(); ExceptionCode ec = 0; range->selectNode(documentElement.get(), ec); if (ec) return String(); return plainText(range.get()); }
void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &wordStart, const VisibleSelection& selectionAfterTyping) { if (unifiedTextCheckerEnabled()) { TextCheckingTypeMask textCheckingOptions = 0; if (isContinuousSpellCheckingEnabled()) textCheckingOptions |= TextCheckingTypeSpelling; if (!(textCheckingOptions & TextCheckingTypeSpelling)) return; if (isGrammarCheckingEnabled()) textCheckingOptions |= TextCheckingTypeGrammar; VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary)); if (textCheckingOptions & TextCheckingTypeGrammar) { VisibleSelection selectedSentence = VisibleSelection(startOfSentence(wordStart), endOfSentence(wordStart)); markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), selectedSentence.toNormalizedRange().get()); } else { markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), adjacentWords.toNormalizedRange().get()); } return; } if (!isContinuousSpellCheckingEnabled()) return; // Check spelling of one word RefPtr<Range> misspellingRange = nullptr; markMisspellings(VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary)), misspellingRange); // Autocorrect the misspelled word. if (!misspellingRange) return; // Get the misspelled word. const String misspelledWord = plainText(misspellingRange.get()); String autocorrectedString = textChecker().getAutoCorrectSuggestionForMisspelledWord(misspelledWord); // If autocorrected word is non empty, replace the misspelled word by this word. if (!autocorrectedString.isEmpty()) { VisibleSelection newSelection(misspellingRange.get(), DOWNSTREAM); if (newSelection != m_frame.selection().selection()) { m_frame.selection().setSelection(newSelection); } m_frame.editor().replaceSelectionWithText(autocorrectedString, false, false); // Reset the charet one character further. m_frame.selection().moveTo(m_frame.selection().selection().visibleEnd()); m_frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity); } if (!isGrammarCheckingEnabled()) return; // Check grammar of entire sentence markBadGrammar(VisibleSelection(startOfSentence(wordStart), endOfSentence(wordStart))); }
QString Fingering::accessibleInfo() { QString rez = Element::accessibleInfo(); if (textStyleType() == TextStyleType::STRING_NUMBER) { rez += " " + tr("String number"); } return QString("%1: %2").arg(rez).arg(plainText()); }
String DOMSelection::toString() { if (!m_frame) return String(); const EphemeralRange range = m_frame->selection().selection().toNormalizedEphemeralRange(); return plainText(range, TextIteratorForSelectionToString); }
String AbstractInlineTextBox::text() const { if (!m_inlineTextBox || !m_layoutText) return String(); unsigned start = m_inlineTextBox->start(); unsigned len = m_inlineTextBox->len(); if (Node* node = m_layoutText->node()) { if (node->isTextNode()) return plainText(Position(node, start), Position(node, start + len), TextIteratorIgnoresStyleVisibility); return plainText(Position(node, PositionAnchorType::BeforeAnchor), Position(node, PositionAnchorType::AfterAnchor), TextIteratorIgnoresStyleVisibility); } String result = m_layoutText->text().substring(start, len).simplifyWhiteSpace(WTF::DoNotStripWhiteSpace); if (m_inlineTextBox->nextTextBox() && m_inlineTextBox->nextTextBox()->start() > m_inlineTextBox->end() && result.length() && !result.right(1).containsOnlyWhitespace()) return result + " "; return result; }
QSize ValueWidget::sizeHint() const { QFontMetrics metrics(font()); // TODO: QLabel internally provides already a method sizeForWidth(), // that would be sufficient. However this method is not accessible, so // as workaround the tags from a richtext are removed manually here to // have a proper size hint. return metrics.size(Qt::TextSingleLine, plainText(text())); }
void Pasteboard::writePlainText(const String& text) { #if PLATFORM(WIN_OS) String plainText(text); replaceNewlinesWithWindowsStyleNewlines(plainText); ChromiumBridge::clipboardWritePlainText(plainText); #else ChromiumBridge::clipboardWritePlainText(text); #endif }
void Pasteboard::writePlainText(const String& text) { #if OS(WINDOWS) String plainText(text); replaceNewlinesWithWindowsStyleNewlines(plainText); PlatformSupport::clipboardWritePlainText(plainText); #else PlatformSupport::clipboardWritePlainText(text); #endif }
String DOMSelection::toString() { if (!m_frame) return String(); Position start, end; if (m_frame->selection().selection().toNormalizedPositions(start, end)) return plainText(start, end, TextIteratorForSelectionToString); return emptyString(); }
void Pasteboard::writePlainText(const String& text) { #if OS(WINDOWS) String plainText(text); replaceNewlinesWithWindowsStyleNewlines(plainText); WebKit::Platform::current()->clipboard()->writePlainText(plainText); #else WebKit::Platform::current()->clipboard()->writePlainText(text); #endif }
void Pasteboard::writePlainText(const String& text, SmartReplaceOption) { // FIXME: add support for smart replace #if OS(WIN) String plainText(text); replaceNewlinesWithWindowsStyleNewlines(plainText); blink::Platform::current()->clipboard()->writePlainText(plainText); #else blink::Platform::current()->clipboard()->writePlainText(text); #endif }
void TextEdit::setTextFormat(QTextEdit::TextFormat format) { if (format == textFormat()) return; if (format == RichText){ QTextEdit::setTextFormat(format); return; } QString t = plainText(0, paragraphs(), 0, 0); QTextEdit::setTextFormat(format); setText(t); }
void TempoText::textChanged() { if (!_followText) return; // cache regexp, they are costly to create static QHash<QString, QRegExp> regexps; static QHash<QString, QRegExp> regexps2; QString s = plainText(); s.replace(",", "."); s.replace("<sym>space</sym>"," "); for (const TempoPattern& pa : tp) { QRegExp re; if (!regexps.contains(pa.pattern)) { re = QRegExp(QString("%1\\s*=\\s*(\\d+[.]{0,1}\\d*)\\s*").arg(pa.pattern)); regexps[pa.pattern] = re; } re = regexps.value(pa.pattern); if (re.indexIn(s) != -1) { QStringList sl = re.capturedTexts(); if (sl.size() == 2) { qreal nt = qreal(sl[1].toDouble()) * pa.f; if (nt != _tempo) { setTempo(qreal(sl[1].toDouble()) * pa.f); _relative = 1.0; _isRelative = false; updateScore(); } break; } } else { for (const TempoPattern& pa2 : tp) { QString key = QString("%1_%2").arg(pa.pattern).arg(pa2.pattern); QRegExp re2; if (!regexps2.contains(key)) { re2 = QRegExp(QString("%1\\s*=\\s*%2\\s*").arg(pa.pattern).arg(pa2.pattern)); regexps2[key] = re2; } re2 = regexps2.value(key); if (re2.indexIn(s) != -1) { _relative = pa2.f / pa.f; _isRelative = true; updateRelative(); updateScore(); return; } } } } }
// FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated. // https://bugs.webkit.org/show_bug.cgi?id=164939 static ExceptionOr<Vector<uint8_t>> decryptRSA_OAEP(CryptoAlgorithmIdentifier hash, const Vector<uint8_t>& label, const PlatformRSAKey key, size_t keyLength, const uint8_t* data, size_t dataLength) { CCDigestAlgorithm digestAlgorithm; if (!getCommonCryptoDigestAlgorithm(hash, digestAlgorithm)) return Exception { OperationError }; Vector<uint8_t> plainText(keyLength / 8); // Per Step 1.b of https://tools.ietf.org/html/rfc3447#section-7.1.1 size_t plainTextLength = plainText.size(); if (CCRSACryptorDecrypt(key, ccOAEPPadding, data, dataLength, plainText.data(), &plainTextLength, label.data(), label.size(), digestAlgorithm)) return Exception { OperationError }; plainText.resize(plainTextLength); return WTFMove(plainText); }
String DOMSelection::toString() { if (!isAvailable()) return String(); // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets // needs to be audited. See http://crbug.com/590369 for more details. frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets(); DocumentLifecycle::DisallowTransitionScope disallowTransition( frame()->document()->lifecycle()); const EphemeralRange range = frame()->selection().selection().toNormalizedEphemeralRange(); return plainText(range, TextIteratorForSelectionToString); }
void HTMLTextAreaElement::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent* event) const { ASSERT(event); ASSERT(renderer()); int signedMaxLength = maxLength(); if (signedMaxLength < 0) return; unsigned unsignedMaxLength = static_cast<unsigned>(signedMaxLength); unsigned currentLength = toRenderTextControl(renderer())->text().numGraphemeClusters(); unsigned selectionLength = plainText(document()->frame()->selection()->selection().toNormalizedRange().get()).numGraphemeClusters(); ASSERT(currentLength >= selectionLength); unsigned baseLength = currentLength - selectionLength; unsigned appendableLength = unsignedMaxLength > baseLength ? unsignedMaxLength - baseLength : 0; event->setText(sanitizeUserInputValue(event->text(), appendableLength)); }
bool InputMethodController::finishComposition(const String& text, FinishCompositionMode mode) { if (!hasComposition()) return false; ASSERT(mode == ConfirmComposition || mode == CancelComposition); Editor::RevealSelectionScope revealSelectionScope(&editor()); bool dirty = m_isDirty || plainText(compositionEphemeralRange()) != text; if (mode == CancelComposition) { ASSERT(text == emptyString()); } else if (dirty) { selectComposition(); } if (frame().selection().isNone()) return false; // Dispatch a compositionend event to the focused node. // We should send this event before sending a TextEvent as written in Section 6.2.2 and 6.2.3 of // the DOM Event specification. if (Element* target = frame().document()->focusedElement()) { RefPtrWillBeRawPtr<CompositionEvent> event = CompositionEvent::create(EventTypeNames::compositionend, frame().domWindow(), text); target->dispatchEvent(event); } // If text is empty, then delete the old composition here. If text is non-empty, InsertTextCommand::input // will delete the old composition with an optimized replace operation. if (text.isEmpty() && mode != CancelComposition && dirty) { ASSERT(frame().document()); TypingCommand::deleteSelection(*frame().document(), 0); } clear(); if (dirty) insertTextForConfirmedComposition(text); if (mode == CancelComposition) { // An open typing command that disagrees about current selection would cause issues with typing later on. TypingCommand::closeTyping(m_frame); } return true; }
String StyledMarkupAccumulator::renderedText(Node& node, const Range* range) { if (!node.isTextNode()) return String(); Text& textNode = toText(node); unsigned startOffset = 0; unsigned endOffset = textNode.length(); if (range && textNode == range->startContainer()) startOffset = range->startOffset(); if (range && textNode == range->endContainer()) endOffset = range->endOffset(); Position start = createLegacyEditingPosition(&textNode, startOffset); Position end = createLegacyEditingPosition(&textNode, endOffset); return plainText(Range::create(textNode.document(), start, end).get()); }
String AbstractInlineTextBox::text() const { if (!m_inlineTextBox || !m_renderText) return String(); unsigned start = m_inlineTextBox->start(); unsigned len = m_inlineTextBox->len(); if (Node* node = m_renderText->node()) { RefPtrWillBeRawPtr<Range> range = Range::create(node->document()); range->setStart(node, start, IGNORE_EXCEPTION); range->setEnd(node, start + len, IGNORE_EXCEPTION); return plainText(range.get(), TextIteratorIgnoresStyleVisibility); } String result = m_renderText->text().substring(start, len).simplifyWhiteSpace(WTF::DoNotStripWhiteSpace); if (m_inlineTextBox->nextTextBox() && m_inlineTextBox->nextTextBox()->start() > m_inlineTextBox->end() && result.length() && !result.right(1).containsOnlyWhitespace()) return result + " "; return result; }