~ubuntu-branches/ubuntu/trusty/xiphos/trusty

« back to all changes in this revision

Viewing changes to src/geckowin/FixFocus.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Dmitrijs Ledkovs, Jonathan Marsden, Dmitrijs Ledkovs
  • Date: 2010-11-25 21:26:48 UTC
  • mfrom: (2.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20101125212648-mc64wvs0nw3xp7bx
Tags: 3.1.4-1
[ Jonathan Marsden ]
* New upstream release 3.1.4
* Removed debian/patch/* since the one patch was included upstream.
* Bumped Standards-Version to 3.9.1 (no changes required).
* debian/README.Debian: Corrected spelling and reworded for clarity.
* debian/control: Add Jonathan Marsden back into Uploaders.

[ Dmitrijs Ledkovs ]
* Added local options dpkg-source to unapply patches and fail on
  upstream source changes (ignoring false positives).
* Added bzr-builddeb hook to generate source-format before build. If you
  are not using bzr-builddeb, you must run "./debian/rules clean" before
  building.
* patches/xul-2.0.patch: bump UPPER_RANGE to allow running against xul20.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Miro - an RSS based video player application
 
3
 * Copyright (C) 2005-2009 Participatory Culture Foundation
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
18
 *
 
19
 * In addition, as a special exception, the copyright holders give
 
20
 * permission to link the code of portions of this program with the OpenSSL
 
21
 * library.
 
22
 *
 
23
 * You must obey the GNU General Public License in all respects for all of
 
24
 * the code used other than OpenSSL. If you modify file(s) with this
 
25
 * exception, you may extend this exception to your version of the file(s),
 
26
 * but you are not obligated to do so. If you do not wish to do so, delete
 
27
 * this exception statement from your version. If you delete this exception
 
28
 * statement from all source files in the program, then also delete it here.
 
29
**/
 
30
 
 
31
#include "windows.h"
 
32
#include "gtk/gtk.h"
 
33
#include "gdk/gdk.h"
 
34
 
 
35
#include <stdio.h>
 
36
 
 
37
/* FixFocus.cpp
 
38
 *
 
39
 * Fix focus problems between GTK and XULRunner.  GTK likes to keep it's
 
40
 * top-level window focused and handle which widget is focused internally.
 
41
 * XULRunner just let's child windows get focus.
 
42
 *
 
43
 */
 
44
 
 
45
 
 
46
/*
 
47
 * Override the Window proc for top-level GTK windows that contain an embedded
 
48
 * XULRunnerBrowser.  This is needed because GTK's focus model is much
 
49
 * different than XULRunner's.
 
50
 */
 
51
LRESULT CALLBACK ToplevelFocusHackWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
 
52
        LPARAM lParam)
 
53
{
 
54
    GdkWindow* window = gdk_window_lookup((GdkNativeWindow)hwnd);
 
55
    WNDPROC old_window_proc = (WNDPROC)GetProp(hwnd,
 
56
            "ToplevelFocusHackOldProc");
 
57
    if (!window) {
 
58
        if (!old_window_proc) {
 
59
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
 
60
        } else {
 
61
            return CallWindowProc(old_window_proc, hwnd, uMsg, wParam, lParam);
 
62
        }
 
63
    }
 
64
 
 
65
    switch (uMsg) {
 
66
        case WM_MOUSEACTIVATE:
 
67
            // Mouse click on a non-browser widget.  Ensure that the top-level
 
68
            // window has the keyboard focus.
 
69
            // (We know it can't be a browser widget, because we handle
 
70
            // WM_MOUSEACTIVATE in BrowserFocusHackWndProc()).
 
71
            gdk_window_focus(window, 0);
 
72
            return MA_NOACTIVATE;
 
73
 
 
74
        case WM_KILLFOCUS:
 
75
            // GTK's toplevel window is losing focus to a child window.
 
76
            // This is probably a XULRunner window.  Handle the event so that
 
77
            // the window doesn't think it's lost focus.
 
78
            if (wParam && IsChild(hwnd, (HWND)wParam)) {
 
79
                return 0;
 
80
            }
 
81
            break;
 
82
 
 
83
        case WM_DESTROY:
 
84
        case WM_NCDESTROY:
 
85
            // The Window is about to be destroyed -- Cleanup
 
86
            SetWindowLongPtr(hwnd, GWL_WNDPROC, (LONG_PTR)old_window_proc);
 
87
            RemoveProp(hwnd, "ToplevelFocusHackOldProc");
 
88
            break;
 
89
    }
 
90
    return CallWindowProc(old_window_proc, hwnd, uMsg, wParam, lParam);
 
91
}
 
