Nothing Special »
Address
:
[go:
up one dir
,
main page
]
Include Form
Remove Scripts
Accept Cookies
Show Images
Show Referer
Rotate13
Base64
Strip Meta
Strip Title
Session Cookies
Bugzilla
Quick Search
Browse
Advanced Search
Reports
Quick Search Help
Documentation
New Account
Log In
Login with GitHub
Remember
Forgot Password
Mozilla Home
Privacy
Cookies
Legal
Attachment 8356415 Details for
Bug 917755
[patch]
Part 5: Implement getBoxQuads
917755-getBoxQuads (text/plain), 15.89 KB, created by
Robert O'Callahan (:roc) (email my personal email if necessary)
(
hide
)
Description:
Part 5: Implement getBoxQuads
Filename:
MIME Type:
Creator:
Robert O'Callahan (:roc) (email my personal email if necessary)
Size:
15.89 KB
patch
obsolete
>From: Robert O'Callahan <robert@ocallahan.org> >Bug 917755. Part 5: Implement getBoxQuads. r=matspal > >diff --git a/content/base/public/nsINode.h b/content/base/public/nsINode.h >--- a/content/base/public/nsINode.h >+++ b/content/base/public/nsINode.h >@@ -60,16 +60,18 @@ inline bool IsSpaceCharacter(PRUnichar a > return aChar == ' ' || aChar == '\t' || aChar == '\n' || aChar == '\r' || > aChar == '\f'; > } > inline bool IsSpaceCharacter(char aChar) { > return aChar == ' ' || aChar == '\t' || aChar == '\n' || aChar == '\r' || > aChar == '\f'; > } > class Element; >+class BoxQuadOptions; >+class DOMQuad; > class EventHandlerNonNull; > class OnErrorEventHandlerNonNull; > template<typename T> class Optional; > } // namespace dom > } // namespace mozilla > > #define NODE_FLAG_BIT(n_) (1U << (WRAPPER_CACHE_FLAGS_BITS_USED + (n_))) > >@@ -265,16 +267,20 @@ private: > /** > * An internal interface that abstracts some DOMNode-related parts that both > * nsIContent and nsIDocument share. An instance of this interface has a list > * of nsIContent children and provides access to them. > */ > class nsINode : public mozilla::dom::EventTarget > { > public: >+ typedef mozilla::dom::BoxQuadOptions BoxQuadOptions; >+ typedef mozilla::dom::DOMQuad DOMQuad; >+ typedef mozilla::ErrorResult ErrorResult; >+ > NS_DECLARE_STATIC_IID_ACCESSOR(NS_INODE_IID) > > // Among the sub-classes that inherit (directly or indirectly) from nsINode, > // measurement of the following members may be added later if DMD finds it is > // worthwhile: > // - nsGenericHTMLElement: mForm, mFieldSet > // - nsGenericHTMLFrameElement: mFrameLoader (bug 672539) > // - HTMLBodyElement: mContentStyleRule >@@ -1596,16 +1602,20 @@ public: > * Remove this node from its parent, if any. > */ > void Remove(); > > // ParentNode methods > mozilla::dom::Element* GetFirstElementChild() const; > mozilla::dom::Element* GetLastElementChild() const; > >+ void GetBoxQuads(const BoxQuadOptions& aOptions, >+ nsTArray<nsRefPtr<DOMQuad> >& aResult, >+ mozilla::ErrorResult& aRv); >+ > protected: > > // Override this function to create a custom slots class. > // Must not return null. > virtual nsINode::nsSlots* CreateSlots(); > > bool HasSlots() const > { >diff --git a/content/base/src/nsINode.cpp b/content/base/src/nsINode.cpp >--- a/content/base/src/nsINode.cpp >+++ b/content/base/src/nsINode.cpp >@@ -98,16 +98,17 @@ > #include "nsWrapperCacheInlines.h" > #include "mozilla/dom/ShadowRoot.h" > #include "WrapperFactory.h" > #include "DocumentType.h" > #include <algorithm> > #include "nsDOMEvent.h" > #include "nsGlobalWindow.h" > #include "nsDOMMutationObserver.h" >+#include "GeometryUtils.h" > > using namespace mozilla; > using namespace mozilla::dom; > > nsINode::nsSlots::~nsSlots() > { > if (mChildNodes) { > mChildNodes->DropReference(); >@@ -2628,16 +2629,24 @@ nsDOMAttributeMap* > nsINode::GetAttributes() > { > if (!IsElement()) { > return nullptr; > } > return AsElement()->Attributes(); > } > >+void >+nsINode::GetBoxQuads(const BoxQuadOptions& aOptions, >+ nsTArray<nsRefPtr<DOMQuad> >& aResult, >+ mozilla::ErrorResult& aRv) >+{ >+ mozilla::GetBoxQuads(this, aOptions, aResult, aRv); >+} >+ > bool > EventTarget::DispatchEvent(nsDOMEvent& aEvent, > ErrorResult& aRv) > { > bool result = false; > aRv = DispatchEvent(&aEvent, &result); > return result; > } >diff --git a/dom/webidl/GeometryUtils.webidl b/dom/webidl/GeometryUtils.webidl >new file mode 100644 >--- /dev/null >+++ b/dom/webidl/GeometryUtils.webidl >@@ -0,0 +1,38 @@ >+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ >+/* This Source Code Form is subject to the terms of the Mozilla Public >+ * License, v. 2.0. If a copy of the MPL was not distributed with this >+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. >+ * >+ * The origin of this IDL file is >+ * http://dev.w3.org/csswg/cssom-view/ >+ * >+ * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C >+ * liability, trademark and document use rules apply. >+ */ >+ >+enum CSSBoxType { "margin", "border", "padding", "content" }; >+dictionary BoxQuadOptions { >+ CSSBoxType box = "border"; >+ GeometryNode relativeTo; >+}; >+ >+dictionary ConvertCoordinateOptions { >+ CSSBoxType fromBox = "border"; >+ CSSBoxType toBox = "border"; >+}; >+ >+[NoInterfaceObject] >+interface GeometryUtils { >+ [Throws, Pref="layout.css.getBoxQuads.enabled"] >+ sequence<DOMQuad> getBoxQuads(optional BoxQuadOptions options); >+// DOMQuad convertQuadFromNode(DOMQuad quad, GeometryNode from, optional ConvertCoordinateOptions options); >+// DOMQuad convertRectFromNode(DOMRectReadOnly rect, GeometryNode from, optional ConvertCoordinateOptions options); >+// DOMPoint convertPointFromNode(DOMPointInit point, GeometryNode from, optional ConvertCoordinateOptions options); >+}; >+ >+Text implements GeometryUtils; >+Element implements GeometryUtils; >+// PseudoElement implements GeometryUtils; >+Document implements GeometryUtils; >+ >+typedef (Text or Element /* or PseudoElement */ or Document) GeometryNode; >\ No newline at end of file >diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build >--- a/dom/webidl/moz.build >+++ b/dom/webidl/moz.build >@@ -105,16 +105,17 @@ WEBIDL_FILES = [ > 'FileReader.webidl', > 'FileReaderSync.webidl', > 'FileRequest.webidl', > 'FocusEvent.webidl', > 'FormData.webidl', > 'Function.webidl', > 'GainNode.webidl', > 'Geolocation.webidl', >+ 'GeometryUtils.webidl', > 'GetUserMediaRequest.webidl', > 'History.webidl', > 'HTMLAnchorElement.webidl', > 'HTMLAppletElement.webidl', > 'HTMLAreaElement.webidl', > 'HTMLAudioElement.webidl', > 'HTMLBaseElement.webidl', > 'HTMLBodyElement.webidl', >diff --git a/layout/base/GeometryUtils.cpp b/layout/base/GeometryUtils.cpp >new file mode 100644 >--- /dev/null >+++ b/layout/base/GeometryUtils.cpp >@@ -0,0 +1,238 @@ >+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ >+/* This Source Code Form is subject to the terms of the Mozilla Public >+ * License, v. 2.0. If a copy of the MPL was not distributed with this >+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ >+ >+#include "GeometryUtils.h" >+ >+#include "mozilla/dom/GeometryUtilsBinding.h" >+#include "mozilla/dom/Element.h" >+#include "mozilla/dom/Text.h" >+#include "mozilla/dom/DOMQuad.h" >+#include "nsIFrame.h" >+#include "nsGenericDOMDataNode.h" >+#include "nsCSSFrameConstructor.h" >+#include "nsLayoutUtils.h" >+#include "nsSVGUtils.h" >+ >+using namespace mozilla; >+using namespace mozilla::dom; >+ >+namespace mozilla { >+ >+typedef OwningTextOrElementOrDocument GeometryNode; >+ >+enum GeometryNodeType { >+ GEOMETRY_NODE_ELEMENT, >+ GEOMETRY_NODE_TEXT, >+ GEOMETRY_NODE_DOCUMENT >+}; >+ >+static nsIFrame* >+GetFrameForNode(nsINode* aNode, GeometryNodeType aType) >+{ >+ nsIDocument* doc = aNode->OwnerDoc(); >+ doc->FlushPendingNotifications(Flush_Layout); >+ switch (aType) { >+ case GEOMETRY_NODE_ELEMENT: >+ return aNode->AsContent()->GetPrimaryFrame(); >+ case GEOMETRY_NODE_TEXT: { >+ nsIPresShell* presShell = doc->GetShell(); >+ if (presShell) { >+ return presShell->FrameConstructor()->EnsureFrameForTextNode( >+ static_cast<nsGenericDOMDataNode*>(aNode)); >+ } >+ return nullptr; >+ } >+ case GEOMETRY_NODE_DOCUMENT: { >+ nsIPresShell* presShell = doc->GetShell(); >+ return presShell ? presShell->GetRootFrame() : nullptr; >+ } >+ default: >+ MOZ_ASSERT(false, "Unknown GeometryNodeType"); >+ return nullptr; >+ } >+} >+ >+static nsIFrame* >+GetFrameForGeometryNode(const Optional<GeometryNode>& aGeometryNode, >+ nsINode* aDefaultNode) >+{ >+ if (!aGeometryNode.WasPassed()) { >+ return GetFrameForNode(aDefaultNode->OwnerDoc(), GEOMETRY_NODE_DOCUMENT); >+ } >+ >+ const GeometryNode& value = aGeometryNode.Value(); >+ if (value.IsElement()) { >+ return GetFrameForNode(value.GetAsElement(), GEOMETRY_NODE_ELEMENT); >+ } >+ if (value.IsDocument()) { >+ return GetFrameForNode(value.GetAsDocument(), GEOMETRY_NODE_DOCUMENT); >+ } >+ return GetFrameForNode(value.GetAsText(), GEOMETRY_NODE_TEXT); >+} >+ >+static nsIFrame* >+GetFrameForNode(nsINode* aNode) >+{ >+ if (aNode->IsElement()) { >+ return GetFrameForNode(aNode, GEOMETRY_NODE_ELEMENT); >+ } >+ if (aNode == aNode->OwnerDoc()) { >+ return GetFrameForNode(aNode, GEOMETRY_NODE_DOCUMENT); >+ } >+ NS_ASSERTION(aNode->IsNodeOfType(nsINode::eTEXT), "Unknown node type"); >+ return GetFrameForNode(aNode, GEOMETRY_NODE_TEXT); >+} >+ >+static nsIFrame* >+GetFirstNonAnonymousFrameForGeometryNode(const Optional<GeometryNode>& aNode, >+ nsINode* aDefaultNode) >+{ >+ nsIFrame* f = GetFrameForGeometryNode(aNode, aDefaultNode); >+ if (f) { >+ f = nsLayoutUtils::GetFirstNonAnonymousFrame(f); >+ } >+ return f; >+} >+ >+/** >+ * This can modify aFrame to point to a different frame. This is needed to >+ * handle SVG, where SVG elements can only compute a rect that's valid with >+ * respect to the "outer SVG" frame. >+ */ >+static nsRect >+GetBoxRectForFrame(nsIFrame** aFrame, CSSBoxType aType) >+{ >+ nsRect r; >+ nsIFrame* f = nsSVGUtils::GetOuterSVGFrameAndCoveredRegion(*aFrame, &r); >+ if (f) { >+ // For SVG, the BoxType is ignored. >+ *aFrame = f; >+ return r; >+ } >+ >+ f = *aFrame; >+ switch (aType) { >+ case CSSBoxType::Content: r = f->GetContentRectRelativeToSelf(); break; >+ case CSSBoxType::Padding: r = f->GetPaddingRectRelativeToSelf(); break; >+ case CSSBoxType::Border: r = nsRect(nsPoint(0, 0), f->GetSize()); break; >+ case CSSBoxType::Margin: { >+ r = nsRect(nsPoint(0, 0), f->GetSize()); >+ r.Inflate(f->GetUsedMargin()); >+ break; >+ } >+ default: MOZ_ASSERT(false, "unknown box type"); return r; >+ } >+ >+ return r; >+} >+ >+class AccumulateQuadCallback : public nsLayoutUtils::BoxCallback { >+public: >+ AccumulateQuadCallback(nsISupports* aParentObject, >+ nsTArray<nsRefPtr<DOMQuad> >& aResult, >+ nsIFrame* aRelativeToFrame, >+ const nsPoint& aRelativeToBoxTopLeft, >+ CSSBoxType aBoxType) >+ : mParentObject(aParentObject) >+ , mResult(aResult) >+ , mRelativeToFrame(aRelativeToFrame) >+ , mRelativeToBoxTopLeft(aRelativeToBoxTopLeft) >+ , mBoxType(aBoxType) >+ { >+ } >+ >+ virtual void AddBox(nsIFrame* aFrame) MOZ_OVERRIDE >+ { >+ nsIFrame* f = aFrame; >+ nsRect box = GetBoxRectForFrame(&f, mBoxType); >+ nsPoint appUnits[4] = >+ { box.TopLeft(), box.TopRight(), box.BottomRight(), box.BottomLeft() }; >+ gfxPoint points[4]; >+ for (uint32_t i = 0; i < 4; ++i) { >+ points[i] = gfxPoint(nsPresContext::AppUnitsToFloatCSSPixels(appUnits[i].x), >+ nsPresContext::AppUnitsToFloatCSSPixels(appUnits[i].y)); >+ } >+ nsLayoutUtils::TransformResult rv = >+ nsLayoutUtils::TransformCSSPoints(f, mRelativeToFrame, 4, points); >+ if (rv == nsLayoutUtils::TRANSFORM_SUCCEEDED) { >+ gfxPoint delta(nsPresContext::AppUnitsToFloatCSSPixels(mRelativeToBoxTopLeft.x), >+ nsPresContext::AppUnitsToFloatCSSPixels(mRelativeToBoxTopLeft.y)); >+ for (uint32_t i = 0; i < 4; ++i) { >+ points[i] -= delta; >+ } >+ } else { >+ PodArrayZero(points); >+ } >+ mResult.AppendElement(new DOMQuad(mParentObject, points)); >+ } >+ >+ nsISupports* mParentObject; >+ nsTArray<nsRefPtr<DOMQuad> >& mResult; >+ nsIFrame* mRelativeToFrame; >+ nsPoint mRelativeToBoxTopLeft; >+ CSSBoxType mBoxType; >+}; >+ >+static nsPresContext* >+FindTopLevelPresContext(nsPresContext* aPC) >+{ >+ bool isChrome = aPC->IsChrome(); >+ nsPresContext* pc = aPC; >+ for (;;) { >+ nsPresContext* parent = pc->GetParentPresContext(); >+ if (!parent || parent->IsChrome() != isChrome) { >+ return pc; >+ } >+ pc = parent; >+ } >+} >+ >+static bool >+CheckFramesInSameTopLevelBrowsingContext(nsIFrame* aFrame1, nsIFrame* aFrame2) >+{ >+ nsPresContext* pc1 = aFrame1->PresContext(); >+ nsPresContext* pc2 = aFrame2->PresContext(); >+ if (pc1 == pc2) { >+ return true; >+ } >+ if (nsContentUtils::IsCallerChrome()) { >+ return true; >+ } >+ if (FindTopLevelPresContext(pc1) == FindTopLevelPresContext(pc2)) { >+ return true; >+ } >+ return false; >+} >+ >+void GetBoxQuads(nsINode* aNode, >+ const dom::BoxQuadOptions& aOptions, >+ nsTArray<nsRefPtr<DOMQuad> >& aResult, >+ ErrorResult& aRv) >+{ >+ nsIDocument* ownerDoc = aNode->OwnerDoc(); >+ nsIFrame* frame = GetFrameForNode(aNode); >+ if (!frame) { >+ // No boxes to return >+ return; >+ } >+ nsIFrame* relativeToFrame = >+ GetFirstNonAnonymousFrameForGeometryNode(aOptions.mRelativeTo, ownerDoc); >+ if (!relativeToFrame) { >+ aRv.Throw(NS_ERROR_DOM_NOT_FOUND_ERR); >+ return; >+ } >+ if (!CheckFramesInSameTopLevelBrowsingContext(frame, relativeToFrame)) { >+ aRv.Throw(NS_ERROR_DOM_NOT_FOUND_ERR); >+ return; >+ } >+ // GetBoxRectForFrame can modify relativeToFrame so call it first. >+ nsPoint relativeToTopLeft = >+ GetBoxRectForFrame(&relativeToFrame, CSSBoxType::Border).TopLeft(); >+ AccumulateQuadCallback callback(ownerDoc, aResult, relativeToFrame, >+ relativeToTopLeft, aOptions.mBox); >+ nsLayoutUtils::GetAllInFlowBoxes(frame, &callback); >+} >+ >+} >diff --git a/layout/base/GeometryUtils.h b/layout/base/GeometryUtils.h >new file mode 100644 >--- /dev/null >+++ b/layout/base/GeometryUtils.h >@@ -0,0 +1,41 @@ >+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ >+/* This Source Code Form is subject to the terms of the Mozilla Public >+ * License, v. 2.0. If a copy of the MPL was not distributed with this >+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ >+ >+#ifndef MOZILLA_GEOMETRYUTILS_H_ >+#define MOZILLA_GEOMETRYUTILS_H_ >+ >+#include "mozilla/ErrorResult.h" >+#include "nsTArray.h" >+#include "gfxPoint.h" >+ >+/** >+ * This file defines utility functions for converting between layout >+ * coordinate systems. >+ */ >+ >+class nsINode; >+class nsIDocument; >+ >+namespace mozilla { >+ >+namespace dom { >+struct BoxQuadOptions; >+class DOMQuad; >+class Element; >+class Text; >+} >+ >+/** >+ * Computes quads for aNode using aOptions, according to GeometryUtils.getBoxQuads. >+ * May set an error in aRv. >+ */ >+void GetBoxQuads(nsINode* aNode, >+ const dom::BoxQuadOptions& aOptions, >+ nsTArray<nsRefPtr<dom::DOMQuad> >& aResult, >+ ErrorResult& aRv); >+ >+} >+ >+#endif /* MOZILLA_GEOMETRYUTILS_H_ */ >diff --git a/layout/base/moz.build b/layout/base/moz.build >--- a/layout/base/moz.build >+++ b/layout/base/moz.build >@@ -54,25 +54,27 @@ EXPORTS += [ > 'nsRefreshDriver.h', > 'nsStyleChangeList.h', > 'ScrollbarStyles.h', > 'StackArena.h', > 'Units.h', > ] > > EXPORTS.mozilla += [ >+ 'GeometryUtils.h', > 'PaintTracker.h', > ] > > UNIFIED_SOURCES += [ > 'ActiveLayerTracker.cpp', > 'DisplayItemClip.cpp', > 'DisplayListClipState.cpp', > 'FrameLayerBuilder.cpp', > 'FramePropertyTable.cpp', >+ 'GeometryUtils.cpp', > 'MaskLayerImageCache.cpp', > 'nsCaret.cpp', > 'nsCounterManager.cpp', > 'nsCSSColorUtils.cpp', > 'nsCSSFrameConstructor.cpp', > 'nsCSSRendering.cpp', > 'nsCSSRenderingBorders.cpp', > 'nsDisplayList.cpp', >diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js >--- a/modules/libpref/src/init/all.js >+++ b/modules/libpref/src/init/all.js >@@ -1762,16 +1762,23 @@ pref("layout.css.sticky.enabled", true); > #endif > > // Is support for DOMPoint enabled? > pref("layout.css.DOMPoint.enabled", true); > > // Is support for DOMQuad enabled? > pref("layout.css.DOMQuad.enabled", true); > >+// Is support for GeometryUtils.getBoxQuads enabled? >+#ifdef RELEASE_BUILD >+pref("layout.css.getBoxQuads.enabled", false); >+#else >+pref("layout.css.getBoxQuads.enabled", true); >+#endif >+ > // Is support for CSS "text-align: true X" enabled? > pref("layout.css.text-align-true-value.enabled", false); > > // Is support for the CSS4 image-orientation property enabled? > pref("layout.css.image-orientation.enabled", true); > > // Is support for CSS3 Fonts features enabled? > // (includes font-variant-*, font-kerning, font-synthesis
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Flags:
MatsPalmgren_bugz
: review+
Actions:
View
|
Diff
|
Review
Attachments on
bug 917755
:
807052
|
807053
|
807054
|
807055
|
807056
|
807057
|
8356406
|
8356410
|
8356411
|
8356413
|
8356415
|
8356416
|
8369459
|
8388503
|
8388504
|
8388505
|
8388507
|
8388509
|
8388510
|
8389628
|
8389630
|
8389631
|
8389632
|
8389633