Changeset 86193 in webkit


Ignore:
Timestamp:
May 10, 2011 4:32:17 PM (13 years ago)
Author:
rniwa@webkit.org
Message:

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

Reviewed by Darin Adler.

Make member variables of CaretBase private
https://bugs.webkit.org/show_bug.cgi?id=60454

Moved m_absCaretBounds, m_absoluteCaretRepaintBounds, m_absCaretBoundsDirty, and m_caretPaint back
from CaretBase to FrameSelection because they are only used in FrameSelection, and made the rest
of member variables in CaretBase private.

  • editing/FrameSelection.cpp: (WebCore::CaretBase::CaretBase): Takes CaretVisibility as an argument. (WebCore::DragCaretController::DragCaretController): (WebCore::FrameSelection::FrameSelection): Initializes m_absCaretBoundsDirty and m_caretPaint now that they are part of FrameSelection again. (WebCore::DragCaretController::setCaretPosition): (WebCore::FrameSelection::setSelection): (WebCore::CaretBase::clearCaretRect): Extracted from updateCaretRect. (WebCore::CaretBase::updateCaretRect): No longer clears caret; all call sites (namely setCaretPosition and localCaretRect) that used to call updateCaretRect now need to call clearCaretRect or updateCaretRect based on some conditions. (WebCore::FrameSelection::localCaretRect): (WebCore::CaretBase::caretRepaintRect): (WebCore::FrameSelection::recomputeCaretRect): (WebCore::FrameSelection::paintCaret): Only calls CaretBase::paintCaret if m_caretPaint is true. (WebCore::CaretBase::paintCaret): Removed an early exit for when m_caretPaint is false since m_caretPaint has been moved from CaretBase to FrameSelection. (WebCore::FrameSelection::focusedOrActiveStateChanged): (WebCore::FrameSelection::updateAppearance): (WebCore::FrameSelection::setCaretVisibility): Takes CaretVisibility instead of bool. (WebCore::FrameSelection::caretBlinkTimerFired):
  • editing/FrameSelection.h: (WebCore::CaretBase::fastLocalCaretRect): Added; replaces localCaretRectForPainting. (WebCore::CaretBase::shouldUpdateCaretRect): Added. (WebCore::CaretBase::setCaretRectNeedsUpdate): Added. (WebCore::CaretBase::setCaretVisibility): Added. (WebCore::CaretBase::caretIsVisible): Added. (WebCore::FrameSelection::setCaretRectNeedsUpdate): Added.
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r86189 r86193  
     12011-05-10  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Make member variables of CaretBase private
     6        https://bugs.webkit.org/show_bug.cgi?id=60454
     7
     8        Moved m_absCaretBounds, m_absoluteCaretRepaintBounds, m_absCaretBoundsDirty, and m_caretPaint back
     9        from CaretBase to FrameSelection because they are only used in FrameSelection, and made the rest
     10        of member variables in CaretBase private.
     11
     12        * editing/FrameSelection.cpp:
     13        (WebCore::CaretBase::CaretBase): Takes CaretVisibility as an argument.
     14        (WebCore::DragCaretController::DragCaretController):
     15        (WebCore::FrameSelection::FrameSelection): Initializes m_absCaretBoundsDirty and m_caretPaint
     16        now that they are part of FrameSelection again.
     17        (WebCore::DragCaretController::setCaretPosition):
     18        (WebCore::FrameSelection::setSelection):
     19        (WebCore::CaretBase::clearCaretRect): Extracted from updateCaretRect.
     20        (WebCore::CaretBase::updateCaretRect): No longer clears caret; all call sites (namely setCaretPosition
     21        and localCaretRect) that used to call updateCaretRect now need to call clearCaretRect or updateCaretRect
     22        based on some conditions.
     23        (WebCore::FrameSelection::localCaretRect):
     24        (WebCore::CaretBase::caretRepaintRect):
     25        (WebCore::FrameSelection::recomputeCaretRect):
     26        (WebCore::FrameSelection::paintCaret): Only calls CaretBase::paintCaret if m_caretPaint is true.
     27        (WebCore::CaretBase::paintCaret): Removed an early exit for when m_caretPaint is false since m_caretPaint
     28        has been moved from CaretBase to FrameSelection.
     29        (WebCore::FrameSelection::focusedOrActiveStateChanged):
     30        (WebCore::FrameSelection::updateAppearance):
     31        (WebCore::FrameSelection::setCaretVisibility): Takes CaretVisibility instead of bool.
     32        (WebCore::FrameSelection::caretBlinkTimerFired):
     33        * editing/FrameSelection.h:
     34        (WebCore::CaretBase::fastLocalCaretRect): Added; replaces localCaretRectForPainting.
     35        (WebCore::CaretBase::shouldUpdateCaretRect): Added.
     36        (WebCore::CaretBase::setCaretRectNeedsUpdate): Added.
     37        (WebCore::CaretBase::setCaretVisibility): Added.
     38        (WebCore::CaretBase::caretIsVisible): Added.
     39        (WebCore::FrameSelection::setCaretRectNeedsUpdate): Added.
     40
    1412011-05-10  James Robinson  <jamesr@chromium.org>
    242
  • trunk/Source/WebCore/editing/FrameSelection.cpp

    r86104 r86193  
    7272const int NoXPosForVerticalArrowNavigation = INT_MIN;
    7373
    74 CaretBase::CaretBase()
     74CaretBase::CaretBase(CaretVisibility visibility)
    7575    : m_caretRectNeedsUpdate(true)
    76     , m_absCaretBoundsDirty(true)
    77     , m_caretVisible(false)
    78     , m_caretPaint(true)
     76    , m_caretVisibility(visibility)
    7977{
    8078}
    8179
    8280DragCaretController::DragCaretController()
    83 {
    84     m_caretVisible = true;
     81    : CaretBase(Visible)
     82{
    8583}
    8684
     
    9593    , m_granularity(CharacterGranularity)
    9694    , m_caretBlinkTimer(this, &FrameSelection::caretBlinkTimerFired)
     95    , m_absCaretBoundsDirty(true)
     96    , m_caretPaint(true)
    9797    , m_isCaretBlinkingSuspended(false)
    9898    , m_focused(frame && frame->page() && frame->page()->focusController()->focusedFrame() == frame)
     
    147147        invalidateCaretRect(node);
    148148    m_position = position;
    149     m_caretRectNeedsUpdate = true;
     149    setCaretRectNeedsUpdate();
    150150    Document* document = 0;
    151151    if (Node* node = m_position.deepEquivalent().deprecatedNode()) {
     
    153153        document = node->document();
    154154    }
    155     updateCaretRect(document, m_position, m_position.isNotNull() ? VisibleSelection::CaretSelection : VisibleSelection::NoSelection, m_position.isOrphan());
     155    if (m_position.isNull() || m_position.isOrphan())
     156        clearCaretRect();
     157    else
     158        updateCaretRect(document, m_position);
    156159}
    157160
     
    196199
    197200    m_selection = s;
    198    
    199     m_caretRectNeedsUpdate = true;
     201    setCaretRectNeedsUpdate();
    200202   
    201203    if (!s.isNone())
     
    10601062}
    10611063
    1062 void FrameSelection::setCaretRectNeedsUpdate(bool flag)
    1063 {
    1064     m_caretRectNeedsUpdate = flag;
    1065 }
    1066 
    1067 void CaretBase::updateCaretRect(Document* document, const VisiblePosition& caretPosition, VisibleSelection::SelectionType type, bool isOrphaned)
    1068 {
    1069     if (type == VisibleSelection::NoSelection || isOrphaned) {
    1070         m_caretRect = IntRect();
    1071         return;
    1072     }
    1073 
     1064void CaretBase::clearCaretRect()
     1065{
     1066    m_caretLocalRect = IntRect();
     1067}
     1068
     1069bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caretPosition)
     1070{
    10741071    document->updateStyleIfNeeded();
    1075 
    1076     m_caretRect = IntRect();
    1077    
    1078     if (type == VisibleSelection::CaretSelection) {
    1079         if (caretPosition.isNotNull()) {
    1080             ASSERT(caretPosition.deepEquivalent().deprecatedNode()->renderer());
    1081 
    1082             // First compute a rect local to the renderer at the selection start
    1083             RenderObject* renderer;
    1084             IntRect localRect = caretPosition.localCaretRect(renderer);
    1085 
    1086             // Get the renderer that will be responsible for painting the caret (which
    1087             // is either the renderer we just found, or one of its containers)
    1088             RenderObject* caretPainter = caretRenderer(caretPosition.deepEquivalent().deprecatedNode());
    1089 
    1090             // Compute an offset between the renderer and the caretPainter
    1091             bool unrooted = false;
    1092             while (renderer != caretPainter) {
    1093                 RenderObject* containerObject = renderer->container();
    1094                 if (!containerObject) {
    1095                     unrooted = true;
    1096                     break;
    1097                 }
    1098                 localRect.move(renderer->offsetFromContainer(containerObject, localRect.location()));
    1099                 renderer = containerObject;
    1100             }
    1101            
    1102             if (!unrooted)
    1103                 m_caretRect = localRect;
    1104            
    1105             m_absCaretBoundsDirty = true;
     1072    m_caretLocalRect = IntRect();
     1073
     1074    m_caretRectNeedsUpdate = false;
     1075
     1076    if (caretPosition.isNull())
     1077        return false;
     1078
     1079    ASSERT(caretPosition.deepEquivalent().deprecatedNode()->renderer());
     1080
     1081    // First compute a rect local to the renderer at the selection start.
     1082    RenderObject* renderer;
     1083    IntRect localRect = caretPosition.localCaretRect(renderer);
     1084
     1085    // Get the renderer that will be responsible for painting the caret
     1086    // (which is either the renderer we just found, or one of its containers).
     1087    RenderObject* caretPainter = caretRenderer(caretPosition.deepEquivalent().deprecatedNode());
     1088
     1089    // Compute an offset between the renderer and the caretPainter.
     1090    bool unrooted = false;
     1091    while (renderer != caretPainter) {
     1092        RenderObject* containerObject = renderer->container();
     1093        if (!containerObject) {
     1094            unrooted = true;
     1095            break;
    11061096        }
    1107     }
    1108 
    1109     m_caretRectNeedsUpdate = false;
     1097        localRect.move(renderer->offsetFromContainer(containerObject, localRect.location()));
     1098        renderer = containerObject;
     1099    }
     1100
     1101    if (!unrooted)
     1102        m_caretLocalRect = localRect;
     1103
     1104    return true;
    11101105}
    11111106
     
    11411136IntRect FrameSelection::localCaretRect()
    11421137{
    1143     if (m_caretRectNeedsUpdate) {
    1144         bool isOrphaned = !isNone() && (!m_selection.start().anchorNode()->inDocument() || !m_selection.end().anchorNode()->inDocument());
    1145         updateCaretRect(m_frame->document(), VisiblePosition(m_selection.start(), m_selection.affinity()), m_selection.selectionType(), isOrphaned);
    1146     }
    1147 
    1148     return m_caretRect;
     1138    if (shouldUpdateCaretRect()) {
     1139        if (!isCaret() || m_selection.start().isOrphan() || m_selection.end().isOrphan())
     1140            clearCaretRect();
     1141        else if (updateCaretRect(m_frame->document(), VisiblePosition(m_selection.start(), m_selection.affinity())))
     1142            m_absCaretBoundsDirty = true;
     1143    }
     1144
     1145    return localCaretRectWithoutUpdate();
    11491146}
    11501147
     
    11791176IntRect CaretBase::caretRepaintRect(Node* node) const
    11801177{
    1181     return absoluteBoundsForLocalRect(node, repaintRectForCaret(localCaretRectForPainting()));
     1178    return absoluteBoundsForLocalRect(node, repaintRectForCaret(localCaretRectWithoutUpdate()));
    11821179}
    11831180
    11841181bool FrameSelection::recomputeCaretRect()
    11851182{
    1186     if (!m_caretRectNeedsUpdate)
     1183    if (!shouldUpdateCaretRect())
    11871184        return false;
    11881185
     
    11941191        return false;
    11951192
    1196     IntRect oldRect = m_caretRect;
     1193    IntRect oldRect = localCaretRectWithoutUpdate();
    11971194    IntRect newRect = localCaretRect();
    11981195    if (oldRect == newRect && !m_absCaretBoundsDirty)
     
    12011198    IntRect oldAbsCaretBounds = m_absCaretBounds;
    12021199    // FIXME: Rename m_caretRect to m_localCaretRect.
    1203     m_absCaretBounds = absoluteBoundsForLocalRect(m_selection.start().deprecatedNode(), m_caretRect);
     1200    m_absCaretBounds = absoluteBoundsForLocalRect(m_selection.start().deprecatedNode(), localCaretRectWithoutUpdate());
    12041201    m_absCaretBoundsDirty = false;
    12051202   
     
    12621259void FrameSelection::paintCaret(GraphicsContext* context, int tx, int ty, const IntRect& clipRect)
    12631260{
    1264     if (!m_selection.isCaret())
    1265         return;
    1266 
    1267     CaretBase::paintCaret(m_selection.start().deprecatedNode(), context, tx, ty, clipRect);
     1261    if (m_selection.isCaret() && m_caretPaint)
     1262        CaretBase::paintCaret(m_selection.start().deprecatedNode(), context, tx, ty, clipRect);
    12681263}
    12691264
     
    12711266{
    12721267#if ENABLE(TEXT_CARET)
    1273     if (!m_caretVisible)
    1274         return;
    1275     if (!m_caretPaint)
    1276         return;
    1277 
    1278     IntRect drawingRect = localCaretRectForPainting();
     1268    if (m_caretVisibility == Hidden)
     1269        return;
     1270
     1271    IntRect drawingRect = localCaretRectWithoutUpdate();
    12791272    RenderObject* renderer = caretRenderer(node);
    12801273    if (renderer && renderer->isBox())
     
    15671560    if (activeAndFocused)
    15681561        setSelectionFromNone();
    1569     setCaretVisible(activeAndFocused);
     1562    setCaretVisibility(activeAndFocused ? Visible : Hidden);
    15701563
    15711564    // Update for caps lock state
     
    16261619
    16271620    bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBrowsingEnabled();
    1628     bool shouldBlink = m_caretVisible
    1629         && isCaret() && (isContentEditable() || caretBrowsing);
     1621    bool shouldBlink = caretIsVisible() && isCaret() && (isContentEditable() || caretBrowsing);
    16301622
    16311623    // If the caret moved, stop the blink timer so we can restart with a
     
    16831675}
    16841676
    1685 void FrameSelection::setCaretVisible(bool flag)
    1686 {
    1687     if (m_caretVisible == flag)
     1677void FrameSelection::setCaretVisibility(CaretVisibility visibility)
     1678{
     1679    if (caretVisibility() == visibility)
    16881680        return;
    16891681    clearCaretRectIfNeeded();
    1690     m_caretVisible = flag;
     1682    CaretBase::setCaretVisibility(visibility);
    16911683    updateAppearance();
    16921684}
     
    17051697{
    17061698#if ENABLE(TEXT_CARET)
    1707     ASSERT(m_caretVisible);
     1699    ASSERT(caretIsVisible());
    17081700    ASSERT(isCaret());
    17091701    bool caretPaint = m_caretPaint;
  • trunk/Source/WebCore/editing/FrameSelection.h

    r86039 r86193  
    5353    WTF_MAKE_FAST_ALLOCATED;
    5454protected:
    55     CaretBase();
     55    enum CaretVisibility { Visible, Hidden };
     56    explicit CaretBase(CaretVisibility = Hidden);
    5657
    5758    void invalidateCaretRect(Node*, bool caretRectChanged = false);
    58     void updateCaretRect(Document*, const VisiblePosition& caretPosition, VisibleSelection::SelectionType, bool isOrphaned);
     59    void clearCaretRect();
     60    bool updateCaretRect(Document*, const VisiblePosition& caretPosition);
    5961    IntRect absoluteBoundsForLocalRect(Node*, const IntRect&) const;
    60     IntRect absoluteCaretBounds(bool isContentEditable);
    6162    IntRect caretRepaintRect(Node*) const;
    6263    bool shouldRepaintCaret(const RenderView*, bool isContentEditable) const;
    63 
    64     IntRect localCaretRectForPainting() const { return m_caretRect; }
    6564    void paintCaret(Node*, GraphicsContext*, int tx, int ty, const IntRect& clipRect) const;
    66 
    6765    RenderObject* caretRenderer(Node*) const;
    6866
    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;
     67    const IntRect& localCaretRectWithoutUpdate() const { return m_caretLocalRect; }
     68
     69    bool shouldUpdateCaretRect() const { return m_caretRectNeedsUpdate; }
     70    void setCaretRectNeedsUpdate() { m_caretRectNeedsUpdate = true; }
     71
     72    void setCaretVisibility(CaretVisibility visibility) { m_caretVisibility = visibility; }
     73    bool caretIsVisible() const { return m_caretVisibility == Visible; }
     74    CaretVisibility caretVisibility() const { return m_caretVisibility; }
     75
     76private:
     77    IntRect m_caretLocalRect; // caret rect in coords local to the renderer responsible for painting the caret
     78    bool m_caretRectNeedsUpdate; // true if m_caretRect (and m_absCaretBounds in FrameSelection) need to be calculated
     79    CaretVisibility m_caretVisibility;
    7780};
    7881
     
    169172    // Bounds of (possibly transformed) caret in absolute coords
    170173    IntRect absoluteCaretBounds();
    171     void setCaretRectNeedsUpdate(bool flag = true);
     174    void setCaretRectNeedsUpdate() { CaretBase::setCaretRectNeedsUpdate(); }
    172175
    173176    void setIsDirectional(bool);
     
    188191    void textWillBeReplaced(CharacterData*, unsigned offset, unsigned oldLength, unsigned newLength);
    189192
    190     void setCaretVisible(bool = true);
     193    void setCaretVisible(bool caretIsVisible) { setCaretVisibility(caretIsVisible ? Visible : Hidden); }
    191194    void clearCaretRectIfNeeded();
    192195    bool recomputeCaretRect();
     
    264267    void setUseSecureKeyboardEntry(bool);
    265268
     269    void setCaretVisibility(CaretVisibility);
     270
    266271    Frame* m_frame;
    267272
     
    274279
    275280    Timer<FrameSelection> m_caretBlinkTimer;
     281    IntRect m_absCaretBounds; // absolute bounding rect for the caret
     282    IntRect m_absoluteCaretRepaintBounds;
     283    bool m_absCaretBoundsDirty;
     284    bool m_caretPaint;
    276285
    277286    bool m_isDirectional;
Note: See TracChangeset for help on using the changeset viewer.