From dfd6a47db324eca850d36c81437e09512ebe450c Mon Sep 17 00:00:00 2001 From: "silver%warwickcompsoc.co.uk" Date: Tue, 9 Sep 2008 18:43:01 +0000 Subject: [PATCH] Bug 384694 - Wrap up find code to fire events before/after, so we can correct the scrolling to be more sensible (i.e. avoiding the header). r=gijs ChatZilla only. git-svn-id: svn://10.0.0.236/trunk@254132 18797224-902f-48f8-a5cc-f745e15eee43 --- .../extensions/irc/xul/content/handlers.js | 11 ++++++ .../irc/xul/content/output-window.js | 17 +++++++--- mozilla/extensions/irc/xul/content/static.js | 34 +++++++++++++++++++ 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/mozilla/extensions/irc/xul/content/handlers.js b/mozilla/extensions/irc/xul/content/handlers.js index 2aae3f2928e..fa21019f995 100644 --- a/mozilla/extensions/irc/xul/content/handlers.js +++ b/mozilla/extensions/irc/xul/content/handlers.js @@ -826,6 +826,17 @@ function onUserDoubleClick(event) dispatch("query", {nickname: nickname, source: "mouse"}); } +client.onFindEnd = +CIRCNetwork.prototype.onFindEnd = +CIRCChannel.prototype.onFindEnd = +CIRCUser.prototype.onFindEnd = +CIRCDCCChat.prototype.onFindEnd = +CIRCDCCFileTransfer.prototype.onFindEnd = +function this_onfindend(e) +{ + this.scrollToElement("selection", "inview"); +} + CIRCChannel.prototype._updateConferenceMode = function my_updateconfmode() { diff --git a/mozilla/extensions/irc/xul/content/output-window.js b/mozilla/extensions/irc/xul/content/output-window.js index 7ed19e2af2a..55698abc66f 100644 --- a/mozilla/extensions/irc/xul/content/output-window.js +++ b/mozilla/extensions/irc/xul/content/output-window.js @@ -204,7 +204,7 @@ function startTopicEdit() { var me = view.getUser(view.parent.me.unicodeName); if (!me || (!view.mode.publicTopic && !me.isOp && !me.isHalfOp) || - !header["topicinput"].hasAttribute("hidden")) + !hasAttribute("topicinput", "hidden")) { return; } @@ -221,7 +221,7 @@ function startTopicEdit() function cancelTopicEdit(force) { var originalTopic = mainWindow.decodeColorCodes(view.topic); - if (!header["topicnodes"].hasAttribute("hidden") || + if (!hasAttribute("topicnodes", "hidden") || (!force && (header["topicinput"].value != originalTopic))) { return; @@ -322,8 +322,15 @@ function scrollToElement(element, position) bottom: window.innerHeight }; if (!hasAttribute("container", "hidden")) { - cont.top += header["container"].offsetHeight; - cont.center += header["container"].offsetHeight / 2; + /* Offset height doesn't include the margins, so we get to do that + * ourselves via getComputedStyle(). We're assuming that will return + * a px value, which is all but guaranteed. + */ + var headerHeight = header["container"].offsetHeight; + var css = getComputedStyle(header["container"], null); + headerHeight += parseInt(css.marginTop) + parseInt(css.marginBottom); + cont.top += headerHeight; + cont.center += headerHeight / 2; } // Pick between 'top' and 'bottom' for 'inview' position. @@ -419,7 +426,7 @@ function removeAttribute(field, name) function hasAttribute(field, name) { - header[field].hasAttribute(name); + return header[field].hasAttribute(name); } function setHeaderState(state) diff --git a/mozilla/extensions/irc/xul/content/static.js b/mozilla/extensions/irc/xul/content/static.js index ba5a0e0370f..3fa21fc6a78 100644 --- a/mozilla/extensions/irc/xul/content/static.js +++ b/mozilla/extensions/irc/xul/content/static.js @@ -601,11 +601,45 @@ function initInstrumentation() function getFindData(e) { + // findNext() wrapper to add our findStart/findEnd events. + function _cz_findNext() { + // Send start notification. + var ev = new CEvent("find", "findStart", e.sourceObject, "onFindStart"); + client.eventPump.routeEvent(ev); + + // Call the original findNext() and keep the result for later. + var rv = this.__proto__.findNext(); + + // Send end notification with result code. + var ev = new CEvent("find", "findEnd", e.sourceObject, "onFindEnd"); + ev.findResult = rv; + client.eventPump.routeEvent(ev); + + // Return the original findNext()'s result to keep up appearances. + return rv; + }; + + // Getter for webBrowserFind property. + function _cz_webBrowserFind() { + return this._cz_wbf; + }; + var findData = new nsFindInstData(); findData.browser = e.sourceObject.frame; findData.rootSearchWindow = getContentWindow(e.sourceObject.frame); findData.currentSearchWindow = getContentWindow(e.sourceObject.frame); + /* Wrap up the webBrowserFind object so we get called for findNext(). Use + * __proto__ so that everything else is exactly like the original object. + */ + findData._cz_wbf = { findNext: _cz_findNext }; + findData._cz_wbf.__proto__ = findData.webBrowserFind; + + /* Replace the nsFindInstData getter for webBrowserFind to call our + * function which in turn returns our object (_cz_wbf). + */ + findData.__defineGetter__("webBrowserFind", _cz_webBrowserFind); + /* Yay, evil hacks! findData.init doesn't care about the findService, it * gets option settings from webBrowserFind. As we want the wrap option *on* * when we use /find foo, we set it on the findService there. However,