Changeset 86193 in webkit
- Timestamp:
- May 10, 2011 4:32:17 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r86189 r86193 1 2011-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 1 41 2011-05-10 James Robinson <jamesr@chromium.org> 2 42 -
trunk/Source/WebCore/editing/FrameSelection.cpp
r86104 r86193 72 72 const int NoXPosForVerticalArrowNavigation = INT_MIN; 73 73 74 CaretBase::CaretBase( )74 CaretBase::CaretBase(CaretVisibility visibility) 75 75 : m_caretRectNeedsUpdate(true) 76 , m_absCaretBoundsDirty(true) 77 , m_caretVisible(false) 78 , m_caretPaint(true) 76 , m_caretVisibility(visibility) 79 77 { 80 78 } 81 79 82 80 DragCaretController::DragCaretController() 83 { 84 m_caretVisible = true; 81 : CaretBase(Visible) 82 { 85 83 } 86 84 … … 95 93 , m_granularity(CharacterGranularity) 96 94 , m_caretBlinkTimer(this, &FrameSelection::caretBlinkTimerFired) 95 , m_absCaretBoundsDirty(true) 96 , m_caretPaint(true) 97 97 , m_isCaretBlinkingSuspended(false) 98 98 , m_focused(frame && frame->page() && frame->page()->focusController()->focusedFrame() == frame) … … 147 147 invalidateCaretRect(node); 148 148 m_position = position; 149 m_caretRectNeedsUpdate = true;149 setCaretRectNeedsUpdate(); 150 150 Document* document = 0; 151 151 if (Node* node = m_position.deepEquivalent().deprecatedNode()) { … … 153 153 document = node->document(); 154 154 } 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); 156 159 } 157 160 … … 196 199 197 200 m_selection = s; 198 199 m_caretRectNeedsUpdate = true; 201 setCaretRectNeedsUpdate(); 200 202 201 203 if (!s.isNone()) … … 1060 1062 } 1061 1063 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 1064 void CaretBase::clearCaretRect() 1065 { 1066 m_caretLocalRect = IntRect(); 1067 } 1068 1069 bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caretPosition) 1070 { 1074 1071 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; 1106 1096 } 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; 1110 1105 } 1111 1106 … … 1141 1136 IntRect FrameSelection::localCaretRect() 1142 1137 { 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(); 1149 1146 } 1150 1147 … … 1179 1176 IntRect CaretBase::caretRepaintRect(Node* node) const 1180 1177 { 1181 return absoluteBoundsForLocalRect(node, repaintRectForCaret(localCaretRect ForPainting()));1178 return absoluteBoundsForLocalRect(node, repaintRectForCaret(localCaretRectWithoutUpdate())); 1182 1179 } 1183 1180 1184 1181 bool FrameSelection::recomputeCaretRect() 1185 1182 { 1186 if (! m_caretRectNeedsUpdate)1183 if (!shouldUpdateCaretRect()) 1187 1184 return false; 1188 1185 … … 1194 1191 return false; 1195 1192 1196 IntRect oldRect = m_caretRect;1193 IntRect oldRect = localCaretRectWithoutUpdate(); 1197 1194 IntRect newRect = localCaretRect(); 1198 1195 if (oldRect == newRect && !m_absCaretBoundsDirty) … … 1201 1198 IntRect oldAbsCaretBounds = m_absCaretBounds; 1202 1199 // 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()); 1204 1201 m_absCaretBoundsDirty = false; 1205 1202 … … 1262 1259 void FrameSelection::paintCaret(GraphicsContext* context, int tx, int ty, const IntRect& clipRect) 1263 1260 { 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); 1268 1263 } 1269 1264 … … 1271 1266 { 1272 1267 #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(); 1279 1272 RenderObject* renderer = caretRenderer(node); 1280 1273 if (renderer && renderer->isBox()) … … 1567 1560 if (activeAndFocused) 1568 1561 setSelectionFromNone(); 1569 setCaretVisib le(activeAndFocused);1562 setCaretVisibility(activeAndFocused ? Visible : Hidden); 1570 1563 1571 1564 // Update for caps lock state … … 1626 1619 1627 1620 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); 1630 1622 1631 1623 // If the caret moved, stop the blink timer so we can restart with a … … 1683 1675 } 1684 1676 1685 void FrameSelection::setCaretVisib le(bool flag)1686 { 1687 if ( m_caretVisible == flag)1677 void FrameSelection::setCaretVisibility(CaretVisibility visibility) 1678 { 1679 if (caretVisibility() == visibility) 1688 1680 return; 1689 1681 clearCaretRectIfNeeded(); 1690 m_caretVisible = flag;1682 CaretBase::setCaretVisibility(visibility); 1691 1683 updateAppearance(); 1692 1684 } … … 1705 1697 { 1706 1698 #if ENABLE(TEXT_CARET) 1707 ASSERT( m_caretVisible);1699 ASSERT(caretIsVisible()); 1708 1700 ASSERT(isCaret()); 1709 1701 bool caretPaint = m_caretPaint; -
trunk/Source/WebCore/editing/FrameSelection.h
r86039 r86193 53 53 WTF_MAKE_FAST_ALLOCATED; 54 54 protected: 55 CaretBase(); 55 enum CaretVisibility { Visible, Hidden }; 56 explicit CaretBase(CaretVisibility = Hidden); 56 57 57 58 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); 59 61 IntRect absoluteBoundsForLocalRect(Node*, const IntRect&) const; 60 IntRect absoluteCaretBounds(bool isContentEditable);61 62 IntRect caretRepaintRect(Node*) const; 62 63 bool shouldRepaintCaret(const RenderView*, bool isContentEditable) const; 63 64 IntRect localCaretRectForPainting() const { return m_caretRect; }65 64 void paintCaret(Node*, GraphicsContext*, int tx, int ty, const IntRect& clipRect) const; 66 67 65 RenderObject* caretRenderer(Node*) const; 68 66 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 76 private: 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; 77 80 }; 78 81 … … 169 172 // Bounds of (possibly transformed) caret in absolute coords 170 173 IntRect absoluteCaretBounds(); 171 void setCaretRectNeedsUpdate( bool flag = true);174 void setCaretRectNeedsUpdate() { CaretBase::setCaretRectNeedsUpdate(); } 172 175 173 176 void setIsDirectional(bool); … … 188 191 void textWillBeReplaced(CharacterData*, unsigned offset, unsigned oldLength, unsigned newLength); 189 192 190 void setCaretVisible(bool = true);193 void setCaretVisible(bool caretIsVisible) { setCaretVisibility(caretIsVisible ? Visible : Hidden); } 191 194 void clearCaretRectIfNeeded(); 192 195 bool recomputeCaretRect(); … … 264 267 void setUseSecureKeyboardEntry(bool); 265 268 269 void setCaretVisibility(CaretVisibility); 270 266 271 Frame* m_frame; 267 272 … … 274 279 275 280 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; 276 285 277 286 bool m_isDirectional;
Note: See TracChangeset
for help on using the changeset viewer.