summaryrefslogtreecommitdiffstats
path: root/WebKit/efl/ewk/ewk_view.cpp
blob: 254fdfdc6291affc071472cf0bf1ead2a9aea091 (plain)
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
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
/*
    Copyright (C) 2009-2010 ProFUSION embedded systems
    Copyright (C) 2009-2010 Samsung Electronics

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#define __STDC_FORMAT_MACROS
#include "config.h"
#include "ewk_view.h"

#include "appcache/ApplicationCacheStorage.h"
#include "ChromeClientEfl.h"
#include "ContextMenuClientEfl.h"
#include "ContextMenuController.h"
#include "DocumentLoader.h"
#include "DragClientEfl.h"
#include "EWebKit.h"
#include "EditorClientEfl.h"
#include "EventHandler.h"
#include "FocusController.h"
#include "FrameLoaderClientEfl.h"
#include "FrameView.h"
#include "GraphicsContext.h"
#include "HTMLElement.h"
#include "HTMLInputElement.h"
#include "HTMLNames.h"
#include "InspectorClientEfl.h"
#include "PlatformMouseEvent.h"
#include "PopupMenuClient.h"
#include "ProgressTracker.h"
#include "ewk_private.h"

#include <Ecore.h>
#include <Eina.h>
#include <Evas.h>
#include <eina_safety_checks.h>
#include <inttypes.h>
#include <sys/time.h>

#define ZOOM_MIN (0.05)
#define ZOOM_MAX (4.0)

static const char EWK_VIEW_TYPE_STR[] = "EWK_View";

static const size_t EWK_VIEW_REPAINTS_SIZE_INITIAL = 32;
static const size_t EWK_VIEW_REPAINTS_SIZE_STEP = 8;
static const size_t EWK_VIEW_REPAINTS_SIZE_MAX_FREE = 64;

static const size_t EWK_VIEW_SCROLLS_SIZE_INITIAL = 8;
static const size_t EWK_VIEW_SCROLLS_SIZE_STEP = 2;
static const size_t EWK_VIEW_SCROLLS_SIZE_MAX_FREE = 32;

struct _Ewk_View_Private_Data {
    WebCore::Page* page;
    WebCore::Settings* page_settings;
    WebCore::Frame* main_frame;
    Ewk_History* history;
    struct {
        Ewk_Menu menu;
        WebCore::PopupMenuClient* menu_client;
    } popup;
    struct {
        Eina_Rectangle* array;
        size_t count;
        size_t allocated;
    } repaints;
    struct {
        Ewk_Scroll_Request* array;
        size_t count;
        size_t allocated;
    } scrolls;
    unsigned int imh; /**< input method hints */
    struct {
        const char* user_agent;
        const char* user_stylesheet;
        const char* encoding_default;
        const char* encoding_custom;
        const char* cache_directory;
        int font_minimum_size;
        int font_minimum_logical_size;
        int font_default_size;
        int font_monospace_size;
        const char* font_standard;
        const char* font_cursive;
        const char* font_monospace;
        const char* font_fantasy;
        const char* font_serif;
        const char* font_sans_serif;
        Eina_Bool auto_load_images:1;
        Eina_Bool auto_shrink_images:1;
        Eina_Bool enable_scripts:1;
        Eina_Bool enable_plugins:1;
        Eina_Bool enable_frame_flattening:1;
        Eina_Bool scripts_window_open:1;
        Eina_Bool resizable_textareas:1;
        Eina_Bool private_browsing:1;
        Eina_Bool caret_browsing:1;
        Eina_Bool spatial_navigation:1;
        Eina_Bool local_storage:1;
        Eina_Bool offline_app_cache: 1;
        struct {
            float w;
            float h;
            float init_scale;
            float min_scale;
            float max_scale;
            float user_scalable;
        } viewport;
        struct {
            float min_scale;
            float max_scale;
            Eina_Bool user_scalable:1;
        } zoom_range;
    } settings;
    struct {
        struct {
            double start;
            double end;
            double duration;
        } time;
        struct {
            float start;
            float end;
            float range;
        } zoom;
        struct {
            Evas_Coord x, y;
        } center;
        Ecore_Animator* animator;
    } animated_zoom;
    struct {
        Evas_Coord w, h;
        Eina_Bool use:1;
    } fixed_layout;
};

#ifndef EWK_TYPE_CHECK
#define EWK_VIEW_TYPE_CHECK(o, ...) do { } while (0)
#else
#define EWK_VIEW_TYPE_CHECK(o, ...)                                     \
    do {                                                                \
        const char* _tmp_otype = evas_object_type_get(o);               \
        const Evas_Smart* _tmp_s = evas_object_smart_smart_get(o);      \
        if (EINA_UNLIKELY(!_tmp_s)) {                                   \
            EINA_LOG_CRIT                                               \
                ("%p (%s) is not a smart object!", o,                   \
                 _tmp_otype ? _tmp_otype : "(null)");                   \
            return __VA_ARGS__;                                         \
        }                                                               \
        const Evas_Smart_Class* _tmp_sc = evas_smart_class_get(_tmp_s); \
        if (EINA_UNLIKELY(!_tmp_sc)) {                                  \
            EINA_LOG_CRIT                                               \
                ("%p (%s) is not a smart object!", o,                   \
                 _tmp_otype ? _tmp_otype : "(null)");                   \
            return __VA_ARGS__;                                         \
        }                                                               \
        if (EINA_UNLIKELY(_tmp_sc->data != EWK_VIEW_TYPE_STR)) {        \
            EINA_LOG_CRIT                                               \
                ("%p (%s) is not of an ewk_view (need %p, got %p)!",    \
                 o, _tmp_otype ? _tmp_otype : "(null)",                 \
                 EWK_VIEW_TYPE_STR, _tmp_sc->data);                     \
            return __VA_ARGS__;                                         \
        }                                                               \
    } while (0)
#endif

#define EWK_VIEW_SD_GET(o, ptr)                                 \
    Ewk_View_Smart_Data* ptr = (Ewk_View_Smart_Data*)evas_object_smart_data_get(o)

#define EWK_VIEW_SD_GET_OR_RETURN(o, ptr, ...)          \
    EWK_VIEW_TYPE_CHECK(o, __VA_ARGS__);                \
    EWK_VIEW_SD_GET(o, ptr);                            \
    if (!ptr) {                                         \
        CRITICAL("no smart data for object %p (%s)",    \
                 o, evas_object_type_get(o));           \
        return __VA_ARGS__;                             \
    }

#define EWK_VIEW_PRIV_GET(sd, ptr)              \
    Ewk_View_Private_Data* ptr = sd->_priv

#define EWK_VIEW_PRIV_GET_OR_RETURN(sd, ptr, ...)               \
    EWK_VIEW_PRIV_GET(sd, ptr);                                 \
    if (!ptr) {                                                 \
        CRITICAL("no private data for object %p (%s)",          \
                 sd->self, evas_object_type_get(sd->self));     \
        return __VA_ARGS__;                                     \
    }

static void _ewk_view_smart_changed(Ewk_View_Smart_Data* sd)
{
    if (sd->changed.any)
        return;
    sd->changed.any = EINA_TRUE;
    evas_object_smart_changed(sd->self);
}

static Eina_Bool _ewk_view_repaints_resize(Ewk_View_Private_Data* priv, size_t size)
{
    void* tmp = realloc(priv->repaints.array, size * sizeof(Eina_Rectangle));
    if (!tmp) {
        CRITICAL("could not realloc repaints array to %zu elements.", size);
        return EINA_FALSE;
    }
    priv->repaints.allocated = size;
    priv->repaints.array = (Eina_Rectangle*)tmp;
    return EINA_TRUE;
}

