Changeset 46330 in webkit


Ignore:
Timestamp:
Jul 24, 2009 12:44:59 AM (15 years ago)
Author:
abarth@webkit.org
Message:

2009-07-24 Mike Fenton <mike.fenton@torchmobile.com>

Reviewed by Eric Seidel.

Update WebCore/page/DOMTimer.cpp/h to conform to WebKit
Style Guidelines as identified by cpplint.py.
https://bugs.webkit.org/show_bug.cgi?id=27624

  • page/DragController.cpp: (WebCore::DragController::~DragController): (WebCore::documentFragmentFromDragData): (WebCore::DragController::dragEnded): (WebCore::DragController::dragEntered): (WebCore::DragController::dragExited): (WebCore::DragController::dragUpdated): (WebCore::DragController::performDrag): (WebCore::asFileInput): (WebCore::DragController::tryDocumentDrag): (WebCore::DragController::delegateDragSourceAction): (WebCore::DragController::concludeEditDrag): (WebCore::DragController::canProcessDrag): (WebCore::DragController::tryDHTMLDrag): (WebCore::DragController::mayStartDragAtEventLocation): (WebCore::getCachedImage): (WebCore::getImage): (WebCore::prepareClipboardForImageDrag): (WebCore::dragLocForDHTMLDrag): (WebCore::DragController::startDrag): (WebCore::DragController::doImageDrag): (WebCore::DragController::doSystemDrag): (WebCore::DragController::placeDragCaret):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r46329 r46330  
     12009-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
    1332009-07-24  Mike Fenton  <mike.fenton@torchmobile.com>
    234
  • trunk/WebCore/page/DragController.cpp

    r45065 r46330  
    7373
    7474}
    75    
     75
    7676DragController::DragController(Page* page, DragClient* client)
    7777    : m_page(page)
     
    8686{
    8787}
    88    
     88
    8989DragController::~DragController()
    90 {   
     90{
    9191    m_client->dragControllerDestroyed();
    9292}
    93    
     93
    9494static PassRefPtr<DocumentFragment> documentFragmentFromDragData(DragData* dragData, RefPtr<Range> context,
    9595                                          bool allowPlainText, bool& chosePlainText)
     
    123123        return createFragmentFromText(context.get(), dragData->asPlainText()).get();
    124124    }
    125    
     125
    126126    return 0;
    127127}
     
    141141{
    142142    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
     147DragOperation DragController::dragEntered(DragData* dragData)
    148148{
    149149    return dragEnteredOrUpdated(dragData);
    150150}
    151    
    152 void DragController::dragExited(DragData* dragData) 
    153 {   
     151
     152void DragController::dragExited(DragData* dragData)
     153{
    154154    ASSERT(dragData);
    155155    Frame* mainFrame = m_page->mainFrame();
    156    
     156
    157157    if (RefPtr<FrameView> v = mainFrame->view()) {
    158158        ClipboardAccessPolicy policy = (!m_documentUnderMouse || m_documentUnderMouse->securityOrigin()->isLocal()) ? ClipboardReadable : ClipboardTypesReadable;
     
    165165}
    166166
    167    
    168 DragOperation DragController::dragUpdated(DragData* dragData)
     167DragOperation DragController::dragUpdated(DragData* dragData)
    169168{
    170169    return dragEnteredOrUpdated(dragData);
    171170}
    172    
     171
    173172bool DragController::performDrag(DragData* dragData)
    174 {   
     173{
    175174    ASSERT(dragData);
    176175    m_documentUnderMouse = m_page->mainFrame()->documentAtPoint(dragData->clientPosition());
     
    188187        m_documentUnderMouse = 0;
    189188        return true;
    190     } 
    191    
     189    }
     190
    192191    if ((m_dragDestinationAction & DragDestinationActionEdit) && concludeEditDrag(dragData)) {
    193192        m_documentUnderMouse = 0;
    194193        return true;
    195194    }
    196    
     195
    197196    m_documentUnderMouse = 0;
    198197
     
    238237{
    239238    ASSERT(node);
    240    
     239
    241240    // The button for a FILE input is a sub element with no set input type
    242241    // In order to get around this problem we assume any non-FILE input element
     
    244243    if (node->hasTagName(HTMLNames::inputTag) && node->isShadowNode() && static_cast<HTMLInputElement*>(node)->inputType() != HTMLInputElement::FILE)
    245244      node = node->shadowParentNode();
    246    
     245
    247246    if (!node || !node->hasTagName(HTMLNames::inputTag))
    248247        return 0;
    249    
     248
    250249    HTMLInputElement* inputElem = static_cast<HTMLInputElement*>(node);
    251250    if (inputElem->inputType() == HTMLInputElement::FILE)
    252251        return inputElem;
    253    
     252
    254253    return 0;
    255254}
    256    
     255
    257256bool DragController::tryDocumentDrag(DragData* dragData, DragDestinationAction actionMask, DragOperation& operation)
    258257{
    259258    ASSERT(dragData);
    260    
     259
    261260    if (!m_documentUnderMouse)
    262261        return false;
    263    
     262
    264263    m_isHandlingDrag = false;
    265264    if (actionMask & DragDestinationActionDHTML) {
     
    290289            return true;
    291290        }
    292        
     291
    293292        IntPoint dragPos = dragData->clientPosition();
    294293        IntPoint point = frameView->windowToContents(dragPos);
     
    308307
    309308DragSourceAction DragController::delegateDragSourceAction(const IntPoint& windowPoint)
    310 { 
     309{
    311310    m_dragSourceAction = m_client->dragSourceActionMaskForPoint(windowPoint);
    312311    return m_dragSourceAction;
    313312}
    314    
     313
    315314DragOperation DragController::operationForLoad(DragData* dragData)
    316315{
     
    337336    ASSERT(dragData);
    338337    ASSERT(!m_isHandlingDrag);
    339    
     338
    340339    if (!m_documentUnderMouse)
    341340        return false;
    342    
     341
    343342    IntPoint point = m_documentUnderMouse->view()->windowToContents(dragData->clientPosition());
    344343    Element* element =  m_documentUnderMouse->elementFromPoint(point.x(), point.y());
    345344    ASSERT(element);
    346345    Frame* innerFrame = element->ownerDocument()->frame();
    347     ASSERT(innerFrame);   
     346    ASSERT(innerFrame);
    348347
    349348    if (dragData->containsColor()) {
     
    363362        return true;
    364363    }
    365    
     364
    366365    if (!m_page->dragController()->canProcessDrag(dragData)) {
    367366        m_page->dragCaretController()->clear();
    368367        return false;
    369368    }
    370    
     369
    371370    if (HTMLInputElement* fileInput = asFileInput(element)) {
    372371        if (!fileInput->isEnabledFormControl())
    373372            return false;
    374        
     373
    375374        if (!dragData->containsFiles())
    376375            return false;
    377        
     376
    378377        Vector<String> filenames;
    379378        dragData->asFilenames(filenames);
    380379        if (filenames.isEmpty())
    381380            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
    384383        // on file inputs.  Even forcing a change in HTMLInputElement doesn't work as
    385384        // RenderFileUploadControl clears the file when doing updateFromElement()
    386385        RenderFileUploadControl* renderer = static_cast<RenderFileUploadControl*>(fileInput->renderer());
    387        
     386
    388387        if (!renderer)
    389388            return false;
    390        
     389
    391390        renderer->receiveDroppedFiles(filenames);
    392391        return true;
     
    396395    m_page->dragCaretController()->clear();
    397396    RefPtr<Range> range = dragCaret.toNormalizedRange();
    398    
     397
    399398    // For range to be null a WebKit client must have done something bad while
    400399    // manually controlling drag behaviour
    401     if (!range) 
     400    if (!range)
    402401        return false;
    403402    DocLoader* loader = range->ownerDocument()->docLoader();
    404403    loader->setAllowStaleResources(true);
    405     if (dragIsMove(innerFrame->selection()) || dragCaret.isContentRichlyEditable()) { 
     404    if (dragIsMove(innerFrame->selection()) || dragCaret.isContentRichlyEditable()) {
    406405        bool chosePlainText = false;
    407406        RefPtr<DocumentFragment> fragment = documentFragmentFromDragData(dragData, range, true, chosePlainText);
     
    410409            return false;
    411410        }
    412        
     411
    413412        m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData);
    414413        if (dragIsMove(innerFrame->selection())) {
    415             bool smartMove = innerFrame->selectionGranularity() == WordGranularity 
    416                           && innerFrame->editor()->smartInsertDeleteEnabled() 
     414            bool smartMove = innerFrame->selectionGranularity() == WordGranularity
     415                          && innerFrame->editor()->smartInsertDeleteEnabled()
    417416                          && dragData->canSmartReplace();
    418417            applyCommand(MoveSelectionCommand::create(fragment, dragCaret.base(), smartMove));
    419418        } else {
    420419            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        }
    423422    } else {
    424423        String text = dragData->asPlainText();
     
    427426            return false;
    428427        }
    429        
     428
    430429        m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData);
    431430        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));
    433432    }
    434433    loader->setAllowStaleResources(false);
     
    436435    return true;
    437436}
    438    
    439    
    440 bool DragController::canProcessDrag(DragData* dragData)
     437
     438bool DragController::canProcessDrag(DragData* dragData)
    441439{
    442440    ASSERT(dragData);
     
    444442    if (!dragData->containsCompatibleContent())
    445443        return false;
    446    
     444
    447445    IntPoint point = m_page->mainFrame()->view()->windowToContents(dragData->clientPosition());
    448446    HitTestResult result = HitTestResult(point);
     
    451449
    452450    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
    457455    if (dragData->containsFiles() && asFileInput(result.innerNonSharedNode()))
    458456        return true;
    459        
     457
    460458    if (!result.innerNonSharedNode()->isContentEditable())
    461459        return false;
    462        
     460
    463461    if (m_didInitiateDrag && m_documentUnderMouse == m_dragInitiator && result.isSelected())
    464462        return false;
     
    483481
    484482bool DragController::tryDHTMLDrag(DragData* dragData, DragOperation& operation)
    485 {   
     483{
    486484    ASSERT(dragData);
    487485    ASSERT(m_documentUnderMouse);
     
    526524    mouseDownTarget = frame->eventHandler()->hitTestResultAtPoint(framePos, true);
    527525
    528     if (mouseDownTarget.image() 
     526    if (mouseDownTarget.image()
    529527        && !mouseDownTarget.absoluteImageURL().isEmpty()
    530528        && frame->settings()->loadsImagesAutomatically()
     
    544542
    545543}
    546    
     544
    547545static CachedImage* getCachedImage(Element* element)
    548546{
    549547    ASSERT(element);
    550548    RenderObject* renderer = element->renderer();
    551     if (!renderer || !renderer->isImage()) 
     549    if (!renderer || !renderer->isImage())
    552550        return 0;
    553551    RenderImage* image = toRenderImage(renderer);
    554552    return image->cachedImage();
    555553}
    556    
     554
    557555static Image* getImage(Element* element)
    558556{
    559557    ASSERT(element);
    560558    RenderObject* renderer = element->renderer();
    561     if (!renderer || !renderer->isImage()) 
     559    if (!renderer || !renderer->isImage())
    562560        return 0;
    563    
     561
    564562    RenderImage* image = toRenderImage(renderer);
    565563    if (image->cachedImage() && !image->cachedImage()->errorOccurred())
     
    567565    return 0;
    568566}
    569    
     567
    570568static void prepareClipboardForImageDrag(Frame* src, Clipboard* clipboard, Element* node, const KURL& linkURL, const KURL& imageURL, const String& label)
    571569{
     
    573571    ExceptionCode ec = 0;
    574572    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));
    577575    clipboard->declareAndWriteDragImage(node, !linkURL.isEmpty() ? linkURL : imageURL, label, src);
    578576}
    579    
     577
    580578static IntPoint dragLocForDHTMLDrag(const IntPoint& mouseDraggedPoint, const IntPoint& dragOrigin, const IntPoint& dragImageOffset, bool isLinkImage)
    581579{
    582580    // 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.
    585583    const int yOffset = dragImageOffset.y();
    586584#else
    587585    const int yOffset = -dragImageOffset.y();
    588586#endif
    589    
     587
    590588    if (isLinkImage)
    591589        return IntPoint(mouseDraggedPoint.x() - dragImageOffset.x(), mouseDraggedPoint.y() + yOffset);
    592    
     590
    593591    return IntPoint(dragOrigin.x() - dragImageOffset.x(), dragOrigin.y() + yOffset);
    594592}
    595    
     593
    596594static IntPoint dragLocForSelectionDrag(Frame* src)
    597595{
     
    608606    return IntPoint(xpos, ypos);
    609607}
    610    
     608
    611609bool DragController::startDrag(Frame* src, Clipboard* clipboard, DragOperation srcOp, const PlatformMouseEvent& dragEvent, const IntPoint& dragOrigin, bool isDHTMLDrag)
    612 {   
     610{
    613611    ASSERT(src);
    614612    ASSERT(clipboard);
    615    
     613
    616614    if (!src->view() || !src->contentRenderer())
    617615        return false;
    618    
     616
    619617    HitTestResult dragSource = HitTestResult(dragOrigin);
    620618    dragSource = src->eventHandler()->hitTestResultAtPoint(dragOrigin, true);
     
    622620    KURL imageURL = dragSource.absoluteImageURL();
    623621    bool isSelected = dragSource.isSelected();
    624    
     622
    625623    IntPoint mouseDraggedPoint = src->view()->windowToContents(dragEvent.pos());
    626    
     624
    627625    m_draggingImageURL = KURL();
    628626    m_sourceDragOperation = srcOp;
    629    
     627
    630628    DragImageRef dragImage = 0;
    631629    IntPoint dragLoc(0, 0);
    632630    IntPoint dragImageOffset(0, 0);
    633    
    634     if (isDHTMLDrag) 
     631
     632    if (isDHTMLDrag)
    635633        dragImage = clipboard->createDragImage(dragImageOffset);
    636    
     634
    637635    // We allow DHTML/JS to set the drag image, even if its a link, image or text we're dragging.
    638636    // This is in the spirit of the IE API, which allows overriding of pasteboard data and DragOp.
     
    641639        m_dragOffset = dragImageOffset;
    642640    }
    643    
     641
    644642    bool startedDrag = true; // optimism - we almost always manage to start the drag
    645    
     643
    646644    Node* node = dragSource.innerNonSharedNode();
    647    
     645
    648646    Image* image = getImage(static_cast<Element*>(node));
    649647    if (!imageURL.isEmpty() && node && node->isElementNode() && image
    650648            && (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.
    652650        // This is an early detection for problems encountered later upon drop.
    653651        ASSERT(!image->filenameExtension().isEmpty());
    654652        Element* element = static_cast<Element*>(node);
    655653        if (!clipboard->hasData()) {
    656             m_draggingImageURL = imageURL; 
     654            m_draggingImageURL = imageURL;
    657655            prepareClipboardForImageDrag(src, clipboard, element, linkURL, imageURL, dragSource.altDisplayString());
    658656        }
    659        
     657
    660658        m_client->willPerformDragSourceAction(DragSourceActionImage, dragOrigin, clipboard);
    661        
     659
    662660        if (!dragImage) {
    663661            IntRect imageRect = dragSource.imageRect();
    664662            imageRect.setLocation(m_page->mainFrame()->view()->windowToContents(src->view()->contentsToWindow(imageRect.location())));
    665663            doImageDrag(element, dragOrigin, dragSource.imageRect(), clipboard, src, m_dragOffset);
    666         } else 
     664        } else
    667665            // DHTML defined drag image
    668666            doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false);
     
    690688            m_dragOffset = IntPoint(-size.width() / 2, -LinkDragBorderInset);
    691689            dragLoc = IntPoint(mouseDraggedPoint.x() + m_dragOffset.x(), mouseDraggedPoint.y() + m_dragOffset.y());
    692         } 
     690        }
    693691        doSystemDrag(dragImage, dragLoc, mouseDraggedPoint, clipboard, src, true);
    694692    } else if (isSelected && (m_dragSourceAction & DragSourceActionSelection)) {
    695693        RefPtr<Range> selectionRange = src->selection()->toNormalizedRange();
    696694        ASSERT(selectionRange);
    697         if (!clipboard->hasData()) 
     695        if (!clipboard->hasData())
    698696            clipboard->writeRange(selectionRange.get(), src);
    699697        m_client->willPerformDragSourceAction(DragSourceActionSelection, dragOrigin, clipboard);
     
    713711        startedDrag = false;
    714712    }
    715    
     713
    716714    if (dragImage)
    717715        deleteDragImage(dragImage);
     
    724722    DragImageRef dragImage;
    725723    IntPoint origin;
    726    
     724
    727725    Image* image = getImage(element);
    728726    if (image && image->size().height() * image->size().width() <= MaxOriginalImageArea
     
    730728        IntSize originalSize = rect.size();
    731729        origin = rect.location();
    732        
     730
    733731        dragImage = fitDragImageToMaxSize(dragImage, rect.size(), maxDragImageSize());
    734732        dragImage = dissolveDragImageToFraction(dragImage, DragImageAlpha);
    735733        IntSize newSize = dragImageSize(dragImage);
    736        
     734
    737735        // Properly orient the drag image and orient it differently if it's smaller than the original
    738736        float scale = newSize.width() / (float)originalSize.width();
     
    752750            origin = IntPoint(DragIconRightInset - dragImageSize(dragImage).width(), DragIconBottomInset);
    753751    }
    754    
     752
    755753    dragImageOffset.setX(mouseDownPoint.x() + origin.x());
    756754    dragImageOffset.setY(mouseDownPoint.y() + origin.y());
    757755    doSystemDrag(dragImage, dragImageOffset, dragOrigin, clipboard, frame, false);
    758    
     756
    759757    deleteDragImage(dragImage);
    760758}
    761    
     759
    762760void DragController::doSystemDrag(DragImageRef image, const IntPoint& dragLoc, const IntPoint& eventPos, Clipboard* clipboard, Frame* frame, bool forLink)
    763761{
     
    769767    m_client->startDrag(image, viewProtector->windowToContents(frame->view()->contentsToWindow(dragLoc)),
    770768        viewProtector->windowToContents(frame->view()->contentsToWindow(eventPos)), clipboard, frameProtector.get(), forLink);
    771    
     769
    772770    cleanupAfterSystemDrag();
    773771}
    774    
     772
    775773// Manual drag caret manipulation
    776774void DragController::placeDragCaret(const IntPoint& windowPoint)
     
    784782        return;
    785783    IntPoint framePoint = frameView->windowToContents(windowPoint);
    786     VisibleSelection dragCaret(frame->visiblePositionForPoint(framePoint)); 
     784    VisibleSelection dragCaret(frame->visiblePositionForPoint(framePoint));
    787785    m_page->dragCaretController()->setSelection(dragCaret);
    788786}
    789    
     787
    790788} // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.