本文整理汇总了C++中VisibleSelection::expandUsingGranularity方法的典型用法代码示例。如果您正苦于以下问题:C++ VisibleSelection::expandUsingGranularity方法的具体用法?C++ VisibleSelection::expandUsingGranularity怎么用?C++ VisibleSelection::expandUsingGranularity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VisibleSelection
的用法示例。
在下文中一共展示了VisibleSelection::expandUsingGranularity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: expandSelectionToGranularity
static void expandSelectionToGranularity(Frame* frame, int x, int y, TextGranularity granularity, bool isInputMode)
{
ASSERT(frame);
ASSERT(frame->selection());
VisibleSelection selection;
if (x < 0 || y < 0) {
if (!isInputMode)
return; // Invalid request
// Input mode based selection, use the current selection as the selection point.
ASSERT(frame->selection()->selectionType() != VisibleSelection::NoSelection);
selection = frame->selection()->selection();
} else {
VisiblePosition pointLocation(frame->visiblePositionForPoint(WebCore::IntPoint(x, y)));
selection = VisibleSelection(pointLocation, pointLocation);
}
if (!(selection.start().anchorNode() && selection.start().anchorNode()->isTextNode()))
return;
selection.expandUsingGranularity(granularity);
RefPtr<Range> newRange = selection.toNormalizedRange();
if (!newRange)
return;
ExceptionCode ec = 0;
if (newRange->collapsed(ec))
return;
RefPtr<Range> oldRange = frame->selection()->selection().toNormalizedRange();
EAffinity affinity = frame->selection()->affinity();
if (isInputMode && !frame->editor()->client()->shouldChangeSelectedRange(oldRange.get(), newRange.get(), affinity, false))
return;
frame->selection()->setSelectedRange(newRange.get(), affinity, true);
}
示例2: getCustomMenuFromDefaultItems
//.........这里部分代码省略.........
// If it's not a link, an image, a media element, or an image/media link,
// show a selection menu or a more generic page menu.
if (selectedFrame->document()->loader())
data.frameEncoding = selectedFrame->document()->encoding();
// Send the frame and page URLs in any case.
data.pageURL = urlFromFrame(m_webView->mainFrameImpl()->frame());
if (selectedFrame != m_webView->mainFrameImpl()->frame()) {
data.frameURL = urlFromFrame(selectedFrame);
RefPtr<HistoryItem> historyItem = selectedFrame->loader()->history()->currentItem();
if (historyItem)
data.frameHistoryItem = WebHistoryItem(historyItem);
}
if (r.isSelected()) {
if (!r.innerNonSharedNode()->hasTagName(HTMLNames::inputTag) || !static_cast<HTMLInputElement*>(r.innerNonSharedNode())->isPasswordField())
data.selectedText = selectedFrame->editor()->selectedText().stripWhiteSpace();
}
if (r.isContentEditable()) {
data.isEditable = true;
#if ENABLE(INPUT_SPEECH)
if (r.innerNonSharedNode()->hasTagName(HTMLNames::inputTag)) {
data.isSpeechInputEnabled =
static_cast<HTMLInputElement*>(r.innerNonSharedNode())->isSpeechEnabled();
}
#endif
// When Chrome enables asynchronous spellchecking, its spellchecker adds spelling markers to misspelled
// words and attaches suggestions to these markers in the background. Therefore, when a user right-clicks
// a mouse on a word, Chrome just needs to find a spelling marker on the word instread of spellchecking it.
if (selectedFrame->settings() && selectedFrame->settings()->asynchronousSpellCheckingEnabled()) {
VisibleSelection selection = selectedFrame->selection()->selection();
if (selection.isCaret()) {
selection.expandUsingGranularity(WordGranularity);
RefPtr<Range> range = selection.toNormalizedRange();
Vector<DocumentMarker*> markers = selectedFrame->document()->markers()->markersInRange(range.get(), DocumentMarker::Spelling | DocumentMarker::Grammar);
if (markers.size() == 1) {
range->setStart(range->startContainer(), markers[0]->startOffset());
range->setEnd(range->endContainer(), markers[0]->endOffset());
data.misspelledWord = range->text();
if (markers[0]->description().length()) {
Vector<String> suggestions;
markers[0]->description().split('\n', suggestions);
data.dictionarySuggestions = suggestions;
} else if (m_webView->spellCheckClient()) {
int misspelledOffset, misspelledLength;
m_webView->spellCheckClient()->spellCheck(data.misspelledWord, misspelledOffset, misspelledLength, &data.dictionarySuggestions);
}
selection = VisibleSelection(range.get());
if (selectedFrame->selection()->shouldChangeSelection(selection))
selectedFrame->selection()->setSelection(selection, WordGranularity);
}
}
} else if (m_webView->focusedWebCoreFrame()->editor()->isContinuousSpellCheckingEnabled()) {
data.isSpellCheckingEnabled = true;
// Spellchecking might be enabled for the field, but could be disabled on the node.
if (m_webView->focusedWebCoreFrame()->editor()->isSpellCheckingEnabledInFocusedNode()) {
data.misspelledWord = selectMisspelledWord(defaultMenu, selectedFrame);
if (m_webView->spellCheckClient()) {
int misspelledOffset, misspelledLength;
m_webView->spellCheckClient()->spellCheck(
data.misspelledWord, misspelledOffset, misspelledLength,
&data.dictionarySuggestions);
if (!misspelledLength)
data.misspelledWord.reset();
}
示例3: checkOverflowScroll
int Frame::checkOverflowScroll(OverflowScrollAction action)
{
Position extent = selection().selection().extent();
if (extent.isNull())
return OverflowScrollNone;
RenderObject* renderer = extent.deprecatedNode()->renderer();
if (!renderer)
return OverflowScrollNone;
FrameView* view = this->view();
if (!view)
return OverflowScrollNone;
RenderBlock* containingBlock = renderer->containingBlock();
if (!containingBlock || !containingBlock->hasOverflowClip())
return OverflowScrollNone;
RenderLayer* layer = containingBlock->layer();
ASSERT(layer);
IntRect visibleRect = IntRect(view->scrollX(), view->scrollY(), view->visibleWidth(), view->visibleHeight());
IntPoint position = m_overflowAutoScrollPos;
if (visibleRect.contains(position.x(), position.y()))
return OverflowScrollNone;
int scrollType = 0;
int deltaX = 0;
int deltaY = 0;
IntPoint selectionPosition;
// This constant will make the selection draw a little bit beyond the edge of the visible area.
// This prevents a visual glitch, in that you can fail to select a portion of a character that
// is being rendered right at the edge of the visible rectangle.
// FIXME: This probably needs improvement, and may need to take the font size into account.
static const int scrollBoundsAdjustment = 3;
// FIXME: Make a small buffer at the end of a visible rectangle so that autoscrolling works
// even if the visible extends to the limits of the screen.
if (position.x() < visibleRect.x()) {
scrollType |= OverflowScrollLeft;
if (action == PerformOverflowScroll) {
deltaX -= static_cast<int>(m_overflowAutoScrollDelta);
selectionPosition.setX(view->scrollX() - scrollBoundsAdjustment);
}
} else if (position.x() > visibleRect.maxX()) {
scrollType |= OverflowScrollRight;
if (action == PerformOverflowScroll) {
deltaX += static_cast<int>(m_overflowAutoScrollDelta);
selectionPosition.setX(view->scrollX() + view->visibleWidth() + scrollBoundsAdjustment);
}
}
if (position.y() < visibleRect.y()) {
scrollType |= OverflowScrollUp;
if (action == PerformOverflowScroll) {
deltaY -= static_cast<int>(m_overflowAutoScrollDelta);
selectionPosition.setY(view->scrollY() - scrollBoundsAdjustment);
}
} else if (position.y() > visibleRect.maxY()) {
scrollType |= OverflowScrollDown;
if (action == PerformOverflowScroll) {
deltaY += static_cast<int>(m_overflowAutoScrollDelta);
selectionPosition.setY(view->scrollY() + view->visibleHeight() + scrollBoundsAdjustment);
}
}
Ref<Frame> protectedThis(*this);
if (action == PerformOverflowScroll && (deltaX || deltaY)) {
layer->scrollToOffset(layer->scrollOffset() + IntSize(deltaX, deltaY));
// Handle making selection.
VisiblePosition visiblePosition(renderer->positionForPoint(selectionPosition, nullptr));
if (visiblePosition.isNotNull()) {
VisibleSelection visibleSelection = selection().selection();
visibleSelection.setExtent(visiblePosition);
if (selection().granularity() != CharacterGranularity)
visibleSelection.expandUsingGranularity(selection().granularity());
if (selection().shouldChangeSelection(visibleSelection))
selection().setSelection(visibleSelection);
}
m_overflowAutoScrollDelta *= 1.02f; // Accelerate the scroll
}
return scrollType;
}