92
 
 
93
LRESULT CALLBACK BrowserFocusHackWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
 
94
        LPARAM lParam)
 
95
{
 
96
    HWND parent;
 
97
    WNDPROC old_window_proc  = (WNDPROC)GetProp(hwnd,
 
98
            "BrowserFocusHackOldProc");
 
99
    if (!old_window_proc) {
 
100
        return DefWindowProc(hwnd, uMsg, wParam, lParam);
 
101
    }
 
102
    switch (uMsg) {
 
103
        case WM_MOUSEACTIVATE:
 
104
            // The user clicked on a xulrunner browser.  Have the GTK widget
 
105
            // grab focus.
 
106
 
 
107
            // NOTE: the window that we are handling messages for is the child
 
108
            // ofthe actual GTK widget.  See browser.py for info on why this
 
109
            // is.
 
110
            parent = GetParent(hwnd);
 
111
            GdkWindow* window;
 
112
            window = gdk_window_lookup((GdkNativeWindow)parent);
 
113
            if (window) {
 
114
                GtkWidget* browser_widget;
 
115
                gdk_window_get_user_data(window, (gpointer*)&browser_widget);
 
116
                if (browser_widget) {
 
117
                    gtk_widget_grab_focus(browser_widget);
 
118
                }
 
119
            }
 
120
            return MA_ACTIVATE;
 
121
            break;
 
122
        case WM_NCDESTROY:
 
123
            // The Window is about to be destroyed -- Cleanup
 
124
            SetWindowLongPtr(hwnd, GWL_WNDPROC, (LONG_PTR)old_window_proc);
 
125
            RemoveProp(hwnd, "BrowserFocusHackOldProc");
 
126
            break;
 
127
    }
 
128
    return CallWindowProc(old_window_proc, hwnd, uMsg, wParam, lParam);
 
129
}
 
130
 
 
131
static void install_toplevel_focus_fix(HWND hwnd)
 
132
{
 
133
    HWND root_window = GetAncestor(hwnd, GA_ROOT);
 
134
    if (GetProp(root_window, "ToplevelFocusHackOldProc") != NULL) {
 
135
        /* We already installed the fix, maybe there are 2 browser's
 
136
         * embedded? */
 
137
        return;
 
138
    }
 
139
    WNDPROC old_proc = (WNDPROC) SetWindowLongPtr(root_window,
 
140
                GWL_WNDPROC, (LONG_PTR)ToplevelFocusHackWndProc);
 
141
    SetProp(root_window,"ToplevelFocusHackOldProc", (void *)old_proc);
 
142
}
 
143
 
 
144
 
 
145
static void install_browser_focus_fix(HWND hwnd)
 
146
{
 
147
 
 
148
    WNDPROC old_proc = (WNDPROC) SetWindowLongPtr(hwnd,
 
149
                GWL_WNDPROC, (LONG_PTR)BrowserFocusHackWndProc);
 
150
    SetProp(hwnd, "BrowserFocusHackOldProc", (HANDLE)old_proc);
 
151
}
 
152
 
 
153
void install_focus_fixes(HWND hwnd)
 
154
{
 
155
    install_toplevel_focus_fix(hwnd);
 
156
    install_browser_focus_fix(hwnd);
 
157
}