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
|
/*
* Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "ScrollView.h"
#include "AXObjectCache.h"
#if PLATFORM(ANDROID)
#include "FrameView.h"
#include "GraphicsLayerAndroid.h"
#include "RenderLayer.h"
#include "RenderLayerBacking.h"
#include "RenderView.h"
#endif
#include "GraphicsContext.h"
#include "GraphicsLayer.h"
#include "HostWindow.h"
#include "PlatformMouseEvent.h"
#include "PlatformWheelEvent.h"
#include "ScrollAnimator.h"
#include "Scrollbar.h"
#include "ScrollbarTheme.h"
#include <wtf/StdLibExtras.h>
using namespace std;
namespace WebCore {
ScrollView::ScrollView()
: m_horizontalScrollbarMode(ScrollbarAuto)
, m_verticalScrollbarMode(ScrollbarAuto)
, m_horizontalScrollbarLock(false)
, m_verticalScrollbarLock(false)
, m_prohibitsScrolling(false)
, m_canBlitOnScroll(true)
, m_scrollbarsAvoidingResizer(0)
, m_scrollbarsSuppressed(false)
, m_inUpdateScrollbars(false)
, m_updateScrollbarsPass(0)
, m_drawPanScrollIcon(false)
, m_useFixedLayout(false)
, m_paintsEntireContents(false)
, m_clipsRepaints(true)
, m_delegatesScrolling(false)
, m_containsScrollableAreaWithOverlayScrollbars(false)
{
platformInit();
}
ScrollView::~ScrollView()
{
platformDestroy();
}
void ScrollView::addChild(PassRefPtr<Widget> prpChild)
{
Widget* child = prpChild.get();
ASSERT(child != this && !child->parent());
child->setParent(this);
m_children.add(prpChild);
if (child->platformWidget())
platformAddChild(child);
}
void ScrollView::removeChild(Widget* child)
{
ASSERT(child->parent() == this);
child->setParent(0);
m_children.remove(child);
if (child->platformWidget())
platformRemoveChild(child);
}
void ScrollView::setHasHorizontalScrollbar(bool hasBar)
{
if (hasBar && avoidScrollbarCreation())
return;
if (hasBar && !m_horizontalScrollbar) {
m_horizontalScrollbar = createScrollbar(HorizontalScrollbar);
addChild(m_horizontalScrollbar.get());
didAddHorizontalScrollbar(m_horizontalScrollbar.get());
m_horizontalScrollbar->styleChanged();
} else if (!hasBar && m_horizontalScrollbar) {
willRemoveHorizontalScrollbar(m_horizontalScrollbar.get());
removeChild(m_horizontalScrollbar.get());
m_horizontalScrollbar = 0;
}
if (AXObjectCache::accessibilityEnabled() && axObjectCache())
axObjectCache()->handleScrollbarUpdate(this);
}
void ScrollView::setHasVerticalScrollbar(bool hasBar)
{
if (hasBar && avoidScrollbarCreation())
return;
if (hasBar && !m_verticalScrollbar) {
m_verticalScrollbar = createScrollbar(VerticalScrollbar);
addChild(m_verticalScrollbar.get());
didAddVerticalScrollbar(m_verticalScrollbar.get());
m_verticalScrollbar->styleChanged();
} else if (!hasBar && m_verticalScrollbar) {
willRemoveVerticalScrollbar(m_verticalScrollbar.get());
removeChild(m_verticalScrollbar.get());
m_verticalScrollbar = 0;
}
if (AXObjectCache::accessibilityEnabled() && axObjectCache())
axObjectCache()->handleScrollbarUpdate(this);
}
#if !USE(NATIVE_GTK_MAIN_FRAME_SCROLLBAR)
PassRefPtr<Scrollbar> ScrollView::createScrollbar(ScrollbarOrientation orientation)
{
return Scrollbar::createNativeScrollbar(this, orientation, RegularScrollbar);
}
void ScrollView::setScrollbarModes(ScrollbarMode horizontalMode, ScrollbarMode verticalMode,
bool horizontalLock, bool verticalLock)
{
bool needsUpdate = false;
if (horizontalMode != horizontalScrollbarMode() && !m_horizontalScrollbarLock) {
m_horizontalScrollbarMode = horizontalMode;
needsUpdate = true;
}
if (verticalMode != verticalScrollbarMode() && !m_verticalScrollbarLock) {
m_verticalScrollbarMode = verticalMode;
needsUpdate = true;
}
if (horizontalLock)
setHorizontalScrollbarLock();
if (verticalLock)
setVerticalScrollbarLock();
if (!needsUpdate)
return;
if (platformWidget())
platformSetScrollbarModes();
else
updateScrollbars(scrollOffset());
}
#endif
void ScrollView::scrollbarModes(ScrollbarMode& horizontalMode, ScrollbarMode& verticalMode) const
{
if (platformWidget()) {
platformScrollbarModes(horizontalMode, verticalMode);
return;
}
horizontalMode = m_horizontalScrollbarMode;
verticalMode = m_verticalScrollbarMode;
}
void ScrollView::setCanHaveScrollbars(bool canScroll)
{
ScrollbarMode newHorizontalMode;
ScrollbarMode newVerticalMode;
scrollbarModes(newHorizontalMode, newVerticalMode);
if (canScroll && newVerticalMode == ScrollbarAlwaysOff)
newVerticalMode = ScrollbarAuto;
else if (!canScroll)
newVerticalMode = ScrollbarAlwaysOff;
if (canScroll && newHorizontalMode == ScrollbarAlwaysOff)
newHorizontalMode = ScrollbarAuto;
else if (!canScroll)
newHorizontalMode = ScrollbarAlwaysOff;
setScrollbarModes(newHorizontalMode, newVerticalMode);
}
void ScrollView::setCanBlitOnScroll(bool b)
{
if (platformWidget()) {
platformSetCanBlitOnScroll(b);
return;
}
m_canBlitOnScroll = b;
}
bool ScrollView::canBlitOnScroll() const
{
if (platformWidget())
return platformCanBlitOnScroll();
return m_canBlitOnScroll;
}
void ScrollView::setPaintsEntireContents(bool paintsEntireContents)
{
m_paintsEntireContents = paintsEntireContents;
}
void ScrollView::setClipsRepaints(bool clipsRepaints)
{
m_clipsRepaints = clipsRepaints;
}
void ScrollView::setDelegatesScrolling(bool delegatesScrolling)
{
m_delegatesScrolling = delegatesScrolling;
}
#if !USE(NATIVE_GTK_MAIN_FRAME_SCROLLBAR)
IntRect ScrollView::visibleContentRect(bool includeScrollbars) const
{
if (platformWidget())
return platformVisibleContentRect(includeScrollbars);
if (paintsEntireContents())
return IntRect(IntPoint(0, 0), contentsSize());
int verticalScrollbarWidth = verticalScrollbar() && !verticalScrollbar()->isOverlayScrollbar()
&& !includeScrollbars ? verticalScrollbar()->width() : 0;
int horizontalScrollbarHeight = horizontalScrollbar() && !horizontalScrollbar()->isOverlayScrollbar()
&& !includeScrollbars ? horizontalScrollbar()->height() : 0;
return IntRect(IntPoint(m_scrollOffset.width(), m_scrollOffset.height()),
IntSize(max(0, m_boundsSize.width() - verticalScrollbarWidth),
max(0, m_boundsSize.height() - horizontalScrollbarHeight)));
}
#endif
int ScrollView::layoutWidth() const
{
return m_fixedLayoutSize.isEmpty() || !m_useFixedLayout ? visibleWidth() : m_fixedLayoutSize.width();
}
int ScrollView::layoutHeight() const
{
return m_fixedLayoutSize.isEmpty() || !m_useFixedLayout ? visibleHeight() : m_fixedLayoutSize.height();
}
IntSize ScrollView::fixedLayoutSize() const
{
return m_fixedLayoutSize;
}
void ScrollView::setFixedLayoutSize(const IntSize& newSize)
{
if (fixedLayoutSize() == newSize)
return;
m_fixedLayoutSize = newSize;
updateScrollbars(scrollOffset());
}
bool ScrollView::useFixedLayout() const
{
return m_useFixedLayout;
}
void ScrollView::setUseFixedLayout(bool enable)
{
if (useFixedLayout() == enable)
return;
m_useFixedLayout = enable;
updateScrollbars(scrollOffset());
}
IntSize ScrollView::contentsSize() const
{
if (platformWidget())
return platformContentsSize();
return m_contentsSize;
}
void ScrollView::setContentsSize(const IntSize& newSize)
{
if (contentsSize() == newSize)
return;
m_contentsSize = newSize;
if (platformWidget())
platformSetContentsSize();
else
updateScrollbars(scrollOffset());
}
#if PLATFORM(ANDROID)
FrameView* ScrollView::frameView() {
if (this->isFrameView()) {
FrameView* frameView = reinterpret_cast<FrameView*>(this);
return frameView;
}
return 0;
}
#endif
IntPoint ScrollView::maximumScrollPosition() const
{
IntPoint maximumOffset(contentsWidth() - visibleWidth() - m_scrollOrigin.x(), contentsHeight() - visibleHeight() - m_scrollOrigin.y());
maximumOffset.clampNegativeToZero();
return maximumOffset;
}
IntPoint ScrollView::minimumScrollPosition() const
{
return IntPoint(-m_scrollOrigin.x(), -m_scrollOrigin.y());
}
IntPoint ScrollView::adjustScrollPositionWithinRange(const IntPoint& scrollPoint) const
{
IntPoint newScrollPosition = scrollPoint.shrunkTo(maximumScrollPosition());
newScrollPosition = newScrollPosition.expandedTo(minimumScrollPosition());
return newScrollPosition;
}
int ScrollView::scrollSize(ScrollbarOrientation orientation) const
{
Scrollbar* scrollbar = ((orientation == HorizontalScrollbar) ? m_horizontalScrollbar : m_verticalScrollbar).get();
return scrollbar ? (scrollbar->totalSize() - scrollbar->visibleSize()) : 0;
}
void ScrollView::didCompleteRubberBand(const IntSize&) const
{
}
void ScrollView::notifyPageThatContentAreaWillPaint() const
{
}
void ScrollView::setScrollOffset(const IntPoint& offset)
{
int horizontalOffset = offset.x();
int verticalOffset = offset.y();
if (constrainsScrollingToContentEdge()) {
horizontalOffset = max(min(horizontalOffset, contentsWidth() - visibleWidth()), 0);
verticalOffset = max(min(verticalOffset, contentsHeight() - visibleHeight()), 0);
}
IntSize newOffset = m_scrollOffset;
newOffset.setWidth(horizontalOffset - m_scrollOrigin.x());
newOffset.setHeight(verticalOffset - m_scrollOrigin.y());
scrollTo(newOffset);
}
void ScrollView::scrollTo(const IntSize& newOffset)
{
IntSize scrollDelta = newOffset - m_scrollOffset;
if (scrollDelta == IntSize())
return;
m_scrollOffset = newOffset;
#if PLATFORM(ANDROID)
if (parent()) {
FrameView* frameView = this->frameView();
// IFrames are composited on a layer, we do not need to repaint them
// when scrolling
if (frameView) {
RenderView* renderer = frameView->frame()->contentRenderer();
if (renderer) {
RenderLayer* layer = renderer->layer();
if (layer->backing()) {
GraphicsLayerAndroid* backing = static_cast<GraphicsLayerAndroid*>(
layer->backing()->graphicsLayer());
backing->updateScrollOffset();
}
}
return;
}
}
#endif
if (scrollbarsSuppressed())
return;
repaintFixedElementsAfterScrolling();
scrollContents(scrollDelta);
}
int ScrollView::scrollPosition(Scrollbar* scrollbar) const
{
if (scrollbar->orientation() == HorizontalScrollbar)
return scrollPosition().x() + m_scrollOrigin.x();
if (scrollbar->orientation() == VerticalScrollbar)
return scrollPosition().y() + m_scrollOrigin.y();
return 0;
}
void ScrollView::setScrollPosition(const IntPoint& scrollPoint)
{
if (prohibitsScrolling())
return;
if (platformWidget()) {
platformSetScrollPosition(scrollPoint);
return;
}
#if ENABLE(TILED_BACKING_STORE)
if (delegatesScrolling()) {
hostWindow()->delegatedScrollRequested(scrollPoint);
if (!m_actualVisibleContentRect.isEmpty())
m_actualVisibleContentRect.setLocation(scrollPoint);
return;
}
#endif
IntPoint newScrollPosition = adjustScrollPositionWithinRange(scrollPoint);
if (newScrollPosition == scrollPosition())
return;
updateScrollbars(IntSize(newScrollPosition.x(), newScrollPosition.y()));
}
bool ScrollView::scroll(ScrollDirection direction, ScrollGranularity granularity)
{
if (platformWidget())
return platformScroll(direction, granularity);
return ScrollableArea::scroll(direction, granularity);
}
bool ScrollView::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity)
{
return scroll(logicalToPhysical(direction, isVerticalDocument(), isFlippedDocument()), granularity);
}
IntSize ScrollView::overhangAmount() const
{
IntSize stretch;
int physicalScrollY = scrollPosition().y() + m_scrollOrigin.y();
if (physicalScrollY < 0)
stretch.setHeight(physicalScrollY);
else if (physicalScrollY > contentsHeight() - visibleContentRect().height())
stretch.setHeight(physicalScrollY - (contentsHeight() - visibleContentRect().height()));
int physicalScrollX = scrollPosition().x() + m_scrollOrigin.x();
if (physicalScrollX < 0)
stretch.setWidth(physicalScrollX);
else if (physicalScrollX > contentsWidth() - visibleContentRect().width())
stretch.setWidth(physicalScrollX - (contentsWidth() - visibleContentRect().width()));
return stretch;
}
void ScrollView::windowResizerRectChanged()
{
if (platformWidget())
return;
updateScrollbars(scrollOffset());
}
static const unsigned cMaxUpdateScrollbarsPass = 2;
void ScrollView::updateScrollbars(const IntSize& desiredOffset)
{
if (m_inUpdateScrollbars || prohibitsScrolling() || delegatesScrolling() || platformWidget())
return;
// If we came in here with the view already needing a layout, then go ahead and do that
// first. (This will be the common case, e.g., when the page changes due to window resizing for example).
// This layout will not re-enter updateScrollbars and does not count towards our max layout pass total.
if (!m_scrollbarsSuppressed) {
m_inUpdateScrollbars = true;
visibleContentsResized();
m_inUpdateScrollbars = false;
}
bool hasHorizontalScrollbar = m_horizontalScrollbar;
bool hasVerticalScrollbar = m_verticalScrollbar;
bool newHasHorizontalScrollbar = hasHorizontalScrollbar;
bool newHasVerticalScrollbar = hasVerticalScrollbar;
ScrollbarMode hScroll = m_horizontalScrollbarMode;
ScrollbarMode vScroll = m_verticalScrollbarMode;
if (hScroll != ScrollbarAuto)
newHasHorizontalScrollbar = (hScroll == ScrollbarAlwaysOn);
if (vScroll != ScrollbarAuto)
newHasVerticalScrollbar = (vScroll == ScrollbarAlwaysOn);
if (m_scrollbarsSuppressed || (hScroll != ScrollbarAuto && vScroll != ScrollbarAuto)) {
if (hasHorizontalScrollbar != newHasHorizontalScrollbar)
setHasHorizontalScrollbar(newHasHorizontalScrollbar);
if (hasVerticalScrollbar != newHasVerticalScrollbar)
setHasVerticalScrollbar(newHasVerticalScrollbar);
} else {
bool sendContentResizedNotification = false;
IntSize docSize = contentsSize();
IntSize frameSize = m_boundsSize;
if (hScroll == ScrollbarAuto) {
newHasHorizontalScrollbar = docSize.width() > visibleWidth();
if (newHasHorizontalScrollbar && !m_updateScrollbarsPass && docSize.width() <= frameSize.width() && docSize.height() <= frameSize.height())
newHasHorizontalScrollbar = false;
}
if (vScroll == ScrollbarAuto) {
newHasVerticalScrollbar = docSize.height() > visibleHeight();
if (newHasVerticalScrollbar && !m_updateScrollbarsPass && docSize.width() <= frameSize.width() && docSize.height() <= frameSize.height())
newHasVerticalScrollbar = false;
}
// If we ever turn one scrollbar off, always turn the other one off too. Never ever
// try to both gain/lose a scrollbar in the same pass.
if (!newHasHorizontalScrollbar && hasHorizontalScrollbar && vScroll != ScrollbarAlwaysOn)
newHasVerticalScrollbar = false;
if (!newHasVerticalScrollbar && hasVerticalScrollbar && hScroll != ScrollbarAlwaysOn)
newHasHorizontalScrollbar = false;
if (hasHorizontalScrollbar != newHasHorizontalScrollbar) {
if (m_scrollOrigin.y() && !newHasHorizontalScrollbar)
m_scrollOrigin.setY(m_scrollOrigin.y() - m_horizontalScrollbar->height());
setHasHorizontalScrollbar(newHasHorizontalScrollbar);
sendContentResizedNotification = true;
}
if (hasVerticalScrollbar != newHasVerticalScrollbar) {
if (m_scrollOrigin.x() && !newHasVerticalScrollbar)
m_scrollOrigin.setX(m_scrollOrigin.x() - m_verticalScrollbar->width());
setHasVerticalScrollbar(newHasVerticalScrollbar);
sendContentResizedNotification = true;
}
if (sendContentResizedNotification && m_updateScrollbarsPass < cMaxUpdateScrollbarsPass) {
m_updateScrollbarsPass++;
contentsResized();
visibleContentsResized();
IntSize newDocSize = contentsSize();
if (newDocSize == docSize) {
// The layout with the new scroll state had no impact on
// the document's overall size, so updateScrollbars didn't get called.
// Recur manually.
updateScrollbars(desiredOffset);
}
m_updateScrollbarsPass--;
}
}
// Set up the range (and page step/line step), but only do this if we're not in a nested call (to avoid
// doing it multiple times).
if (m_updateScrollbarsPass)
return;
m_inUpdateScrollbars = true;
IntPoint scrollPoint = adjustScrollPositionWithinRange(IntPoint(desiredOffset));
IntSize scroll(scrollPoint.x(), scrollPoint.y());
if (m_horizontalScrollbar) {
int clientWidth = visibleWidth();
m_horizontalScrollbar->setEnabled(contentsWidth() > clientWidth);
int pageStep = max(max<int>(clientWidth * Scrollbar::minFractionToStepWhenPaging(), clientWidth - Scrollbar::maxOverlapBetweenPages()), 1);
IntRect oldRect(m_horizontalScrollbar->frameRect());
IntRect hBarRect = IntRect(0,
m_boundsSize.height() - m_horizontalScrollbar->height(),
m_boundsSize.width() - (m_verticalScrollbar ? m_verticalScrollbar->width() : 0),
m_horizontalScrollbar->height());
m_horizontalScrollbar->setFrameRect(hBarRect);
if (!m_scrollbarsSuppressed && oldRect != m_horizontalScrollbar->frameRect())
m_horizontalScrollbar->invalidate();
if (m_scrollbarsSuppressed)
m_horizontalScrollbar->setSuppressInvalidation(true);
m_horizontalScrollbar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep);
m_horizontalScrollbar->setProportion(clientWidth, contentsWidth());
if (m_scrollbarsSuppressed)
m_horizontalScrollbar->setSuppressInvalidation(false);
}
if (m_verticalScrollbar) {
int clientHeight = visibleHeight();
m_verticalScrollbar->setEnabled(contentsHeight() > clientHeight);
int pageStep = max(max<int>(clientHeight * Scrollbar::minFractionToStepWhenPaging(), clientHeight - Scrollbar::maxOverlapBetweenPages()), 1);
IntRect oldRect(m_verticalScrollbar->frameRect());
IntRect vBarRect = IntRect(m_boundsSize.width() - m_verticalScrollbar->width(),
0,
m_verticalScrollbar->width(),
m_boundsSize.height() - (m_horizontalScrollbar ? m_horizontalScrollbar->height() : 0));
m_verticalScrollbar->setFrameRect(vBarRect);
if (!m_scrollbarsSuppressed && oldRect != m_verticalScrollbar->frameRect())
m_verticalScrollbar->invalidate();
if (m_scrollbarsSuppressed)
m_verticalScrollbar->setSuppressInvalidation(true);
m_verticalScrollbar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep);
m_verticalScrollbar->setProportion(clientHeight, contentsHeight());
if (m_scrollbarsSuppressed)
m_verticalScrollbar->setSuppressInvalidation(false);
}
if (hasHorizontalScrollbar != (m_horizontalScrollbar != 0) || hasVerticalScrollbar != (m_verticalScrollbar != 0)) {
frameRectsChanged();
updateScrollCorner();
}
ScrollableArea::scrollToOffsetWithoutAnimation(FloatPoint(scroll.width() + m_scrollOrigin.x(), scroll.height() + m_scrollOrigin.y()));
// Make sure the scrollbar offsets are up to date.
if (m_horizontalScrollbar)
m_horizontalScrollbar->offsetDidChange();
if (m_verticalScrollbar)
m_verticalScrollbar->offsetDidChange();
m_inUpdateScrollbars = false;
}
const int panIconSizeLength = 16;
void ScrollView::scrollContents(const IntSize& scrollDelta)
{
if (!hostWindow())
return;
// Since scrolling is double buffered, we will be blitting the scroll view's intersection
// with the clip rect every time to keep it smooth.
IntRect clipRect = windowClipRect();
IntRect scrollViewRect = convertToContainingWindow(IntRect(0, 0, visibleWidth(), visibleHeight()));
if (hasOverlayScrollbars()) {
int verticalScrollbarWidth = verticalScrollbar() ? verticalScrollbar()->width() : 0;
int horizontalScrollbarHeight = horizontalScrollbar() ? horizontalScrollbar()->height() : 0;
scrollViewRect.setWidth(scrollViewRect.width() - verticalScrollbarWidth);
scrollViewRect.setHeight(scrollViewRect.height() - horizontalScrollbarHeight);
}
IntRect updateRect = clipRect;
updateRect.intersect(scrollViewRect);
// Invalidate the window (not the backing store).
hostWindow()->invalidateWindow(updateRect, false /*immediate*/);
if (m_drawPanScrollIcon) {
// FIXME: the pan icon is broken when accelerated compositing is on, since it will draw under the compositing layers.
// https://bugs.webkit.org/show_bug.cgi?id=47837
int panIconDirtySquareSizeLength = 2 * (panIconSizeLength + max(abs(scrollDelta.width()), abs(scrollDelta.height()))); // We only want to repaint what's necessary
IntPoint panIconDirtySquareLocation = IntPoint(m_panScrollIconPoint.x() - (panIconDirtySquareSizeLength / 2), m_panScrollIconPoint.y() - (panIconDirtySquareSizeLength / 2));
IntRect panScrollIconDirtyRect = IntRect(panIconDirtySquareLocation , IntSize(panIconDirtySquareSizeLength, panIconDirtySquareSizeLength));
panScrollIconDirtyRect.intersect(clipRect);
hostWindow()->invalidateContentsAndWindow(panScrollIconDirtyRect, false /*immediate*/);
}
if (canBlitOnScroll()) { // The main frame can just blit the WebView window
// FIXME: Find a way to scroll subframes with this faster path
if (!scrollContentsFastPath(-scrollDelta, scrollViewRect, clipRect))
scrollContentsSlowPath(updateRect);
} else {
// We need to go ahead and repaint the entire backing store. Do it now before moving the
// windowed plugins.
scrollContentsSlowPath(updateRect);
}
// Invalidate the overhang areas if they are visible.
IntRect horizontalOverhangRect;
IntRect verticalOverhangRect;
calculateOverhangAreasForPainting(horizontalOverhangRect, verticalOverhangRect);
if (!horizontalOverhangRect.isEmpty())
hostWindow()->invalidateContentsAndWindow(horizontalOverhangRect, false /*immediate*/);
if (!verticalOverhangRect.isEmpty())
hostWindow()->invalidateContentsAndWindow(verticalOverhangRect, false /*immediate*/);
// This call will move children with native widgets (plugins) and invalidate them as well.
frameRectsChanged();
// Now blit the backingstore into the window which should be very fast.
hostWindow()->invalidateWindow(IntRect(), true);
}
bool ScrollView::scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect)
{
hostWindow()->scroll(scrollDelta, rectToScroll, clipRect);
return true;
}
void ScrollView::scrollContentsSlowPath(const IntRect& updateRect)
{
hostWindow()->invalidateContentsForSlowScroll(updateRect, false);
}
IntPoint ScrollView::windowToContents(const IntPoint& windowPoint) const
{
IntPoint viewPoint = convertFromContainingWindow(windowPoint);
return viewPoint + scrollOffset();
}
IntPoint ScrollView::contentsToWindow(const IntPoint& contentsPoint) const
{
IntPoint viewPoint = contentsPoint - scrollOffset();
return convertToContainingWindow(viewPoint);
}
IntRect ScrollView::windowToContents(const IntRect& windowRect) const
{
IntRect viewRect = convertFromContainingWindow(windowRect);
viewRect.move(scrollOffset());
return viewRect;
}
IntRect ScrollView::contentsToWindow(const IntRect& contentsRect) const
{
IntRect viewRect = contentsRect;
viewRect.move(-scrollOffset());
return convertToContainingWindow(viewRect);
}
IntRect ScrollView::contentsToScreen(const IntRect& rect) const
{
if (platformWidget())
return platformContentsToScreen(rect);
if (!hostWindow())
return IntRect();
return hostWindow()->windowToScreen(contentsToWindow(rect));
}
IntPoint ScrollView::screenToContents(const IntPoint& point) const
{
if (platformWidget())
return platformScreenToContents(point);
if (!hostWindow())
return IntPoint();
return windowToContents(hostWindow()->screenToWindow(point));
}
bool ScrollView::containsScrollbarsAvoidingResizer() const
{
return !m_scrollbarsAvoidingResizer;
}
void ScrollView::adjustScrollbarsAvoidingResizerCount(int overlapDelta)
{
int oldCount = m_scrollbarsAvoidingResizer;
m_scrollbarsAvoidingResizer += overlapDelta;
if (parent())
parent()->adjustScrollbarsAvoidingResizerCount(overlapDelta);
else if (!scrollbarsSuppressed()) {
// If we went from n to 0 or from 0 to n and we're the outermost view,
// we need to invalidate the windowResizerRect(), since it will now need to paint
// differently.
if ((oldCount > 0 && m_scrollbarsAvoidingResizer == 0) ||
(oldCount == 0 && m_scrollbarsAvoidingResizer > 0))
invalidateRect(windowResizerRect());
}
}
void ScrollView::setParent(ScrollView* parentView)
{
if (parentView == parent())
return;
if (m_scrollbarsAvoidingResizer && parent())
parent()->adjustScrollbarsAvoidingResizerCount(-m_scrollbarsAvoidingResizer);
Widget::setParent(parentView);
if (m_scrollbarsAvoidingResizer && parent())
parent()->adjustScrollbarsAvoidingResizerCount(m_scrollbarsAvoidingResizer);
}
void ScrollView::setScrollbarsSuppressed(bool suppressed, bool repaintOnUnsuppress)
{
if (suppressed == m_scrollbarsSuppressed)
return;
m_scrollbarsSuppressed = suppressed;
if (platformWidget())
platformSetScrollbarsSuppressed(repaintOnUnsuppress);
else if (repaintOnUnsuppress && !suppressed) {
if (m_horizontalScrollbar)
m_horizontalScrollbar->invalidate();
if (m_verticalScrollbar)
m_verticalScrollbar->invalidate();
// Invalidate the scroll corner too on unsuppress.
invalidateRect(scrollCornerRect());
}
}
Scrollbar* ScrollView::scrollbarAtPoint(const IntPoint& windowPoint)
{
if (platformWidget())
return 0;
IntPoint viewPoint = convertFromContainingWindow(windowPoint);
if (m_horizontalScrollbar && m_horizontalScrollbar->frameRect().contains(viewPoint))
return m_horizontalScrollbar.get();
if (m_verticalScrollbar && m_verticalScrollbar->frameRect().contains(viewPoint))
return m_verticalScrollbar.get();
return 0;
}
void ScrollView::wheelEvent(PlatformWheelEvent& e)
{
// We don't allow mouse wheeling to happen in a ScrollView that has had its scrollbars explicitly disabled.
#if PLATFORM(WX)
if (!canHaveScrollbars()) {
#else
if (!canHaveScrollbars() || platformWidget()) {
#endif
return;
}
ScrollableArea::handleWheelEvent(e);
}
#if ENABLE(GESTURE_EVENTS)
void ScrollView::gestureEvent(const PlatformGestureEvent& gestureEvent)
{
if (platformWidget())
return;
ScrollableArea::handleGestureEvent(gestureEvent);
}
#endif
void ScrollView::setFrameRect(const IntRect& newRect)
{
IntRect oldRect = frameRect();
if (newRect == oldRect)
return;
Widget::setFrameRect(newRect);
}
void ScrollView::setBoundsSize(const IntSize& newSize)
{
if (newSize == m_boundsSize)
return;
Widget::setBoundsSize(newSize);
m_boundsSize = newSize;
if (platformWidget())
return;
updateScrollbars(m_scrollOffset);
if (!m_useFixedLayout)
contentsResized();
frameRectsChanged();
}
void ScrollView::setInitialBoundsSize(const IntSize& newSize)
{
ASSERT(m_boundsSize.isZero());
m_boundsSize = newSize;
}
void ScrollView::frameRectsChanged()
{
if (platformWidget())
return;
HashSet<RefPtr<Widget> >::const_iterator end = m_children.end();
for (HashSet<RefPtr<Widget> >::const_iterator current = m_children.begin(); current != end; ++current)
(*current)->frameRectsChanged();
positionScrollbarLayers();
}
#if USE(ACCELERATED_COMPOSITING)
static void positionScrollbarLayer(GraphicsLayer* graphicsLayer, Scrollbar* scrollbar)
{
if (!graphicsLayer || !scrollbar)
return;
graphicsLayer->setDrawsContent(true);
IntRect scrollbarRect = scrollbar->frameRect();
graphicsLayer->setPosition(scrollbarRect.location());
if (scrollbarRect.size() != graphicsLayer->size())
graphicsLayer->setNeedsDisplay();
graphicsLayer->setSize(scrollbarRect.size());
}
static void positionScrollCornerLayer(GraphicsLayer* graphicsLayer, const IntRect& cornerRect)
{
if (!graphicsLayer)
return;
graphicsLayer->setDrawsContent(!cornerRect.isEmpty());
graphicsLayer->setPosition(cornerRect.location());
if (cornerRect.size() != graphicsLayer->size())
graphicsLayer->setNeedsDisplay();
graphicsLayer->setSize(cornerRect.size());
}
#endif
void ScrollView::positionScrollbarLayers()
{
#if USE(ACCELERATED_COMPOSITING)
positionScrollbarLayer(layerForHorizontalScrollbar(), horizontalScrollbar());
positionScrollbarLayer(layerForVerticalScrollbar(), verticalScrollbar());
positionScrollCornerLayer(layerForScrollCorner(), scrollCornerRect());
#endif
}
void ScrollView::repaintContentRectangle(const IntRect& rect, bool now)
{
IntRect paintRect = rect;
if (clipsRepaints() && !paintsEntireContents())
paintRect.intersect(visibleContentRect());
#ifdef ANDROID_CAPTURE_OFFSCREEN_PAINTS
if (rect != paintRect)
platformOffscreenContentRectangle(visibleContentRect(), rect);
#endif
if (paintRect.isEmpty())
return;
if (platformWidget()) {
platformRepaintContentRectangle(paintRect, now);
return;
}
if (hostWindow())
hostWindow()->invalidateContentsAndWindow(contentsToWindow(paintRect), now /*immediate*/);
}
IntRect ScrollView::scrollCornerRect() const
{
IntRect cornerRect;
if (hasOverlayScrollbars())
return cornerRect;
if (m_horizontalScrollbar && m_boundsSize.width() - m_horizontalScrollbar->width() > 0) {
cornerRect.unite(IntRect(m_horizontalScrollbar->width(),
m_boundsSize.height() - m_horizontalScrollbar->height(),
m_boundsSize.width() - m_horizontalScrollbar->width(),
m_horizontalScrollbar->height()));
}
if (m_verticalScrollbar && m_boundsSize.height() - m_verticalScrollbar->height() > 0) {
cornerRect.unite(IntRect(m_boundsSize.width() - m_verticalScrollbar->width(),
m_verticalScrollbar->height(),
m_verticalScrollbar->width(),
m_boundsSize.height() - m_verticalScrollbar->height()));
}
return cornerRect;
}
bool ScrollView::isScrollCornerVisible() const
{
return !scrollCornerRect().isEmpty();
}
void ScrollView::updateScrollCorner()
{
}
void ScrollView::paintScrollCorner(GraphicsContext* context, const IntRect& cornerRect)
{
ScrollbarTheme::nativeTheme()->paintScrollCorner(this, context, cornerRect);
}
void ScrollView::invalidateScrollCornerRect(const IntRect& rect)
{
invalidateRect(rect);
}
void ScrollView::paintScrollbars(GraphicsContext* context, const IntRect& rect)
{
if (m_horizontalScrollbar
#if USE(ACCELERATED_COMPOSITING)
&& !layerForHorizontalScrollbar()
#endif
)
m_horizontalScrollbar->paint(context, rect);
if (m_verticalScrollbar
#if USE(ACCELERATED_COMPOSITING)
&& !layerForVerticalScrollbar()
#endif
)
m_verticalScrollbar->paint(context, rect);
#if USE(ACCELERATED_COMPOSITING)
if (layerForScrollCorner())
return;
#endif
paintScrollCorner(context, scrollCornerRect());
}
void ScrollView::paintPanScrollIcon(GraphicsContext* context)
{
static Image* panScrollIcon = Image::loadPlatformResource("panIcon").releaseRef();
context->drawImage(panScrollIcon, ColorSpaceDeviceRGB, m_panScrollIconPoint);
}
void ScrollView::paint(GraphicsContext* context, const IntRect& rect)
{
if (platformWidget()) {
Widget::paint(context, rect);
return;
}
if (context->paintingDisabled() && !context->updatingControlTints())
return;
notifyPageThatContentAreaWillPaint();
// If we encounter any overlay scrollbars as we paint, this will be set to true.
m_containsScrollableAreaWithOverlayScrollbars = false;
IntRect documentDirtyRect = rect;
documentDirtyRect.intersect(frameRect());
context->save();
context->translate(x(), y());
documentDirtyRect.move(-x(), -y());
if (!paintsEntireContents()) {
context->translate(-scrollX(), -scrollY());
documentDirtyRect.move(scrollX(), scrollY());
context->clip(visibleContentRect());
}
paintContents(context, documentDirtyRect);
context->restore();
IntRect horizontalOverhangRect;
IntRect verticalOverhangRect;
calculateOverhangAreasForPainting(horizontalOverhangRect, verticalOverhangRect);
if (rect.intersects(horizontalOverhangRect) || rect.intersects(verticalOverhangRect))
paintOverhangAreas(context, horizontalOverhangRect, verticalOverhangRect, rect);
// Now paint the scrollbars.
if (!m_scrollbarsSuppressed && (m_horizontalScrollbar || m_verticalScrollbar)) {
context->save();
IntRect scrollViewDirtyRect = rect;
scrollViewDirtyRect.intersect(frameRect());
context->translate(x(), y());
scrollViewDirtyRect.move(-x(), -y());
paintScrollbars(context, scrollViewDirtyRect);
context->restore();
}
// Paint the panScroll Icon
if (m_drawPanScrollIcon)
paintPanScrollIcon(context);
}
void ScrollView::calculateOverhangAreasForPainting(IntRect& horizontalOverhangRect, IntRect& verticalOverhangRect)
{
int verticalScrollbarWidth = (verticalScrollbar() && !verticalScrollbar()->isOverlayScrollbar())
? verticalScrollbar()->width() : 0;
int horizontalScrollbarHeight = (horizontalScrollbar() && !horizontalScrollbar()->isOverlayScrollbar())
? horizontalScrollbar()->height() : 0;
int physicalScrollY = scrollPosition().y() + m_scrollOrigin.y();
if (physicalScrollY < 0) {
horizontalOverhangRect = frameRect();
horizontalOverhangRect.setHeight(-physicalScrollY);
} else if (physicalScrollY > contentsHeight() - visibleContentRect().height()) {
int height = physicalScrollY - (contentsHeight() - visibleContentRect().height());
horizontalOverhangRect = frameRect();
horizontalOverhangRect.setY(frameRect().maxY() - height - horizontalScrollbarHeight);
horizontalOverhangRect.setHeight(height);
}
int physicalScrollX = scrollPosition().x() + m_scrollOrigin.x();
if (physicalScrollX < 0) {
verticalOverhangRect.setWidth(-physicalScrollX);
verticalOverhangRect.setHeight(frameRect().height() - horizontalOverhangRect.height());
verticalOverhangRect.setX(frameRect().x());
if (horizontalOverhangRect.y() == frameRect().y())
verticalOverhangRect.setY(frameRect().y() + horizontalOverhangRect.height());
else
verticalOverhangRect.setY(frameRect().y());
} else if (physicalScrollX > contentsWidth() - visibleContentRect().width()) {
int width = physicalScrollX - (contentsWidth() - visibleContentRect().width());
verticalOverhangRect.setWidth(width);
verticalOverhangRect.setHeight(frameRect().height() - horizontalOverhangRect.height());
verticalOverhangRect.setX(frameRect().maxX() - width - verticalScrollbarWidth);
if (horizontalOverhangRect.y() == frameRect().y())
verticalOverhangRect.setY(frameRect().y() + horizontalOverhangRect.height());
else
verticalOverhangRect.setY(frameRect().y());
}
}
void ScrollView::paintOverhangAreas(GraphicsContext* context, const IntRect& horizontalOverhangRect, const IntRect& verticalOverhangRect, const IntRect&)
{
// FIXME: This should be checking the dirty rect.
context->setFillColor(Color::white, ColorSpaceDeviceRGB);
if (!horizontalOverhangRect.isEmpty())
context->fillRect(horizontalOverhangRect);
context->setFillColor(Color::white, ColorSpaceDeviceRGB);
if (!verticalOverhangRect.isEmpty())
context->fillRect(verticalOverhangRect);
}
bool ScrollView::isPointInScrollbarCorner(const IntPoint& windowPoint)
{
if (!scrollbarCornerPresent())
return false;
IntPoint viewPoint = convertFromContainingWindow(windowPoint);
if (m_horizontalScrollbar) {
int horizontalScrollbarYMin = m_horizontalScrollbar->frameRect().y();
int horizontalScrollbarYMax = m_horizontalScrollbar->frameRect().y() + m_horizontalScrollbar->frameRect().height();
int horizontalScrollbarXMin = m_horizontalScrollbar->frameRect().x() + m_horizontalScrollbar->frameRect().width();
return viewPoint.y() > horizontalScrollbarYMin && viewPoint.y() < horizontalScrollbarYMax && viewPoint.x() > horizontalScrollbarXMin;
}
int verticalScrollbarXMin = m_verticalScrollbar->frameRect().x();
int verticalScrollbarXMax = m_verticalScrollbar->frameRect().x() + m_verticalScrollbar->frameRect().width();
int verticalScrollbarYMin = m_verticalScrollbar->frameRect().y() + m_verticalScrollbar->frameRect().height();
return viewPoint.x() > verticalScrollbarXMin && viewPoint.x() < verticalScrollbarXMax && viewPoint.y() > verticalScrollbarYMin;
}
bool ScrollView::scrollbarCornerPresent() const
{
return (m_horizontalScrollbar && m_boundsSize.width() - m_horizontalScrollbar->width() > 0) ||
(m_verticalScrollbar && m_boundsSize.height() - m_verticalScrollbar->height() > 0);
}
IntRect ScrollView::convertFromScrollbarToContainingView(const Scrollbar* scrollbar, const IntRect& localRect) const
{
// Scrollbars won't be transformed within us
IntRect newRect = localRect;
newRect.move(scrollbar->x(), scrollbar->y());
return newRect;
}
IntRect ScrollView::convertFromContainingViewToScrollbar(const Scrollbar* scrollbar, const IntRect& parentRect) const
{
IntRect newRect = parentRect;
// Scrollbars won't be transformed within us
newRect.move(-scrollbar->x(), -scrollbar->y());
return newRect;
}
// FIXME: test these on windows
IntPoint ScrollView::convertFromScrollbarToContainingView(const Scrollbar* scrollbar, const IntPoint& localPoint) const
{
// Scrollbars won't be transformed within us
IntPoint newPoint = localPoint;
newPoint.move(scrollbar->x(), scrollbar->y());
return newPoint;
}
IntPoint ScrollView::convertFromContainingViewToScrollbar(const Scrollbar* scrollbar, const IntPoint& parentPoint) const
{
IntPoint newPoint = parentPoint;
// Scrollbars won't be transformed within us
newPoint.move(-scrollbar->x(), -scrollbar->y());
return newPoint;
}
void ScrollView::setParentVisible(bool visible)
{
if (isParentVisible() == visible)
return;
Widget::setParentVisible(visible);
if (!isSelfVisible())
return;
HashSet<RefPtr<Widget> >::iterator end = m_children.end();
for (HashSet<RefPtr<Widget> >::iterator it = m_children.begin(); it != end; ++it)
(*it)->setParentVisible(visible);
}
void ScrollView::show()
{
if (!isSelfVisible()) {
setSelfVisible(true);
if (isParentVisible()) {
HashSet<RefPtr<Widget> >::iterator end = m_children.end();
for (HashSet<RefPtr<Widget> >::iterator it = m_children.begin(); it != end; ++it)
(*it)->setParentVisible(true);
}
}
Widget::show();
}
void ScrollView::hide()
{
if (isSelfVisible()) {
if (isParentVisible()) {
HashSet<RefPtr<Widget> >::iterator end = m_children.end();
for (HashSet<RefPtr<Widget> >::iterator it = m_children.begin(); it != end; ++it)
(*it)->setParentVisible(false);
}
setSelfVisible(false);
}
Widget::hide();
}
bool ScrollView::isOffscreen() const
{
if (platformWidget())
return platformIsOffscreen();
if (!isVisible())
return true;
// FIXME: Add a HostWindow::isOffscreen method here. Since only Mac implements this method
// currently, we can add the method when the other platforms decide to implement this concept.
return false;
}
void ScrollView::addPanScrollIcon(const IntPoint& iconPosition)
{
if (!hostWindow())
return;
m_drawPanScrollIcon = true;
m_panScrollIconPoint = IntPoint(iconPosition.x() - panIconSizeLength / 2 , iconPosition.y() - panIconSizeLength / 2) ;
hostWindow()->invalidateContentsAndWindow(IntRect(m_panScrollIconPoint, IntSize(panIconSizeLength, panIconSizeLength)), true /*immediate*/);
}
void ScrollView::removePanScrollIcon()
{
if (!hostWindow())
return;
m_drawPanScrollIcon = false;
hostWindow()->invalidateContentsAndWindow(IntRect(m_panScrollIconPoint, IntSize(panIconSizeLength, panIconSizeLength)), true /*immediate*/);
}
void ScrollView::setScrollOrigin(const IntPoint& origin, bool updatePositionAtAll, bool updatePositionSynchronously)
{
if (m_scrollOrigin == origin)
return;
m_scrollOrigin = origin;
if (platformWidget()) {
platformSetScrollOrigin(origin, updatePositionAtAll, updatePositionSynchronously);
return;
}
// Update if the scroll origin changes, since our position will be different if the content size did not change.
if (updatePositionAtAll && updatePositionSynchronously)
updateScrollbars(scrollOffset());
}
#if !PLATFORM(WX) && !USE(NATIVE_GTK_MAIN_FRAME_SCROLLBAR) && !PLATFORM(EFL)
void ScrollView::platformInit()
{
}
void ScrollView::platformDestroy()
{
}
#endif
#if !PLATFORM(WX) && !PLATFORM(QT) && !PLATFORM(MAC)
void ScrollView::platformAddChild(Widget*)
{
}
void ScrollView::platformRemoveChild(Widget*)
{
}
#endif
#if !PLATFORM(MAC)
void ScrollView::platformSetScrollbarsSuppressed(bool)
{
}
void ScrollView::platformSetScrollOrigin(const IntPoint&, bool updatePositionAtAll, bool updatePositionSynchronously)
{
}
#endif
#if !PLATFORM(MAC) && !PLATFORM(WX)
#if !PLATFORM(ANDROID)
void ScrollView::platformSetScrollbarModes()
{
}
void ScrollView::platformScrollbarModes(ScrollbarMode& horizontal, ScrollbarMode& vertical) const
{
horizontal = ScrollbarAuto;
vertical = ScrollbarAuto;
}
#endif
void ScrollView::platformSetCanBlitOnScroll(bool)
{
}
bool ScrollView::platformCanBlitOnScroll() const
{
return false;
}
#if !PLATFORM(ANDROID)
IntRect ScrollView::platformVisibleContentRect(bool) const
{
return IntRect();
}
#endif
#if !PLATFORM(ANDROID)
IntSize ScrollView::platformContentsSize() const
{
return IntSize();
}
#endif
void ScrollView::platformSetContentsSize()
{
}
IntRect ScrollView::platformContentsToScreen(const IntRect& rect) const
{
return rect;
}
IntPoint ScrollView::platformScreenToContents(const IntPoint& point) const
{
return point;
}
#if !PLATFORM(ANDROID)
void ScrollView::platformSetScrollPosition(const IntPoint&)
{
}
#endif
bool ScrollView::platformScroll(ScrollDirection, ScrollGranularity)
{
return true;
}
#if !PLATFORM(ANDROID)
void ScrollView::platformRepaintContentRectangle(const IntRect&, bool /*now*/)
{
}
#ifdef ANDROID_CAPTURE_OFFSCREEN_PAINTS
void ScrollView::platformOffscreenContentRectangle(const IntRect& )
{
}
#endif
bool ScrollView::platformIsOffscreen() const
{
return false;
}
#endif
#endif
}
|