OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 { | 1149 { |
1150 m_granularity = CharacterGranularity; | 1150 m_granularity = CharacterGranularity; |
1151 | 1151 |
1152 m_caretBlinkTimer.stop(); | 1152 m_caretBlinkTimer.stop(); |
1153 | 1153 |
1154 RenderView* view = m_frame->contentRenderer(); | 1154 RenderView* view = m_frame->contentRenderer(); |
1155 if (view) | 1155 if (view) |
1156 view->clearSelection(); | 1156 view->clearSelection(); |
1157 | 1157 |
1158 setSelection(VisibleSelection(), CloseTyping | ClearTypingStyle | DoNotUpdat
eAppearance); | 1158 setSelection(VisibleSelection(), CloseTyping | ClearTypingStyle | DoNotUpdat
eAppearance); |
1159 m_previousCaretNode.clear(); | 1159 m_previousCaretPosition.clear(); |
1160 } | 1160 } |
1161 | 1161 |
1162 void FrameSelection::setStart(const VisiblePosition &pos, EUserTriggered trigger
) | 1162 void FrameSelection::setStart(const VisiblePosition &pos, EUserTriggered trigger
) |
1163 { | 1163 { |
1164 if (m_selection.isBaseFirst()) | 1164 if (m_selection.isBaseFirst()) |
1165 setBase(pos, trigger); | 1165 setBase(pos, trigger); |
1166 else | 1166 else |
1167 setExtent(pos, trigger); | 1167 setExtent(pos, trigger); |
1168 } | 1168 } |
1169 | 1169 |
(...skipping 24 matching lines...) Expand all Loading... |
1194 } | 1194 } |
1195 | 1195 |
1196 void FrameSelection::setExtent(const Position &pos, EAffinity affinity, EUserTri
ggered userTriggered) | 1196 void FrameSelection::setExtent(const Position &pos, EAffinity affinity, EUserTri
ggered userTriggered) |
1197 { | 1197 { |
1198 const bool selectionHasDirection = true; | 1198 const bool selectionHasDirection = true; |
1199 setSelection(VisibleSelection(m_selection.base(), pos, affinity, selectionHa
sDirection), CloseTyping | ClearTypingStyle | userTriggered); | 1199 setSelection(VisibleSelection(m_selection.base(), pos, affinity, selectionHa
sDirection), CloseTyping | ClearTypingStyle | userTriggered); |
1200 } | 1200 } |
1201 | 1201 |
1202 RenderObject* FrameSelection::caretRenderer() const | 1202 RenderObject* FrameSelection::caretRenderer() const |
1203 { | 1203 { |
1204 return CaretBase::caretRenderer(m_selection.start().deprecatedNode()); | 1204 return CaretBase::caretRenderer(m_selection.start()); |
1205 } | 1205 } |
1206 | 1206 |
1207 static bool isNonOrphanedCaret(const VisibleSelection& selection) | 1207 static bool isNonOrphanedCaret(const VisibleSelection& selection) |
1208 { | 1208 { |
1209 return selection.isCaret() && !selection.start().isOrphan() && !selection.en
d().isOrphan(); | 1209 return selection.isCaret() && !selection.start().isOrphan() && !selection.en
d().isOrphan(); |
1210 } | 1210 } |
1211 | 1211 |
1212 LayoutRect FrameSelection::localCaretRect() | 1212 LayoutRect FrameSelection::localCaretRect() |
1213 { | 1213 { |
1214 if (shouldUpdateCaretRect()) { | 1214 if (shouldUpdateCaretRect()) { |
(...skipping 23 matching lines...) Expand all Loading... |
1238 FrameView* v = m_frame->document()->view(); | 1238 FrameView* v = m_frame->document()->view(); |
1239 if (!v) | 1239 if (!v) |
1240 return false; | 1240 return false; |
1241 | 1241 |
1242 LayoutRect oldRect = localCaretRectWithoutUpdate(); | 1242 LayoutRect oldRect = localCaretRectWithoutUpdate(); |
1243 LayoutRect newRect = localCaretRect(); | 1243 LayoutRect newRect = localCaretRect(); |
1244 if (oldRect == newRect && !m_absCaretBoundsDirty) | 1244 if (oldRect == newRect && !m_absCaretBoundsDirty) |
1245 return false; | 1245 return false; |
1246 | 1246 |
1247 IntRect oldAbsCaretBounds = m_absCaretBounds; | 1247 IntRect oldAbsCaretBounds = m_absCaretBounds; |
1248 m_absCaretBounds = absoluteBoundsForLocalRect(m_selection.start().deprecated
Node(), localCaretRectWithoutUpdate()); | 1248 m_absCaretBounds = absoluteBoundsForLocalRect(m_selection.start(), localCare
tRectWithoutUpdate()); |
1249 m_absCaretBoundsDirty = false; | 1249 m_absCaretBoundsDirty = false; |
1250 | 1250 |
1251 if (oldAbsCaretBounds == m_absCaretBounds) | 1251 if (oldAbsCaretBounds == m_absCaretBounds) |
1252 return false; | 1252 return false; |
1253 | 1253 |
1254 if (RenderView* view = m_frame->document()->renderView()) { | 1254 if (RenderView* view = m_frame->document()->renderView()) { |
1255 Node* node = m_selection.start().deprecatedNode(); | 1255 if (m_previousCaretPosition.isNotNull()) |
1256 if (m_previousCaretNode) | 1256 repaintCaretForLocalRect(m_previousCaretPosition, oldRect); |
1257 repaintCaretForLocalRect(m_previousCaretNode.get(), oldRect); | 1257 m_previousCaretPosition = m_selection.start(); |
1258 m_previousCaretNode = node; | |
1259 if (shouldRepaintCaret(view, isContentEditable())) | 1258 if (shouldRepaintCaret(view, isContentEditable())) |
1260 repaintCaretForLocalRect(node, newRect); | 1259 repaintCaretForLocalRect(m_previousCaretPosition, newRect); |
1261 } | 1260 } |
1262 | 1261 |
1263 return true; | 1262 return true; |
1264 } | 1263 } |
1265 | 1264 |
1266 void FrameSelection::invalidateCaretRect() | 1265 void FrameSelection::invalidateCaretRect() |
1267 { | 1266 { |
1268 if (!isCaret()) | 1267 if (!isCaret()) |
1269 return; | 1268 return; |
1270 | 1269 |
1271 CaretBase::invalidateCaretRect(m_selection.start().deprecatedNode(), recompu
teCaretRect()); | 1270 CaretBase::invalidateCaretRect(m_selection.start(), recomputeCaretRect()); |
1272 } | 1271 } |
1273 | 1272 |
1274 void FrameSelection::paintCaret(GraphicsContext* context, const LayoutPoint& pai
ntOffset, const LayoutRect& clipRect) | 1273 void FrameSelection::paintCaret(GraphicsContext* context, const LayoutPoint& pai
ntOffset, const LayoutRect& clipRect) |
1275 { | 1274 { |
1276 if (m_selection.isCaret() && m_caretPaint) | 1275 if (m_selection.isCaret() && m_caretPaint) |
1277 CaretBase::paintCaret(m_selection.start().deprecatedNode(), context, pai
ntOffset, clipRect); | 1276 CaretBase::paintCaret(m_selection.start(), context, paintOffset, clipRec
t); |
1278 } | 1277 } |
1279 | 1278 |
1280 void FrameSelection::debugRenderer(RenderObject *r, bool selected) const | 1279 void FrameSelection::debugRenderer(RenderObject *r, bool selected) const |
1281 { | 1280 { |
1282 if (r->node()->isElementNode()) { | 1281 if (r->node()->isElementNode()) { |
1283 Element* element = toElement(r->node()); | 1282 Element* element = toElement(r->node()); |
1284 fprintf(stderr, "%s%s\n", selected ? "==> " : " ", element->localName
().string().utf8().data()); | 1283 fprintf(stderr, "%s%s\n", selected ? "==> " : " ", element->localName
().string().utf8().data()); |
1285 } else if (r->isText()) { | 1284 } else if (r->isText()) { |
1286 RenderText* textRenderer = toRenderText(r); | 1285 RenderText* textRenderer = toRenderText(r); |
1287 if (!textRenderer->textLength() || !textRenderer->firstTextBox()) { | 1286 if (!textRenderer->textLength() || !textRenderer->firstTextBox()) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 | 1347 |
1349 // Treat a collapsed selection like no selection. | 1348 // Treat a collapsed selection like no selection. |
1350 if (!isRange()) | 1349 if (!isRange()) |
1351 return false; | 1350 return false; |
1352 if (!document->renderer()) | 1351 if (!document->renderer()) |
1353 return false; | 1352 return false; |
1354 | 1353 |
1355 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | H
itTestRequest::DisallowShadowContent); | 1354 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | H
itTestRequest::DisallowShadowContent); |
1356 HitTestResult result(point); | 1355 HitTestResult result(point); |
1357 document->renderView()->hitTest(request, result); | 1356 document->renderView()->hitTest(request, result); |
1358 Node* innerNode = result.innerNode(); | 1357 RenderObject* renderer = result.renderer(); |
1359 if (!innerNode || !innerNode->renderer()) | 1358 if (!renderer) |
1360 return false; | 1359 return false; |
1361 | 1360 |
1362 VisiblePosition visiblePos(innerNode->renderer()->positionForPoint(result.lo
calPoint())); | 1361 VisiblePosition visiblePos(renderer->positionForPoint(result.localPoint())); |
1363 if (visiblePos.isNull()) | 1362 if (visiblePos.isNull()) |
1364 return false; | 1363 return false; |
1365 | 1364 |
1366 if (m_selection.visibleStart().isNull() || m_selection.visibleEnd().isNull()
) | 1365 if (m_selection.visibleStart().isNull() || m_selection.visibleEnd().isNull()
) |
1367 return false; | 1366 return false; |
1368 | 1367 |
1369 Position start(m_selection.visibleStart().deepEquivalent()); | 1368 Position start(m_selection.visibleStart().deepEquivalent()); |
1370 Position end(m_selection.visibleEnd().deepEquivalent()); | 1369 Position end(m_selection.visibleEnd().deepEquivalent()); |
1371 Position p(visiblePos.deepEquivalent()); | 1370 Position p(visiblePos.deepEquivalent()); |
1372 | 1371 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1631 Position candidate = startPos.downstream(); | 1630 Position candidate = startPos.downstream(); |
1632 if (candidate.isCandidate()) | 1631 if (candidate.isCandidate()) |
1633 startPos = candidate; | 1632 startPos = candidate; |
1634 Position endPos = selection.end(); | 1633 Position endPos = selection.end(); |
1635 candidate = endPos.upstream(); | 1634 candidate = endPos.upstream(); |
1636 if (candidate.isCandidate()) | 1635 if (candidate.isCandidate()) |
1637 endPos = candidate; | 1636 endPos = candidate; |
1638 | 1637 |
1639 // We can get into a state where the selection endpoints map to the same Vis
iblePosition when a selection is deleted | 1638 // We can get into a state where the selection endpoints map to the same Vis
iblePosition when a selection is deleted |
1640 // because we don't yet notify the FrameSelection of text removal. | 1639 // because we don't yet notify the FrameSelection of text removal. |
1641 if (startPos.isNotNull() && endPos.isNotNull() && selection.visibleStart() !
= selection.visibleEnd()) { | 1640 if (startPos.isNotNull() && endPos.isNotNull() && selection.visibleStart() !
= selection.visibleEnd()) |
1642 RenderObject* startRenderer = startPos.deprecatedNode()->renderer(); | 1641 view->setSelection(startPos.renderer(), startPos.offsetInRenderer(), end
Pos.renderer(), endPos.offsetInRenderer()); |
1643 RenderObject* endRenderer = endPos.deprecatedNode()->renderer(); | |
1644 view->setSelection(startRenderer, startPos.deprecatedEditingOffset(), en
dRenderer, endPos.deprecatedEditingOffset()); | |
1645 } | |
1646 } | 1642 } |
1647 | 1643 |
1648 void FrameSelection::setCaretVisibility(CaretVisibility visibility) | 1644 void FrameSelection::setCaretVisibility(CaretVisibility visibility) |
1649 { | 1645 { |
1650 if (caretVisibility() == visibility) | 1646 if (caretVisibility() == visibility) |
1651 return; | 1647 return; |
1652 | 1648 |
1653 m_frame->document()->updateLayoutIgnorePendingStylesheets(); | 1649 m_frame->document()->updateLayoutIgnorePendingStylesheets(); |
1654 if (m_caretPaint) { | 1650 if (m_caretPaint) { |
1655 m_caretPaint = false; | 1651 m_caretPaint = false; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1854 case VisibleSelection::CaretSelection: | 1850 case VisibleSelection::CaretSelection: |
1855 rect = absoluteCaretBounds(); | 1851 rect = absoluteCaretBounds(); |
1856 break; | 1852 break; |
1857 case VisibleSelection::RangeSelection: | 1853 case VisibleSelection::RangeSelection: |
1858 rect = revealExtentOption == RevealExtent ? VisiblePosition(extent()).ab
soluteCaretBounds() : enclosingIntRect(bounds(false)); | 1854 rect = revealExtentOption == RevealExtent ? VisiblePosition(extent()).ab
soluteCaretBounds() : enclosingIntRect(bounds(false)); |
1859 break; | 1855 break; |
1860 } | 1856 } |
1861 | 1857 |
1862 Position start = this->start(); | 1858 Position start = this->start(); |
1863 ASSERT(start.deprecatedNode()); | 1859 ASSERT(start.deprecatedNode()); |
1864 if (start.deprecatedNode() && start.deprecatedNode()->renderer()) { | 1860 if (start.renderer()) { |
1865 // FIXME: This code only handles scrolling the startContainer's layer, b
ut | 1861 // FIXME: This code only handles scrolling the startContainer's layer, b
ut |
1866 // the selection rect could intersect more than just that. | 1862 // the selection rect could intersect more than just that. |
1867 // See <rdar://problem/4799899>. | 1863 // See <rdar://problem/4799899>. |
1868 if (start.deprecatedNode()->renderer()->scrollRectToVisible(rect, alignm
ent, alignment)) | 1864 if (start.renderer()->scrollRectToVisible(rect, alignment, alignment)) |
1869 updateAppearance(); | 1865 updateAppearance(); |
1870 } | 1866 } |
1871 } | 1867 } |
1872 | 1868 |
1873 void FrameSelection::setSelectionFromNone() | 1869 void FrameSelection::setSelectionFromNone() |
1874 { | 1870 { |
1875 // Put a caret inside the body if the entire frame is editable (either the | 1871 // Put a caret inside the body if the entire frame is editable (either the |
1876 // entire WebView is editable or designMode is on for this document). | 1872 // entire WebView is editable or designMode is on for this document). |
1877 | 1873 |
1878 Document* document = m_frame->document(); | 1874 Document* document = m_frame->document(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1939 sel.showTreeForThis(); | 1935 sel.showTreeForThis(); |
1940 } | 1936 } |
1941 | 1937 |
1942 void showTree(const WebCore::FrameSelection* sel) | 1938 void showTree(const WebCore::FrameSelection* sel) |
1943 { | 1939 { |
1944 if (sel) | 1940 if (sel) |
1945 sel->showTreeForThis(); | 1941 sel->showTreeForThis(); |
1946 } | 1942 } |
1947 | 1943 |
1948 #endif | 1944 #endif |
OLD | NEW |