Changeset 46330 in webkit
- Timestamp:
- Jul 24, 2009 12:44:59 AM (15 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r46329 r46330 1 2009-07-24 Mike Fenton <mike.fenton@torchmobile.com> 2 3 Reviewed by Eric Seidel. 4 5 Update WebCore/page/DOMTimer.cpp/h to conform to WebKit 6 Style Guidelines as identified by cpplint.py. 7 https://bugs.webkit.org/show_bug.cgi?id=27624 8 9 * page/DragController.cpp: 10 (WebCore::DragController::~DragController): 11 (WebCore::documentFragmentFromDragData): 12 (WebCore::DragController::dragEnded): 13 (WebCore::DragController::dragEntered): 14 (WebCore::DragController::dragExited): 15 (WebCore::DragController::dragUpdated): 16 (WebCore::DragController::performDrag): 17 (WebCore::asFileInput): 18 (WebCore::DragController::tryDocumentDrag): 19 (WebCore::DragController::delegateDragSourceAction): 20 (WebCore::DragController::concludeEditDrag): 21 (WebCore::DragController::canProcessDrag): 22 (WebCore::DragController::tryDHTMLDrag): 23 (WebCore::DragController::mayStartDragAtEventLocation): 24 (WebCore::getCachedImage): 25 (WebCore::getImage): 26 (WebCore::prepareClipboardForImageDrag): 27 (WebCore::dragLocForDHTMLDrag): 28 (WebCore::DragController::startDrag): 29 (WebCore::DragController::doImageDrag): 30 (WebCore::DragController::doSystemDrag): 31 (WebCore::DragController::placeDragCaret): 32 1 33 2009-07-24 Mike Fenton <mike.fenton@torchmobile.com> 2 34 -
trunk/WebCore/page/DragController.cpp
r45065 r46330 73 73 74 74 } 75 75 76 76 DragController::DragController(Page* page, DragClient* client) 77 77 : m_page(page) … … 86 86 { 87 87 } 88 88 89 89 DragController::~DragController() 90 { 90 { 91 91 m_client->dragControllerDestroyed(); 92 92 } 93 93 94 94 static PassRefPtr<DocumentFragment> documentFragmentFromDragData(DragData* dragData, RefPtr<Range> context, 95 95 bool allowPlainText, bool& chosePlainText) … … 123 123 return createFragmentFromText(context.get(), dragData->asPlainText()).get(); 124 124 } 125 125 126 126 return 0; 127 127 } … … 141 141 { 142 142 m_dragInitiator = 0; 143 m_didInitiateDrag = false; 144 m_page->dragCaretController()->clear(); 145 } 146 147 DragOperation DragController::dragEntered(DragData* dragData) 143 m_didInitiateDrag = false; 144 m_page->dragCaretController()->clear(); 145 } 146 147 DragOperation DragController::dragEntered(DragData* dragData) 148 148 { 149 149 return dragEnteredOrUpdated(dragData); 150 150 } 151 152 void DragController::dragExited(DragData* dragData) 153 { 151 152 void DragController::dragExited(DragData* dragData) 153 { 154 154 ASSERT(dragData); 155 155 Frame* mainFrame = m_page->mainFrame(); 156 156 157 157 if (RefPtr<FrameView> v = mainFrame->view()) { 158 158 ClipboardAccessPolicy policy = (!m_documentUnderMouse || m_documentUnderMouse->securityOrigin()->isLocal()) ? ClipboardReadable : ClipboardTypesReadable; … … 165 165 } 166 166 167 168 DragOperation DragController::dragUpdated(DragData* dragData) 167 DragOperation DragController::dragUpdated(DragData* dragData) 169 168 { 170 169 return dragEnteredOrUpdated(dragData); 171 170 } 172 171 173 172 bool DragController::performDrag(DragData* dragData) 174 { 173 { 175 174 ASSERT(dragData); 176 175 m_documentUnderMouse = m_page->mainFrame()->documentAtPoint(dragData->clientPosition()); … … 188 187 m_documentUnderMouse = 0; 189 188 return true; 190 } 191 189 } 190 192 191 if ((m_dragDestinationAction & DragDestinationActionEdit) && concludeEditDrag(dragData)) { 193 192 m_documentUnderMouse = 0; 194 193 return true; 195 194 } 196 195 197 196 m_documentUnderMouse = 0; 198 197 … … 238 237 { 239 238 ASSERT(node); 240 239 241 240 // The button for a FILE input is a sub element with no set input type 242 241 // In order to get around this problem we assume any non-FILE input element … … 244 243 if (node->hasTagName(HTMLNames::inputTag) && node->isShadowNode() && static_cast<HTMLInputElement*>(node)->inputType() != HTMLInputElement::FILE) 245 244 node = node->shadowParentNode(); 246 245 247 246 if (!node || !node->hasTagName(HTMLNames::inputTag)) 248 247 return 0; 249 248 250 249 HTMLInputElement* inputElem = static_cast<HTMLInputElement*>(node); 251 250 if (inputElem->inputType() == HTMLInputElement::FILE) 252 251 return inputElem; 253 252 254 253 return 0; 255 254 } 256 255 257 256 bool DragController::tryDocumentDrag(DragData* dragData, DragDestinationAction actionMask, DragOperation& operation) 258 257 { 259 258 ASSERT(dragData); 260 259 261 260 if (!m_documentUnderMouse) 262 261 return false; 263 262 264 263 m_isHandlingDrag = false; 265 264 if (actionMask & DragDestinationActionDHTML) { … … 290 289 return true; 291 290 } 292 291 293 292 IntPoint dragPos = dragData->clientPosition(); 294 293 IntPoint point = frameView->windowToContents(dragPos); … … 308 307 309 308 DragSourceAction DragController::delegateDragSourceAction(const IntPoint& windowPoint) 310 { 309 { 311 310 m_dragSourceAction = m_client->dragSourceActionMaskForPoint(windowPoint); 312 311 return m_dragSourceAction; 313 312 } 314 313 315 314 DragOperation DragController::operationForLoad(DragData* dragData) 316 315 { … … 337 336 ASSERT(dragData); 338 337 ASSERT(!m_isHandlingDrag); 339 338 340 339 if (!m_documentUnderMouse) 341 340 return false; 342 341 343 342 IntPoint point = m_documentUnderMouse->view()->windowToContents(dragData->clientPosition()); 344 343 Element* element = m_documentUnderMouse->elementFromPoint(point.x(), point.y()); 345 344 ASSERT(element); 346 345 Frame* innerFrame = element->ownerDocument()->frame(); 347 ASSERT(innerFrame); 346 ASSERT(innerFrame); 348 347 349 348 if (dragData->containsColor()) { … … 363 362 return true; 364 363 } 365 364 366 365 if (!m_page->dragController()->canProcessDrag(dragData)) { 367 366 m_page->dragCaretController()->clear(); 368 367 return false; 369 368 } 370 369 371 370 if (HTMLInputElement* fileInput = asFileInput(element)) { 372 371 if (!fileInput->isEnabledFormControl()) 373 372 return false; 374 373 375 374 if (!dragData->containsFiles()) 376 375 return false; 377 376 378 377 Vector<String> filenames; 379 378 dragData->asFilenames(filenames); 380 379 if (filenames.isEmpty()) 381 380 return false; 382 383 // Ugly. For security none of the API's available to us to set the input value 381 382 // Ugly. For security none of the API's available to us to set the input value 384 383 // on file inputs. Even forcing a change in HTMLInputElement doesn't work as 385 384 // RenderFileUploadControl clears the file when doing updateFromElement() 386 385 RenderFileUploadControl* renderer = static_cast<RenderFileUploadControl*>(fileInput->renderer()); 387 386 388 387 if (!renderer) 389 388 return false; 390 389 391 390 renderer->receiveDroppedFiles(filenames); 392 391 return true; … … 396 395 m_page->dragCaretController()->clear(); 397 396 RefPtr<Range> range = dragCaret.toNormalizedRange(); 398 397 399 398 // For range to be null a WebKit client must have done something bad while 400 399 // manually controlling drag behaviour 401 if (!range) 400 if (!range) 402 401 return false; 403 402 DocLoader* loader = range->ownerDocument()->docLoader(); 404 403 loader->setAllowStaleResources(true); 405 if (dragIsMove(innerFrame->selection()) || dragCaret.isContentRichlyEditable()) { 404 if (dragIsMove(innerFrame->selection()) || dragCaret.isContentRichlyEditable()) { 406 405 bool chosePlainText = false; 407 406 RefPtr<DocumentFragment> fragment = documentFragmentFromDragData(dragData, range, true, chosePlainText); … … 410 409 return false; 411 410 } 412 411 413 412 m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData); 414 413 if (dragIsMove(innerFrame->selection())) { 415 bool smartMove = innerFrame->selectionGranularity() == WordGranularity 416 && innerFrame->editor()->smartInsertDeleteEnabled() 414 bool smartMove = innerFrame->selectionGranularity() == WordGranularity 415 && innerFrame->editor()->smartInsertDeleteEnabled() 417 416 && dragData->canSmartReplace(); 418 417 applyCommand(MoveSelectionCommand::create(fragment, dragCaret.base(), smartMove)); 419 418 } else { 420 419 if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) 421 applyCommand(ReplaceSelectionCommand::create(m_documentUnderMouse, fragment, true, dragData->canSmartReplace(), chosePlainText)); 422 } 420 applyCommand(ReplaceSelectionCommand::create(m_documentUnderMouse, fragment, true, dragData->canSmartReplace(), chosePlainText)); 421 } 423 422 } else { 424 423 String text = dragData->asPlainText(); … … 427 426 return false; 428 427 } 429 428 430 429 m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData); 431 430 if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) 432 applyCommand(ReplaceSelectionCommand::create(m_documentUnderMouse, createFragmentFromText(range.get(), text), true, false, true)); 431 applyCommand(ReplaceSelectionCommand::create(m_documentUnderMouse, createFragmentFromText(range.get(), text), true, false, true)); 433 432 } 434 433 loader->setAllowStaleResources(false); … … 436 435 return true; 437 436 } 438 439 440 bool DragController::canProcessDrag(DragData* dragData) 437 438 bool DragController::canProcessDrag(DragData* dragData) 441 439 { 442 440 ASSERT(dragData); … … 444 442 if (!dragData->containsCompatibleContent()) 445 443 return false; 446 444 447 445 IntPoint point = m_page->mainFrame()->view()->windowToContents(dragData->clientPosition()); 448 446 HitTestResult result = HitTestResult(point); … … 451 449 452 450 result = m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(point, true); 453 454 if (!result.innerNonSharedNode()) 455 return false; 456 451 452 if (!result.innerNonSharedNode()) 453 return false; 454 457 455 if (dragData->containsFiles() && asFileInput(result.innerNonSharedNode())) 458 456 return true; 459 457 460 458 if (!result.innerNonSharedNode()->isContentEditable()) 461 459 return false; 462 460 463 461 if (m_didInitiateDrag && m_documentUnderMouse == m_dragInitiator && result.isSelected()) 464 462 return false; … … 483 481 484 482 bool DragController::tryDHTMLDrag(DragData* dragData, DragOperation& operation) 485 { 483 { 486 484 ASSERT(dragData); 487 485 ASSERT(m_documentUnderMouse); … … 526 524 mouseDownTarget = frame->eventHandler()->hitTestResultAtPoint(framePos, true); 527 525 528 if (mouseDownTarget.image() 526 if (mouseDownTarget.image() 529 527 && !mouseDownTarget.absoluteImageURL().isEmpty() 530 528 && frame->settings()->loadsImagesAutomatically() … … 544 542 545 543 } 546 544 547 545 static CachedImage* getCachedImage(Element* element) 548 546 { 549 547 ASSERT(element); 550 548 RenderObject* renderer = element->renderer(); 551 if (!renderer || !renderer->isImage()) 549 if (!renderer || !renderer->isImage()) 552 550 return 0; 553 551 RenderImage* image = toRenderImage(renderer); 554 552 return image->cachedImage(); 555 553 } 556 554 557 555 static Image* getImage(Element* element) 558 556 { 559 557 ASSERT(element); 560 558 RenderObject* renderer = element->renderer(); 561 if (!renderer || !renderer->isImage()) 559 if (!renderer || !renderer->isImage()) 562 560 return 0; 563 561 564 562 RenderImage* image = toRenderImage(renderer); 565 563 if (image->cachedImage() && !image->cachedImage()->errorOccurred()) … … 567 565 return 0; 568 566 } 569 567 570 568 static void prepareClipboardForImageDrag(Frame* src, Clipboard* clipboard, Element* node, const KURL& linkURL, const KURL& imageURL, const String& label) 571 569 { … … 573 571 ExceptionCode ec = 0; 574 572 range->selectNode(node, ec); 575 ASSERT( ec == 0);576 src->selection()->setSelection(VisibleSelection(range.get(), DOWNSTREAM)); 573 ASSERT(!ec); 574 src->selection()->setSelection(VisibleSelection(range.get(), DOWNSTREAM)); 577 575 clipboard->declareAndWriteDragImage(node, !linkURL.isEmpty() ? linkURL : imageURL, label, src); 578 576 } 579 577 580 578 static IntPoint dragLocForDHTMLDrag(const IntPoint& mouseDraggedPoint, const IntPoint& dragOrigin, const IntPoint& dragImageOffset, bool isLinkImage) 581 579 { 582 580 // dragImageOffset is the cursor position relative to the lower-left corner of the image. 583 #if PLATFORM(MAC) 584 // We add in the Y dimension because we are a flipped view, so adding moves the image down. 581 #if PLATFORM(MAC) 582 // We add in the Y dimension because we are a flipped view, so adding moves the image down. 585 583 const int yOffset = dragImageOffset.y(); 586 584 #else 587 585 const int yOffset = -dragImageOffset.y(); 588 586 #endif 589 587 590 588 if (isLinkImage) 591 589 return IntPoint(mouseDraggedPoint.x() - dragImageOffset.x(), mouseDraggedPoint.y() + yOffset); 592 590 593 591 return IntPoint(dragOrigin.x() - dragImageOffset.x(), dragOrigin.y() + yOffset); 594 592 } 595 593 596 594 static IntPoint dragLocForSelectionDrag(Frame* src) 597 595 { … … 608 606 return IntPoint(xpos, ypos); 609 607 } 610 608 611 609 bool DragController::startDrag(Frame* src, Clipboard* clipboard, DragOperation srcOp, const PlatformMouseEvent& dragEvent, const IntPoint& dragOrigin, bool isDHTMLDrag) 612 { 610 { 613 611 ASSERT(src); 614 612 ASSERT(clipboard); 615 613 616 614 if (!src->view() || !src->contentRenderer()) 617 615 return false; 618 616 619 617 HitTestResult dragSource = HitTestResult(dragOrigin); 620 618 dragSource = src->eventHandler()->hitTestResultAtPoint(dragOrigin, true); … … 622 620 KURL imageURL = dragSource.absoluteImageURL(); 623 621 bool isSelected = dragSource.isSelected(); 624 622 625 623 IntPoint mouseDraggedPoint = src->view()->windowToContents(dragEvent.pos()); 626 624 627 625 m_draggingImageURL = KURL(); 628 626 m_sourceDragOperation = srcOp; 629 627 630 628 DragImageRef dragImage = 0; 631 629 IntPoint dragLoc(0, 0); 632 630 IntPoint dragImageOffset(0, 0); 633 634 if (isDHTMLDrag) 631 632 if (isDHTMLDrag) 635 633 dragImage = clipboard->createDragImage(dragImageOffset); 636 634 637 635 // We allow DHTML/JS to set the drag image, even if its a link, image or text we're dragging. 638 636 // This is in the spirit of the IE API, which allows overriding of pasteboard data and DragOp. … … 641 639 m_dragOffset = dragImageOffset; 642 640 } 643 641 644 642 bool startedDrag = true; // optimism - we almost always manage to start the drag 645 643 646 644 Node* node = dragSource.innerNonSharedNode(); 647 645 648 646 Image* image = getImage(static_cast<Element*>(node)); 649 647 if (!imageURL.isEmpty() && node && node->isElementNode() && image 650 648 && (m_dragSourceAction & DragSourceActionImage)) { 651 // We shouldn't be starting a drag for an image that can't provide an extension. 649 // We shouldn't be starting a drag for an image that can't provide an extension. 652 650 // This is an early detection for problems encountered later upon drop. 653 651 ASSERT(!image->filenameExtension().isEmpty()); 654 652 Element* element = static_cast<Element*>(node); 655 653 if (!clipboard->hasData()) { 656 m_draggingImageURL = imageURL; 654 m_draggingImageURL = imageURL; 657 655 prepareClipboardForImageDrag(src, clipboard, element, linkURL, imageURL, dragSource.altDisplayString()); 658 656 } 659 657 660 658 m_client->willPerformDragSourceAction(DragSourceActionImage, dragOrigin, clipboard); 661 659 662 660 if (!dragImage) { 663 661 IntRect imageRect = dragSource.imageRect(); 664 662 imageRect.setLocation(m_page->mainFrame()->view()->windowToContents(src->view()->contentsToWindow(imageRect.location()))); 665 663 doImageDrag(element, dragOrigin, dragSource.imageRect(), clipboard, src, m_dragOffset); 666 } else 664 } else 667 665 // DHTML defined drag image 668 666 doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false); … … 690 688 m_dragOffset = IntPoint(-size.width() / 2, -LinkDragBorderInset); 691 689 dragLoc = IntPoint(mouseDraggedPoint.x() + m_dragOffset.x(), mouseDraggedPoint.y() + m_dragOffset.y()); 692 } 690 } 693 691 doSystemDrag(dragImage, dragLoc, mouseDraggedPoint, clipboard, src, true); 694 692 } else if (isSelected && (m_dragSourceAction & DragSourceActionSelection)) { 695 693 RefPtr<Range> selectionRange = src->selection()->toNormalizedRange(); 696 694 ASSERT(selectionRange); 697 if (!clipboard->hasData()) 695 if (!clipboard->hasData()) 698 696 clipboard->writeRange(selectionRange.get(), src); 699 697 m_client->willPerformDragSourceAction(DragSourceActionSelection, dragOrigin, clipboard); … … 713 711 startedDrag = false; 714 712 } 715 713 716 714 if (dragImage) 717 715 deleteDragImage(dragImage); … … 724 722 DragImageRef dragImage; 725 723 IntPoint origin; 726 724 727 725 Image* image = getImage(element); 728 726 if (image && image->size().height() * image->size().width() <= MaxOriginalImageArea … … 730 728 IntSize originalSize = rect.size(); 731 729 origin = rect.location(); 732 730 733 731 dragImage = fitDragImageToMaxSize(dragImage, rect.size(), maxDragImageSize()); 734 732 dragImage = dissolveDragImageToFraction(dragImage, DragImageAlpha); 735 733 IntSize newSize = dragImageSize(dragImage); 736 734 737 735 // Properly orient the drag image and orient it differently if it's smaller than the original 738 736 float scale = newSize.width() / (float)originalSize.width(); … … 752 750 origin = IntPoint(DragIconRightInset - dragImageSize(dragImage).width(), DragIconBottomInset); 753 751 } 754 752 755 753 dragImageOffset.setX(mouseDownPoint.x() + origin.x()); 756 754 dragImageOffset.setY(mouseDownPoint.y() + origin.y()); 757 755 doSystemDrag(dragImage, dragImageOffset, dragOrigin, clipboard, frame, false); 758 756 759 757 deleteDragImage(dragImage); 760 758 } 761 759 762 760 void DragController::doSystemDrag(DragImageRef image, const IntPoint& dragLoc, const IntPoint& eventPos, Clipboard* clipboard, Frame* frame, bool forLink) 763 761 { … … 769 767 m_client->startDrag(image, viewProtector->windowToContents(frame->view()->contentsToWindow(dragLoc)), 770 768 viewProtector->windowToContents(frame->view()->contentsToWindow(eventPos)), clipboard, frameProtector.get(), forLink); 771 769 772 770 cleanupAfterSystemDrag(); 773 771 } 774 772 775 773 // Manual drag caret manipulation 776 774 void DragController::placeDragCaret(const IntPoint& windowPoint) … … 784 782 return; 785 783 IntPoint framePoint = frameView->windowToContents(windowPoint); 786 VisibleSelection dragCaret(frame->visiblePositionForPoint(framePoint)); 784 VisibleSelection dragCaret(frame->visiblePositionForPoint(framePoint)); 787 785 m_page->dragCaretController()->setSelection(dragCaret); 788 786 } 789 787 790 788 } // namespace WebCore
Note: See TracChangeset
for help on using the changeset viewer.