From a0df9249436690bdbf51ab4b965eb597f6417ca3 Mon Sep 17 00:00:00 2001 From: piro Date: Mon, 23 Nov 2009 16:11:30 +0000 Subject: [PATCH] =?UTF-8?q?=E9=81=B8=E6=8A=9E=E7=AF=84=E5=9B=B2=E3=81=AE?= =?UTF-8?q?=E3=83=AA=E3=83=B3=E3=82=AF=E3=82=92=E3=82=BF=E3=83=96=E3=81=A7?= =?UTF-8?q?=E9=96=8B=E3=81=8F=E6=A9=9F=E8=83=BD=E3=82=92=E5=BB=83=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@5483 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/config.xul | 6 - content/treestyletab/treestyletab.js | 152 +--------------- content/treestyletab/treestyletab.xul | 10 - defaults/preferences/treestyletab.js | 1 - locale/de-DE/treestyletab/treestyletab.dtd | 3 - locale/en-US/treestyletab/treestyletab.dtd | 3 - locale/es-ES/treestyletab/treestyletab.dtd | 4 - locale/it-IT/treestyletab/treestyletab.dtd | 4 - locale/ja/treestyletab/treestyletab.dtd | 4 - locale/pl-PL/treestyletab/treestyletab.dtd | 4 - locale/ru-RU/treestyletab/treestyletab.dtd | 4 - locale/zh-CN/treestyletab/treestyletab.dtd | 3 - locale/zh-TW/treestyletab/treestyletab.dtd | 4 - tests/unit/treestyletab_linkUtils.test.js | 202 --------------------- 14 files changed, 6 insertions(+), 398 deletions(-) delete mode 100644 tests/unit/treestyletab_linkUtils.test.js diff --git a/content/treestyletab/config.xul b/content/treestyletab/config.xul index 64b52d2c..98cd40f1 100644 --- a/content/treestyletab/config.xul +++ b/content/treestyletab/config.xul @@ -190,9 +190,6 @@ - @@ -264,9 +261,6 @@ label="&context.bookmarkTabSubTree.label;"/> - diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js index 5bc34c9d..17c53b08 100644 --- a/content/treestyletab/treestyletab.js +++ b/content/treestyletab/treestyletab.js @@ -396,7 +396,7 @@ var TreeStyleTabService = { null ; }, - readyToOpenDivertedTab : function(aFrameOrTabBrowser) + readyToOpenDivertedTab : function(aFrameOrTabBrowser) { var frame = this.getFrameFromTabBrowserElements(aFrameOrTabBrowser); if (!frame) return; @@ -1436,7 +1436,6 @@ var TreeStyleTabService = { window.removeEventListener('load', this, false); window.addEventListener('unload', this, false); - document.getElementById('contentAreaContextMenu').addEventListener('popupshowing', this, false); document.addEventListener('popupshowing', this, false); document.addEventListener('popuphiding', this, false); @@ -2080,7 +2079,6 @@ catch(e) { this.endListenKeyEventsFor(this.LISTEN_FOR_AUTOHIDE); this.endListenKeyEventsFor(this.LISTEN_FOR_AUTOEXPAND_BY_FOCUSCHANGE); - document.getElementById('contentAreaContextMenu').removeEventListener('popupshowing', this, false); document.removeEventListener('popupshowing', this, false); document.removeEventListener('popuphiding', this, false); @@ -2123,10 +2121,6 @@ catch(e) { return; case 'popupshowing': - if (aEvent.currentTarget.id == 'contentAreaContextMenu' && - aEvent.target == aEvent.currentTarget) { - this.initContextMenu(); - } if (!this.evaluateXPath( 'local-name() = "tooltip" or local-name() ="panel" or '+ 'parent::*/ancestor-or-self::*[local-name()="popup" or local-name()="menupopup"]', @@ -2326,20 +2320,6 @@ catch(e) { ).booleanValue; }, - initContextMenu : function() - { - var item = document.getElementById('context-treestyletab-openSelectionLinks'); - var sep = document.getElementById('context-treestyletab-openSelectionLinks-separator'); - if (this.getTreePref('show.openSelectionLinks') && this.getSelectionLinks().length) { - item.removeAttribute('hidden'); - sep.removeAttribute('hidden'); - } - else { - item.setAttribute('hidden', true); - sep.setAttribute('hidden', true); - } - }, - showHideSubTreeMenuItem : function(aMenuItem, aTabs) { if (!aMenuItem || @@ -2561,7 +2541,8 @@ catch(e) { } }, 0, this); }, - canCreateSubTree : function(aTabs) + + canCreateSubTree : function(aTabs) { aTabs = this.getRootTabs(aTabs); if (aTabs.length < 2) return false; @@ -2575,7 +2556,8 @@ catch(e) { } return this.getChildTabs(lastParent).length != aTabs.length; }, - getRootTabs : function(aTabs) + + getRootTabs : function(aTabs) { var roots = []; if (!aTabs || !aTabs.length) return roots; @@ -2587,129 +2569,7 @@ catch(e) { }, this); return roots; }, - - openSelectionLinks : function(aFrame) - { - aFrame = this.getCurrentFrame(aFrame); - - var b = this.browser; - var links = this.getSelectionLinks(aFrame); - if (!links.length) return; - - var referrer = this.makeURIFromSpec(aFrame.location.href); - - this.readyToOpenChildTab(aFrame, true); - links.forEach(function(aLink, aIndex) { - var tab = b.addTab(aLink.href, referrer); - if (aIndex == 0 && !this.getPref('browser.tabs.loadInBackground')) - b.selectedTab = tab; - }, this); - this.stopToOpenChildTab(aFrame); - }, - - getCurrentFrame : function(aFrame) - { - if (aFrame) return aFrame; - var targetWindow = document.commandDispatcher.focusedWindow; - if (!targetWindow || targetWindow.top == window) - targetWindow = this.browser.contentWindow; - return targetWindow; - }, - - getSelectionLinks : function(aFrame) - { - aFrame = this.getCurrentFrame(aFrame); - - var links = []; - - var selection = aFrame.getSelection(); - if (!selection || !selection.rangeCount) - return links; - - for (var i = 0, maxi = selection.rangeCount; i < maxi; i++) - { - links = links.concat(this.getLinksInRange(selection.getRangeAt(i))); - } - - var visited = {}; - var uniqueLinks = []; - links.forEach(function(aLink) { - if (aLink.href in visited) return; - visited[aLink.href] = true; - uniqueLinks.push(aLink); - }); - return uniqueLinks; - }, - - getLinksInRange : function(aRange) - { - // http://nanto.asablo.jp/blog/2008/10/18/3829312 - var links = []; - if (aRange.collapsed) return links; - - var startCountExpression = 'count(preceding::*[@href])'; - var startNode = aRange.startContainer; - if (startNode.nodeType == Node.ELEMENT_NODE) { - if (aRange.startOffset < startNode.childNodes.length) { - startNode = startNode.childNodes[aRange.startOffset]; - } - else { - startCountExpression += ' + count(descendant::*[@href])'; - } - } - var startCount = this.evaluateXPath( - startCountExpression, - startNode, - XPathResult.NUMBER_TYPE - ).numberValue; - - var linksExpression = 'ancestor::*[@href] | preceding::*[@href]'; - var endNode = aRange.endContainer; - if (endNode.nodeType == Node.ELEMENT_NODE) { - if (aRange.endOffset < endNode.childNodes.length) { - endNode = endNode.childNodes[aRange.endOffset]; - } - else { - linksExpression += ' | descendant-or-self::*[@href]'; - } - } - var linksResult = this.evaluateXPath(linksExpression, endNode); - - var allLinksCount = linksResult.snapshotLength; - var contentRange = startNode.ownerDocument.createRange(); - if (startCount < allLinksCount) { - var lastNode = this.evaluateXPath( - 'descendant-or-self::node()[not(child::node()) and not(following-sibling::node())]', - linksResult.snapshotItem(startCount), - XPathResult.FIRST_ORDERED_NODE_TYPE - ).singleNodeValue; - contentRange.selectNodeContents(lastNode); - contentRange.setStart(aRange.startContainer, aRange.startOffset); - if (contentRange.collapsed) { - startCount++; - } - } - if (startCount < allLinksCount) { - var firstNode = this.evaluateXPath( - 'descendant-or-self::node()[not(child::node()) and not(preceding-sibling::node())]', - linksResult.snapshotItem(allLinksCount-1), - XPathResult.FIRST_ORDERED_NODE_TYPE - ).singleNodeValue; - contentRange.selectNodeContents(firstNode); - contentRange.setEnd(aRange.endContainer, aRange.endOffset); - if (contentRange.collapsed) { - allLinksCount--; - } - } - contentRange.detach(); - - for (var i = startCount; i < allLinksCount; i++) - { - links.push(linksResult.snapshotItem(i)); - } - return links; - }, - + collapseExpandAllSubtree : function(aCollapse) { this.ObserverService.notifyObservers( diff --git a/content/treestyletab/treestyletab.xul b/content/treestyletab/treestyletab.xul index b3625638..f8ccd414 100644 --- a/content/treestyletab/treestyletab.xul +++ b/content/treestyletab/treestyletab.xul @@ -39,16 +39,6 @@ ]]> - - - - - - - diff --git a/locale/en-US/treestyletab/treestyletab.dtd b/locale/en-US/treestyletab/treestyletab.dtd index b4e8cd4e..518b2194 100644 --- a/locale/en-US/treestyletab/treestyletab.dtd +++ b/locale/en-US/treestyletab/treestyletab.dtd @@ -37,7 +37,6 @@ - @@ -152,8 +151,6 @@ - - diff --git a/locale/es-ES/treestyletab/treestyletab.dtd b/locale/es-ES/treestyletab/treestyletab.dtd index 43fab394..5e344c79 100644 --- a/locale/es-ES/treestyletab/treestyletab.dtd +++ b/locale/es-ES/treestyletab/treestyletab.dtd @@ -37,7 +37,6 @@ - @@ -156,9 +155,6 @@ - - - diff --git a/locale/it-IT/treestyletab/treestyletab.dtd b/locale/it-IT/treestyletab/treestyletab.dtd index 15e74968..7be6399e 100644 --- a/locale/it-IT/treestyletab/treestyletab.dtd +++ b/locale/it-IT/treestyletab/treestyletab.dtd @@ -37,7 +37,6 @@ - @@ -156,9 +155,6 @@ - - - diff --git a/locale/ja/treestyletab/treestyletab.dtd b/locale/ja/treestyletab/treestyletab.dtd index 2041365a..f6c2ef4d 100644 --- a/locale/ja/treestyletab/treestyletab.dtd +++ b/locale/ja/treestyletab/treestyletab.dtd @@ -37,7 +37,6 @@ - @@ -151,9 +150,6 @@ - - - diff --git a/locale/pl-PL/treestyletab/treestyletab.dtd b/locale/pl-PL/treestyletab/treestyletab.dtd index 4c5e48cf..1faee0c5 100644 --- a/locale/pl-PL/treestyletab/treestyletab.dtd +++ b/locale/pl-PL/treestyletab/treestyletab.dtd @@ -37,7 +37,6 @@ - @@ -155,9 +154,6 @@ - - - diff --git a/locale/ru-RU/treestyletab/treestyletab.dtd b/locale/ru-RU/treestyletab/treestyletab.dtd index cc89097e..5c36cbd6 100755 --- a/locale/ru-RU/treestyletab/treestyletab.dtd +++ b/locale/ru-RU/treestyletab/treestyletab.dtd @@ -37,7 +37,6 @@ - @@ -155,9 +154,6 @@ - - - diff --git a/locale/zh-CN/treestyletab/treestyletab.dtd b/locale/zh-CN/treestyletab/treestyletab.dtd index 36f19e2c..9c8a9d2c 100644 --- a/locale/zh-CN/treestyletab/treestyletab.dtd +++ b/locale/zh-CN/treestyletab/treestyletab.dtd @@ -37,7 +37,6 @@ - @@ -152,8 +151,6 @@ - - diff --git a/locale/zh-TW/treestyletab/treestyletab.dtd b/locale/zh-TW/treestyletab/treestyletab.dtd index cc4b5f7c..20b7ee79 100644 --- a/locale/zh-TW/treestyletab/treestyletab.dtd +++ b/locale/zh-TW/treestyletab/treestyletab.dtd @@ -37,7 +37,6 @@ - @@ -153,9 +152,6 @@ - - - diff --git a/tests/unit/treestyletab_linkUtils.test.js b/tests/unit/treestyletab_linkUtils.test.js deleted file mode 100644 index 78dff776..00000000 --- a/tests/unit/treestyletab_linkUtils.test.js +++ /dev/null @@ -1,202 +0,0 @@ -var win; -var sv; - -function setUp() -{ - utils.setPref('browser.tabs.warnOnClose', false); - - yield utils.setUpTestWindow(); - win = utils.getTestWindow(); - sv = win.TreeStyleTabService; - - yield Do(utils.addTab('../fixtures/links.html')); - var tabs = gBrowser.mTabs; - gBrowser.removeAllTabsBut(tabs[tabs.length-1]); - assert.equals(1, tabs.length); -} - -function tearDown() -{ - win = null; - utils.tearDownTestWindow(); -} - -function $(aId) -{ - return content.document.getElementById(aId); -} - -function test_getCurrentFrame() -{ - yield Do(utils.addTab('../fixtures/frameTest.html')); - yield Do(utils.addTab('../fixtures/frameTestInline.html')); - var tabs = gBrowser.mTabs; - assert.equals(3, tabs.length); - - var frame; - - frame = gBrowser.contentWindow; - assert.equals(frame, sv.getCurrentFrame()); - assert.equals(frame, sv.getCurrentFrame(frame)); - - frame = tabs[1].linkedBrowser.contentWindow.frames[1]; - assert.equals(frame, sv.getCurrentFrame(frame)); - - frame = tabs[2].linkedBrowser.contentWindow.frames[0]; - assert.equals(frame, sv.getCurrentFrame(frame)); -} - -function test_getLinksInRange() -{ - var range = content.document.createRange(); - - range.setStartBefore($('item2')); - range.setEndAfter($('item4')); - assert.equals( - [$('link2'), $('link3'), $('link4')], - sv.getLinksInRange(range) - ); - - range.setStartBefore($('link2')); - range.setEndAfter($('link4')); - assert.equals( - [$('link2'), $('link3'), $('link4')], - sv.getLinksInRange(range) - ); - - range.setStartBefore($('em2')); - range.setEndAfter($('em4')); - assert.equals( - [$('link2'), $('link3'), $('link4')], - sv.getLinksInRange(range) - ); - - range.setStart($('em2').firstChild, 2); - range.setEnd($('em4').firstChild, 2); - assert.equals( - [$('link2'), $('link3'), $('link4')], - sv.getLinksInRange(range) - ); - - range.setStartAfter($('em1')); - range.setEndBefore($('em5')); - assert.equals( - [$('link2'), $('link3'), $('link4')], - sv.getLinksInRange(range) - ); - - range.setStartAfter($('em1').firstChild); - range.setEndBefore($('em5').firstChild); - assert.equals( - [$('link2'), $('link3'), $('link4')], - sv.getLinksInRange(range) - ); -} - -function test_getSelectionLinks() -{ - var selection = content.getSelection(); - assert.equals(0, selection.rangeCount); - - var range1 = content.document.createRange(); - range1.setStartBefore($('link2')); - range1.setEndAfter($('link4')); - selection.addRange(range1); - - assert.equals(1, selection.rangeCount); - assert.equals( - [$('link2'), $('link3'), $('link4')], - sv.getSelectionLinks(content) - ); - - var range2 = content.document.createRange(); - range2.setStartBefore($('link6')); - range2.setEndAfter($('link8')); - selection.addRange(range2); - - var range3 = content.document.createRange(); - range3.setStartBefore($('link12')); - range3.setEndAfter($('link14')); - selection.addRange(range3); - - assert.equals(3, selection.rangeCount); - assert.equals( - [$('link2'), $('link3'), $('link4'), - $('link6'), $('link7'), $('link8'), - $('link12'), $('link13'), $('link14')], - sv.getSelectionLinks(content) - ); - - selection.removeAllRanges(); - range1.detach(); - range2.detach(); - range3.detach(); -} - -function test_openSelectionLinks() -{ - function assert_openSelectionLinksInFrame(aFrame) - { - function $(aId) - { - return aFrame.document.getElementById(aId); - } - - gBrowser.removeAllTabsBut(gBrowser.selectedTab); - assert.equals(1, gBrowser.mTabs.length); - - var selection = aFrame.getSelection(); - assert.equals(0, selection.rangeCount); - - var range1 = aFrame.document.createRange(); - range1.setStartBefore($('link2')); - range1.setEndAfter($('link4')); - selection.addRange(range1); - assert.equals(1, selection.rangeCount); - - var tabs = gBrowser.mTabs; - assert.equals(1, tabs.length); - - sv.openSelectionLinks(aFrame); - assert.equals(4, tabs.length); - assert.equals( - [tabs[1], tabs[2], tabs[3]], - sv.getChildTabs(tabs[0]) - ); - - gBrowser.removeAllTabsBut(tabs[0]); - assert.equals(1, tabs.length); - - var range2 = aFrame.document.createRange(); - range2.setStartBefore($('link6')); - range2.setEndAfter($('link8')); - selection.addRange(range2); - - var range3 = aFrame.document.createRange(); - range3.setStartBefore($('link12')); - range3.setEndAfter($('link14')); - selection.addRange(range3); - - sv.openSelectionLinks(aFrame); - assert.equals(10, tabs.length); - assert.equals( - [tabs[1], tabs[2], tabs[3], - tabs[4], tabs[5], tabs[6], - tabs[7], tabs[8], tabs[9]], - sv.getChildTabs(tabs[0]) - ); - - selection.removeAllRanges(); - range1.detach(); - range2.detach(); - range3.detach(); - } - - assert_openSelectionLinksInFrame(content); - - yield Do(utils.addTab('../fixtures/frameTest.html', { selected : true })); - assert_openSelectionLinksInFrame(content.frames[2]); - - yield Do(utils.addTab('../fixtures/frameTestInline.html', { selected : true })); - assert_openSelectionLinksInFrame(content.frames[1]); -}