~ubuntu-branches/ubuntu/intrepid/xulrunner-1.9/intrepid

« back to all changes in this revision

Viewing changes to mozilla/embedding/tests/wxEmbed/BrowserFrame.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack, Alexander Sack, Fabien Tassin
  • Date: 2008-02-13 11:47:21 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080213114721-7om0mgzngvuk9czv
Tags: 1.9~b3+nobinonly-0ubuntu1
* release FIREFOX_3_0b3_RELEASE

[ Alexander Sack ]
* submit patch that ships xpcshell to bugzilla
  - rename debian/patches/ship_xpcshell.patch =>
           debian/patches/bz410617_att295212_ship_xpcshell.patch
  - update debian/patches/series
* fix tooltip in epiphany: previously displayed out of screen bounds
  (LP: #37507)
  - add debian/patches/bz233371_att297343_fix_outofscreen_embed_tooltip.patch
  - update debian/patches/series
* use default upstream gcc tweaks for improved performance - especially of the
  javascript engine
  - update debian/rules
* update global extension/plugin patch to apply cleanly against latest code
  - update debian/patches/bzXXX_gre_extension_plugin_support.patch
* fix pyxpcom build failure introduced by recent commit
  - add debian/patches/bzXXX_fix_pyxpcom_build_failure.patch
  - update debian/patches/series
* add distro independent global install locations for extensions,
  /usr/lib/mozilla/extensions and /usr/share/mozilla/extensions
  - update debian/xulrunner-1.9.dirs
* support embedded tarball layout when either there is a *.tar.bz2 in orig tarball
  or if DEBIAN_MOZCLIENT_EMBEDDED is not unset (you will need this to produce embedded
  tarballs during |get-orig-source|
  - update debian/rules
* bump minimum libnss3-dev build requirements to >= 3.12.0~1.9b3
  - update debian/control
* bump minimum libnspr4-dev build requirements to >= 4.7.0~1.9b3
  - update debian/control

[ Fabien Tassin ]
* Drop patches applied upstream
  - drop debian/patches/bz410617_att295212_ship_xpcshell.patch
  - drop debian/patches/bz404634_att294921.patch
  - drop debian/patches/bz386610_python2.5_ftbfs_amd64.patch
  - drop debian/patches/bz373918_att295042.patch
  - drop debian/patches/bz408062_unstable_pc.patch
  - drop debian/patches/bz384304_fix_recursive_symlinks.patch
  - update debian/patches/series
* Refresh diverged patches:
  - update debian/patches/bzXXX_pc_honour_system_nspr_nss.patch
  - update debian/patches/rename_venkman_addon.patch
  - update debian/patches/bz344818_cairo_xrender.patch
* Install links for all .so libs in the -dev package
  - update debian/patches/dont_install_so_in_dev.patch
* Bump gtk requirement to 2.12 as per Mozilla bug 412432
  - update debian/control
* Add #DEBHELPER# token to postinst/prerm scripts
  - update debian/xulrunner-1.9.{postinst,prerm}
* Install previously missed libdbusservice.so
  - update debian/xulrunner-1.9.install
* Update venkman patch to also rename locales
  - update debian/patches/rename_venkman_addon.patch
* Bump requirement for system cairo to >= 1.5.8 as we now need
  the newly added cairo_path_extents()
  - update debian/rules
* Include mozilla-devscripts file using -include so ifneq could be omitted
  - update debian/rules
* Fix missing .so symlinks regression
  - update debian/patches/dont_install_so_in_dev.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ***** BEGIN LICENSE BLOCK *****
2
 
 * Version: Mozilla-sample-code 1.0
3
 
 *
4
 
 * Copyright (c) 2002 Netscape Communications Corporation and
5
 
 * other contributors
6
 
 *
7
 
 * Permission is hereby granted, free of charge, to any person obtaining a
8
 
 * copy of this Mozilla sample software and associated documentation files
9
 
 * (the "Software"), to deal in the Software without restriction, including
10
 
 * without limitation the rights to use, copy, modify, merge, publish,
11
 
 * distribute, sublicense, and/or sell copies of the Software, and to permit
12
 
 * persons to whom the Software is furnished to do so, subject to the
13
 
 * following conditions:
14
 
 *
15
 
 * The above copyright notice and this permission notice shall be included
16
 
 * in all copies or substantial portions of the Software.
17
 
 *
18
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
 
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21
 
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
 
 * DEALINGS IN THE SOFTWARE.
25
 
 *
26
 
 * Contributor(s):
27
 
 *
28
 
 * ***** END LICENSE BLOCK ***** */
29
 
 
30
 
#include "global.h"
31
 
 
32
 
#include "wx/strconv.h"
33
 
 
34
 
#include "BrowserFrame.h"
35
 
 
36
 
#include "nsIURI.h"
37
 
 
38
 
BEGIN_EVENT_TABLE(BrowserFrame, GeckoFrame)
39
 
 
40
 
    // View menu
41
 
    EVT_MENU(XRCID("view_pagesource"),  BrowserFrame::OnViewPageSource)
42
 
    EVT_UPDATE_UI(XRCID("view_pagesource"),
43
 
                                        BrowserFrame::OnUpdateViewPageSource)
44
 
 
45
 
    // Browser operations, back / forward etc.
46
 
    // TODO some of these can go in GeckoFrame
47
 
    EVT_MENU(XRCID("browse_back"),      BrowserFrame::OnBrowserBack)
48
 
    EVT_UPDATE_UI(XRCID("browse_back"), BrowserFrame::OnUpdateBrowserBack)
49
 
    EVT_MENU(XRCID("browse_fwd"),       BrowserFrame::OnBrowserForward)
50
 
    EVT_UPDATE_UI(XRCID("browse_fwd"),  BrowserFrame::OnUpdateBrowserForward)
51
 
    EVT_MENU(XRCID("browse_reload"),    BrowserFrame::OnBrowserReload)
52
 
    EVT_MENU(XRCID("browse_stop"),      BrowserFrame::OnBrowserStop)
53
 
    EVT_UPDATE_UI(XRCID("browse_stop"), BrowserFrame::OnUpdateBrowserStop)
54
 
    EVT_MENU(XRCID("browse_home"),      BrowserFrame::OnBrowserHome)
55
 
    EVT_BUTTON(XRCID("browser_go"),     BrowserFrame::OnBrowserGo)
56
 
    EVT_TEXT_ENTER(XRCID("url"),        BrowserFrame::OnBrowserUrl)
57
 
    EVT_MENU(XRCID("browser_open_in_new_window"),
58
 
                                        BrowserFrame::OnBrowserOpenLinkInNewWindow)
59
 
END_EVENT_TABLE()
60
 
 
61
 
BrowserFrame::BrowserFrame(wxWindow* aParent)
62
 
{
63
 
    wxXmlResource::Get()->LoadFrame(this, aParent, wxT("browser_frame"));
64
 
 
65
 
    SetIcon(wxICON(appicon));
66
 
 
67
 
    SetName("browser");
68
 
 
69
 
    SetupDefaultGeckoWindow();
70
 
 
71
 
    CreateStatusBar();
72
 
}
73
 
 
74
 
 
75
 
nsresult BrowserFrame::LoadURI(const wchar_t *aURI)
76
 
{
77
 
    if (mWebBrowser)
78
 
    {
79
 
        nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
80
 
        if (webNav)
81
 
        {
82
 
            return webNav->LoadURI(aURI,
83
 
                    nsIWebNavigation::LOAD_FLAGS_NONE,
84
 
                    nsnull,
85
 
                    nsnull,
86
 
                    nsnull);
87
 
        }
88
 
    }
89
 
    return NS_ERROR_FAILURE;
90
 
}
91
 
 
92
 
 
93
 
nsresult BrowserFrame::LoadURI(const char *aURI)
94
 
{
95
 
    wxMBConv conv;
96
 
    return LoadURI(conv.cWX2WC(aURI));
97
 
}
98
 
 
99
 
 
100
 
///////////////////////////////////////////////////////////////////////////////
101
 
// Browser specific handlers
102
 
 
103
 
 
104
 
void BrowserFrame::OnFileSave(wxCommandEvent & WXUNUSED(event))
105
 
{
106
 
}
107
 
 
108
 
void BrowserFrame::OnFilePrint(wxCommandEvent & WXUNUSED(event))
109
 
{
110
 
}
111
 
 
112
 
void BrowserFrame::OnViewPageSource(wxCommandEvent &event)
113
 
{
114
 
    nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
115
 
    if(!webNav)
116
 
        return;
117
 
 
118
 
    // Get the URI object whose source we want to view.
119
 
    nsresult rv = NS_OK;
120
 
    nsCOMPtr<nsIURI> currentURI;
121
 
    rv = webNav->GetCurrentURI(getter_AddRefs(currentURI));
122
 
    if(NS_FAILED(rv) || !currentURI)
123
 
        return;
124
 
 
125
 
    // Get the uri string associated with the nsIURI object
126
 
    nsCAutoString uriString;
127
 
    rv = currentURI->GetSpec(uriString);
128
 
    if(NS_FAILED(rv))
129
 
        return;
130
 
 
131
 
    // Build the view-source: url
132
 
    nsAutoString viewSrcUrl(L"view-source:");
133
 
    viewSrcUrl.AppendWithConversion(uriString.get());
134
 
 
135
 
    BrowserFrame *frame = new BrowserFrame(NULL);
136
 
    if (frame)
137
 
    {
138
 
        frame->Show(TRUE);
139
 
        frame->LoadURI(viewSrcUrl.get());
140
 
    }
141
 
 
142
 
}
143
 
 
144
 
void BrowserFrame::OnUpdateViewPageSource(wxUpdateUIEvent &event)
145
 
{
146
 
}
147
 
 
148
 
void BrowserFrame::OnBrowserGo(wxCommandEvent & WXUNUSED(event))
149
 
{
150
 
    wxTextCtrl *txtCtrl = (wxTextCtrl *) FindWindowById(XRCID("url"), this);
151
 
    wxString url = txtCtrl->GetValue();
152
 
    if (!url.IsEmpty())
153
 
    {
154
 
        LoadURI(url);
155
 
    }
156
 
}
157
 
 
158
 
void BrowserFrame::OnBrowserUrl(wxCommandEvent & event)
159
 
{
160
 
    OnBrowserGo(event);
161
 
}
162
 
 
163
 
void BrowserFrame::OnBrowserBack(wxCommandEvent & WXUNUSED(event))
164
 
{
165
 
    if (mWebBrowser)
166
 
    {
167
 
        nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
168
 
        webNav->GoBack();
169
 
    }
170
 
}
171
 
 
172
 
void BrowserFrame::OnUpdateBrowserBack(wxUpdateUIEvent &event)
173
 
{
174
 
    PRBool canGoBack = PR_FALSE;
175
 
    if (mWebBrowser)
176
 
    {
177
 
        nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
178
 
        webNav->GetCanGoBack(&canGoBack);
179
 
    }
180
 
    event.Enable(canGoBack ? true : false);
181
 
}
182
 
 
183
 
void BrowserFrame::OnBrowserForward(wxCommandEvent & WXUNUSED(event))
184
 
{
185
 
    if (mWebBrowser)
186
 
    {
187
 
        nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
188
 
        webNav->GoForward();
189
 
    }
190
 
}
191
 
 
192
 
void BrowserFrame::OnUpdateBrowserForward(wxUpdateUIEvent &event)
193
 
{
194
 
    PRBool canGoForward = PR_FALSE;
195
 
    if (mWebBrowser)
196
 
    {
197
 
        nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
198
 
        webNav->GetCanGoForward(&canGoForward);
199
 
    }
200
 
    event.Enable(canGoForward ? true : false);
201
 
}
202
 
 
203
 
void BrowserFrame::OnBrowserReload(wxCommandEvent & WXUNUSED(event))
204
 
{
205
 
    if (mWebBrowser)
206
 
    {
207
 
        nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
208
 
        webNav->Reload(nsIWebNavigation::LOAD_FLAGS_NONE);
209
 
    }
210
 
}
211
 
 
212
 
void BrowserFrame::OnBrowserStop(wxCommandEvent & WXUNUSED(event))
213
 
{
214
 
    if (mWebBrowser)
215
 
    {
216
 
        nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
217
 
        webNav->Stop(nsIWebNavigation::STOP_ALL);
218
 
    }
219
 
}
220
 
 
221
 
void BrowserFrame::OnUpdateBrowserStop(wxUpdateUIEvent &event)
222
 
{
223
 
    event.Enable(mBusy ? true : false);
224
 
}
225
 
 
226
 
void BrowserFrame::OnBrowserHome(wxCommandEvent & WXUNUSED(event))
227
 
{
228
 
    LoadURI("http://www.mozilla.org/projects/embedding/");
229
 
}
230
 
 
231
 
void BrowserFrame::OnBrowserOpenLinkInNewWindow(wxCommandEvent & WXUNUSED(event))
232
 
{
233
 
    BrowserFrame* frame = new BrowserFrame(NULL);
234
 
    frame->Show(TRUE);
235
 
    frame->LoadURI(mContextLinkUrl.get());
236
 
}
237
 
 
238
 
///////////////////////////////////////////////////////////////////////////////
239
 
// GeckoContainerUI overrides
240
 
 
241
 
nsresult BrowserFrame::CreateBrowserWindow(PRUint32 aChromeFlags,
242
 
         nsIWebBrowserChrome *aParent, nsIWebBrowserChrome **aNewWindow)
243
 
{
244
 
    // Create the main frame window
245
 
    BrowserFrame* frame = new BrowserFrame(NULL);
246
 
    if (!frame)
247
 
        return NS_ERROR_OUT_OF_MEMORY;
248
 
    frame->Show(TRUE);
249
 
    GeckoContainer *container = frame->mGeckoWnd->GetGeckoContainer();
250
 
    return container->QueryInterface(NS_GET_IID(nsIWebBrowserChrome), (void **) aNewWindow);
251
 
}
252
 
 
253
 
void BrowserFrame::UpdateStatusBarText(const PRUnichar* aStatusText)
254
 
{
255
 
    SetStatusText(aStatusText);
256
 
}
257
 
 
258
 
void BrowserFrame::UpdateCurrentURI()
259
 
{
260
 
    if (mWebBrowser)
261
 
    {
262
 
        nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mWebBrowser);
263
 
        nsCOMPtr<nsIURI> currentURI;
264
 
        webNav->GetCurrentURI(getter_AddRefs(currentURI));
265
 
        nsCAutoString spec;
266
 
        currentURI->GetSpec(spec);
267
 
 
268
 
        wxTextCtrl *txtCtrl = (wxTextCtrl *) FindWindowById(XRCID("url"), this);
269
 
        if (txtCtrl)
270
 
        {
271
 
            txtCtrl->SetValue(spec.get());
272
 
        }
273
 
    }
274
 
}
275
 
 
276
 
#include "nsIDOMMouseEvent.h"
277
 
 
278
 
void BrowserFrame::ShowContextMenu(PRUint32 aContextFlags, nsIContextMenuInfo *aContextMenuInfo)
279
 
{
280
 
    nsCOMPtr<nsIDOMEvent> event;
281
 
    aContextMenuInfo->GetMouseEvent(getter_AddRefs(event));
282
 
    if (!event)
283
 
    {
284
 
        return;
285
 
    }
286
 
 
287
 
    mContextLinkUrl.SetLength(0);
288
 
 
289
 
    nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(event);
290
 
    if (mouseEvent)
291
 
    {
292
 
        PRInt32 x, y;
293
 
        mouseEvent->GetScreenX(&x);
294
 
        mouseEvent->GetScreenY(&y);
295
 
 
296
 
        char *menuName = NULL;
297
 
 
298
 
        // CONTEXT_LINK                   <A>
299
 
        // CONTEXT_IMAGE                  <IMG>
300
 
        // CONTEXT_IMAGE | CONTEXT_LINK   <IMG> with <A> as an ancestor
301
 
        // CONTEXT_INPUT                  <INPUT>
302
 
        // CONTEXT_INPUT | CONTEXT_IMAGE  <INPUT> with type=image
303
 
        // CONTEXT_TEXT                   <TEXTAREA>
304
 
        // CONTEXT_DOCUMENT               <HTML>
305
 
        // CONTEXT_BACKGROUND_IMAGE       <HTML> with background image
306
 
        
307
 
        if (aContextFlags & nsIContextMenuListener2::CONTEXT_IMAGE)
308
 
        {
309
 
            if (aContextFlags & nsIContextMenuListener2::CONTEXT_LINK)
310
 
                menuName = "context_browser_image"; // TODO
311
 
            else if (aContextFlags & nsIContextMenuListener2::CONTEXT_INPUT)
312
 
                menuName = "context_browser_image"; // TODO
313
 
            else
314
 
                menuName = "context_browser_image"; // TODO
315
 
        }
316
 
        else if (aContextFlags & nsIContextMenuListener2::CONTEXT_LINK)
317
 
        {
318
 
            menuName = "context_browser_link";
319
 
 
320
 
            aContextMenuInfo->GetAssociatedLink(mContextLinkUrl);
321
 
        }
322
 
        else if (aContextFlags & nsIContextMenuListener2::CONTEXT_INPUT)
323
 
        {
324
 
            menuName = "context_browser_input";
325
 
        }
326
 
        else if (aContextFlags & nsIContextMenuListener2::CONTEXT_TEXT)
327
 
        {
328
 
            menuName = "context_browser_text";
329
 
        }
330
 
        else if (aContextFlags & nsIContextMenuListener2::CONTEXT_DOCUMENT)
331
 
        {
332
 
            menuName = "context_browser_document";
333
 
        }
334
 
        else if (aContextFlags & nsIContextMenuListener2::CONTEXT_BACKGROUND_IMAGE)
335
 
        {
336
 
            menuName = "context_browser_document";
337
 
        }
338
 
 
339
 
        if (!menuName)
340
 
            return;
341
 
 
342
 
// Hack for Win32 that has a #define for LoadMenu
343
 
#undef LoadMenu
344
 
        wxMenu *menu = wxXmlResource::Get()->LoadMenu(menuName);
345
 
        if (menu)
346
 
        {
347
 
            int fX = 0, fY = 0;
348
 
            // Make screen coords relative to the frame window for accurate
349
 
            // popup menu position
350
 
            GetPosition(&fX, &fY);
351
 
            PopupMenu(menu, x - fX, y - fY);
352
 
        }
353
 
    }
354
 
}
355
 
 
356