Changeset 218982 in webkit
- Timestamp:
- Jun 29, 2017, 7:09:09 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r218965 r218982 1 2017-06-28 Simon Fraser <simon.fraser@apple.com> 2 3 getBoundingClientRect returns wrong value for combination of page zoom and scroll 4 https://bugs.webkit.org/show_bug.cgi?id=173841 5 rdar://problem/32983841 6 7 Reviewed by Dean Jackson. 8 9 * fast/events/clientXY-in-zoom-and-scroll.html: New baseline for progressed behavior. 10 * fast/events/simulated-click-zoomed-expected.txt: Added. 11 * fast/events/simulated-click-zoomed.html: Added. 12 * fast/visual-viewport/client-rects-relative-to-layout-viewport-zoomed-expected.txt: Added. 13 * fast/visual-viewport/client-rects-relative-to-layout-viewport-zoomed.html: Added. 14 * platform/ios/TestExpectations: 15 * platform/mac/fast/events/clientXY-in-zoom-and-scroll-expected.txt: 16 1 17 2017-06-29 John Wilander <wilander@apple.com> 2 18 -
trunk/LayoutTests/fast/events/clientXY-in-zoom-and-scroll.html
r216824 r218982 105 105 event = e; 106 106 debug("\nZoomed and scrolled"); 107 shouldBe("event.clientX", hasSubpixelSupport ? " 73" : "74");108 shouldBe("event.clientY", hasSubpixelSupport ? " 73" : "74");107 shouldBe("event.clientX", hasSubpixelSupport ? "83" : "84"); 108 shouldBe("event.clientY", hasSubpixelSupport ? "83" : "84"); 109 109 shouldBe("event.pageX", "133"); 110 110 shouldBe("event.pageY", "133"); -
trunk/LayoutTests/platform/ios/TestExpectations
r218722 r218982 328 328 fast/scrolling/scroll-animator-select-list-events.html [ Skip ] 329 329 fast/events/prevent-default-prevents-interaction-with-scrollbars.html [ Skip ] 330 fast/events/simulated-click-zoomed.html [ Skip ] 330 331 fast/text/text-disappear-on-deselect.html [ ImageOnlyFailure ] 331 332 fast/css/pseudo-active-on-labeled-control-without-renderer.html [ Skip ] … … 2727 2728 fast/scrolling/scroll-to-anchor-zoomed-header.html [ Skip ] 2728 2729 fast/visual-viewport/client-coordinates-relative-to-layout-viewport.html [ Skip ] 2730 fast/visual-viewport/client-rects-relative-to-layout-viewport-zoomed.html [ Skip ] 2729 2731 2730 2732 # On iOS we do not visually highlight a programmatic selection -
trunk/LayoutTests/platform/mac/fast/events/clientXY-in-zoom-and-scroll-expected.txt
r216824 r218982 18 18 19 19 Zoomed and scrolled 20 PASS event.clientX is 7321 PASS event.clientY is 7320 PASS event.clientX is 83 21 PASS event.clientY is 83 22 22 PASS event.pageX is 133 23 23 PASS event.pageY is 133 -
trunk/Source/WebCore/ChangeLog
r218979 r218982 1 2017-06-28 Simon Fraser <simon.fraser@apple.com> 2 3 getBoundingClientRect returns wrong value for combination of page zoom and scroll 4 https://bugs.webkit.org/show_bug.cgi?id=173841 5 rdar://problem/32983841 6 7 Reviewed by Dean Jackson. 8 9 The layout viewport returned by FrameView::layoutViewportRect() is affected by page (Command-+) zooming, 10 since it's computed using scroll positions, so when we use its origin to convert into client coordinates 11 (which are zoom-agnostic), we need to account for page zoom, so fix FrameView::documentToClientOffset() 12 to do this. 13 14 Callers of documentToClientOffset() were checked, revealing that event client coordinates were also 15 wrong with page zoom and are fixed in the same way. It was found that SimulatedClick was using an 16 entirely wrong rect to compute its location: Element::clientRect() is NOT in client coordinates, 17 so change this code to use getBoundingClientRect() instead. 18 19 Minor refactoring in MouseRelatedEvent to make getting to the FrameView cleaner. 20 21 Some geometry types enhanced to have non-mutating scale functions. 22 23 Tests: fast/events/simulated-click-zoomed.html 24 fast/visual-viewport/client-rects-relative-to-layout-viewport-zoomed.html 25 26 * dom/MouseRelatedEvent.cpp: 27 (WebCore::MouseRelatedEvent::init): 28 (WebCore::MouseRelatedEvent::initCoordinates): 29 (WebCore::MouseRelatedEvent::frameView): 30 (WebCore::MouseRelatedEvent::documentToAbsoluteScaleFactor): 31 (WebCore::MouseRelatedEvent::computePageLocation): 32 (WebCore::MouseRelatedEvent::computeRelativePosition): 33 (WebCore::pageZoomFactor): Deleted. 34 (WebCore::frameScaleFactor): Deleted. 35 * dom/MouseRelatedEvent.h: 36 (WebCore::MouseRelatedEvent::absoluteLocation): 37 (WebCore::MouseRelatedEvent::setAbsoluteLocation): Deleted. 38 * dom/SimulatedClick.cpp: 39 * page/FrameView.cpp: 40 (WebCore::FrameView::layoutViewportRect): baseLayoutViewportSize() is the same as the old code. 41 (WebCore::FrameView::documentToAbsoluteScaleFactor): 42 (WebCore::FrameView::absoluteToDocumentScaleFactor): 43 (WebCore::FrameView::absoluteToDocumentPoint): 44 (WebCore::FrameView::documentToClientOffset): 45 * page/FrameView.h: 46 * platform/graphics/FloatPoint.h: 47 (WebCore::FloatPoint::scale): 48 (WebCore::FloatPoint::scaled): 49 * platform/graphics/FloatSize.h: 50 (WebCore::FloatSize::scaled): 51 * platform/graphics/LayoutPoint.h: 52 (WebCore::LayoutPoint::scaled): 53 1 54 2017-06-29 Megan Gardner <megan_gardner@apple.com> 2 55 -
trunk/Source/WebCore/dom/Element.cpp
r218501 r218982 1163 1163 } 1164 1164 1165 Ref<DOMRect> Element::getBoundingClientRect()1165 FloatRect Element::boundingClientRect() 1166 1166 { 1167 1167 document().updateLayoutIgnorePendingStylesheets(); … … 1181 1181 1182 1182 if (quads.isEmpty()) 1183 return DOMRect::create();1183 return { }; 1184 1184 1185 1185 FloatRect result = quads[0].boundingBox(); … … 1188 1188 1189 1189 document().convertAbsoluteToClientRect(result, renderer()->style()); 1190 return DOMRect::create(result); 1190 return result; 1191 } 1192 1193 Ref<DOMRect> Element::getBoundingClientRect() 1194 { 1195 return DOMRect::create(boundingClientRect()); 1191 1196 } 1192 1197 -
trunk/Source/WebCore/dom/Element.h
r218345 r218982 174 174 WEBCORE_EXPORT IntRect boundsInRootViewSpace(); 175 175 176 FloatRect boundingClientRect(); 177 176 178 Ref<DOMRectList> getClientRects(); 177 179 Ref<DOMRect> getBoundingClientRect(); -
trunk/Source/WebCore/dom/MouseRelatedEvent.cpp
r216824 r218982 60 60 void MouseRelatedEvent::init(bool isSimulated, const IntPoint& windowLocation) 61 61 { 62 auto* frame = view() ? view()->frame() : nullptr; 63 if (frame && !isSimulated) { 64 if (FrameView* frameView = frame->view()) { 62 if (!isSimulated) { 63 if (auto* frameView = this->frameView()) { 65 64 FloatPoint absolutePoint = frameView->windowToContents(windowLocation); 66 65 FloatPoint documentPoint = frameView->absoluteToDocumentPoint(absolutePoint); … … 89 88 // Correct values are computed lazily, see computeRelativePosition. 90 89 FloatSize documentToClientOffset; 91 auto* frame = view() ? view()->frame() : nullptr; 92 if (frame) { 93 if (FrameView* frameView = frame->view()) 94 documentToClientOffset = frameView->documentToClientOffset(); 95 } 90 if (auto* frameView = this->frameView()) 91 documentToClientOffset = frameView->documentToClientOffset(); 96 92 97 93 m_clientLocation = clientLocation; … … 105 101 } 106 102 107 static float pageZoomFactor(const UIEvent* event) 108 { 109 DOMWindow* window = event->view(); 110 if (!window) 111 return 1; 112 Frame* frame = window->frame(); 103 FrameView* MouseRelatedEvent::frameView() const 104 { 105 auto* frame = view() ? view()->frame() : nullptr; 113 106 if (!frame) 114 return 1; 115 return frame->pageZoomFactor(); 116 } 117 118 static float frameScaleFactor(const UIEvent* event) 119 { 120 DOMWindow* window = event->view(); 121 if (!window) 122 return 1; 123 Frame* frame = window->frame(); 124 if (!frame) 125 return 1; 126 return frame->frameScaleFactor(); 107 return nullptr; 108 109 return frame->view(); 110 } 111 112 float MouseRelatedEvent::documentToAbsoluteScaleFactor() const 113 { 114 if (auto* frameView = this->frameView()) 115 return frameView->documentToAbsoluteScaleFactor(); 116 117 return 1; 127 118 } 128 119 129 120 void MouseRelatedEvent::computePageLocation() 130 121 { 131 float scaleFactor = pageZoomFactor(this) * frameScaleFactor(this); 132 setAbsoluteLocation(LayoutPoint(pageX() * scaleFactor, pageY() * scaleFactor)); 122 m_absoluteLocation = m_pageLocation.scaled(documentToAbsoluteScaleFactor()); 133 123 } 134 124 … … 154 144 if (RenderObject* r = targetNode->renderer()) { 155 145 m_offsetLocation = LayoutPoint(r->absoluteToLocal(absoluteLocation(), UseTransforms)); 156 float scaleFactor = 1 / (pageZoomFactor(this) * frameScaleFactor(this));146 float scaleFactor = 1 / documentToAbsoluteScaleFactor(); 157 147 if (scaleFactor != 1.0f) 158 148 m_offsetLocation.scale(scaleFactor); -
trunk/Source/WebCore/dom/MouseRelatedEvent.h
r216824 r218982 28 28 29 29 namespace WebCore { 30 31 class FrameView; 30 32 31 33 struct MouseRelatedEventInit : public EventModifierInit { … … 63 65 // usable with RenderObject::absoluteToLocal). 64 66 const LayoutPoint& absoluteLocation() const { return m_absoluteLocation; } 65 void setAbsoluteLocation(const LayoutPoint& p) { m_absoluteLocation = p; }66 67 67 68 protected: … … 81 82 void computePageLocation(); 82 83 void computeRelativePosition(); 84 85 float documentToAbsoluteScaleFactor() const; 86 FrameView* frameView() const; 83 87 84 88 // Expose these so MouseEvent::initMouseEvent can set them. -
trunk/Source/WebCore/dom/SimulatedClick.cpp
r210216 r218982 27 27 #include "SimulatedClick.h" 28 28 29 #include "DOMRect.h" 29 30 #include "DataTransfer.h" 30 31 #include "Element.h" … … 73 74 // Note that the call to screenRect() causes a synchronous IPC with the UI process. 74 75 m_screenLocation = target.screenRect().center(); 75 initCoordinates(LayoutPoint(target. clientRect().center()));76 initCoordinates(LayoutPoint(target.boundingClientRect().center())); 76 77 } 77 78 } -
trunk/Source/WebCore/page/FrameView.cpp
r218928 r218982 1979 1979 1980 1980 // Size of initial containing block, anchored at scroll position, in document coordinates (unchanged by scale factor). 1981 return LayoutRect(m_layoutViewportOrigin, renderView() ? renderView()->size() : size());1981 return LayoutRect(m_layoutViewportOrigin, baseLayoutViewportSize()); 1982 1982 } 1983 1983 … … 4883 4883 } 4884 4884 4885 float FrameView::documentToAbsoluteScaleFactor(std::optional<float> effectiveZoom) const 4886 { 4887 // If effectiveZoom is passed, it already factors in pageZoomFactor(). 4888 return effectiveZoom.value_or(frame().pageZoomFactor()) * frame().frameScaleFactor(); 4889 } 4890 4885 4891 float FrameView::absoluteToDocumentScaleFactor(std::optional<float> effectiveZoom) const 4886 4892 { 4887 4893 // If effectiveZoom is passed, it already factors in pageZoomFactor(). 4888 float cssZoom = effectiveZoom.value_or(frame().pageZoomFactor()); 4889 return 1 / (cssZoom * frame().frameScaleFactor()); 4894 return 1 / documentToAbsoluteScaleFactor(effectiveZoom); 4890 4895 } 4891 4896 … … 4898 4903 FloatPoint FrameView::absoluteToDocumentPoint(FloatPoint p, std::optional<float> effectiveZoom) const 4899 4904 { 4900 p.scale(absoluteToDocumentScaleFactor(effectiveZoom)); 4901 return p; 4905 return p.scaled(absoluteToDocumentScaleFactor(effectiveZoom)); 4902 4906 } 4903 4907 4904 4908 FloatSize FrameView::documentToClientOffset() const 4905 4909 { 4906 return frame().settings().visualViewportEnabled() ? -toFloatSize(layoutViewportRect().location()) : -toFloatSize(visibleContentRect().location()); 4910 FloatSize clientOrigin = frame().settings().visualViewportEnabled() ? -toFloatSize(layoutViewportRect().location()) : -toFloatSize(visibleContentRect().location()); 4911 4912 // Layout and visual viewports are affected by page zoom, so we need to factor that out. 4913 return clientOrigin.scaled(1 / frame().pageZoomFactor()); 4907 4914 } 4908 4915 -
trunk/Source/WebCore/page/FrameView.h
r218501 r218982 260 260 WEBCORE_EXPORT void setLayoutViewportOverrideRect(std::optional<LayoutRect>); 261 261 262 // These are in document coordinates, unaffected by zooming.262 // These are in document coordinates, unaffected by page scale (but affected by zooming). 263 263 WEBCORE_EXPORT LayoutRect layoutViewportRect() const; 264 264 WEBCORE_EXPORT LayoutRect visualViewportRect() const; … … 446 446 // "Document" 447 447 // Relative to the document's scroll origin, but not affected by page zoom or page scale. Size is equivalent to CSS pixel dimensions. 448 // FIXME: some uses are affected by page zoom (e.g. layout and visual viewports). 448 449 // 449 450 // "Client" … … 464 465 IntPoint convertFromContainingView(const IntPoint&) const final; 465 466 467 float documentToAbsoluteScaleFactor(std::optional<float> effectiveZoom = std::nullopt) const; 466 468 float absoluteToDocumentScaleFactor(std::optional<float> effectiveZoom = std::nullopt) const; 469 467 470 FloatRect absoluteToDocumentRect(FloatRect, std::optional<float> effectiveZoom = std::nullopt) const; 468 471 FloatPoint absoluteToDocumentPoint(FloatPoint, std::optional<float> effectiveZoom = std::nullopt) const; -
trunk/Source/WebCore/platform/graphics/FloatPoint.h
r218368 r218982 119 119 } 120 120 121 void scale(float sx, float sy) 122 { 123 m_x *= sx; 124 m_y *= sy; 121 void scale(float scaleX, float scaleY) 122 { 123 m_x *= scaleX; 124 m_y *= scaleY; 125 } 126 127 FloatPoint scaled(float scale) 128 { 129 return { m_x * scale, m_y * scale }; 130 } 131 132 FloatPoint scaled(float scaleX, float scaleY) 133 { 134 return { m_x * scaleX, m_y * scaleY }; 125 135 } 126 136 -
trunk/Source/WebCore/platform/graphics/FloatSize.h
r218368 r218982 95 95 } 96 96 97 FloatSize scaled(float s) const 98 { 99 return { m_width * s, m_height * s }; 100 } 101 102 FloatSize scaled(float scaleX, float scaleY) const 103 { 104 return { m_width * scaleX, m_height * scaleY }; 105 } 106 97 107 WEBCORE_EXPORT FloatSize constrainedBetween(const FloatSize& min, const FloatSize& max) const; 98 108 -
trunk/Source/WebCore/platform/graphics/LayoutPoint.h
r218368 r218982 68 68 } 69 69 70 LayoutPoint scaled(float s) const 71 { 72 return { m_x * s, m_y * s }; 73 } 74 75 LayoutPoint scaled(float sx, float sy) const 76 { 77 return { m_x * sx, m_y * sy }; 78 } 79 70 80 LayoutPoint constrainedBetween(const LayoutPoint& min, const LayoutPoint& max) const; 71 81 -
trunk/Tools/ChangeLog
r218965 r218982 1 2017-06-28 Simon Fraser <simon.fraser@apple.com> 2 3 getBoundingClientRect returns wrong value for combination of page zoom and scroll 4 https://bugs.webkit.org/show_bug.cgi?id=173841 5 rdar://problem/32983841 6 7 Reviewed by Dean Jackson. 8 9 Make "Zoom In" and "Zoom Out" work correctly in the WebKit1 window. Previously they 10 always did text zooming. 11 12 * MiniBrowser/mac/WK1BrowserWindowController.m: 13 (-[WK1BrowserWindowController zoomIn:]): 14 (-[WK1BrowserWindowController zoomOut:]): 15 (-[WK1BrowserWindowController canResetZoom]): 16 (-[WK1BrowserWindowController resetZoom:]): 17 1 18 2017-06-29 John Wilander <wilander@apple.com> 2 19 -
trunk/Tools/MiniBrowser/mac/WK1BrowserWindowController.m
r217117 r218982 200 200 return; 201 201 202 [_webView makeTextLarger:sender]; 202 if (_zoomTextOnly) 203 [_webView makeTextLarger:sender]; 204 else 205 [_webView zoomPageIn:sender]; 206 203 207 } 204 208 … … 213 217 return; 214 218 215 [_webView makeTextSmaller:sender]; 219 if (_zoomTextOnly) 220 [_webView makeTextSmaller:sender]; 221 else 222 [_webView zoomPageOut:sender]; 216 223 } 217 224 218 225 - (BOOL)canResetZoom 219 226 { 220 return [_webView canMakeTextStandardSize];227 return _zoomTextOnly ? [_webView canMakeTextStandardSize] : [_webView canResetPageZoom]; 221 228 } 222 229 … … 226 233 return; 227 234 228 [_webView makeTextStandardSize:sender]; 235 if (_zoomTextOnly) 236 [_webView makeTextStandardSize:sender]; 237 else 238 [_webView resetPageZoom:sender]; 229 239 } 230 240
Note:
See TracChangeset
for help on using the changeset viewer.