static void _ewk_view_repaint_add(Ewk_View_Private_Data* priv, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
{
    Eina_Rectangle* r;

    // fprintf(stderr, ">>> repaint requested: %d,%d+%dx%d\n", x, y, w, h);
    if (priv->repaints.allocated == priv->repaints.count) {
        size_t size;
        if (!priv->repaints.allocated)
            size = EWK_VIEW_REPAINTS_SIZE_INITIAL;
        else
            size = priv->repaints.allocated + EWK_VIEW_REPAINTS_SIZE_STEP;
        if (!_ewk_view_repaints_resize(priv, size))
            return;
    }

    r = priv->repaints.array + priv->repaints.count;
    priv->repaints.count++;

    r->x = x;
    r->y = y;
    r->w = w;
    r->h = h;

    DBG("add repaint %d,%d+%dx%d", x, y, w, h);
}

static void _ewk_view_repaints_flush(Ewk_View_Private_Data* priv)
{
    priv->repaints.count = 0;
    if (priv->repaints.allocated <= EWK_VIEW_REPAINTS_SIZE_MAX_FREE)
        return;
    _ewk_view_repaints_resize(priv, EWK_VIEW_REPAINTS_SIZE_MAX_FREE);
}

static Eina_Bool _ewk_view_scrolls_resize(Ewk_View_Private_Data* priv, size_t size)
{
    void* tmp = realloc(priv->scrolls.array, size * sizeof(Ewk_Scroll_Request));
    if (!tmp) {
        CRITICAL("could not realloc scrolls array to %zu elements.", size);
        return EINA_FALSE;
    }
    priv->scrolls.allocated = size;
    priv->scrolls.array = (Ewk_Scroll_Request*)tmp;
    return EINA_TRUE;
}

static void _ewk_view_scroll_add(Ewk_View_Private_Data* priv, Evas_Coord dx, Evas_Coord dy, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h, Eina_Bool main_scroll)
{
    Ewk_Scroll_Request* r;
    Ewk_Scroll_Request* r_end;
    Evas_Coord x2 = x + w, y2 = y + h;

    r = priv->scrolls.array;
    r_end = r + priv->scrolls.count;
    for (; r < r_end; r++) {
        if (r->x == x && r->y == y && r->w == w && r->h == h) {
            DBG("region already scrolled %d,%d+%dx%d %+03d,%+03d add "
                "%+03d,%+03d",
                r->x, r->y, r->w, r->h, r->dx, r->dy, dx, dy);
            r->dx += dx;
            r->dy += dy;
            return;
        }
        if ((x <= r->x && x2 >= r->x2) && (y <= r->y && y2 >= r->y2)) {
            DBG("old viewport (%d,%d+%dx%d %+03d,%+03d) was scrolled itself, "
                "add %+03d,%+03d",
                r->x, r->y, r->w, r->h, r->dx, r->dy, dx, dy);
            r->x += dx;
            r->y += dy;
        }
    }

    if (priv->scrolls.allocated == priv->scrolls.count) {
        size_t size;
        if (!priv->scrolls.allocated)
            size = EWK_VIEW_SCROLLS_SIZE_INITIAL;
        else
            size = priv->scrolls.allocated + EWK_VIEW_SCROLLS_SIZE_STEP;
        if (!_ewk_view_scrolls_resize(priv, size))
            return;
    }

    r = priv->scrolls.array + priv->scrolls.count;
    priv->scrolls.count++;

    r->x = x;
    r->y = y;
    r->w = w;
    r->h = h;
    r->x2 = x2;
    r->y2 = y2;
    r->dx = dx;
    r->dy = dy;
    r->main_scroll = main_scroll;
    DBG("add scroll in region: %d,%d+%dx%d %+03d,%+03d", x, y, w, h, dx, dy);

    Eina_Rectangle* pr;
    Eina_Rectangle* pr_end;
    size_t count;
    pr = priv->repaints.array;
    count = priv->repaints.count;
    pr_end = pr + count;
    for (; pr < pr_end; pr++) {
        pr->x += dx;
        pr->y += dy;
    }
}

static void _ewk_view_scrolls_flush(Ewk_View_Private_Data* priv)
{
    priv->scrolls.count = 0;
    if (priv->scrolls.allocated <= EWK_VIEW_SCROLLS_SIZE_MAX_FREE)
        return;
    _ewk_view_scrolls_resize(priv, EWK_VIEW_SCROLLS_SIZE_MAX_FREE);
}

// Default Event Handling //////////////////////////////////////////////
static Eina_Bool _ewk_view_smart_focus_in(Ewk_View_Smart_Data* sd)
{
    EWK_VIEW_PRIV_GET(sd, priv);
    WebCore::FocusController* fc = priv->page->focusController();
    DBG("o=%p, fc=%p", sd->self, fc);
    EINA_SAFETY_ON_NULL_RETURN_VAL(fc, EINA_FALSE);

    fc->setActive(true);
    fc->setFocused(true);
    return EINA_TRUE;
}

static Eina_Bool _ewk_view_smart_focus_out(Ewk_View_Smart_Data* sd)
{
    EWK_VIEW_PRIV_GET(sd, priv);
    WebCore::FocusController* fc = priv->page->focusController();
    DBG("o=%p, fc=%p", sd->self, fc);
    EINA_SAFETY_ON_NULL_RETURN_VAL(fc, EINA_FALSE);

    fc->setActive(false);
    fc->setFocused(false);
    return EINA_TRUE;
}

static Eina_Bool _ewk_view_smart_mouse_wheel(Ewk_View_Smart_Data* sd, const Evas_Event_Mouse_Wheel* ev)
{
    return ewk_frame_feed_mouse_wheel(sd->main_frame, ev);
}

static Eina_Bool _ewk_view_smart_mouse_down(Ewk_View_Smart_Data* sd, const Evas_Event_Mouse_Down* ev)
{
    return ewk_frame_feed_mouse_down(sd->main_frame, ev);
}

static Eina_Bool _ewk_view_smart_mouse_up(Ewk_View_Smart_Data* sd, const Evas_Event_Mouse_Up* ev)
{
    return ewk_frame_feed_mouse_up(sd->main_frame, ev);
}

static Eina_Bool _ewk_view_smart_mouse_move(Ewk_View_Smart_Data* sd, const Evas_Event_Mouse_Move* ev)
{
    return ewk_frame_feed_mouse_move(sd->main_frame, ev);
}

static Eina_Bool _ewk_view_smart_key_down(Ewk_View_Smart_Data* sd, const Evas_Event_Key_Down* ev)
{
    Evas_Object* frame = ewk_view_frame_focused_get(sd->self);

    if (!frame)
        frame = sd->main_frame;

    return ewk_frame_feed_key_down(frame, ev);
}

static Eina_Bool _ewk_view_smart_key_up(Ewk_View_Smart_Data* sd, const Evas_Event_Key_Up* ev)
{
    Evas_Object* frame = ewk_view_frame_focused_get(sd->self);

    if (!frame)
        frame = sd->main_frame;

    return ewk_frame_feed_key_up(frame, ev);
}

static void _ewk_view_smart_add_console_message(Ewk_View_Smart_Data* sd, const char* message, unsigned int lineNumber, const char* sourceID)
{
    INF("console message: %s @%d: %s\n", sourceID, lineNumber, message);
}

static void _ewk_view_smart_run_javascript_alert(Ewk_View_Smart_Data* sd, Evas_Object* frame, const char* message)
{
    INF("javascript alert: %s\n", message);
}

static Eina_Bool _ewk_view_smart_run_javascript_confirm(Ewk_View_Smart_Data* sd, Evas_Object* frame, const char* message)
{
    INF("javascript confirm: %s", message);
    INF("javascript confirm (HARD CODED)? YES");
    return EINA_TRUE;
}

static Eina_Bool _ewk_view_smart_should_interrupt_javascript(Ewk_View_Smart_Data* sd)
{
    INF("should interrupt javascript?\n"
            "\t(HARD CODED) NO");
    return EINA_FALSE;
}

static Eina_Bool _ewk_view_smart_run_javascript_prompt(Ewk_View_Smart_Data* sd, Evas_Object* frame, const char* message, const char* defaultValue, char** value)
{
    *value = strdup("test");
    Eina_Bool ret = EINA_TRUE;
    INF("javascript prompt:\n"
            "\t      message: %s\n"
            "\tdefault value: %s\n"
            "\tgiving answer: %s\n"
            "\t       button: %s", message, defaultValue, *value, ret?"ok":"cancel");

    return ret;
}

// Event Handling //////////////////////////////////////////////////////
static void _ewk_view_on_focus_in(void* data, Evas* e, Evas_Object* o, void* event_info)
{
    Ewk_View_Smart_Data* sd = (Ewk_View_Smart_Data*)data;
    EINA_SAFETY_ON_NULL_RETURN(sd->api);
    EINA_SAFETY_ON_NULL_RETURN(sd->api->focus_in);
    sd->api->focus_in(sd);
}

static void _ewk_view_on_focus_out(void* data, Evas* e, Evas_Object* o, void* event_info)
{
    Ewk_View_Smart_Data* sd = (Ewk_View_Smart_Data*)data;
    EINA_SAFETY_ON_NULL_RETURN(sd->api);
    EINA_SAFETY_ON_NULL_RETURN(sd->api->focus_out);
    sd->api->focus_out(sd);
}

static void _ewk_view_on_mouse_wheel(void* data, Evas* e, Evas_Object* o, void* event_info)
{
    Evas_Event_Mouse_Wheel* ev = (Evas_Event_Mouse_Wheel*)event_info;
    Ewk_View_Smart_Data* sd = (Ewk_View_Smart_Data*)data;
    EINA_SAFETY_ON_NULL_RETURN(sd->api);
    EINA_SAFETY_ON_NULL_RETURN(sd->api->mouse_wheel);
    sd->api->mouse_wheel(sd, ev);
}

static void _ewk_view_on_mouse_down(void* data, Evas* e, Evas_Object* o, void* event_info)
{
    Evas_Event_Mouse_Down* ev = (Evas_Event_Mouse_Down*)event_info;
    Ewk_View_Smart_Data* sd = (Ewk_View_Smart_Data*)data;
    EINA_SAFETY_ON_NULL_RETURN(sd->api);
    EINA_SAFETY_ON_NULL_RETURN(sd->api->mouse_down);
    sd->api->mouse_down(sd, ev);
}

static void _ewk_view_on_mouse_up(void* data, Evas* e, Evas_Object* o, void* event_info)
{
    Evas_Event_Mouse_Up* ev = (Evas_Event_Mouse_Up*)event_info;
    Ewk_View_Smart_Data* sd = (Ewk_View_Smart_Data*)data;
    EINA_SAFETY_ON_NULL_RETURN(sd->api);
    EINA_SAFETY_ON_NULL_RETURN(sd->api->mouse_up);
    sd->api->mouse_up(sd, ev);
}

static void _ewk_view_on_mouse_move(void* data, Evas* e, Evas_Object* o, void* event_info)
{
    Evas_Event_Mouse_Move* ev = (Evas_Event_Mouse_Move*)event_info;
    Ewk_View_Smart_Data* sd = (Ewk_View_Smart_Data*)data;
    EINA_SAFETY_ON_NULL_RETURN(sd->api);
    EINA_SAFETY_ON_NULL_RETURN(sd->api->mouse_move);
    sd->api->mouse_move(sd, ev);
}

static void _ewk_view_on_key_down(void* data, Evas* e, Evas_Object* o, void* event_info)
{
    Evas_Event_Key_Down* ev = (Evas_Event_Key_Down*)event_info;
    Ewk_View_Smart_Data* sd = (Ewk_View_Smart_Data*)data;
    EINA_SAFETY_ON_NULL_RETURN(sd->api);
    EINA_SAFETY_ON_NULL_RETURN(sd->api->key_down);
    sd->api->key_down(sd, ev);
}

static void _ewk_view_on_key_up(void* data, Evas* e, Evas_Object* o, void* event_info)
{
    Evas_Event_Key_Up* ev = (Evas_Event_Key_Up*)event_info;
    Ewk_View_Smart_Data* sd = (Ewk_View_Smart_Data*)data;
    EINA_SAFETY_ON_NULL_RETURN(sd->api);
    EINA_SAFETY_ON_NULL_RETURN(sd->api->key_up);
    sd->api->key_up(sd, ev);
}

static WTF::PassRefPtr<WebCore::Frame> _ewk_view_core_frame_new(Ewk_View_Smart_Data* sd, Ewk_View_Private_Data* priv, WebCore::HTMLFrameOwnerElement* owner)
{
    WebCore::FrameLoaderClientEfl* flc = new WebCore::FrameLoaderClientEfl(sd->self);
    if (!flc) {
        CRITICAL("Could not create frame loader client.");
        return 0;
    }
    flc->setCustomUserAgent(WTF::String::fromUTF8(priv->settings.user_agent));

    return WebCore::Frame::create(priv->page, owner, flc);
}

static Evas_Smart_Class _parent_sc = EVAS_SMART_CLASS_INIT_NULL;

static Ewk_View_Private_Data* _ewk_view_priv_new(Ewk_View_Smart_Data* sd)
{
    Ewk_View_Private_Data* priv =
        (Ewk_View_Private_Data*)calloc(1, sizeof(Ewk_View_Private_Data));
    WTF::AtomicString s;
    WebCore::KURL url;

    if (!priv) {
        CRITICAL("could not allocate Ewk_View_Private_Data");
        return 0;
    }

    WebCore::Page::PageClients pageClients;
    pageClients.chromeClient = static_cast<WebCore::ChromeClient*>(new WebCore::ChromeClientEfl(sd->self));
    pageClients.contextMenuClient = static_cast<WebCore::ContextMenuClient*>(new WebCore::ContextMenuClientEfl(sd->self));
    pageClients.editorClient = static_cast<WebCore::EditorClient*>(new WebCore::EditorClientEfl(sd->self));
    pageClients.dragClient = static_cast<WebCore::DragClient*>(new WebCore::DragClientEfl);
    pageClients.inspectorClient = static_cast<WebCore::InspectorClient*>(new WebCore::InspectorClientEfl);
    priv->page = new WebCore::Page(pageClients);
    if (!priv->page) {
        CRITICAL("Could not create WebKit Page");
        goto error_page;
    }

    priv->page_settings = priv->page->settings();
    if (!priv->page_settings) {
        CRITICAL("Could not get page settings.");
        goto error_settings;
    }

    priv->page_settings->setLoadsImagesAutomatically(true);
    priv->page_settings->setDefaultFixedFontSize(12);
    priv->page_settings->setDefaultFontSize(16);
    priv->page_settings->setSerifFontFamily("serif");
    priv->page_settings->setFixedFontFamily("monotype");
    priv->page_settings->setSansSerifFontFamily("sans");
    priv->page_settings->setStandardFontFamily("sans");
    priv->page_settings->setJavaScriptEnabled(true);
    priv->page_settings->setPluginsEnabled(true);
    priv->page_settings->setLocalStorageEnabled(true);
    priv->page_settings->setOfflineWebApplicationCacheEnabled(true);

    url = priv->page_settings->userStyleSheetLocation();
    priv->settings.user_stylesheet = eina_stringshare_add(url.prettyURL().utf8().data());

    priv->settings.encoding_default = eina_stringshare_add
        (priv->page_settings->defaultTextEncodingName().utf8().data());
    priv->settings.encoding_custom = 0;

    priv->settings.cache_directory = eina_stringshare_add
        (WebCore::cacheStorage().cacheDirectory().utf8().data());

    priv->settings.font_minimum_size = priv->page_settings->minimumFontSize();
    priv->settings.font_minimum_logical_size = priv->page_settings->minimumLogicalFontSize();
    priv->settings.font_default_size = priv->page_settings->defaultFontSize();
    priv->settings.font_monospace_size = priv->page_settings->defaultFixedFontSize();

    s = priv->page_settings->standardFontFamily();
    priv->settings.font_standard = eina_stringshare_add(s.string().utf8().data());
    s = priv->page_settings->cursiveFontFamily();
    priv->settings.font_cursive = eina_stringshare_add(s.string().utf8().data());
    s = priv->page_settings->fixedFontFamily();
    priv->settings.font_monospace = eina_stringshare_add(s.string().utf8().data());
    s = priv->page_settings->fantasyFontFamily();
    priv->settings.font_fantasy = eina_stringshare_add(s.string().utf8().data());
    s = priv->page_settings->serifFontFamily();
    priv->settings.font_serif = eina_stringshare_add(s.string().utf8().data());
    s = priv->page_settings->sansSerifFontFamily();
    priv->settings.font_sans_serif = eina_stringshare_add(s.string().utf8().data());

    priv->settings.auto_load_images = priv->page_settings->loadsImagesAutomatically();
    priv->settings.auto_shrink_images = priv->page_settings->shrinksStandaloneImagesToFit();
    priv->settings.enable_scripts = priv->page_settings->isJavaScriptEnabled();
    priv->settings.enable_plugins = priv->page_settings->arePluginsEnabled();
    priv->settings.enable_frame_flattening = priv->page_settings->frameFlatteningEnabled();
    priv->settings.scripts_window_open = priv->page_settings->allowScriptsToCloseWindows();
    priv->settings.resizable_textareas = priv->page_settings->textAreasAreResizable();
    priv->settings.private_browsing = priv->page_settings->privateBrowsingEnabled();
    priv->settings.caret_browsing = priv->page_settings->caretBrowsingEnabled();
    priv->settings.local_storage = priv->page_settings->localStorageEnabled();
    priv->settings.offline_app_cache = true; // XXX no function to read setting; this keeps the original setting

    // Since there's no scale separated from zooming in webkit-efl, this functionality of
    // viewport meta tag is implemented using zoom. When scale zoom is supported by webkit-efl,
    // this functionality will be modified by the scale zoom patch.
    priv->settings.zoom_range.min_scale = ZOOM_MIN;
    priv->settings.zoom_range.max_scale = ZOOM_MAX;
    priv->settings.zoom_range.user_scalable = EINA_TRUE;

    priv->main_frame = _ewk_view_core_frame_new(sd, priv, 0).get();
    if (!priv->main_frame) {
        CRITICAL("Could not create main frame.");
        goto error_main_frame;
    }

    priv->history = ewk_history_new(priv->page->backForwardList());
    if (!priv->history) {
        CRITICAL("Could not create history instance for view.");
        goto error_history;
    }

    return priv;

error_history:
    // delete priv->main_frame; /* do not delete priv->main_frame */
error_main_frame:
error_settings:
    delete priv->page;
error_page:
    free(priv);
    return 0;
}

static void _ewk_view_priv_del(Ewk_View_Private_Data* priv)
{
    if (!priv)
        return;

    /* do not delete priv->main_frame */

    free(priv->repaints.array);
    free(priv->scrolls.array);

    eina_stringshare_del(priv->settings.user_agent);
    eina_stringshare_del(priv->settings.user_stylesheet);
    eina_stringshare_del(priv->settings.encoding_default);
    eina_stringshare_del(priv->settings.encoding_custom);
    eina_stringshare_del(priv->settings.cache_directory);
    eina_stringshare_del(priv->settings.font_standard);
    eina_stringshare_del(priv->settings.font_cursive);
    eina_stringshare_del(priv->settings.font_monospace);
    eina_stringshare_del(priv->settings.font_fantasy);
    eina_stringshare_del(priv->settings.font_serif);
    eina_stringshare_del(priv->settings.font_sans_serif);

    if (priv->animated_zoom.animator)
        ecore_animator_del(priv->animated_zoom.animator);

    ewk_history_free(priv->history);

    delete priv->page;
    free(priv);
}

static void _ewk_view_smart_add(Evas_Object* o)
{
    const Evas_Smart* smart = evas_object_smart_smart_get(o);
    const Evas_Smart_Class* sc = evas_smart_class_get(smart);
    const Ewk_View_Smart_Class* api = (const Ewk_View_Smart_Class*)sc;
    EINA_SAFETY_ON_NULL_RETURN(api->backing_store_add);
    EWK_VIEW_SD_GET(o, sd);

    if (!sd) {
        sd = (Ewk_View_Smart_Data*)calloc(1, sizeof(Ewk_View_Smart_Data));
        if (!sd)
            CRITICAL("could not allocate Ewk_View_Smart_Data");
        else
            evas_object_smart_data_set(o, sd);
    }

    sd->bg_color.r = 255;
    sd->bg_color.g = 255;
    sd->bg_color.b = 255;
    sd->bg_color.a = 255;

    sd->self = o;
    sd->_priv = _ewk_view_priv_new(sd);
    sd->api = api;

    _parent_sc.add(o);

    if (!sd->_priv)
        return;

    EWK_VIEW_PRIV_GET(sd, priv);

    sd->backing_store = api->backing_store_add(sd);
    if (!sd->backing_store) {
        ERR("Could not create backing store object.");
        return;
    }

    evas_object_smart_member_add(sd->backing_store, o);
    evas_object_show(sd->backing_store);

    sd->main_frame = ewk_frame_add(sd->base.evas);
    if (!sd->main_frame) {
        ERR("Could not create main frame object.");
        return;
    }

    if (!ewk_frame_init(sd->main_frame, o, priv->main_frame)) {
        ERR("Could not initialize main frme object.");
        evas_object_del(sd->main_frame);
        sd->main_frame = 0;

        delete priv->main_frame;
        priv->main_frame = 0;
        return;
    }

    evas_object_name_set(sd->main_frame, "EWK_Frame:main");
    evas_object_smart_member_add(sd->main_frame, o);
    evas_object_show(sd->main_frame);

#define CONNECT(s, c) evas_object_event_callback_add(o, s, c, sd)
    CONNECT(EVAS_CALLBACK_FOCUS_IN, _ewk_view_on_focus_in);
    CONNECT(EVAS_CALLBACK_FOCUS_OUT, _ewk_view_on_focus_out);
    CONNECT(EVAS_CALLBACK_MOUSE_WHEEL, _ewk_view_on_mouse_wheel);
    CONNECT(EVAS_CALLBACK_MOUSE_DOWN, _ewk_view_on_mouse_down);
    CONNECT(EVAS_CALLBACK_MOUSE_UP, _ewk_view_on_mouse_up);
    CONNECT(EVAS_CALLBACK_MOUSE_MOVE, _ewk_view_on_mouse_move);
    CONNECT(EVAS_CALLBACK_KEY_DOWN, _ewk_view_on_key_down);
    CONNECT(EVAS_CALLBACK_KEY_UP, _ewk_view_on_key_up);
#undef CONNECT
}

static void _ewk_view_smart_del(Evas_Object* o)
{
    EWK_VIEW_SD_GET(o, sd);
    Ewk_View_Private_Data* priv = sd ? sd->_priv : 0;

    ewk_view_stop(o);
    _parent_sc.del(o);
    _ewk_view_priv_del(priv);
}

static void _ewk_view_smart_resize(Evas_Object* o, Evas_Coord w, Evas_Coord h)
{
    EWK_VIEW_SD_GET(o, sd);

    // these should be queued and processed in calculate as well!
    evas_object_resize(sd->backing_store, w, h);

    sd->changed.size = EINA_TRUE;
    _ewk_view_smart_changed(sd);
}

static void _ewk_view_smart_move(Evas_Object* o, Evas_Coord x, Evas_Coord y)
{
    EWK_VIEW_SD_GET(o, sd);
    sd->changed.position = EINA_TRUE;
    _ewk_view_smart_changed(sd);
}

static void _ewk_view_smart_calculate(Evas_Object* o)
{
    EWK_VIEW_SD_GET(o, sd);
    EWK_VIEW_PRIV_GET(sd, priv);
    EINA_SAFETY_ON_NULL_RETURN(sd->api->contents_resize);
    EINA_SAFETY_ON_NULL_RETURN(sd->api->scrolls_process);
    EINA_SAFETY_ON_NULL_RETURN(sd->api->repaints_process);
    Evas_Coord x, y, w, h;

    sd->changed.any = EINA_FALSE;

    if (!sd->main_frame || !priv->main_frame)
        return;

    evas_object_geometry_get(o, &x, &y, &w, &h);

    DBG("o=%p geo=[%d, %d + %dx%d], changed: size=%hhu, "
        "scrolls=%zu, repaints=%zu",
        o, x, y, w, h, sd->changed.size,
        priv->scrolls.count, priv->repaints.count);

    if (sd->changed.size && ((w != sd->view.w) || (h != sd->view.h))) {
        WebCore::FrameView* view = priv->main_frame->view();
        if (view) {
            view->resize(w, h);
            view->forceLayout();
            view->adjustViewSize();
            IntSize size = view->contentsSize();
            if (!sd->api->contents_resize(sd, size.width(), size.height()))
                ERR("failed to resize contents to %dx%d",
                    size.width(), size.height());
        }
        evas_object_resize(sd->main_frame, w, h);
        sd->changed.frame_rect = EINA_TRUE;
        sd->view.w = w;
        sd->view.h = h;

        // This callback is a good place e.g. to change fixed layout size (ewk_view_fixed_layout_size_set).
        evas_object_smart_callback_call(o, "view,resized", 0);
    }
    sd->changed.size = EINA_FALSE;

    if (sd->changed.position && ((x != sd->view.x) || (y != sd->view.y))) {
        evas_object_move(sd->main_frame, x, y);
        evas_object_move(sd->backing_store, x, y);
        sd->changed.frame_rect = EINA_TRUE;
        sd->view.x = x;
        sd->view.y = y;
    }
    sd->changed.position = EINA_FALSE;

    ewk_view_layout_if_needed_recursive(sd->_priv);

    if (!sd->api->scrolls_process(sd))
        ERR("failed to process scrolls.");
    _ewk_view_scrolls_flush(priv);

    if (!sd->api->repaints_process(sd))
        ERR("failed to process repaints.");
    _ewk_view_repaints_flush(priv);

    if (sd->changed.frame_rect) {
        WebCore::FrameView* view = priv->main_frame->view();
        view->frameRectsChanged(); /* force tree to get position from root */
        sd->changed.frame_rect = EINA_FALSE;
    }
}

static Eina_Bool _ewk_view_smart_contents_resize(Ewk_View_Smart_Data* sd, int w, int h)
{
    return EINA_TRUE;
}

static Eina_Bool _ewk_view_smart_zoom_set(Ewk_View_Smart_Data* sd, float zoom, Evas_Coord cx, Evas_Coord cy)
{
    double px, py;
    Evas_Coord x, y, w, h;
    Eina_Bool ret;

    ewk_frame_scroll_size_get(sd->main_frame, &w, &h);
    ewk_frame_scroll_pos_get(sd->main_frame, &x, &y);

    if (w + sd->view.w > 0)
        px = (double)(x + cx) / (w + sd->view.w);
    else
        px = 0.0;

    if (h + sd->view.h > 0)
        py = (double)(y + cy) / (h + sd->view.h);
    else
        py = 0.0;

    ret = ewk_frame_zoom_set(sd->main_frame, zoom);

    ewk_frame_scroll_size_get(sd->main_frame, &w, &h);
    x = (w + sd->view.w) * px - cx;
    y = (h + sd->view.h) * py - cy;
    ewk_frame_scroll_set(sd->main_frame, x, y);
    return ret;
}

static void _ewk_view_smart_flush(Ewk_View_Smart_Data* sd)
{
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv);
    _ewk_view_repaints_flush(priv);
    _ewk_view_scrolls_flush(priv);
}

