Changeset 86039 in webkit


Ignore:
Timestamp:
May 8, 2011 5:40:11 PM (13 years ago)
Author:
rniwa@webkit.org
Message:

2011-05-08 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Darin Adler.

Extract a DragCaretController from FrameSelection
https://bugs.webkit.org/show_bug.cgi?id=60273

Extracted CaretBase and DragCaretController from FrameSelection. CaretBase is a base class for
DragCaretController and FrameSelection and provides functions to paint caret.

Since DragCaretController doesn't need to store selection, it only holds one VisiblePosition.

  • WebCore.exp.in:
  • editing/FrameSelection.cpp: (WebCore::CaretBase::CaretBase): Added. (WebCore::DragCaretController::DragCaretController): Added; Set m_caretVisible true. (WebCore::DragCaretController::isContentRichlyEditable): Added. (WebCore::FrameSelection::FrameSelection): Several member variables are move to CaretBase. (WebCore::DragCaretController::setCaretPosition): Extracted from FrameSelection::setSelection. (WebCore::FrameSelection::setSelection): Removed an early exit for DragCaretController. (WebCore::clearRenderViewSelection): Extracted from FrameSelection::respondToNodeModification. (WebCore::DragCaretController::nodeWillBeRemoved): Extracted from FrameSelection::nodeWillBeRemoved and respondToNodeModification. Note that the position DragCaretController holds is equivalent to FrameSelection's base or start so when removingNodeRemovesPosition returns true for m_position, we used to execute the first if clause and cleared render tree selection and DOM tree selection. This is exactly what new DragCaretController::nodeWillBeRemoved does. (WebCore::FrameSelection::nodeWillBeRemoved): Simplified early exist conditions. (WebCore::FrameSelection::respondToNodeModification): Calls clearRenderViewSelection. (WebCore::CaretBase::updateCaretRect): Takes document, caretPosition, selection type, and boolean isOrphaned. Note that we can't obtain the document from caretPosition because VisiblePosition can be null even if FrameSelection's start was not null. (WebCore::caretRendersInsideNode): Moved; Made static local. (WebCore::CaretBase::caretRenderer): Extracted from FrameSelection::caretRenderer. (WebCore::FrameSelection::caretRenderer): Calls CaretBase::caretRenderer. (WebCore::DragCaretController::caretRenderer): Ditto. (WebCore::FrameSelection::localCaretRect): Calls updateCaretRect with extra arguments. (WebCore::CaretBase::absoluteBoundsForLocalRect): Moved from FrameSelection; Takes Node*. (WebCore::CaretBase::caretRepaintRect): Ditto. (WebCore::FrameSelection::recomputeCaretRect): Calls absoluteBoundsForLocalRect, caretRepaintRect, and shouldRepaintCaret with extra arguments. (WebCore::CaretBase::shouldRepaintCaret): Takes a boolean isContentEditable. (WebCore::FrameSelection::invalidateCaretRect): Calls CaretBase::invalidateCaretRect. (WebCore::CaretBase::invalidateCaretRect): Extracted from FrameSelection::invalidateCaretRect. (WebCore::FrameSelection::paintCaret): Calls CaretBase::paintCaret. (WebCore::CaretBase::paintCaret): Extracted from FrameSelection::paintCaret. (WebCore::FrameSelection::updateAppearance): Removed an assertion that this function is never called for DragCaretController. (WebCore::DragCaretController::paintDragCaret): Moved from FrameSelection::paintDragCaret.
  • editing/FrameSelection.h: (WebCore::CaretBase::localCaretRectForPainting): Added. (WebCore::DragCaretController::isContentEditable): Added. (WebCore::DragCaretController::hasCaret): Added. (WebCore::DragCaretController::caretPosition): Added. (WebCore::DragCaretController::clear): Added.
  • page/DragController.cpp: (WebCore::DragController::tryDocumentDrag): Uses DragCaretController. (WebCore::DragController::dispatchTextInputEventFor): Ditto. (WebCore::DragController::concludeEditDrag): Ditto. (WebCore::DragController::placeDragCaret): Ditto.
  • page/Page.cpp: (WebCore::Page::Page): Instantiates DragCaretController instead of FrameSelection.
  • page/Page.h: (WebCore::Page::dragCaretController): Returns DragCaretController* instead of FrameSelection*.
  • rendering/RenderBlock.cpp: (WebCore::RenderBlock::paintCaret): Uses FrameSelection and DragCaretController.
Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r86028 r86039  
     12011-05-08  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Extract a DragCaretController from FrameSelection
     6        https://bugs.webkit.org/show_bug.cgi?id=60273
     7
     8        Extracted CaretBase and DragCaretController from FrameSelection. CaretBase is a base class for
     9        DragCaretController and FrameSelection and provides functions to paint caret.
     10
     11        Since DragCaretController doesn't need to store selection, it only holds one VisiblePosition.
     12
     13        * WebCore.exp.in:
     14        * editing/FrameSelection.cpp:
     15        (WebCore::CaretBase::CaretBase): Added.
     16        (WebCore::DragCaretController::DragCaretController): Added; Set m_caretVisible true.
     17        (WebCore::DragCaretController::isContentRichlyEditable): Added.
     18        (WebCore::FrameSelection::FrameSelection): Several member variables are move to CaretBase.
     19        (WebCore::DragCaretController::setCaretPosition): Extracted from FrameSelection::setSelection.
     20        (WebCore::FrameSelection::setSelection): Removed an early exit for DragCaretController.
     21        (WebCore::clearRenderViewSelection): Extracted from FrameSelection::respondToNodeModification.
     22        (WebCore::DragCaretController::nodeWillBeRemoved): Extracted from FrameSelection::nodeWillBeRemoved
     23        and respondToNodeModification. Note that the position DragCaretController holds is equivalent to
     24        FrameSelection's base or start so when removingNodeRemovesPosition returns true for m_position,
     25        we used to execute the first if clause and cleared render tree selection and DOM tree selection.
     26        This is exactly what new DragCaretController::nodeWillBeRemoved does.
     27        (WebCore::FrameSelection::nodeWillBeRemoved): Simplified early exist conditions.
     28        (WebCore::FrameSelection::respondToNodeModification): Calls clearRenderViewSelection.
     29        (WebCore::CaretBase::updateCaretRect): Takes document, caretPosition, selection type, and boolean isOrphaned.
     30        Note that we can't obtain the document from caretPosition because VisiblePosition can be null even if
     31        FrameSelection's start was not null.
     32        (WebCore::caretRendersInsideNode): Moved; Made static local.
     33        (WebCore::CaretBase::caretRenderer): Extracted from FrameSelection::caretRenderer.
     34        (WebCore::FrameSelection::caretRenderer): Calls CaretBase::caretRenderer.
     35        (WebCore::DragCaretController::caretRenderer): Ditto.
     36        (WebCore::FrameSelection::localCaretRect): Calls updateCaretRect with extra arguments.
     37        (WebCore::CaretBase::absoluteBoundsForLocalRect): Moved from FrameSelection; Takes Node*.
     38        (WebCore::CaretBase::caretRepaintRect): Ditto.
     39        (WebCore::FrameSelection::recomputeCaretRect): Calls absoluteBoundsForLocalRect, caretRepaintRect,
     40        and shouldRepaintCaret with extra arguments.
     41        (WebCore::CaretBase::shouldRepaintCaret): Takes a boolean isContentEditable.
     42        (WebCore::FrameSelection::invalidateCaretRect): Calls CaretBase::invalidateCaretRect.
     43        (WebCore::CaretBase::invalidateCaretRect): Extracted from FrameSelection::invalidateCaretRect.
     44        (WebCore::FrameSelection::paintCaret): Calls CaretBase::paintCaret.
     45        (WebCore::CaretBase::paintCaret): Extracted from FrameSelection::paintCaret.
     46        (WebCore::FrameSelection::updateAppearance): Removed an assertion that this function is never called for
     47        DragCaretController.
     48        (WebCore::DragCaretController::paintDragCaret): Moved from FrameSelection::paintDragCaret.
     49        * editing/FrameSelection.h:
     50        (WebCore::CaretBase::localCaretRectForPainting): Added.
     51        (WebCore::DragCaretController::isContentEditable): Added.
     52        (WebCore::DragCaretController::hasCaret): Added.
     53        (WebCore::DragCaretController::caretPosition): Added.
     54        (WebCore::DragCaretController::clear): Added.
     55        * page/DragController.cpp:
     56        (WebCore::DragController::tryDocumentDrag): Uses DragCaretController.
     57        (WebCore::DragController::dispatchTextInputEventFor): Ditto.
     58        (WebCore::DragController::concludeEditDrag): Ditto.
     59        (WebCore::DragController::placeDragCaret): Ditto.
     60        * page/Page.cpp:
     61        (WebCore::Page::Page): Instantiates DragCaretController instead of FrameSelection.
     62        * page/Page.h:
     63        (WebCore::Page::dragCaretController): Returns DragCaretController* instead of FrameSelection*.
     64        * rendering/RenderBlock.cpp:
     65        (WebCore::RenderBlock::paintCaret): Uses FrameSelection and DragCaretController.
     66
    1672011-05-08  Dan Bernstein  <mitz@apple.com>
    268
  • trunk/Source/WebCore/WebCore.exp.in

    r85998 r86039  
    357357__ZN7WebCore14FrameSelection5clearEv
    358358__ZN7WebCore14FrameSelection9selectAllEv
    359 __ZN7WebCore14FrameSelectionC1EPNS_5FrameEb
     359__ZN7WebCore14FrameSelectionC1EPNS_5FrameE
    360360__ZN7WebCore14ResourceHandle12releaseProxyEv
    361361__ZN7WebCore14ResourceHandle20forceContentSniffingEv
  • trunk/Source/WebCore/editing/FrameSelection.cpp

    r85864 r86039  
    7171const int NoXPosForVerticalArrowNavigation = INT_MIN;
    7272
    73 FrameSelection::FrameSelection(Frame* frame, bool isDragCaretController)
     73CaretBase::CaretBase()
     74    : m_caretRectNeedsUpdate(true)
     75    , m_absCaretBoundsDirty(true)
     76    , m_caretVisible(false)
     77    , m_caretPaint(true)
     78{
     79}
     80
     81DragCaretController::DragCaretController()
     82{
     83    m_caretVisible = true;
     84}
     85
     86bool DragCaretController::isContentRichlyEditable() const
     87{
     88    return isRichlyEditablePosition(m_position.deepEquivalent());
     89}
     90
     91FrameSelection::FrameSelection(Frame* frame)
    7492    : m_frame(frame)
    7593    , m_xPosForVerticalArrowNavigation(NoXPosForVerticalArrowNavigation)
    7694    , m_granularity(CharacterGranularity)
    7795    , m_caretBlinkTimer(this, &FrameSelection::caretBlinkTimerFired)
    78     , m_caretRectNeedsUpdate(true)
    79     , m_absCaretBoundsDirty(true)
    80     , m_isDragCaretController(isDragCaretController)
    8196    , m_isCaretBlinkingSuspended(false)
    8297    , m_focused(frame && frame->page() && frame->page()->focusController()->focusedFrame() == frame)
    83     , m_caretVisible(isDragCaretController)
    84     , m_caretPaint(true)
    8598{
    8699    setIsDirectional(false);
     
    128141}
    129142
     143void DragCaretController::setCaretPosition(const VisiblePosition& position)
     144{
     145    if (m_position == position)
     146        return;
     147
     148    if (Node* node = m_position.deepEquivalent().containerNode())
     149        invalidateCaretRect(node);
     150    m_position = position;
     151    m_caretRectNeedsUpdate = true;
     152    Document* document = 0;
     153    if (Node* node = m_position.deepEquivalent().containerNode()) {
     154        invalidateCaretRect(node);
     155        document = node->document();
     156    }
     157    updateCaretRect(document, m_position, m_position.isNotNull() ? VisibleSelection::CaretSelection : VisibleSelection::NoSelection, m_position.isOrphan());
     158}
     159
    130160void FrameSelection::setSelection(const VisibleSelection& s, SetSelectionOptions options, CursorAlignOnScroll align, TextGranularity granularity, DirectionalityPolicy directionalityPolicy)
    131161{
     
    138168    setIsDirectional(directionalityPolicy == MakeDirectionalSelection);
    139169
    140     if (m_isDragCaretController) {
    141         invalidateCaretRect();
    142         m_selection = s;
    143         m_caretRectNeedsUpdate = true;
    144         invalidateCaretRect();
    145         updateCaretRect();
    146         return;
    147     }
    148170    if (!m_frame) {
    149171        m_selection = s;
     
    220242}
    221243
    222 void FrameSelection::nodeWillBeRemoved(Node *node)
    223 {
    224     if (isNone())
    225         return;
    226 
     244static void clearRenderViewSelection(const Position& position)
     245{
     246    RefPtr<Document> document = position.anchorNode()->document();
     247    document->updateStyleIfNeeded();
     248    if (RenderView* view = toRenderView(document->renderer()))
     249        view->clearSelection();
     250}
     251
     252void DragCaretController::nodeWillBeRemoved(Node* node)
     253{
     254    if (!hasCaret() || (node && !node->inDocument()))
     255        return;
     256
     257    if (!removingNodeRemovesPosition(node, m_position.deepEquivalent()))
     258        return;
     259
     260    clearRenderViewSelection(m_position.deepEquivalent());
     261    clear();
     262}
     263
     264void FrameSelection::nodeWillBeRemoved(Node* node)
     265{
    227266    // There can't be a selection inside a fragment, so if a fragment's node is being removed,
    228267    // the selection in the document that created the fragment needs no adjustment.
    229     if (node && highestAncestor(node)->nodeType() == Node::DOCUMENT_FRAGMENT_NODE)
     268    if (isNone() || (node && !node->inDocument()))
    230269        return;
    231270
     
    264303    }
    265304
    266     if (clearRenderTreeSelection) {
    267         RefPtr<Document> document = m_selection.start().anchorNode()->document();
    268         document->updateStyleIfNeeded();
    269         if (RenderView* view = toRenderView(document->renderer()))
    270             view->clearSelection();
    271     }
     305    if (clearRenderTreeSelection)
     306        clearRenderViewSelection(m_selection.start());
    272307
    273308    if (clearDOMTreeSelection)
     
    10321067}
    10331068
    1034 void FrameSelection::updateCaretRect()
    1035 {
    1036     if (isNone() || !m_selection.start().anchorNode()->inDocument() || !m_selection.end().anchorNode()->inDocument()) {
     1069void CaretBase::updateCaretRect(Document* document, const VisiblePosition& caretPosition, VisibleSelection::SelectionType type, bool isOrphaned)
     1070{
     1071    if (type == VisibleSelection::NoSelection || isOrphaned) {
    10371072        m_caretRect = IntRect();
    10381073        return;
    10391074    }
    10401075
    1041     m_selection.start().anchorNode()->document()->updateStyleIfNeeded();
     1076    document->updateStyleIfNeeded();
     1077
     1078    m_caretRect = IntRect();
    10421079   
    1043     m_caretRect = IntRect();
    1044        
    1045     if (isCaret()) {
    1046         VisiblePosition pos(m_selection.start(), m_selection.affinity());
    1047         if (pos.isNotNull()) {
    1048             ASSERT(pos.deepEquivalent().deprecatedNode()->renderer());
    1049            
     1080    if (type == VisibleSelection::CaretSelection) {
     1081        if (caretPosition.isNotNull()) {
     1082            ASSERT(caretPosition.deepEquivalent().deprecatedNode()->renderer());
     1083
    10501084            // First compute a rect local to the renderer at the selection start
    10511085            RenderObject* renderer;
    1052             IntRect localRect = pos.localCaretRect(renderer);
     1086            IntRect localRect = caretPosition.localCaretRect(renderer);
    10531087
    10541088            // Get the renderer that will be responsible for painting the caret (which
    10551089            // is either the renderer we just found, or one of its containers)
    1056             RenderObject* caretPainter = caretRenderer();
     1090            RenderObject* caretPainter = caretRenderer(caretPosition.deepEquivalent().deprecatedNode());
    10571091
    10581092            // Compute an offset between the renderer and the caretPainter
     
    10781112}
    10791113
    1080 RenderObject* FrameSelection::caretRenderer() const
    1081 {
    1082     Node* node = m_selection.start().deprecatedNode();
     1114static inline bool caretRendersInsideNode(Node* node)
     1115{
     1116    return node && !isTableElement(node) && !editingIgnoresContent(node);
     1117}
     1118
     1119RenderObject* CaretBase::caretRenderer(Node* node) const
     1120{
    10831121    if (!node)
    10841122        return 0;
     
    10931131}
    10941132
     1133RenderObject* FrameSelection::caretRenderer() const
     1134{
     1135    return CaretBase::caretRenderer(m_selection.start().deprecatedNode());
     1136}
     1137
     1138RenderObject* DragCaretController::caretRenderer() const
     1139{
     1140    return CaretBase::caretRenderer(m_position.deepEquivalent().deprecatedNode());
     1141}
     1142
    10951143IntRect FrameSelection::localCaretRect()
    10961144{
    1097     if (m_caretRectNeedsUpdate)
    1098         updateCaretRect();
    1099    
     1145    if (m_caretRectNeedsUpdate) {
     1146        bool isOrphaned = !isNone() && (!m_selection.start().anchorNode()->inDocument() || !m_selection.end().anchorNode()->inDocument());
     1147        updateCaretRect(m_frame->document(), VisiblePosition(m_selection.start(), m_selection.affinity()), m_selection.selectionType(), isOrphaned);
     1148    }
     1149
    11001150    return m_caretRect;
    11011151}
    11021152
    1103 IntRect FrameSelection::absoluteBoundsForLocalRect(const IntRect& rect) const
    1104 {
    1105     RenderObject* caretPainter = caretRenderer();
     1153IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const IntRect& rect) const
     1154{
     1155    RenderObject* caretPainter = caretRenderer(node);
    11061156    if (!caretPainter)
    11071157        return IntRect();
     
    11291179}
    11301180
    1131 IntRect FrameSelection::caretRepaintRect() const
    1132 {
    1133     return absoluteBoundsForLocalRect(repaintRectForCaret(localCaretRectForPainting()));
     1181IntRect CaretBase::caretRepaintRect(Node* node) const
     1182{
     1183    return absoluteBoundsForLocalRect(node, repaintRectForCaret(localCaretRectForPainting()));
    11341184}
    11351185
     
    11411191    if (!m_frame)
    11421192        return false;
    1143        
     1193
    11441194    FrameView* v = m_frame->document()->view();
    11451195    if (!v)
     
    11531203    IntRect oldAbsCaretBounds = m_absCaretBounds;
    11541204    // FIXME: Rename m_caretRect to m_localCaretRect.
    1155     m_absCaretBounds = absoluteBoundsForLocalRect(m_caretRect);
     1205    m_absCaretBounds = absoluteBoundsForLocalRect(m_selection.start().deprecatedNode(), m_caretRect);
    11561206    m_absCaretBoundsDirty = false;
    11571207   
     
    11611211    IntRect oldAbsoluteCaretRepaintBounds = m_absoluteCaretRepaintBounds;
    11621212    // We believe that we need to inflate the local rect before transforming it to obtain the repaint bounds.
    1163     m_absoluteCaretRepaintBounds = caretRepaintRect();
     1213    m_absoluteCaretRepaintBounds = caretRepaintRect(m_selection.start().deprecatedNode());
    11641214
    11651215#if ENABLE(TEXT_CARET)   
     
    11671217        // FIXME: make caret repainting container-aware.
    11681218        view->repaintRectangleInViewAndCompositedLayers(oldAbsoluteCaretRepaintBounds, false);
    1169         if (shouldRepaintCaret(view))
     1219        if (shouldRepaintCaret(view, isContentEditable()))
    11701220            view->repaintRectangleInViewAndCompositedLayers(m_absoluteCaretRepaintBounds, false);
    11711221    }
     
    11741224}
    11751225
    1176 bool FrameSelection::shouldRepaintCaret(const RenderView* view) const
     1226bool CaretBase::shouldRepaintCaret(const RenderView* view, bool isContentEditable) const
    11771227{
    11781228    ASSERT(view);
    11791229    Frame* frame = view->frameView() ? view->frameView()->frame() : 0; // The frame where the selection started.
    11801230    bool caretBrowsing = frame && frame->settings() && frame->settings()->caretBrowsingEnabled();
    1181     return (caretBrowsing || isContentEditable());
     1231    return (caretBrowsing || isContentEditable);
    11821232}
    11831233
     
    11871237        return;
    11881238
    1189     Document* d = m_selection.start().anchorNode()->document();
    1190 
    1191     // recomputeCaretRect will always return false for the drag caret,
    1192     // because its m_frame is always 0.
    1193     bool caretRectChanged = recomputeCaretRect();
    1194 
     1239    CaretBase::invalidateCaretRect(m_selection.start().deprecatedNode(), recomputeCaretRect());
     1240}
     1241
     1242void CaretBase::invalidateCaretRect(Node* node, bool caretRectChanged)
     1243{
    11951244    // EDIT FIXME: This is an unfortunate hack.
    11961245    // Basically, we can't trust this layout position since we
     
    12071256
    12081257    if (!caretRectChanged) {
    1209         RenderView* view = toRenderView(d->renderer());
    1210         if (view && shouldRepaintCaret(view))
    1211             view->repaintRectangleInViewAndCompositedLayers(caretRepaintRect(), false);
     1258        RenderView* view = toRenderView(node->document()->renderer());
     1259        if (view && shouldRepaintCaret(view, node->isContentEditable()))
     1260            view->repaintRectangleInViewAndCompositedLayers(caretRepaintRect(node), false);
    12121261    }
    12131262}
    12141263
    12151264void FrameSelection::paintCaret(GraphicsContext* context, int tx, int ty, const IntRect& clipRect)
     1265{
     1266    if (!m_selection.isCaret())
     1267        return;
     1268
     1269    CaretBase::paintCaret(m_selection.start().deprecatedNode(), context, tx, ty, clipRect);
     1270}
     1271
     1272void CaretBase::paintCaret(Node* node, GraphicsContext* context, int tx, int ty, const IntRect& clipRect) const
    12161273{
    12171274#if ENABLE(TEXT_CARET)
     
    12201277    if (!m_caretPaint)
    12211278        return;
    1222     if (!m_selection.isCaret())
    1223         return;
    12241279
    12251280    IntRect drawingRect = localCaretRectForPainting();
    1226     if (caretRenderer() && caretRenderer()->isBox())
    1227         toRenderBox(caretRenderer())->flipForWritingMode(drawingRect);
     1281    RenderObject* renderer = caretRenderer(node);
     1282    if (renderer && renderer->isBox())
     1283        toRenderBox(renderer)->flipForWritingMode(drawingRect);
    12281284    drawingRect.move(tx, ty);
    12291285    IntRect caret = intersection(drawingRect, clipRect);
     
    12331289    Color caretColor = Color::black;
    12341290    ColorSpace colorSpace = ColorSpaceDeviceRGB;
    1235     Element* element = rootEditableElement();
     1291    Element* element = node->rootEditableElement();
    12361292    if (element && element->renderer()) {
    12371293        caretColor = element->renderer()->style()->visitedDependentColor(CSSPropertyColor);
     
    12411297    context->fillRect(caret, caretColor, colorSpace);
    12421298#else
     1299    UNUSED_PARAM(node);
    12431300    UNUSED_PARAM(context);
    12441301    UNUSED_PARAM(tx);
     
    14811538}
    14821539
    1483 bool FrameSelection::caretRendersInsideNode(Node* node) const
    1484 {
    1485     if (!node)
    1486         return false;
    1487     return !isTableElement(node) && !editingIgnoresContent(node);
    1488 }
    1489 
    14901540void FrameSelection::focusedOrActiveStateChanged()
    14911541{
     
    15561606void FrameSelection::updateAppearance()
    15571607{
    1558     ASSERT(!m_isDragCaretController);
    1559 
    15601608#if ENABLE(TEXT_CARET)
    15611609    bool caretRectChanged = recomputeCaretRect();
     
    17101758}
    17111759
    1712 void FrameSelection::paintDragCaret(GraphicsContext* p, int tx, int ty, const IntRect& clipRect) const
     1760void DragCaretController::paintDragCaret(Frame* frame, GraphicsContext* p, int tx, int ty, const IntRect& clipRect) const
    17131761{
    17141762#if ENABLE(TEXT_CARET)
    1715     FrameSelection* dragCaretController = m_frame->page()->dragCaretController();
    1716     ASSERT(dragCaretController->selection().isCaret());
    1717     if (dragCaretController->selection().start().anchorNode()->document()->frame() == m_frame)
    1718         dragCaretController->paintCaret(p, tx, ty, clipRect);
     1763    if (m_position.deepEquivalent().deprecatedNode()->document()->frame() == frame)
     1764        paintCaret(m_position.deepEquivalent().deprecatedNode(), p, tx, ty, clipRect);
    17191765#else
    17201766    UNUSED_PARAM(p);
  • trunk/Source/WebCore/editing/FrameSelection.h

    r85864 r86039  
    4949enum DirectionalityPolicy { MakeNonDirectionalSelection, MakeDirectionalSelection };
    5050
    51 class FrameSelection {
     51class CaretBase {
     52    WTF_MAKE_NONCOPYABLE(CaretBase);
     53    WTF_MAKE_FAST_ALLOCATED;
     54protected:
     55    CaretBase();
     56
     57    void invalidateCaretRect(Node*, bool caretRectChanged = false);
     58    void updateCaretRect(Document*, const VisiblePosition& caretPosition, VisibleSelection::SelectionType, bool isOrphaned);
     59    IntRect absoluteBoundsForLocalRect(Node*, const IntRect&) const;
     60    IntRect absoluteCaretBounds(bool isContentEditable);
     61    IntRect caretRepaintRect(Node*) const;
     62    bool shouldRepaintCaret(const RenderView*, bool isContentEditable) const;
     63
     64    IntRect localCaretRectForPainting() const { return m_caretRect; }
     65    void paintCaret(Node*, GraphicsContext*, int tx, int ty, const IntRect& clipRect) const;
     66
     67    RenderObject* caretRenderer(Node*) const;
     68
     69    IntRect m_caretRect; // caret rect in coords local to the renderer responsible for painting the caret
     70    IntRect m_absCaretBounds; // absolute bounding rect for the caret
     71    IntRect m_absoluteCaretRepaintBounds;
     72
     73    bool m_caretRectNeedsUpdate; // true if m_caretRect and m_absCaretBounds need to be calculated
     74    bool m_absCaretBoundsDirty;
     75    bool m_caretVisible;
     76    bool m_caretPaint;
     77};
     78
     79class DragCaretController : private CaretBase {
     80    WTF_MAKE_NONCOPYABLE(DragCaretController);
     81    WTF_MAKE_FAST_ALLOCATED;
     82public:
     83    DragCaretController();
     84
     85    RenderObject* caretRenderer() const;
     86    void paintDragCaret(Frame*, GraphicsContext*, int tx, int ty, const IntRect& clipRect) const;
     87
     88    bool isContentEditable() const { return m_position.rootEditableElement(); }
     89    bool isContentRichlyEditable() const;
     90
     91    bool hasCaret() const { return m_position.isNotNull(); }
     92    const VisiblePosition& caretPosition() { return m_position; }
     93    void setCaretPosition(const VisiblePosition&);
     94    void clear() { setCaretPosition(VisiblePosition()); }
     95
     96    void nodeWillBeRemoved(Node*);
     97
     98private:
     99    VisiblePosition m_position;
     100};
     101
     102class FrameSelection : private CaretBase {
    52103    WTF_MAKE_NONCOPYABLE(FrameSelection);
    53104    WTF_MAKE_FAST_ALLOCATED;
     
    64115    typedef unsigned SetSelectionOptions;
    65116
    66     FrameSelection(Frame* = 0, bool isDragCaretController = false);
     117    FrameSelection(Frame* = 0);
    67118
    68119    Element* rootEditableElement() const { return m_selection.rootEditableElement(); }
     
    115166    // Caret rect local to the caret's renderer
    116167    IntRect localCaretRect();
    117     IntRect localCaretRectForPainting() const { return m_caretRect; }
    118168
    119169    // Bounds of (possibly transformed) caret in absolute coords
     
    140190    void setCaretVisible(bool = true);
    141191    void clearCaretRectIfNeeded();
    142     bool recomputeCaretRect(); // returns true if caret rect moved
     192    bool recomputeCaretRect();
    143193    void invalidateCaretRect();
    144194    void paintCaret(GraphicsContext*, int tx, int ty, const IntRect& clipRect);
     
    204254    VisiblePosition modifyMovingBackward(TextGranularity);
    205255
    206     void updateCaretRect();
    207     IntRect caretRepaintRect() const;
    208     bool shouldRepaintCaret(const RenderView* view) const;
    209 
    210256    int xPosForVerticalArrowNavigation(EPositionType);
    211257   
     
    213259
    214260    void focusedOrActiveStateChanged();
    215     bool caretRendersInsideNode(Node*) const;
    216    
    217     IntRect absoluteBoundsForLocalRect(const IntRect&) const;
    218261
    219262    void caretBlinkTimerFired(Timer<FrameSelection>*);
     
    232275    Timer<FrameSelection> m_caretBlinkTimer;
    233276
    234     IntRect m_caretRect; // caret rect in coords local to the renderer responsible for painting the caret
    235     IntRect m_absCaretBounds; // absolute bounding rect for the caret
    236     IntRect m_absoluteCaretRepaintBounds;
    237    
    238     bool m_caretRectNeedsUpdate; // true if m_caretRect and m_absCaretBounds need to be calculated
    239     bool m_absCaretBoundsDirty;
    240277    bool m_isDirectional;
    241     bool m_isDragCaretController;
    242278    bool m_isCaretBlinkingSuspended;
    243279    bool m_focused;
    244     bool m_caretVisible;
    245     bool m_caretPaint;
    246280};
    247281
  • trunk/Source/WebCore/page/DragController.cpp

    r85864 r86039  
    331331        if (!element)
    332332            return false;
    333         if (!asFileInput(element)) {
    334             VisibleSelection dragCaret = m_documentUnderMouse->frame()->visiblePositionForPoint(point);
    335             m_page->dragCaretController()->setSelection(dragCaret);
    336         }
     333        if (!asFileInput(element))
     334            m_page->dragCaretController()->setCaretPosition(m_documentUnderMouse->frame()->visiblePositionForPoint(point));
    337335
    338336        Frame* innerFrame = element->document()->frame();
     
    373371bool DragController::dispatchTextInputEventFor(Frame* innerFrame, DragData* dragData)
    374372{
    375     ASSERT(!m_page->dragCaretController()->isNone());
    376     VisibleSelection dragCaret(m_page->dragCaretController()->selection());
    377     String text = dragCaret.isContentRichlyEditable() ? "" : dragData->asPlainText(innerFrame);
    378     Node* target = innerFrame->editor()->findEventTargetFrom(dragCaret);
     373    ASSERT(m_page->dragCaretController()->hasCaret());
     374    String text = m_page->dragCaretController()->isContentRichlyEditable() ? "" : dragData->asPlainText(innerFrame);
     375    Node* target = innerFrame->editor()->findEventTargetFrom(m_page->dragCaretController()->caretPosition());
    379376    ExceptionCode ec = 0;
    380377    return target->dispatchEvent(TextEvent::createForDrop(innerFrame->domWindow(), text), ec);
     
    396393    ASSERT(innerFrame);
    397394
    398     if (!m_page->dragCaretController()->isNone() && !dispatchTextInputEventFor(innerFrame, dragData))
     395    if (m_page->dragCaretController()->hasCaret() && !dispatchTextInputEventFor(innerFrame, dragData))
    399396        return true;
    400397
     
    442439    }
    443440
    444     VisibleSelection dragCaret(m_page->dragCaretController()->selection());
     441    VisibleSelection dragCaret = m_page->dragCaretController()->caretPosition();
    445442    m_page->dragCaretController()->clear();
    446443    RefPtr<Range> range = dragCaret.toNormalizedRange();
     
    852849        return;
    853850    IntPoint framePoint = frameView->windowToContents(windowPoint);
    854     VisibleSelection dragCaret(frame->visiblePositionForPoint(framePoint));
    855     m_page->dragCaretController()->setSelection(dragCaret);
     851
     852    m_page->dragCaretController()->setCaretPosition(frame->visiblePositionForPoint(framePoint));
    856853}
    857854
  • trunk/Source/WebCore/page/Page.cpp

    r85895 r86039  
    116116Page::Page(const PageClients& pageClients)
    117117    : m_chrome(adoptPtr(new Chrome(this, pageClients.chromeClient)))
    118     , m_dragCaretController(adoptPtr(new FrameSelection(0, true)))
     118    , m_dragCaretController(adoptPtr(new DragCaretController))
    119119#if ENABLE(DRAG_SUPPORT)
    120120    , m_dragController(adoptPtr(new DragController(this, pageClients.dragClient)))
  • trunk/Source/WebCore/page/Page.h

    r85864 r86039  
    5555    class DeviceOrientationController;
    5656    class Document;
     57    class DragCaretController;
    5758    class DragClient;
    5859    class DragController;
     
    166167
    167168        Chrome* chrome() const { return m_chrome.get(); }
    168         FrameSelection* dragCaretController() const { return m_dragCaretController.get(); }
     169        DragCaretController* dragCaretController() const { return m_dragCaretController.get(); }
    169170#if ENABLE(DRAG_SUPPORT)
    170171        DragController* dragController() const { return m_dragController.get(); }
     
    316317
    317318        OwnPtr<Chrome> m_chrome;
    318         OwnPtr<FrameSelection> m_dragCaretController;
     319        OwnPtr<DragCaretController> m_dragCaretController;
    319320
    320321#if ENABLE(ACCELERATED_2D_CANVAS)
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r85876 r86039  
    24302430void RenderBlock::paintCaret(PaintInfo& paintInfo, int tx, int ty, CaretType type)
    24312431{
    2432     FrameSelection* selection = type == CursorCaret ? frame()->selection() : frame()->page()->dragCaretController();
    2433 
    24342432    // Paint the caret if the FrameSelection says so or if caret browsing is enabled
    24352433    bool caretBrowsing = frame()->settings() && frame()->settings()->caretBrowsingEnabled();
    2436     RenderObject* caretPainter = selection->caretRenderer();
    2437     if (caretPainter == this && (selection->isContentEditable() || caretBrowsing)) {
     2434    RenderObject* caretPainter;
     2435    bool isContentEditable;
     2436    if (type == CursorCaret) {
     2437        caretPainter = frame()->selection()->caretRenderer();
     2438        isContentEditable = frame()->selection()->isContentEditable();
     2439    } else {
     2440        caretPainter = frame()->page()->dragCaretController()->caretRenderer();
     2441        isContentEditable = frame()->page()->dragCaretController()->isContentEditable();
     2442    }
     2443
     2444    if (caretPainter == this && (isContentEditable || caretBrowsing)) {
    24382445        // Convert the painting offset into the local coordinate system of this renderer,
    24392446        // to match the localCaretRect computed by the FrameSelection
     
    24432450            frame()->selection()->paintCaret(paintInfo.context, tx, ty, paintInfo.rect);
    24442451        else
    2445             frame()->selection()->paintDragCaret(paintInfo.context, tx, ty, paintInfo.rect);
     2452            frame()->page()->dragCaretController()->paintDragCaret(frame(), paintInfo.context, tx, ty, paintInfo.rect);
    24462453    }
    24472454}
Note: See TracChangeset for help on using the changeset viewer.