1 /*
2 * Copyright (C) 2007 Kevin Ollivier All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27 #include "CString.h"
28 #include "Document.h"
29 #include "Element.h"
30 #include "Editor.h"
31 #include "EventHandler.h"
32 #include "FocusController.h"
33 #include "Frame.h"
34 #include "FrameLoader.h"
35 #include "FrameView.h"
36 #include "GraphicsContext.h"
37 #include "Logging.h"
38 #include "markup.h"
39 #include "Page.h"
40 #include "ContextMenu.h"
41 #include "ContextMenuItem.h"
42 #include "ContextMenuController.h"
43 #include "PlatformKeyboardEvent.h"
44 #include "PlatformMouseEvent.h"
45 #include "PlatformString.h"
46 #include "PlatformWheelEvent.h"
47 #include "RenderObject.h"
48 #include "RenderView.h"
49 #include "Scrollbar.h"
50 #include "SelectionController.h"
51 #include "Settings.h"
52 #include "SubstituteData.h"
53
54 #include "ChromeClientWx.h"
55 #include "ContextMenuClientWx.h"
56 #include "DragClientWx.h"
57 #include "EditorClientWx.h"
58 #include "FrameLoaderClientWx.h"
59 #include "InspectorClientWx.h"
60
61 #include "ScriptController.h"
62 #include "JSDOMBinding.h"
63 #include <runtime/JSValue.h>
64 #include <runtime/UString.h>
65
66 #include "wx/wxprec.h"
67 #ifndef WX_PRECOMP
68 #include "wx/wx.h"
69 #endif
70
71 #include "WebFrame.h"
72 #include "WebView.h"
73 #include "WebViewPrivate.h"
74
75 #include <wx/defs.h>
76 #include <wx/dcbuffer.h>
77 #include <wx/dcgraph.h>
78
79 #if defined(_MSC_VER)
rint(double val)80 int rint(double val)
81 {
82 return (int)(val < 0 ? val - 0.5 : val + 0.5);
83 }
84 #endif
85
86 // ----------------------------------------------------------------------------
87 // wxWebView Events
88 // ----------------------------------------------------------------------------
89
IMPLEMENT_DYNAMIC_CLASS(wxWebViewLoadEvent,wxCommandEvent)90 IMPLEMENT_DYNAMIC_CLASS(wxWebViewLoadEvent, wxCommandEvent)
91
92 DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_LOAD)
93
94 wxWebViewLoadEvent::wxWebViewLoadEvent(wxWindow* win)
95 {
96 SetEventType( wxEVT_WEBVIEW_LOAD);
97 SetEventObject( win );
98 if (win)
99 SetId(win->GetId());
100 }
101
IMPLEMENT_DYNAMIC_CLASS(wxWebViewBeforeLoadEvent,wxCommandEvent)102 IMPLEMENT_DYNAMIC_CLASS(wxWebViewBeforeLoadEvent, wxCommandEvent)
103
104 DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_BEFORE_LOAD)
105
106 wxWebViewBeforeLoadEvent::wxWebViewBeforeLoadEvent(wxWindow* win)
107 {
108 m_cancelled = false;
109 SetEventType(wxEVT_WEBVIEW_BEFORE_LOAD);
110 SetEventObject(win);
111 if (win)
112 SetId(win->GetId());
113 }
114
IMPLEMENT_DYNAMIC_CLASS(wxWebViewNewWindowEvent,wxCommandEvent)115 IMPLEMENT_DYNAMIC_CLASS(wxWebViewNewWindowEvent, wxCommandEvent)
116
117 DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_NEW_WINDOW)
118
119 wxWebViewNewWindowEvent::wxWebViewNewWindowEvent(wxWindow* win)
120 {
121 SetEventType(wxEVT_WEBVIEW_NEW_WINDOW);
122 SetEventObject(win);
123 if (win)
124 SetId(win->GetId());
125 }
126
IMPLEMENT_DYNAMIC_CLASS(wxWebViewRightClickEvent,wxCommandEvent)127 IMPLEMENT_DYNAMIC_CLASS(wxWebViewRightClickEvent, wxCommandEvent)
128
129 DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_RIGHT_CLICK)
130
131 wxWebViewRightClickEvent::wxWebViewRightClickEvent(wxWindow* win)
132 {
133 SetEventType(wxEVT_WEBVIEW_RIGHT_CLICK);
134 SetEventObject(win);
135 if (win)
136 SetId(win->GetId());
137 }
138
IMPLEMENT_DYNAMIC_CLASS(wxWebViewConsoleMessageEvent,wxCommandEvent)139 IMPLEMENT_DYNAMIC_CLASS(wxWebViewConsoleMessageEvent, wxCommandEvent)
140
141 DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_CONSOLE_MESSAGE)
142
143 wxWebViewConsoleMessageEvent::wxWebViewConsoleMessageEvent(wxWindow* win)
144 {
145 SetEventType(wxEVT_WEBVIEW_CONSOLE_MESSAGE);
146 SetEventObject(win);
147 if (win)
148 SetId(win->GetId());
149 }
150
IMPLEMENT_DYNAMIC_CLASS(wxWebViewAlertEvent,wxCommandEvent)151 IMPLEMENT_DYNAMIC_CLASS(wxWebViewAlertEvent, wxCommandEvent)
152
153 DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_JS_ALERT)
154
155 wxWebViewAlertEvent::wxWebViewAlertEvent(wxWindow* win)
156 {
157 SetEventType(wxEVT_WEBVIEW_JS_ALERT);
158 SetEventObject(win);
159 if (win)
160 SetId(win->GetId());
161 }
162
IMPLEMENT_DYNAMIC_CLASS(wxWebViewConfirmEvent,wxCommandEvent)163 IMPLEMENT_DYNAMIC_CLASS(wxWebViewConfirmEvent, wxCommandEvent)
164
165 DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_JS_CONFIRM)
166
167 wxWebViewConfirmEvent::wxWebViewConfirmEvent(wxWindow* win)
168 {
169 SetEventType(wxEVT_WEBVIEW_JS_CONFIRM);
170 SetEventObject(win);
171 if (win)
172 SetId(win->GetId());
173 }
174
IMPLEMENT_DYNAMIC_CLASS(wxWebViewPromptEvent,wxCommandEvent)175 IMPLEMENT_DYNAMIC_CLASS(wxWebViewPromptEvent, wxCommandEvent)
176
177 DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_JS_PROMPT)
178
179 wxWebViewPromptEvent::wxWebViewPromptEvent(wxWindow* win)
180 {
181 SetEventType(wxEVT_WEBVIEW_JS_PROMPT);
182 SetEventObject(win);
183 if (win)
184 SetId(win->GetId());
185 }
186
IMPLEMENT_DYNAMIC_CLASS(wxWebViewReceivedTitleEvent,wxCommandEvent)187 IMPLEMENT_DYNAMIC_CLASS(wxWebViewReceivedTitleEvent, wxCommandEvent)
188
189 DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_RECEIVED_TITLE)
190
191 wxWebViewReceivedTitleEvent::wxWebViewReceivedTitleEvent(wxWindow* win)
192 {
193 SetEventType(wxEVT_WEBVIEW_RECEIVED_TITLE);
194 SetEventObject(win);
195 if (win)
196 SetId(win->GetId());
197 }
198
IMPLEMENT_DYNAMIC_CLASS(wxWebViewWindowObjectClearedEvent,wxCommandEvent)199 IMPLEMENT_DYNAMIC_CLASS(wxWebViewWindowObjectClearedEvent, wxCommandEvent)
200
201 DEFINE_EVENT_TYPE(wxEVT_WEBVIEW_WINDOW_OBJECT_CLEARED)
202
203 wxWebViewWindowObjectClearedEvent::wxWebViewWindowObjectClearedEvent(wxWindow* win)
204 {
205 SetEventType(wxEVT_WEBVIEW_WINDOW_OBJECT_CLEARED);
206 SetEventObject(win);
207 if (win)
208 SetId(win->GetId());
209 }
210
211
212 //---------------------------------------------------------
213 // DOM Element info data type
214 //---------------------------------------------------------
215
wxWebViewDOMElementInfo()216 wxWebViewDOMElementInfo::wxWebViewDOMElementInfo() :
217 m_domElement(NULL),
218 m_isSelected(false),
219 m_text(wxEmptyString),
220 m_imageSrc(wxEmptyString),
221 m_link(wxEmptyString)
222 {
223 }
224
225 BEGIN_EVENT_TABLE(wxWebView, wxWindow)
226 EVT_PAINT(wxWebView::OnPaint)
227 EVT_SIZE(wxWebView::OnSize)
228 EVT_MOUSE_EVENTS(wxWebView::OnMouseEvents)
229 EVT_CONTEXT_MENU(wxWebView::OnContextMenuEvents)
230 EVT_MENU(wxID_ANY, wxWebView::OnMenuSelectEvents)
231 EVT_KEY_DOWN(wxWebView::OnKeyEvents)
232 EVT_KEY_UP(wxWebView::OnKeyEvents)
233 EVT_CHAR(wxWebView::OnKeyEvents)
234 EVT_SET_FOCUS(wxWebView::OnSetFocus)
235 EVT_KILL_FOCUS(wxWebView::OnKillFocus)
236 EVT_ACTIVATE(wxWebView::OnActivate)
237 END_EVENT_TABLE()
238
239 IMPLEMENT_DYNAMIC_CLASS(wxWebView, wxWindow)
240
241 const wxChar* wxWebViewNameStr = wxT("webView");
242
wxWebView()243 wxWebView::wxWebView() :
244 m_textMagnifier(1.0),
245 m_isEditable(false),
246 m_isInitialized(false),
247 m_beingDestroyed(false),
248 m_title(wxEmptyString)
249 {
250 }
251
wxWebView(wxWindow * parent,int id,const wxPoint & position,const wxSize & size,long style,const wxString & name)252 wxWebView::wxWebView(wxWindow* parent, int id, const wxPoint& position,
253 const wxSize& size, long style, const wxString& name) :
254 m_textMagnifier(1.0),
255 m_isEditable(false),
256 m_isInitialized(false),
257 m_beingDestroyed(false),
258 m_title(wxEmptyString)
259 {
260 Create(parent, id, position, size, style, name);
261 }
262
Create(wxWindow * parent,int id,const wxPoint & position,const wxSize & size,long style,const wxString & name)263 bool wxWebView::Create(wxWindow* parent, int id, const wxPoint& position,
264 const wxSize& size, long style, const wxString& name)
265 {
266 if ( (style & wxBORDER_MASK) == 0)
267 style |= wxBORDER_NONE;
268 style |= wxHSCROLL | wxVSCROLL;
269
270 if (!wxWindow::Create(parent, id, position, size, style, name))
271 return false;
272
273 // This is necessary because we are using SharedTimerWin.cpp on Windows,
274 // due to a problem with exceptions getting eaten when using the callback
275 // approach to timers (which wx itself uses).
276 #if __WXMSW__
277 WebCore::Page::setInstanceHandle(wxGetInstance());
278 #endif
279
280 // this helps reduce flicker on platforms like MSW
281 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
282
283 m_impl = new WebViewPrivate();
284
285 WebCore::InitializeLoggingChannelsIfNecessary();
286 WebCore::HTMLFrameOwnerElement* parentFrame = 0;
287
288 WebCore::EditorClientWx* editorClient = new WebCore::EditorClientWx();
289 m_impl->page = new WebCore::Page(new WebCore::ChromeClientWx(this), new WebCore::ContextMenuClientWx(), editorClient, new WebCore::DragClientWx(), new WebCore::InspectorClientWx());
290 editorClient->setPage(m_impl->page);
291
292 m_mainFrame = new wxWebFrame(this);
293
294 // Default settings - we should have wxWebViewSettings class for this
295 // eventually
296 WebCore::Settings* settings = m_impl->page->settings();
297 settings->setLoadsImagesAutomatically(true);
298 settings->setDefaultFixedFontSize(13);
299 settings->setDefaultFontSize(16);
300 settings->setSerifFontFamily("Times New Roman");
301 settings->setFixedFontFamily("Courier New");
302 settings->setSansSerifFontFamily("Arial");
303 settings->setStandardFontFamily("Times New Roman");
304 settings->setJavaScriptEnabled(true);
305
306 m_isInitialized = true;
307
308 return true;
309 }
310
~wxWebView()311 wxWebView::~wxWebView()
312 {
313 m_beingDestroyed = true;
314
315 delete m_mainFrame;
316
317 delete m_impl->page;
318 m_impl->page = 0;
319 }
320
Stop()321 void wxWebView::Stop()
322 {
323 if (m_mainFrame)
324 m_mainFrame->Stop();
325 }
326
Reload()327 void wxWebView::Reload()
328 {
329 if (m_mainFrame)
330 m_mainFrame->Reload();
331 }
332
GetPageSource()333 wxString wxWebView::GetPageSource()
334 {
335 if (m_mainFrame)
336 return m_mainFrame->GetPageSource();
337
338 return wxEmptyString;
339 }
340
SetPageSource(const wxString & source,const wxString & baseUrl)341 void wxWebView::SetPageSource(const wxString& source, const wxString& baseUrl)
342 {
343 if (m_mainFrame)
344 m_mainFrame->SetPageSource(source, baseUrl);
345 }
346
GetInnerText()347 wxString wxWebView::GetInnerText()
348 {
349 if (m_mainFrame)
350 return m_mainFrame->GetInnerText();
351
352 return wxEmptyString;
353 }
354
GetAsMarkup()355 wxString wxWebView::GetAsMarkup()
356 {
357 if (m_mainFrame)
358 return m_mainFrame->GetAsMarkup();
359
360 return wxEmptyString;
361 }
362
GetExternalRepresentation()363 wxString wxWebView::GetExternalRepresentation()
364 {
365 if (m_mainFrame)
366 return m_mainFrame->GetExternalRepresentation();
367
368 return wxEmptyString;
369 }
370
SetTransparent(bool transparent)371 void wxWebView::SetTransparent(bool transparent)
372 {
373 WebCore::Frame* frame = 0;
374 if (m_mainFrame)
375 frame = m_mainFrame->GetFrame();
376
377 if (!frame || !frame->view())
378 return;
379
380 frame->view()->setTransparent(transparent);
381 }
382
IsTransparent() const383 bool wxWebView::IsTransparent() const
384 {
385 WebCore::Frame* frame = 0;
386 if (m_mainFrame)
387 frame = m_mainFrame->GetFrame();
388
389 if (!frame || !frame->view())
390 return false;
391
392 return frame->view()->isTransparent();
393 }
394
RunScript(const wxString & javascript)395 wxString wxWebView::RunScript(const wxString& javascript)
396 {
397 if (m_mainFrame)
398 return m_mainFrame->RunScript(javascript);
399
400 return wxEmptyString;
401 }
402
LoadURL(const wxString & url)403 void wxWebView::LoadURL(const wxString& url)
404 {
405 if (m_mainFrame)
406 m_mainFrame->LoadURL(url);
407 }
408
GoBack()409 bool wxWebView::GoBack()
410 {
411 if (m_mainFrame)
412 return m_mainFrame->GoBack();
413
414 return false;
415 }
416
GoForward()417 bool wxWebView::GoForward()
418 {
419 if (m_mainFrame)
420 return m_mainFrame->GoForward();
421
422 return false;
423 }
424
CanGoBack()425 bool wxWebView::CanGoBack()
426 {
427 if (m_mainFrame)
428 return m_mainFrame->CanGoBack();
429
430 return false;
431 }
432
CanGoForward()433 bool wxWebView::CanGoForward()
434 {
435 if (m_mainFrame)
436 return m_mainFrame->CanGoForward();
437
438 return false;
439 }
440
CanIncreaseTextSize() const441 bool wxWebView::CanIncreaseTextSize() const
442 {
443 if (m_mainFrame)
444 return m_mainFrame->CanIncreaseTextSize();
445
446 return false;
447 }
448
IncreaseTextSize()449 void wxWebView::IncreaseTextSize()
450 {
451 if (m_mainFrame)
452 m_mainFrame->IncreaseTextSize();
453 }
454
CanDecreaseTextSize() const455 bool wxWebView::CanDecreaseTextSize() const
456 {
457 if (m_mainFrame)
458 m_mainFrame->CanDecreaseTextSize();
459
460 return false;
461 }
462
DecreaseTextSize()463 void wxWebView::DecreaseTextSize()
464 {
465 if (m_mainFrame)
466 m_mainFrame->DecreaseTextSize();
467 }
468
ResetTextSize()469 void wxWebView::ResetTextSize()
470 {
471 if (m_mainFrame)
472 m_mainFrame->ResetTextSize();
473 }
474
MakeEditable(bool enable)475 void wxWebView::MakeEditable(bool enable)
476 {
477 m_isEditable = enable;
478 }
479
480
481 /*
482 * Event forwarding functions to send events down to WebCore.
483 */
484
OnPaint(wxPaintEvent & event)485 void wxWebView::OnPaint(wxPaintEvent& event)
486 {
487
488 if (m_beingDestroyed || !m_mainFrame)
489 return;
490
491 WebCore::Frame* frame = m_mainFrame->GetFrame();
492 if (!frame || !frame->view())
493 return;
494
495 wxAutoBufferedPaintDC dc(this);
496
497 if (IsShown() && frame->document()) {
498 #if USE(WXGC)
499 wxGCDC gcdc(dc);
500 #endif
501
502 if (dc.IsOk()) {
503 wxRect paintRect = GetUpdateRegion().GetBox();
504
505 WebCore::IntSize offset = frame->view()->scrollOffset();
506 #if USE(WXGC)
507 gcdc.SetDeviceOrigin(-offset.width(), -offset.height());
508 #endif
509 dc.SetDeviceOrigin(-offset.width(), -offset.height());
510 paintRect.Offset(offset.width(), offset.height());
511
512 #if USE(WXGC)
513 WebCore::GraphicsContext gc(&gcdc);
514 #else
515 WebCore::GraphicsContext gc(&dc);
516 #endif
517 if (frame->contentRenderer()) {
518 if (frame->view()->needsLayout())
519 frame->view()->layout();
520
521 frame->view()->paintContents(&gc, paintRect);
522 }
523 }
524 }
525 }
526
FindString(const wxString & string,bool forward,bool caseSensitive,bool wrapSelection,bool startInSelection)527 bool wxWebView::FindString(const wxString& string, bool forward, bool caseSensitive, bool wrapSelection, bool startInSelection)
528 {
529 if (m_mainFrame)
530 return m_mainFrame->FindString(string, forward, caseSensitive, wrapSelection, startInSelection);
531
532 return false;
533 }
534
OnSize(wxSizeEvent & event)535 void wxWebView::OnSize(wxSizeEvent& event)
536 {
537 if (m_isInitialized && m_mainFrame) {
538 WebCore::Frame* frame = m_mainFrame->GetFrame();
539 frame->eventHandler()->sendResizeEvent();
540 frame->view()->layout();
541 frame->view()->adjustScrollbars();
542 }
543
544 event.Skip();
545 }
546
getDoubleClickTime()547 static int getDoubleClickTime()
548 {
549 #if __WXMSW__
550 return ::GetDoubleClickTime();
551 #else
552 return 500;
553 #endif
554 }
555
OnMouseEvents(wxMouseEvent & event)556 void wxWebView::OnMouseEvents(wxMouseEvent& event)
557 {
558 event.Skip();
559
560 if (m_beingDestroyed)
561 return;
562
563 if (!m_mainFrame)
564 return;
565
566 WebCore::Frame* frame = m_mainFrame->GetFrame();
567 if (!frame || !frame->view())
568 return;
569
570 wxPoint globalPoint = ClientToScreen(event.GetPosition());
571
572 wxEventType type = event.GetEventType();
573
574 if (type == wxEVT_MOUSEWHEEL) {
575 WebCore::PlatformWheelEvent wkEvent(event, globalPoint);
576 frame->eventHandler()->handleWheelEvent(wkEvent);
577 return;
578 }
579
580 int clickCount = event.ButtonDClick() ? 2 : 1;
581
582 if (clickCount == 1 && m_impl->tripleClickTimer.IsRunning()) {
583 wxPoint diff(event.GetPosition() - m_impl->tripleClickPos);
584 if (abs(diff.x) <= wxSystemSettings::GetMetric(wxSYS_DCLICK_X) &&
585 abs(diff.y) <= wxSystemSettings::GetMetric(wxSYS_DCLICK_Y)) {
586 clickCount = 3;
587 }
588 } else if (clickCount == 2) {
589 m_impl->tripleClickTimer.Start(getDoubleClickTime(), false);
590 m_impl->tripleClickPos = event.GetPosition();
591 }
592
593 WebCore::PlatformMouseEvent wkEvent(event, globalPoint, clickCount);
594
595 if (type == wxEVT_LEFT_DOWN || type == wxEVT_MIDDLE_DOWN || type == wxEVT_RIGHT_DOWN ||
596 type == wxEVT_LEFT_DCLICK || type == wxEVT_MIDDLE_DCLICK || type == wxEVT_RIGHT_DCLICK)
597 frame->eventHandler()->handleMousePressEvent(wkEvent);
598
599 else if (type == wxEVT_LEFT_UP || type == wxEVT_MIDDLE_UP || type == wxEVT_RIGHT_UP)
600 frame->eventHandler()->handleMouseReleaseEvent(wkEvent);
601
602 else if (type == wxEVT_MOTION)
603 frame->eventHandler()->mouseMoved(wkEvent);
604 }
605
OnContextMenuEvents(wxContextMenuEvent & event)606 void wxWebView::OnContextMenuEvents(wxContextMenuEvent& event)
607 {
608 m_impl->page->contextMenuController()->clearContextMenu();
609 wxPoint localEventPoint = ScreenToClient(event.GetPosition());
610
611 if (!m_mainFrame)
612 return;
613
614 WebCore::Frame* focusedFrame = m_mainFrame->GetFrame();
615 if (!focusedFrame->view())
616 return;
617
618 //Create WebCore mouse event from the wxContextMenuEvent
619 wxMouseEvent mouseEvent(wxEVT_RIGHT_DOWN);
620 mouseEvent.m_x = localEventPoint.x;
621 mouseEvent.m_y = localEventPoint.y;
622 WebCore::PlatformMouseEvent wkEvent(mouseEvent, event.GetPosition(), 1);
623
624 bool handledEvent = focusedFrame->eventHandler()->sendContextMenuEvent(wkEvent);
625 if (!handledEvent)
626 return;
627
628 WebCore::ContextMenu* coreMenu = m_impl->page->contextMenuController()->contextMenu();
629 if (!coreMenu)
630 return;
631
632 WebCore::PlatformMenuDescription menuWx = coreMenu->platformDescription();
633 if (!menuWx)
634 return;
635
636 PopupMenu(menuWx, localEventPoint);
637 }
638
OnMenuSelectEvents(wxCommandEvent & event)639 void wxWebView::OnMenuSelectEvents(wxCommandEvent& event)
640 {
641 WebCore::ContextMenuItem* item = WebCore::ContextMenu::itemWithId (event.GetId());
642 if (!item)
643 return;
644
645 m_impl->page->contextMenuController()->contextMenuItemSelected(item);
646 delete item;
647 }
648
CanCopy()649 bool wxWebView::CanCopy()
650 {
651 if (m_mainFrame)
652 return m_mainFrame->CanCopy();
653
654 return false;
655 }
656
Copy()657 void wxWebView::Copy()
658 {
659 if (m_mainFrame)
660 m_mainFrame->Copy();
661 }
662
CanCut()663 bool wxWebView::CanCut()
664 {
665 if (m_mainFrame)
666 return m_mainFrame->CanCut();
667
668 return false;
669 }
670
Cut()671 void wxWebView::Cut()
672 {
673 if (m_mainFrame)
674 m_mainFrame->Cut();
675 }
676
CanPaste()677 bool wxWebView::CanPaste()
678 {
679 if (m_mainFrame)
680 return m_mainFrame->CanPaste();
681
682 return false;
683 }
684
Paste()685 void wxWebView::Paste()
686 {
687 if (m_mainFrame)
688 m_mainFrame->Paste();
689 }
690
OnKeyEvents(wxKeyEvent & event)691 void wxWebView::OnKeyEvents(wxKeyEvent& event)
692 {
693 WebCore::Frame* frame = 0;
694 if (m_mainFrame)
695 frame = m_mainFrame->GetFrame();
696
697 if (!(frame && frame->view()))
698 return;
699
700 if (event.GetKeyCode() == WXK_CAPITAL)
701 frame->eventHandler()->capsLockStateMayHaveChanged();
702
703 WebCore::PlatformKeyboardEvent wkEvent(event);
704
705 if (frame->eventHandler()->keyEvent(wkEvent))
706 return;
707
708 //Some things WebKit won't do for us... Copy/Cut/Paste and KB scrolling
709 if (event.GetEventType() == wxEVT_KEY_DOWN) {
710 switch (event.GetKeyCode()) {
711 case 67: //"C"
712 if (CanCopy() && event.GetModifiers() == wxMOD_CMD) {
713 Copy();
714 return;
715 }
716 break;
717 case 86: //"V"
718 if (CanPaste() && event.GetModifiers() == wxMOD_CMD) {
719 Paste();
720 return;
721 }
722 break;
723 case 88: //"X"
724 if (CanCut() && event.GetModifiers() == wxMOD_CMD) {
725 Cut();
726 return;
727 }
728 break;
729 case WXK_INSERT:
730 if (CanCopy() && event.GetModifiers() == wxMOD_CMD) {
731 Copy();
732 return;
733 }
734 if (CanPaste() && event.GetModifiers() == wxMOD_SHIFT) {
735 Paste();
736 return;
737 }
738 return; //Insert shall not become a char
739 case WXK_DELETE:
740 if (CanCut() && event.GetModifiers() == wxMOD_SHIFT) {
741 Cut();
742 return;
743 }
744 break;
745 case WXK_LEFT:
746 case WXK_NUMPAD_LEFT:
747 frame->view()->scrollBy(WebCore::IntSize(-WebCore::cScrollbarPixelsPerLineStep, 0));
748 return;
749 case WXK_UP:
750 case WXK_NUMPAD_UP:
751 frame->view()->scrollBy(WebCore::IntSize(0, -WebCore::cScrollbarPixelsPerLineStep));
752 return;
753 case WXK_RIGHT:
754 case WXK_NUMPAD_RIGHT:
755 frame->view()->scrollBy(WebCore::IntSize(WebCore::cScrollbarPixelsPerLineStep, 0));
756 return;
757 case WXK_DOWN:
758 case WXK_NUMPAD_DOWN:
759 frame->view()->scrollBy(WebCore::IntSize(0, WebCore::cScrollbarPixelsPerLineStep));
760 return;
761 case WXK_END:
762 case WXK_NUMPAD_END:
763 frame->view()->setScrollPosition(WebCore::IntPoint(frame->view()->scrollX(), frame->view()->maximumScrollPosition().y()));
764 return;
765 case WXK_HOME:
766 case WXK_NUMPAD_HOME:
767 frame->view()->setScrollPosition(WebCore::IntPoint(frame->view()->scrollX(), 0));
768 return;
769 case WXK_PAGEUP:
770 case WXK_NUMPAD_PAGEUP:
771 frame->view()->scrollBy(WebCore::IntSize(0, -frame->view()->visibleHeight() + WebCore::cAmountToKeepWhenPaging));
772 return;
773 case WXK_PAGEDOWN:
774 case WXK_NUMPAD_PAGEDOWN:
775 frame->view()->scrollBy(WebCore::IntSize(0, frame->view()->visibleHeight() - WebCore::cAmountToKeepWhenPaging));
776 return;
777 //These we don't want turning into char events, stuff 'em
778 case WXK_ESCAPE:
779 case WXK_LBUTTON:
780 case WXK_RBUTTON:
781 case WXK_CANCEL:
782 case WXK_MENU:
783 case WXK_MBUTTON:
784 case WXK_CLEAR:
785 case WXK_PAUSE:
786 case WXK_SELECT:
787 case WXK_PRINT:
788 case WXK_EXECUTE:
789 case WXK_SNAPSHOT:
790 case WXK_HELP:
791 case WXK_F1:
792 case WXK_F2:
793 case WXK_F3:
794 case WXK_F4:
795 case WXK_F5:
796 case WXK_F6:
797 case WXK_F7:
798 case WXK_F8:
799 case WXK_F9:
800 case WXK_F10:
801 case WXK_F11:
802 case WXK_F12:
803 case WXK_F13:
804 case WXK_F14:
805 case WXK_F15:
806 case WXK_F16:
807 case WXK_F17:
808 case WXK_F18:
809 case WXK_F19:
810 case WXK_F20:
811 case WXK_F21:
812 case WXK_F22:
813 case WXK_F23:
814 case WXK_F24:
815 case WXK_NUMPAD_F1:
816 case WXK_NUMPAD_F2:
817 case WXK_NUMPAD_F3:
818 case WXK_NUMPAD_F4:
819 //When numlock is off Numpad 5 becomes BEGIN, or HOME on Char
820 case WXK_NUMPAD_BEGIN:
821 case WXK_NUMPAD_INSERT:
822 return;
823 }
824 }
825
826 event.Skip();
827 }
828
OnSetFocus(wxFocusEvent & event)829 void wxWebView::OnSetFocus(wxFocusEvent& event)
830 {
831 WebCore::Frame* frame = 0;
832 if (m_mainFrame)
833 frame = m_mainFrame->GetFrame();
834
835 if (frame) {
836 m_impl->page->focusController()->setActive(true);
837 frame->selection()->setFocused(true);
838 }
839
840 event.Skip();
841 }
842
OnKillFocus(wxFocusEvent & event)843 void wxWebView::OnKillFocus(wxFocusEvent& event)
844 {
845 WebCore::Frame* frame = 0;
846 if (m_mainFrame)
847 frame = m_mainFrame->GetFrame();
848
849 if (frame) {
850 m_impl->page->focusController()->setActive(false);
851 frame->selection()->setFocused(false);
852 }
853 event.Skip();
854 }
855
OnActivate(wxActivateEvent & event)856 void wxWebView::OnActivate(wxActivateEvent& event)
857 {
858 if (m_impl->page)
859 m_impl->page->focusController()->setActive(event.GetActive());
860
861 event.Skip();
862 }
863
HitTest(const wxPoint & pos) const864 wxWebViewDOMElementInfo wxWebView::HitTest(const wxPoint& pos) const
865 {
866 if (m_mainFrame)
867 return m_mainFrame->HitTest(pos);
868
869 return wxWebViewDOMElementInfo();
870 }
871
872