Changeset 38186 in webkit
- Timestamp:
- Nov 6, 2008 10:42:24 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r38148 r38186 1 2008-11-05 Simon Fraser <simon.fraser@apple.com> 2 3 Reviewed by Dave Hyatt 4 5 https://bugs.webkit.org/show_bug.cgi?id=21870 6 7 Test event.offsetX/offsetY for various types of elements, which 8 exercises absoluteToLocal() code. 9 10 * fast/events/offsetX-offsetY-expected.txt: Added. 11 * fast/events/offsetX-offsetY.html: Added. 12 1 13 2008-11-05 Gavin Barraclough <barraclough@apple.com> 2 14 -
trunk/WebCore/ChangeLog
r38184 r38186 1 2008-11-05 Simon Fraser <simon.fraser@apple.com> 2 3 Reviewed by Dave Hyatt 4 5 https://bugs.webkit.org/show_bug.cgi?id=21870 6 7 Implement absoluteToLocal() to convert a point from absolute 8 to local coordinates, optionally taking transforms into account. 9 10 Use this to set offsetX/offsetY in mouse events, thus fixing 11 offsetX/offsetY in events on elements with transforms. 12 13 Test: fast/events/offsetX-offsetY.html 14 15 * dom/MouseRelatedEvent.cpp: 16 (WebCore::MouseRelatedEvent::receivedTarget): 17 * rendering/RenderBox.cpp: 18 (WebCore::RenderBox::localToAbsolute): 19 (WebCore::RenderBox::absoluteToLocal): 20 (WebCore::RenderBox::offsetFromContainer): 21 * rendering/RenderBox.h: 22 * rendering/RenderObject.cpp: 23 (WebCore::RenderObject::absoluteToLocal): 24 * rendering/RenderObject.h: 25 * rendering/RenderTableCell.cpp: 26 (WebCore::RenderTableCell::localToAbsolute): 27 (WebCore::RenderTableCell::absoluteToLocal): 28 * rendering/RenderTableCell.h: 29 * rendering/RenderView.cpp: 30 (WebCore::RenderView::absoluteToLocal): 31 * rendering/RenderView.h: 32 1 33 2008-11-06 Alp Toker <alp@nuanti.com> 2 34 -
trunk/WebCore/dom/MouseRelatedEvent.cpp
r38098 r38186 134 134 if (!isSimulated()) { 135 135 if (RenderObject* r = targ->renderer()) { 136 // FIXME: This doesn't work correctly with transforms. We need 137 // an absoluteToLocal() method. 138 FloatPoint absPos = r->localToAbsolute(); 139 m_offsetX -= absPos.x(); 140 m_offsetY -= absPos.y(); 136 FloatPoint absPos = r->absoluteToLocal(FloatPoint(m_pageX, m_pageY), false, true); 137 m_offsetX = absPos.x(); 138 m_offsetY = absPos.y(); 141 139 } 142 140 } -
trunk/WebCore/rendering/RenderBox.cpp
r38098 r38186 1015 1015 } 1016 1016 1017 if (isRelPositioned()) 1018 localPoint += relativePositionOffset(); 1019 1020 if (!isInline() || isReplaced()) { 1021 RenderBlock* cb; 1022 if (o->isBlockFlow() && style()->position() != AbsolutePosition && style()->position() != FixedPosition 1023 && (cb = static_cast<RenderBlock*>(o))->hasColumns()) { 1024 IntRect rect(m_x, m_y, 1, 1); 1025 cb->adjustRectForColumns(rect); 1026 localPoint.move(rect.x(), rect.y()); 1027 } else 1028 localPoint.move(m_x, m_y); 1029 } 1030 1031 if (o->hasOverflowClip()) 1032 localPoint -= o->layer()->scrolledContentOffset(); 1033 1034 if (style()->position() == AbsolutePosition) 1035 localPoint += offsetForPositionedInContainer(o); 1017 localPoint += offsetFromContainer(o); 1036 1018 1037 1019 return o->localToAbsoluteForContent(localPoint, fixed, useTransforms); … … 1039 1021 1040 1022 return FloatPoint(); 1023 } 1024 1025 FloatPoint RenderBox::absoluteToLocal(FloatPoint containerPoint, bool fixed, bool useTransforms) const 1026 { 1027 // We don't expect absoluteToLocal() to be called during layout (yet) 1028 ASSERT(!view() || !view()->layoutState()); 1029 1030 if (style()->position() == FixedPosition) 1031 fixed = true; 1032 1033 if (useTransforms && m_layer && m_layer->transform()) 1034 fixed = false; 1035 1036 RenderObject* o = container(); 1037 if (o) { 1038 FloatPoint localPoint = o->absoluteToLocal(containerPoint, fixed, useTransforms); 1039 1040 // Take into account space above a vertically aligned table cell 1041 // (see localToAbsoluteForContent()) 1042 localPoint.move(0.0f, -static_cast<float>(borderTopExtra())); 1043 1044 localPoint -= offsetFromContainer(o); 1045 1046 if (useTransforms && m_layer && m_layer->transform()) 1047 localPoint = m_layer->transform()->inverse().mapPoint(localPoint); 1048 1049 return localPoint; 1050 } 1051 1052 return FloatPoint(); 1053 } 1054 1055 IntSize RenderBox::offsetFromContainer(RenderObject* o) const 1056 { 1057 ASSERT(o == container()); 1058 1059 IntSize offset; 1060 if (isRelPositioned()) 1061 offset += relativePositionOffset(); 1062 1063 if (!isInline() || isReplaced()) { 1064 RenderBlock* cb; 1065 if (o->isBlockFlow() && style()->position() != AbsolutePosition && style()->position() != FixedPosition 1066 && (cb = static_cast<RenderBlock*>(o))->hasColumns()) { 1067 IntRect rect(m_x, m_y, 1, 1); 1068 cb->adjustRectForColumns(rect); 1069 offset.expand(rect.x(), rect.y()); 1070 } else 1071 offset.expand(m_x, m_y); 1072 } 1073 1074 if (o->hasOverflowClip()) 1075 offset -= o->layer()->scrolledContentOffset(); 1076 1077 if (style()->position() == AbsolutePosition) 1078 offset += offsetForPositionedInContainer(o); 1079 1080 return offset; 1041 1081 } 1042 1082 -
trunk/WebCore/rendering/RenderBox.h
r38098 r38186 51 51 52 52 virtual FloatPoint localToAbsolute(FloatPoint localPoint = FloatPoint(), bool fixed = false, bool useTransforms = false) const; 53 virtual FloatPoint absoluteToLocal(FloatPoint containerPoint, bool fixed = false, bool useTransforms = false) const; 53 54 54 55 virtual int xPos() const { return m_x; } … … 190 191 virtual bool shouldCalculateSizeAsReplaced() const { return isReplaced() && !isInlineBlockOrInlineTable(); } 191 192 193 IntSize offsetFromContainer(RenderObject*) const; 194 192 195 private: 193 196 void paintRootBoxDecorations(PaintInfo&, int tx, int ty); -
trunk/WebCore/rendering/RenderObject.cpp
r38098 r38186 2386 2386 } 2387 2387 2388 FloatPoint RenderObject::absoluteToLocal(FloatPoint containerPoint, bool fixed, bool useTransforms) const 2389 { 2390 RenderObject* o = parent(); 2391 if (o) { 2392 FloatPoint localPoint = o->absoluteToLocal(containerPoint, fixed, useTransforms); 2393 localPoint.move(0.0f, -static_cast<float>(o->borderTopExtra())); 2394 if (o->hasOverflowClip()) 2395 localPoint += o->layer()->scrolledContentOffset(); 2396 return localPoint; 2397 } 2398 return FloatPoint(); 2399 } 2400 2388 2401 IntRect RenderObject::caretRect(InlineBox* inlineBox, int caretOffset, int* extraWidthToEndOfLine) 2389 2402 { -
trunk/WebCore/rendering/RenderObject.h
r38098 r38186 584 584 // FIXME: Temporary. If useTransforms is true, take transforms into account. Eventually localToAbsolute() will always be transform-aware. 585 585 virtual FloatPoint localToAbsolute(FloatPoint localPoint = FloatPoint(), bool fixed = false, bool useTransforms = false) const; 586 virtual FloatPoint absoluteToLocal(FloatPoint, bool fixed = false, bool useTransforms = false) const; 586 587 587 588 // This function is used to deal with the extra top space that can occur in table cells (called borderTopExtra). -
trunk/WebCore/rendering/RenderTableCell.cpp
r38098 r38186 199 199 FloatPoint RenderTableCell::localToAbsolute(FloatPoint localPoint, bool fixed, bool useTransforms) const 200 200 { 201 FloatPoint result = RenderBlock::localToAbsolute(localPoint, fixed, useTransforms);202 201 RenderView* v = view(); 203 202 if ((!v || !v->layoutState()) && parent()) { 204 203 // Rows are in the same coordinate space, so don't add their offset in. 205 result.move(-parent()->xPos(), -parent()->yPos()); 206 } 207 return result; 204 localPoint.move(-parent()->xPos(), -parent()->yPos()); 205 } 206 return RenderBlock::localToAbsolute(localPoint, fixed, useTransforms);; 207 } 208 209 FloatPoint RenderTableCell::absoluteToLocal(FloatPoint containerPoint, bool fixed, bool useTransforms) const 210 { 211 FloatPoint localPoint = RenderBlock::absoluteToLocal(containerPoint, fixed, useTransforms); 212 if (parent()) { 213 // Rows are in the same coordinate space, so add their offset back in. 214 localPoint.move(parent()->xPos(), parent()->yPos()); 215 } 216 return localPoint; 208 217 } 209 218 -
trunk/WebCore/rendering/RenderTableCell.h
r38098 r38186 103 103 virtual void computeAbsoluteRepaintRect(IntRect&, bool fixed = false); 104 104 virtual FloatPoint localToAbsolute(FloatPoint localPoint = FloatPoint(), bool fixed = false, bool useTransforms = false) const; 105 virtual FloatPoint absoluteToLocal(FloatPoint containerPoint, bool fixed = false, bool useTransforms = false) const; 105 106 106 107 virtual int baselinePosition(bool firstLine = false, bool isRootLineBox = false) const; -
trunk/WebCore/rendering/RenderView.cpp
r38098 r38186 140 140 } 141 141 142 FloatPoint RenderView::absoluteToLocal(FloatPoint containerPoint, bool fixed, bool useTransforms) const 143 { 144 if (fixed && m_frameView) 145 containerPoint -= m_frameView->scrollOffset(); 146 147 return containerPoint; 148 } 149 142 150 void RenderView::paint(PaintInfo& paintInfo, int tx, int ty) 143 151 { -
trunk/WebCore/rendering/RenderView.h
r38098 r38186 46 46 virtual void calcPrefWidths(); 47 47 virtual FloatPoint localToAbsolute(FloatPoint localPoint = FloatPoint(), bool fixed = false, bool useTransforms = false) const; 48 virtual FloatPoint absoluteToLocal(FloatPoint containerPoint, bool fixed = false, bool useTransforms = false) const; 48 49 49 50 int docHeight() const;
Note: See TracChangeset
for help on using the changeset viewer.