Nothing Special   »   [go: up one dir, main page]

Attachment #8356417: Part 1: Implement GeometryUtils.convertPointFromNode, convertRectFromNode, and convertQudFromNode918189-implement for bug #918189

View | Details | Raw Unified | Return to bug 918189
Collapse All | Expand All

(-)a/content/base/public/nsINode.h (-2 / +25 lines)
Line     Link Here 
 Lines 59-80   namespace dom { Link Here 
59
inline bool IsSpaceCharacter(PRUnichar aChar) {
59
inline bool IsSpaceCharacter(PRUnichar aChar) {
60
  return aChar == ' ' || aChar == '\t' || aChar == '\n' || aChar == '\r' ||
60
  return aChar == ' ' || aChar == '\t' || aChar == '\n' || aChar == '\r' ||
61
         aChar == '\f';
61
         aChar == '\f';
62
}
62
}
63
inline bool IsSpaceCharacter(char aChar) {
63
inline bool IsSpaceCharacter(char aChar) {
64
  return aChar == ' ' || aChar == '\t' || aChar == '\n' || aChar == '\r' ||
64
  return aChar == ' ' || aChar == '\t' || aChar == '\n' || aChar == '\r' ||
65
         aChar == '\f';
65
         aChar == '\f';
66
}
66
}
67
class BoxQuadOptions;
68
class ConvertCoordinateOptions;
69
class DOMPoint;
70
class DOMQuad;
71
class DOMRectReadOnly;
67
class Element;
72
class Element;
68
class BoxQuadOptions;
69
class DOMQuad;
70
class EventHandlerNonNull;
73
class EventHandlerNonNull;
71
class OnErrorEventHandlerNonNull;
74
class OnErrorEventHandlerNonNull;
72
template<typename T> class Optional;
75
template<typename T> class Optional;
76
class TextOrElementOrDocument;
77
struct DOMPointInit;
73
} // namespace dom
78
} // namespace dom
74
} // namespace mozilla
79
} // namespace mozilla
75
80
76
#define NODE_FLAG_BIT(n_) (1U << (WRAPPER_CACHE_FLAGS_BITS_USED + (n_)))
81
#define NODE_FLAG_BIT(n_) (1U << (WRAPPER_CACHE_FLAGS_BITS_USED + (n_)))
77
82
78
enum {
83
enum {
79
  // This bit will be set if the node has a listener manager.
84
  // This bit will be set if the node has a listener manager.
80
  NODE_HAS_LISTENERMANAGER =              NODE_FLAG_BIT(0),
85
  NODE_HAS_LISTENERMANAGER =              NODE_FLAG_BIT(0),
 Lines 268-284   private: Link Here 
268
 * An internal interface that abstracts some DOMNode-related parts that both
273
 * An internal interface that abstracts some DOMNode-related parts that both
269
 * nsIContent and nsIDocument share.  An instance of this interface has a list
274
 * nsIContent and nsIDocument share.  An instance of this interface has a list
270
 * of nsIContent children and provides access to them.
275
 * of nsIContent children and provides access to them.
271
 */
276
 */
272
class nsINode : public mozilla::dom::EventTarget
277
class nsINode : public mozilla::dom::EventTarget
273
{
278
{
274
public:
279
public:
275
  typedef mozilla::dom::BoxQuadOptions BoxQuadOptions;
280
  typedef mozilla::dom::BoxQuadOptions BoxQuadOptions;
281
  typedef mozilla::dom::ConvertCoordinateOptions ConvertCoordinateOptions;
282
  typedef mozilla::dom::DOMPoint DOMPoint;
283
  typedef mozilla::dom::DOMPointInit DOMPointInit;
276
  typedef mozilla::dom::DOMQuad DOMQuad;
284
  typedef mozilla::dom::DOMQuad DOMQuad;
285
  typedef mozilla::dom::DOMRectReadOnly DOMRectReadOnly;
286
  typedef mozilla::dom::TextOrElementOrDocument TextOrElementOrDocument;
277
  typedef mozilla::ErrorResult ErrorResult;
287
  typedef mozilla::ErrorResult ErrorResult;
278
288
279
  NS_DECLARE_STATIC_IID_ACCESSOR(NS_INODE_IID)
289
  NS_DECLARE_STATIC_IID_ACCESSOR(NS_INODE_IID)
280
290
281
  // Among the sub-classes that inherit (directly or indirectly) from nsINode,
291
  // Among the sub-classes that inherit (directly or indirectly) from nsINode,
282
  // measurement of the following members may be added later if DMD finds it is
292
  // measurement of the following members may be added later if DMD finds it is
283
  // worthwhile:
293
  // worthwhile:
284
  // - nsGenericHTMLElement:  mForm, mFieldSet
294
  // - nsGenericHTMLElement:  mForm, mFieldSet
 Lines 1606-1621   public: Link Here 
1606
  // ParentNode methods
1616
  // ParentNode methods
1607
  mozilla::dom::Element* GetFirstElementChild() const;
1617
  mozilla::dom::Element* GetFirstElementChild() const;
1608
  mozilla::dom::Element* GetLastElementChild() const;
1618
  mozilla::dom::Element* GetLastElementChild() const;
1609
1619
1610
  void GetBoxQuads(const BoxQuadOptions& aOptions,
1620
  void GetBoxQuads(const BoxQuadOptions& aOptions,
1611
                   nsTArray<nsRefPtr<DOMQuad> >& aResult,
1621
                   nsTArray<nsRefPtr<DOMQuad> >& aResult,
1612
                   mozilla::ErrorResult& aRv);
1622
                   mozilla::ErrorResult& aRv);
1613
1623
1624
  already_AddRefed<DOMQuad> ConvertQuadFromNode(DOMQuad& aQuad,
1625
                                                const TextOrElementOrDocument& aFrom,
1626
                                                const ConvertCoordinateOptions& aOptions,
1627
                                                ErrorResult& aRv);
1628
  already_AddRefed<DOMQuad> ConvertRectFromNode(DOMRectReadOnly& aRect,
1629
                                                const TextOrElementOrDocument& aFrom,
1630
                                                const ConvertCoordinateOptions& aOptions,
1631
                                                ErrorResult& aRv);
1632
  already_AddRefed<DOMPoint> ConvertPointFromNode(const DOMPointInit& aPoint,
1633
                                                  const TextOrElementOrDocument& aFrom,
1634
                                                  const ConvertCoordinateOptions& aOptions,
1635
                                                  ErrorResult& aRv);
1636
1614
protected:
1637
protected:
1615
1638
1616
  // Override this function to create a custom slots class.
1639
  // Override this function to create a custom slots class.
1617
  // Must not return null.
1640
  // Must not return null.
1618
  virtual nsINode::nsSlots* CreateSlots();
1641
  virtual nsINode::nsSlots* CreateSlots();
1619
1642
1620
  bool HasSlots() const
1643
  bool HasSlots() const
1621
  {
1644
  {
(-)a/content/base/src/nsINode.cpp (+27 lines)
Line     Link Here 
 Lines 2637-2652   nsINode::GetAttributes() Link Here 
2637
void
2637
void
2638
nsINode::GetBoxQuads(const BoxQuadOptions& aOptions,
2638
nsINode::GetBoxQuads(const BoxQuadOptions& aOptions,
2639
                     nsTArray<nsRefPtr<DOMQuad> >& aResult,
2639
                     nsTArray<nsRefPtr<DOMQuad> >& aResult,
2640
                     mozilla::ErrorResult& aRv)
2640
                     mozilla::ErrorResult& aRv)
2641
{
2641
{
2642
  mozilla::GetBoxQuads(this, aOptions, aResult, aRv);
2642
  mozilla::GetBoxQuads(this, aOptions, aResult, aRv);
2643
}
2643
}
2644
2644
2645
already_AddRefed<DOMQuad>
2646
nsINode::ConvertQuadFromNode(DOMQuad& aQuad,
2647
                             const GeometryNode& aFrom,
2648
                             const ConvertCoordinateOptions& aOptions,
2649
                             ErrorResult& aRv)
2650
{
2651
  return mozilla::ConvertQuadFromNode(this, aQuad, aFrom, aOptions, aRv);
2652
}
2653
2654
already_AddRefed<DOMQuad>
2655
nsINode::ConvertRectFromNode(DOMRectReadOnly& aRect,
2656
                             const GeometryNode& aFrom,
2657
                             const ConvertCoordinateOptions& aOptions,
2658
                             ErrorResult& aRv)
2659
{
2660
  return mozilla::ConvertRectFromNode(this, aRect, aFrom, aOptions, aRv);
2661
}
2662
2663
already_AddRefed<DOMPoint>
2664
nsINode::ConvertPointFromNode(const DOMPointInit& aPoint,
2665
                              const GeometryNode& aFrom,
2666
                              const ConvertCoordinateOptions& aOptions,
2667
                              ErrorResult& aRv)
2668
{
2669
  return mozilla::ConvertPointFromNode(this, aPoint, aFrom, aOptions, aRv);
2670
}
2671
2645
bool
2672
bool
2646
EventTarget::DispatchEvent(nsDOMEvent& aEvent,
2673
EventTarget::DispatchEvent(nsDOMEvent& aEvent,
2647
                           ErrorResult& aRv)
2674
                           ErrorResult& aRv)
2648
{
2675
{
2649
  bool result = false;
2676
  bool result = false;
2650
  aRv = DispatchEvent(&aEvent, &result);
2677
  aRv = DispatchEvent(&aEvent, &result);
2651
  return result;
2678
  return result;
2652
}
2679
}
(-)a/dom/webidl/GeometryUtils.webidl (-3 / +6 lines)
Line     Link Here 
 Lines 20-38   dictionary ConvertCoordinateOptions { Link Here 
20
  CSSBoxType fromBox = "border";
20
  CSSBoxType fromBox = "border";
21
  CSSBoxType toBox = "border";
21
  CSSBoxType toBox = "border";
22
};
22
};
23
23
24
[NoInterfaceObject]
24
[NoInterfaceObject]
25
interface GeometryUtils {
25
interface GeometryUtils {
26
  [Throws, Pref="layout.css.getBoxQuads.enabled"]
26
  [Throws, Pref="layout.css.getBoxQuads.enabled"]
27
  sequence<DOMQuad> getBoxQuads(optional BoxQuadOptions options);
27
  sequence<DOMQuad> getBoxQuads(optional BoxQuadOptions options);
28
//  DOMQuad convertQuadFromNode(DOMQuad quad, GeometryNode from, optional ConvertCoordinateOptions options);
28
  [Throws, Pref="layout.css.convertFromNode.enabled"]
29
//  DOMQuad convertRectFromNode(DOMRectReadOnly rect, GeometryNode from, optional ConvertCoordinateOptions options);
29
  DOMQuad convertQuadFromNode(DOMQuad quad, GeometryNode from, optional ConvertCoordinateOptions options);
30
//  DOMPoint convertPointFromNode(DOMPointInit point, GeometryNode from, optional ConvertCoordinateOptions options);
30
  [Throws, Pref="layout.css.convertFromNode.enabled"]
31
  DOMQuad convertRectFromNode(DOMRectReadOnly rect, GeometryNode from, optional ConvertCoordinateOptions options);
32
  [Throws, Pref="layout.css.convertFromNode.enabled"]
33
  DOMPoint convertPointFromNode(DOMPointInit point, GeometryNode from, optional ConvertCoordinateOptions options);
31
};
34
};
32
35
33
Text implements GeometryUtils;
36
Text implements GeometryUtils;
34
Element implements GeometryUtils;
37
Element implements GeometryUtils;
35
// PseudoElement implements GeometryUtils;
38
// PseudoElement implements GeometryUtils;
36
Document implements GeometryUtils;
39
Document implements GeometryUtils;
37
40
38
typedef (Text or Element /* or PseudoElement */ or Document) GeometryNode;
41
typedef (Text or Element /* or PseudoElement */ or Document) GeometryNode;
(-)a/editor/libeditor/html/nsHTMLEditRules.cpp (-2 / +2 lines)
Line     Link Here 
 Lines 2927-2943   nsHTMLEditRules::JoinBlocks(nsIDOMNode * Link Here 
2927
*         int32_t aRightOffset           offset in aRightBlock to move content from
2927
*         int32_t aRightOffset           offset in aRightBlock to move content from
2928
*/
2928
*/
2929
nsresult
2929
nsresult
2930
nsHTMLEditRules::MoveBlock(nsIDOMNode *aLeftBlock, nsIDOMNode *aRightBlock, int32_t aLeftOffset, int32_t aRightOffset)
2930
nsHTMLEditRules::MoveBlock(nsIDOMNode *aLeftBlock, nsIDOMNode *aRightBlock, int32_t aLeftOffset, int32_t aRightOffset)
2931
{
2931
{
2932
  nsCOMArray<nsIDOMNode> arrayOfNodes;
2932
  nsCOMArray<nsIDOMNode> arrayOfNodes;
2933
  nsCOMPtr<nsISupports> isupports;
2933
  nsCOMPtr<nsISupports> isupports;
2934
  // GetNodesFromPoint is the workhorse that figures out what we wnat to move.
2934
  // GetNodesFromPoint is the workhorse that figures out what we wnat to move.
2935
  nsresult res = GetNodesFromPoint(DOMPoint(aRightBlock,aRightOffset),
2935
  nsresult res = GetNodesFromPoint(::DOMPoint(aRightBlock,aRightOffset),
2936
                                   EditAction::makeList, arrayOfNodes, true);
2936
                                   EditAction::makeList, arrayOfNodes, true);
2937
  NS_ENSURE_SUCCESS(res, res);
2937
  NS_ENSURE_SUCCESS(res, res);
2938
  int32_t listCount = arrayOfNodes.Count();
2938
  int32_t listCount = arrayOfNodes.Count();
2939
  int32_t i;
2939
  int32_t i;
2940
  for (i=0; i<listCount; i++)
2940
  for (i=0; i<listCount; i++)
2941
  {
2941
  {
2942
    // get the node to act on
2942
    // get the node to act on
2943
    nsIDOMNode* curNode = arrayOfNodes[i];
2943
    nsIDOMNode* curNode = arrayOfNodes[i];
 Lines 6454-6470   nsHTMLEditRules::GetHighestInlineParent( Link Here 
6454
}
6454
}
6455
6455
6456
6456
6457
///////////////////////////////////////////////////////////////////////////
6457
///////////////////////////////////////////////////////////////////////////
6458
// GetNodesFromPoint: given a particular operation, construct a list  
6458
// GetNodesFromPoint: given a particular operation, construct a list  
6459
//                     of nodes from a point that will be operated on. 
6459
//                     of nodes from a point that will be operated on. 
6460
//                       
6460
//                       
6461
nsresult 
6461
nsresult 
6462
nsHTMLEditRules::GetNodesFromPoint(DOMPoint point,
6462
nsHTMLEditRules::GetNodesFromPoint(::DOMPoint point,
6463
                                   EditAction operation,
6463
                                   EditAction operation,
6464
                                   nsCOMArray<nsIDOMNode> &arrayOfNodes,
6464
                                   nsCOMArray<nsIDOMNode> &arrayOfNodes,
6465
                                   bool dontTouchContent)
6465
                                   bool dontTouchContent)
6466
{
6466
{
6467
  nsresult res;
6467
  nsresult res;
6468
6468
6469
  // get our point
6469
  // get our point
6470
  nsCOMPtr<nsIDOMNode> node;
6470
  nsCOMPtr<nsIDOMNode> node;
(-)a/layout/base/GeometryUtils.cpp (-5 / +136 lines)
Line     Link Here 
 Lines 1-32    Link Here 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
5
6
#include "GeometryUtils.h"
6
#include "GeometryUtils.h"
7
7
8
#include "mozilla/dom/DOMPointBinding.h"
8
#include "mozilla/dom/GeometryUtilsBinding.h"
9
#include "mozilla/dom/GeometryUtilsBinding.h"
9
#include "mozilla/dom/Element.h"
10
#include "mozilla/dom/Element.h"
10
#include "mozilla/dom/Text.h"
11
#include "mozilla/dom/Text.h"
12
#include "mozilla/dom/DOMPoint.h"
11
#include "mozilla/dom/DOMQuad.h"
13
#include "mozilla/dom/DOMQuad.h"
14
#include "mozilla/dom/DOMRect.h"
12
#include "nsIFrame.h"
15
#include "nsIFrame.h"
13
#include "nsGenericDOMDataNode.h"
16
#include "nsGenericDOMDataNode.h"
14
#include "nsCSSFrameConstructor.h"
17
#include "nsCSSFrameConstructor.h"
15
#include "nsLayoutUtils.h"
18
#include "nsLayoutUtils.h"
16
#include "nsSVGUtils.h"
19
#include "nsSVGUtils.h"
17
20
18
using namespace mozilla;
21
using namespace mozilla;
19
using namespace mozilla::dom;
22
using namespace mozilla::dom;
20
23
21
namespace mozilla {
24
namespace mozilla {
22
25
23
typedef OwningTextOrElementOrDocument GeometryNode;
24
25
enum GeometryNodeType {
26
enum GeometryNodeType {
26
  GEOMETRY_NODE_ELEMENT,
27
  GEOMETRY_NODE_ELEMENT,
27
  GEOMETRY_NODE_TEXT,
28
  GEOMETRY_NODE_TEXT,
28
  GEOMETRY_NODE_DOCUMENT
29
  GEOMETRY_NODE_DOCUMENT
29
};
30
};
30
31
31
static nsIFrame*
32
static nsIFrame*
32
GetFrameForNode(nsINode* aNode, GeometryNodeType aType)
33
GetFrameForNode(nsINode* aNode, GeometryNodeType aType)
 Lines 50-106   GetFrameForNode(nsINode* aNode, Geometry Link Here 
50
  }
51
  }
51
  default:
52
  default:
52
    MOZ_ASSERT(false, "Unknown GeometryNodeType");
53
    MOZ_ASSERT(false, "Unknown GeometryNodeType");
53
    return nullptr;
54
    return nullptr;
54
  }
55
  }
55
}
56
}
56
57
57
static nsIFrame*
58
static nsIFrame*
58
GetFrameForGeometryNode(const Optional<GeometryNode>& aGeometryNode,
59
GetFrameForGeometryNode(const Optional<OwningGeometryNode>& aGeometryNode,
59
                        nsINode* aDefaultNode)
60
                        nsINode* aDefaultNode)
60
{
61
{
61
  if (!aGeometryNode.WasPassed()) {
62
  if (!aGeometryNode.WasPassed()) {
62
    return GetFrameForNode(aDefaultNode->OwnerDoc(), GEOMETRY_NODE_DOCUMENT);
63
    return GetFrameForNode(aDefaultNode->OwnerDoc(), GEOMETRY_NODE_DOCUMENT);
63
  }
64
  }
64
65
65
  const GeometryNode& value = aGeometryNode.Value();
66
  const OwningGeometryNode& value = aGeometryNode.Value();
66
  if (value.IsElement()) {
67
  if (value.IsElement()) {
67
    return GetFrameForNode(value.GetAsElement(), GEOMETRY_NODE_ELEMENT);
68
    return GetFrameForNode(value.GetAsElement(), GEOMETRY_NODE_ELEMENT);
68
  }
69
  }
69
  if (value.IsDocument()) {
70
  if (value.IsDocument()) {
70
    return GetFrameForNode(value.GetAsDocument(), GEOMETRY_NODE_DOCUMENT);
71
    return GetFrameForNode(value.GetAsDocument(), GEOMETRY_NODE_DOCUMENT);
71
  }
72
  }
72
  return GetFrameForNode(value.GetAsText(), GEOMETRY_NODE_TEXT);
73
  return GetFrameForNode(value.GetAsText(), GEOMETRY_NODE_TEXT);
73
}
74
}
74
75
75
static nsIFrame*
76
static nsIFrame*
77
GetFrameForGeometryNode(const GeometryNode& aGeometryNode)
78
{
79
  if (aGeometryNode.IsElement()) {
80
    return GetFrameForNode(&aGeometryNode.GetAsElement(), GEOMETRY_NODE_ELEMENT);
81
  }
82
  if (aGeometryNode.IsDocument()) {
83
    return GetFrameForNode(&aGeometryNode.GetAsDocument(), GEOMETRY_NODE_DOCUMENT);
84
  }
85
  return GetFrameForNode(&aGeometryNode.GetAsText(), GEOMETRY_NODE_TEXT);
86
}
87
88
static nsIFrame*
76
GetFrameForNode(nsINode* aNode)
89
GetFrameForNode(nsINode* aNode)
77
{
90
{
78
  if (aNode->IsElement()) {
91
  if (aNode->IsElement()) {
79
    return GetFrameForNode(aNode, GEOMETRY_NODE_ELEMENT);
92
    return GetFrameForNode(aNode, GEOMETRY_NODE_ELEMENT);
80
  }
93
  }
81
  if (aNode == aNode->OwnerDoc()) {
94
  if (aNode == aNode->OwnerDoc()) {
82
    return GetFrameForNode(aNode, GEOMETRY_NODE_DOCUMENT);
95
    return GetFrameForNode(aNode, GEOMETRY_NODE_DOCUMENT);
83
  }
96
  }
84
  NS_ASSERTION(aNode->IsNodeOfType(nsINode::eTEXT), "Unknown node type");
97
  NS_ASSERTION(aNode->IsNodeOfType(nsINode::eTEXT), "Unknown node type");
85
  return GetFrameForNode(aNode, GEOMETRY_NODE_TEXT);
98
  return GetFrameForNode(aNode, GEOMETRY_NODE_TEXT);
86
}
99
}
87
100
88
static nsIFrame*
101
static nsIFrame*
89
GetFirstNonAnonymousFrameForGeometryNode(const Optional<GeometryNode>& aNode,
102
GetFirstNonAnonymousFrameForGeometryNode(const Optional<OwningGeometryNode>& aNode,
90
                                         nsINode* aDefaultNode)
103
                                         nsINode* aDefaultNode)
91
{
104
{
92
  nsIFrame* f = GetFrameForGeometryNode(aNode, aDefaultNode);
105
  nsIFrame* f = GetFrameForGeometryNode(aNode, aDefaultNode);
93
  if (f) {
106
  if (f) {
94
    f = nsLayoutUtils::GetFirstNonAnonymousFrame(f);
107
    f = nsLayoutUtils::GetFirstNonAnonymousFrame(f);
95
  }
108
  }
96
  return f;
109
  return f;
97
}
110
}
98
111
112
static nsIFrame*
113
GetFirstNonAnonymousFrameForGeometryNode(const GeometryNode& aNode)
114
{
115
  nsIFrame* f = GetFrameForGeometryNode(aNode);
116
  if (f) {
117
    f = nsLayoutUtils::GetFirstNonAnonymousFrame(f);
118
  }
119
  return f;
120
}
121
122
static nsIFrame*
123
GetFirstNonAnonymousFrameForNode(nsINode* aNode)
124
{
125
  nsIFrame* f = GetFrameForNode(aNode);
126
  if (f) {
127
    f = nsLayoutUtils::GetFirstNonAnonymousFrame(f);
128
  }
129
  return f;
130
}
131
99
/**
132
/**
100
 * This can modify aFrame to point to a different frame. This is needed to
133
 * This can modify aFrame to point to a different frame. This is needed to
101
 * handle SVG, where SVG elements can only compute a rect that's valid with
134
 * handle SVG, where SVG elements can only compute a rect that's valid with
102
 * respect to the "outer SVG" frame.
135
 * respect to the "outer SVG" frame.
103
 */
136
 */
104
static nsRect
137
static nsRect
105
GetBoxRectForFrame(nsIFrame** aFrame, CSSBoxType aType)
138
GetBoxRectForFrame(nsIFrame** aFrame, CSSBoxType aType)
106
{
139
{
 Lines 230-238   void GetBoxQuads(nsINode* aNode, Link Here 
230
  // GetBoxRectForFrame can modify relativeToFrame so call it first.
263
  // GetBoxRectForFrame can modify relativeToFrame so call it first.
231
  nsPoint relativeToTopLeft =
264
  nsPoint relativeToTopLeft =
232
      GetBoxRectForFrame(&relativeToFrame, CSSBoxType::Border).TopLeft();
265
      GetBoxRectForFrame(&relativeToFrame, CSSBoxType::Border).TopLeft();
233
  AccumulateQuadCallback callback(ownerDoc, aResult, relativeToFrame,
266
  AccumulateQuadCallback callback(ownerDoc, aResult, relativeToFrame,
234
                                  relativeToTopLeft, aOptions.mBox);
267
                                  relativeToTopLeft, aOptions.mBox);
235
  nsLayoutUtils::GetAllInFlowBoxes(frame, &callback);
268
  nsLayoutUtils::GetAllInFlowBoxes(frame, &callback);
236
}
269
}
237
270
271
static void
272
TransformCSSPoints(nsINode* aTo, const GeometryNode& aFrom,
273
                   uint32_t aPointCount, gfxPoint* aPoints,
274
                   const ConvertCoordinateOptions& aOptions, ErrorResult& aRv)
275
{
276
  nsIFrame* fromFrame = GetFirstNonAnonymousFrameForGeometryNode(aFrom);
277
  nsIFrame* toFrame = GetFirstNonAnonymousFrameForNode(aTo);
278
  if (!fromFrame || !toFrame) {
279
    aRv.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
280
    return;
281
  }
282
  if (!CheckFramesInSameTopLevelBrowsingContext(fromFrame, toFrame)) {
283
    aRv.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
284
    return;
285
  }
286
287
  nsPoint fromOffset = GetBoxRectForFrame(&fromFrame, aOptions.mFromBox).TopLeft();
288
  nsPoint toOffset = GetBoxRectForFrame(&toFrame, aOptions.mToBox).TopLeft();
289
  gfxPoint fromOffsetGfx(nsPresContext::AppUnitsToFloatCSSPixels(fromOffset.x),
290
                         nsPresContext::AppUnitsToFloatCSSPixels(fromOffset.y));
291
  for (uint32_t i = 0; i < aPointCount; ++i) {
292
    aPoints[i] += fromOffsetGfx;
293
  }
294
  nsLayoutUtils::TransformResult rv =
295
    nsLayoutUtils::TransformCSSPoints(fromFrame, toFrame, aPointCount, aPoints);
296
  if (rv == nsLayoutUtils::TRANSFORM_SUCCEEDED) {
297
    gfxPoint toOffsetGfx(nsPresContext::AppUnitsToFloatCSSPixels(toOffset.x),
298
                         nsPresContext::AppUnitsToFloatCSSPixels(toOffset.y));
299
    for (uint32_t i = 0; i < aPointCount; ++i) {
300
      aPoints[i] -= toOffsetGfx;
301
    }
302
  } else {
303
    PodZero(aPoints, aPointCount);
304
  }
238
}
305
}
306
307
already_AddRefed<DOMQuad>
308
ConvertQuadFromNode(nsINode* aTo, dom::DOMQuad& aQuad,
309
                    const GeometryNode& aFrom,
310
                    const dom::ConvertCoordinateOptions& aOptions,
311
                    ErrorResult& aRv)
312
{
313
  gfxPoint points[4];
314
  for (uint32_t i = 0; i < 4; ++i) {
315
    DOMPoint* p = aQuad.Point(i);
316
    if (p->W() != 1.0 || p->Z() != 0.0) {
317
      aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
318
      return nullptr;
319
    }
320
    points[i] = gfxPoint(p->X(), p->Y());
321
  }
322
  TransformCSSPoints(aTo, aFrom, 4, points, aOptions, aRv);
323
  if (aRv.Failed()) {
324
    return nullptr;
325
  }
326
  nsRefPtr<DOMQuad> result = new DOMQuad(aTo->GetParentObject(), points);
327
  return result.forget();
328
}
329
330
already_AddRefed<DOMQuad>
331
ConvertRectFromNode(nsINode* aTo, dom::DOMRectReadOnly& aRect,
332
                    const GeometryNode& aFrom,
333
                    const dom::ConvertCoordinateOptions& aOptions,
334
                    ErrorResult& aRv)
335
{
336
  gfxPoint points[4];
337
  double x = aRect.X(), y = aRect.Y(), w = aRect.Width(), h = aRect.Height();
338
  points[0] = gfxPoint(x, y);
339
  points[1] = gfxPoint(x + w, y);
340
  points[2] = gfxPoint(x + w, y + h);
341
  points[3] = gfxPoint(x, y + h);
342
  TransformCSSPoints(aTo, aFrom, 4, points, aOptions, aRv);
343
  if (aRv.Failed()) {
344
    return nullptr;
345
  }
346
  nsRefPtr<DOMQuad> result = new DOMQuad(aTo->GetParentObject(), points);
347
  return result.forget();
348
}
349
350
already_AddRefed<DOMPoint>
351
ConvertPointFromNode(nsINode* aTo, const dom::DOMPointInit& aPoint,
352
                     const GeometryNode& aFrom,
353
                     const dom::ConvertCoordinateOptions& aOptions,
354
                     ErrorResult& aRv)
355
{
356
  if (aPoint.mW != 1.0 || aPoint.mZ != 0.0) {
357
    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
358
    return nullptr;
359
  }
360
  gfxPoint point(aPoint.mX, aPoint.mY);
361
  TransformCSSPoints(aTo, aFrom, 1, &point, aOptions, aRv);
362
  if (aRv.Failed()) {
363
    return nullptr;
364
  }
365
  nsRefPtr<DOMPoint> result = new DOMPoint(aTo->GetParentObject(), point.x, point.y);
366
  return result.forget();
367
}
368
369
}
(-)a/layout/base/GeometryUtils.h (-2 / +26 lines)
Line     Link Here 
 Lines 17-41    Link Here 
17
17
18
class nsINode;
18
class nsINode;
19
class nsIDocument;
19
class nsIDocument;
20
20
21
namespace mozilla {
21
namespace mozilla {
22
22
23
namespace dom {
23
namespace dom {
24
struct BoxQuadOptions;
24
struct BoxQuadOptions;
25
struct ConvertCoordinateOptions;
25
class DOMQuad;
26
class DOMQuad;
26
class Element;
27
class DOMRectReadOnly;
27
class Text;
28
class DOMPointInit;
29
class OwningTextOrElementOrDocument;
30
class TextOrElementOrDocument;
28
}
31
}
29
32
33
typedef dom::TextOrElementOrDocument GeometryNode;
34
typedef dom::OwningTextOrElementOrDocument OwningGeometryNode;
35
30
/**
36
/**
31
 * Computes quads for aNode using aOptions, according to GeometryUtils.getBoxQuads.
37
 * Computes quads for aNode using aOptions, according to GeometryUtils.getBoxQuads.
32
 * May set an error in aRv.
38
 * May set an error in aRv.
33
 */
39
 */
34
void GetBoxQuads(nsINode* aNode,
40
void GetBoxQuads(nsINode* aNode,
35
                 const dom::BoxQuadOptions& aOptions,
41
                 const dom::BoxQuadOptions& aOptions,
36
                 nsTArray<nsRefPtr<dom::DOMQuad> >& aResult,
42
                 nsTArray<nsRefPtr<dom::DOMQuad> >& aResult,
37
                 ErrorResult& aRv);
43
                 ErrorResult& aRv);
38
44
45
already_AddRefed<dom::DOMQuad>
46
ConvertQuadFromNode(nsINode* aTo, dom::DOMQuad& aQuad,
47
                    const GeometryNode& aFrom,
48
                    const dom::ConvertCoordinateOptions& aOptions,
49
                    ErrorResult& aRv);
50
51
already_AddRefed<dom::DOMQuad>
52
ConvertRectFromNode(nsINode* aTo, dom::DOMRectReadOnly& aRect,
53
                    const GeometryNode& aFrom,
54
                    const dom::ConvertCoordinateOptions& aOptions,
55
                    ErrorResult& aRv);
56
57
already_AddRefed<dom::DOMPoint>
58
ConvertPointFromNode(nsINode* aTo, const dom::DOMPointInit& aPoint,
59
                     const GeometryNode& aFrom,
60
                     const dom::ConvertCoordinateOptions& aOptions,
61
                     ErrorResult& aRv);
62
39
}
63
}
40
64
41
#endif /* MOZILLA_GEOMETRYUTILS_H_ */
65
#endif /* MOZILLA_GEOMETRYUTILS_H_ */
(-)a/layout/base/tests/test_getBoxQuads_convertPointRectQuad.html (-1 / +2 lines)
Line     Link Here 
 Lines 211-227   TextTextTextTextTextTextTextTextTextText Link Here 
211
<script>
211
<script>
212
SimpleTest.waitForExplicitFinish();
212
SimpleTest.waitForExplicitFinish();
213
213
214
window.scrollTo(0,0);
214
window.scrollTo(0,0);
215
215
216
function startTest() {
216
function startTest() {
217
  SpecialPowers.pushPrefEnv({"set": [["layout.css.DOMPoint.enabled", true],
217
  SpecialPowers.pushPrefEnv({"set": [["layout.css.DOMPoint.enabled", true],
218
                                     ["layout.css.DOMQuad.enabled", true],
218
                                     ["layout.css.DOMQuad.enabled", true],
219
                                     ["layout.css.getBoxQuads.enabled", true]]}, runTest);
219
                                     ["layout.css.getBoxQuads.enabled", true],
220
                                     ["layout.css.convertFromNode.enabled", true]]}, runTest);
220
}
221
}
221
222
222
function runTest() {
223
function runTest() {
223
  // Setup globals
224
  // Setup globals
224
  f1d = f1.contentWindow.f1d;
225
  f1d = f1.contentWindow.f1d;
225
  text = textContainer.firstChild;
226
  text = textContainer.firstChild;
226
  suppressedText = suppressedTextContainer.firstChild;
227
  suppressedText = suppressedTextContainer.firstChild;
227
228
(-)a/modules/libpref/src/init/all.js (+7 lines)
Line     Link Here 
 Lines 1769-1784   pref("layout.css.DOMQuad.enabled", true) Link Here 
1769
1769
1770
// Is support for GeometryUtils.getBoxQuads enabled?
1770
// Is support for GeometryUtils.getBoxQuads enabled?
1771
#ifdef RELEASE_BUILD
1771
#ifdef RELEASE_BUILD
1772
pref("layout.css.getBoxQuads.enabled", false);
1772
pref("layout.css.getBoxQuads.enabled", false);
1773
#else
1773
#else
1774
pref("layout.css.getBoxQuads.enabled", true);
1774
pref("layout.css.getBoxQuads.enabled", true);
1775
#endif
1775
#endif
1776
1776
1777
// Is support for GeometryUtils.getBoxQuads enabled?
1778
#ifdef RELEASE_BUILD
1779
pref("layout.css.convertFromNode.enabled", false);
1780
#else
1781
pref("layout.css.convertFromNode.enabled", true);
1782
#endif
1783
1777
// Is support for CSS "text-align: true X" enabled?
1784
// Is support for CSS "text-align: true X" enabled?
1778
pref("layout.css.text-align-true-value.enabled", false);
1785
pref("layout.css.text-align-true-value.enabled", false);
1779
1786
1780
// Is support for the CSS4 image-orientation property enabled?
1787
// Is support for the CSS4 image-orientation property enabled?
1781
pref("layout.css.image-orientation.enabled", true);
1788
pref("layout.css.image-orientation.enabled", true);
1782
1789
1783
// Is support for CSS3 Fonts features enabled?
1790
// Is support for CSS3 Fonts features enabled?
1784
// (includes font-variant-*, font-kerning, font-synthesis
1791
// (includes font-variant-*, font-kerning, font-synthesis

Return to bug 918189