static Eina_Bool _ewk_view_smart_pre_render_region(Ewk_View_Smart_Data* sd, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h, float zoom)
{
    WRN("not supported by engine. sd=%p area=%d,%d+%dx%d, zoom=%f",
        sd, x, y, w, h, zoom);
    return EINA_FALSE;
}

static void _ewk_view_smart_pre_render_cancel(Ewk_View_Smart_Data* sd)
{
    WRN("not supported by engine. sd=%p", sd);
}

static void _ewk_view_zoom_animated_mark_stop(Ewk_View_Smart_Data* sd)
{
    sd->animated_zoom.zoom.start = 0.0;
    sd->animated_zoom.zoom.end = 0.0;
    sd->animated_zoom.zoom.current = 0.0;
}

static void _ewk_view_zoom_animated_finish(Ewk_View_Smart_Data* sd)
{
    EWK_VIEW_PRIV_GET(sd, priv);
    ecore_animator_del(priv->animated_zoom.animator);
    priv->animated_zoom.animator = 0;
    _ewk_view_zoom_animated_mark_stop(sd);
    evas_object_smart_callback_call(sd->self, "zoom,animated,end", 0);
}

static float _ewk_view_zoom_animated_current(Ewk_View_Private_Data* priv)
{
    double now = ecore_loop_time_get();
    double delta = now - priv->animated_zoom.time.start;

    if (delta > priv->animated_zoom.time.duration)
        delta = priv->animated_zoom.time.duration;
    if (delta < 0.0) // time went back, clock adjusted?
        delta = 0.0;

    delta /= priv->animated_zoom.time.duration;

    return ((priv->animated_zoom.zoom.range * delta)
            + priv->animated_zoom.zoom.start);
}

static Eina_Bool _ewk_view_zoom_animator_cb(void* data)
{
    Ewk_View_Smart_Data* sd = (Ewk_View_Smart_Data*)data;
    Evas_Coord cx, cy;
    EWK_VIEW_PRIV_GET(sd, priv);
    double now = ecore_loop_time_get();

    cx = priv->animated_zoom.center.x;
    cy = priv->animated_zoom.center.y;

    // TODO: progressively center (cx, cy) -> (view.x + view.h/2, view.y + view.h/2)
    if (cx >= sd->view.w)
        cx = sd->view.w - 1;
    if (cy >= sd->view.h)
        cy = sd->view.h - 1;

    if ((now >= priv->animated_zoom.time.end)
        || (now < priv->animated_zoom.time.start)) {
        _ewk_view_zoom_animated_finish(sd);
        ewk_view_zoom_set(sd->self, priv->animated_zoom.zoom.end, cx, cy);
        return EINA_FALSE;
    }

    sd->animated_zoom.zoom.current = _ewk_view_zoom_animated_current(priv);
    sd->api->zoom_weak_set(sd, sd->animated_zoom.zoom.current, cx, cy);
    return EINA_TRUE;
}

static void _ewk_view_zoom_animation_start(Ewk_View_Smart_Data* sd)
{
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv);
    if (priv->animated_zoom.animator)
        return;
    priv->animated_zoom.animator = ecore_animator_add
        (_ewk_view_zoom_animator_cb, sd);
}

/**
 * Sets the smart class api without any backing store, enabling view
 * to be inherited.
 *
 * @param api class definition to be set, all members with the
 *        exception of Evas_Smart_Class->data may be overridden. Must
 *        @b not be @c 0.
 *
 * @note Evas_Smart_Class->data is used to implement type checking and
 *       is not supposed to be changed/overridden. If you need extra
 *       data for your smart class to work, just extend
 *       Ewk_View_Smart_Class instead.
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE on failure (probably
 *         version mismatch).
 *
 * @see ewk_view_single_smart_set()
 * @see ewk_view_tiled_smart_set()
 */
Eina_Bool ewk_view_base_smart_set(Ewk_View_Smart_Class* api)
{
    EINA_SAFETY_ON_NULL_RETURN_VAL(api, EINA_FALSE);

    if (api->version != EWK_VIEW_SMART_CLASS_VERSION) {
        EINA_LOG_CRIT
            ("Ewk_View_Smart_Class %p is version %lu while %lu was expected.",
             api, api->version, EWK_VIEW_SMART_CLASS_VERSION);
        return EINA_FALSE;
    }

    if (EINA_UNLIKELY(!_parent_sc.add))
        evas_object_smart_clipped_smart_set(&_parent_sc);

    evas_object_smart_clipped_smart_set(&api->sc);
    api->sc.add = _ewk_view_smart_add;
    api->sc.del = _ewk_view_smart_del;
    api->sc.resize = _ewk_view_smart_resize;
    api->sc.move = _ewk_view_smart_move;
    api->sc.calculate = _ewk_view_smart_calculate;
    api->sc.data = EWK_VIEW_TYPE_STR; /* used by type checking */

    api->contents_resize = _ewk_view_smart_contents_resize;
    api->zoom_set = _ewk_view_smart_zoom_set;
    api->flush = _ewk_view_smart_flush;
    api->pre_render_region = _ewk_view_smart_pre_render_region;
    api->pre_render_cancel = _ewk_view_smart_pre_render_cancel;

    api->focus_in = _ewk_view_smart_focus_in;
    api->focus_out = _ewk_view_smart_focus_out;
    api->mouse_wheel = _ewk_view_smart_mouse_wheel;
    api->mouse_down = _ewk_view_smart_mouse_down;
    api->mouse_up = _ewk_view_smart_mouse_up;
    api->mouse_move = _ewk_view_smart_mouse_move;
    api->key_down = _ewk_view_smart_key_down;
    api->key_up = _ewk_view_smart_key_up;

    api->add_console_message = _ewk_view_smart_add_console_message;
    api->run_javascript_alert = _ewk_view_smart_run_javascript_alert;
    api->run_javascript_confirm = _ewk_view_smart_run_javascript_confirm;
    api->run_javascript_prompt = _ewk_view_smart_run_javascript_prompt;
    api->should_interrupt_javascript = _ewk_view_smart_should_interrupt_javascript;

    return EINA_TRUE;
}

/**
 * Set a fixed layout size to be used, dissociating it from viewport size.
 *
 * Setting a width different than zero enables fixed layout on that
 * size. It's automatically scaled based on zoom, but will not change
 * if viewport changes.
 *
 * Setting both @a w and @a h to zero will disable fixed layout.
 *
 * @param o view object to change fixed layout.
 * @param w fixed width to use. This size will be automatically scaled
 *        based on zoom level.
 * @param h fixed height to use. This size will be automatically scaled
 *        based on zoom level.
 */
void ewk_view_fixed_layout_size_set(Evas_Object* o, Evas_Coord w, Evas_Coord h)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv);

    WebCore::FrameLoaderClientEfl* client = static_cast<WebCore::FrameLoaderClientEfl*>(priv->main_frame->loader()->client());
    if (!client->getInitLayoutCompleted())
        return;

    WebCore::FrameView* view = sd->_priv->main_frame->view();
    if (w <= 0 && h <= 0) {
        if (!priv->fixed_layout.use)
            return;
        priv->fixed_layout.w = 0;
        priv->fixed_layout.h = 0;
        priv->fixed_layout.use = EINA_FALSE;
    } else {
        if (priv->fixed_layout.use
            && priv->fixed_layout.w == w && priv->fixed_layout.h == h)
            return;
        priv->fixed_layout.w = w;
        priv->fixed_layout.h = h;
        priv->fixed_layout.use = EINA_TRUE;

        if (view)
            view->setFixedLayoutSize(WebCore::IntSize(w, h));
    }

    if (!view)
        return;
    view->setUseFixedLayout(priv->fixed_layout.use);
    view->forceLayout();
}

/**
 * Get fixed layout size in use.
 *
 * @param o view object to query fixed layout size.
 * @param w where to return width. Returns 0 on error or if no fixed
 *        layout in use.
 * @param h where to return height. Returns 0 on error or if no fixed
 *        layout in use.
 */
void ewk_view_fixed_layout_size_get(Evas_Object* o, Evas_Coord* w, Evas_Coord* h)
{
    if (w)
        *w = 0;
    if (h)
        *h = 0;
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv);
    if (priv->fixed_layout.use) {
        if (w)
            *w = priv->fixed_layout.w;
        if (h)
            *h = priv->fixed_layout.h;
    }
}

/**
 * Set the theme path to be used by this view.
 *
 * This also sets the theme on the main frame. As frames inherit theme
 * from their parent, this will have all frames with unset theme to
 * use this one.
 *
 * @param o view object to change theme.
 * @param path theme path, may be @c 0 to reset to default.
 */
void ewk_view_theme_set(Evas_Object* o, const char* path)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    ewk_frame_theme_set(sd->main_frame, path);
}

/**
 * Gets the theme set on this frame.
 *
 * This returns the value set by ewk_view_theme_set().
 *
 * @param o view object to get theme path.
 *
 * @return theme path, may be @c 0 if not set.
 */
const char* ewk_view_theme_get(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    return ewk_frame_theme_get(sd->main_frame);
}

/**
 * Get the object that represents the main frame.
 *
 * @param o view object to get main frame.
 *
 * @return ewk_frame object or @c 0 if none yet.
 */
Evas_Object* ewk_view_frame_main_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    return sd->main_frame;
}

/**
 * Get the currently focused frame object.
 *
 * @param o view object to get focused frame.
 *
 * @return ewk_frame object or @c 0 if none yet.
 */
Evas_Object* ewk_view_frame_focused_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);

    WebCore::Frame* core = priv->page->focusController()->focusedFrame();
    if (!core)
        return 0;

    WebCore::FrameLoaderClientEfl* client = static_cast<WebCore::FrameLoaderClientEfl*>(core->loader()->client());
    if (!client)
        return 0;
    return client->webFrame();
}

/**
 * Ask main frame to load the given URI.
 *
 * @param o view object to load uri.
 * @param uri uniform resource identifier to load.
 *
 * @return @c EINA_TRUE on successful request, @c EINA_FALSE on failure.
 *         Note that it means the request was done, not that it was
 *         satisfied.
 */
Eina_Bool ewk_view_uri_set(Evas_Object* o, const char* uri)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return ewk_frame_uri_set(sd->main_frame, uri);
}

/**
 * Get the current uri loaded by main frame.
 *
 * @param o view object to get current uri.
 *
 * @return current uri reference or @c 0. It's internal, don't change.
 */
const char* ewk_view_uri_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    return ewk_frame_uri_get(sd->main_frame);
}

/**
 * Get the current title of main frame.
 *
 * @param o view object to get current title.
 *
 * @return current title reference or @c 0. It's internal, don't change.
 */
const char* ewk_view_title_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    return ewk_frame_title_get(sd->main_frame);
}

/**
 * Gets if main frame is editable.
 *
 * @param o view object to get editable state.
 *
 * @return @c EINA_TRUE if editable, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_editable_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return ewk_frame_editable_get(sd->main_frame);
}

/**
 * Set background color and transparency
 *
 * Just as in Evas, colors are pre-multiplied, so 50% red is
 * (128, 0, 0, 128) and not (255, 0, 0, 128)!
 *
 * @warning Watch out performance issues with transparency! Object
 *          will be handled as transparent image by evas even if the
 *          webpage specifies a background color. That mean you'll pay
 *          a price even if it's not really transparent, thus
 *          scrolling/panning and zooming will be likely slower than
 *          if transparency is off.
 *
 * @param o view object to change.
 * @param r red component.
 * @param g green component.
 * @param b blue component.
 * @param a transparency.
 */
void ewk_view_bg_color_set(Evas_Object* o, int r, int g, int b, int a)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    EINA_SAFETY_ON_NULL_RETURN(sd->api);
    EINA_SAFETY_ON_NULL_RETURN(sd->api->bg_color_set);

    if (a < 0) {
        WRN("Alpha less than zero (%d).", a);
        a = 0;
    } else if (a > 255) {
        WRN("Alpha is larger than 255 (%d).", a);
        a = 255;
    }

#define CHECK_PREMUL_COLOR(c, a)                                        \
    if (c < 0) {                                                        \
        WRN("Color component "#c" is less than zero (%d).", c);         \
        c = 0;                                                          \
    } else if (c > a) {                                                 \
        WRN("Color component "#c" is greater than alpha (%d, alpha=%d).", \
            c, a);                                                      \
        c = a;                                                          \
    }
    CHECK_PREMUL_COLOR(r, a);
    CHECK_PREMUL_COLOR(g, a);
    CHECK_PREMUL_COLOR(b, a);
#undef CHECK_PREMUL_COLOR

    sd->bg_color.r = r;
    sd->bg_color.g = g;
    sd->bg_color.b = b;
    sd->bg_color.a = a;

    sd->api->bg_color_set(sd, r, g, b, a);

    WebCore::FrameView* view = sd->_priv->main_frame->view();
    if (view) {
        WebCore::Color color;

        if (!a)
            color = WebCore::Color(0, 0, 0, 0);
        else if (a == 255)
            color = WebCore::Color(r, g, b, a);
        else
            color = WebCore::Color(r * 255 / a, g * 255 / a, b * 255 / a, a);

        view->updateBackgroundRecursively(color, !a);
    }
}

/**
 * Query if view object background color.
 *
 * Just as in Evas, colors are pre-multiplied, so 50% red is
 * (128, 0, 0, 128) and not (255, 0, 0, 128)!
 *
 * @param o view object to query.
 * @param r where to return red color component.
 * @param g where to return green color component.
 * @param b where to return blue color component.
 * @param a where to return alpha value.
 */
void ewk_view_bg_color_get(const Evas_Object* o, int* r, int* g, int* b, int* a)
{
    if (r)
        *r = 0;
    if (g)
        *g = 0;
    if (b)
        *b = 0;
    if (a)
        *a = 0;
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    if (r)
        *r = sd->bg_color.r;
    if (g)
        *g = sd->bg_color.g;
    if (b)
        *b = sd->bg_color.b;
    if (a)
        *a = sd->bg_color.a;
}

/**
 * Search the given text string in document.
 *
 * @param o view object where to search text.
 * @param string reference string to search.
 * @param case_sensitive if search should be case sensitive or not.
 * @param forward if search is from cursor and on or backwards.
 * @param wrap if search should wrap at end.
 *
 * @return @c EINA_TRUE if found, @c EINA_FALSE if not or failure.
 */
