1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
|
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
* Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved.
* Copyright (C) 2011 Igalia S.L.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "WebKitWebViewBase.h"
#include "DrawingAreaProxyImpl.h"
#include "NativeWebKeyboardEvent.h"
#include "NativeWebMouseEvent.h"
#include "NativeWebWheelEvent.h"
#include "PageClientImpl.h"
#include "WebContext.h"
#include "WebEventFactory.h"
#include "WebFullScreenClientGtk.h"
#include "WebInspectorProxy.h"
#include "WebKitPrivate.h"
#include "WebKitWebViewBaseAccessible.h"
#include "WebKitWebViewBasePrivate.h"
#include "WebPageProxy.h"
#include <WebCore/ClipboardGtk.h>
#include <WebCore/ClipboardUtilitiesGtk.h>
#include <WebCore/DataObjectGtk.h>
#include <WebCore/DragData.h>
#include <WebCore/DragIcon.h>
#include <WebCore/GOwnPtrGtk.h>
#include <WebCore/GtkClickCounter.h>
#include <WebCore/GtkDragAndDropHelper.h>
#include <WebCore/GtkUtilities.h>
#include <WebCore/GtkVersioning.h>
#include <WebCore/NotImplemented.h>
#include <WebCore/PasteboardHelper.h>
#include <WebCore/RefPtrCairo.h>
#include <WebCore/Region.h>
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <wtf/HashMap.h>
#include <wtf/gobject/GOwnPtr.h>
#include <wtf/gobject/GRefPtr.h>
#include <wtf/text/CString.h>
#if ENABLE(FULLSCREEN_API)
#include "WebFullScreenManagerProxy.h"
#endif
#if USE(TEXTURE_MAPPER_GL) && defined(GDK_WINDOWING_X11)
#include <WebCore/RedirectedXCompositeWindow.h>
#endif
using namespace WebKit;
using namespace WebCore;
typedef HashMap<GtkWidget*, IntRect> WebKitWebViewChildrenMap;
#if USE(TEXTURE_MAPPER_GL)
void redirectedWindowDamagedCallback(void* data);
#endif
struct _WebKitWebViewBasePrivate {
WebKitWebViewChildrenMap children;
OwnPtr<PageClientImpl> pageClient;
RefPtr<WebPageProxy> pageProxy;
bool shouldForwardNextKeyEvent;
GRefPtr<GtkIMContext> imContext;
GtkClickCounter clickCounter;
CString tooltipText;
IntRect tooltipArea;
GtkDragAndDropHelper dragAndDropHelper;
DragIcon dragIcon;
IntSize resizerSize;
GRefPtr<AtkObject> accessible;
bool needsResizeOnMap;
GtkWidget* inspectorView;
unsigned inspectorViewHeight;
GOwnPtr<GdkEvent> contextMenuEvent;
WebContextMenuProxyGtk* activeContextMenuProxy;
GtkWindow* toplevelOnScreenWindow;
unsigned long toplevelResizeGripVisibilityID;
unsigned long toplevelFocusInEventID;
unsigned long toplevelFocusOutEventID;
// View State.
bool isInWindowActive : 1;
bool isFocused : 1;
bool isVisible : 1;
WebKitWebViewBaseDownloadRequestHandler downloadHandler;
#if ENABLE(FULLSCREEN_API)
bool fullScreenModeActive;
WebFullScreenClientGtk fullScreenClient;
#endif
#if USE(TEXTURE_MAPPER_GL)
OwnPtr<RedirectedXCompositeWindow> redirectedWindow;
#endif
};
G_DEFINE_TYPE(WebKitWebViewBase, webkit_web_view_base, GTK_TYPE_CONTAINER)
static void webkitWebViewBaseNotifyResizerSize(WebKitWebViewBase* webViewBase)
{
WebKitWebViewBasePrivate* priv = webViewBase->priv;
if (!priv->toplevelOnScreenWindow)
return;
gboolean resizerVisible;
g_object_get(G_OBJECT(priv->toplevelOnScreenWindow), "resize-grip-visible", &resizerVisible, NULL);
IntSize resizerSize;
if (resizerVisible) {
GdkRectangle resizerRect;
gtk_window_get_resize_grip_area(priv->toplevelOnScreenWindow, &resizerRect);
GdkRectangle allocation;
gtk_widget_get_allocation(GTK_WIDGET(webViewBase), &allocation);
if (gdk_rectangle_intersect(&resizerRect, &allocation, 0))
resizerSize = IntSize(resizerRect.width, resizerRect.height);
}
if (resizerSize != priv->resizerSize) {
priv->resizerSize = resizerSize;
priv->pageProxy->setWindowResizerSize(resizerSize);
}
}
static void toplevelWindowResizeGripVisibilityChanged(GObject*, GParamSpec*, WebKitWebViewBase* webViewBase)
{
webkitWebViewBaseNotifyResizerSize(webViewBase);
}
static gboolean toplevelWindowFocusInEvent(GtkWidget* widget, GdkEventFocus*, WebKitWebViewBase* webViewBase)
{
WebKitWebViewBasePrivate* priv = webViewBase->priv;
if (!priv->isInWindowActive) {
priv->isInWindowActive = true;
priv->pageProxy->viewStateDidChange(WebPageProxy::ViewWindowIsActive);
}
return FALSE;
}
static gboolean toplevelWindowFocusOutEvent(GtkWidget* widget, GdkEventFocus*, WebKitWebViewBase* webViewBase)
{
WebKitWebViewBasePrivate* priv = webViewBase->priv;
if (priv->isInWindowActive) {
priv->isInWindowActive = false;
priv->pageProxy->viewStateDidChange(WebPageProxy::ViewWindowIsActive);
}
return FALSE;
}
static void webkitWebViewBaseSetToplevelOnScreenWindow(WebKitWebViewBase* webViewBase, GtkWindow* window)
{
WebKitWebViewBasePrivate* priv = webViewBase->priv;
if (priv->toplevelOnScreenWindow == window)
return;
if (priv->toplevelResizeGripVisibilityID) {
g_signal_handler_disconnect(priv->toplevelOnScreenWindow, priv->toplevelResizeGripVisibilityID);
priv->toplevelResizeGripVisibilityID = 0;
}
if (priv->toplevelFocusInEventID) {
g_signal_handler_disconnect(priv->toplevelOnScreenWindow, priv->toplevelFocusInEventID);
priv->toplevelFocusInEventID = 0;
}
if (priv->toplevelFocusOutEventID) {
g_signal_handler_disconnect(priv->toplevelOnScreenWindow, priv->toplevelFocusOutEventID);
priv->toplevelFocusOutEventID = 0;
}
priv->toplevelOnScreenWindow = window;
priv->pageProxy->viewStateDidChange(WebPageProxy::ViewIsInWindow);
if (!priv->toplevelOnScreenWindow)
return;
webkitWebViewBaseNotifyResizerSize(webViewBase);
priv->toplevelResizeGripVisibilityID =
g_signal_connect(priv->toplevelOnScreenWindow, "notify::resize-grip-visible",
G_CALLBACK(toplevelWindowResizeGripVisibilityChanged), webViewBase);
priv->toplevelFocusInEventID =
g_signal_connect(priv->toplevelOnScreenWindow, "focus-in-event",
G_CALLBACK(toplevelWindowFocusInEvent), webViewBase);
priv->toplevelFocusOutEventID =
g_signal_connect(priv->toplevelOnScreenWindow, "focus-out-event",
G_CALLBACK(toplevelWindowFocusOutEvent), webViewBase);
}
static void webkitWebViewBaseRealize(GtkWidget* widget)
{
gtk_widget_set_realized(widget, TRUE);
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
GdkWindowAttr attributes;
attributes.window_type = GDK_WINDOW_CHILD;
attributes.x = allocation.x;
attributes.y = allocation.y;
attributes.width = allocation.width;
attributes.height = allocation.height;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual(widget);
attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK
| GDK_EXPOSURE_MASK
| GDK_BUTTON_PRESS_MASK
| GDK_BUTTON_RELEASE_MASK
| GDK_SCROLL_MASK
#if GTK_CHECK_VERSION(3, 3, 18)
| GDK_SMOOTH_SCROLL_MASK
#endif
| GDK_POINTER_MOTION_MASK
| GDK_KEY_PRESS_MASK
| GDK_KEY_RELEASE_MASK
| GDK_BUTTON_MOTION_MASK
| GDK_BUTTON1_MOTION_MASK
| GDK_BUTTON2_MOTION_MASK
| GDK_BUTTON3_MOTION_MASK;
gint attributesMask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
GdkWindow* window = gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, attributesMask);
gtk_widget_set_window(widget, window);
gdk_window_set_user_data(window, widget);
gtk_style_context_set_background(gtk_widget_get_style_context(widget), window);
WebKitWebViewBase* webView = WEBKIT_WEB_VIEW_BASE(widget);
WebKitWebViewBasePrivate* priv = webView->priv;
gtk_im_context_set_client_window(priv->imContext.get(), window);
GtkWidget* toplevel = gtk_widget_get_toplevel(widget);
if (widgetIsOnscreenToplevelWindow(toplevel))
webkitWebViewBaseSetToplevelOnScreenWindow(webView, GTK_WINDOW(toplevel));
}
static void webkitWebViewBaseContainerAdd(GtkContainer* container, GtkWidget* widget)
{
WebKitWebViewBase* webView = WEBKIT_WEB_VIEW_BASE(container);
WebKitWebViewBasePrivate* priv = webView->priv;
if (WEBKIT_IS_WEB_VIEW_BASE(widget)
&& WebInspectorProxy::isInspectorPage(WEBKIT_WEB_VIEW_BASE(widget)->priv->pageProxy.get())) {
ASSERT(!priv->inspectorView);
priv->inspectorView = widget;
} else {
GtkAllocation childAllocation;
gtk_widget_get_allocation(widget, &childAllocation);
priv->children.set(widget, childAllocation);
}
gtk_widget_set_parent(widget, GTK_WIDGET(container));
}
static void webkitWebViewBaseContainerRemove(GtkContainer* container, GtkWidget* widget)
{
WebKitWebViewBase* webView = WEBKIT_WEB_VIEW_BASE(container);
WebKitWebViewBasePrivate* priv = webView->priv;
GtkWidget* widgetContainer = GTK_WIDGET(container);
gboolean wasVisible = gtk_widget_get_visible(widget);
gtk_widget_unparent(widget);
if (priv->inspectorView == widget) {
priv->inspectorView = 0;
priv->inspectorViewHeight = 0;
} else {
ASSERT(priv->children.contains(widget));
priv->children.remove(widget);
}
if (wasVisible && gtk_widget_get_visible(widgetContainer))
gtk_widget_queue_resize(widgetContainer);
}
static void webkitWebViewBaseContainerForall(GtkContainer* container, gboolean includeInternals, GtkCallback callback, gpointer callbackData)
{
WebKitWebViewBase* webView = WEBKIT_WEB_VIEW_BASE(container);
WebKitWebViewBasePrivate* priv = webView->priv;
WebKitWebViewChildrenMap children = priv->children;
WebKitWebViewChildrenMap::const_iterator end = children.end();
for (WebKitWebViewChildrenMap::const_iterator current = children.begin(); current != end; ++current)
(*callback)(current->key, callbackData);
if (includeInternals && priv->inspectorView)
(*callback)(priv->inspectorView, callbackData);
}
void webkitWebViewBaseChildMoveResize(WebKitWebViewBase* webView, GtkWidget* child, const IntRect& childRect)
{
const IntRect& geometry = webView->priv->children.get(child);
if (geometry == childRect)
return;
webView->priv->children.set(child, childRect);
gtk_widget_queue_resize_no_redraw(GTK_WIDGET(webView));
}
static void webkitWebViewBaseFinalize(GObject* gobject)
{
WebKitWebViewBase* webkitWebViewBase = WEBKIT_WEB_VIEW_BASE(gobject);
WebKitWebViewBasePrivate* priv = webkitWebViewBase->priv;
priv->pageProxy->close();
webkitWebViewBaseSetToplevelOnScreenWindow(webkitWebViewBase, 0);
priv->~WebKitWebViewBasePrivate();
G_OBJECT_CLASS(webkit_web_view_base_parent_class)->finalize(gobject);
}
static void webkit_web_view_base_init(WebKitWebViewBase* webkitWebViewBase)
{
WebKitWebViewBasePrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(webkitWebViewBase, WEBKIT_TYPE_WEB_VIEW_BASE, WebKitWebViewBasePrivate);
webkitWebViewBase->priv = priv;
new (priv) WebKitWebViewBasePrivate();
priv->shouldForwardNextKeyEvent = FALSE;
GtkWidget* viewWidget = GTK_WIDGET(webkitWebViewBase);
gtk_widget_set_can_focus(viewWidget, TRUE);
priv->imContext = adoptGRef(gtk_im_multicontext_new());
priv->pageClient = PageClientImpl::create(viewWidget);
priv->dragAndDropHelper.setWidget(viewWidget);
gtk_drag_dest_set(viewWidget, static_cast<GtkDestDefaults>(0), 0, 0,
static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_PRIVATE));
gtk_drag_dest_set_target_list(viewWidget, PasteboardHelper::defaultPasteboardHelper()->targetList());
#if USE(TEXTURE_MAPPER_GL)
priv->redirectedWindow = RedirectedXCompositeWindow::create(IntSize(1, 1));
if (priv->redirectedWindow)
priv->redirectedWindow->setDamageNotifyCallback(redirectedWindowDamagedCallback, webkitWebViewBase);
#endif
}
#if USE(TEXTURE_MAPPER_GL)
static bool webkitWebViewRenderAcceleratedCompositingResults(WebKitWebViewBase* webViewBase, DrawingAreaProxyImpl* drawingArea, cairo_t* cr, GdkRectangle* clipRect)
{
if (!drawingArea->isInAcceleratedCompositingMode())
return false;
// To avoid flashes when initializing accelerated compositing for the first
// time, we wait until we know there's a frame ready before rendering.
WebKitWebViewBasePrivate* priv = webViewBase->priv;
if (!priv->redirectedWindow)
return false;
cairo_rectangle(cr, clipRect->x, clipRect->y, clipRect->width, clipRect->height);
cairo_surface_t* surface = priv->redirectedWindow->cairoSurfaceForWidget(GTK_WIDGET(webViewBase));
cairo_set_source_surface(cr, surface, 0, 0);
cairo_fill(cr);
return true;
}
#endif
static gboolean webkitWebViewBaseDraw(GtkWidget* widget, cairo_t* cr)
{
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
DrawingAreaProxyImpl* drawingArea = static_cast<DrawingAreaProxyImpl*>(webViewBase->priv->pageProxy->drawingArea());
if (!drawingArea)
return FALSE;
GdkRectangle clipRect;
if (!gdk_cairo_get_clip_rectangle(cr, &clipRect))
return FALSE;
#if USE(TEXTURE_MAPPER_GL)
if (webkitWebViewRenderAcceleratedCompositingResults(webViewBase, drawingArea, cr, &clipRect))
return FALSE;
#endif
WebCore::Region unpaintedRegion; // This is simply unused.
drawingArea->paint(cr, clipRect, unpaintedRegion);
return FALSE;
}
static void webkitWebViewBaseChildAllocate(GtkWidget* child, gpointer userData)
{
if (!gtk_widget_get_visible(child))
return;
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(userData);
WebKitWebViewBasePrivate* priv = webViewBase->priv;
const IntRect& geometry = priv->children.get(child);
if (geometry.isEmpty())
return;
GtkAllocation childAllocation = geometry;
gtk_widget_size_allocate(child, &childAllocation);
priv->children.set(child, IntRect());
}
static void resizeWebKitWebViewBaseFromAllocation(WebKitWebViewBase* webViewBase, GtkAllocation* allocation, bool sizeChanged)
{
gtk_container_foreach(GTK_CONTAINER(webViewBase), webkitWebViewBaseChildAllocate, webViewBase);
IntRect viewRect(allocation->x, allocation->y, allocation->width, allocation->height);
WebKitWebViewBasePrivate* priv = webViewBase->priv;
if (priv->inspectorView) {
GtkAllocation childAllocation = viewRect;
childAllocation.y = allocation->height - priv->inspectorViewHeight;
childAllocation.height = priv->inspectorViewHeight;
gtk_widget_size_allocate(priv->inspectorView, &childAllocation);
viewRect.setHeight(allocation->height - priv->inspectorViewHeight);
}
#if USE(TEXTURE_MAPPER_GL)
if (sizeChanged && webViewBase->priv->redirectedWindow)
webViewBase->priv->redirectedWindow->resize(viewRect.size());
#endif
if (priv->pageProxy->drawingArea())
priv->pageProxy->drawingArea()->setSize(viewRect.size(), IntSize());
webkitWebViewBaseNotifyResizerSize(webViewBase);
}
static void webkitWebViewBaseSizeAllocate(GtkWidget* widget, GtkAllocation* allocation)
{
bool sizeChanged = gtk_widget_get_allocated_width(widget) != allocation->width
|| gtk_widget_get_allocated_height(widget) != allocation->height;
GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->size_allocate(widget, allocation);
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
if (sizeChanged && !gtk_widget_get_mapped(widget) && !webViewBase->priv->pageProxy->drawingArea()->size().isEmpty()) {
webViewBase->priv->needsResizeOnMap = true;
return;
}
resizeWebKitWebViewBaseFromAllocation(webViewBase, allocation, sizeChanged);
}
static void webkitWebViewBaseMap(GtkWidget* widget)
{
GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->map(widget);
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
WebKitWebViewBasePrivate* priv = webViewBase->priv;
if (!priv->isVisible) {
priv->isVisible = true;
priv->pageProxy->viewStateDidChange(WebPageProxy::ViewIsVisible);
}
if (!priv->needsResizeOnMap)
return;
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
resizeWebKitWebViewBaseFromAllocation(webViewBase, &allocation, true /* sizeChanged */);
priv->needsResizeOnMap = false;
}
static void webkitWebViewBaseUnmap(GtkWidget* widget)
{
GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->unmap(widget);
WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
if (priv->isVisible) {
priv->isVisible = false;
priv->pageProxy->viewStateDidChange(WebPageProxy::ViewIsVisible);
}
}
static gboolean webkitWebViewBaseFocusInEvent(GtkWidget* widget, GdkEventFocus* event)
{
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
webkitWebViewBaseSetFocus(webViewBase, true);
gtk_im_context_focus_in(webViewBase->priv->imContext.get());
return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->focus_in_event(widget, event);
}
static gboolean webkitWebViewBaseFocusOutEvent(GtkWidget* widget, GdkEventFocus* event)
{
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
webkitWebViewBaseSetFocus(webViewBase, false);
gtk_im_context_focus_out(webViewBase->priv->imContext.get());
return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->focus_out_event(widget, event);
}
static gboolean webkitWebViewBaseKeyPressEvent(GtkWidget* widget, GdkEventKey* event)
{
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
WebKitWebViewBasePrivate* priv = webViewBase->priv;
#if ENABLE(FULLSCREEN_API)
if (priv->fullScreenModeActive) {
switch (event->keyval) {
case GDK_KEY_Escape:
case GDK_KEY_f:
case GDK_KEY_F:
webkitWebViewBaseExitFullScreen(webViewBase);
return TRUE;
default:
break;
}
}
#endif
// Since WebProcess key event handling is not synchronous, handle the event in two passes.
// When WebProcess processes the input event, it will call PageClientImpl::doneWithKeyEvent
// with event handled status which determines whether to pass the input event to parent or not
// using gtk_main_do_event().
if (priv->shouldForwardNextKeyEvent) {
priv->shouldForwardNextKeyEvent = FALSE;
return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->key_press_event(widget, event);
}
priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event)));
return TRUE;
}
static gboolean webkitWebViewBaseKeyReleaseEvent(GtkWidget* widget, GdkEventKey* event)
{
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
WebKitWebViewBasePrivate* priv = webViewBase->priv;
if (gtk_im_context_filter_keypress(priv->imContext.get(), event))
return TRUE;
if (priv->shouldForwardNextKeyEvent) {
priv->shouldForwardNextKeyEvent = FALSE;
return GTK_WIDGET_CLASS(webkit_web_view_base_parent_class)->key_release_event(widget, event);
}
priv->pageProxy->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event)));
return TRUE;
}
static gboolean webkitWebViewBaseButtonPressEvent(GtkWidget* widget, GdkEventButton* buttonEvent)
{
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
WebKitWebViewBasePrivate* priv = webViewBase->priv;
gtk_widget_grab_focus(widget);
if (!priv->clickCounter.shouldProcessButtonEvent(buttonEvent))
return TRUE;
// If it's a right click event save it as a possible context menu event.
if (buttonEvent->button == 3)
priv->contextMenuEvent.set(gdk_event_copy(reinterpret_cast<GdkEvent*>(buttonEvent)));
priv->pageProxy->handleMouseEvent(NativeWebMouseEvent(reinterpret_cast<GdkEvent*>(buttonEvent),
priv->clickCounter.clickCountForGdkButtonEvent(widget, buttonEvent)));
return TRUE;
}
static gboolean webkitWebViewBaseButtonReleaseEvent(GtkWidget* widget, GdkEventButton* event)
{
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
WebKitWebViewBasePrivate* priv = webViewBase->priv;
gtk_widget_grab_focus(widget);
priv->pageProxy->handleMouseEvent(NativeWebMouseEvent(reinterpret_cast<GdkEvent*>(event), 0 /* currentClickCount */));
return TRUE;
}
static gboolean webkitWebViewBaseScrollEvent(GtkWidget* widget, GdkEventScroll* event)
{
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
WebKitWebViewBasePrivate* priv = webViewBase->priv;
priv->pageProxy->handleWheelEvent(NativeWebWheelEvent(reinterpret_cast<GdkEvent*>(event)));
return TRUE;
}
static gboolean webkitWebViewBaseMotionNotifyEvent(GtkWidget* widget, GdkEventMotion* event)
{
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
WebKitWebViewBasePrivate* priv = webViewBase->priv;
priv->pageProxy->handleMouseEvent(NativeWebMouseEvent(reinterpret_cast<GdkEvent*>(event), 0 /* currentClickCount */));
return TRUE;
}
static gboolean webkitWebViewBaseQueryTooltip(GtkWidget* widget, gint x, gint y, gboolean keyboardMode, GtkTooltip* tooltip)
{
WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
if (keyboardMode) {
// TODO: https://bugs.webkit.org/show_bug.cgi?id=61732.
notImplemented();
return FALSE;
}
if (priv->tooltipText.length() <= 0)
return FALSE;
if (!priv->tooltipArea.isEmpty()) {
GdkRectangle area = priv->tooltipArea;
gtk_tooltip_set_tip_area(tooltip, &area);
} else
gtk_tooltip_set_tip_area(tooltip, 0);
gtk_tooltip_set_text(tooltip, priv->tooltipText.data());
return TRUE;
}
static void webkitWebViewBaseDragDataGet(GtkWidget* widget, GdkDragContext* context, GtkSelectionData* selectionData, guint info, guint time)
{
WEBKIT_WEB_VIEW_BASE(widget)->priv->dragAndDropHelper.handleGetDragData(context, selectionData, info);
}
static void webkitWebViewBaseDragEnd(GtkWidget* widget, GdkDragContext* context)
{
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
if (!webViewBase->priv->dragAndDropHelper.handleDragEnd(context))
return;
GdkDevice* device = gdk_drag_context_get_device(context);
int x = 0, y = 0;
gdk_device_get_window_at_position(device, &x, &y);
int xRoot = 0, yRoot = 0;
gdk_device_get_position(device, 0, &xRoot, &yRoot);
webViewBase->priv->pageProxy->dragEnded(IntPoint(x, y), IntPoint(xRoot, yRoot),
gdkDragActionToDragOperation(gdk_drag_context_get_selected_action(context)));
}
static void webkitWebViewBaseDragDataReceived(GtkWidget* widget, GdkDragContext* context, gint x, gint y, GtkSelectionData* selectionData, guint info, guint time)
{
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
OwnPtr<DragData> dragData(webViewBase->priv->dragAndDropHelper.handleDragDataReceived(context, selectionData, info));
if (!dragData)
return;
webViewBase->priv->pageProxy->resetDragOperation();
webViewBase->priv->pageProxy->dragEntered(dragData.get());
DragOperation operation = webViewBase->priv->pageProxy->dragSession().operation;
gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time);
}
static AtkObject* webkitWebViewBaseGetAccessible(GtkWidget* widget)
{
// If the socket has already been created and embedded a plug ID, return it.
WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
if (priv->accessible && atk_socket_is_occupied(ATK_SOCKET(priv->accessible.get())))
return priv->accessible.get();
// Create the accessible object and associate it to the widget.
if (!priv->accessible) {
priv->accessible = adoptGRef(ATK_OBJECT(webkitWebViewBaseAccessibleNew(widget)));
// Set the parent not to break bottom-up navigation.
GtkWidget* parentWidget = gtk_widget_get_parent(widget);
AtkObject* axParent = parentWidget ? gtk_widget_get_accessible(parentWidget) : 0;
if (axParent)
atk_object_set_parent(priv->accessible.get(), axParent);
}
// Try to embed the plug in the socket, if posssible.
String plugID = priv->pageProxy->accessibilityPlugID();
if (plugID.isNull())
return priv->accessible.get();
atk_socket_embed(ATK_SOCKET(priv->accessible.get()), const_cast<gchar*>(plugID.utf8().data()));
return priv->accessible.get();
}
static gboolean webkitWebViewBaseDragMotion(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time)
{
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
OwnPtr<DragData> dragData(webViewBase->priv->dragAndDropHelper.handleDragMotion(context, IntPoint(x, y), time));
if (!dragData)
return TRUE;
webViewBase->priv->pageProxy->dragUpdated(dragData.get());
DragOperation operation = webViewBase->priv->pageProxy->dragSession().operation;
gdk_drag_status(context, dragOperationToSingleGdkDragAction(operation), time);
return TRUE;
}
static void dragExitedCallback(GtkWidget* widget, DragData* dragData, bool dropHappened)
{
// Don't call dragExited if we have just received a drag-drop signal. This
// happens in the case of a successful drop onto the view.
if (dropHappened)
return;
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
webViewBase->priv->pageProxy->dragExited(dragData);
webViewBase->priv->pageProxy->resetDragOperation();
}
static void webkitWebViewBaseDragLeave(GtkWidget* widget, GdkDragContext* context, guint time)
{
WEBKIT_WEB_VIEW_BASE(widget)->priv->dragAndDropHelper.handleDragLeave(context, dragExitedCallback);
}
static gboolean webkitWebViewBaseDragDrop(GtkWidget* widget, GdkDragContext* context, gint x, gint y, guint time)
{
WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(widget);
OwnPtr<DragData> dragData(webViewBase->priv->dragAndDropHelper.handleDragDrop(context, IntPoint(x, y)));
if (!dragData)
return FALSE;
SandboxExtension::Handle handle;
SandboxExtension::HandleArray sandboxExtensionForUpload;
webViewBase->priv->pageProxy->performDrag(dragData.get(), String(), handle, sandboxExtensionForUpload);
gtk_drag_finish(context, TRUE, FALSE, time);
return TRUE;
}
static void webkitWebViewBaseParentSet(GtkWidget* widget, GtkWidget* oldParent)
{
if (!gtk_widget_get_parent(widget))
webkitWebViewBaseSetToplevelOnScreenWindow(WEBKIT_WEB_VIEW_BASE(widget), 0);
}
static void webkit_web_view_base_class_init(WebKitWebViewBaseClass* webkitWebViewBaseClass)
{
GtkWidgetClass* widgetClass = GTK_WIDGET_CLASS(webkitWebViewBaseClass);
widgetClass->realize = webkitWebViewBaseRealize;
widgetClass->draw = webkitWebViewBaseDraw;
widgetClass->size_allocate = webkitWebViewBaseSizeAllocate;
widgetClass->map = webkitWebViewBaseMap;
widgetClass->unmap = webkitWebViewBaseUnmap;
widgetClass->focus_in_event = webkitWebViewBaseFocusInEvent;
widgetClass->focus_out_event = webkitWebViewBaseFocusOutEvent;
widgetClass->key_press_event = webkitWebViewBaseKeyPressEvent;
widgetClass->key_release_event = webkitWebViewBaseKeyReleaseEvent;
widgetClass->button_press_event = webkitWebViewBaseButtonPressEvent;
widgetClass->button_release_event = webkitWebViewBaseButtonReleaseEvent;
widgetClass->scroll_event = webkitWebViewBaseScrollEvent;
widgetClass->motion_notify_event = webkitWebViewBaseMotionNotifyEvent;
widgetClass->query_tooltip = webkitWebViewBaseQueryTooltip;
widgetClass->drag_end = webkitWebViewBaseDragEnd;
widgetClass->drag_data_get = webkitWebViewBaseDragDataGet;
widgetClass->drag_motion = webkitWebViewBaseDragMotion;
widgetClass->drag_leave = webkitWebViewBaseDragLeave;
widgetClass->drag_drop = webkitWebViewBaseDragDrop;
widgetClass->drag_data_received = webkitWebViewBaseDragDataReceived;
widgetClass->get_accessible = webkitWebViewBaseGetAccessible;
widgetClass->parent_set = webkitWebViewBaseParentSet;
GObjectClass* gobjectClass = G_OBJECT_CLASS(webkitWebViewBaseClass);
gobjectClass->finalize = webkitWebViewBaseFinalize;
GtkContainerClass* containerClass = GTK_CONTAINER_CLASS(webkitWebViewBaseClass);
containerClass->add = webkitWebViewBaseContainerAdd;
containerClass->remove = webkitWebViewBaseContainerRemove;
containerClass->forall = webkitWebViewBaseContainerForall;
g_type_class_add_private(webkitWebViewBaseClass, sizeof(WebKitWebViewBasePrivate));
}
WebKitWebViewBase* webkitWebViewBaseCreate(WebContext* context, WebPageGroup* pageGroup)
{
WebKitWebViewBase* webkitWebViewBase = WEBKIT_WEB_VIEW_BASE(g_object_new(WEBKIT_TYPE_WEB_VIEW_BASE, NULL));
webkitWebViewBaseCreateWebPage(webkitWebViewBase, context, pageGroup);
return webkitWebViewBase;
}
GtkIMContext* webkitWebViewBaseGetIMContext(WebKitWebViewBase* webkitWebViewBase)
{
return webkitWebViewBase->priv->imContext.get();
}
WebPageProxy* webkitWebViewBaseGetPage(WebKitWebViewBase* webkitWebViewBase)
{
return webkitWebViewBase->priv->pageProxy.get();
}
void webkitWebViewBaseCreateWebPage(WebKitWebViewBase* webkitWebViewBase, WebContext* context, WebPageGroup* pageGroup)
{
WebKitWebViewBasePrivate* priv = webkitWebViewBase->priv;
priv->pageProxy = context->createWebPage(priv->pageClient.get(), pageGroup);
priv->pageProxy->initializeWebPage();
#if ENABLE(FULLSCREEN_API)
priv->pageProxy->fullScreenManager()->setWebView(webkitWebViewBase);
#endif
#if USE(TEXTURE_MAPPER_GL)
if (priv->redirectedWindow)
priv->pageProxy->setAcceleratedCompositingWindowId(priv->redirectedWindow->windowId());
#endif
}
void webkitWebViewBaseSetTooltipText(WebKitWebViewBase* webViewBase, const char* tooltip)
{
WebKitWebViewBasePrivate* priv = webViewBase->priv;
if (tooltip && tooltip[0] != '\0') {
priv->tooltipText = tooltip;
gtk_widget_set_has_tooltip(GTK_WIDGET(webViewBase), TRUE);
} else {
priv->tooltipText = "";
gtk_widget_set_has_tooltip(GTK_WIDGET(webViewBase), FALSE);
}
gtk_widget_trigger_tooltip_query(GTK_WIDGET(webViewBase));
}
void webkitWebViewBaseSetTooltipArea(WebKitWebViewBase* webViewBase, const IntRect& tooltipArea)
{
webViewBase->priv->tooltipArea = tooltipArea;
}
void webkitWebViewBaseStartDrag(WebKitWebViewBase* webViewBase, const DragData& dragData, PassRefPtr<ShareableBitmap> dragImage)
{
WebKitWebViewBasePrivate* priv = webViewBase->priv;
RefPtr<DataObjectGtk> dataObject = adoptRef(dragData.platformData());
GRefPtr<GtkTargetList> targetList = adoptGRef(PasteboardHelper::defaultPasteboardHelper()->targetListForDataObject(dataObject.get()));
GOwnPtr<GdkEvent> currentEvent(gtk_get_current_event());
GdkDragContext* context = gtk_drag_begin(GTK_WIDGET(webViewBase),
targetList.get(),
dragOperationToGdkDragActions(dragData.draggingSourceOperationMask()),
1, /* button */
currentEvent.get());
priv->dragAndDropHelper.startedDrag(context, dataObject.get());
// A drag starting should prevent a double-click from happening. This might
// happen if a drag is followed very quickly by another click (like in the DRT).
priv->clickCounter.reset();
if (dragImage) {
RefPtr<cairo_surface_t> image(dragImage->createCairoSurface());
priv->dragIcon.setImage(image.get());
priv->dragIcon.useForDrag(context);
} else
gtk_drag_set_icon_default(context);
}
void webkitWebViewBaseForwardNextKeyEvent(WebKitWebViewBase* webkitWebViewBase)
{
webkitWebViewBase->priv->shouldForwardNextKeyEvent = TRUE;
}
void webkitWebViewBaseEnterFullScreen(WebKitWebViewBase* webkitWebViewBase)
{
#if ENABLE(FULLSCREEN_API)
WebKitWebViewBasePrivate* priv = webkitWebViewBase->priv;
if (priv->fullScreenModeActive)
return;
if (!priv->fullScreenClient.willEnterFullScreen())
return;
WebFullScreenManagerProxy* fullScreenManagerProxy = priv->pageProxy->fullScreenManager();
fullScreenManagerProxy->willEnterFullScreen();
GtkWidget* topLevelWindow = gtk_widget_get_toplevel(GTK_WIDGET(webkitWebViewBase));
if (gtk_widget_is_toplevel(topLevelWindow))
gtk_window_fullscreen(GTK_WINDOW(topLevelWindow));
fullScreenManagerProxy->didEnterFullScreen();
priv->fullScreenModeActive = true;
#endif
}
void webkitWebViewBaseExitFullScreen(WebKitWebViewBase* webkitWebViewBase)
{
#if ENABLE(FULLSCREEN_API)
WebKitWebViewBasePrivate* priv = webkitWebViewBase->priv;
if (!priv->fullScreenModeActive)
return;
if (!priv->fullScreenClient.willExitFullScreen())
return;
WebFullScreenManagerProxy* fullScreenManagerProxy = priv->pageProxy->fullScreenManager();
fullScreenManagerProxy->willExitFullScreen();
GtkWidget* topLevelWindow = gtk_widget_get_toplevel(GTK_WIDGET(webkitWebViewBase));
if (gtk_widget_is_toplevel(topLevelWindow))
gtk_window_unfullscreen(GTK_WINDOW(topLevelWindow));
fullScreenManagerProxy->didExitFullScreen();
priv->fullScreenModeActive = false;
#endif
}
void webkitWebViewBaseInitializeFullScreenClient(WebKitWebViewBase* webkitWebViewBase, const WKFullScreenClientGtk* wkClient)
{
webkitWebViewBase->priv->fullScreenClient.initialize(wkClient);
}
void webkitWebViewBaseSetInspectorViewHeight(WebKitWebViewBase* webkitWebViewBase, unsigned height)
{
if (webkitWebViewBase->priv->inspectorViewHeight == height)
return;
webkitWebViewBase->priv->inspectorViewHeight = height;
if (webkitWebViewBase->priv->inspectorView)
gtk_widget_queue_resize_no_redraw(GTK_WIDGET(webkitWebViewBase));
}
void webkitWebViewBaseSetActiveContextMenuProxy(WebKitWebViewBase* webkitWebViewBase, WebContextMenuProxyGtk* contextMenuProxy)
{
webkitWebViewBase->priv->activeContextMenuProxy = contextMenuProxy;
}
WebContextMenuProxyGtk* webkitWebViewBaseGetActiveContextMenuProxy(WebKitWebViewBase* webkitWebViewBase)
{
return webkitWebViewBase->priv->activeContextMenuProxy;
}
GdkEvent* webkitWebViewBaseTakeContextMenuEvent(WebKitWebViewBase* webkitWebViewBase)
{
return webkitWebViewBase->priv->contextMenuEvent.release();
}
#if USE(TEXTURE_MAPPER_GL)
void redirectedWindowDamagedCallback(void* data)
{
gtk_widget_queue_draw(GTK_WIDGET(data));
}
#endif
void webkitWebViewBaseSetFocus(WebKitWebViewBase* webViewBase, bool focused)
{
WebKitWebViewBasePrivate* priv = webViewBase->priv;
if (priv->isFocused == focused)
return;
unsigned viewStateFlags = WebPageProxy::ViewIsFocused;
priv->isFocused = focused;
// If the view has received the focus and the window is not active
// mark the current window as active now. This can happen if the
// toplevel window is a GTK_WINDOW_POPUP and the focus has been
// set programatically like WebKitTestRunner does, because POPUP
// can't be focused.
if (priv->isFocused && !priv->isInWindowActive) {
priv->isInWindowActive = true;
viewStateFlags |= WebPageProxy::ViewWindowIsActive;
}
priv->pageProxy->viewStateDidChange(viewStateFlags);
}
bool webkitWebViewBaseIsInWindowActive(WebKitWebViewBase* webViewBase)
{
return webViewBase->priv->isInWindowActive;
}
bool webkitWebViewBaseIsFocused(WebKitWebViewBase* webViewBase)
{
return webViewBase->priv->isFocused;
}
bool webkitWebViewBaseIsVisible(WebKitWebViewBase* webViewBase)
{
return webViewBase->priv->isVisible;
}
bool webkitWebViewBaseIsInWindow(WebKitWebViewBase* webViewBase)
{
return webViewBase->priv->toplevelOnScreenWindow;
}
void webkitWebViewBaseSetDownloadRequestHandler(WebKitWebViewBase* webViewBase, WebKitWebViewBaseDownloadRequestHandler downloadHandler)
{
webViewBase->priv->downloadHandler = downloadHandler;
}
void webkitWebViewBaseHandleDownloadRequest(WebKitWebViewBase* webViewBase, DownloadProxy* download)
{
if (webViewBase->priv->downloadHandler)
webViewBase->priv->downloadHandler(webViewBase, download);
}
|