bool DragController::startDrag(Frame* src, const DragState& state, DragOperation srcOp, const PlatformMouseEvent& dragEvent, const IntPoint& dragOrigin) { ASSERT(src); if (!src->view() || !src->contentRenderer()) return false; HitTestResult hitTestResult = src->eventHandler()->hitTestResultAtPoint(dragOrigin, true); if (!state.m_dragSrc->contains(hitTestResult.innerNode())) // The original node being dragged isn't under the drag origin anymore... maybe it was // hidden or moved out from under the cursor. Regardless, we don't want to start a drag on // something that's not actually under the drag origin. return false; KURL linkURL = hitTestResult.absoluteLinkURL(); KURL imageURL = hitTestResult.absoluteImageURL(); IntPoint mouseDraggedPoint = src->view()->windowToContents(dragEvent.position()); m_draggingImageURL = KURL(); m_sourceDragOperation = srcOp; DragImageRef dragImage = 0; IntPoint dragLoc(0, 0); IntPoint dragImageOffset(0, 0); Clipboard* clipboard = state.m_dragClipboard.get(); if (state.m_dragType == DragSourceActionDHTML) dragImage = clipboard->createDragImage(dragImageOffset); if (state.m_dragType == DragSourceActionSelection || !imageURL.isEmpty() || !linkURL.isEmpty()) // Selection, image, and link drags receive a default set of allowed drag operations that // follows from: // http://trac.webkit.org/browser/trunk/WebKit/mac/WebView/WebHTMLView.mm?rev=48526#L3430 m_sourceDragOperation = static_cast<DragOperation>(m_sourceDragOperation | DragOperationGeneric | DragOperationCopy); // We allow DHTML/JS to set the drag image, even if its a link, image or text we're dragging. // This is in the spirit of the IE API, which allows overriding of pasteboard data and DragOp. if (dragImage) { dragLoc = dragLocForDHTMLDrag(mouseDraggedPoint, dragOrigin, dragImageOffset, !linkURL.isEmpty()); m_dragOffset = dragImageOffset; } bool startedDrag = true; // optimism - we almost always manage to start the drag Node* node = state.m_dragSrc.get(); Image* image = getImage(static_cast<Element*>(node)); if (state.m_dragType == DragSourceActionSelection) { if (!clipboard->hasData()) { if (enclosingTextFormControl(src->selection()->start())) clipboard->writePlainText(src->editor()->selectedText()); else { RefPtr<Range> selectionRange = src->selection()->toNormalizedRange(); ASSERT(selectionRange); clipboard->writeRange(selectionRange.get(), src); } } m_client->willPerformDragSourceAction(DragSourceActionSelection, dragOrigin, clipboard); if (!dragImage) { dragImage = createDragImageForSelection(src); dragLoc = dragLocForSelectionDrag(src); m_dragOffset = IntPoint(dragOrigin.x() - dragLoc.x(), dragOrigin.y() - dragLoc.y()); } doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false); } else if (!imageURL.isEmpty() && node && node->isElementNode() && image && !image->isNull() && (m_dragSourceAction & DragSourceActionImage)) { // We shouldn't be starting a drag for an image that can't provide an extension. // This is an early detection for problems encountered later upon drop. ASSERT(!image->filenameExtension().isEmpty()); Element* element = static_cast<Element*>(node); if (!clipboard->hasData()) { m_draggingImageURL = imageURL; prepareClipboardForImageDrag(src, clipboard, element, linkURL, imageURL, hitTestResult.altDisplayString()); } m_client->willPerformDragSourceAction(DragSourceActionImage, dragOrigin, clipboard); if (!dragImage) { IntRect imageRect = hitTestResult.imageRect(); imageRect.setLocation(m_page->mainFrame()->view()->rootViewToContents(src->view()->contentsToRootView(imageRect.location()))); doImageDrag(element, dragOrigin, hitTestResult.imageRect(), clipboard, src, m_dragOffset); } else // DHTML defined drag image doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false); } else if (!linkURL.isEmpty() && (m_dragSourceAction & DragSourceActionLink)) { if (!clipboard->hasData()) // Simplify whitespace so the title put on the clipboard resembles what the user sees // on the web page. This includes replacing newlines with spaces. clipboard->writeURL(linkURL, hitTestResult.textContent().simplifyWhiteSpace(), src); if (src->selection()->isCaret() && src->selection()->isContentEditable()) { // a user can initiate a drag on a link without having any text // selected. In this case, we should expand the selection to // the enclosing anchor element Position pos = src->selection()->base(); Node* node = enclosingAnchorElement(pos); if (node) src->selection()->setSelection(VisibleSelection::selectionFromContentsOfNode(node)); } m_client->willPerformDragSourceAction(DragSourceActionLink, dragOrigin, clipboard); if (!dragImage) { dragImage = createDragImageForLink(linkURL, hitTestResult.textContent(), src); IntSize size = dragImageSize(dragImage); m_dragOffset = IntPoint(-size.width() / 2, -LinkDragBorderInset); dragLoc = IntPoint(mouseDraggedPoint.x() + m_dragOffset.x(), mouseDraggedPoint.y() + m_dragOffset.y()); } doSystemDrag(dragImage, dragLoc, mouseDraggedPoint, clipboard, src, true); } else if (state.m_dragType == DragSourceActionDHTML) { ASSERT(m_dragSourceAction & DragSourceActionDHTML); m_client->willPerformDragSourceAction(DragSourceActionDHTML, dragOrigin, clipboard); doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false); } else { // draggableNode() determined an image or link node was draggable, but it turns out the // image or link had no URL, so there is nothing to drag. startedDrag = false; } if (dragImage) deleteDragImage(dragImage); return startedDrag; }
void ChromeClientQt::mouseDidMoveOverElement(const HitTestResult& result, unsigned modifierFlags) { if (result.absoluteLinkURL() != lastHoverURL || result.title() != lastHoverTitle || result.textContent() != lastHoverContent) { lastHoverURL = result.absoluteLinkURL(); lastHoverTitle = result.title(); lastHoverContent = result.textContent(); emit m_webPage->linkHovered(lastHoverURL.prettyURL(), lastHoverTitle, lastHoverContent); } }
void ChromeClientQt::mouseDidMoveOverElement(const HitTestResult& result, unsigned) { TextDirection dir; if (result.absoluteLinkURL() != lastHoverURL || result.title(dir) != lastHoverTitle || result.textContent() != lastHoverContent) { lastHoverURL = result.absoluteLinkURL(); lastHoverTitle = result.title(dir); lastHoverContent = result.textContent(); emit m_webPage->linkHovered(lastHoverURL.string(), lastHoverTitle, lastHoverContent); } }
void ChromeClientEA::mouseDidMoveOverElement(const HitTestResult& result, unsigned) { #if 0 // This could have interesting usage in UI. On PC, it is mostly used to display info in the // status panel. TextDirection dir; if (result.absoluteLinkURL() != lastHoverURL || result.title(dir) != lastHoverTitle || result.textContent() != lastHoverContent) { lastHoverURL = result.absoluteLinkURL(); lastHoverTitle = result.title(dir); lastHoverContent = result.textContent(); emit m_webPage->linkHovered(lastHoverURL.string(), lastHoverTitle, lastHoverContent); } #endif }
WebHitTestResult::Data::Data(const HitTestResult& hitTestResult) : absoluteImageURL(hitTestResult.absoluteImageURL().string()) , absolutePDFURL(hitTestResult.absolutePDFURL().string()) , absoluteLinkURL(hitTestResult.absoluteLinkURL().string()) , absoluteMediaURL(hitTestResult.absoluteMediaURL().string()) , linkLabel(hitTestResult.textContent()) , linkTitle(hitTestResult.titleDisplayString()) , isContentEditable(hitTestResult.isContentEditable()) , elementBoundingBox(elementBoundingBoxInWindowCoordinates(hitTestResult)) , isScrollbar(hitTestResult.scrollbar()) { }
bool DragController::startDrag(Frame* src, Clipboard* clipboard, DragOperation srcOp, const PlatformMouseEvent& dragEvent, const IntPoint& dragOrigin, bool isDHTMLDrag) #endif { ASSERT(src); ASSERT(clipboard); if (!src->view() || !src->renderer()) return false; HitTestResult dragSource = HitTestResult(dragOrigin); dragSource = src->eventHandler()->hitTestResultAtPoint(dragOrigin, true); KURL linkURL = dragSource.absoluteLinkURL(); KURL imageURL = dragSource.absoluteImageURL(); bool isSelected = dragSource.isSelected(); IntPoint mouseDraggedPoint = src->view()->windowToContents(dragEvent.pos()); m_draggingImageURL = KURL(); m_dragOperation = srcOp; DragImageRef dragImage = 0; IntPoint dragLoc(0, 0); IntPoint dragImageOffset(0, 0); if (isDHTMLDrag) dragImage = clipboard->createDragImage(dragImageOffset); // We allow DHTML/JS to set the drag image, even if its a link, image or text we're dragging. // This is in the spirit of the IE API, which allows overriding of pasteboard data and DragOp. if (dragImage) { dragLoc = dragLocForDHTMLDrag(mouseDraggedPoint, dragOrigin, dragImageOffset, !linkURL.isEmpty()); m_dragOffset = dragImageOffset; } bool startedDrag = true; // optimism - we almost always manage to start the drag Node* node = dragSource.innerNonSharedNode(); if (!imageURL.isEmpty() && node && node->isElementNode() && getImage(static_cast<Element*>(node)) && (m_dragSourceAction & DragSourceActionImage)) { Element* element = static_cast<Element*>(node); if (!clipboard->hasData()) { m_draggingImageURL = imageURL; prepareClipboardForImageDrag(src, clipboard, element, linkURL, imageURL, dragSource.altDisplayString()); } m_client->willPerformDragSourceAction(DragSourceActionImage, dragOrigin, clipboard); if (!dragImage) { IntRect imageRect = dragSource.imageRect(); imageRect.setLocation(m_page->mainFrame()->view()->windowToContents(src->view()->contentsToWindow(imageRect.location()))); doImageDrag(element, dragOrigin, dragSource.imageRect(), clipboard, src, m_dragOffset); } else // DHTML defined drag image doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false); } else if (!linkURL.isEmpty() && (m_dragSourceAction & DragSourceActionLink)) { if (!clipboard->hasData()) // Simplify whitespace so the title put on the clipboard resembles what the user sees // on the web page. This includes replacing newlines with spaces. clipboard->writeURL(linkURL, dragSource.textContent().simplifyWhiteSpace(), src); m_client->willPerformDragSourceAction(DragSourceActionLink, dragOrigin, clipboard); if (!dragImage) { dragImage = m_client->createDragImageForLink(linkURL, dragSource.textContent(), src); IntSize size = dragImageSize(dragImage); m_dragOffset = IntPoint(-size.width() / 2, -LinkDragBorderInset); dragLoc = IntPoint(mouseDraggedPoint.x() + m_dragOffset.x(), mouseDraggedPoint.y() + m_dragOffset.y()); } doSystemDrag(dragImage, dragLoc, mouseDraggedPoint, clipboard, src, true); } else if (isSelected && (m_dragSourceAction & DragSourceActionSelection)) { RefPtr<Range> selectionRange = src->selectionController()->toRange(); ASSERT(selectionRange); if (!clipboard->hasData()) clipboard->writeRange(selectionRange.get(), src); m_client->willPerformDragSourceAction(DragSourceActionSelection, dragOrigin, clipboard); if (!dragImage) { dragImage = createDragImageForSelection(src); dragLoc = dragLocForSelectionDrag(src); m_dragOffset = IntPoint((int)(dragOrigin.x() - dragLoc.x()), (int)(dragOrigin.y() - dragLoc.y())); } doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false); } else if (isDHTMLDrag) { ASSERT(m_dragSourceAction & DragSourceActionDHTML); m_client->willPerformDragSourceAction(DragSourceActionDHTML, dragOrigin, clipboard); doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false); } else { // Only way I know to get here is if to get here is if the original element clicked on in the mousedown is no longer // under the mousedown point, so linkURL, imageURL and isSelected are all false/empty. startedDrag = false; } if (dragImage) deleteDragImage(dragImage); return startedDrag; }
void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item) { ASSERT(item->type() == ActionType || item->type() == CheckableActionType); if (item->action() >= ContextMenuItemBaseApplicationTag) { m_client->contextMenuItemSelected(item, m_contextMenu.get()); return; } if (item->action() >= ContextMenuItemBaseCustomTag) { ASSERT(m_menuProvider); m_menuProvider->contextMenuItemSelected(item); return; } HitTestResult result = m_contextMenu->hitTestResult(); Frame* frame = result.innerNonSharedNode()->document()->frame(); if (!frame) return; switch (item->action()) { case ContextMenuItemTagOpenLinkInNewWindow: openNewWindow(result.absoluteLinkURL(), frame); break; case ContextMenuItemTagDownloadLinkToDisk: // FIXME: Some day we should be able to do this from within WebCore. m_client->downloadURL(result.absoluteLinkURL()); break; case ContextMenuItemTagCopyLinkToClipboard: frame->editor()->copyURL(result.absoluteLinkURL(), result.textContent()); break; case ContextMenuItemTagOpenImageInNewWindow: openNewWindow(result.absoluteImageURL(), frame); break; case ContextMenuItemTagDownloadImageToDisk: // FIXME: Some day we should be able to do this from within WebCore. m_client->downloadURL(result.absoluteImageURL()); break; case ContextMenuItemTagCopyImageToClipboard: // FIXME: The Pasteboard class is not written yet // For now, call into the client. This is temporary! frame->editor()->copyImage(result); break; case ContextMenuItemTagOpenMediaInNewWindow: openNewWindow(result.absoluteMediaURL(), frame); break; case ContextMenuItemTagCopyMediaLinkToClipboard: frame->editor()->copyURL(result.absoluteMediaURL(), result.textContent()); break; case ContextMenuItemTagToggleMediaControls: result.toggleMediaControlsDisplay(); break; case ContextMenuItemTagToggleMediaLoop: result.toggleMediaLoopPlayback(); break; case ContextMenuItemTagEnterVideoFullscreen: result.enterFullscreenForVideo(); break; case ContextMenuItemTagMediaPlayPause: result.toggleMediaPlayState(); break; case ContextMenuItemTagMediaMute: result.toggleMediaMuteState(); break; case ContextMenuItemTagOpenFrameInNewWindow: { DocumentLoader* loader = frame->loader()->documentLoader(); if (!loader->unreachableURL().isEmpty()) openNewWindow(loader->unreachableURL(), frame); else openNewWindow(loader->url(), frame); break; } case ContextMenuItemTagCopy: frame->editor()->copy(); break; case ContextMenuItemTagGoBack: if (Page* page = frame->page()) page->goBackOrForward(-1); break; case ContextMenuItemTagGoForward: if (Page* page = frame->page()) page->goBackOrForward(1); break; case ContextMenuItemTagStop: frame->loader()->stop(); break; case ContextMenuItemTagReload: frame->loader()->reload(); break; case ContextMenuItemTagCut: frame->editor()->cut(); break; case ContextMenuItemTagPaste: frame->editor()->paste(); break; #if PLATFORM(GTK) case ContextMenuItemTagDelete: frame->editor()->performDelete(); break; case ContextMenuItemTagSelectAll: frame->editor()->command("SelectAll").execute(); break; #endif case ContextMenuItemTagSpellingGuess: ASSERT(frame->editor()->selectedText().length()); if (frame->editor()->shouldInsertText(item->title(), frame->selection()->toNormalizedRange().get(), EditorInsertActionPasted)) { Document* document = frame->document(); RefPtr<ReplaceSelectionCommand> command = ReplaceSelectionCommand::create(document, createFragmentFromMarkup(document, item->title(), ""), true, false, true); applyCommand(command); frame->selection()->revealSelection(ScrollAlignment::alignToEdgeIfNeeded); } break; case ContextMenuItemTagIgnoreSpelling: frame->editor()->ignoreSpelling(); break; case ContextMenuItemTagLearnSpelling: frame->editor()->learnSpelling(); break; case ContextMenuItemTagSearchWeb: m_client->searchWithGoogle(frame); break; case ContextMenuItemTagLookUpInDictionary: // FIXME: Some day we may be able to do this from within WebCore. m_client->lookUpInDictionary(frame); break; case ContextMenuItemTagOpenLink: if (Frame* targetFrame = result.targetFrame()) targetFrame->loader()->loadFrameRequest(FrameLoadRequest(ResourceRequest(result.absoluteLinkURL(), frame->loader()->outgoingReferrer())), false, false, 0, 0, SendReferrer); else openNewWindow(result.absoluteLinkURL(), frame); break; case ContextMenuItemTagBold: frame->editor()->command("ToggleBold").execute(); break; case ContextMenuItemTagItalic: frame->editor()->command("ToggleItalic").execute(); break; case ContextMenuItemTagUnderline: frame->editor()->toggleUnderline(); break; case ContextMenuItemTagOutline: // We actually never enable this because CSS does not have a way to specify an outline font, // which may make this difficult to implement. Maybe a special case of text-shadow? break; case ContextMenuItemTagStartSpeaking: { ExceptionCode ec; RefPtr<Range> selectedRange = frame->selection()->toNormalizedRange(); if (!selectedRange || selectedRange->collapsed(ec)) { Document* document = result.innerNonSharedNode()->document(); selectedRange = document->createRange(); selectedRange->selectNode(document->documentElement(), ec); } m_client->speak(plainText(selectedRange.get())); break; } case ContextMenuItemTagStopSpeaking: m_client->stopSpeaking(); break; case ContextMenuItemTagDefaultDirection: frame->editor()->setBaseWritingDirection(NaturalWritingDirection); break; case ContextMenuItemTagLeftToRight: frame->editor()->setBaseWritingDirection(LeftToRightWritingDirection); break; case ContextMenuItemTagRightToLeft: frame->editor()->setBaseWritingDirection(RightToLeftWritingDirection); break; case ContextMenuItemTagTextDirectionDefault: frame->editor()->command("MakeTextWritingDirectionNatural").execute(); break; case ContextMenuItemTagTextDirectionLeftToRight: frame->editor()->command("MakeTextWritingDirectionLeftToRight").execute(); break; case ContextMenuItemTagTextDirectionRightToLeft: frame->editor()->command("MakeTextWritingDirectionRightToLeft").execute(); break; #if PLATFORM(MAC) case ContextMenuItemTagSearchInSpotlight: m_client->searchWithSpotlight(); break; #endif case ContextMenuItemTagShowSpellingPanel: frame->editor()->showSpellingGuessPanel(); break; case ContextMenuItemTagCheckSpelling: frame->editor()->advanceToNextMisspelling(); break; case ContextMenuItemTagCheckSpellingWhileTyping: frame->editor()->toggleContinuousSpellChecking(); break; #ifndef BUILDING_ON_TIGER case ContextMenuItemTagCheckGrammarWithSpelling: frame->editor()->toggleGrammarChecking(); break; #endif #if PLATFORM(MAC) case ContextMenuItemTagShowFonts: frame->editor()->showFontPanel(); break; case ContextMenuItemTagStyles: frame->editor()->showStylesPanel(); break; case ContextMenuItemTagShowColors: frame->editor()->showColorPanel(); break; #endif #if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) case ContextMenuItemTagMakeUpperCase: frame->editor()->uppercaseWord(); break; case ContextMenuItemTagMakeLowerCase: frame->editor()->lowercaseWord(); break; case ContextMenuItemTagCapitalize: frame->editor()->capitalizeWord(); break; case ContextMenuItemTagShowSubstitutions: frame->editor()->showSubstitutionsPanel(); break; case ContextMenuItemTagSmartCopyPaste: frame->editor()->toggleSmartInsertDelete(); break; case ContextMenuItemTagSmartQuotes: frame->editor()->toggleAutomaticQuoteSubstitution(); break; case ContextMenuItemTagSmartDashes: frame->editor()->toggleAutomaticDashSubstitution(); break; case ContextMenuItemTagSmartLinks: frame->editor()->toggleAutomaticLinkDetection(); break; case ContextMenuItemTagTextReplacement: frame->editor()->toggleAutomaticTextReplacement(); break; case ContextMenuItemTagCorrectSpellingAutomatically: frame->editor()->toggleAutomaticSpellingCorrection(); break; case ContextMenuItemTagChangeBack: frame->editor()->changeBackToReplacedString(result.replacedString()); break; #endif #if ENABLE(INSPECTOR) case ContextMenuItemTagInspectElement: if (Page* page = frame->page()) page->inspectorController()->inspect(result.innerNonSharedNode()); break; #endif default: break; } }
void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item) { ASSERT(item->type() == ActionType || item->type() == CheckableActionType); if (item->action() >= ContextMenuItemBaseApplicationTag) { m_client->contextMenuItemSelected(item, m_contextMenu.get()); return; } HitTestResult result = m_contextMenu->hitTestResult(); Frame* frame = result.innerNonSharedNode()->document()->frame(); if (!frame) return; switch (item->action()) { case ContextMenuItemTagOpenLinkInNewWindow: openNewWindow(result.absoluteLinkURL(), frame); break; case ContextMenuItemTagDownloadLinkToDisk: // FIXME: Some day we should be able to do this from within WebCore. m_client->downloadURL(result.absoluteLinkURL()); break; case ContextMenuItemTagCopyLinkToClipboard: frame->editor()->copyURL(result.absoluteLinkURL(), result.textContent()); break; case ContextMenuItemTagOpenImageInNewWindow: openNewWindow(result.absoluteImageURL(), frame); break; case ContextMenuItemTagDownloadImageToDisk: // FIXME: Some day we should be able to do this from within WebCore. m_client->downloadURL(result.absoluteImageURL()); break; case ContextMenuItemTagCopyImageToClipboard: // FIXME: The Pasteboard class is not written yet // For now, call into the client. This is temporary! frame->editor()->copyImage(result); break; case ContextMenuItemTagOpenFrameInNewWindow: { DocumentLoader* loader = frame->loader()->documentLoader(); if (!loader->unreachableURL().isEmpty()) openNewWindow(loader->unreachableURL(), frame); else openNewWindow(loader->url(), frame); break; } case ContextMenuItemTagCopy: frame->editor()->copy(); break; case ContextMenuItemTagGoBack: frame->loader()->goBackOrForward(-1); break; case ContextMenuItemTagGoForward: frame->loader()->goBackOrForward(1); break; case ContextMenuItemTagStop: frame->loader()->stop(); break; case ContextMenuItemTagReload: frame->loader()->reload(); break; case ContextMenuItemTagCut: frame->editor()->cut(); break; case ContextMenuItemTagPaste: frame->editor()->paste(); break; #if PLATFORM(GTK) || PLATFORM(BAL) case ContextMenuItemTagDelete: frame->editor()->performDelete(); break; case ContextMenuItemTagSelectAll: frame->editor()->command("SelectAll").execute(); break; #endif case ContextMenuItemTagSpellingGuess: ASSERT(frame->selectedText().length()); if (frame->editor()->shouldInsertText(item->title(), frame->selection()->toRange().get(), EditorInsertActionPasted)) { Document* document = frame->document(); RefPtr<ReplaceSelectionCommand> command = ReplaceSelectionCommand::create(document, createFragmentFromMarkup(document, item->title(), ""), true, false, true); applyCommand(command); frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded); } break; case ContextMenuItemTagIgnoreSpelling: frame->editor()->ignoreSpelling(); break; case ContextMenuItemTagLearnSpelling: frame->editor()->learnSpelling(); break; case ContextMenuItemTagSearchWeb: m_client->searchWithGoogle(frame); break; case ContextMenuItemTagLookUpInDictionary: // FIXME: Some day we may be able to do this from within WebCore. m_client->lookUpInDictionary(frame); break; case ContextMenuItemTagOpenLink: if (Frame* targetFrame = result.targetFrame()) targetFrame->loader()->loadFrameRequestWithFormAndValues(FrameLoadRequest(ResourceRequest(result.absoluteLinkURL(), frame->loader()->outgoingReferrer())), false, 0, 0, HashMap<String, String>()); else openNewWindow(result.absoluteLinkURL(), frame); break; case ContextMenuItemTagBold: frame->editor()->command("ToggleBold").execute(); break; case ContextMenuItemTagItalic: frame->editor()->command("ToggleItalic").execute(); break; case ContextMenuItemTagUnderline: frame->editor()->toggleUnderline(); break; case ContextMenuItemTagOutline: // We actually never enable this because CSS does not have a way to specify an outline font, // which may make this difficult to implement. Maybe a special case of text-shadow? break; case ContextMenuItemTagStartSpeaking: { ExceptionCode ec; RefPtr<Range> selectedRange = frame->selection()->toRange(); if (!selectedRange || selectedRange->collapsed(ec)) { Document* document = result.innerNonSharedNode()->document(); selectedRange = document->createRange(); selectedRange->selectNode(document->documentElement(), ec); } m_client->speak(plainText(selectedRange.get())); break; } case ContextMenuItemTagStopSpeaking: m_client->stopSpeaking(); break; case ContextMenuItemTagDefaultDirection: frame->editor()->setBaseWritingDirection(NaturalWritingDirection); break; case ContextMenuItemTagLeftToRight: frame->editor()->setBaseWritingDirection(LeftToRightWritingDirection); break; case ContextMenuItemTagRightToLeft: frame->editor()->setBaseWritingDirection(RightToLeftWritingDirection); break; #if PLATFORM(MAC) case ContextMenuItemTagSearchInSpotlight: m_client->searchWithSpotlight(); break; #endif case ContextMenuItemTagShowSpellingPanel: frame->editor()->showSpellingGuessPanel(); break; case ContextMenuItemTagCheckSpelling: frame->editor()->advanceToNextMisspelling(); break; case ContextMenuItemTagCheckSpellingWhileTyping: frame->editor()->toggleContinuousSpellChecking(); break; #ifndef BUILDING_ON_TIGER case ContextMenuItemTagCheckGrammarWithSpelling: frame->editor()->toggleGrammarChecking(); break; #endif #if PLATFORM(MAC) case ContextMenuItemTagShowFonts: frame->editor()->showFontPanel(); break; case ContextMenuItemTagStyles: frame->editor()->showStylesPanel(); break; case ContextMenuItemTagShowColors: frame->editor()->showColorPanel(); break; #endif case ContextMenuItemTagInspectElement: if (Page* page = frame->page()) page->inspectorController()->inspect(result.innerNonSharedNode()); break; default: break; } }
bool DragController::startDrag(Frame* src, Clipboard* clipboard, DragOperation srcOp, const PlatformMouseEvent& dragEvent, const IntPoint& dragOrigin, bool isDHTMLDrag) { ASSERT(src); ASSERT(clipboard); if (!src->view() || !src->contentRenderer()) return false; HitTestResult dragSource = HitTestResult(dragOrigin); dragSource = src->eventHandler()->hitTestResultAtPoint(dragOrigin, true); KURL linkURL = dragSource.absoluteLinkURL(); KURL imageURL = dragSource.absoluteImageURL(); bool isSelected = dragSource.isSelected(); IntPoint mouseDraggedPoint = src->view()->windowToContents(dragEvent.pos()); m_draggingImageURL = KURL(); m_sourceDragOperation = srcOp; DragImageRef dragImage = 0; IntPoint dragLoc(0, 0); IntPoint dragImageOffset(0, 0); if (isDHTMLDrag) dragImage = clipboard->createDragImage(dragImageOffset); else { // This drag operation is not a DHTML drag and may go outside the WebView. // We provide a default set of allowed drag operations that follows from: // http://trac.webkit.org/browser/trunk/WebKit/mac/WebView/WebHTMLView.mm?rev=48526#L3430 m_sourceDragOperation = (DragOperation)(DragOperationGeneric | DragOperationCopy); } // We allow DHTML/JS to set the drag image, even if its a link, image or text we're dragging. // This is in the spirit of the IE API, which allows overriding of pasteboard data and DragOp. if (dragImage) { dragLoc = dragLocForDHTMLDrag(mouseDraggedPoint, dragOrigin, dragImageOffset, !linkURL.isEmpty()); m_dragOffset = dragImageOffset; } bool startedDrag = true; // optimism - we almost always manage to start the drag Node* node = dragSource.innerNonSharedNode(); Image* image = getImage(static_cast<Element*>(node)); if (!imageURL.isEmpty() && node && node->isElementNode() && image && (m_dragSourceAction & DragSourceActionImage)) { // We shouldn't be starting a drag for an image that can't provide an extension. // This is an early detection for problems encountered later upon drop. ASSERT(!image->filenameExtension().isEmpty()); Element* element = static_cast<Element*>(node); if (!clipboard->hasData()) { m_draggingImageURL = imageURL; prepareClipboardForImageDrag(src, clipboard, element, linkURL, imageURL, dragSource.altDisplayString()); } m_client->willPerformDragSourceAction(DragSourceActionImage, dragOrigin, clipboard); if (!dragImage) { IntRect imageRect = dragSource.imageRect(); imageRect.setLocation(m_page->mainFrame()->view()->windowToContents(src->view()->contentsToWindow(imageRect.location()))); doImageDrag(element, dragOrigin, dragSource.imageRect(), clipboard, src, m_dragOffset); } else // DHTML defined drag image doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false); } else if (!linkURL.isEmpty() && (m_dragSourceAction & DragSourceActionLink)) { if (!clipboard->hasData()) // Simplify whitespace so the title put on the clipboard resembles what the user sees // on the web page. This includes replacing newlines with spaces. clipboard->writeURL(linkURL, dragSource.textContent().simplifyWhiteSpace(), src); if (src->selection()->isCaret() && src->selection()->isContentEditable()) { // a user can initiate a drag on a link without having any text // selected. In this case, we should expand the selection to // the enclosing anchor element Position pos = src->selection()->base(); Node* node = enclosingAnchorElement(pos); if (node) src->selection()->setSelection(VisibleSelection::selectionFromContentsOfNode(node)); } m_client->willPerformDragSourceAction(DragSourceActionLink, dragOrigin, clipboard); if (!dragImage) { dragImage = m_client->createDragImageForLink(linkURL, dragSource.textContent(), src); IntSize size = dragImageSize(dragImage); m_dragOffset = IntPoint(-size.width() / 2, -LinkDragBorderInset); dragLoc = IntPoint(mouseDraggedPoint.x() + m_dragOffset.x(), mouseDraggedPoint.y() + m_dragOffset.y()); } doSystemDrag(dragImage, dragLoc, mouseDraggedPoint, clipboard, src, true); } else if (isSelected && (m_dragSourceAction & DragSourceActionSelection)) { RefPtr<Range> selectionRange = src->selection()->toNormalizedRange(); ASSERT(selectionRange); if (!clipboard->hasData()) clipboard->writeRange(selectionRange.get(), src); m_client->willPerformDragSourceAction(DragSourceActionSelection, dragOrigin, clipboard); if (!dragImage) { dragImage = createDragImageForSelection(src); dragLoc = dragLocForSelectionDrag(src); m_dragOffset = IntPoint((int)(dragOrigin.x() - dragLoc.x()), (int)(dragOrigin.y() - dragLoc.y())); } doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false); } else if (isDHTMLDrag) { ASSERT(m_dragSourceAction & DragSourceActionDHTML); m_client->willPerformDragSourceAction(DragSourceActionDHTML, dragOrigin, clipboard); doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false); } else { // Only way I know to get here is if to get here is if the original element clicked on in the mousedown is no longer // under the mousedown point, so linkURL, imageURL and isSelected are all false/empty. startedDrag = false; } if (dragImage) deleteDragImage(dragImage); return startedDrag; }