Eina_Bool ewk_view_text_search(const Evas_Object* o, const char* string, Eina_Bool case_sensitive, Eina_Bool forward, Eina_Bool wrap)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(string, EINA_FALSE);
    WTF::TextCaseSensitivity sensitive;
    WebCore::FindDirection direction;

    if (case_sensitive)
        sensitive = WTF::TextCaseSensitive;
    else
        sensitive = WTF::TextCaseInsensitive;

    if (forward)
        direction = WebCore::FindDirectionForward;
    else
        direction = WebCore::FindDirectionBackward;

    return priv->page->findString(WTF::String::fromUTF8(string), sensitive, direction, wrap);
}

/**
 * Mark matches the given text string in document.
 *
 * @param o view object where to search text.
 * @param string reference string to match.
 * @param case_sensitive if match should be case sensitive or not.
 * @param highlight if matches should be highlighted.
 * @param limit maximum amount of matches, or zero to unlimited.
 *
 * @return number of matches.
 */
unsigned int ewk_view_text_matches_mark(Evas_Object* o, const char* string, Eina_Bool case_sensitive, Eina_Bool highlight, unsigned int limit)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(string, 0);
    WTF::TextCaseSensitivity sensitive;

    if (case_sensitive)
        sensitive = WTF::TextCaseSensitive;
    else
        sensitive = WTF::TextCaseInsensitive;

    return priv->page->markAllMatchesForText(WTF::String::fromUTF8(string), sensitive, highlight, limit);
}

/**
 * Reverses the effect of ewk_view_text_matches_mark()
 *
 * @param o view object where to search text.
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE for failure.
 */
Eina_Bool ewk_view_text_matches_unmark_all(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    priv->page->unmarkAllTextMatches();
    return EINA_TRUE;
}

/**
 * Set if should highlight matches marked with ewk_view_text_matches_mark().
 *
 * @param o view object where to set if matches are highlighted or not.
 * @param highlight if @c EINA_TRUE, matches will be highlighted.
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE for failure.
 */
Eina_Bool ewk_view_text_matches_highlight_set(Evas_Object* o, Eina_Bool highlight)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return ewk_frame_text_matches_highlight_set(sd->main_frame, highlight);
}

/**
 * Get if should highlight matches marked with ewk_view_text_matches_mark().
 *
 * @param o view object to query if matches are highlighted or not.
 *
 * @return @c EINA_TRUE if they are highlighted, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_text_matches_highlight_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return ewk_frame_text_matches_highlight_get(sd->main_frame);
}

/**
 * Sets if main frame is editable.
 *
 * @param o view object to set editable state.
 * @param editable new state.
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_editable_set(Evas_Object* o, Eina_Bool editable)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return ewk_frame_editable_set(sd->main_frame, editable);
}

/**
 * Get the copy of the selection text.
 *
 * @param o view object to get selection text.
 *
 * @return newly allocated string or @c 0 if nothing is selected or failure.
 */
char* ewk_view_selection_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    WTF::CString s = priv->page->focusController()->focusedOrMainFrame()->editor()->selectedText().utf8();
    if (s.isNull())
        return 0;
    return strdup(s.data());
}

static Eina_Bool _ewk_view_editor_command(Ewk_View_Private_Data* priv, const char* command)
{
    return priv->page->focusController()->focusedOrMainFrame()->editor()->command(WTF::String::fromUTF8(command)).execute();
}

/**
 * Unselects whatever was selected.
 *
 * @return @c EINA_TRUE if operation was executed, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_select_none(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return _ewk_view_editor_command(priv, "Unselect");
}

/**
 * Selects everything.
 *
 * @return @c EINA_TRUE if operation was executed, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_select_all(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return _ewk_view_editor_command(priv, "SelectAll");
}

/**
 * Selects the current paragrah.
 *
 * @return @c EINA_TRUE if operation was executed, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_select_paragraph(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return _ewk_view_editor_command(priv, "SelectParagraph");
}

/**
 * Selects the current sentence.
 *
 * @return @c EINA_TRUE if operation was executed, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_select_sentence(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return _ewk_view_editor_command(priv, "SelectSentence");
}

/**
 * Selects the current line.
 *
 * @return @c EINA_TRUE if operation was executed, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_select_line(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return _ewk_view_editor_command(priv, "SelectLine");
}

/**
 * Selects the current word.
 *
 * @return @c EINA_TRUE if operation was executed, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_select_word(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return _ewk_view_editor_command(priv, "SelectWord");
}

/**
 * Forwards a request of new Context Menu to WebCore.
 *
 * @param o View.
 * @param ev Event data.
 *
 * @return @c EINA_TRUE if operation was executed, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_context_menu_forward_event(Evas_Object* o, const Evas_Event_Mouse_Down* ev)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    Eina_Bool mouse_press_handled = EINA_FALSE;

    priv->page->contextMenuController()->clearContextMenu();
    WebCore::Frame* main_frame = priv->page->mainFrame();
    Evas_Coord x, y;
    evas_object_geometry_get(sd->self, &x, &y, 0, 0);

    WebCore::PlatformMouseEvent event(ev, WebCore::IntPoint(x, y));

    if (main_frame->view()) {
        mouse_press_handled =
            main_frame->eventHandler()->handleMousePressEvent(event);
    }

    if (main_frame->eventHandler()->sendContextMenuEvent(event))
        return EINA_FALSE;

    WebCore::ContextMenu* coreMenu =
        priv->page->contextMenuController()->contextMenu();
    if (!coreMenu) {
        // WebCore decided not to create a context menu, return true if event
        // was handled by handleMouseReleaseEvent
        return mouse_press_handled;
    }

    return EINA_TRUE;
}

/**
 * Get current load progress estimate from 0.0 to 1.0.
 *
 * @param o view object to get current progress.
 *
 * @return progres value from 0.0 to 1.0 or -1.0 on error.
 */
double ewk_view_load_progress_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, -1.0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, -1.0);
    return priv->page->progress()->estimatedProgress();
}

/**
 * Ask main frame to stop loading.
 *
 * @param o view object to stop loading.
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 *
 * @see ewk_frame_stop()
 */
Eina_Bool ewk_view_stop(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return ewk_frame_stop(sd->main_frame);
}

/**
 * Ask main frame to reload current document.
 *
 * @param o view object to reload.
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 *
 * @see ewk_frame_reload()
 */
Eina_Bool ewk_view_reload(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return ewk_frame_reload(sd->main_frame);
}

/**
 * Ask main frame to fully reload current document, using no caches.
 *
 * @param o view object to reload.
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 *
 * @see ewk_frame_reload_full()
 */
Eina_Bool ewk_view_reload_full(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return ewk_frame_reload_full(sd->main_frame);
}

/**
 * Ask main frame to navigate back in history.
 *
 * @param o view object to navigate back.
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 *
 * @see ewk_frame_back()
 */
Eina_Bool ewk_view_back(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return ewk_frame_back(sd->main_frame);
}

/**
 * Ask main frame to navigate forward in history.
 *
 * @param o view object to navigate forward.
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 *
 * @see ewk_frame_forward()
 */
Eina_Bool ewk_view_forward(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return ewk_frame_forward(sd->main_frame);
}

/**
 * Navigate back or forward in history.
 *
 * @param o view object to navigate.
 * @param steps if positive navigates that amount forwards, if negative
 *        does backwards.
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 *
 * @see ewk_frame_navigate()
 */
Eina_Bool ewk_view_navigate(Evas_Object* o, int steps)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return ewk_frame_navigate(sd->main_frame, steps);
}

/**
 * Check if it is possible to navigate backwards one item in history.
 *
 * @param o view object to check if backward navigation is possible.
 *
 * @return @c EINA_TRUE if possible, @c EINA_FALSE otherwise.
 *
 * @see ewk_view_navigate_possible()
 */
Eina_Bool ewk_view_back_possible(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return ewk_frame_back_possible(sd->main_frame);
}

/**
 * Check if it is possible to navigate forwards one item in history.
 *
 * @param o view object to check if forward navigation is possible.
 *
 * @return @c EINA_TRUE if possible, @c EINA_FALSE otherwise.
 *
 * @see ewk_view_navigate_possible()
 */
Eina_Bool ewk_view_forward_possible(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return ewk_frame_forward_possible(sd->main_frame);
}

/**
 * Check if it is possible to navigate given @a steps in history.
 *
 * @param o view object to navigate.
 * @param steps if positive navigates that amount forwards, if negative
 *        does backwards.
 *
 * @return @c EINA_TRUE if possible, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_navigate_possible(Evas_Object* o, int steps)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return ewk_frame_navigate_possible(sd->main_frame, steps);
}

/**
 * Check if navigation history (back-forward lists) is enabled.
 *
 * @param o view object to check if navigation history is enabled.
 *
 * @return @c EINA_TRUE if view keeps history, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_history_enable_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return priv->page->backForwardList()->enabled();
}

/**
 * Sets if navigation history (back-forward lists) is enabled.
 *
 * @param o view object to set if navigation history is enabled.
 * @param enable @c EINA_TRUE if we want to enable navigation history;
 * @c EINA_FALSE otherwise.
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_history_enable_set(Evas_Object* o, Eina_Bool enable)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    priv->page->backForwardList()->setEnabled(enable);
    return EINA_TRUE;
}

/**
 * Gets the history (back-forward list) associated with this view.
 *
 * @param o view object to get navigation history from.
 *
 * @return returns the history instance handle associated with this
 *         view or @c 0 on errors (including when history is not
 *         enabled with ewk_view_history_enable_set()). This instance
 *         is unique for this view and thus multiple calls to this
 *         function with the same view as parameter returns the same
 *         handle. This handle is alive while view is alive, thus one
 *         might want to listen for EVAS_CALLBACK_DEL on given view
 *         (@a o) to know when to stop using returned handle.
 *
 * @see ewk_view_history_enable_set()
 */
Ewk_History* ewk_view_history_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    if (!priv->page->backForwardList()->enabled()) {
        ERR("asked history, but it's disabled! Returning 0!");
        return 0;
    }
    return priv->history;
}

/**
 * Get the current zoom level of main frame.
 *
 * @param o view object to query zoom level.
 *
 * @return current zoom level in use or -1.0 on error.
 */
float ewk_view_zoom_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, -1.0);
    return ewk_frame_zoom_get(sd->main_frame);
}

/**
 * Set the current zoom level of main frame.
 *
 * @param o view object to set zoom level.
 * @param zoom new level to use.
 * @param cx x of center coordinate
 * @param cy y of center coordinate
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_zoom_set(Evas_Object* o, float zoom, Evas_Coord cx, Evas_Coord cy)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET(sd, priv);

    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->api, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->api->zoom_set, EINA_FALSE);

    if (!priv->settings.zoom_range.user_scalable) {
        WRN("userScalable is false");
        return EINA_FALSE;
    }

    if (zoom < priv->settings.zoom_range.min_scale) {
        WRN("zoom level is < %f : %f", (double)priv->settings.zoom_range.min_scale, (double)zoom);
        return EINA_FALSE;
    }
    if (zoom > priv->settings.zoom_range.max_scale) {
        WRN("zoom level is > %f : %f", (double)priv->settings.zoom_range.max_scale, (double)zoom);
        return EINA_FALSE;
    }

    if (cx >= sd->view.w)
        cx = sd->view.w - 1;
    if (cy >= sd->view.h)
        cy = sd->view.h - 1;
    if (cx < 0)
        cx = 0;
    if (cy < 0)
        cy = 0;
    _ewk_view_zoom_animated_mark_stop(sd);
    return sd->api->zoom_set(sd, zoom, cx, cy);
}

Eina_Bool ewk_view_zoom_weak_smooth_scale_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return sd->zoom_weak_smooth_scale;
}

void ewk_view_zoom_weak_smooth_scale_set(Evas_Object* o, Eina_Bool smooth_scale)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    smooth_scale = !!smooth_scale;
    if (sd->zoom_weak_smooth_scale == smooth_scale)
        return;
    sd->zoom_weak_smooth_scale = smooth_scale;
    EINA_SAFETY_ON_NULL_RETURN(sd->api);
    EINA_SAFETY_ON_NULL_RETURN(sd->api->zoom_weak_smooth_scale_set);
    sd->api->zoom_weak_smooth_scale_set(sd, smooth_scale);
}

/**
 * Set the current zoom level of backing store, centered at given point.
 *
 * Unlike ewk_view_zoom_set(), this call do not ask WebKit to render
 * at new size, but scale what is already rendered, being much faster
 * but worse quality.
 *
 * Often one should use ewk_view_zoom_animated_set(), it will call the
 * same machinery internally.
 *
 * @note this will set variables used by ewk_view_zoom_animated_set()
 *       so sub-classes will not reset internal state on their
 *       "calculate" phase. To unset those and enable sub-classes to
 *       reset their internal state, call
 *       ewk_view_zoom_animated_mark_stop(). Namely, this call will
 *       set ewk_view_zoom_animated_mark_start() to actual webkit zoom
 *       level, ewk_view_zoom_animated_mark_end() and
 *       ewk_view_zoom_animated_mark_current() to given zoom level.
 *
 * @param o view object to set weak zoom level.
 * @param zoom level to scale backing store.
 * @param cx horizontal center offset, relative to object (w/2 is middle).
 * @param cy vertical center offset, relative to object (h/2 is middle).
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_zoom_weak_set(Evas_Object* o, float zoom, Evas_Coord cx, Evas_Coord cy)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET(sd, priv);

    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->api, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->api->zoom_weak_set, EINA_FALSE);

    if (!priv->settings.zoom_range.user_scalable) {
        WRN("userScalable is false");
        return EINA_FALSE;
    }

    if (zoom < priv->settings.zoom_range.min_scale) {
        WRN("zoom level is < %f : %f", (double)priv->settings.zoom_range.min_scale, (double)zoom);
        return EINA_FALSE;
    }
    if (zoom > priv->settings.zoom_range.max_scale) {
        WRN("zoom level is > %f : %f", (double)priv->settings.zoom_range.max_scale, (double)zoom);
        return EINA_FALSE;
    }

    if (cx >= sd->view.w)
        cx = sd->view.w - 1;
    if (cy >= sd->view.h)
        cy = sd->view.h - 1;
    if (cx < 0)
        cx = 0;
    if (cy < 0)
        cy = 0;

    sd->animated_zoom.zoom.start = ewk_frame_zoom_get(sd->main_frame);
    sd->animated_zoom.zoom.end = zoom;
    sd->animated_zoom.zoom.current = zoom;
    return sd->api->zoom_weak_set(sd, zoom, cx, cy);
}

/**
 * Mark internal zoom animation state to given zoom.
 *
 * This does not modify any actual zoom in WebKit or backing store,
 * just set the Ewk_View_Smart_Data->animated_zoom.zoom.start so
 * sub-classes will know they should not reset their internal state.
 *
 * @param o view object to change value.
 * @param zoom new start value.
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 *
 * @see ewk_view_zoom_animated_set()
 * @see ewk_view_zoom_weak_set()
 * @see ewk_view_zoom_animated_mark_stop()
 * @see ewk_view_zoom_animated_mark_end()
 * @see ewk_view_zoom_animated_mark_current()
 */
Eina_Bool ewk_view_zoom_animated_mark_start(Evas_Object* o, float zoom)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    sd->animated_zoom.zoom.start = zoom;
    return EINA_TRUE;
}

/**
 * Mark internal zoom animation state to given zoom.
 *
 * This does not modify any actual zoom in WebKit or backing store,
 * just set the Ewk_View_Smart_Data->animated_zoom.zoom.end so
 * sub-classes will know they should not reset their internal state.
 *
 * @param o view object to change value.
 * @param zoom new end value.
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 *
 * @see ewk_view_zoom_animated_set()
 * @see ewk_view_zoom_weak_set()
 * @see ewk_view_zoom_animated_mark_stop()
 * @see ewk_view_zoom_animated_mark_start()
 * @see ewk_view_zoom_animated_mark_current()
 */
Eina_Bool ewk_view_zoom_animated_mark_end(Evas_Object* o, float zoom)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    sd->animated_zoom.zoom.end = zoom;
    return EINA_TRUE;
}

