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
This commit is contained in:
silver%warwickcompsoc.co.uk 2008-09-09 18:43:01 +00:00
parent 244f7f7115
commit dfd6a47db3
3 changed files with 57 additions and 5 deletions

View File

@ -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()
{

View File

@ -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)

View File

@ -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,