Bug 1519952, add screenX and screenY properties to XULElement in order to replace places that currently get the screen coordinates of an element via the box object, r=bz
authorNeil Deakin <neil@mozilla.com>
Fri, 15 Feb 2019 15:26:08 -0500
changeset 517534 41da7f72eb6eb912a702170e912db116195f6beb
parent 517533 75b0a937397c76253bd72bfe1d548d842b81066d
child 517535 b980d74e702db481501dad76d4705c60062c3b69
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1519952
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1519952, add screenX and screenY properties to XULElement in order to replace places that currently get the screen coordinates of an element via the box object, r=bz
dom/webidl/XULElement.webidl
dom/xul/nsXULElement.cpp
dom/xul/nsXULElement.h
--- a/dom/webidl/XULElement.webidl
+++ b/dom/webidl/XULElement.webidl
@@ -55,16 +55,20 @@ interface XULElement : Element {
   // Position properties for
   // * popups - these are screen coordinates
   // * other elements - these are client coordinates relative to parent stack.
   [SetterThrows]
   attribute DOMString left;
   [SetterThrows]
   attribute DOMString top;
 
+  // Return the screen coordinates of the element.
+  readonly attribute long screenX;
+  readonly attribute long screenY;
+
   // Tooltip
   [SetterThrows]
   attribute DOMString tooltipText;
 
   // Properties for images
   [SetterThrows]
   attribute DOMString src;
 
--- a/dom/xul/nsXULElement.cpp
+++ b/dom/xul/nsXULElement.cpp
@@ -467,16 +467,26 @@ bool nsXULElement::IsFocusableInternal(i
         *aTabIndex = -1;
       }
     }
   }
 
   return shouldFocus;
 }
 
+int32_t nsXULElement::ScreenX() {
+  nsIFrame* frame = GetPrimaryFrame(FlushType::Layout);
+  return frame ? frame->GetScreenRect().x: 0;
+}
+
+int32_t nsXULElement::ScreenY() {
+  nsIFrame* frame = GetPrimaryFrame(FlushType::Layout);
+  return frame ? frame->GetScreenRect().y : 0;
+}
+
 bool nsXULElement::HasMenu() {
   nsMenuFrame* menu = do_QueryFrame(GetPrimaryFrame());
   return menu != nullptr;
 }
 
 void nsXULElement::OpenMenu(bool aOpenFlag) {
   nsMenuFrame* menu = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
 
--- a/dom/xul/nsXULElement.h
+++ b/dom/xul/nsXULElement.h
@@ -332,16 +332,19 @@ class nsXULElement : public nsStyledElem
   virtual void DoneAddingChildren(bool aHaveNotified) override;
 
 #ifdef DEBUG
   virtual void List(FILE* out, int32_t aIndent) const override;
   virtual void DumpContent(FILE* out, int32_t aIndent,
                            bool aDumpAll) const override {}
 #endif
 
+  MOZ_CAN_RUN_SCRIPT int32_t ScreenX();
+  MOZ_CAN_RUN_SCRIPT int32_t ScreenY();
+
   bool HasMenu();
   MOZ_CAN_RUN_SCRIPT void OpenMenu(bool aOpenFlag);
 
   virtual bool PerformAccesskey(bool aKeyCausesActivation,
                                 bool aIsTrustedEvent) override;
   void ClickWithInputSource(uint16_t aInputSource, bool aIsTrustedEvent);
 
   nsIContent* GetBindingParent() const final { return mBindingParent; }