| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 5 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 6 #include "core/dom/Document.h" | 6 #include "core/dom/Document.h" |
| 7 #include "core/dom/Element.h" | 7 #include "core/dom/Element.h" |
| 8 #include "core/dom/Text.h" | 8 #include "core/dom/Text.h" |
| 9 #include "core/editing/FrameSelection.h" | 9 #include "core/editing/FrameSelection.h" |
| 10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 p1 = Position(text2, selBegin - str1.length()); | 270 p1 = Position(text2, selBegin - str1.length()); |
| 271 else | 271 else |
| 272 p1 = Position(text3, selBegin - str1.length() - str2.length()); | 272 p1 = Position(text3, selBegin - str1.length() - str2.length()); |
| 273 if (selEnd < str1.length()) | 273 if (selEnd < str1.length()) |
| 274 p2 = Position(text1, selEnd); | 274 p2 = Position(text1, selEnd); |
| 275 else if (selEnd < str1.length() + str2.length()) | 275 else if (selEnd < str1.length() + str2.length()) |
| 276 p2 = Position(text2, selEnd - str1.length()); | 276 p2 = Position(text2, selEnd - str1.length()); |
| 277 else | 277 else |
| 278 p2 = Position(text3, selEnd - str1.length() - str2.length()); | 278 p2 = Position(text3, selEnd - str1.length() - str2.length()); |
| 279 | 279 |
| 280 selection().setSelection(createVisibleSelection(p1, p2)); | 280 selection().setSelection( |
| 281 SelectionInDOMTree::Builder().setBaseAndExtent(p1, p2).build()); |
| 281 } | 282 } |
| 282 | 283 |
| 283 void GranularityStrategyTest::setupVerticalAlign(String str1, | 284 void GranularityStrategyTest::setupVerticalAlign(String str1, |
| 284 String str2, | 285 String str2, |
| 285 String str3, | 286 String str3, |
| 286 size_t selBegin, | 287 size_t selBegin, |
| 287 size_t selEnd) { | 288 size_t selEnd) { |
| 288 setInnerHTML( | 289 setInnerHTML( |
| 289 "<html>" | 290 "<html>" |
| 290 "<head>" | 291 "<head>" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 dummyPageHolder().frame().settings()->setSelectionStrategy( | 498 dummyPageHolder().frame().settings()->setSelectionStrategy( |
| 498 SelectionStrategy::Character); | 499 SelectionStrategy::Character); |
| 499 dummyPageHolder().frame().settings()->setDefaultFontSize(12); | 500 dummyPageHolder().frame().settings()->setDefaultFontSize(12); |
| 500 // "Foo Bar Baz," | 501 // "Foo Bar Baz," |
| 501 Text* text = appendTextNode("Foo Bar Baz,"); | 502 Text* text = appendTextNode("Foo Bar Baz,"); |
| 502 document().updateStyleAndLayout(); | 503 document().updateStyleAndLayout(); |
| 503 | 504 |
| 504 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > | 505 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > |
| 505 // means end). | 506 // means end). |
| 506 selection().setSelection( | 507 selection().setSelection( |
| 507 createVisibleSelection(Position(text, 5), Position(text, 6))); | 508 SelectionInDOMTree::Builder() |
| 509 .setBaseAndExtent(Position(text, 5), Position(text, 6)) |
| 510 .build()); |
| 508 EXPECT_EQ_SELECTED_TEXT("a"); | 511 EXPECT_EQ_SELECTED_TEXT("a"); |
| 509 // "Foo B^ar B|>az," | 512 // "Foo B^ar B|>az," |
| 510 selection().moveRangeSelectionExtent( | 513 selection().moveRangeSelectionExtent( |
| 511 visiblePositionToContentsPoint(createVisiblePosition(Position(text, 9)))); | 514 visiblePositionToContentsPoint(createVisiblePosition(Position(text, 9)))); |
| 512 EXPECT_EQ_SELECTED_TEXT("ar B"); | 515 EXPECT_EQ_SELECTED_TEXT("ar B"); |
| 513 // "F<|oo B^ar Baz," | 516 // "F<|oo B^ar Baz," |
| 514 selection().moveRangeSelectionExtent( | 517 selection().moveRangeSelectionExtent( |
| 515 visiblePositionToContentsPoint(createVisiblePosition(Position(text, 1)))); | 518 visiblePositionToContentsPoint(createVisiblePosition(Position(text, 1)))); |
| 516 EXPECT_EQ_SELECTED_TEXT("oo B"); | 519 EXPECT_EQ_SELECTED_TEXT("oo B"); |
| 517 } | 520 } |
| 518 | 521 |
| 519 // DirectionGranularityStrategy strategy on rotated text should revert to the | 522 // DirectionGranularityStrategy strategy on rotated text should revert to the |
| 520 // same behavior as CharacterGranularityStrategy | 523 // same behavior as CharacterGranularityStrategy |
| 521 TEST_F(GranularityStrategyTest, DirectionRotate) { | 524 TEST_F(GranularityStrategyTest, DirectionRotate) { |
| 522 Text* text = setupRotate("Foo Bar Baz,"); | 525 Text* text = setupRotate("Foo Bar Baz,"); |
| 523 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > | 526 // "Foo B^a|>r Baz," (^ means base, | means extent, , < means start, and > |
| 524 // means end). | 527 // means end). |
| 525 selection().setSelection( | 528 selection().setSelection( |
| 526 createVisibleSelection(Position(text, 5), Position(text, 6))); | 529 SelectionInDOMTree::Builder() |
| 530 .setBaseAndExtent(Position(text, 5), Position(text, 6)) |
| 531 .build()); |
| 527 EXPECT_EQ_SELECTED_TEXT("a"); | 532 EXPECT_EQ_SELECTED_TEXT("a"); |
| 528 IntPoint p = m_letterPos[9]; | 533 IntPoint p = m_letterPos[9]; |
| 529 // Need to move by one pixel, otherwise this point is not evaluated | 534 // Need to move by one pixel, otherwise this point is not evaluated |
| 530 // to the same line as the text by hit testing. | 535 // to the same line as the text by hit testing. |
| 531 p.move(1, 0); | 536 p.move(1, 0); |
| 532 // "Foo B^ar B|>az," | 537 // "Foo B^ar B|>az," |
| 533 selection().moveRangeSelectionExtent(p); | 538 selection().moveRangeSelectionExtent(p); |
| 534 EXPECT_EQ_SELECTED_TEXT("ar B"); | 539 EXPECT_EQ_SELECTED_TEXT("ar B"); |
| 535 p = m_letterPos[1]; | 540 p = m_letterPos[1]; |
| 536 p.move(1, 0); | 541 p.move(1, 0); |
| 537 // "F<|oo B^ar Baz," | 542 // "F<|oo B^ar Baz," |
| 538 selection().moveRangeSelectionExtent(p); | 543 selection().moveRangeSelectionExtent(p); |
| 539 EXPECT_EQ_SELECTED_TEXT("oo B"); | 544 EXPECT_EQ_SELECTED_TEXT("oo B"); |
| 540 } | 545 } |
| 541 | 546 |
| 542 TEST_F(GranularityStrategyTest, DirectionExpandTranslateZ) { | 547 TEST_F(GranularityStrategyTest, DirectionExpandTranslateZ) { |
| 543 Text* text = setupTranslateZ("abcdef ghij kl mnopqr stuvwi inm mnii,"); | 548 Text* text = setupTranslateZ("abcdef ghij kl mnopqr stuvwi inm mnii,"); |
| 544 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means extent, | 549 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means extent, |
| 545 // < means start, and > means end). | 550 // < means start, and > means end). |
| 546 selection().setSelection( | 551 selection().setSelection( |
| 547 createVisibleSelection(Position(text, 18), Position(text, 19))); | 552 SelectionInDOMTree::Builder() |
| 553 .setBaseAndExtent(Position(text, 18), Position(text, 19)) |
| 554 .build()); |
| 548 EXPECT_EQ_SELECTED_TEXT("p"); | 555 EXPECT_EQ_SELECTED_TEXT("p"); |
| 549 testDirectionExpand(); | 556 testDirectionExpand(); |
| 550 } | 557 } |
| 551 | 558 |
| 552 TEST_F(GranularityStrategyTest, DirectionExpandTransform) { | 559 TEST_F(GranularityStrategyTest, DirectionExpandTransform) { |
| 553 Text* text = setupTransform("abcdef ghij kl mnopqr stuvwi inm mnii,"); | 560 Text* text = setupTransform("abcdef ghij kl mnopqr stuvwi inm mnii,"); |
| 554 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means extent, | 561 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means extent, |
| 555 // < means start, and > means end). | 562 // < means start, and > means end). |
| 556 selection().setSelection( | 563 selection().setSelection( |
| 557 createVisibleSelection(Position(text, 18), Position(text, 19))); | 564 SelectionInDOMTree::Builder() |
| 565 .setBaseAndExtent(Position(text, 18), Position(text, 19)) |
| 566 .build()); |
| 558 EXPECT_EQ_SELECTED_TEXT("p"); | 567 EXPECT_EQ_SELECTED_TEXT("p"); |
| 559 testDirectionExpand(); | 568 testDirectionExpand(); |
| 560 } | 569 } |
| 561 | 570 |
| 562 TEST_F(GranularityStrategyTest, DirectionExpandVerticalAlign) { | 571 TEST_F(GranularityStrategyTest, DirectionExpandVerticalAlign) { |
| 563 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means extent, | 572 // "abcdef ghij kl mno^p|>qr stuvwi inm mnii," (^ means base, | means extent, |
| 564 // < means start, and > means end). | 573 // < means start, and > means end). |
| 565 setupVerticalAlign("abcdef ghij kl m", "nopq", "r stuvwi inm mnii,", 18, 19); | 574 setupVerticalAlign("abcdef ghij kl m", "nopq", "r stuvwi inm mnii,", 18, 19); |
| 566 EXPECT_EQ_SELECTED_TEXT("p"); | 575 EXPECT_EQ_SELECTED_TEXT("p"); |
| 567 testDirectionExpand(); | 576 testDirectionExpand(); |
| 568 } | 577 } |
| 569 | 578 |
| 570 TEST_F(GranularityStrategyTest, DirectionExpandFontSizes) { | 579 TEST_F(GranularityStrategyTest, DirectionExpandFontSizes) { |
| 571 setupFontSize("abcdef ghij kl mnopqr st", "uv", "wi inm mnii,", 18, 19); | 580 setupFontSize("abcdef ghij kl mnopqr st", "uv", "wi inm mnii,", 18, 19); |
| 572 EXPECT_EQ_SELECTED_TEXT("p"); | 581 EXPECT_EQ_SELECTED_TEXT("p"); |
| 573 testDirectionExpand(); | 582 testDirectionExpand(); |
| 574 } | 583 } |
| 575 | 584 |
| 576 TEST_F(GranularityStrategyTest, DirectionShrinkTranslateZ) { | 585 TEST_F(GranularityStrategyTest, DirectionShrinkTranslateZ) { |
| 577 Text* text = setupTranslateZ("abcdef ghij kl mnopqr iiinmni, abc"); | 586 Text* text = setupTranslateZ("abcdef ghij kl mnopqr iiinmni, abc"); |
| 578 selection().setSelection( | 587 selection().setSelection( |
| 579 createVisibleSelection(Position(text, 18), Position(text, 21))); | 588 SelectionInDOMTree::Builder() |
| 589 .setBaseAndExtent(Position(text, 18), Position(text, 21)) |
| 590 .build()); |
| 580 EXPECT_EQ_SELECTED_TEXT("pqr"); | 591 EXPECT_EQ_SELECTED_TEXT("pqr"); |
| 581 testDirectionShrink(); | 592 testDirectionShrink(); |
| 582 } | 593 } |
| 583 | 594 |
| 584 TEST_F(GranularityStrategyTest, DirectionShrinkTransform) { | 595 TEST_F(GranularityStrategyTest, DirectionShrinkTransform) { |
| 585 Text* text = setupTransform("abcdef ghij kl mnopqr iiinmni, abc"); | 596 Text* text = setupTransform("abcdef ghij kl mnopqr iiinmni, abc"); |
| 586 selection().setSelection( | 597 selection().setSelection( |
| 587 createVisibleSelection(Position(text, 18), Position(text, 21))); | 598 SelectionInDOMTree::Builder() |
| 599 .setBaseAndExtent(Position(text, 18), Position(text, 21)) |
| 600 .build()); |
| 588 EXPECT_EQ_SELECTED_TEXT("pqr"); | 601 EXPECT_EQ_SELECTED_TEXT("pqr"); |
| 589 testDirectionShrink(); | 602 testDirectionShrink(); |
| 590 } | 603 } |
| 591 | 604 |
| 592 TEST_F(GranularityStrategyTest, DirectionShrinkVerticalAlign) { | 605 TEST_F(GranularityStrategyTest, DirectionShrinkVerticalAlign) { |
| 593 setupVerticalAlign("abcdef ghij kl mnopqr ii", "inm", "ni, abc", 18, 21); | 606 setupVerticalAlign("abcdef ghij kl mnopqr ii", "inm", "ni, abc", 18, 21); |
| 594 EXPECT_EQ_SELECTED_TEXT("pqr"); | 607 EXPECT_EQ_SELECTED_TEXT("pqr"); |
| 595 testDirectionShrink(); | 608 testDirectionShrink(); |
| 596 } | 609 } |
| 597 | 610 |
| 598 TEST_F(GranularityStrategyTest, DirectionShrinkFontSizes) { | 611 TEST_F(GranularityStrategyTest, DirectionShrinkFontSizes) { |
| 599 setupFontSize("abcdef ghij kl mnopqr ii", "inm", "ni, abc", 18, 21); | 612 setupFontSize("abcdef ghij kl mnopqr ii", "inm", "ni, abc", 18, 21); |
| 600 EXPECT_EQ_SELECTED_TEXT("pqr"); | 613 EXPECT_EQ_SELECTED_TEXT("pqr"); |
| 601 testDirectionShrink(); | 614 testDirectionShrink(); |
| 602 } | 615 } |
| 603 | 616 |
| 604 TEST_F(GranularityStrategyTest, DirectionSwitchSideTranslateZ) { | 617 TEST_F(GranularityStrategyTest, DirectionSwitchSideTranslateZ) { |
| 605 Text* text = setupTranslateZ("abcd efgh ijkl mnopqr iiinmni, abc"); | 618 Text* text = setupTranslateZ("abcd efgh ijkl mnopqr iiinmni, abc"); |
| 606 selection().setSelection( | 619 selection().setSelection( |
| 607 createVisibleSelection(Position(text, 18), Position(text, 21))); | 620 SelectionInDOMTree::Builder() |
| 621 .setBaseAndExtent(Position(text, 18), Position(text, 21)) |
| 622 .build()); |
| 608 EXPECT_EQ_SELECTED_TEXT("pqr"); | 623 EXPECT_EQ_SELECTED_TEXT("pqr"); |
| 609 testDirectionSwitchSide(); | 624 testDirectionSwitchSide(); |
| 610 } | 625 } |
| 611 | 626 |
| 612 TEST_F(GranularityStrategyTest, DirectionSwitchSideTransform) { | 627 TEST_F(GranularityStrategyTest, DirectionSwitchSideTransform) { |
| 613 Text* text = setupTransform("abcd efgh ijkl mnopqr iiinmni, abc"); | 628 Text* text = setupTransform("abcd efgh ijkl mnopqr iiinmni, abc"); |
| 614 selection().setSelection( | 629 selection().setSelection( |
| 615 createVisibleSelection(Position(text, 18), Position(text, 21))); | 630 SelectionInDOMTree::Builder() |
| 631 .setBaseAndExtent(Position(text, 18), Position(text, 21)) |
| 632 .build()); |
| 616 EXPECT_EQ_SELECTED_TEXT("pqr"); | 633 EXPECT_EQ_SELECTED_TEXT("pqr"); |
| 617 testDirectionSwitchSide(); | 634 testDirectionSwitchSide(); |
| 618 } | 635 } |
| 619 | 636 |
| 620 TEST_F(GranularityStrategyTest, DirectionSwitchSideVerticalAlign) { | 637 TEST_F(GranularityStrategyTest, DirectionSwitchSideVerticalAlign) { |
| 621 setupVerticalAlign("abcd efgh ijkl", " mnopqr", " iiinmni, abc", 18, 21); | 638 setupVerticalAlign("abcd efgh ijkl", " mnopqr", " iiinmni, abc", 18, 21); |
| 622 EXPECT_EQ_SELECTED_TEXT("pqr"); | 639 EXPECT_EQ_SELECTED_TEXT("pqr"); |
| 623 testDirectionSwitchSide(); | 640 testDirectionSwitchSide(); |
| 624 } | 641 } |
| 625 | 642 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 638 document().body()->appendChild(text); | 655 document().body()->appendChild(text); |
| 639 document().updateStyleAndLayout(); | 656 document().updateStyleAndLayout(); |
| 640 dummyPageHolder().frame().settings()->setSelectionStrategy( | 657 dummyPageHolder().frame().settings()->setSelectionStrategy( |
| 641 SelectionStrategy::Direction); | 658 SelectionStrategy::Direction); |
| 642 | 659 |
| 643 parseText(text); | 660 parseText(text); |
| 644 | 661 |
| 645 // "abcd efgh ijkl mno^pqr|> iiin, abc" (^ means base, | means extent, < means | 662 // "abcd efgh ijkl mno^pqr|> iiin, abc" (^ means base, | means extent, < means |
| 646 // start, and > means end). | 663 // start, and > means end). |
| 647 selection().setSelection( | 664 selection().setSelection( |
| 648 createVisibleSelection(Position(text, 18), Position(text, 21))); | 665 SelectionInDOMTree::Builder() |
| 666 .setBaseAndExtent(Position(text, 18), Position(text, 21)) |
| 667 .build()); |
| 649 EXPECT_EQ_SELECTED_TEXT("pqr"); | 668 EXPECT_EQ_SELECTED_TEXT("pqr"); |
| 650 // Move to the middle of word #4 selecting it - this will set the offset to | 669 // Move to the middle of word #4 selecting it - this will set the offset to |
| 651 // be half the width of "iiin". | 670 // be half the width of "iiin". |
| 652 selection().moveRangeSelectionExtent(m_wordMiddles[4]); | 671 selection().moveRangeSelectionExtent(m_wordMiddles[4]); |
| 653 EXPECT_EQ_SELECTED_TEXT("pqr iiin"); | 672 EXPECT_EQ_SELECTED_TEXT("pqr iiin"); |
| 654 // Move to the middle of word #2 - extent will switch over to the other | 673 // Move to the middle of word #2 - extent will switch over to the other |
| 655 // side of the base, and we should enter word granularity since we pass | 674 // side of the base, and we should enter word granularity since we pass |
| 656 // the word boundary. The offset should become negative since the width | 675 // the word boundary. The offset should become negative since the width |
| 657 // of "efghjkkl" is greater than that of "iiin". | 676 // of "efghjkkl" is greater than that of "iiin". |
| 658 int offset = m_letterPos[26].x() - m_wordMiddles[4].x(); | 677 int offset = m_letterPos[26].x() - m_wordMiddles[4].x(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 674 document().body()->appendChild(text); | 693 document().body()->appendChild(text); |
| 675 document().updateStyleAndLayout(); | 694 document().updateStyleAndLayout(); |
| 676 dummyPageHolder().frame().settings()->setSelectionStrategy( | 695 dummyPageHolder().frame().settings()->setSelectionStrategy( |
| 677 SelectionStrategy::Direction); | 696 SelectionStrategy::Direction); |
| 678 | 697 |
| 679 parseText(text); | 698 parseText(text); |
| 680 | 699 |
| 681 // "ab cd efghijkl ^mnopqr |>stuvwi inm," (^ means base and | means extent, | 700 // "ab cd efghijkl ^mnopqr |>stuvwi inm," (^ means base and | means extent, |
| 682 // > means end). | 701 // > means end). |
| 683 selection().setSelection( | 702 selection().setSelection( |
| 684 createVisibleSelection(Position(text, 15), Position(text, 22))); | 703 SelectionInDOMTree::Builder() |
| 704 .setBaseAndExtent(Position(text, 15), Position(text, 22)) |
| 705 .build()); |
| 685 EXPECT_EQ_SELECTED_TEXT("mnopqr "); | 706 EXPECT_EQ_SELECTED_TEXT("mnopqr "); |
| 686 selection().moveRangeSelectionExtent(m_wordMiddles[4]); | 707 selection().moveRangeSelectionExtent(m_wordMiddles[4]); |
| 687 EXPECT_EQ_SELECTED_TEXT("mnopqr iiin"); | 708 EXPECT_EQ_SELECTED_TEXT("mnopqr iiin"); |
| 688 } | 709 } |
| 689 | 710 |
| 690 } // namespace blink | 711 } // namespace blink |
| OLD | NEW |