Skip to content

Commit b56595c

Browse files
committed
Fixed position elements are misplaced when a WK1 view has contentInsets set
https://bugs.webkit.org/show_bug.cgi?id=135031 -and corresponding- <rdar://problem/17682335> Reviewed by Tim Horton. [NSScrollView documentVisibleRect] includes content that is within the inset-area of a view, but WebCore is interested in the content that is fully visible, so we need to factor the inset sizes out of this rect. Implement contract() to avoid the awkwardness of calling expand() with negative values. * platform/graphics/IntSize.h: (WebCore::IntSize::contract): Factor out insets * platform/mac/ScrollViewMac.mm: (WebCore::ScrollView::platformVisibleContentRect): (WebCore::ScrollView::platformVisibleContentSize): Canonical link: https://commits.webkit.org/152977@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@171246 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent fa9e382 commit b56595c

3 files changed

Lines changed: 51 additions & 11 deletions

File tree

Source/WebCore/ChangeLog

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
2014-07-18 Beth Dakin <bdakin@apple.com>
2+
3+
Fixed position elements are misplaced when a WK1 view has contentInsets set
4+
https://bugs.webkit.org/show_bug.cgi?id=135031
5+
-and corresponding-
6+
<rdar://problem/17682335>
7+
8+
Reviewed by Tim Horton.
9+
10+
[NSScrollView documentVisibleRect] includes content that is within the inset-area
11+
of a view, but WebCore is interested in the content that is fully visible, so we
12+
need to factor the inset sizes out of this rect.
13+
14+
Implement contract() to avoid the awkwardness of calling expand() with negative
15+
values.
16+
* platform/graphics/IntSize.h:
17+
(WebCore::IntSize::contract):
18+
19+
Factor out insets
20+
* platform/mac/ScrollViewMac.mm:
21+
(WebCore::ScrollView::platformVisibleContentRect):
22+
(WebCore::ScrollView::platformVisibleContentSize):
23+
124
2014-07-18 Tim Horton <timothy_horton@apple.com>
225

326
Take navigation snapshots whenever the current back-forward item is going to change

Source/WebCore/platform/graphics/IntSize.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ class IntSize {
8181
m_height += height;
8282
}
8383

84+
void contract(int width, int height)
85+
{
86+
m_width -= width;
87+
m_height -= height;
88+
}
89+
8490
void scale(float widthScale, float heightScale)
8591
{
8692
m_width = static_cast<int>(static_cast<float>(m_width) * widthScale);

Source/WebCore/platform/mac/ScrollViewMac.mm

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
#import "NotImplemented.h"
3535
#import "WebCoreFrameView.h"
3636

37+
@interface NSScrollView (Details)
38+
- (NSEdgeInsets)contentInsets;
39+
@end
40+
3741
@interface NSWindow (WebWindowDetails)
3842
- (BOOL)_needsToResetDragMargins;
3943
- (void)_setNeedsToResetDragMargins:(BOOL)needs;
@@ -107,23 +111,30 @@ - (void)_setNeedsToResetDragMargins:(BOOL)needs;
107111
IntRect ScrollView::platformVisibleContentRect(bool includeScrollbars) const
108112
{
109113
BEGIN_BLOCK_OBJC_EXCEPTIONS;
110-
IntRect result = enclosingIntRect([scrollView() documentVisibleRect]);
111-
if (includeScrollbars)
112-
result.setSize(IntSize([scrollView() frame].size));
113-
return result;
114+
115+
IntRect visibleContentRect = enclosingIntRect([scrollView() documentVisibleRect]);
116+
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
117+
visibleContentRect.move(scrollView().contentInsets.left, scrollView().contentInsets.top);
118+
visibleContentRect.contract(scrollView().contentInsets.left + scrollView().contentInsets.right, scrollView().contentInsets.top + scrollView().contentInsets.bottom);
119+
#endif
120+
121+
if (includeScrollbars) {
122+
IntSize frameSize = IntSize([scrollView() frame].size);
123+
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
124+
frameSize.contract(scrollView().contentInsets.left + scrollView().contentInsets.right, scrollView().contentInsets.top + scrollView().contentInsets.bottom);
125+
#endif
126+
visibleContentRect.setSize(frameSize);
127+
}
128+
129+
return visibleContentRect;
114130
END_BLOCK_OBJC_EXCEPTIONS;
131+
115132
return IntRect();
116133
}
117134

118135
IntSize ScrollView::platformVisibleContentSize(bool includeScrollbars) const
119136
{
120-
BEGIN_BLOCK_OBJC_EXCEPTIONS;
121-
if (includeScrollbars)
122-
return IntSize([scrollView() frame].size);
123-
124-
return expandedIntSize(FloatSize([scrollView() documentVisibleRect].size));
125-
END_BLOCK_OBJC_EXCEPTIONS;
126-
return IntSize();
137+
return platformVisibleContentRect(includeScrollbars).size();
127138
}
128139

129140
void ScrollView::platformSetContentsSize()

0 commit comments

Comments
 (0)