Changeset 143030 in webkit


Ignore:
Timestamp:
Feb 15, 2013 11:59:41 AM (11 years ago)
Author:
rniwa@webkit.org
Message:

DeleteButtonController::enable and disable should be called via a RAII object
https://bugs.webkit.org/show_bug.cgi?id=109550

Reviewed by Enrica Casucci.

Added DeleteButtonControllerDisableScope, a friend class of DeleteButtonController,
and made DeleteButtonController::enable/disable private.

  • dom/ContainerNode.cpp:
  • editing/CompositeEditCommand.cpp:

(WebCore::EditCommandComposition::unapply):
(WebCore::EditCommandComposition::reapply):
(WebCore::CompositeEditCommand::apply):

  • editing/DeleteButtonController.h:

(WebCore):
(DeleteButtonController):
(DeleteButtonControllerDisableScope):
(WebCore::DeleteButtonControllerDisableScope::DeleteButtonControllerDisableScope):
(WebCore::DeleteButtonControllerDisableScope::~DeleteButtonControllerDisableScope):

  • editing/markup.cpp:

(WebCore::createMarkup):
(WebCore::createFragmentFromNodes):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r143028 r143030  
     12013-02-13  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        DeleteButtonController::enable and disable should be called via a RAII object
     4        https://bugs.webkit.org/show_bug.cgi?id=109550
     5
     6        Reviewed by Enrica Casucci.
     7
     8        Added DeleteButtonControllerDisableScope, a friend class of DeleteButtonController,
     9        and made DeleteButtonController::enable/disable private.
     10
     11        * dom/ContainerNode.cpp:
     12        * editing/CompositeEditCommand.cpp:
     13        (WebCore::EditCommandComposition::unapply):
     14        (WebCore::EditCommandComposition::reapply):
     15        (WebCore::CompositeEditCommand::apply):
     16        * editing/DeleteButtonController.h:
     17        (WebCore):
     18        (DeleteButtonController):
     19        (DeleteButtonControllerDisableScope):
     20        (WebCore::DeleteButtonControllerDisableScope::DeleteButtonControllerDisableScope):
     21        (WebCore::DeleteButtonControllerDisableScope::~DeleteButtonControllerDisableScope):
     22        * editing/markup.cpp:
     23        (WebCore::createMarkup):
     24        (WebCore::createFragmentFromNodes):
     25
    1262013-02-15  Max Vujovic  <mvujovic@adobe.com>
    227
  • trunk/Source/WebCore/editing/CompositeEditCommand.cpp

    r142642 r143030  
    104104    m_document->updateLayoutIgnorePendingStylesheets();
    105105
     106    {
    106107#if ENABLE(DELETION_UI)
    107     DeleteButtonController* deleteButtonController = frame->editor()->deleteButtonController();
    108     deleteButtonController->disable();
     108        DeleteButtonControllerDisableScope deleteButtonControllerDisableScope(frame.get());
    109109#endif
    110     size_t size = m_commands.size();
    111     for (size_t i = size; i != 0; --i)
    112         m_commands[i - 1]->doUnapply();
    113 #if ENABLE(DELETION_UI)
    114     deleteButtonController->enable();
    115 #endif
     110
     111        size_t size = m_commands.size();
     112        for (size_t i = size; i; --i)
     113            m_commands[i - 1]->doUnapply();
     114    }
     115
    116116    frame->editor()->unappliedEditing(this);
    117117}
     
    127127    // if one is necessary (like for the creation of VisiblePositions).
    128128    m_document->updateLayoutIgnorePendingStylesheets();
    129    
     129
     130    {
    130131#if ENABLE(DELETION_UI)
    131     DeleteButtonController* deleteButtonController = frame->editor()->deleteButtonController();
    132     deleteButtonController->disable();
     132        DeleteButtonControllerDisableScope deleteButtonControllerDisableScope(frame.get());
    133133#endif
    134     size_t size = m_commands.size();
    135     for (size_t i = 0; i != size; ++i)
    136         m_commands[i]->doReapply();
    137 #if ENABLE(DELETION_UI)
    138     deleteButtonController->enable();
    139 #endif
     134        size_t size = m_commands.size();
     135        for (size_t i = 0; i != size; ++i)
     136            m_commands[i]->doReapply();
     137    }
    140138   
    141139    frame->editor()->reappliedEditing(this);
     
    212210        EventQueueScope scope;
    213211#if ENABLE(DELETION_UI)
    214         DeleteButtonController* deleteButtonController = frame->editor()->deleteButtonController();
    215         deleteButtonController->disable();
     212        DeleteButtonControllerDisableScope deleteButtonControllerDisableScope(frame);
    216213#endif
    217214        doApply();
    218 #if ENABLE(DELETION_UI)
    219         deleteButtonController->enable();
    220 #endif
    221215    }
    222216
  • trunk/Source/WebCore/editing/DeleteButtonController.h

    r142533 r143030  
    2828
    2929#include "DeleteButton.h"
     30#include "Frame.h"
    3031
    3132namespace WebCore {
    3233
     34#if ENABLE(DELETION_UI)
     35
    3336class DeleteButton;
    34 class Frame;
    3537class HTMLElement;
    3638class RenderObject;
     
    5153    void hide();
    5254
    53     void enable();
    54     void disable();
    55 
    5655    void deleteTarget();
    5756
     
    6059    static const char* const outlineElementIdentifier;
    6160    static const char* const containerElementIdentifier;
     61   
     62    void enable();
     63    void disable();
     64    friend class DeleteButtonControllerDisableScope;
    6265
    6366    void createDeletionUI();
     
    7477};
    7578
     79class DeleteButtonControllerDisableScope {
     80public:
     81    DeleteButtonControllerDisableScope(Frame* frame)
     82        : m_frame(frame)
     83    {
     84        if (frame)
     85            frame->editor()->deleteButtonController()->disable();
     86    }
     87
     88    ~DeleteButtonControllerDisableScope()
     89    {
     90        if (m_frame)
     91            m_frame->editor()->deleteButtonController()->enable();
     92    }
     93
     94private:
     95    RefPtr<Frame> m_frame;
     96};
     97
     98#endif
     99
    76100} // namespace WebCore
    77101
  • trunk/Source/WebCore/editing/markup.cpp

    r142705 r143030  
    640640        return emptyString();
    641641
     642    const Range* updatedRange = range;
     643
     644#if ENABLE(DELETION_UI)
    642645    // Disable the delete button so it's elements are not serialized into the markup,
    643646    // but make sure neither endpoint is inside the delete user interface.
    644 #if ENABLE(DELETION_UI)
    645647    Frame* frame = document->frame();
    646     if (DeleteButtonController* deleteButton = frame ? frame->editor()->deleteButtonController() : 0) {
    647         RefPtr<Range> updatedRange = frame->editor()->avoidIntersectionWithDeleteButtonController(range);
     648    DeleteButtonControllerDisableScope deleteButtonControllerDisableScope(frame);
     649
     650    if (frame) {
     651        RefPtr<Range> updatedRangeRef = frame->editor()->avoidIntersectionWithDeleteButtonController(range);
     652        updatedRange = updatedRangeRef.get();
    648653        if (!updatedRange)
    649654            return emptyString();
    650 
    651         deleteButton->disable();
    652 
    653         String result = createMarkupInternal(document, range, updatedRange.get(), nodes, shouldAnnotate, convertBlocksToInlines, shouldResolveURLs);
    654 
    655         deleteButton->enable();
    656 
    657         return result;
    658655    }
    659656#endif
    660     return createMarkupInternal(document, range, range, nodes, shouldAnnotate, convertBlocksToInlines, shouldResolveURLs);
     657
     658    return createMarkupInternal(document, range, updatedRange, nodes, shouldAnnotate, convertBlocksToInlines, shouldResolveURLs);
    661659}
    662660
     
    910908#if ENABLE(DELETION_UI)
    911909    // disable the delete button so it's elements are not serialized into the markup
    912     if (document->frame())
    913         document->frame()->editor()->deleteButtonController()->disable();
     910    DeleteButtonControllerDisableScope(document->frame());
    914911#endif
     912
    915913    RefPtr<DocumentFragment> fragment = document->createDocumentFragment();
    916914
     
    922920    }
    923921
    924 #if ENABLE(DELETION_UI)
    925     if (document->frame())
    926         document->frame()->editor()->deleteButtonController()->enable();
    927 #endif
    928922    return fragment.release();
    929923}
Note: See TracChangeset for help on using the changeset viewer.