Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: third_party/WebKit/Source/core/dom/Element.cpp

Issue 2349653002: Added support of getClientRects() for SVG Elements. (Closed)
Patch Set: Align with review comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
8 * (C) 2007 Eric Seidel (eric@webkit.org) 8 * (C) 2007 Eric Seidel (eric@webkit.org)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 // TODO(tkent): Can we check invisibility by scrollable non-frame elements? 1027 // TODO(tkent): Can we check invisibility by scrollable non-frame elements?
1028 1028
1029 IntSize viewportSize = document().page()->frameHost().visualViewport().size( ); 1029 IntSize viewportSize = document().page()->frameHost().visualViewport().size( );
1030 IntRect rect(0, 0, viewportSize.width(), viewportSize.height()); 1030 IntRect rect(0, 0, viewportSize.width(), viewportSize.height());
1031 // We don't use absoluteBoundingBoxRect() because it can return an IntRect 1031 // We don't use absoluteBoundingBoxRect() because it can return an IntRect
1032 // larger the actual size by 1px. crbug.com/470503 1032 // larger the actual size by 1px. crbug.com/470503
1033 rect.intersect(document().view()->contentsToViewport(roundedIntRect(layoutOb ject()->absoluteBoundingBoxFloatRect()))); 1033 rect.intersect(document().view()->contentsToViewport(roundedIntRect(layoutOb ject()->absoluteBoundingBoxFloatRect())));
1034 return rect; 1034 return rect;
1035 } 1035 }
1036 1036
1037 void Element::clientQuads(Vector<FloatQuad>& quads)
1038 {
1039 document().updateStyleAndLayoutIgnorePendingStylesheetsForNode(this);
1040
1041 LayoutObject* elementLayoutObject = layoutObject();
1042 if (!elementLayoutObject)
1043 return;
1044
1045 if (isSVGElement() && !elementLayoutObject->isSVGRoot()) {
1046 // Get the bounding rectangle from the SVG model.
1047 if (toSVGElement(this)->isSVGGraphicsElement())
1048 quads.append(elementLayoutObject->localToAbsoluteQuad(elementLayoutO bject->objectBoundingBox()));
1049 } else if (elementLayoutObject->isBoxModelObject() || elementLayoutObject->i sBR()) {
fs 2016/09/29 12:04:21 Nit: While we're shuffling code, we could consider
Shanmuga Pandi 2016/09/29 13:14:13 Done.
1050 elementLayoutObject->absoluteQuads(quads);
1051 }
1052 }
1053
1037 ClientRectList* Element::getClientRects() 1054 ClientRectList* Element::getClientRects()
1038 { 1055 {
1039 document().updateStyleAndLayoutIgnorePendingStylesheetsForNode(this); 1056 Vector<FloatQuad> quads;
1057 clientQuads(quads);
1058 if (quads.isEmpty())
1059 return ClientRectList::create();
1060
1061 // FIXME: Handle table/inline-table with a caption.
fs 2016/09/29 12:04:21 Nit: I guess this comment might be better suited f
Shanmuga Pandi 2016/09/29 13:14:12 Done.
1040 1062
1041 LayoutObject* elementLayoutObject = layoutObject(); 1063 LayoutObject* elementLayoutObject = layoutObject();
1042 if (!elementLayoutObject || (!elementLayoutObject->isBoxModelObject() && !el ementLayoutObject->isBR())) 1064 DCHECK(elementLayoutObject);
1043 return ClientRectList::create();
1044
1045 // FIXME: Handle SVG elements.
1046 // FIXME: Handle table/inline-table with a caption.
1047
1048 Vector<FloatQuad> quads;
1049 elementLayoutObject->absoluteQuads(quads);
1050 document().adjustFloatQuadsForScrollAndAbsoluteZoom(quads, *elementLayoutObj ect); 1065 document().adjustFloatQuadsForScrollAndAbsoluteZoom(quads, *elementLayoutObj ect);
1051 return ClientRectList::create(quads); 1066 return ClientRectList::create(quads);
1052 } 1067 }
1053 1068
1054 ClientRect* Element::getBoundingClientRect() 1069 ClientRect* Element::getBoundingClientRect()
1055 { 1070 {
1056 document().updateStyleAndLayoutIgnorePendingStylesheetsForNode(this);
1057
1058 Vector<FloatQuad> quads; 1071 Vector<FloatQuad> quads;
1059 LayoutObject* elementLayoutObject = layoutObject(); 1072 clientQuads(quads);
1060 if (elementLayoutObject) {
1061 if (isSVGElement() && !elementLayoutObject->isSVGRoot()) {
1062 // Get the bounding rectangle from the SVG model.
1063 if (toSVGElement(this)->isSVGGraphicsElement())
1064 quads.append(elementLayoutObject->localToAbsoluteQuad(elementLay outObject->objectBoundingBox()));
1065 } else if (elementLayoutObject->isBoxModelObject() || elementLayoutObjec t->isBR()) {
1066 elementLayoutObject->absoluteQuads(quads);
1067 }
1068 }
1069
1070 if (quads.isEmpty()) 1073 if (quads.isEmpty())
1071 return ClientRect::create(); 1074 return ClientRect::create();
1072 1075
1073 FloatRect result = quads[0].boundingBox(); 1076 FloatRect result = quads[0].boundingBox();
1074 for (size_t i = 1; i < quads.size(); ++i) 1077 for (size_t i = 1; i < quads.size(); ++i)
1075 result.unite(quads[i].boundingBox()); 1078 result.unite(quads[i].boundingBox());
1076 1079
1080 LayoutObject* elementLayoutObject = layoutObject();
1077 DCHECK(elementLayoutObject); 1081 DCHECK(elementLayoutObject);
1078 document().adjustFloatRectForScrollAndAbsoluteZoom(result, *elementLayoutObj ect); 1082 document().adjustFloatRectForScrollAndAbsoluteZoom(result, *elementLayoutObj ect);
1079 return ClientRect::create(result); 1083 return ClientRect::create(result);
1080 } 1084 }
1081 1085
1082 const AtomicString& Element::computedRole() 1086 const AtomicString& Element::computedRole()
1083 { 1087 {
1084 document().updateStyleAndLayoutIgnorePendingStylesheetsForNode(this); 1088 document().updateStyleAndLayoutIgnorePendingStylesheetsForNode(this);
1085 std::unique_ptr<ScopedAXObjectCache> cache = ScopedAXObjectCache::create(doc ument()); 1089 std::unique_ptr<ScopedAXObjectCache> cache = ScopedAXObjectCache::create(doc ument());
1086 return cache->get()->computedRoleForNode(this); 1090 return cache->get()->computedRoleForNode(this);
(...skipping 2742 matching lines...) Expand 10 before | Expand all | Expand 10 after
3829 3833
3830 DEFINE_TRACE_WRAPPERS(Element) 3834 DEFINE_TRACE_WRAPPERS(Element)
3831 { 3835 {
3832 if (hasRareData()) { 3836 if (hasRareData()) {
3833 visitor->traceWrappers(elementRareData()); 3837 visitor->traceWrappers(elementRareData());
3834 } 3838 }
3835 ContainerNode::traceWrappers(visitor); 3839 ContainerNode::traceWrappers(visitor);
3836 } 3840 }
3837 3841
3838 } // namespace blink 3842 } // namespace blink
OLDNEW
« third_party/WebKit/Source/core/dom/Element.h ('K') | « third_party/WebKit/Source/core/dom/Element.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698