Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: Source/core/editing/FrameSelection.cpp

Issue 20681004: Make first-letter style to work with editing Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 2013-08-01T17:57:42 Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 169
170 void FrameSelection::moveTo(const Position &base, const Position &extent, EAffin ity affinity, EUserTriggered userTriggered) 170 void FrameSelection::moveTo(const Position &base, const Position &extent, EAffin ity affinity, EUserTriggered userTriggered)
171 { 171 {
172 const bool selectionHasDirection = true; 172 const bool selectionHasDirection = true;
173 SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered ; 173 SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered ;
174 setSelection(VisibleSelection(base, extent, affinity, selectionHasDirection) , options); 174 setSelection(VisibleSelection(base, extent, affinity, selectionHasDirection) , options);
175 } 175 }
176 176
177 void DragCaretController::setCaretPosition(const VisiblePosition& position) 177 void DragCaretController::setCaretPosition(const VisiblePosition& position)
178 { 178 {
179 if (Node* node = m_position.deepEquivalent().deprecatedNode()) 179 if (m_position.isNotNull())
180 invalidateCaretRect(node); 180 invalidateCaretRect(m_position.deepEquivalent());
181 m_position = position; 181 m_position = position;
182 setCaretRectNeedsUpdate(); 182 setCaretRectNeedsUpdate();
183 Document* document = 0; 183 if (m_position.isNotNull())
184 if (Node* node = m_position.deepEquivalent().deprecatedNode()) { 184 invalidateCaretRect(m_position.deepEquivalent());
185 invalidateCaretRect(node);
186 document = node->document();
187 }
188 if (m_position.isNull() || m_position.isOrphan()) 185 if (m_position.isNull() || m_position.isOrphan())
189 clearCaretRect(); 186 clearCaretRect();
190 else 187 else
191 updateCaretRect(document, m_position); 188 updateCaretRect(m_position.deepEquivalent().document(), m_position);
192 } 189 }
193 190
194 static void adjustEndpointsAtBidiBoundary(VisiblePosition& visibleBase, VisibleP osition& visibleExtent) 191 static void adjustEndpointsAtBidiBoundary(VisiblePosition& visibleBase, VisibleP osition& visibleExtent)
195 { 192 {
196 RenderedPosition base(visibleBase); 193 RenderedPosition base(visibleBase);
197 RenderedPosition extent(visibleExtent); 194 RenderedPosition extent(visibleExtent);
198 195
199 if (base.isNull() || extent.isNull() || base.isEquivalent(extent)) 196 if (base.isNull() || extent.isNull() || base.isEquivalent(extent))
200 return; 197 return;
201 198
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 { 1194 {
1198 m_granularity = CharacterGranularity; 1195 m_granularity = CharacterGranularity;
1199 1196
1200 m_caretBlinkTimer.stop(); 1197 m_caretBlinkTimer.stop();
1201 1198
1202 RenderView* view = m_frame->contentRenderer(); 1199 RenderView* view = m_frame->contentRenderer();
1203 if (view) 1200 if (view)
1204 view->clearSelection(); 1201 view->clearSelection();
1205 1202
1206 setSelection(VisibleSelection(), CloseTyping | ClearTypingStyle | DoNotUpdat eAppearance); 1203 setSelection(VisibleSelection(), CloseTyping | ClearTypingStyle | DoNotUpdat eAppearance);
1207 m_previousCaretNode.clear(); 1204 m_previousCaretPosition.clear();
1208 } 1205 }
1209 1206
1210 void FrameSelection::setStart(const VisiblePosition &pos, EUserTriggered trigger ) 1207 void FrameSelection::setStart(const VisiblePosition &pos, EUserTriggered trigger )
1211 { 1208 {
1212 if (m_selection.isBaseFirst()) 1209 if (m_selection.isBaseFirst())
1213 setBase(pos, trigger); 1210 setBase(pos, trigger);
1214 else 1211 else
1215 setExtent(pos, trigger); 1212 setExtent(pos, trigger);
1216 } 1213 }
1217 1214
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 void CaretBase::clearCaretRect() 1247 void CaretBase::clearCaretRect()
1251 { 1248 {
1252 m_caretLocalRect = LayoutRect(); 1249 m_caretLocalRect = LayoutRect();
1253 } 1250 }
1254 1251
1255 static inline bool caretRendersInsideNode(Node* node) 1252 static inline bool caretRendersInsideNode(Node* node)
1256 { 1253 {
1257 return node && !isTableElement(node) && !editingIgnoresContent(node); 1254 return node && !isTableElement(node) && !editingIgnoresContent(node);
1258 } 1255 }
1259 1256
1260 static RenderObject* caretRenderer(Node* node) 1257 static RenderObject* caretRenderer(RenderObject* renderer)
1261 { 1258 {
1262 if (!node)
1263 return 0;
1264
1265 RenderObject* renderer = node->renderer();
1266 if (!renderer) 1259 if (!renderer)
1267 return 0; 1260 return 0;
1268 1261
1269 // if caretNode is a block and caret is inside it then caret should be paint ed by that block 1262 // if caretNode is a block and caret is inside it then caret should be paint ed by that block
1270 bool paintedByBlock = renderer->isBlockFlow() && caretRendersInsideNode(node ); 1263 bool paintedByBlock = renderer->isBlockFlow() && caretRendersInsideNode(rend erer->node());
1271 return paintedByBlock ? renderer : renderer->containingBlock(); 1264 return paintedByBlock ? renderer : renderer->containingBlock();
1272 } 1265 }
1273 1266
1267 static RenderObject* caretRenderer(const Position& position)
1268 {
1269 return caretRenderer(position.renderer());
1270 }
1271
1274 bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caret Position) 1272 bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caret Position)
1275 { 1273 {
1276 document->updateStyleIfNeeded(); 1274 document->updateStyleIfNeeded();
1277 m_caretLocalRect = LayoutRect(); 1275 m_caretLocalRect = LayoutRect();
1278 1276
1279 m_caretRectNeedsUpdate = false; 1277 m_caretRectNeedsUpdate = false;
1280 1278
1281 if (caretPosition.isNull()) 1279 if (caretPosition.isNull())
1282 return false; 1280 return false;
1283 1281
1284 ASSERT(caretPosition.deepEquivalent().deprecatedNode()->renderer()); 1282 ASSERT(caretPosition.deepEquivalent().renderer());
1285 1283
1286 // First compute a rect local to the renderer at the selection start. 1284 // First compute a rect local to the renderer at the selection start.
1287 RenderObject* renderer; 1285 RenderObject* renderer;
1288 LayoutRect localRect = caretPosition.localCaretRect(renderer); 1286 LayoutRect localRect = caretPosition.localCaretRect(renderer);
1289 1287
1290 // Get the renderer that will be responsible for painting the caret 1288 // Get the renderer that will be responsible for painting the caret
1291 // (which is either the renderer we just found, or one of its containers). 1289 // (which is either the renderer we just found, or one of its containers).
1292 RenderObject* caretPainter = caretRenderer(caretPosition.deepEquivalent().de precatedNode()); 1290 RenderObject* caretPainter = caretRenderer(caretPosition.deepEquivalent());
1293 1291
1294 // Compute an offset between the renderer and the caretPainter. 1292 // Compute an offset between the renderer and the caretPainter.
1295 bool unrooted = false; 1293 bool unrooted = false;
1296 while (renderer != caretPainter) { 1294 while (renderer != caretPainter) {
1297 RenderObject* containerObject = renderer->container(); 1295 RenderObject* containerObject = renderer->container();
1298 if (!containerObject) { 1296 if (!containerObject) {
1299 unrooted = true; 1297 unrooted = true;
1300 break; 1298 break;
1301 } 1299 }
1302 localRect.move(renderer->offsetFromContainer(containerObject, localRect. location())); 1300 localRect.move(renderer->offsetFromContainer(containerObject, localRect. location()));
1303 renderer = containerObject; 1301 renderer = containerObject;
1304 } 1302 }
1305 1303
1306 if (!unrooted) 1304 if (!unrooted)
1307 m_caretLocalRect = localRect; 1305 m_caretLocalRect = localRect;
1308 1306
1309 return true; 1307 return true;
1310 } 1308 }
1311 1309
1312 RenderObject* FrameSelection::caretRenderer() const 1310 RenderObject* FrameSelection::caretRenderer() const
1313 { 1311 {
1314 return WebCore::caretRenderer(m_selection.start().deprecatedNode()); 1312 return WebCore::caretRenderer(m_selection.start());
1315 } 1313 }
1316 1314
1317 RenderObject* DragCaretController::caretRenderer() const 1315 RenderObject* DragCaretController::caretRenderer() const
1318 { 1316 {
1319 return WebCore::caretRenderer(m_position.deepEquivalent().deprecatedNode()); 1317 return WebCore::caretRenderer(m_position.deepEquivalent());
1320 } 1318 }
1321 1319
1322 static bool isNonOrphanedCaret(const VisibleSelection& selection) 1320 static bool isNonOrphanedCaret(const VisibleSelection& selection)
1323 { 1321 {
1324 return selection.isCaret() && !selection.start().isOrphan() && !selection.en d().isOrphan(); 1322 return selection.isCaret() && !selection.start().isOrphan() && !selection.en d().isOrphan();
1325 } 1323 }
1326 1324
1327 LayoutRect FrameSelection::localCaretRect() 1325 LayoutRect FrameSelection::localCaretRect()
1328 { 1326 {
1329 if (shouldUpdateCaretRect()) { 1327 if (shouldUpdateCaretRect()) {
1330 if (!isNonOrphanedCaret(m_selection)) 1328 if (!isNonOrphanedCaret(m_selection))
1331 clearCaretRect(); 1329 clearCaretRect();
1332 else if (updateCaretRect(m_frame->document(), VisiblePosition(m_selectio n.start(), m_selection.affinity()))) 1330 else if (updateCaretRect(m_frame->document(), VisiblePosition(m_selectio n.start(), m_selection.affinity())))
1333 m_absCaretBoundsDirty = true; 1331 m_absCaretBoundsDirty = true;
1334 } 1332 }
1335 1333
1336 return localCaretRectWithoutUpdate(); 1334 return localCaretRectWithoutUpdate();
1337 } 1335 }
1338 1336
1339 IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect ) const 1337 IntRect CaretBase::absoluteBoundsForLocalRect(const Position& position, const La youtRect& rect) const
1340 { 1338 {
1341 RenderObject* caretPainter = caretRenderer(node); 1339 RenderObject* caretPainter = caretRenderer(position);
1342 if (!caretPainter) 1340 if (!caretPainter)
1343 return IntRect(); 1341 return IntRect();
1344 1342
1345 LayoutRect localRect(rect); 1343 LayoutRect localRect(rect);
1346 if (caretPainter->isBox()) 1344 if (caretPainter->isBox())
1347 toRenderBox(caretPainter)->flipForWritingMode(localRect); 1345 toRenderBox(caretPainter)->flipForWritingMode(localRect);
1348 return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun dingBox(); 1346 return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun dingBox();
1349 } 1347 }
1350 1348
1351 IntRect FrameSelection::absoluteCaretBounds() 1349 IntRect FrameSelection::absoluteCaretBounds()
1352 { 1350 {
1353 recomputeCaretRect(); 1351 recomputeCaretRect();
1354 return m_absCaretBounds; 1352 return m_absCaretBounds;
1355 } 1353 }
1356 1354
1357 static void repaintCaretForLocalRect(Node* node, const LayoutRect& rect) 1355 static void repaintCaretForLocalRect(const Position& position, const LayoutRect& rect)
1358 { 1356 {
1359 RenderObject* caretPainter = caretRenderer(node); 1357 RenderObject* caretPainter = caretRenderer(position);
1360 if (!caretPainter) 1358 if (!caretPainter)
1361 return; 1359 return;
1362 1360
1363 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems. 1361 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems.
1364 // https://bugs.webkit.org/show_bug.cgi?id=108283 1362 // https://bugs.webkit.org/show_bug.cgi?id=108283
1365 LayoutRect inflatedRect = rect; 1363 LayoutRect inflatedRect = rect;
1366 inflatedRect.inflate(1); 1364 inflatedRect.inflate(1);
1367 1365
1368 caretPainter->repaintRectangle(inflatedRect); 1366 caretPainter->repaintRectangle(inflatedRect);
1369 } 1367 }
1370 1368
1371 bool FrameSelection::recomputeCaretRect() 1369 bool FrameSelection::recomputeCaretRect()
1372 { 1370 {
1373 if (!shouldUpdateCaretRect()) 1371 if (!shouldUpdateCaretRect())
1374 return false; 1372 return false;
1375 1373
1376 if (!m_frame) 1374 if (!m_frame)
1377 return false; 1375 return false;
1378 1376
1379 FrameView* v = m_frame->document()->view(); 1377 FrameView* v = m_frame->document()->view();
1380 if (!v) 1378 if (!v)
1381 return false; 1379 return false;
1382 1380
1383 LayoutRect oldRect = localCaretRectWithoutUpdate(); 1381 LayoutRect oldRect = localCaretRectWithoutUpdate();
1384 LayoutRect newRect = localCaretRect(); 1382 LayoutRect newRect = localCaretRect();
1385 if (oldRect == newRect && !m_absCaretBoundsDirty) 1383 if (oldRect == newRect && !m_absCaretBoundsDirty)
1386 return false; 1384 return false;
1387 1385
1388 IntRect oldAbsCaretBounds = m_absCaretBounds; 1386 IntRect oldAbsCaretBounds = m_absCaretBounds;
1389 m_absCaretBounds = absoluteBoundsForLocalRect(m_selection.start().deprecated Node(), localCaretRectWithoutUpdate()); 1387 m_absCaretBounds = absoluteBoundsForLocalRect(m_selection.start(), localCare tRectWithoutUpdate());
1390 m_absCaretBoundsDirty = false; 1388 m_absCaretBoundsDirty = false;
1391 1389
1392 if (oldAbsCaretBounds == m_absCaretBounds) 1390 if (oldAbsCaretBounds == m_absCaretBounds)
1393 return false; 1391 return false;
1394 1392
1395 if (RenderView* view = m_frame->document()->renderView()) { 1393 if (RenderView* view = m_frame->document()->renderView()) {
1396 Node* node = m_selection.start().deprecatedNode(); 1394 if (m_previousCaretPosition.isNotNull())
1397 if (m_previousCaretNode) 1395 repaintCaretForLocalRect(m_previousCaretPosition, oldRect);
1398 repaintCaretForLocalRect(m_previousCaretNode.get(), oldRect); 1396 m_previousCaretPosition = m_selection.start();
1399 m_previousCaretNode = node;
1400 if (shouldRepaintCaret(view, isContentEditable())) 1397 if (shouldRepaintCaret(view, isContentEditable()))
1401 repaintCaretForLocalRect(node, newRect); 1398 repaintCaretForLocalRect(m_previousCaretPosition, newRect);
1402 } 1399 }
1403 1400
1404 return true; 1401 return true;
1405 } 1402 }
1406 1403
1407 bool CaretBase::shouldRepaintCaret(const RenderView* view, bool isContentEditabl e) const 1404 bool CaretBase::shouldRepaintCaret(const RenderView* view, bool isContentEditabl e) const
1408 { 1405 {
1409 ASSERT(view); 1406 ASSERT(view);
1410 Frame* frame = view->frameView() ? view->frameView()->frame() : 0; // The fr ame where the selection started. 1407 Frame* frame = view->frameView() ? view->frameView()->frame() : 0; // The fr ame where the selection started.
1411 bool caretBrowsing = frame && frame->settings() && frame->settings()->caretB rowsingEnabled(); 1408 bool caretBrowsing = frame && frame->settings() && frame->settings()->caretB rowsingEnabled();
1412 return (caretBrowsing || isContentEditable); 1409 return (caretBrowsing || isContentEditable);
1413 } 1410 }
1414 1411
1415 void FrameSelection::invalidateCaretRect() 1412 void FrameSelection::invalidateCaretRect()
1416 { 1413 {
1417 if (!isCaret()) 1414 if (!isCaret())
1418 return; 1415 return;
1419 1416
1420 CaretBase::invalidateCaretRect(m_selection.start().deprecatedNode(), recompu teCaretRect()); 1417 CaretBase::invalidateCaretRect(m_selection.start(), recomputeCaretRect());
1421 } 1418 }
1422 1419
1423 void CaretBase::invalidateCaretRect(Node* node, bool caretRectChanged) 1420 void CaretBase::invalidateCaretRect(const Position& position, bool caretRectChan ged)
1424 { 1421 {
1425 // EDIT FIXME: This is an unfortunate hack. 1422 // EDIT FIXME: This is an unfortunate hack.
1426 // Basically, we can't trust this layout position since we 1423 // Basically, we can't trust this layout position since we
1427 // can't guarantee that the check to see if we are in unrendered 1424 // can't guarantee that the check to see if we are in unrendered
1428 // content will work at this point. We may have to wait for 1425 // content will work at this point. We may have to wait for
1429 // a layout and re-render of the document to happen. So, resetting this 1426 // a layout and re-render of the document to happen. So, resetting this
1430 // flag will cause another caret layout to happen the first time 1427 // flag will cause another caret layout to happen the first time
1431 // that we try to paint the caret after this call. That one will work since 1428 // that we try to paint the caret after this call. That one will work since
1432 // it happens after the document has accounted for any editing 1429 // it happens after the document has accounted for any editing
1433 // changes which may have been done. 1430 // changes which may have been done.
1434 // And, we need to leave this layout here so the caret moves right 1431 // And, we need to leave this layout here so the caret moves right
1435 // away after clicking. 1432 // away after clicking.
1436 m_caretRectNeedsUpdate = true; 1433 m_caretRectNeedsUpdate = true;
1437 1434
1438 if (caretRectChanged) 1435 if (caretRectChanged)
1439 return; 1436 return;
1440 1437
1441 if (RenderView* view = node->document()->renderView()) { 1438 if (RenderView* view = position.document()->renderView()) {
1442 if (shouldRepaintCaret(view, node->isContentEditable(Node::UserSelectAll IsAlwaysNonEditable))) 1439 if (shouldRepaintCaret(view, position.anchorNode()->isContentEditable(No de::UserSelectAllIsAlwaysNonEditable)))
1443 repaintCaretForLocalRect(node, localCaretRectWithoutUpdate()); 1440 repaintCaretForLocalRect(position, localCaretRectWithoutUpdate());
1444 } 1441 }
1445 } 1442 }
1446 1443
1447 void FrameSelection::paintCaret(GraphicsContext* context, const LayoutPoint& pai ntOffset, const LayoutRect& clipRect) 1444 void FrameSelection::paintCaret(GraphicsContext* context, const LayoutPoint& pai ntOffset, const LayoutRect& clipRect)
1448 { 1445 {
1449 if (m_selection.isCaret() && m_caretPaint) 1446 if (m_selection.isCaret() && m_caretPaint)
1450 CaretBase::paintCaret(m_selection.start().deprecatedNode(), context, pai ntOffset, clipRect); 1447 CaretBase::paintCaret(m_selection.start(), context, paintOffset, clipRec t);
1451 } 1448 }
1452 1449
1453 void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi nt& paintOffset, const LayoutRect& clipRect) const 1450 void CaretBase::paintCaret(const Position& position, GraphicsContext* context, c onst LayoutPoint& paintOffset, const LayoutRect& clipRect) const
1454 { 1451 {
1455 if (m_caretVisibility == Hidden) 1452 if (m_caretVisibility == Hidden)
1456 return; 1453 return;
1457 1454
1458 LayoutRect drawingRect = localCaretRectWithoutUpdate(); 1455 LayoutRect drawingRect = localCaretRectWithoutUpdate();
1459 RenderObject* renderer = caretRenderer(node); 1456 RenderObject* renderer = caretRenderer(position);
1460 if (renderer && renderer->isBox()) 1457 if (renderer && renderer->isBox())
1461 toRenderBox(renderer)->flipForWritingMode(drawingRect); 1458 toRenderBox(renderer)->flipForWritingMode(drawingRect);
1462 drawingRect.moveBy(roundedIntPoint(paintOffset)); 1459 drawingRect.moveBy(roundedIntPoint(paintOffset));
1463 LayoutRect caret = intersection(drawingRect, clipRect); 1460 LayoutRect caret = intersection(drawingRect, clipRect);
1464 if (caret.isEmpty()) 1461 if (caret.isEmpty())
1465 return; 1462 return;
1466 1463
1467 Color caretColor = Color::black; 1464 Color caretColor = Color::black;
1468 1465
1469 Element* element; 1466 Element* element = position.element();
1470 if (node->isElementNode())
1471 element = toElement(node);
1472 else
1473 element = node->parentElement();
1474
1475 if (element && element->renderer()) 1467 if (element && element->renderer())
1476 caretColor = element->renderer()->resolveColor(CSSPropertyColor); 1468 caretColor = element->renderer()->resolveColor(CSSPropertyColor);
1477 1469
1478 context->fillRect(caret, caretColor); 1470 context->fillRect(caret, caretColor);
1479 } 1471 }
1480 1472
1481 void FrameSelection::debugRenderer(RenderObject *r, bool selected) const 1473 void FrameSelection::debugRenderer(RenderObject *r, bool selected) const
1482 { 1474 {
1483 if (r->node()->isElementNode()) { 1475 if (r->node()->isElementNode()) {
1484 Element* element = toElement(r->node()); 1476 Element* element = toElement(r->node());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 1541
1550 // Treat a collapsed selection like no selection. 1542 // Treat a collapsed selection like no selection.
1551 if (!isRange()) 1543 if (!isRange())
1552 return false; 1544 return false;
1553 if (!document->renderer()) 1545 if (!document->renderer())
1554 return false; 1546 return false;
1555 1547
1556 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | H itTestRequest::DisallowShadowContent); 1548 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | H itTestRequest::DisallowShadowContent);
1557 HitTestResult result(point); 1549 HitTestResult result(point);
1558 document->renderView()->hitTest(request, result); 1550 document->renderView()->hitTest(request, result);
1559 Node* innerNode = result.innerNode(); 1551 RenderObject* renderer = result.renderer();
1560 if (!innerNode || !innerNode->renderer()) 1552 if (!renderer)
1561 return false; 1553 return false;
1562 1554
1563 VisiblePosition visiblePos(innerNode->renderer()->positionForPoint(result.lo calPoint())); 1555 VisiblePosition visiblePos(renderer->positionForPoint(result.localPoint()));
1564 if (visiblePos.isNull()) 1556 if (visiblePos.isNull())
1565 return false; 1557 return false;
1566 1558
1567 if (m_selection.visibleStart().isNull() || m_selection.visibleEnd().isNull() ) 1559 if (m_selection.visibleStart().isNull() || m_selection.visibleEnd().isNull() )
1568 return false; 1560 return false;
1569 1561
1570 Position start(m_selection.visibleStart().deepEquivalent()); 1562 Position start(m_selection.visibleStart().deepEquivalent());
1571 Position end(m_selection.visibleEnd().deepEquivalent()); 1563 Position end(m_selection.visibleEnd().deepEquivalent());
1572 Position p(visiblePos.deepEquivalent()); 1564 Position p(visiblePos.deepEquivalent());
1573 1565
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 Position candidate = startPos.downstream(); 1822 Position candidate = startPos.downstream();
1831 if (candidate.isCandidate()) 1823 if (candidate.isCandidate())
1832 startPos = candidate; 1824 startPos = candidate;
1833 Position endPos = selection.end(); 1825 Position endPos = selection.end();
1834 candidate = endPos.upstream(); 1826 candidate = endPos.upstream();
1835 if (candidate.isCandidate()) 1827 if (candidate.isCandidate())
1836 endPos = candidate; 1828 endPos = candidate;
1837 1829
1838 // We can get into a state where the selection endpoints map to the same Vis iblePosition when a selection is deleted 1830 // We can get into a state where the selection endpoints map to the same Vis iblePosition when a selection is deleted
1839 // because we don't yet notify the FrameSelection of text removal. 1831 // because we don't yet notify the FrameSelection of text removal.
1840 if (startPos.isNotNull() && endPos.isNotNull() && selection.visibleStart() ! = selection.visibleEnd()) { 1832 if (startPos.isNotNull() && endPos.isNotNull() && selection.visibleStart() ! = selection.visibleEnd())
1841 RenderObject* startRenderer = startPos.deprecatedNode()->renderer(); 1833 view->setSelection(startPos.renderer(), startPos.offsetInRenderer(), end Pos.renderer(), endPos.offsetInRenderer());
1842 RenderObject* endRenderer = endPos.deprecatedNode()->renderer();
1843 view->setSelection(startRenderer, startPos.deprecatedEditingOffset(), en dRenderer, endPos.deprecatedEditingOffset());
1844 }
1845 } 1834 }
1846 1835
1847 void FrameSelection::setCaretVisibility(CaretVisibility visibility) 1836 void FrameSelection::setCaretVisibility(CaretVisibility visibility)
1848 { 1837 {
1849 if (caretVisibility() == visibility) 1838 if (caretVisibility() == visibility)
1850 return; 1839 return;
1851 1840
1852 m_frame->document()->updateLayoutIgnorePendingStylesheets(); 1841 m_frame->document()->updateLayoutIgnorePendingStylesheets();
1853 if (m_caretPaint) { 1842 if (m_caretPaint) {
1854 m_caretPaint = false; 1843 m_caretPaint = false;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1938 m_frame->document()->setFocusedElement(0); 1927 m_frame->document()->setFocusedElement(0);
1939 } 1928 }
1940 1929
1941 if (caretBrowsing) 1930 if (caretBrowsing)
1942 m_frame->page()->focusController()->setFocusedElement(0, m_frame); 1931 m_frame->page()->focusController()->setFocusedElement(0, m_frame);
1943 } 1932 }
1944 1933
1945 void DragCaretController::paintDragCaret(Frame* frame, GraphicsContext* p, const LayoutPoint& paintOffset, const LayoutRect& clipRect) const 1934 void DragCaretController::paintDragCaret(Frame* frame, GraphicsContext* p, const LayoutPoint& paintOffset, const LayoutRect& clipRect) const
1946 { 1935 {
1947 if (m_position.deepEquivalent().deprecatedNode()->document()->frame() == fra me) 1936 if (m_position.deepEquivalent().deprecatedNode()->document()->frame() == fra me)
1948 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset, clipRect); 1937 paintCaret(m_position.deepEquivalent(), p, paintOffset, clipRect);
1949 } 1938 }
1950 1939
1951 PassRefPtr<MutableStylePropertySet> FrameSelection::copyTypingStyle() const 1940 PassRefPtr<MutableStylePropertySet> FrameSelection::copyTypingStyle() const
1952 { 1941 {
1953 if (!m_typingStyle || !m_typingStyle->style()) 1942 if (!m_typingStyle || !m_typingStyle->style())
1954 return 0; 1943 return 0;
1955 return m_typingStyle->style()->mutableCopy(); 1944 return m_typingStyle->style()->mutableCopy();
1956 } 1945 }
1957 1946
1958 bool FrameSelection::shouldDeleteSelection(const VisibleSelection& selection) co nst 1947 bool FrameSelection::shouldDeleteSelection(const VisibleSelection& selection) co nst
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2041 case VisibleSelection::CaretSelection: 2030 case VisibleSelection::CaretSelection:
2042 rect = absoluteCaretBounds(); 2031 rect = absoluteCaretBounds();
2043 break; 2032 break;
2044 case VisibleSelection::RangeSelection: 2033 case VisibleSelection::RangeSelection:
2045 rect = revealExtentOption == RevealExtent ? VisiblePosition(extent()).ab soluteCaretBounds() : enclosingIntRect(bounds(false)); 2034 rect = revealExtentOption == RevealExtent ? VisiblePosition(extent()).ab soluteCaretBounds() : enclosingIntRect(bounds(false));
2046 break; 2035 break;
2047 } 2036 }
2048 2037
2049 Position start = this->start(); 2038 Position start = this->start();
2050 ASSERT(start.deprecatedNode()); 2039 ASSERT(start.deprecatedNode());
2051 if (start.deprecatedNode() && start.deprecatedNode()->renderer()) { 2040 if (start.renderer()) {
2052 // FIXME: This code only handles scrolling the startContainer's layer, b ut 2041 // FIXME: This code only handles scrolling the startContainer's layer, b ut
2053 // the selection rect could intersect more than just that. 2042 // the selection rect could intersect more than just that.
2054 // See <rdar://problem/4799899>. 2043 // See <rdar://problem/4799899>.
2055 if (start.deprecatedNode()->renderer()->scrollRectToVisible(rect, alignm ent, alignment)) 2044 if (start.renderer()->scrollRectToVisible(rect, alignment, alignment))
2056 updateAppearance(); 2045 updateAppearance();
2057 } 2046 }
2058 } 2047 }
2059 2048
2060 void FrameSelection::setSelectionFromNone() 2049 void FrameSelection::setSelectionFromNone()
2061 { 2050 {
2062 // Put a caret inside the body if the entire frame is editable (either the 2051 // Put a caret inside the body if the entire frame is editable (either the
2063 // entire WebView is editable or designMode is on for this document). 2052 // entire WebView is editable or designMode is on for this document).
2064 2053
2065 Document* document = m_frame->document(); 2054 Document* document = m_frame->document();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2126 sel.showTreeForThis(); 2115 sel.showTreeForThis();
2127 } 2116 }
2128 2117
2129 void showTree(const WebCore::FrameSelection* sel) 2118 void showTree(const WebCore::FrameSelection* sel)
2130 { 2119 {
2131 if (sel) 2120 if (sel)
2132 sel->showTreeForThis(); 2121 sel->showTreeForThis();
2133 } 2122 }
2134 2123
2135 #endif 2124 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698