2006-05-17 02:33:34 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2006-05-17 02:38:30 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2006-05-17 02:21:49 +00:00
|
|
|
*
|
2006-05-17 02:38:30 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2006-05-17 02:33:34 +00:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2006-05-17 02:21:49 +00:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2006-05-17 02:38:30 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2006-05-17 02:33:34 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2006-05-17 02:21:49 +00:00
|
|
|
*
|
2006-05-17 02:33:34 +00:00
|
|
|
* Contributor(s):
|
2006-05-17 02:21:53 +00:00
|
|
|
* Joe Hewitt <hewitt@netscape.com> (original author)
|
2006-05-17 02:37:47 +00:00
|
|
|
* Christopher A. Aillon <christopher@aillon.com>
|
2006-05-17 02:33:34 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2006-05-17 02:38:30 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2006-05-17 02:33:34 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2006-05-17 02:38:30 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2006-05-17 02:33:34 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-05-17 02:21:49 +00:00
|
|
|
|
|
|
|
#include "inFlasher.h"
|
2006-05-17 02:21:53 +00:00
|
|
|
#include "inLayoutUtils.h"
|
2006-05-17 02:21:49 +00:00
|
|
|
|
2006-05-17 02:33:55 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2006-05-17 02:33:42 +00:00
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIWidget.h"
|
2006-05-17 02:37:47 +00:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIFrame.h"
|
2006-05-17 02:38:14 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2006-05-17 02:33:42 +00:00
|
|
|
|
2006-05-17 02:37:48 +00:00
|
|
|
#include "prprf.h"
|
|
|
|
|
2006-05-17 02:33:55 +00:00
|
|
|
static NS_DEFINE_CID(kInspectorCSSUtilsCID, NS_INSPECTORCSSUTILS_CID);
|
|
|
|
|
2006-05-17 02:21:49 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-05-17 02:37:48 +00:00
|
|
|
inFlasher::inFlasher() :
|
|
|
|
mColor(NS_RGB(0,0,0)),
|
|
|
|
mThickness(0),
|
|
|
|
mInvert(PR_FALSE)
|
2006-05-17 02:21:49 +00:00
|
|
|
{
|
2006-05-17 02:33:55 +00:00
|
|
|
mCSSUtils = do_GetService(kInspectorCSSUtilsCID);
|
2006-05-17 02:21:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inFlasher::~inFlasher()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:38:09 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(inFlasher, inIFlasher)
|
2006-05-17 02:21:49 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// inIFlasher
|
|
|
|
|
2006-05-17 02:37:48 +00:00
|
|
|
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));
|
2006-05-17 02:38:14 +00:00
|
|
|
CopyASCIItoUTF16(buf, aColor);
|
2006-05-17 02:37:48 +00:00
|
|
|
|
|
|
|
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(PRUint16 *aThickness)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aThickness, "Null pointer");
|
|
|
|
*aThickness = mThickness;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inFlasher::SetThickness(PRUint16 aThickness)
|
|
|
|
{
|
|
|
|
mThickness = aThickness;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inFlasher::GetInvert(PRBool *aInvert)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aInvert, "Null pointer");
|
|
|
|
*aInvert = mInvert;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inFlasher::SetInvert(PRBool aInvert)
|
|
|
|
{
|
|
|
|
mInvert = aInvert;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-05-17 02:21:53 +00:00
|
|
|
inFlasher::RepaintElement(nsIDOMElement* aElement)
|
2006-05-17 02:21:49 +00:00
|
|
|
{
|
2006-05-17 02:21:53 +00:00
|
|
|
nsCOMPtr<nsIDOMWindowInternal> window = inLayoutUtils::GetWindowFor(aElement);
|
|
|
|
if (!window) return NS_OK;
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = inLayoutUtils::GetPresShellFor(window);
|
|
|
|
if (!presShell) return NS_OK;
|
|
|
|
nsIFrame* frame = inLayoutUtils::GetFrameFor(aElement, presShell);
|
2006-05-17 02:21:49 +00:00
|
|
|
if (!frame) return NS_OK;
|
|
|
|
|
2006-05-17 02:38:12 +00:00
|
|
|
nsIFrame* parentWithView = frame->GetAncestorWithViewExternal();
|
2006-05-17 02:21:49 +00:00
|
|
|
if (parentWithView) {
|
2006-05-17 02:38:10 +00:00
|
|
|
nsIView* view = parentWithView->GetViewExternal();
|
2006-05-17 02:37:59 +00:00
|
|
|
if (view) {
|
2006-05-17 02:38:10 +00:00
|
|
|
nsIViewManager* viewManager = view->GetViewManager();
|
2006-05-17 02:21:53 +00:00
|
|
|
if (viewManager) {
|
2006-05-17 02:38:10 +00:00
|
|
|
nsRect rect = parentWithView->GetRect();
|
2006-05-17 02:21:53 +00:00
|
|
|
viewManager->UpdateView(view, rect, NS_VMREFRESH_NO_SYNC);
|
|
|
|
}
|
2006-05-17 02:21:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-05-17 02:37:48 +00:00
|
|
|
inFlasher::DrawElementOutline(nsIDOMElement* aElement)
|
2006-05-17 02:21:49 +00:00
|
|
|
{
|
2006-05-17 02:21:53 +00:00
|
|
|
nsCOMPtr<nsIDOMWindowInternal> window = inLayoutUtils::GetWindowFor(aElement);
|
|
|
|
if (!window) return NS_OK;
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = inLayoutUtils::GetPresShellFor(window);
|
2006-05-17 02:38:43 +00:00
|
|
|
if (!presShell) return NS_OK;
|
|
|
|
|
2006-05-17 02:38:41 +00:00
|
|
|
nsPresContext *presContext = presShell->GetPresContext();
|
2006-05-17 02:38:39 +00:00
|
|
|
|
2006-05-17 02:38:41 +00:00
|
|
|
float p2t = presContext->PixelsToTwips();
|
2006-05-17 02:33:42 +00:00
|
|
|
|
2006-05-17 02:38:39 +00:00
|
|
|
PRBool isFirstFrame = PR_TRUE;
|
|
|
|
nsCOMPtr<nsIRenderingContext> rcontext;
|
|
|
|
nsIFrame* frame = inLayoutUtils::GetFrameFor(aElement, presShell);
|
|
|
|
while (frame) {
|
|
|
|
if (!rcontext) {
|
|
|
|
presShell->CreateRenderingContext(frame, getter_AddRefs(rcontext));
|
|
|
|
}
|
|
|
|
// get view bounds in case this frame is being scrolled
|
|
|
|
nsRect rect = frame->GetRect();
|
2006-05-17 02:38:44 +00:00
|
|
|
nsPoint origin = inLayoutUtils::GetClientOrigin(frame);
|
2006-05-17 02:38:39 +00:00
|
|
|
rect.MoveTo(origin);
|
|
|
|
mCSSUtils->AdjustRectForMargins(frame, rect);
|
|
|
|
|
|
|
|
if (mInvert) {
|
|
|
|
rcontext->InvertRect(rect);
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:38:54 +00:00
|
|
|
frame = frame->GetNextContinuation();
|
2006-05-17 02:21:49 +00:00
|
|
|
|
2006-05-17 02:38:39 +00:00
|
|
|
PRBool isLastFrame = (frame == nsnull);
|
|
|
|
DrawOutline(rect.x, rect.y, rect.width, rect.height, p2t, rcontext,
|
|
|
|
isFirstFrame, isLastFrame);
|
|
|
|
isFirstFrame = PR_FALSE;
|
|
|
|
}
|
2006-05-17 02:21:49 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:37:47 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
inFlasher::ScrollElementIntoView(nsIDOMElement *aElement)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aElement, "Dude, where's my arg?!");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> window = inLayoutUtils::GetWindowFor(aElement);
|
|
|
|
if (!window) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = inLayoutUtils::GetPresShellFor(window);
|
2006-05-17 02:38:43 +00:00
|
|
|
if (!presShell) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-05-17 02:37:47 +00:00
|
|
|
nsIFrame* frame = inLayoutUtils::GetFrameFor(aElement, presShell);
|
|
|
|
if (!frame) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
presShell->ScrollFrameIntoView(frame,
|
|
|
|
NS_PRESSHELL_SCROLL_ANYWHERE /* VPercent */,
|
|
|
|
NS_PRESSHELL_SCROLL_ANYWHERE /* HPercent */);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:21:49 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// inFlasher
|
|
|
|
|
2006-05-17 02:37:48 +00:00
|
|
|
void
|
2006-05-17 02:37:47 +00:00
|
|
|
inFlasher::DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
|
2006-05-17 02:38:39 +00:00
|
|
|
float aP2T, nsIRenderingContext* aRenderContext,
|
|
|
|
PRBool aDrawBegin, PRBool aDrawEnd)
|
2006-05-17 02:21:49 +00:00
|
|
|
{
|
2006-05-17 02:37:48 +00:00
|
|
|
aRenderContext->SetColor(mColor);
|
2006-05-17 02:21:49 +00:00
|
|
|
|
2006-05-17 02:37:48 +00:00
|
|
|
DrawLine(aX, aY, aWidth, DIR_HORIZONTAL, BOUND_OUTER, aP2T, aRenderContext);
|
2006-05-17 02:38:39 +00:00
|
|
|
if (aDrawBegin) {
|
|
|
|
DrawLine(aX, aY, aHeight, DIR_VERTICAL, BOUND_OUTER, aP2T, aRenderContext);
|
|
|
|
}
|
2006-05-17 02:37:48 +00:00
|
|
|
DrawLine(aX, aY+aHeight, aWidth, DIR_HORIZONTAL, BOUND_INNER, aP2T, aRenderContext);
|
2006-05-17 02:38:39 +00:00
|
|
|
if (aDrawEnd) {
|
|
|
|
DrawLine(aX+aWidth, aY, aHeight, DIR_VERTICAL, BOUND_INNER, aP2T, aRenderContext);
|
|
|
|
}
|
2006-05-17 02:21:49 +00:00
|
|
|
}
|
|
|
|
|
2006-05-17 02:37:48 +00:00
|
|
|
void
|
2006-05-17 02:37:47 +00:00
|
|
|
inFlasher::DrawLine(nscoord aX, nscoord aY, nscoord aLength,
|
2006-05-17 02:37:48 +00:00
|
|
|
PRBool aDir, PRBool aBounds, float aP2T,
|
|
|
|
nsIRenderingContext* aRenderContext)
|
2006-05-17 02:21:49 +00:00
|
|
|
{
|
2006-05-17 02:37:48 +00:00
|
|
|
nscoord thickTwips = NSIntPixelsToTwips(mThickness, aP2T);
|
2006-05-17 02:21:49 +00:00
|
|
|
if (aDir) { // horizontal
|
|
|
|
aRenderContext->FillRect(aX, aY+(aBounds?0:-thickTwips), aLength, thickTwips);
|
|
|
|
} else { // vertical
|
|
|
|
aRenderContext->FillRect(aX+(aBounds?0:-thickTwips), aY, thickTwips, aLength);
|
|
|
|
}
|
|
|
|
}
|