Bug 1018324 - Restore inIFlasher, but with drawElementOutline and repaintElement as no-ops. r=bz
authorJonathan Watt <jwatt@jwatt.org>
Wed, 11 Jun 2014 21:29:15 +0100
changeset 210165 199108b7f25d65253a12982d150dc3e1b0136db0
parent 210164 19ba96e89095eb06d1c8c22dddd15bb66c16566f
child 210166 6c44c84703fa693bd8d91b066900af8d7b6c4acd
child 210167 aebb40693f4860cefd429ff4a124313ab98248b3
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1018324
milestone33.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 1018324 - Restore inIFlasher, but with drawElementOutline and repaintElement as no-ops. r=bz
layout/build/nsLayoutModule.cpp
layout/inspector/inFlasher.cpp
layout/inspector/inFlasher.h
layout/inspector/inIFlasher.idl
layout/inspector/inLayoutUtils.cpp
layout/inspector/inLayoutUtils.h
layout/inspector/moz.build
--- a/layout/build/nsLayoutModule.cpp
+++ b/layout/build/nsLayoutModule.cpp
@@ -188,16 +188,17 @@ class nsIDocumentLoaderFactory;
 
 #include "nsIBoxObject.h"
 
 #ifdef MOZ_XUL
 #include "inDOMView.h"
 #endif /* MOZ_XUL */
 
 #include "inDeepTreeWalker.h"
+#include "inFlasher.h"
 #include "inCSSValueSearch.h"
 #include "inDOMUtils.h"
 
 #ifdef MOZ_XUL
 #include "nsIXULDocument.h"
 #include "nsIXULSortService.h"
 
 nsresult
