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

Side by Side Diff: third_party/WebKit/LayoutTests/editing/assert_selection.js

Issue 2963113002: Introduce Selection#compute{Left,Top} in assert_selection() (Closed)
Patch Set: 2017-06-29T15:20:58 Created 3 years, 5 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 'use strict'; 5 'use strict';
6 6
7 // This file provides |assert_selection(sample, tester, expectedText, options)| 7 // This file provides |assert_selection(sample, tester, expectedText, options)|
8 // assertion to W3C test harness to write editing test cases easier. 8 // assertion to W3C test harness to write editing test cases easier.
9 // 9 //
10 // |sample| is an HTML fragment text which is inserted as |innerHTML|. It should 10 // |sample| is an HTML fragment text which is inserted as |innerHTML|. It should
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 // TODO(yosin): Please use "clang-format -style=Chromium -i" for formatting 53 // TODO(yosin): Please use "clang-format -style=Chromium -i" for formatting
54 // this file. 54 // this file.
55 55
56 (function() { 56 (function() {
57 /** @enum{string} */ 57 /** @enum{string} */
58 const DumpAs = { 58 const DumpAs = {
59 DOM_TREE: 'domtree', 59 DOM_TREE: 'domtree',
60 FLAT_TREE: 'flattree', 60 FLAT_TREE: 'flattree',
61 }; 61 };
62 62
63 const kOffsetLeftOfBodyInIFrame = 16;
64 const kOffsetTopOfBodyInIFrame = 16;
65
63 /** @const @type {string} */ 66 /** @const @type {string} */
64 const kTextArea = 'TEXTAREA'; 67 const kTextArea = 'TEXTAREA';
65 68
66 class Traversal { 69 class Traversal {
67 /** 70 /**
68 * @param {!Node} node 71 * @param {!Node} node
69 * @return {Node} 72 * @return {Node}
70 */ 73 */
71 firstChildOf(node) { throw new Error('You should implement firstChildOf'); } 74 firstChildOf(node) { throw new Error('You should implement firstChildOf'); }
72 75
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 serializeInternal(node) { 660 serializeInternal(node) {
658 if (isElement(node)) 661 if (isElement(node))
659 return this.handleElementNode(node); 662 return this.handleElementNode(node);
660 if (isCharacterData(node)) 663 if (isCharacterData(node))
661 return this.handleCharacterData(node); 664 return this.handleCharacterData(node);
662 throw new Error(`Unexpected node ${node}`); 665 throw new Error(`Unexpected node ${node}`);
663 } 666 }
664 } 667 }
665 668
666 /** 669 /**
670 * @param {!HTMLElement} element
671 * @return {number}
672 */
673 function computeLeft(element) {
674 let left = kOffsetLeftOfBodyInIFrame;
675 for (let runner = element; runner; runner = runner.offsetParent)
676 left += runner.offsetLeft;
677 return left;
678 }
679
680 /**
681 * @param {!HTMLElement} element
682 * @return {number}
683 */
684 function computeTop(element) {
685 let top = kOffsetTopOfBodyInIFrame;
686 for (let runner = element; runner; runner = runner.offsetParent)
687 top += runner.offsetTop;
688 return top;
689 }
690
691 /**
667 * @this {!DOMSelection} 692 * @this {!DOMSelection}
668 * @param {string} html 693 * @param {string} html
669 * @param {string=} opt_text 694 * @param {string=} opt_text
670 */ 695 */
671 function setClipboardData(html, opt_text) { 696 function setClipboardData(html, opt_text) {
672 assert_not_equals(window.internals, undefined, 697 assert_not_equals(window.internals, undefined,
673 'This test requests clipboard access from JavaScript.'); 698 'This test requests clipboard access from JavaScript.');
674 function computeTextData() { 699 function computeTextData() {
675 if (opt_text !== undefined) 700 if (opt_text !== undefined)
676 return opt_text; 701 return opt_text;
(...skipping 28 matching lines...) Expand all
705 730
706 // Set focus to sample IFRAME to make |eventSender| and 731 // Set focus to sample IFRAME to make |eventSender| and
707 // |testRunner.execCommand()| to work on sample rather than main frame. 732 // |testRunner.execCommand()| to work on sample rather than main frame.
708 this.iframe_.focus(); 733 this.iframe_.focus();
709 /** @const @type {!Selection} */ 734 /** @const @type {!Selection} */
710 this.selection_ = this.iframe_.contentWindow.getSelection(); 735 this.selection_ = this.iframe_.contentWindow.getSelection();
711 this.selection_.document = this.document_; 736 this.selection_.document = this.document_;
712 this.selection_.document.offsetLeft = this.iframe_.offsetLeft; 737 this.selection_.document.offsetLeft = this.iframe_.offsetLeft;
713 this.selection_.document.offsetTop = this.iframe_.offsetTop; 738 this.selection_.document.offsetTop = this.iframe_.offsetTop;
714 this.selection_.setClipboardData = setClipboardData; 739 this.selection_.setClipboardData = setClipboardData;
740 this.selection_.computeLeft = computeLeft;
741 this.selection_.computeTop = computeTop;
715 this.load(sampleText); 742 this.load(sampleText);
716 } 743 }
717 744
718 /** @return {!HTMLDocument} */ 745 /** @return {!HTMLDocument} */
719 get document() { return this.document_; } 746 get document() { return this.document_; }
720 747
721 /** @return {!Selection} */ 748 /** @return {!Selection} */
722 get selection() { return this.selection_; } 749 get selection() { return this.selection_; }
723 750
724 /** 751 /**
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 throw new Error(`${description}\n` + 957 throw new Error(`${description}\n` +
931 `\t expected ${expectedText},\n` + 958 `\t expected ${expectedText},\n` +
932 `\t but got ${actualText},\n` + 959 `\t but got ${actualText},\n` +
933 `\t sameupto ${commonPrefixOf(expectedText, actualText)}`); 960 `\t sameupto ${commonPrefixOf(expectedText, actualText)}`);
934 } 961 }
935 962
936 // Export symbols 963 // Export symbols
937 window.Sample = Sample; 964 window.Sample = Sample;
938 window.assert_selection = assertSelection; 965 window.assert_selection = assertSelection;
939 })(); 966 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698