unfocus command rewrite

View: New views
3 Messages — Rating Filter:   Alert me  

unfocus command rewrite

by John J. Foerch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

  I would appreciate some review and testing of the following rewrite
of the unfocus command.  I think unfocus it needs a rewrite because
the current implementation is both inconsistent and unreliable in the
following ways:

 * you have to call it twice to regain focus from a plugin

 * it doesn't work if the currently focused element has been removed
   from the document via javascript.

 * it cannot unfocus an iframe or frameset-frame (I think it should)

 * it cannot deselect text inside an iframe or frameset-frame.


  That said, I do want to say that the re-implementation below was
arrived at more through empiricism than through a thorough
understanding of Mozilla's focus system.  I also cannot claim that I
have necessarily thought of every possibility for how the command
should behave, so I welcome comments.  If there are none within a day
or two, I will go ahead and commit.  So here's the code:

///////////// begin
function unfocus (window, buffer) {
    // 1. if there is a focused element, unfocus it.
    if (buffer.focused_element) {
        buffer.focused_element.blur();
        // if an element in a detached fragment has focus, blur() will not
        // work, and we need to take more drastic measures.
        if (buffer.focused_element) {
            buffer.element.focus();
            buffer.top_frame.focus();
        }
        window.minibuffer.message("unfocused element");
        return;
    }
    // 2. if there is a selection, clear it.
    selc = getFocusedSelCtrl(buffer);
    if (selc && selc.getSelection(selc.SELECTION_NORMAL).isCollapsed == false) {
        clear_selection(buffer);
        window.minibuffer.message("cleared selection");
        return;
    }
    // 3. return focus to top-frame from subframes and plugins.
    var win = buffer.focused_frame;
    buffer.top_frame.focus();
    buffer.top_frame.focus(); // needed to get focus back from plugins
    window.minibuffer.message("focused top frame");
}
interactive("unfocus", null, function (I) {
    unfocus(I.window, I.buffer);
});
///////////// end

Thanks!

--
John Foerch
_______________________________________________
Conkeror mailing list
Conkeror@...
https://www.mozdev.org/mailman/listinfo/conkeror

Re: unfocus command rewrite

by John J. Foerch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I pushed the rewrite of the unfocus command.  Not exactly the code I
sent in my last message, because there were a couple of small things
that needed to be changed.

--
John Foerch
_______________________________________________
Conkeror mailing list
Conkeror@...
https://www.mozdev.org/mailman/listinfo/conkeror

Re: unfocus command rewrite

by John J. Foerch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

After using the new unfocus command for a little while, it seemed more
natural for clearing selection to have higher precedence than
unfocus-element.  Others agreed so I pushed that change.

--
John Foerch
_______________________________________________
Conkeror mailing list
Conkeror@...
https://www.mozdev.org/mailman/listinfo/conkeror