@@ -501,16 +502,17 @@ MAKE_CTOR(CreateNewScrollBoxObject,     
 MAKE_CTOR(CreateNewTreeBoxObject,       nsIBoxObject,           NS_NewTreeBoxObject)
 MAKE_CTOR(CreateNewContainerBoxObject,  nsIBoxObject,           NS_NewContainerBoxObject)
 #endif // MOZ_XUL
 
 #ifdef MOZ_XUL
 NS_GENERIC_FACTORY_CONSTRUCTOR(inDOMView)
 #endif
 NS_GENERIC_FACTORY_CONSTRUCTOR(inDeepTreeWalker)
+NS_GENERIC_FACTORY_CONSTRUCTOR(inFlasher)
 NS_GENERIC_FACTORY_CONSTRUCTOR(inCSSValueSearch)
 NS_GENERIC_FACTORY_CONSTRUCTOR(inDOMUtils)
 
 MAKE_CTOR2(CreateContentViewer,           nsIContentViewer,            NS_NewContentViewer)
 MAKE_CTOR(CreateHTMLDocument,             nsIDocument,                 NS_NewHTMLDocument)
 MAKE_CTOR(CreateXMLDocument,              nsIDocument,                 NS_NewXMLDocument)
 MAKE_CTOR(CreateSVGDocument,              nsIDocument,                 NS_NewSVGDocument)
 MAKE_CTOR(CreateImageDocument,            nsIDocument,                 NS_NewImageDocument)
@@ -656,16 +658,17 @@ NS_DEFINE_NAMED_CID(NS_POPUPBOXOBJECT_CI
 NS_DEFINE_NAMED_CID(NS_CONTAINERBOXOBJECT_CID);
 NS_DEFINE_NAMED_CID(NS_SCROLLBOXOBJECT_CID);
 NS_DEFINE_NAMED_CID(NS_TREEBOXOBJECT_CID);
 #endif // MOZ_XUL
 #ifdef MOZ_XUL
 NS_DEFINE_NAMED_CID(IN_DOMVIEW_CID);
 #endif
 NS_DEFINE_NAMED_CID(IN_DEEPTREEWALKER_CID);
+NS_DEFINE_NAMED_CID(IN_FLASHER_CID);
 NS_DEFINE_NAMED_CID(IN_CSSVALUESEARCH_CID);
 NS_DEFINE_NAMED_CID(IN_DOMUTILS_CID);
 NS_DEFINE_NAMED_CID(NS_CONTENT_VIEWER_CID);
 NS_DEFINE_NAMED_CID(NS_HTMLDOCUMENT_CID);
 NS_DEFINE_NAMED_CID(NS_XMLDOCUMENT_CID);
 NS_DEFINE_NAMED_CID(NS_SVGDOCUMENT_CID);
 NS_DEFINE_NAMED_CID(NS_IMAGEDOCUMENT_CID);
 NS_DEFINE_NAMED_CID(NS_DOMMULTIPARTBLOB_CID);
@@ -945,16 +948,17 @@ static const mozilla::Module::CIDEntry k
   { &kNS_CONTAINERBOXOBJECT_CID, false, nullptr, CreateNewContainerBoxObject },
   { &kNS_SCROLLBOXOBJECT_CID, false, nullptr, CreateNewScrollBoxObject },
   { &kNS_TREEBOXOBJECT_CID, false, nullptr, CreateNewTreeBoxObject },
 #endif // MOZ_XUL
 #ifdef MOZ_XUL
   { &kIN_DOMVIEW_CID, false, nullptr, inDOMViewConstructor },
 #endif
   { &kIN_DEEPTREEWALKER_CID, false, nullptr, inDeepTreeWalkerConstructor },
+  { &kIN_FLASHER_CID, false, nullptr, inFlasherConstructor },
   { &kIN_CSSVALUESEARCH_CID, false, nullptr, inCSSValueSearchConstructor },
   { &kIN_DOMUTILS_CID, false, nullptr, inDOMUtilsConstructor },
   { &kNS_CONTENT_VIEWER_CID, false, nullptr, CreateContentViewer },
   { &kNS_HTMLDOCUMENT_CID, false, nullptr, CreateHTMLDocument },
   { &kNS_XMLDOCUMENT_CID, false, nullptr, CreateXMLDocument },
   { &kNS_SVGDOCUMENT_CID, false, nullptr, CreateSVGDocument },
   { &kNS_IMAGEDOCUMENT_CID, false, nullptr, CreateImageDocument },
   { &kNS_DOMMULTIPARTBLOB_CID, false, nullptr, CreateDOMBlob },
@@ -1098,16 +1102,17 @@ static const mozilla::Module::ContractID
   { "@mozilla.org/layout/xul-boxobject-container;1", &kNS_CONTAINERBOXOBJECT_CID },
   { "@mozilla.org/layout/xul-boxobject-scrollbox;1", &kNS_SCROLLBOXOBJECT_CID },
   { "@mozilla.org/layout/xul-boxobject-tree;1", &kNS_TREEBOXOBJECT_CID },
 #endif // MOZ_XUL
 #ifdef MOZ_XUL
   { "@mozilla.org/inspector/dom-view;1", &kIN_DOMVIEW_CID },
 #endif
   { "@mozilla.org/inspector/deep-tree-walker;1", &kIN_DEEPTREEWALKER_CID },
+  { "@mozilla.org/inspector/flasher;1", &kIN_FLASHER_CID },
   { "@mozilla.org/inspector/search;1?type=cssvalue", &kIN_CSSVALUESEARCH_CID },
   { IN_DOMUTILS_CONTRACTID, &kIN_DOMUTILS_CID },
   { "@mozilla.org/xml/xml-document;1", &kNS_XMLDOCUMENT_CID },
   { "@mozilla.org/svg/svg-document;1", &kNS_SVGDOCUMENT_CID },
   { NS_DOMMULTIPARTBLOB_CONTRACTID, &kNS_DOMMULTIPARTBLOB_CID },
   { NS_DOMMULTIPARTFILE_CONTRACTID, &kNS_DOMMULTIPARTFILE_CID },
   { "@mozilla.org/content/dom-selection;1", &kNS_DOMSELECTION_CID },
   { "@mozilla.org/content/post-content-iterator;1", &kNS_CONTENTITERATOR_CID },
new file mode 100644
--- /dev/null
+++ b/layout/inspector/inFlasher.cpp
@@ -0,0 +1,169 @@
+/* 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 "inFlasher.h"
+#include "inLayoutUtils.h"
+
+#include "nsIDOMElement.h"
+#include "nsIServiceManager.h"
+#include "nsIPresShell.h"
+#include "nsIFrame.h"
+#include "nsIWidget.h"
+#include "nsReadableUtils.h"
+#include "nsRenderingContext.h"
+#include "nsIDOMWindow.h"
+#include "nsIContent.h"
+
+#include "prprf.h"
+
+///////////////////////////////////////////////////////////////////////////////
+
+inFlasher::inFlasher() :
+  mColor(NS_RGB(0,0,0)),
+  mThickness(0),
+  mInvert(false)
+{
+}
+
+inFlasher::~inFlasher()
+{
+}
+
+NS_IMPL_ISUPPORTS(inFlasher, inIFlasher)
+
+///////////////////////////////////////////////////////////////////////////////
+// inIFlasher
+
+NS_IMETHODIMP
+inFlasher::GetColor(nsAString& aColor)
+{
+  // Copied from nsGenericHTMLElement::ColorToString()
+  char buf[10];
+  PR_snprintf(buf, sizeof(buf), "#%02x%02x%02x",
+              NS_GET_R(mColor), NS_GET_G(mColor), NS_GET_B(mColor));
+  CopyASCIItoUTF16(buf, aColor);
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+inFlasher::SetColor(const nsAString& aColor)
+{
+  NS_ENSURE_FALSE(aColor.IsEmpty(), NS_ERROR_ILLEGAL_VALUE);
+
+  nsAutoString colorStr;
+  colorStr.Assign(aColor);
+
+  if (colorStr.CharAt(0) != '#') {
+    if (NS_ColorNameToRGB(colorStr, &mColor)) {
+      return NS_OK;
+    }
+  }
+  else {
+    colorStr.Cut(0, 1);
+    if (NS_HexToRGB(colorStr, &mColor)) {
+      return NS_OK;
+    }
+  }
+
+  return NS_ERROR_ILLEGAL_VALUE;
+}
+
+NS_IMETHODIMP
+inFlasher::GetThickness(uint16_t *aThickness)
+{
+  NS_PRECONDITION(aThickness, "Null pointer");
+  *aThickness = mThickness;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+inFlasher::SetThickness(uint16_t aThickness)
+{
+  mThickness = aThickness;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+inFlasher::GetInvert(bool *aInvert)
+{
+  NS_PRECONDITION(aInvert, "Null pointer");
+  *aInvert = mInvert;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+inFlasher::SetInvert(bool aInvert)
+{
+  mInvert = aInvert;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+inFlasher::RepaintElement(nsIDOMElement* aElement)
+{
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+inFlasher::DrawElementOutline(nsIDOMElement* aElement)
+{
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+inFlasher::ScrollElementIntoView(nsIDOMElement *aElement)
+{
+  NS_ENSURE_ARG_POINTER(aElement);
+  nsCOMPtr<nsIDOMWindow> window = inLayoutUtils::GetWindowFor(aElement);
+  if (!window) {
+    return NS_OK;
+  }
+
+  nsCOMPtr<nsIPresShell> presShell = inLayoutUtils::GetPresShellFor(window);
+  if (!presShell) {
+    return NS_OK;
+  }
+
+  nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
+  presShell->ScrollContentIntoView(content,
+                                   nsIPresShell::ScrollAxis(),
+                                   nsIPresShell::ScrollAxis(),
+                                   nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
+
+  return NS_OK;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// inFlasher
+
+void
+inFlasher::DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
+                       nsRenderingContext* aRenderContext,
+                       bool aDrawBegin, bool aDrawEnd)
+{
+  aRenderContext->SetColor(mColor);
+
+  DrawLine(aX, aY, aWidth, DIR_HORIZONTAL, BOUND_OUTER, aRenderContext);
+  if (aDrawBegin) {
+    DrawLine(aX, aY, aHeight, DIR_VERTICAL, BOUND_OUTER, aRenderContext);
+  }
+  DrawLine(aX, aY+aHeight, aWidth, DIR_HORIZONTAL, BOUND_INNER, aRenderContext);
+  if (aDrawEnd) {
+    DrawLine(aX+aWidth, aY, aHeight, DIR_VERTICAL, BOUND_INNER, aRenderContext);
+  }
+}
+
+void
+inFlasher::DrawLine(nscoord aX, nscoord aY, nscoord aLength,
+                    bool aDir, bool aBounds,
+                    nsRenderingContext* aRenderContext)
+{
+  nscoord thickTwips = nsPresContext::CSSPixelsToAppUnits(mThickness);
+  if (aDir) { // horizontal
+    aRenderContext->FillRect(aX, aY+(aBounds?0:-thickTwips), aLength, thickTwips);
+  } else { // vertical
+    aRenderContext->FillRect(aX+(aBounds?0:-thickTwips), aY, thickTwips, aLength);
+  }
+}
new file mode 100644
--- /dev/null
+++ b/layout/inspector/inFlasher.h
@@ -0,0 +1,47 @@
+/* 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 __inFlasher_h__
+#define __inFlasher_h__
+
+#include "inIFlasher.h"
+#include "nsCoord.h"
+#include "nsColor.h"
+
+class nsRenderingContext;
+
+#define BOUND_INNER 0
+#define BOUND_OUTER 1
+
+#define DIR_VERTICAL 0
+#define DIR_HORIZONTAL 1
+
+class inFlasher : public inIFlasher
+{
+public:
+  NS_DECL_ISUPPORTS
+  NS_DECL_INIFLASHER
+
+  inFlasher();
+  virtual ~inFlasher();
+
+protected:
+  void DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
+                   nsRenderingContext* aRenderContext,
+                   bool aDrawBegin, bool aDrawEnd);
+  void DrawLine(nscoord aX, nscoord aY, nscoord aLength,
+                bool aDir, bool aBounds,
+                nsRenderingContext* aRenderContext);
+
+  nscolor mColor;
+
+  uint16_t mThickness;
+  bool mInvert;
+};
+
+// {9286E71A-621A-4b91-851E-9984C1A2E81A}
+#define IN_FLASHER_CID \
+{ 0x9286e71a, 0x621a, 0x4b91, { 0x85, 0x1e, 0x99, 0x84, 0xc1, 0xa2, 0xe8, 0x1a } }
+
+#endif // __inFlasher_h__
new file mode 100644
--- /dev/null
+++ b/layout/inspector/inIFlasher.idl
@@ -0,0 +1,46 @@
+/* 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 "nsISupports.idl"
+
+interface nsIDOMElement;
+
+/**
+ * This class will be removed in gecko v33. See comments below for alternatives.
+ *
+ * @status DEPRECATED - see comments below.
+ */
+[scriptable, uuid(7B4A099F-6F6E-4565-977B-FB622ADBFF49)]
+interface inIFlasher : nsISupports 
+{
+  attribute DOMString       color;
+  attribute boolean         invert;
+  attribute unsigned short  thickness;
+
+  /**
+   * This function now does nothing at all. Use the :-moz-devtools-highlighted
+   * pseudo-class instead. For example, see the "HIGHLIGHTED_PSEUDO_CLASS" and
+   * "INVERT" lines in:
+   * https://hg.mozilla.org/dom-inspector/file/tip/resources/content/Flasher.js
+   *
+   * @status DEPRECATED
+   */
+  void drawElementOutline(in nsIDOMElement aElement);
+
+  /**
+   * This function now does nothing at all.
+   *
+   * @status DEPRECATED
+   */
+  void repaintElement(in nsIDOMElement aElement);
+
+  /**
+   * As of gecko v33 you should use inIDOMUtils::scrollElementIntoView instead
+   * of this function.
+   *
+   * @status DEPRECATED
+   */
+  void scrollElementIntoView(in nsIDOMElement aElement);
+};
+
--- a/layout/inspector/inLayoutUtils.cpp
+++ b/layout/inspector/inLayoutUtils.cpp
@@ -15,16 +15,48 @@
 #include "nsPresContext.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/dom/Element.h"
 
 using namespace mozilla;
 
 ///////////////////////////////////////////////////////////////////////////////
 
+nsIDOMWindow*
+inLayoutUtils::GetWindowFor(nsIDOMNode* aNode)
+{
+  nsCOMPtr<nsIDOMDocument> doc1;
+  aNode->GetOwnerDocument(getter_AddRefs(doc1));
+  return GetWindowFor(doc1.get());
+}
+
+nsIDOMWindow*
+inLayoutUtils::GetWindowFor(nsIDOMDocument* aDoc)
+{
+  nsCOMPtr<nsIDOMWindow> window;
+  aDoc->GetDefaultView(getter_AddRefs(window));
+  return window;
+}
+
+nsIPresShell* 
+inLayoutUtils::GetPresShellFor(nsISupports* aThing)
+{
+  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aThing);
+
+  return window->GetDocShell()->GetPresShell();
+}
+
+/*static*/
+nsIFrame*
+inLayoutUtils::GetFrameFor(nsIDOMElement* aElement)
+{
+  nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
+  return content->GetPrimaryFrame();
+}
+
 EventStateManager*
 inLayoutUtils::GetEventStateManagerFor(nsIDOMElement *aElement)
 {
   NS_PRECONDITION(aElement, "Passing in a null element is bad");
 
   nsCOMPtr<nsIDOMDocument> domDoc;
   aElement->GetOwnerDocument(getter_AddRefs(domDoc));
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
--- a/layout/inspector/inLayoutUtils.h
+++ b/layout/inspector/inLayoutUtils.h
@@ -17,15 +17,19 @@ class nsISupports;
 
 namespace mozilla {
 class EventStateManager;
 }
 
 class inLayoutUtils
 {
 public:
+  static nsIDOMWindow* GetWindowFor(nsIDOMNode* aNode);
+  static nsIDOMWindow* GetWindowFor(nsIDOMDocument* aDoc);
+  static nsIPresShell* GetPresShellFor(nsISupports* aThing);
+  static nsIFrame* GetFrameFor(nsIDOMElement* aElement);
   static mozilla::EventStateManager*
            GetEventStateManagerFor(nsIDOMElement *aElement);
   static nsIDOMDocument* GetSubDocumentFor(nsIDOMNode* aNode);
   static nsIDOMNode* GetContainerFor(const nsIDocument& aDoc);
 };
 
 #endif // __inLayoutUtils_h__
--- a/layout/inspector/moz.build
+++ b/layout/inspector/moz.build
@@ -4,16 +4,17 @@
 # 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/.
 
 XPIDL_SOURCES += [
     'inICSSValueSearch.idl',
     'inIDeepTreeWalker.idl',
     'inIDOMUtils.idl',
     'inIDOMView.idl',
+    'inIFlasher.idl',
     'inISearchObserver.idl',
     'inISearchProcess.idl',
     'nsIDOMFontFace.idl',
     'nsIDOMFontFaceList.idl',
 ]
 
 XPIDL_MODULE = 'inspector'
 
@@ -21,16 +22,17 @@ EXPORTS += [
     'nsFontFace.h',
     'nsFontFaceList.h',
 ]
 
 UNIFIED_SOURCES += [
     'inCSSValueSearch.cpp',
     'inDeepTreeWalker.cpp',
     'inDOMUtils.cpp',
+    'inFlasher.cpp',
     'inLayoutUtils.cpp',
     'inSearchLoop.cpp',
     'nsFontFace.cpp',
     'nsFontFaceList.cpp',
 ]
 
 if CONFIG['MOZ_XUL']:
     UNIFIED_SOURCES += [