OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // Should never reach this point. | 160 // Should never reach this point. |
161 ASSERT_NOT_REACHED(); | 161 ASSERT_NOT_REACHED(); |
162 return 0; | 162 return 0; |
163 } | 163 } |
164 | 164 |
165 int comparePositionsInDOMTree(Node* containerA, int offsetA, Node* containerB, i
nt offsetB, bool* disconnected) | 165 int comparePositionsInDOMTree(Node* containerA, int offsetA, Node* containerB, i
nt offsetB, bool* disconnected) |
166 { | 166 { |
167 return comparePositions<NodeTraversal>(containerA, offsetA, containerB, offs
etB, disconnected); | 167 return comparePositions<NodeTraversal>(containerA, offsetA, containerB, offs
etB, disconnected); |
168 } | 168 } |
169 | 169 |
170 int comparePositionsInComposedTree(Node* containerA, int offsetA, Node* containe
rB, int offsetB, bool* disconnected) | 170 int comparePositionsInFlatTree(Node* containerA, int offsetA, Node* containerB,
int offsetB, bool* disconnected) |
171 { | 171 { |
172 return comparePositions<ComposedTreeTraversal>(containerA, offsetA, containe
rB, offsetB, disconnected); | 172 return comparePositions<FlatTreeTraversal>(containerA, offsetA, containerB,
offsetB, disconnected); |
173 } | 173 } |
174 | 174 |
175 // Compare two positions, taking into account the possibility that one or both | 175 // Compare two positions, taking into account the possibility that one or both |
176 // could be inside a shadow tree. Only works for non-null values. | 176 // could be inside a shadow tree. Only works for non-null values. |
177 int comparePositions(const Position& a, const Position& b) | 177 int comparePositions(const Position& a, const Position& b) |
178 { | 178 { |
179 ASSERT(a.isNotNull()); | 179 ASSERT(a.isNotNull()); |
180 ASSERT(b.isNotNull()); | 180 ASSERT(b.isNotNull()); |
181 const TreeScope* commonScope = Position::commonAncestorTreeScope(a, b); | 181 const TreeScope* commonScope = Position::commonAncestorTreeScope(a, b); |
182 | 182 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 if (node->hasEditableStyle(editableType)) | 233 if (node->hasEditableStyle(editableType)) |
234 highestRoot = node; | 234 highestRoot = node; |
235 if (isHTMLBodyElement(*node)) | 235 if (isHTMLBodyElement(*node)) |
236 break; | 236 break; |
237 node = node->parentNode(); | 237 node = node->parentNode(); |
238 } | 238 } |
239 | 239 |
240 return highestRoot; | 240 return highestRoot; |
241 } | 241 } |
242 | 242 |
243 ContainerNode* highestEditableRoot(const PositionInComposedTree& position, Edita
bleType editableType) | 243 ContainerNode* highestEditableRoot(const PositionInFlatTree& position, EditableT
ype editableType) |
244 { | 244 { |
245 return highestEditableRoot(toPositionInDOMTree(position), editableType); | 245 return highestEditableRoot(toPositionInDOMTree(position), editableType); |
246 } | 246 } |
247 | 247 |
248 bool isEditablePosition(const Position& p, EditableType editableType, EUpdateSty
le updateStyle) | 248 bool isEditablePosition(const Position& p, EditableType editableType, EUpdateSty
le updateStyle) |
249 { | 249 { |
250 Node* node = p.parentAnchoredEquivalent().anchorNode(); | 250 Node* node = p.parentAnchoredEquivalent().anchorNode(); |
251 if (!node) | 251 if (!node) |
252 return false; | 252 return false; |
253 if (updateStyle == UpdateStyle) | 253 if (updateStyle == UpdateStyle) |
254 node->document().updateLayoutIgnorePendingStylesheets(); | 254 node->document().updateLayoutIgnorePendingStylesheets(); |
255 else | 255 else |
256 ASSERT(updateStyle == DoNotUpdateStyle); | 256 ASSERT(updateStyle == DoNotUpdateStyle); |
257 | 257 |
258 if (isDisplayInsideTable(node)) | 258 if (isDisplayInsideTable(node)) |
259 node = node->parentNode(); | 259 node = node->parentNode(); |
260 | 260 |
261 if (node->isDocumentNode()) | 261 if (node->isDocumentNode()) |
262 return false; | 262 return false; |
263 return node->hasEditableStyle(editableType); | 263 return node->hasEditableStyle(editableType); |
264 } | 264 } |
265 | 265 |
266 bool isEditablePosition(const PositionInComposedTree& p, EditableType editableTy
pe, EUpdateStyle updateStyle) | 266 bool isEditablePosition(const PositionInFlatTree& p, EditableType editableType,
EUpdateStyle updateStyle) |
267 { | 267 { |
268 return isEditablePosition(toPositionInDOMTree(p), editableType, updateStyle)
; | 268 return isEditablePosition(toPositionInDOMTree(p), editableType, updateStyle)
; |
269 } | 269 } |
270 | 270 |
271 bool isAtUnsplittableElement(const Position& pos) | 271 bool isAtUnsplittableElement(const Position& pos) |
272 { | 272 { |
273 Node* node = pos.anchorNode(); | 273 Node* node = pos.anchorNode(); |
274 return (node == rootEditableElementOf(pos) || node == enclosingNodeOfType(po
s, &isTableCell)); | 274 return (node == rootEditableElementOf(pos) || node == enclosingNodeOfType(po
s, &isTableCell)); |
275 } | 275 } |
276 | 276 |
(...skipping 15 matching lines...) Expand all Loading... |
292 Node* node = p.computeContainerNode(); | 292 Node* node = p.computeContainerNode(); |
293 if (!node) | 293 if (!node) |
294 return 0; | 294 return 0; |
295 | 295 |
296 if (isDisplayInsideTable(node)) | 296 if (isDisplayInsideTable(node)) |
297 node = node->parentNode(); | 297 node = node->parentNode(); |
298 | 298 |
299 return node->rootEditableElement(editableType); | 299 return node->rootEditableElement(editableType); |
300 } | 300 } |
301 | 301 |
302 Element* rootEditableElementOf(const PositionInComposedTree& p, EditableType edi
tableType) | 302 Element* rootEditableElementOf(const PositionInFlatTree& p, EditableType editabl
eType) |
303 { | 303 { |
304 return rootEditableElementOf(toPositionInDOMTree(p), editableType); | 304 return rootEditableElementOf(toPositionInDOMTree(p), editableType); |
305 } | 305 } |
306 | 306 |
307 // TODO(yosin) This does not handle [table, 0] correctly. | 307 // TODO(yosin) This does not handle [table, 0] correctly. |
308 Element* rootEditableElementOf(const VisiblePosition& visiblePosition) | 308 Element* rootEditableElementOf(const VisiblePosition& visiblePosition) |
309 { | 309 { |
310 Node* anchorNode = visiblePosition.deepEquivalent().anchorNode(); | 310 Node* anchorNode = visiblePosition.deepEquivalent().anchorNode(); |
311 return anchorNode ? anchorNode->rootEditableElement() : nullptr; | 311 return anchorNode ? anchorNode->rootEditableElement() : nullptr; |
312 } | 312 } |
(...skipping 28 matching lines...) Expand all Loading... |
341 } | 341 } |
342 | 342 |
343 return PositionTemplate<Strategy>(); | 343 return PositionTemplate<Strategy>(); |
344 } | 344 } |
345 | 345 |
346 Position nextCandidate(const Position& position) | 346 Position nextCandidate(const Position& position) |
347 { | 347 { |
348 return nextCandidateAlgorithm<EditingStrategy>(position); | 348 return nextCandidateAlgorithm<EditingStrategy>(position); |
349 } | 349 } |
350 | 350 |
351 PositionInComposedTree nextCandidate(const PositionInComposedTree& position) | 351 PositionInFlatTree nextCandidate(const PositionInFlatTree& position) |
352 { | 352 { |
353 return nextCandidateAlgorithm<EditingInComposedTreeStrategy>(position); | 353 return nextCandidateAlgorithm<EditingInFlatTreeStrategy>(position); |
354 } | 354 } |
355 | 355 |
356 // |nextVisuallyDistinctCandidate| is similar to |nextCandidate| except | 356 // |nextVisuallyDistinctCandidate| is similar to |nextCandidate| except |
357 // for returning position which |downstream()| not equal to initial position's | 357 // for returning position which |downstream()| not equal to initial position's |
358 // |downstream()|. | 358 // |downstream()|. |
359 template <typename Strategy> | 359 template <typename Strategy> |
360 static PositionTemplate<Strategy> nextVisuallyDistinctCandidateAlgorithm(const P
ositionTemplate<Strategy>& position) | 360 static PositionTemplate<Strategy> nextVisuallyDistinctCandidateAlgorithm(const P
ositionTemplate<Strategy>& position) |
361 { | 361 { |
362 TRACE_EVENT0("input", "EditingUtility::nextVisuallyDistinctCandidateAlgorith
m"); | 362 TRACE_EVENT0("input", "EditingUtility::nextVisuallyDistinctCandidateAlgorith
m"); |
363 if (position.isNull()) | 363 if (position.isNull()) |
(...skipping 12 matching lines...) Expand all Loading... |
376 } | 376 } |
377 | 377 |
378 return PositionTemplate<Strategy>(); | 378 return PositionTemplate<Strategy>(); |
379 } | 379 } |
380 | 380 |
381 Position nextVisuallyDistinctCandidate(const Position& position) | 381 Position nextVisuallyDistinctCandidate(const Position& position) |
382 { | 382 { |
383 return nextVisuallyDistinctCandidateAlgorithm<EditingStrategy>(position); | 383 return nextVisuallyDistinctCandidateAlgorithm<EditingStrategy>(position); |
384 } | 384 } |
385 | 385 |
386 PositionInComposedTree nextVisuallyDistinctCandidate(const PositionInComposedTre
e& position) | 386 PositionInFlatTree nextVisuallyDistinctCandidate(const PositionInFlatTree& posit
ion) |
387 { | 387 { |
388 return nextVisuallyDistinctCandidateAlgorithm<EditingInComposedTreeStrategy>
(position); | 388 return nextVisuallyDistinctCandidateAlgorithm<EditingInFlatTreeStrategy>(pos
ition); |
389 } | 389 } |
390 | 390 |
391 template <typename Strategy> | 391 template <typename Strategy> |
392 PositionTemplate<Strategy> previousCandidateAlgorithm(const PositionTemplate<Str
ategy>& position) | 392 PositionTemplate<Strategy> previousCandidateAlgorithm(const PositionTemplate<Str
ategy>& position) |
393 { | 393 { |
394 TRACE_EVENT0("input", "EditingUtility::previousCandidateAlgorithm"); | 394 TRACE_EVENT0("input", "EditingUtility::previousCandidateAlgorithm"); |
395 PositionIteratorAlgorithm<Strategy> p(position); | 395 PositionIteratorAlgorithm<Strategy> p(position); |
396 | 396 |
397 p.decrement(); | 397 p.decrement(); |
398 while (!p.atStart()) { | 398 while (!p.atStart()) { |
399 PositionTemplate<Strategy> candidate = p.computePosition(); | 399 PositionTemplate<Strategy> candidate = p.computePosition(); |
400 if (isVisuallyEquivalentCandidate(candidate)) | 400 if (isVisuallyEquivalentCandidate(candidate)) |
401 return candidate; | 401 return candidate; |
402 | 402 |
403 p.decrement(); | 403 p.decrement(); |
404 } | 404 } |
405 | 405 |
406 return PositionTemplate<Strategy>(); | 406 return PositionTemplate<Strategy>(); |
407 } | 407 } |
408 | 408 |
409 Position previousCandidate(const Position& position) | 409 Position previousCandidate(const Position& position) |
410 { | 410 { |
411 return previousCandidateAlgorithm<EditingStrategy>(position); | 411 return previousCandidateAlgorithm<EditingStrategy>(position); |
412 } | 412 } |
413 | 413 |
414 PositionInComposedTree previousCandidate(const PositionInComposedTree& position) | 414 PositionInFlatTree previousCandidate(const PositionInFlatTree& position) |
415 { | 415 { |
416 return previousCandidateAlgorithm<EditingInComposedTreeStrategy>(position); | 416 return previousCandidateAlgorithm<EditingInFlatTreeStrategy>(position); |
417 } | 417 } |
418 | 418 |
419 // |previousVisuallyDistinctCandidate| is similar to |previousCandidate| except | 419 // |previousVisuallyDistinctCandidate| is similar to |previousCandidate| except |
420 // for returning position which |downstream()| not equal to initial position's | 420 // for returning position which |downstream()| not equal to initial position's |
421 // |downstream()|. | 421 // |downstream()|. |
422 template <typename Strategy> | 422 template <typename Strategy> |
423 PositionTemplate<Strategy> previousVisuallyDistinctCandidateAlgorithm(const Posi
tionTemplate<Strategy>& position) | 423 PositionTemplate<Strategy> previousVisuallyDistinctCandidateAlgorithm(const Posi
tionTemplate<Strategy>& position) |
424 { | 424 { |
425 TRACE_EVENT0("input", "EditingUtility::previousVisuallyDistinctCandidateAlgo
rithm"); | 425 TRACE_EVENT0("input", "EditingUtility::previousVisuallyDistinctCandidateAlgo
rithm"); |
426 if (position.isNull()) | 426 if (position.isNull()) |
(...skipping 12 matching lines...) Expand all Loading... |
439 } | 439 } |
440 | 440 |
441 return PositionTemplate<Strategy>(); | 441 return PositionTemplate<Strategy>(); |
442 } | 442 } |
443 | 443 |
444 Position previousVisuallyDistinctCandidate(const Position& position) | 444 Position previousVisuallyDistinctCandidate(const Position& position) |
445 { | 445 { |
446 return previousVisuallyDistinctCandidateAlgorithm<EditingStrategy>(position)
; | 446 return previousVisuallyDistinctCandidateAlgorithm<EditingStrategy>(position)
; |
447 } | 447 } |
448 | 448 |
449 PositionInComposedTree previousVisuallyDistinctCandidate(const PositionInCompose
dTree& position) | 449 PositionInFlatTree previousVisuallyDistinctCandidate(const PositionInFlatTree& p
osition) |
450 { | 450 { |
451 return previousVisuallyDistinctCandidateAlgorithm<EditingInComposedTreeStrat
egy>(position); | 451 return previousVisuallyDistinctCandidateAlgorithm<EditingInFlatTreeStrategy>
(position); |
452 } | 452 } |
453 | 453 |
454 VisiblePosition firstEditableVisiblePositionAfterPositionInRoot(const Position&
position, ContainerNode& highestRoot) | 454 VisiblePosition firstEditableVisiblePositionAfterPositionInRoot(const Position&
position, ContainerNode& highestRoot) |
455 { | 455 { |
456 return createVisiblePosition(firstEditablePositionAfterPositionInRoot(positi
on, highestRoot)); | 456 return createVisiblePosition(firstEditablePositionAfterPositionInRoot(positi
on, highestRoot)); |
457 } | 457 } |
458 | 458 |
459 VisiblePositionInComposedTree firstEditableVisiblePositionAfterPositionInRoot(co
nst PositionInComposedTree& position, ContainerNode& highestRoot) | 459 VisiblePositionInFlatTree firstEditableVisiblePositionAfterPositionInRoot(const
PositionInFlatTree& position, ContainerNode& highestRoot) |
460 { | 460 { |
461 return createVisiblePosition(firstEditablePositionAfterPositionInRoot(positi
on, highestRoot)); | 461 return createVisiblePosition(firstEditablePositionAfterPositionInRoot(positi
on, highestRoot)); |
462 } | 462 } |
463 | 463 |
464 template <typename Strategy> | 464 template <typename Strategy> |
465 PositionTemplate<Strategy> firstEditablePositionAfterPositionInRootAlgorithm(con
st PositionTemplate<Strategy>& position, Node& highestRoot) | 465 PositionTemplate<Strategy> firstEditablePositionAfterPositionInRootAlgorithm(con
st PositionTemplate<Strategy>& position, Node& highestRoot) |
466 { | 466 { |
467 // position falls before highestRoot. | 467 // position falls before highestRoot. |
468 if (position.compareTo(PositionTemplate<Strategy>::firstPositionInNode(&high
estRoot)) == -1 && highestRoot.hasEditableStyle()) | 468 if (position.compareTo(PositionTemplate<Strategy>::firstPositionInNode(&high
estRoot)) == -1 && highestRoot.hasEditableStyle()) |
469 return PositionTemplate<Strategy>::firstPositionInNode(&highestRoot); | 469 return PositionTemplate<Strategy>::firstPositionInNode(&highestRoot); |
(...skipping 15 matching lines...) Expand all Loading... |
485 return PositionTemplate<Strategy>(); | 485 return PositionTemplate<Strategy>(); |
486 | 486 |
487 return editablePosition; | 487 return editablePosition; |
488 } | 488 } |
489 | 489 |
490 Position firstEditablePositionAfterPositionInRoot(const Position& position, Node
& highestRoot) | 490 Position firstEditablePositionAfterPositionInRoot(const Position& position, Node
& highestRoot) |
491 { | 491 { |
492 return firstEditablePositionAfterPositionInRootAlgorithm<EditingStrategy>(po
sition, highestRoot); | 492 return firstEditablePositionAfterPositionInRootAlgorithm<EditingStrategy>(po
sition, highestRoot); |
493 } | 493 } |
494 | 494 |
495 PositionInComposedTree firstEditablePositionAfterPositionInRoot(const PositionIn
ComposedTree& position, Node& highestRoot) | 495 PositionInFlatTree firstEditablePositionAfterPositionInRoot(const PositionInFlat
Tree& position, Node& highestRoot) |
496 { | 496 { |
497 return firstEditablePositionAfterPositionInRootAlgorithm<EditingInComposedTr
eeStrategy>(position, highestRoot); | 497 return firstEditablePositionAfterPositionInRootAlgorithm<EditingInFlatTreeSt
rategy>(position, highestRoot); |
498 } | 498 } |
499 | 499 |
500 VisiblePosition lastEditableVisiblePositionBeforePositionInRoot(const Position&
position, ContainerNode& highestRoot) | 500 VisiblePosition lastEditableVisiblePositionBeforePositionInRoot(const Position&
position, ContainerNode& highestRoot) |
501 { | 501 { |
502 return createVisiblePosition(lastEditablePositionBeforePositionInRoot(positi
on, highestRoot)); | 502 return createVisiblePosition(lastEditablePositionBeforePositionInRoot(positi
on, highestRoot)); |
503 } | 503 } |
504 | 504 |
505 VisiblePositionInComposedTree lastEditableVisiblePositionBeforePositionInRoot(co
nst PositionInComposedTree& position, ContainerNode& highestRoot) | 505 VisiblePositionInFlatTree lastEditableVisiblePositionBeforePositionInRoot(const
PositionInFlatTree& position, ContainerNode& highestRoot) |
506 { | 506 { |
507 return createVisiblePosition(lastEditablePositionBeforePositionInRoot(positi
on, highestRoot)); | 507 return createVisiblePosition(lastEditablePositionBeforePositionInRoot(positi
on, highestRoot)); |
508 } | 508 } |
509 | 509 |
510 template <typename Strategy> | 510 template <typename Strategy> |
511 PositionTemplate<Strategy> lastEditablePositionBeforePositionInRootAlgorithm(con
st PositionTemplate<Strategy>& position, Node& highestRoot) | 511 PositionTemplate<Strategy> lastEditablePositionBeforePositionInRootAlgorithm(con
st PositionTemplate<Strategy>& position, Node& highestRoot) |
512 { | 512 { |
513 // When position falls after highestRoot, the result is easy to compute. | 513 // When position falls after highestRoot, the result is easy to compute. |
514 if (position.compareTo(PositionTemplate<Strategy>::lastPositionInNode(&highe
stRoot)) == 1) | 514 if (position.compareTo(PositionTemplate<Strategy>::lastPositionInNode(&highe
stRoot)) == 1) |
515 return PositionTemplate<Strategy>::lastPositionInNode(&highestRoot); | 515 return PositionTemplate<Strategy>::lastPositionInNode(&highestRoot); |
(...skipping 14 matching lines...) Expand all Loading... |
530 if (editablePosition.anchorNode() && editablePosition.anchorNode() != &highe
stRoot && !editablePosition.anchorNode()->isDescendantOf(&highestRoot)) | 530 if (editablePosition.anchorNode() && editablePosition.anchorNode() != &highe
stRoot && !editablePosition.anchorNode()->isDescendantOf(&highestRoot)) |
531 return PositionTemplate<Strategy>(); | 531 return PositionTemplate<Strategy>(); |
532 return editablePosition; | 532 return editablePosition; |
533 } | 533 } |
534 | 534 |
535 Position lastEditablePositionBeforePositionInRoot(const Position& position, Node
& highestRoot) | 535 Position lastEditablePositionBeforePositionInRoot(const Position& position, Node
& highestRoot) |
536 { | 536 { |
537 return lastEditablePositionBeforePositionInRootAlgorithm<EditingStrategy>(po
sition, highestRoot); | 537 return lastEditablePositionBeforePositionInRootAlgorithm<EditingStrategy>(po
sition, highestRoot); |
538 } | 538 } |
539 | 539 |
540 PositionInComposedTree lastEditablePositionBeforePositionInRoot(const PositionIn
ComposedTree& position, Node& highestRoot) | 540 PositionInFlatTree lastEditablePositionBeforePositionInRoot(const PositionInFlat
Tree& position, Node& highestRoot) |
541 { | 541 { |
542 return lastEditablePositionBeforePositionInRootAlgorithm<EditingInComposedTr
eeStrategy>(position, highestRoot); | 542 return lastEditablePositionBeforePositionInRootAlgorithm<EditingInFlatTreeSt
rategy>(position, highestRoot); |
543 } | 543 } |
544 | 544 |
545 int uncheckedPreviousOffset(const Node* n, int current) | 545 int uncheckedPreviousOffset(const Node* n, int current) |
546 { | 546 { |
547 return n->layoutObject() ? n->layoutObject()->previousOffset(current) : curr
ent - 1; | 547 return n->layoutObject() ? n->layoutObject()->previousOffset(current) : curr
ent - 1; |
548 } | 548 } |
549 | 549 |
550 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current
) | 550 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current
) |
551 { | 551 { |
552 return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDelet
ion(current) : current - 1; | 552 return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDelet
ion(current) : current - 1; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 return PositionTemplate<Strategy>(parent, node->nodeIndex()); | 596 return PositionTemplate<Strategy>(parent, node->nodeIndex()); |
597 } | 597 } |
598 return position; | 598 return position; |
599 } | 599 } |
600 | 600 |
601 Position previousPositionOf(const Position& position, PositionMoveType moveType) | 601 Position previousPositionOf(const Position& position, PositionMoveType moveType) |
602 { | 602 { |
603 return previousPositionOfAlgorithm<EditingStrategy>(position, moveType); | 603 return previousPositionOfAlgorithm<EditingStrategy>(position, moveType); |
604 } | 604 } |
605 | 605 |
606 PositionInComposedTree previousPositionOf(const PositionInComposedTree& position
, PositionMoveType moveType) | 606 PositionInFlatTree previousPositionOf(const PositionInFlatTree& position, Positi
onMoveType moveType) |
607 { | 607 { |
608 return previousPositionOfAlgorithm<EditingInComposedTreeStrategy>(position,
moveType); | 608 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>(position, move
Type); |
609 } | 609 } |
610 | 610 |
611 template <typename Strategy> | 611 template <typename Strategy> |
612 PositionTemplate<Strategy> nextPositionOfAlgorithm(const PositionTemplate<Strate
gy>& position, PositionMoveType moveType) | 612 PositionTemplate<Strategy> nextPositionOfAlgorithm(const PositionTemplate<Strate
gy>& position, PositionMoveType moveType) |
613 { | 613 { |
614 ASSERT(moveType != PositionMoveType::BackwardDeletion); | 614 ASSERT(moveType != PositionMoveType::BackwardDeletion); |
615 | 615 |
616 Node* node = position.anchorNode(); | 616 Node* node = position.anchorNode(); |
617 if (!node) | 617 if (!node) |
618 return position; | 618 return position; |
(...skipping 18 matching lines...) Expand all Loading... |
637 if (ContainerNode* parent = Strategy::parent(*node)) | 637 if (ContainerNode* parent = Strategy::parent(*node)) |
638 return PositionTemplate<Strategy>::editingPositionOf(parent, Strategy::i
ndex(*node) + 1); | 638 return PositionTemplate<Strategy>::editingPositionOf(parent, Strategy::i
ndex(*node) + 1); |
639 return position; | 639 return position; |
640 } | 640 } |
641 | 641 |
642 Position nextPositionOf(const Position& position, PositionMoveType moveType) | 642 Position nextPositionOf(const Position& position, PositionMoveType moveType) |
643 { | 643 { |
644 return nextPositionOfAlgorithm<EditingStrategy>(position, moveType); | 644 return nextPositionOfAlgorithm<EditingStrategy>(position, moveType); |
645 } | 645 } |
646 | 646 |
647 PositionInComposedTree nextPositionOf(const PositionInComposedTree& position, Po
sitionMoveType moveType) | 647 PositionInFlatTree nextPositionOf(const PositionInFlatTree& position, PositionMo
veType moveType) |
648 { | 648 { |
649 return nextPositionOfAlgorithm<EditingInComposedTreeStrategy>(position, move
Type); | 649 return nextPositionOfAlgorithm<EditingInFlatTreeStrategy>(position, moveType
); |
650 } | 650 } |
651 | 651 |
652 bool isEnclosingBlock(const Node* node) | 652 bool isEnclosingBlock(const Node* node) |
653 { | 653 { |
654 return node && node->layoutObject() && !node->layoutObject()->isInline() &&
!node->layoutObject()->isRubyText(); | 654 return node && node->layoutObject() && !node->layoutObject()->isInline() &&
!node->layoutObject()->isRubyText(); |
655 } | 655 } |
656 | 656 |
657 bool isInline(const Node* node) | 657 bool isInline(const Node* node) |
658 { | 658 { |
659 return node && node->layoutObject() && node->layoutObject()->isInline(); | 659 return node && node->layoutObject() && node->layoutObject()->isInline(); |
(...skipping 15 matching lines...) Expand all Loading... |
675 { | 675 { |
676 Node* enclosingNode = enclosingNodeOfType(position, isEnclosingBlock, rule); | 676 Node* enclosingNode = enclosingNodeOfType(position, isEnclosingBlock, rule); |
677 return enclosingNode && enclosingNode->isElementNode() ? toElement(enclosing
Node) : nullptr; | 677 return enclosingNode && enclosingNode->isElementNode() ? toElement(enclosing
Node) : nullptr; |
678 } | 678 } |
679 | 679 |
680 Element* enclosingBlock(const Position& position, EditingBoundaryCrossingRule ru
le) | 680 Element* enclosingBlock(const Position& position, EditingBoundaryCrossingRule ru
le) |
681 { | 681 { |
682 return enclosingBlockAlgorithm<EditingStrategy>(position, rule); | 682 return enclosingBlockAlgorithm<EditingStrategy>(position, rule); |
683 } | 683 } |
684 | 684 |
685 Element* enclosingBlock(const PositionInComposedTree& position, EditingBoundaryC
rossingRule rule) | 685 Element* enclosingBlock(const PositionInFlatTree& position, EditingBoundaryCross
ingRule rule) |
686 { | 686 { |
687 return enclosingBlockAlgorithm<EditingInComposedTreeStrategy>(position, rule
); | 687 return enclosingBlockAlgorithm<EditingInFlatTreeStrategy>(position, rule); |
688 } | 688 } |
689 | 689 |
690 Element* enclosingBlockFlowElement(Node& node) | 690 Element* enclosingBlockFlowElement(Node& node) |
691 { | 691 { |
692 if (isBlockFlowElement(node)) | 692 if (isBlockFlowElement(node)) |
693 return &toElement(node); | 693 return &toElement(node); |
694 | 694 |
695 for (Node* n = node.parentNode(); n; n = n->parentNode()) { | 695 for (Node* n = node.parentNode(); n; n = n->parentNode()) { |
696 if (isBlockFlowElement(*n) || isHTMLBodyElement(*n)) | 696 if (isBlockFlowElement(*n) || isHTMLBodyElement(*n)) |
697 return toElement(n); | 697 return toElement(n); |
(...skipping 20 matching lines...) Expand all Loading... |
718 return LTR; | 718 return LTR; |
719 LayoutObject* layoutObject = enclosingBlockElement->layoutObject(); | 719 LayoutObject* layoutObject = enclosingBlockElement->layoutObject(); |
720 return layoutObject ? layoutObject->style()->direction() : LTR; | 720 return layoutObject ? layoutObject->style()->direction() : LTR; |
721 } | 721 } |
722 | 722 |
723 TextDirection directionOfEnclosingBlock(const Position& position) | 723 TextDirection directionOfEnclosingBlock(const Position& position) |
724 { | 724 { |
725 return directionOfEnclosingBlockAlgorithm<EditingStrategy>(position); | 725 return directionOfEnclosingBlockAlgorithm<EditingStrategy>(position); |
726 } | 726 } |
727 | 727 |
728 TextDirection directionOfEnclosingBlock(const PositionInComposedTree& position) | 728 TextDirection directionOfEnclosingBlock(const PositionInFlatTree& position) |
729 { | 729 { |
730 return directionOfEnclosingBlockAlgorithm<EditingInComposedTreeStrategy>(pos
ition); | 730 return directionOfEnclosingBlockAlgorithm<EditingInFlatTreeStrategy>(positio
n); |
731 } | 731 } |
732 | 732 |
733 TextDirection primaryDirectionOf(const Node& node) | 733 TextDirection primaryDirectionOf(const Node& node) |
734 { | 734 { |
735 TextDirection primaryDirection = LTR; | 735 TextDirection primaryDirection = LTR; |
736 for (const LayoutObject* r = node.layoutObject(); r; r = r->parent()) { | 736 for (const LayoutObject* r = node.layoutObject(); r; r = r->parent()) { |
737 if (r->isLayoutBlockFlow()) { | 737 if (r->isLayoutBlockFlow()) { |
738 primaryDirection = r->style()->direction(); | 738 primaryDirection = r->style()->direction(); |
739 break; | 739 break; |
740 } | 740 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 return toElement(upstream.anchorNode()); | 875 return toElement(upstream.anchorNode()); |
876 | 876 |
877 return nullptr; | 877 return nullptr; |
878 } | 878 } |
879 | 879 |
880 Element* isFirstPositionAfterTable(const VisiblePosition& visiblePosition) | 880 Element* isFirstPositionAfterTable(const VisiblePosition& visiblePosition) |
881 { | 881 { |
882 return isFirstPositionAfterTableAlgorithm<EditingStrategy>(visiblePosition); | 882 return isFirstPositionAfterTableAlgorithm<EditingStrategy>(visiblePosition); |
883 } | 883 } |
884 | 884 |
885 Element* isFirstPositionAfterTable(const VisiblePositionInComposedTree& visibleP
osition) | 885 Element* isFirstPositionAfterTable(const VisiblePositionInFlatTree& visiblePosit
ion) |
886 { | 886 { |
887 return isFirstPositionAfterTableAlgorithm<EditingInComposedTreeStrategy>(vis
iblePosition); | 887 return isFirstPositionAfterTableAlgorithm<EditingInFlatTreeStrategy>(visible
Position); |
888 } | 888 } |
889 | 889 |
890 Element* isLastPositionBeforeTable(const VisiblePosition& visiblePosition) | 890 Element* isLastPositionBeforeTable(const VisiblePosition& visiblePosition) |
891 { | 891 { |
892 Position downstream(mostForwardCaretPosition(visiblePosition.deepEquivalent(
))); | 892 Position downstream(mostForwardCaretPosition(visiblePosition.deepEquivalent(
))); |
893 if (isDisplayInsideTable(downstream.anchorNode()) && downstream.atFirstEditi
ngPositionForNode()) | 893 if (isDisplayInsideTable(downstream.anchorNode()) && downstream.atFirstEditi
ngPositionForNode()) |
894 return toElement(downstream.anchorNode()); | 894 return toElement(downstream.anchorNode()); |
895 | 895 |
896 return 0; | 896 return 0; |
897 } | 897 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 } | 1022 } |
1023 | 1023 |
1024 return nullptr; | 1024 return nullptr; |
1025 } | 1025 } |
1026 | 1026 |
1027 Node* enclosingNodeOfType(const Position& p, bool (*nodeIsOfType)(const Node*),
EditingBoundaryCrossingRule rule) | 1027 Node* enclosingNodeOfType(const Position& p, bool (*nodeIsOfType)(const Node*),
EditingBoundaryCrossingRule rule) |
1028 { | 1028 { |
1029 return enclosingNodeOfTypeAlgorithm<EditingStrategy>(p, nodeIsOfType, rule); | 1029 return enclosingNodeOfTypeAlgorithm<EditingStrategy>(p, nodeIsOfType, rule); |
1030 } | 1030 } |
1031 | 1031 |
1032 Node* enclosingNodeOfType(const PositionInComposedTree& p, bool (*nodeIsOfType)(
const Node*), EditingBoundaryCrossingRule rule) | 1032 Node* enclosingNodeOfType(const PositionInFlatTree& p, bool (*nodeIsOfType)(cons
t Node*), EditingBoundaryCrossingRule rule) |
1033 { | 1033 { |
1034 return enclosingNodeOfTypeAlgorithm<EditingInComposedTreeStrategy>(p, nodeIs
OfType, rule); | 1034 return enclosingNodeOfTypeAlgorithm<EditingInFlatTreeStrategy>(p, nodeIsOfTy
pe, rule); |
1035 } | 1035 } |
1036 | 1036 |
1037 Node* highestEnclosingNodeOfType(const Position& p, bool (*nodeIsOfType)(const N
ode*), EditingBoundaryCrossingRule rule, Node* stayWithin) | 1037 Node* highestEnclosingNodeOfType(const Position& p, bool (*nodeIsOfType)(const N
ode*), EditingBoundaryCrossingRule rule, Node* stayWithin) |
1038 { | 1038 { |
1039 Node* highest = nullptr; | 1039 Node* highest = nullptr; |
1040 ContainerNode* root = rule == CannotCrossEditingBoundary ? highestEditableRo
ot(p) : nullptr; | 1040 ContainerNode* root = rule == CannotCrossEditingBoundary ? highestEditableRo
ot(p) : nullptr; |
1041 for (Node* n = p.computeContainerNode(); n && n != stayWithin; n = n->parent
Node()) { | 1041 for (Node* n = p.computeContainerNode(); n && n != stayWithin; n = n->parent
Node()) { |
1042 if (root && !n->hasEditableStyle()) | 1042 if (root && !n->hasEditableStyle()) |
1043 continue; | 1043 continue; |
1044 if (nodeIsOfType(n)) | 1044 if (nodeIsOfType(n)) |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1530 if (normalizedStart.compareTo(normalizedEnd) > 0) | 1530 if (normalizedStart.compareTo(normalizedEnd) > 0) |
1531 return EphemeralRangeTemplate<Strategy>(normalizedEnd, normalizedStart); | 1531 return EphemeralRangeTemplate<Strategy>(normalizedEnd, normalizedStart); |
1532 return EphemeralRangeTemplate<Strategy>(normalizedStart, normalizedEnd); | 1532 return EphemeralRangeTemplate<Strategy>(normalizedStart, normalizedEnd); |
1533 } | 1533 } |
1534 | 1534 |
1535 EphemeralRange normalizeRange(const EphemeralRange& range) | 1535 EphemeralRange normalizeRange(const EphemeralRange& range) |
1536 { | 1536 { |
1537 return normalizeRangeAlgorithm<EditingStrategy>(range); | 1537 return normalizeRangeAlgorithm<EditingStrategy>(range); |
1538 } | 1538 } |
1539 | 1539 |
1540 EphemeralRangeInComposedTree normalizeRange(const EphemeralRangeInComposedTree&
range) | 1540 EphemeralRangeInFlatTree normalizeRange(const EphemeralRangeInFlatTree& range) |
1541 { | 1541 { |
1542 return normalizeRangeAlgorithm<EditingInComposedTreeStrategy>(range); | 1542 return normalizeRangeAlgorithm<EditingInFlatTreeStrategy>(range); |
1543 } | 1543 } |
1544 | 1544 |
1545 VisiblePosition visiblePositionForIndex(int index, ContainerNode* scope) | 1545 VisiblePosition visiblePositionForIndex(int index, ContainerNode* scope) |
1546 { | 1546 { |
1547 if (!scope) | 1547 if (!scope) |
1548 return VisiblePosition(); | 1548 return VisiblePosition(); |
1549 EphemeralRange range = PlainTextRange(index).createRangeForSelection(*scope)
; | 1549 EphemeralRange range = PlainTextRange(index).createRangeForSelection(*scope)
; |
1550 // Check for an invalid index. Certain editing operations invalidate indices | 1550 // Check for an invalid index. Certain editing operations invalidate indices |
1551 // because of problems with | 1551 // because of problems with |
1552 // TextIteratorEmitsCharactersBetweenAllVisiblePositions. | 1552 // TextIteratorEmitsCharactersBetweenAllVisiblePositions. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 // instead of possibly at the end of the last node before the selection | 1646 // instead of possibly at the end of the last node before the selection |
1647 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); | 1647 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); |
1648 } | 1648 } |
1649 | 1649 |
1650 bool isTextSecurityNode(const Node* node) | 1650 bool isTextSecurityNode(const Node* node) |
1651 { | 1651 { |
1652 return node && node->layoutObject() && node->layoutObject()->style()->textSe
curity() != TSNONE; | 1652 return node && node->layoutObject() && node->layoutObject()->style()->textSe
curity() != TSNONE; |
1653 } | 1653 } |
1654 | 1654 |
1655 } // namespace blink | 1655 } // namespace blink |
OLD | NEW |