diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index 16c74da42add..c790795aa93d 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -193,6 +193,7 @@ class nsIDocumentLoaderFactory; #endif /* MOZ_XUL */ #include "inDeepTreeWalker.h" +#include "inFlasher.h" #include "inCSSValueSearch.h" #include "inDOMUtils.h" @@ -506,6 +507,7 @@ MAKE_CTOR(CreateNewContainerBoxObject, nsIBoxObject, NS_NewContainerB 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) @@ -661,6 +663,7 @@ NS_DEFINE_NAMED_CID(NS_TREEBOXOBJECT_CID); 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); @@ -950,6 +953,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = { { &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 }, @@ -1103,6 +1107,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = { { "@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 }, diff --git a/layout/inspector/inFlasher.cpp b/layout/inspector/inFlasher.cpp new file mode 100644 index 000000000000..3290f5f0d13e --- /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 window = inLayoutUtils::GetWindowFor(aElement); + if (!window) { + return NS_OK; + } + + nsCOMPtr presShell = inLayoutUtils::GetPresShellFor(window); + if (!presShell) { + return NS_OK; + } + + nsCOMPtr 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); + } +} diff --git a/layout/inspector/inFlasher.h b/layout/inspector/inFlasher.h new file mode 100644 index 000000000000..259c9b05d968 --- /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__ diff --git a/layout/inspector/inIFlasher.idl b/layout/inspector/inIFlasher.idl new file mode 100644 index 000000000000..6483f1b88b84 --- /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); +}; + diff --git a/layout/inspector/inLayoutUtils.cpp b/layout/inspector/inLayoutUtils.cpp index b5128b2483e0..ad524941fe7b 100644 --- a/layout/inspector/inLayoutUtils.cpp +++ b/layout/inspector/inLayoutUtils.cpp @@ -20,6 +20,38 @@ using namespace mozilla; /////////////////////////////////////////////////////////////////////////////// +nsIDOMWindow* +inLayoutUtils::GetWindowFor(nsIDOMNode* aNode) +{ + nsCOMPtr doc1; + aNode->GetOwnerDocument(getter_AddRefs(doc1)); + return GetWindowFor(doc1.get()); +} + +nsIDOMWindow* +inLayoutUtils::GetWindowFor(nsIDOMDocument* aDoc) +{ + nsCOMPtr window; + aDoc->GetDefaultView(getter_AddRefs(window)); + return window; +} + +nsIPresShell* +inLayoutUtils::GetPresShellFor(nsISupports* aThing) +{ + nsCOMPtr window = do_QueryInterface(aThing); + + return window->GetDocShell()->GetPresShell(); +} + +/*static*/ +nsIFrame* +inLayoutUtils::GetFrameFor(nsIDOMElement* aElement) +{ + nsCOMPtr content = do_QueryInterface(aElement); + return content->GetPrimaryFrame(); +} + EventStateManager* inLayoutUtils::GetEventStateManagerFor(nsIDOMElement *aElement) { diff --git a/layout/inspector/inLayoutUtils.h b/layout/inspector/inLayoutUtils.h index 826c19ef3362..4aa9dbd279d9 100644 --- a/layout/inspector/inLayoutUtils.h +++ b/layout/inspector/inLayoutUtils.h @@ -22,6 +22,10 @@ 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); diff --git a/layout/inspector/moz.build b/layout/inspector/moz.build index 288f6f888067..f081fca41108 100644 --- a/layout/inspector/moz.build +++ b/layout/inspector/moz.build @@ -9,6 +9,7 @@ XPIDL_SOURCES += [ 'inIDeepTreeWalker.idl', 'inIDOMUtils.idl', 'inIDOMView.idl', + 'inIFlasher.idl', 'inISearchObserver.idl', 'inISearchProcess.idl', 'nsIDOMFontFace.idl', @@ -26,6 +27,7 @@ UNIFIED_SOURCES += [ 'inCSSValueSearch.cpp', 'inDeepTreeWalker.cpp', 'inDOMUtils.cpp', + 'inFlasher.cpp', 'inLayoutUtils.cpp', 'inSearchLoop.cpp', 'nsFontFace.cpp',