Changeset 87951 in webkit


Ignore:
Timestamp:
Jun 2, 2011 2:29:46 PM (13 years ago)
Author:
rniwa@webkit.org
Message:

2011-06-02 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Eric Seidel.

Make more functions static local in EventHandlers.cpp
https://bugs.webkit.org/show_bug.cgi?id=58503

Removed canHandleDragAndDropForTarget and made focusDirectionForKey local to EventHandler.cpp.

  • page/EventHandler.cpp: (WebCore::targetIsFrame): Extracted from canHandleDragAndDropForTarget. (WebCore::EventHandler::updateDragAndDrop): Calls contentFrameForTarget instead of canHandleDragAndDropForTarget. (WebCore::EventHandler::cancelDragAndDrop): Ditto. (WebCore::EventHandler::performDragAndDrop): Ditto. (WebCore::focusDirectionForKey): No longer a member function of EventHandler class. (WebCore::handleKeyboardSelectionMovement): No longer a member function of EventHandler class; also calls focusDirectionForKey instead of manually comparing.
  • page/EventHandler.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r87949 r87951  
     12011-06-02  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Make more functions static local in EventHandlers.cpp
     6        https://bugs.webkit.org/show_bug.cgi?id=58503
     7
     8        Removed canHandleDragAndDropForTarget and made focusDirectionForKey local to EventHandler.cpp.
     9
     10        * page/EventHandler.cpp:
     11        (WebCore::targetIsFrame): Extracted from canHandleDragAndDropForTarget.
     12        (WebCore::EventHandler::updateDragAndDrop): Calls contentFrameForTarget instead of canHandleDragAndDropForTarget.
     13        (WebCore::EventHandler::cancelDragAndDrop): Ditto.
     14        (WebCore::EventHandler::performDragAndDrop): Ditto.
     15        (WebCore::focusDirectionForKey): No longer a member function of EventHandler class.
     16        (WebCore::handleKeyboardSelectionMovement): No longer a member function of EventHandler class; also calls
     17        focusDirectionForKey instead of manually comparing.
     18        * page/EventHandler.h:
     19
    1202011-06-02  Alok Priyadarshi  <alokp@chromium.org>
    221
  • trunk/Source/WebCore/page/EventHandler.cpp

    r87499 r87951  
    17611761}
    17621762
    1763 bool EventHandler::canHandleDragAndDropForTarget(DragAndDropHandleType type, Node* target, const PlatformMouseEvent& event, Clipboard* clipboard, bool* accepted)
    1764 {
    1765     bool canHandle = false;
    1766     bool wasAccepted = false;
    1767 
    1768     if (target->hasTagName(frameTag) || target->hasTagName(iframeTag)) {
    1769         Frame* frame = static_cast<HTMLFrameElementBase*>(target)->contentFrame();
    1770         if (frame) {
    1771             switch (type) {
    1772             case UpdateDragAndDrop:
    1773                 wasAccepted = frame->eventHandler()->updateDragAndDrop(event, clipboard);
    1774                 break;
    1775             case CancelDragAndDrop:
    1776                 frame->eventHandler()->cancelDragAndDrop(event, clipboard);
    1777                 break;
    1778             case PerformDragAndDrop:
    1779                 wasAccepted = frame->eventHandler()->performDragAndDrop(event, clipboard);
    1780                 break;
    1781             }
    1782         }
    1783     } else
    1784         canHandle = true;
    1785 
    1786     if (accepted)
    1787         *accepted = wasAccepted;
    1788 
    1789     return canHandle;
     1763static bool targetIsFrame(Node* target, Frame*& frame)
     1764{
     1765    if (!target)
     1766        return false;
     1767
     1768    if (!target->hasTagName(frameTag) && !target->hasTagName(iframeTag))
     1769        return false;
     1770
     1771    frame = static_cast<HTMLFrameElementBase*>(target)->contentFrame();
     1772
     1773    return true;
    17901774}
    17911775
     
    18491833        //
    18501834        // Moreover, this ordering conforms to section 7.9.4 of the HTML 5 spec. <http://dev.w3.org/html5/spec/Overview.html#drag-and-drop-processing-model>.
    1851         if (newTarget && canHandleDragAndDropForTarget(UpdateDragAndDrop, newTarget, event, clipboard, &accept)) {
     1835        Frame* targetFrame;
     1836        if (targetIsFrame(newTarget, targetFrame)) {
     1837            if (targetFrame)
     1838                accept = targetFrame->eventHandler()->updateDragAndDrop(event, clipboard);
     1839        } else if (newTarget) {
    18521840            // As per section 7.9.4 of the HTML 5 spec., we must always fire a drag event before firing a dragenter, dragleave, or dragover event.
    18531841            if (dragState().m_dragSrc && dragState().shouldDispatchEvents()) {
     
    18601848        }
    18611849
    1862         if (m_dragTarget && canHandleDragAndDropForTarget(UpdateDragAndDrop, m_dragTarget.get(), event, clipboard, &accept))
     1850        if (targetIsFrame(m_dragTarget.get(), targetFrame)) {
     1851            if (targetFrame)
     1852                accept = targetFrame->eventHandler()->updateDragAndDrop(event, clipboard);
     1853        } else if (m_dragTarget)
    18631854            dispatchDragEvent(eventNames().dragleaveEvent, m_dragTarget.get(), event, clipboard);
    1864        
     1855
    18651856        if (newTarget) {
    18661857            // We do not explicitly call dispatchDragEvent here because it could ultimately result in the appearance that
     
    18691860        }
    18701861    } else {
    1871         if (newTarget && canHandleDragAndDropForTarget(UpdateDragAndDrop, newTarget, event, clipboard, &accept)) {
     1862        Frame* targetFrame;
     1863        if (targetIsFrame(newTarget, targetFrame)) {
     1864            if (targetFrame)
     1865                accept = targetFrame->eventHandler()->updateDragAndDrop(event, clipboard);
     1866        } else if (newTarget) {
    18721867            // Note, when dealing with sub-frames, we may need to fire only a dragover event as a drag event may have been fired earlier.
    18731868            if (!m_shouldOnlyFireDragOverEvent && dragState().m_dragSrc && dragState().shouldDispatchEvents()) {
     
    18881883void EventHandler::cancelDragAndDrop(const PlatformMouseEvent& event, Clipboard* clipboard)
    18891884{
    1890     if (m_dragTarget && canHandleDragAndDropForTarget(CancelDragAndDrop, m_dragTarget.get(), event, clipboard)) {
     1885    Frame* targetFrame;
     1886    if (targetIsFrame(m_dragTarget.get(), targetFrame)) {
     1887        if (targetFrame)
     1888            targetFrame->eventHandler()->cancelDragAndDrop(event, clipboard);
     1889    } else if (m_dragTarget.get()) {
    18911890        if (dragState().m_dragSrc && dragState().shouldDispatchEvents())
    18921891            dispatchDragSrcEvent(eventNames().dragEvent, event);
     
    18961895}
    18971896
    1898 bool EventHandler::performDragAndDrop(const PlatformMouseEvent& event, Clipboard* clipboard)
    1899 {
    1900     bool accept = false;
    1901     if (m_dragTarget && canHandleDragAndDropForTarget(PerformDragAndDrop, m_dragTarget.get(), event, clipboard, &accept))
     1897void EventHandler::performDragAndDrop(const PlatformMouseEvent& event, Clipboard* clipboard)
     1898{
     1899    Frame* targetFrame;
     1900    if (targetIsFrame(m_dragTarget.get(), targetFrame)) {
     1901        if (targetFrame)
     1902            targetFrame->eventHandler()->performDragAndDrop(event, clipboard);
     1903    } else if (m_dragTarget.get())
    19021904        dispatchDragEvent(eventNames().dropEvent, m_dragTarget.get(), event, clipboard);
    19031905    clearDragState();
    1904     return accept;
    19051906}
    19061907
     
    25892590}
    25902591
    2591 void EventHandler::handleKeyboardSelectionMovement(KeyboardEvent* event)
     2592static FocusDirection focusDirectionForKey(const AtomicString& keyIdentifier)
     2593{
     2594    DEFINE_STATIC_LOCAL(AtomicString, Down, ("Down"));
     2595    DEFINE_STATIC_LOCAL(AtomicString, Up, ("Up"));
     2596    DEFINE_STATIC_LOCAL(AtomicString, Left, ("Left"));
     2597    DEFINE_STATIC_LOCAL(AtomicString, Right, ("Right"));
     2598
     2599    FocusDirection retVal = FocusDirectionNone;
     2600
     2601    if (keyIdentifier == Down)
     2602        retVal = FocusDirectionDown;
     2603    else if (keyIdentifier == Up)
     2604        retVal = FocusDirectionUp;
     2605    else if (keyIdentifier == Left)
     2606        retVal = FocusDirectionLeft;
     2607    else if (keyIdentifier == Right)
     2608        retVal = FocusDirectionRight;
     2609
     2610    return retVal;
     2611}
     2612
     2613static void handleKeyboardSelectionMovement(FrameSelection* selection, KeyboardEvent* event)
    25922614{
    25932615    if (!event)
    25942616        return;
    2595    
    2596     const String& key = event->keyIdentifier();
    2597     bool isShifted = event->getModifierState("Shift");
     2617
    25982618    bool isOptioned = event->getModifierState("Alt");
    25992619    bool isCommanded = event->getModifierState("Meta");
    2600    
    2601     if (key == "Up") {
    2602         m_frame->selection()->modify((isShifted) ? FrameSelection::AlterationExtend : FrameSelection::AlterationMove, DirectionBackward, (isCommanded) ? DocumentBoundary : LineGranularity, true);
    2603         event->setDefaultHandled();
    2604     } else if (key == "Down") {
    2605         m_frame->selection()->modify((isShifted) ? FrameSelection::AlterationExtend : FrameSelection::AlterationMove, DirectionForward, (isCommanded) ? DocumentBoundary : LineGranularity, true);
    2606         event->setDefaultHandled();
    2607     } else if (key == "Left") {
    2608         m_frame->selection()->modify((isShifted) ? FrameSelection::AlterationExtend : FrameSelection::AlterationMove, DirectionLeft, (isCommanded) ? LineBoundary : (isOptioned) ? WordGranularity : CharacterGranularity, true);
    2609         event->setDefaultHandled();
    2610     } else if (key == "Right") {
    2611         m_frame->selection()->modify((isShifted) ? FrameSelection::AlterationExtend : FrameSelection::AlterationMove, DirectionRight, (isCommanded) ? LineBoundary : (isOptioned) ? WordGranularity : CharacterGranularity, true);
    2612         event->setDefaultHandled();
    2613     }   
     2620
     2621    SelectionDirection direction = DirectionForward;
     2622    TextGranularity granularity = CharacterGranularity;
     2623
     2624    switch (focusDirectionForKey(event->keyIdentifier())) {
     2625    case FocusDirectionNone:
     2626        return;
     2627    case FocusDirectionForward:
     2628    case FocusDirectionBackward:
     2629        ASSERT_NOT_REACHED();
     2630        return;
     2631    case FocusDirectionUp:
     2632        direction = DirectionBackward;
     2633        granularity = isCommanded ? DocumentBoundary : LineGranularity;
     2634        break;
     2635    case FocusDirectionDown:
     2636        direction = DirectionForward;
     2637        granularity = isCommanded ? DocumentBoundary : LineGranularity;
     2638        break;
     2639    case FocusDirectionLeft:
     2640        direction = DirectionLeft;
     2641        granularity = (isCommanded) ? LineBoundary : (isOptioned) ? WordGranularity : CharacterGranularity;
     2642        break;
     2643    case FocusDirectionRight:
     2644        direction = DirectionRight;
     2645        granularity = (isCommanded) ? LineBoundary : (isOptioned) ? WordGranularity : CharacterGranularity;
     2646        break;
     2647    }
     2648
     2649    FrameSelection::EAlteration alternation = event->getModifierState("Shift") ? FrameSelection::AlterationExtend : FrameSelection::AlterationMove;
     2650    selection->modify(alternation, direction, granularity, true);
     2651    event->setDefaultHandled();
    26142652}
    26152653   
     
    26322670        // provides KB navigation and selection for enhanced accessibility users
    26332671        if (AXObjectCache::accessibilityEnhancedUserInterfaceEnabled())
    2634             handleKeyboardSelectionMovement(event);
     2672            handleKeyboardSelectionMovement(m_frame->selection(), event);
    26352673    }
    26362674    if (event->type() == eventNames().keypressEvent) {
     
    26412679            defaultSpaceEventHandler(event);
    26422680    }
    2643 }
    2644 
    2645 FocusDirection EventHandler::focusDirectionForKey(const AtomicString& keyIdentifier) const
    2646 {
    2647     DEFINE_STATIC_LOCAL(AtomicString, Down, ("Down"));
    2648     DEFINE_STATIC_LOCAL(AtomicString, Up, ("Up"));
    2649     DEFINE_STATIC_LOCAL(AtomicString, Left, ("Left"));
    2650     DEFINE_STATIC_LOCAL(AtomicString, Right, ("Right"));
    2651 
    2652     FocusDirection retVal = FocusDirectionNone;
    2653 
    2654     if (keyIdentifier == Down)
    2655         retVal = FocusDirectionDown;
    2656     else if (keyIdentifier == Up)
    2657         retVal = FocusDirectionUp;
    2658     else if (keyIdentifier == Left)
    2659         retVal = FocusDirectionLeft;
    2660     else if (keyIdentifier == Right)
    2661         retVal = FocusDirectionRight;
    2662 
    2663     return retVal;
    26642681}
    26652682
  • trunk/Source/WebCore/page/EventHandler.h

    r87096 r87951  
    132132    bool updateDragAndDrop(const PlatformMouseEvent&, Clipboard*);
    133133    void cancelDragAndDrop(const PlatformMouseEvent&, Clipboard*);
    134     bool performDragAndDrop(const PlatformMouseEvent&, Clipboard*);
     134    void performDragAndDrop(const PlatformMouseEvent&, Clipboard*);
    135135#endif
    136136
     
    218218private:
    219219#if ENABLE(DRAG_SUPPORT)
    220     enum DragAndDropHandleType {
    221         UpdateDragAndDrop,
    222         CancelDragAndDrop,
    223         PerformDragAndDrop
    224     };
    225 
    226220    static DragState& dragState();
    227221    static const double TextDragDelay;
    228 
    229     bool canHandleDragAndDropForTarget(DragAndDropHandleType, Node* target, const PlatformMouseEvent&, Clipboard*, bool* accepted = 0);
    230222   
    231223    PassRefPtr<Clipboard> createDraggingClipboard() const;
     
    251243    bool handleMouseReleaseEvent(const MouseEventWithHitTestResults&);
    252244
    253     void handleKeyboardSelectionMovement(KeyboardEvent*);
    254    
    255245    Cursor selectCursor(const MouseEventWithHitTestResults&, Scrollbar*);
    256246#if ENABLE(PAN_SCROLLING)
     
    340330    void setFrameWasScrolledByUser();
    341331
    342     FocusDirection focusDirectionForKey(const AtomicString&) const;
    343 
    344332    bool capturesDragging() const { return m_capturesDragging; }
    345333
Note: See TracChangeset for help on using the changeset viewer.