/**
 * Mark internal zoom animation state to given zoom.
 *
 * This does not modify any actual zoom in WebKit or backing store,
 * just set the Ewk_View_Smart_Data->animated_zoom.zoom.current so
 * sub-classes will know they should not reset their internal state.
 *
 * @param o view object to change value.
 * @param zoom new current value.
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 *
 * @see ewk_view_zoom_animated_set()
 * @see ewk_view_zoom_weak_set()
 * @see ewk_view_zoom_animated_mark_stop()
 * @see ewk_view_zoom_animated_mark_start()
 * @see ewk_view_zoom_animated_mark_end()
 */
Eina_Bool ewk_view_zoom_animated_mark_current(Evas_Object* o, float zoom)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    sd->animated_zoom.zoom.current = zoom;
    return EINA_TRUE;
}

/**
 * Unmark internal zoom animation state.
 *
 * This zero all start, end and current values.
 *
 * @param o view object to mark as animated is stopped.
 *
 * @see ewk_view_zoom_animated_mark_start()
 * @see ewk_view_zoom_animated_mark_end()
 * @see ewk_view_zoom_animated_mark_current()
 * @see ewk_view_zoom_weak_set()
 */
Eina_Bool ewk_view_zoom_animated_mark_stop(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    _ewk_view_zoom_animated_mark_stop(sd);
    return EINA_TRUE;
}

/**
 * Set the current zoom level while animating.
 *
 * If the view was already animating to another zoom, it will start
 * from current point to the next provided zoom (@a zoom parameter)
 * and duration (@a duration parameter).
 *
 * This is the recommended way to do transitions from one level to
 * another. However, one may wish to do those from outside, in that
 * case use ewk_view_zoom_weak_set() and later control intermediate
 * states with ewk_view_zoom_animated_mark_current(),
 * ewk_view_zoom_animated_mark_end() and
 * ewk_view_zoom_animated_mark_stop().
 *
 * @param o view object to animate.
 * @param zoom final zoom level to use.
 * @param duration time in seconds the animation should take.
 * @param cx offset inside object that defines zoom center. 0 is left side.
 * @param cy offset inside object that defines zoom center. 0 is top side.
 * @return @c EINA_TRUE if animation will be started, @c EINA_FALSE if not
 *            because zoom is too small/big.
 */
Eina_Bool ewk_view_zoom_animated_set(Evas_Object* o, float zoom, float duration, Evas_Coord cx, Evas_Coord cy)
{
    double now;
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->api, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->api->zoom_weak_set, EINA_FALSE);

    if (!priv->settings.zoom_range.user_scalable) {
        WRN("userScalable is false");
        return EINA_FALSE;
    }

    if (zoom < priv->settings.zoom_range.min_scale) {
        WRN("zoom level is < %f : %f", (double)priv->settings.zoom_range.min_scale, (double)zoom);
        return EINA_FALSE;
    }
    if (zoom > priv->settings.zoom_range.max_scale) {
        WRN("zoom level is > %f : %f", (double)priv->settings.zoom_range.max_scale, (double)zoom);
        return EINA_FALSE;
    }

    if (priv->animated_zoom.animator)
        priv->animated_zoom.zoom.start = _ewk_view_zoom_animated_current(priv);
    else {
        priv->animated_zoom.zoom.start = ewk_frame_zoom_get(sd->main_frame);
        _ewk_view_zoom_animation_start(sd);
    }

    if (cx < 0)
        cx = 0;
    if (cy < 0)
        cy = 0;

    now = ecore_loop_time_get();
    priv->animated_zoom.time.start = now;
    priv->animated_zoom.time.end = now + duration;
    priv->animated_zoom.time.duration = duration;
    priv->animated_zoom.zoom.end = zoom;
    priv->animated_zoom.zoom.range = (priv->animated_zoom.zoom.end - priv->animated_zoom.zoom.start);
    priv->animated_zoom.center.x = cx;
    priv->animated_zoom.center.y = cy;
    sd->animated_zoom.zoom.current = priv->animated_zoom.zoom.start;
    sd->animated_zoom.zoom.start = priv->animated_zoom.zoom.start;
    sd->animated_zoom.zoom.end = priv->animated_zoom.zoom.end;

    return EINA_TRUE;
}

/**
 * Query if zoom level just applies to text and not other elements.
 *
 * @param o view to query setting.
 *
 * @return @c EINA_TRUE if just text are scaled, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_zoom_text_only_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return ewk_frame_zoom_text_only_get(sd->main_frame);
}

/**
 * Set if zoom level just applies to text and not other elements.
 *
 * @param o view to change setting.
 * @param setting @c EINA_TRUE if zoom should just be applied to text.
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_zoom_text_only_set(Evas_Object* o, Eina_Bool setting)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    return ewk_frame_zoom_text_only_set(sd->main_frame, setting);
}

/**
 * Hint engine to pre-render region.
 *
 * Engines and backing store might be able to pre-render regions in
 * order to speed up zooming or scrolling to that region. Not all
 * engines might implement that and they will return @c EINA_FALSE
 * in that case.
 *
 * The given region is a hint. Engines might do bigger or smaller area
 * that covers that region. Pre-render might not be immediate, it may
 * be postponed to a thread, operated cooperatively in the main loop
 * and may be even ignored or cancelled afterwards.
 *
 * Multiple requests might be queued by engines. One can clear/forget
 * about them with ewk_view_pre_render_cancel().
 *
 * @param o view to ask pre-render of given region.
 * @param x absolute coordinate (0=left) to pre-render at zoom.
 * @param y absolute coordinate (0=top) to pre-render at zoom.
 * @param w width to pre-render starting from @a x at zoom.
 * @param h height to pre-render starting from @a y at zoom.
 * @param zoom desired zoom.
 *
 * @return @c EINA_TRUE if request was accepted, @c EINA_FALSE
 *         otherwise (errors, pre-render not supported, etc).
 *
 * @see ewk_view_pre_render_cancel()
 */
Eina_Bool ewk_view_pre_render_region(Evas_Object* o, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h, float zoom)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->api->pre_render_region, EINA_FALSE);
    float cur_zoom = ewk_frame_zoom_get(sd->main_frame);
    Evas_Coord cw, ch;

    if (cur_zoom < 0.00001)
        return EINA_FALSE;
    if (!ewk_frame_contents_size_get(sd->main_frame, &cw, &ch))
        return EINA_FALSE;

    cw *= zoom / cur_zoom;
    ch *= zoom / cur_zoom;
    DBG("region %d,%d+%dx%d @ %f contents=%dx%d", x, y, w, h, zoom, cw, ch);

    if (x + w > cw)
        w = cw - x;

    if (y + h > ch)
        h = ch - y;

    if (x < 0) {
        w += x;
        x = 0;
    }
    if (y < 0) {
        h += y;
        y = 0;
    }

    return sd->api->pre_render_region(sd, x, y, w, h, zoom);
}

/**
 * Get input method hints
 *
 * @param o View.
 *
 * @return input method hints
 */
unsigned int ewk_view_imh_get(Evas_Object *o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    return priv->imh;
}

/**
 * Cancel (clear) previous pre-render requests.
 *
 * @param o view to clear pre-render requests.
 */
void ewk_view_pre_render_cancel(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    EINA_SAFETY_ON_NULL_RETURN(sd->api->pre_render_cancel);
    sd->api->pre_render_cancel(sd);
}

const char* ewk_view_setting_user_agent_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    return priv->settings.user_agent;
}

Eina_Bool ewk_view_setting_user_agent_set(Evas_Object* o, const char* user_agent)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    if (eina_stringshare_replace(&priv->settings.user_agent, user_agent)) {
        WebCore::FrameLoaderClientEfl* client = static_cast<WebCore::FrameLoaderClientEfl*>(priv->main_frame->loader()->client());
        client->setCustomUserAgent(WTF::String::fromUTF8(user_agent));
    }
    return EINA_TRUE;
}

const char* ewk_view_setting_user_stylesheet_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    return priv->settings.user_stylesheet;
}

Eina_Bool ewk_view_setting_user_stylesheet_set(Evas_Object* o, const char* uri)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    if (eina_stringshare_replace(&priv->settings.user_stylesheet, uri)) {
        WebCore::KURL kurl(WebCore::KURL(), WTF::String::fromUTF8(uri));
        priv->page_settings->setUserStyleSheetLocation(kurl);
    }
    return EINA_TRUE;
}

Eina_Bool ewk_view_setting_auto_load_images_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return priv->settings.auto_load_images;
}

Eina_Bool ewk_view_setting_auto_load_images_set(Evas_Object* o, Eina_Bool automatic)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    automatic = !!automatic;
    if (priv->settings.auto_load_images != automatic) {
        priv->page_settings->setLoadsImagesAutomatically(automatic);
        priv->settings.auto_load_images = automatic;
    }
    return EINA_TRUE;
}

Eina_Bool ewk_view_setting_auto_shrink_images_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return priv->settings.auto_shrink_images;
}

Eina_Bool ewk_view_setting_auto_shrink_images_set(Evas_Object* o, Eina_Bool automatic)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    automatic = !!automatic;
    if (priv->settings.auto_shrink_images != automatic) {
        priv->page_settings->setShrinksStandaloneImagesToFit(automatic);
        priv->settings.auto_shrink_images = automatic;
    }
    return EINA_TRUE;
}

Eina_Bool ewk_view_setting_enable_scripts_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return priv->settings.enable_scripts;
}

Eina_Bool ewk_view_setting_enable_scripts_set(Evas_Object* o, Eina_Bool enable)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    enable = !!enable;
    if (priv->settings.enable_scripts != enable) {
        priv->page_settings->setJavaScriptEnabled(enable);
        priv->settings.enable_scripts = enable;
    }
    return EINA_TRUE;
}

Eina_Bool ewk_view_setting_enable_plugins_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return priv->settings.enable_plugins;
}

Eina_Bool ewk_view_setting_enable_plugins_set(Evas_Object* o, Eina_Bool enable)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    enable = !!enable;
    if (priv->settings.enable_plugins != enable) {
        priv->page_settings->setPluginsEnabled(enable);
        priv->settings.enable_plugins = enable;
    }
    return EINA_TRUE;
}

/**
 * Get status of frame flattening.
 *
 * @param o view to check status
 *
 * @return EINA_TRUE if flattening is enabled, EINA_FALSE
 *         otherwise (errors, flattening disabled).
 */
Eina_Bool ewk_view_setting_enable_frame_flattening_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return priv->settings.enable_frame_flattening;
}

/**
 * Set frame flattening.
 *
 * @param o view to set flattening
 *
 * @return EINA_TRUE if flattening status set, EINA_FALSE
 *         otherwise (errors).
 */
Eina_Bool ewk_view_setting_enable_frame_flattening_set(Evas_Object* o, Eina_Bool enable)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    enable = !!enable;
    if (priv->settings.enable_frame_flattening != enable) {
        priv->page_settings->setFrameFlatteningEnabled(enable);
        priv->settings.enable_frame_flattening = enable;
    }
    return EINA_TRUE;
}

Eina_Bool ewk_view_setting_scripts_window_open_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return priv->settings.scripts_window_open;
}

Eina_Bool ewk_view_setting_scripts_window_open_set(Evas_Object* o, Eina_Bool allow)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    allow = !!allow;
    if (priv->settings.scripts_window_open != allow) {
        priv->page_settings->setJavaScriptCanOpenWindowsAutomatically(allow);
        priv->settings.scripts_window_open = allow;
    }
    return EINA_TRUE;
}

Eina_Bool ewk_view_setting_resizable_textareas_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return priv->settings.resizable_textareas;
}

Eina_Bool ewk_view_setting_resizable_textareas_set(Evas_Object* o, Eina_Bool enable)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    enable = !!enable;
    if (priv->settings.resizable_textareas != enable) {
        priv->page_settings->setTextAreasAreResizable(enable);
        priv->settings.resizable_textareas = enable;
    }
    return EINA_TRUE;
}

Eina_Bool ewk_view_setting_private_browsing_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return priv->settings.private_browsing;
}

Eina_Bool ewk_view_setting_private_browsing_set(Evas_Object* o, Eina_Bool enable)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    enable = !!enable;
    if (priv->settings.private_browsing != enable) {
        priv->page_settings->setPrivateBrowsingEnabled(enable);
        priv->settings.private_browsing = enable;
    }
    return EINA_TRUE;
}

Eina_Bool ewk_view_setting_offline_app_cache_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return priv->settings.offline_app_cache;
}

Eina_Bool ewk_view_setting_offline_app_cache_set(Evas_Object* o, Eina_Bool enable)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    enable = !!enable;
    if (priv->settings.offline_app_cache != enable) {
        priv->page_settings->setOfflineWebApplicationCacheEnabled(enable);
        priv->settings.offline_app_cache = enable;
    }
    return EINA_TRUE;
}


Eina_Bool ewk_view_setting_caret_browsing_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return priv->settings.caret_browsing;
}

Eina_Bool ewk_view_setting_caret_browsing_set(Evas_Object* o, Eina_Bool enable)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    enable = !!enable;
    if (priv->settings.caret_browsing != enable) {
        priv->page_settings->setCaretBrowsingEnabled(enable);
        priv->settings.caret_browsing = enable;
    }
    return EINA_TRUE;
}

/**
 * Get current encoding of this View.
 *
 * @param o View.
 *
 * @return A pointer to an eina_strinshare containing the current custom
 * encoding for View object @param o, or @c 0 if it's not set.
 */
const char* ewk_view_setting_encoding_custom_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    Evas_Object* main_frame = ewk_view_frame_main_get(o);
    WebCore::Frame* core_frame = ewk_frame_core_get(main_frame);

    WTF::String overrideEncoding = core_frame->loader()->documentLoader()->overrideEncoding();

    if (overrideEncoding.isEmpty())
        return 0;

    eina_stringshare_replace(&priv->settings.encoding_custom, overrideEncoding.utf8().data());
    return priv->settings.encoding_custom;
}

/**
 * Set encoding of this View and reload page.
 *
 * @param o View.
 * @param encoding The new encoding or @c 0 to restore the default encoding.
 *
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 */
Eina_Bool ewk_view_setting_encoding_custom_set(Evas_Object* o, const char *encoding)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    Evas_Object* main_frame = ewk_view_frame_main_get(o);
    WebCore::Frame* core_frame = ewk_frame_core_get(main_frame);
DBG("%s", encoding);
    eina_stringshare_replace(&priv->settings.encoding_custom, encoding);
    core_frame->loader()->reloadWithOverrideEncoding(WTF::String::fromUTF8(encoding));

    return EINA_TRUE;
}

const char* ewk_view_setting_encoding_default_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    return priv->settings.encoding_default;
}

Eina_Bool ewk_view_setting_encoding_default_set(Evas_Object* o, const char* encoding)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    if (eina_stringshare_replace(&priv->settings.encoding_default, encoding))
        priv->page_settings->setDefaultTextEncodingName(WTF::String::fromUTF8(encoding));
    return EINA_TRUE;
}

const char* ewk_view_setting_cache_directory_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    return priv->settings.cache_directory;
}

Eina_Bool ewk_view_setting_cache_directory_set(Evas_Object* o, const char* path)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    if (eina_stringshare_replace(&priv->settings.cache_directory, path))
        WebCore::cacheStorage().setCacheDirectory(WTF::String::fromUTF8(path));
    return EINA_TRUE;
}

int ewk_view_setting_font_minimum_size_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    return priv->settings.font_minimum_size;
}

Eina_Bool ewk_view_setting_font_minimum_size_set(Evas_Object* o, int size)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    if (priv->settings.font_minimum_size != size) {
        priv->page_settings->setMinimumFontSize(size);
        priv->settings.font_minimum_size = size;
    }
    return EINA_TRUE;
}

int ewk_view_setting_font_minimum_logical_size_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    return priv->settings.font_minimum_logical_size;
}

Eina_Bool ewk_view_setting_font_minimum_logical_size_set(Evas_Object* o, int size)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    if (priv->settings.font_minimum_logical_size != size) {
        priv->page_settings->setMinimumLogicalFontSize(size);
        priv->settings.font_minimum_logical_size = size;
    }
    return EINA_TRUE;
}

int ewk_view_setting_font_default_size_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    return priv->settings.font_default_size;
}

Eina_Bool ewk_view_setting_font_default_size_set(Evas_Object* o, int size)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    if (priv->settings.font_default_size != size) {
        priv->page_settings->setDefaultFontSize(size);
        priv->settings.font_default_size = size;
    }
    return EINA_TRUE;
}

int ewk_view_setting_font_monospace_size_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    return priv->settings.font_monospace_size;
}

Eina_Bool ewk_view_setting_font_monospace_size_set(Evas_Object* o, int size)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    if (priv->settings.font_monospace_size != size) {
        priv->page_settings->setDefaultFixedFontSize(size);
        priv->settings.font_monospace_size = size;
    }
    return EINA_TRUE;
}

const char* ewk_view_setting_font_standard_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    return priv->settings.font_standard;
}

Eina_Bool ewk_view_setting_font_standard_set(Evas_Object* o, const char* family)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    if (eina_stringshare_replace(&priv->settings.font_standard, family)) {
        WTF::AtomicString s = WTF::String::fromUTF8(family);
        priv->page_settings->setStandardFontFamily(s);
    }
    return EINA_TRUE;
}

const char* ewk_view_setting_font_cursive_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    return priv->settings.font_cursive;
}

Eina_Bool ewk_view_setting_font_cursive_set(Evas_Object* o, const char* family)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    if (eina_stringshare_replace(&priv->settings.font_cursive, family)) {
        WTF::AtomicString s = WTF::String::fromUTF8(family);
        priv->page_settings->setCursiveFontFamily(s);
    }
    return EINA_TRUE;
}

const char* ewk_view_setting_font_fantasy_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    return priv->settings.font_fantasy;
}

Eina_Bool ewk_view_setting_font_fantasy_set(Evas_Object* o, const char* family)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    if (eina_stringshare_replace(&priv->settings.font_fantasy, family)) {
        WTF::AtomicString s = WTF::String::fromUTF8(family);
        priv->page_settings->setFantasyFontFamily(s);
    }
    return EINA_TRUE;
}

const char* ewk_view_setting_font_monospace_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    return priv->settings.font_monospace;
}

Eina_Bool ewk_view_setting_font_monospace_set(Evas_Object* o, const char* family)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    if (eina_stringshare_replace(&priv->settings.font_monospace, family)) {
        WTF::AtomicString s = WTF::String::fromUTF8(family);
        priv->page_settings->setFixedFontFamily(s);
    }
    return EINA_TRUE;
}

const char* ewk_view_setting_font_serif_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    return priv->settings.font_serif;
}

Eina_Bool ewk_view_setting_font_serif_set(Evas_Object* o, const char* family)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    if (eina_stringshare_replace(&priv->settings.font_serif, family)) {
        WTF::AtomicString s = WTF::String::fromUTF8(family);
        priv->page_settings->setSerifFontFamily(s);
    }
    return EINA_TRUE;
}

const char* ewk_view_setting_font_sans_serif_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    return priv->settings.font_sans_serif;
}
  
Eina_Bool ewk_view_setting_font_sans_serif_set(Evas_Object* o, const char* family)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    if (eina_stringshare_replace(&priv->settings.font_sans_serif, family)) {
        WTF::AtomicString s = WTF::String::fromUTF8(family);
        priv->page_settings->setSansSerifFontFamily(s);
    }
    return EINA_TRUE;
}

Eina_Bool ewk_view_setting_spatial_navigation_get(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return priv->settings.spatial_navigation;
}

Eina_Bool ewk_view_setting_spatial_navigation_set(Evas_Object* o, Eina_Bool enable)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    enable = !!enable;
    if (priv->settings.spatial_navigation != enable) {
        priv->page_settings->setSpatialNavigationEnabled(enable);
        priv->settings.spatial_navigation = enable;
    }
    return EINA_TRUE;
}

/**
 * Gets if the local storage is enabled.
 *
 * @param o view object to set if local storage is enabled.
 * @return @c EINA_TRUE if local storage is enabled, @c EINA_FALSE if not.
 */
Eina_Bool ewk_view_setting_local_storage_get(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    return priv->settings.local_storage;
}

/**
 * Sets the local storage of HTML5.
 *
 * @param o view object to set if local storage is enabled.
 * @return @c EINA_TRUE on success and @c EINA_FALSE on failure
 */
Eina_Bool ewk_view_setting_local_storage_set(Evas_Object* o, Eina_Bool enable)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);
    enable = !!enable;
    if (priv->settings.local_storage != enable) {
        priv->page_settings->setLocalStorageEnabled(enable);
        priv->settings.local_storage = enable;
    }
    return EINA_TRUE;
}

/**
 * Similar to evas_object_smart_data_get(), but does type checking.
 *
 * @param o view object to query internal data.
 * @return internal data or @c 0 on errors (ie: incorrect type of @a o).
 */
Ewk_View_Smart_Data* ewk_view_smart_data_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    return sd;
}

/**
 * Gets the internal array of repaint requests.
 *
 * This array should not be modified anyhow. It should be processed
 * immediately as any further ewk_view call might change it, like
 * those that add repaints or flush them, so be sure that your code
 * does not call any of those while you process the repaints,
 * otherwise copy the array.
 *
 * @param priv private handle pointer of the view to get repaints.
 * @param count where to return the number of elements of returned array.
 *
 * @return reference to array of requested repaints.
 *
 * @note this is not for general use but just for subclasses that want
 *       to define their own backing store.
 */
const Eina_Rectangle* ewk_view_repaints_get(const Ewk_View_Private_Data* priv, size_t* count)
{
    EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0);
    if (count)
        *count = 0;
    EINA_SAFETY_ON_NULL_RETURN_VAL(priv, 0);
    if (count)
        *count = priv->repaints.count;
    return priv->repaints.array;
}

/**
 * Gets the internal array of scroll requests.
 *
 * This array should not be modified anyhow. It should be processed
 * immediately as any further ewk_view call might change it, like
 * those that add scrolls or flush them, so be sure that your code
 * does not call any of those while you process the scrolls,
 * otherwise copy the array.
 *
 * @param priv private handle pointer of the view to get scrolls.
 * @param count where to return the number of elements of returned array.
 *
 * @return reference to array of requested scrolls.
 *
 * @note this is not for general use but just for subclasses that want
 *       to define their own backing store.
 */
const Ewk_Scroll_Request* ewk_view_scroll_requests_get(const Ewk_View_Private_Data* priv, size_t* count)
{
    EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0);
    if (count)
        *count = 0;
    EINA_SAFETY_ON_NULL_RETURN_VAL(priv, 0);
    if (count)
        *count = priv->scrolls.count;
    return priv->scrolls.array;
}

/**
 * Add a new repaint request to queue.
 *
 * The repaints are assumed to be relative to current viewport.
 *
 * @param priv private handle pointer of the view to add repaint request.
 * @param x horizontal position relative to current view port (scrolled).
 * @param y vertical position relative to current view port (scrolled).
 * @param w width of area to be repainted
 * @param h height of area to be repainted
 *
 * @note this is not for general use but just for subclasses that want
 *       to define their own backing store.
 */
void ewk_view_repaint_add(Ewk_View_Private_Data* priv, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
{
    EINA_SAFETY_ON_NULL_RETURN(priv);
    _ewk_view_repaint_add(priv, x, y, w, h);
}

/**
 * Do layout if required, applied recursively.
 *
 * @param priv private handle pointer of the view to layout.
 *
 * @note this is not for general use but just for subclasses that want
 *       to define their own backing store.
 */
void ewk_view_layout_if_needed_recursive(Ewk_View_Private_Data* priv)
{
    EINA_SAFETY_ON_NULL_RETURN(priv);

    WebCore::FrameView* v = priv->main_frame->view();
    if (!v) {
        ERR("no main frame view");
        return;
    }
    v->updateLayoutAndStyleIfNeededRecursive();
}

void ewk_view_scrolls_process(Ewk_View_Smart_Data* sd)
{
    EINA_SAFETY_ON_NULL_RETURN(sd);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv);
    if (!sd->api->scrolls_process(sd))
        ERR("failed to process scrolls.");
    _ewk_view_scrolls_flush(priv);
}

struct _Ewk_View_Paint_Context {
    WebCore::GraphicsContext* gc;
    WebCore::FrameView* view;
    cairo_t* cr;
};

/**
 * Create a new paint context using the view as source and cairo as output.
 *
 * @param priv private handle pointer of the view to use as paint source.
 * @param cr cairo context to use as paint destination. A new
 *        reference is taken, so it's safe to call cairo_destroy()
 *        after this function returns.
 *
 * @return newly allocated instance or @c 0 on errors.
 *
 * @note this is not for general use but just for subclasses that want
 *       to define their own backing store.
 */
Ewk_View_Paint_Context* ewk_view_paint_context_new(Ewk_View_Private_Data* priv, cairo_t* cr)
{
    EINA_SAFETY_ON_NULL_RETURN_VAL(priv, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(cr, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(priv->main_frame, 0);
    WebCore::FrameView* view = priv->main_frame->view();
    EINA_SAFETY_ON_NULL_RETURN_VAL(view, 0);
    Ewk_View_Paint_Context* ctxt = (Ewk_View_Paint_Context*)malloc(sizeof(*ctxt));
    EINA_SAFETY_ON_NULL_RETURN_VAL(ctxt, 0);

    ctxt->gc = new WebCore::GraphicsContext(cr);
    if (!ctxt->gc) {
        free(ctxt);
        return 0;
    }
    ctxt->view = view;
    ctxt->cr = cairo_reference(cr);
    return ctxt;
}

/**
 * Destroy previously created paint context.
 *
 * @param ctxt paint context to destroy. Must @b not be @c 0.
 *
 * @note this is not for general use but just for subclasses that want
 *       to define their own backing store.
 */
void ewk_view_paint_context_free(Ewk_View_Paint_Context* ctxt)
{
    EINA_SAFETY_ON_NULL_RETURN(ctxt);
    delete ctxt->gc;
    cairo_destroy(ctxt->cr);
    free(ctxt);
}

/**
 * Save (push to stack) paint context status.
 *
 * @param ctxt paint context to save. Must @b not be @c 0.
 *
 * @see ewk_view_paint_context_restore()
 *
 * @note this is not for general use but just for subclasses that want
 *       to define their own backing store.
 */
void ewk_view_paint_context_save(Ewk_View_Paint_Context* ctxt)
{
    EINA_SAFETY_ON_NULL_RETURN(ctxt);
    cairo_save(ctxt->cr);
    ctxt->gc->save();
}

/**
 * Restore (pop from stack) paint context status.
 *
 * @param ctxt paint context to restore. Must @b not be @c 0.
 *
 * @see ewk_view_paint_context_save()
 *
 * @note this is not for general use but just for subclasses that want
 *       to define their own backing store.
 */
void ewk_view_paint_context_restore(Ewk_View_Paint_Context* ctxt)
{
    EINA_SAFETY_ON_NULL_RETURN(ctxt);
    ctxt->gc->restore();
    cairo_restore(ctxt->cr);
}

/**
 * Clip paint context drawings to given area.
 *
 * @param ctxt paint context to clip. Must @b not be @c 0.
 * @param area clip area to use.
 *
 * @see ewk_view_paint_context_save()
 * @see ewk_view_paint_context_restore()
 *
 * @note this is not for general use but just for subclasses that want
 *       to define their own backing store.
 */
void ewk_view_paint_context_clip(Ewk_View_Paint_Context* ctxt, const Eina_Rectangle* area)
{
    EINA_SAFETY_ON_NULL_RETURN(ctxt);
    EINA_SAFETY_ON_NULL_RETURN(area);
    ctxt->gc->clip(WebCore::IntRect(area->x, area->y, area->w, area->h));
}

/**
 * Paint using context using given area.
 *
 * @param ctxt paint context to paint. Must @b not be @c 0.
 * @param area paint area to use. Coordinates are relative to current viewport,
 *        thus "scrolled".
 *
 * @note one may use cairo functions on the cairo context to
 *       translate, scale or any modification that may fit his desires.
 *
 * @see ewk_view_paint_context_clip()
 * @see ewk_view_paint_context_paint_contents()
 *
 * @note this is not for general use but just for subclasses that want
 *       to define their own backing store.
 */
void ewk_view_paint_context_paint(Ewk_View_Paint_Context* ctxt, const Eina_Rectangle* area)
{
    EINA_SAFETY_ON_NULL_RETURN(ctxt);
    EINA_SAFETY_ON_NULL_RETURN(area);

    WebCore::IntRect rect(area->x, area->y, area->w, area->h);

    if (ctxt->view->isTransparent())
        ctxt->gc->clearRect(rect);
    ctxt->view->paint(ctxt->gc, rect);
}

/**
 * Paint just contents using context using given area.
 *
 * Unlike ewk_view_paint_context_paint(), this function paint just
 * bare contents and ignores any scrolling, scrollbars and extras. It
 * will walk the rendering tree and paint contents inside the given
 * area to the cairo context specified in @a ctxt.
 *
 * @param ctxt paint context to paint. Must @b not be @c 0.
 * @param area paint area to use. Coordinates are absolute to page.
 *
 * @note one may use cairo functions on the cairo context to
 *       translate, scale or any modification that may fit his desires.
 *
 * @see ewk_view_paint_context_clip()
 * @see ewk_view_paint_context_paint()
 *
 * @note this is not for general use but just for subclasses that want
 *       to define their own backing store.
 */
void ewk_view_paint_context_paint_contents(Ewk_View_Paint_Context* ctxt, const Eina_Rectangle* area)
{
    EINA_SAFETY_ON_NULL_RETURN(ctxt);
    EINA_SAFETY_ON_NULL_RETURN(area);

    WebCore::IntRect rect(area->x, area->y, area->w, area->h);

    if (ctxt->view->isTransparent())
        ctxt->gc->clearRect(rect);

    ctxt->view->paintContents(ctxt->gc, rect);
}

/**
 * Scale the contents by the given factors.
 *
 * This function applies a scaling transformation using Cairo.
 *
 * @param ctxt    paint context to paint. Must @b not be @c 0.
 * @param scale_x scale factor for the X dimension.
 * @param scale_y scale factor for the Y dimension.
 */
void ewk_view_paint_context_scale(Ewk_View_Paint_Context* ctxt, float scale_x, float scale_y)
{
    EINA_SAFETY_ON_NULL_RETURN(ctxt);

    ctxt->gc->scale(WebCore::FloatSize(scale_x, scale_y));
}

/**
 * Performs a translation of the origin coordinates.
 *
 * This function moves the origin coordinates by @p x and @p y pixels.
 *
 * @param ctxt paint context to paint. Must @b not be @c 0.
 * @param x    amount of pixels to translate in the X dimension.
 * @param y    amount of pixels to translate in the Y dimension.
 */
void ewk_view_paint_context_translate(Ewk_View_Paint_Context* ctxt, float x, float y)
{
    EINA_SAFETY_ON_NULL_RETURN(ctxt);

    ctxt->gc->translate(x, y);
}

/**
 * Paint using given graphics context the given area.
 *
 * This uses viewport relative area and will also handle scrollbars
 * and other extra elements. See ewk_view_paint_contents() for the
 * alternative function.
 *
 * @param priv private handle pointer of view to use as paint source.
 * @param cr cairo context to use as paint destination. Its state will
 *        be saved before operation and restored afterwards.
 * @param area viewport relative geometry to paint.
 *
 * @return @c EINA_TRUE on success and @c EINA_FALSE on failure, like
 *         incorrect parameters.
 *
 * @note this is an easy to use version, but internal structures are
 *       always created, then graphics context is clipped, then
 *       painted, restored and destroyed. This might not be optimum,
 *       so using #Ewk_View_Paint_Context may be a better solutions
 *       for large number of operations.
 *
 * @see ewk_view_paint_contents()
 * @see ewk_view_paint_context_paint()
 *
 * @note this is not for general use but just for subclasses that want
 *       to define their own backing store.
 */
Eina_Bool ewk_view_paint(Ewk_View_Private_Data* priv, cairo_t* cr, const Eina_Rectangle* area)
{
    EINA_SAFETY_ON_NULL_RETURN_VAL(priv, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(cr, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(area, EINA_FALSE);
    WebCore::FrameView* view = priv->main_frame->view();
    EINA_SAFETY_ON_NULL_RETURN_VAL(view, EINA_FALSE);

    if (view->needsLayout())
        view->forceLayout();
    WebCore::GraphicsContext gc(cr);
    WebCore::IntRect rect(area->x, area->y, area->w, area->h);

    cairo_save(cr);
    gc.save();
    gc.clip(rect);
    if (view->isTransparent())
        gc.clearRect(rect);
    view->paint(&gc,  rect);
    gc.restore();
    cairo_restore(cr);

    return EINA_TRUE;
}

/**
 * Paint just contents using given graphics context the given area.
 *
 * This uses absolute coordinates for area and will just handle
 * contents, no scrollbars or extras. See ewk_view_paint() for the
 * alternative solution.
 *
 * @param priv private handle pointer of view to use as paint source.
 * @param cr cairo context to use as paint destination. Its state will
 *        be saved before operation and restored afterwards.
 * @param area absolute geometry to paint.
 *
 * @return @c EINA_TRUE on success and @c EINA_FALSE on failure, like
 *         incorrect parameters.
 *
 * @note this is an easy to use version, but internal structures are
 *       always created, then graphics context is clipped, then
 *       painted, restored and destroyed. This might not be optimum,
 *       so using #Ewk_View_Paint_Context may be a better solutions
 *       for large number of operations.
 *
 * @see ewk_view_paint()
 * @see ewk_view_paint_context_paint_contents()
 *
 * @note this is not for general use but just for subclasses that want
 *       to define their own backing store.
 */
Eina_Bool ewk_view_paint_contents(Ewk_View_Private_Data* priv, cairo_t* cr, const Eina_Rectangle* area)
{
    EINA_SAFETY_ON_NULL_RETURN_VAL(priv, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(cr, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(area, EINA_FALSE);
    WebCore::FrameView* view = priv->main_frame->view();
    EINA_SAFETY_ON_NULL_RETURN_VAL(view, EINA_FALSE);

    WebCore::GraphicsContext gc(cr);
    WebCore::IntRect rect(area->x, area->y, area->w, area->h);

    cairo_save(cr);
    gc.save();
    gc.clip(rect);
    if (view->isTransparent())
        gc.clearRect(rect);
    view->paintContents(&gc,  rect);
    gc.restore();
    cairo_restore(cr);

    return EINA_TRUE;
}


/* internal methods ****************************************************/
/**
 * @internal
 * Reports the view is ready to be displayed as all elements are aready.
 *
 * Emits signal: "ready" with no parameters.
 */
void ewk_view_ready(Evas_Object* o)
{
    DBG("o=%p", o);
    evas_object_smart_callback_call(o, "ready", 0);
}

/**
 * @internal
 * Reports the state of input method changed. This is triggered, for example
 * when a input field received/lost focus
 *
 * Emits signal: "inputmethod,changed" with a boolean indicating whether it's
 * enabled or not.
 */
void ewk_view_input_method_state_set(Evas_Object* o, Eina_Bool active)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    EWK_VIEW_PRIV_GET(sd, priv);
    WebCore::Frame* focusedFrame = priv->page->focusController()->focusedOrMainFrame();

    if (focusedFrame
        && focusedFrame->document()
        && focusedFrame->document()->focusedNode()
        && focusedFrame->document()->focusedNode()->hasTagName(WebCore::HTMLNames::inputTag)) {
        WebCore::HTMLInputElement* inputElement;

        inputElement = static_cast<WebCore::HTMLInputElement*>(focusedFrame->document()->focusedNode());
        if (inputElement) {
            priv->imh = 0;
            // for password fields, active == false
            if (!active) {
                active = inputElement->isPasswordField();
                priv->imh = inputElement->isPasswordField() * EWK_IMH_PASSWORD;
            } else {
                // Set input method hints for "number", "tel", "email", and "url" input elements.
                priv->imh |= inputElement->isTelephoneField() * EWK_IMH_TELEPHONE;
                priv->imh |= inputElement->isNumberField() * EWK_IMH_NUMBER;
                priv->imh |= inputElement->isEmailField() * EWK_IMH_EMAIL;
                priv->imh |= inputElement->isUrlField() * EWK_IMH_URL;
            }
        }
    }

    evas_object_smart_callback_call(o, "inputmethod,changed", (void*)active);
}

/**
 * @internal
 * The view title was changed by the frame loader.
 *
 * Emits signal: "title,changed" with pointer to new title string.
 */
void ewk_view_title_set(Evas_Object* o, const char* title)
{
    DBG("o=%p, title=%s", o, title ? title : "(null)");
    evas_object_smart_callback_call(o, "title,changed", (void*)title);
}

/**
 * @internal
 * Reports that main frame's uri changed.
 *
 * Emits signal: "uri,changed" with pointer to the new uri string.
 */
void ewk_view_uri_changed(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    const char* uri = ewk_frame_uri_get(sd->main_frame);
    DBG("o=%p, uri=%s", o, uri ? uri : "(null)");
    evas_object_smart_callback_call(o, "uri,changed", (void*)uri);
}

/**
 * @internal
 * Reports the view started loading something.
 *
 * @param o View.
 *
 * Emits signal: "load,started" with no parameters.
 */
void ewk_view_load_started(Evas_Object* o)
{
    DBG("o=%p", o);
    evas_object_smart_callback_call(o, "load,started", 0);
}

/**
 * Reports the frame started loading something.
 *
 * @param o View.
 *
 * Emits signal: "load,started" on main frame with no parameters.
 */
void ewk_view_frame_main_load_started(Evas_Object* o)
{
    DBG("o=%p", o);
    Evas_Object* frame = ewk_view_frame_main_get(o);
    evas_object_smart_callback_call(frame, "load,started", 0);
}

/**
 * @internal
 * Reports the main frame started provisional load.
 *
 * @param o View.
 *
 * Emits signal: "load,provisional" on View with no parameters.
 */
void ewk_view_load_provisional(Evas_Object* o)
{
    DBG("o=%p", o);
    evas_object_smart_callback_call(o, "load,provisional", 0);
}

/**
 * @internal
 * Reports view can be shown after a new window is created.
 *
 * @param o Frame.
 *
 * Emits signal: "load,newwindow,show" on view with no parameters.
 */
void ewk_view_load_show(Evas_Object* o)
{
    DBG("o=%p", o);
    evas_object_smart_callback_call(o, "load,newwindow,show", 0);
}


/**
 * @internal
 * Reports the main frame was cleared.
 *
 * @param o View.
 */
void ewk_view_frame_main_cleared(Evas_Object* o)
{
    DBG("o=%p", o);
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    EINA_SAFETY_ON_NULL_RETURN(sd->api->flush);
    sd->api->flush(sd);
}

/**
 * @internal
 * Reports the main frame received an icon.
 *
 * @param o View.
 *
 * Emits signal: "icon,received" with no parameters.
 */
void ewk_view_frame_main_icon_received(Evas_Object* o)
{
    DBG("o=%p", o);
    Evas_Object* frame = ewk_view_frame_main_get(o);
    evas_object_smart_callback_call(frame, "icon,received", 0);
}

/**
 * @internal
 * Reports load finished, optionally with error information.
 *
 * Emits signal: "load,finished" with pointer to #Ewk_Frame_Load_Error
 * if any error, or @c 0 if successful load.
 *
 * @note there should not be any error stuff here, but trying to be
 *       compatible with previous WebKit.
 */
void ewk_view_load_finished(Evas_Object* o, const Ewk_Frame_Load_Error* error)
{
    DBG("o=%p, error=%p", o, error);
    evas_object_smart_callback_call(o, "load,finished", (void*)error);
}

/**
 * @internal
 * Reports load failed with error information.
 *
 * Emits signal: "load,error" with pointer to Ewk_Frame_Load_Error.
 */
void ewk_view_load_error(Evas_Object* o, const Ewk_Frame_Load_Error* error)
{
    DBG("o=%p, error=%p", o, error);
    evas_object_smart_callback_call(o, "load,error", (void*)error);
}

/**
 * @internal
 * Reports load progress changed.
 *
 * Emits signal: "load,progress" with pointer to a double from 0.0 to 1.0.
 */
void ewk_view_load_progress_changed(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv);

    // Evas_Coord w, h;
    double progress = priv->page->progress()->estimatedProgress();

    DBG("o=%p (p=%0.3f)", o, progress);

    evas_object_smart_callback_call(o, "load,progress", &progress);
}

/**
 * @internal
 * Reports view @param o should be restored to default conditions
 *
 * @param o View.
 * @param frame Frame that originated restore.
 *
 * Emits signal: "restore" with frame.
 */
void ewk_view_restore_state(Evas_Object* o, Evas_Object* frame)
{
    evas_object_smart_callback_call(o, "restore", frame);
}

/**
 * @internal
 * Delegates to browser the creation of a new window. If it is not implemented,
 * current view is returned, so navigation might continue in same window. If
 * browser supports the creation of new windows, a new Ewk_Window_Features is
 * created and passed to browser. If it intends to keep the request for opening
 * the window later it must increments the Ewk_Winwdow_Features ref count by
 * calling ewk_window_features_ref(window_features). Otherwise this struct will
 * be freed after returning to this function.
 *
 * @param o Current view.
 * @param javascript @c EINA_TRUE if the new window is originated from javascript,
 * @c EINA_FALSE otherwise
 * @param window_features Features of the new window being created. If it's @c
 * NULL, it will be created a window with default features.
 *
 * @return New view, in case smart class implements the creation of new windows;
 * else, current view @param o.
 *
 * @see ewk_window_features_ref().
 */
Evas_Object* ewk_view_window_create(Evas_Object* o, Eina_Bool javascript, const WebCore::WindowFeatures* coreFeatures)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);

    if (!sd->api->window_create)
        return o;

    Ewk_Window_Features* window_features = ewk_window_features_new_from_core(coreFeatures);
    Evas_Object* view = sd->api->window_create(sd, javascript, window_features);
    ewk_window_features_unref(window_features);

    return view;
}

/**
 * @internal
 * Reports a window should be closed. It's client responsibility to decide if
 * the window should in fact be closed. So, if only windows created by javascript
 * are allowed to be closed by this call, browser needs to save the javascript
 * flag when the window is created. Since a window can close itself (for example
 * with a 'self.close()' in Javascript) browser must postpone the deletion to an
 * idler.
 *
 * @param o View to be closed.
 */
void ewk_view_window_close(Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);

    ewk_view_stop(o);
    if (!sd->api->window_close)
        return;
    sd->api->window_close(sd);
}

/**
 * @internal
 * Reports mouse has moved over a link.
 *
 * Emits signal: "link,hover,in"
 */
void ewk_view_mouse_link_hover_in(Evas_Object* o, void* data)
{
    evas_object_smart_callback_call(o, "link,hover,in", data);
}

/**
 * @internal
 * Reports mouse is not over a link anymore.
 *
 * Emits signal: "link,hover,out"
 */
void ewk_view_mouse_link_hover_out(Evas_Object* o)
{
    evas_object_smart_callback_call(o, "link,hover,out", 0);
}

/**
 * @internal
 * Set toolbar visible.
 *
 * Emits signal: "toolbars,visible,set" with a pointer to a boolean.
 */
void ewk_view_toolbars_visible_set(Evas_Object* o, Eina_Bool visible)
{
    DBG("o=%p (visible=%d)", o, !!visible);
    evas_object_smart_callback_call(o, "toolbars,visible,set", &visible);
}

/**
 * @internal
 * Get toolbar visibility.
 *
 * @param o View.
 * @param visible boolean pointer in which to save the result. It defaults
 * to @c FALSE, i.e. if browser does no listen to emitted signal, it means
 * there are no toolbars and therefore they are not visible.
 *
 * Emits signal: "toolbars,visible,get" with a pointer to a boolean.
 */
void ewk_view_toolbars_visible_get(Evas_Object* o, Eina_Bool* visible)
{
    DBG("%s, o=%p", __func__, o);
    *visible = EINA_FALSE;
    evas_object_smart_callback_call(o, "toolbars,visible,get", visible);
}

/**
 * @internal
 * Set statusbar visible.
 *
 * @param o View.
 * @param visible @c TRUE if statusbar are visible, @c FALSE otherwise.
 *
 * Emits signal: "statusbar,visible,set" with a pointer to a boolean.
 */
void ewk_view_statusbar_visible_set(Evas_Object* o, Eina_Bool visible)
{
    DBG("o=%p (visible=%d)", o, !!visible);
    evas_object_smart_callback_call(o, "statusbar,visible,set", &visible);
}

/**
 * @internal
 * Get statusbar visibility.
 *
 * @param o View.
 * @param visible boolean pointer in which to save the result. It defaults
 * to @c FALSE, i.e. if browser does no listen to emitted signal, it means
 * there is no statusbar and therefore it is not visible.
 *
 * Emits signal: "statusbar,visible,get" with a pointer to a boolean.
 */
void ewk_view_statusbar_visible_get(Evas_Object* o, Eina_Bool* visible)
{
    DBG("%s, o=%p", __func__, o);
    *visible = EINA_FALSE;
    evas_object_smart_callback_call(o, "statusbar,visible,get", visible);
}

/**
 * @internal
 * Set text of statusbar
 *
 * @param o View.
 * @param text New text to put on statusbar.
 *
 * Emits signal: "statusbar,text,set" with a string.
 */
void ewk_view_statusbar_text_set(Evas_Object* o, const char* text)
{
    DBG("o=%p (text=%s)", o, text);
    INF("status bar text set: %s", text);
    evas_object_smart_callback_call(o, "statusbar,text,set", (void *)text);
}

/**
 * @internal
 * Set scrollbars visible.
 *
 * @param o View.
 * @param visible @c TRUE if scrollbars are visible, @c FALSE otherwise.
 *
 * Emits signal: "scrollbars,visible,set" with a pointer to a boolean.
 */
void ewk_view_scrollbars_visible_set(Evas_Object* o, Eina_Bool visible)
{
    DBG("o=%p (visible=%d)", o, !!visible);
    evas_object_smart_callback_call(o, "scrollbars,visible,set", &visible);
}

/**
 * @internal
 * Get scrollbars visibility.
 *
 * @param o View.
 * @param visible boolean pointer in which to save the result. It defaults
 * to @c FALSE, i.e. if browser does no listen to emitted signal, it means
 * there are no scrollbars and therefore they are not visible.
 *
 * Emits signal: "scrollbars,visible,get" with a pointer to a boolean.
 */
void ewk_view_scrollbars_visible_get(Evas_Object* o, Eina_Bool* visible)
{
    DBG("%s, o=%p", __func__, o);
    *visible = EINA_FALSE;
    evas_object_smart_callback_call(o, "scrollbars,visible,get", visible);
}

/**
 * @internal
 * Set menubar visible.
 *
 * @param o View.
 * @param visible @c TRUE if menubar is visible, @c FALSE otherwise.
 *
 * Emits signal: "menubar,visible,set" with a pointer to a boolean.
 */
void ewk_view_menubar_visible_set(Evas_Object* o, Eina_Bool visible)
{
    DBG("o=%p (visible=%d)", o, !!visible);
    evas_object_smart_callback_call(o, "menubar,visible,set", &visible);
}

/**
 * @internal
 * Get menubar visibility.
 *
 * @param o View.
 * @param visible boolean pointer in which to save the result. It defaults
 * to @c FALSE, i.e. if browser does no listen to emitted signal, it means
 * there is no menubar and therefore it is not visible.
 *
 * Emits signal: "menubar,visible,get" with a pointer to a boolean.
 */
void ewk_view_menubar_visible_get(Evas_Object* o, Eina_Bool* visible)
{
    DBG("%s, o=%p", __func__, o);
    *visible = EINA_FALSE;
    evas_object_smart_callback_call(o, "menubar,visible,get", visible);
}

/**
 * @internal
 * Set tooltip text and display if it is currently hidden.
 *
 * @param o View.
 * @param text Text to set tooltip to.
 *
 * Emits signal: "tooltip,text,set" with a string. If tooltip must be actually
 * removed, text will be 0 or '\0'
 */
void ewk_view_tooltip_text_set(Evas_Object* o, const char* text)
{
    DBG("o=%p text=%s", o, text);
    evas_object_smart_callback_call(o, "tooltip,text,set", (void *)text);
}

/**
 * @internal
 *
 * @param o View.
 * @param message String to show on console.
 * @param lineNumber Line number.
 * @sourceID Source id.
 *
 */
void ewk_view_add_console_message(Evas_Object* o, const char* message, unsigned int lineNumber, const char* sourceID)
{
    DBG("o=%p message=%s lineNumber=%u sourceID=%s", o, message, lineNumber, sourceID);
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    EINA_SAFETY_ON_NULL_RETURN(sd->api);
    EINA_SAFETY_ON_NULL_RETURN(sd->api->add_console_message);
    sd->api->add_console_message(sd, message, lineNumber, sourceID);
}

void ewk_view_run_javascript_alert(Evas_Object* o, Evas_Object* frame, const char* message)
{
    DBG("o=%p frame=%p message=%s", o, frame, message);
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    EINA_SAFETY_ON_NULL_RETURN(sd->api);

    if (!sd->api->run_javascript_alert)
        return;

    sd->api->run_javascript_alert(sd, frame, message);
}

Eina_Bool ewk_view_run_javascript_confirm(Evas_Object* o, Evas_Object* frame, const char* message)
{
    DBG("o=%p frame=%p message=%s", o, frame, message);
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->api, EINA_FALSE);

    if (!sd->api->run_javascript_confirm)
        return EINA_FALSE;

    return sd->api->run_javascript_confirm(sd, frame, message);
}

Eina_Bool ewk_view_run_javascript_prompt(Evas_Object* o, Evas_Object* frame, const char* message, const char* defaultValue, char** value)
{
    DBG("o=%p frame=%p message=%s", o, frame, message);
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->api, EINA_FALSE);

    if (!sd->api->run_javascript_prompt)
        return EINA_FALSE;

    return sd->api->run_javascript_prompt(sd, frame, message, defaultValue, value);
}

/**
 * @internal
 * Delegates to client to decide whether a script must be stopped because it's
 * running for too long. If client does not implement it, it goes to default
 * implementation, which logs and returns EINA_FALSE. Client may remove log by
 * setting this function 0, which will just return EINA_FALSE.
 *
 * @param o View.
 *
 * @return @c EINA_TRUE if script should be stopped; @c EINA_FALSE otherwise
 */
Eina_Bool ewk_view_should_interrupt_javascript(Evas_Object* o)
{
    DBG("o=%p", o);
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->api, EINA_FALSE);

    if (!sd->api->should_interrupt_javascript)
        return EINA_FALSE;

    return sd->api->should_interrupt_javascript(sd);
}

/**
 * @internal
 * This is called whenever the web site shown in @param frame is asking to store data
 * to the database @param databaseName and the quota allocated to that web site
 * is exceeded. Browser may use this to increase the size of quota before the
 * originating operationa fails.
 *
 * @param o View.
 * @param frame The frame whose web page exceeded its database quota.
 * @param databaseName Database name.
 * @param current_size Current size of this database
 * @param expected_size The expected size of this database in order to fulfill
 * site's requirement.
 */
uint64_t ewk_view_exceeded_database_quota(Evas_Object* o, Evas_Object* frame, const char* databaseName, uint64_t current_size, uint64_t expected_size)
{
    DBG("o=%p", o);
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->api, 0);
    if (!sd->api->exceeded_database_quota)
        return 0;

    INF("current_size=%"PRIu64" expected_size="PRIu64, current_size, expected_size);
    return sd->api->exceeded_database_quota(sd, frame, databaseName, current_size, expected_size);
}

/**
 * @internal
 * Open panel to choose a file.
 *
 * @param o View.
 * @param frame Frame in which operation is required.
 * @param allows_multiple_files @c EINA_TRUE when more than one file may be
 * selected, @c EINA_FALSE otherwise
 * @suggested_filenames List of suggested files to select. It's advisable to
 * just ignore this value, since it's a source of security flaw.
 * @selected_filenames List of files selected.
 *
 * @return @EINA_FALSE if user canceled file selection; @EINA_TRUE if confirmed.
 */
Eina_Bool ewk_view_run_open_panel(Evas_Object* o, Evas_Object* frame, Eina_Bool allows_multiple_files, const Eina_List* suggested_filenames, Eina_List** selected_filenames)
{
    DBG("o=%p frame=%p allows_multiple_files=%d", o, frame, allows_multiple_files);
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->api, EINA_FALSE);
    Eina_Bool confirm;

    if (!sd->api->run_open_panel)
        return EINA_FALSE;

    *selected_filenames = 0;

    confirm = sd->api->run_open_panel(sd, frame, allows_multiple_files, suggested_filenames, selected_filenames);
    if (!confirm && *selected_filenames)
        ERR("Canceled file selection, but selected filenames != 0. Free names before return.");
    return confirm;
}

void ewk_view_repaint(Evas_Object* o, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
{
    DBG("o=%p, region=%d,%d + %dx%d", o, x, y, w, h);
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv);

    if (!priv->main_frame->contentRenderer()) {
        ERR("no main frame content renderer.");
        return;
    }

    _ewk_view_repaint_add(priv, x, y, w, h);
    _ewk_view_smart_changed(sd);
}

void ewk_view_scroll(Evas_Object* o, Evas_Coord dx, Evas_Coord dy, Evas_Coord sx, Evas_Coord sy, Evas_Coord sw, Evas_Coord sh, Evas_Coord cx, Evas_Coord cy, Evas_Coord cw, Evas_Coord ch, Eina_Bool main_frame)
{
    DBG("o=%p, delta: %d,%d, scroll: %d,%d+%dx%d, clip: %d,%d+%dx%d",
        o, dx, dy, sx, sy, sw, sh, cx, cy, cw, ch);

    if ((sx != cx) || (sy != cy) || (sw != cw) || (sh != ch))
        WRN("scroll region and clip are different! %d,%d+%dx%d and %d,%d+%dx%d",
            sx, sy, sw, sh, cx, cy, cw, ch);

    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv);
    EINA_SAFETY_ON_TRUE_RETURN(!dx && !dy);

    _ewk_view_scroll_add(priv, dx, dy, sx, sy, sw, sh, main_frame);
    _ewk_view_smart_changed(sd);
}

WebCore::Page* ewk_view_core_page_get(const Evas_Object* o)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);
    return priv->page;
}

/**
 * Creates a new frame for given url and owner element.
 *
 * Emits "frame,created" with the new frame object on success.
 */
WTF::PassRefPtr<WebCore::Frame> ewk_view_frame_create(Evas_Object* o, Evas_Object* frame, const WTF::String& name, WebCore::HTMLFrameOwnerElement* ownerElement, const WebCore::KURL& url, const WTF::String& referrer)
{
    DBG("o=%p, frame=%p, name=%s, ownerElement=%p, url=%s, referrer=%s",
        o, frame, name.utf8().data(), ownerElement,
        url.prettyURL().utf8().data(), referrer.utf8().data());

    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, 0);

    WTF::RefPtr<WebCore::Frame> cf = _ewk_view_core_frame_new
        (sd, priv, ownerElement);
    if (!cf) {
        ERR("Could not create child core frame '%s'", name.utf8().data());
        return 0;
    }

    if (!ewk_frame_child_add(frame, cf, name, url, referrer)) {
        ERR("Could not create child frame object '%s'", name.utf8().data());
        return 0;
    }

    // The creation of the frame may have removed itself already.
    if (!cf->page() || !cf->tree() || !cf->tree()->parent())
        return 0;

    sd->changed.frame_rect = EINA_TRUE;
    _ewk_view_smart_changed(sd);

    evas_object_smart_callback_call(o, "frame,created", frame);
    return cf.release();
}

WTF::PassRefPtr<WebCore::Widget> ewk_view_plugin_create(Evas_Object* o, Evas_Object* frame, const WebCore::IntSize& pluginSize, WebCore::HTMLPlugInElement* element, const WebCore::KURL& url, const WTF::Vector<WTF::String>& paramNames, const WTF::Vector<WTF::String>& paramValues, const WTF::String& mimeType, bool loadManually)
{
    DBG("o=%p, frame=%p, size=%dx%d, element=%p, url=%s, mimeType=%s",
        o, frame, pluginSize.width(), pluginSize.height(), element,
        url.prettyURL().utf8().data(), mimeType.utf8().data());

    EWK_VIEW_SD_GET_OR_RETURN(o, sd, 0);
    sd->changed.frame_rect = EINA_TRUE;
    _ewk_view_smart_changed(sd);

    return ewk_frame_plugin_create
        (frame, pluginSize, element, url, paramNames, paramValues,
         mimeType, loadManually);
}


/**
 * @internal
 *
 * Creates a new popup with options when a select widget was clicked.
 *
 * @param client PopupMenuClient instance that allows communication with webkit.
 * @param selected Selected item.
 * @param rect Menu's position.
 *
 * Emits: "popup,create" with a list of Ewk_Menu containing each item's data
 */
void ewk_view_popup_new(Evas_Object* o, WebCore::PopupMenuClient* client, int selected, const WebCore::IntRect& rect)
{
    INF("o=%p", o);
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv);

    if (priv->popup.menu_client)
        ewk_view_popup_destroy(o);

    priv->popup.menu_client = client;

    // populate items
    const int size = client->listSize();
    for (int i = 0; i < size; ++i) {
        Ewk_Menu_Item* item = (Ewk_Menu_Item*) malloc(sizeof(*item));
        if (client->itemIsSeparator(i))
            item->type = EWK_MENU_SEPARATOR;
        else if (client->itemIsLabel(i))
            item->type = EWK_MENU_GROUP;
        else
            item->type = EWK_MENU_OPTION;
        item->text = eina_stringshare_add(client->itemText(i).utf8().data());

        priv->popup.menu.items = eina_list_append(priv->popup.menu.items, item);
    }

    priv->popup.menu.x = rect.x();
    priv->popup.menu.y = rect.y();
    priv->popup.menu.width = rect.width();
    priv->popup.menu.height = rect.height();
    evas_object_smart_callback_call(o, "popup,create", &priv->popup.menu);
}

/**
 * Destroy a previously created menu.
 *
 * Before destroying, it informs client that menu's data is ready to be
 * destroyed by sending a "popup,willdelete" with a list of menu items. Then it
 * removes any reference to menu inside webkit. It's safe to call this
 * function either from inside webkit or from browser.
 *
 * @param o View.
 *
 * @returns EINA_TRUE in case menu was successfully destroyed or EINA_TRUE in
 * case there wasn't any menu to be destroyed.
 */
Eina_Bool ewk_view_popup_destroy(Evas_Object* o)
{
    INF("o=%p", o);
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_FALSE);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv, EINA_FALSE);

    if (!priv->popup.menu_client)
        return EINA_FALSE;

    evas_object_smart_callback_call(o, "popup,willdelete", &priv->popup.menu);

    void* itemv;
    EINA_LIST_FREE(priv->popup.menu.items, itemv) {
        Ewk_Menu_Item* item = (Ewk_Menu_Item*)itemv;
        eina_stringshare_del(item->text);
        free(item);
    }
    priv->popup.menu_client->popupDidHide();
    priv->popup.menu_client = 0;

    return EINA_TRUE;
}

/**
 * Changes currently selected item.
 *
 * Changes the option selected in select widget. This is called by browser
 * whenever user has chosen a different item. Most likely after calling this, a
 * call to ewk_view_popup_destroy might be made in order to close the popup.
 *
 * @param o View.
 * @index Index of selected item.
 *
 */
void ewk_view_popup_selected_set(Evas_Object* o, int index)
{
    INF("o=%p", o);
    EWK_VIEW_SD_GET_OR_RETURN(o, sd);
    EWK_VIEW_PRIV_GET_OR_RETURN(sd, priv);
    EINA_SAFETY_ON_NULL_RETURN(priv->popup.menu_client);

    priv->popup.menu_client->valueChanged(index);
}

/**
 * @internal
 * Request a download to user.
 *
 * @param o View.
 * @oaram download Ewk_Download struct to be sent.
 *
 * Emits: "download,request" with an Ewk_Download containing the details of the
 * requested download. The download per se must be handled outside of webkit.
 */
void ewk_view_download_request(Evas_Object* o, Ewk_Download* download)
{
    DBG("view=%p", o);
    evas_object_smart_callback_call(o, "download,request", download);
}

/**
 * @internal
 * Reports the viewport has changed.
 *
 * @param o view.
 * @param w width.
 * @param h height.
 * @param init_scale initialScale value.
 * @param max_scale maximumScale value.
 * @param min_scale minimumScale value.
 * @param user_scalable userscalable flag.
 *
 * Emits signal: "viewport,changed" with no parameters.
 */
void ewk_view_viewport_set(Evas_Object *o, float w, float h, float init_scale, float max_scale, float min_scale, float user_scalable)
{
    EWK_VIEW_SD_GET(o, sd);
    EWK_VIEW_PRIV_GET(sd, priv);

    priv->settings.viewport.w = w;
    priv->settings.viewport.h = h;
    priv->settings.viewport.init_scale = init_scale;
    priv->settings.viewport.min_scale = min_scale;
    priv->settings.viewport.max_scale = max_scale;
    priv->settings.viewport.user_scalable = user_scalable;

    evas_object_smart_callback_call(o, "viewport,changed", 0);
}

/**
 * Gets data of viewport meta tag.
 *
 * @param o view.
 * @param w width.
 * @param h height.
 * @param init_scale initial Scale value.
 * @param max_scale maximum Scale value.
 * @param min_scale minimum Scale value.
 * @param user_scalable user Scalable value.
 */
void ewk_view_viewport_get(Evas_Object *o, float* w, float* h, float* init_scale, float* max_scale, float* min_scale, float* user_scalable)
{
    EWK_VIEW_SD_GET(o, sd);
    EWK_VIEW_PRIV_GET(sd, priv);

    if (w)
        *w = priv->settings.viewport.w;
    if (h)
        *h = priv->settings.viewport.h;
    if (init_scale)
        *init_scale = priv->settings.viewport.init_scale;
    if (max_scale)
        *max_scale = priv->settings.viewport.max_scale;
    if (min_scale)
        *min_scale = priv->settings.viewport.min_scale;
    if (user_scalable)
        *user_scalable = priv->settings.viewport.user_scalable;
}

/**
 * Sets the zoom range.
 *
 * @param o view.
 * @param min_scale minimum value of zoom range.
 * @param max_scale maximum value of zoom range.
 * 
 * @return @c EINA_TRUE if zoom range is changed, @c EINA_FALSE if not or failure.
 */
Eina_Bool ewk_view_zoom_range_set(Evas_Object* o, float min_scale, float max_scale)
{
    EWK_VIEW_SD_GET(o, sd);
    EWK_VIEW_PRIV_GET(sd, priv);

    if (max_scale < min_scale) {
        WRN("min_scale is larger than max_scale");
        return EINA_FALSE;
    }

    priv->settings.zoom_range.min_scale = min_scale;
    priv->settings.zoom_range.max_scale = max_scale;

    return EINA_TRUE;
}

/**
 * Gets the minimum value of zoom range.
 *
 * @param o view.
 *
 * @return minimum value of zoom range.
 */
float ewk_view_zoom_range_min_get(Evas_Object* o)
{
    EWK_VIEW_SD_GET(o, sd);
    EWK_VIEW_PRIV_GET(sd, priv);

    return priv->settings.zoom_range.min_scale;
}

/**
 * Gets the maximum value of zoom range.
 *
 * @param o view.
 *
 * @return maximum value of zoom range.
 */
float ewk_view_zoom_range_max_get(Evas_Object* o)
{
    EWK_VIEW_SD_GET(o, sd);
    EWK_VIEW_PRIV_GET(sd, priv);

    return priv->settings.zoom_range.max_scale;
}

/**
 * Sets if zoom is enabled.
 *
 * @param o view.
 * @param user_scalable boolean pointer in which to enable zoom. It defaults
 * to @c EINA_TRUE.
 */
void ewk_view_user_scalable_set(Evas_Object* o, Eina_Bool user_scalable)
{
    EWK_VIEW_SD_GET(o, sd);
    EWK_VIEW_PRIV_GET(sd, priv);

    priv->settings.zoom_range.user_scalable = user_scalable;
}

/**
 * Gets if zoom is enabled.
 *
 * @param o view.
 * @param user_scalable where to return the current user scalable value.
 *
 * @return @c EINA_TRUE if zoom is enabled, @c EINA_FALSE if not.
 */
Eina_Bool ewk_view_user_scalable_get(Evas_Object* o)
{
    EWK_VIEW_SD_GET(o, sd);
    EWK_VIEW_PRIV_GET(sd, priv);

    return priv->settings.zoom_range.user_scalable;
}

/**
 * @internal
 * Reports a requeset will be loaded. It's client responsibility to decide if
 * request would be used. If @return is true, loader will try to load. Else,
 * Loader ignore action of request.
 *
 * @param o View to load
 * @param request Request which contain url to navigate
 */
Eina_Bool ewk_view_navigation_policy_decision(Evas_Object* o, Ewk_Frame_Resource_Request* request)
{
    EWK_VIEW_SD_GET_OR_RETURN(o, sd, EINA_TRUE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(sd->api, EINA_TRUE);

    if (!sd->api->navigation_policy_decision)
        return EINA_TRUE;

    return sd->api->navigation_policy_decision(sd, request);
}