зеркало из https://github.com/mozilla/gecko-dev.git
(NOT PART OF BUILD) Document Inspector
This commit is contained in:
Родитель
58e0aa3e4b
Коммит
17e4fcf7b3
|
@ -0,0 +1,45 @@
|
|||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH=../../../..
|
||||
topsrcdir=@top_srcdir@
|
||||
srcdir=@srcdir@
|
||||
VPATH=@srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE=inspector
|
||||
XPIDL_MODULE=inspector
|
||||
|
||||
XPIDLSRCS = nsIDOMDSResource.idl \
|
||||
nsIInsDOMDataSource.idl \
|
||||
nsICSSRuleDataSource.idl \
|
||||
nsICSSDecDataSource.idl \
|
||||
nsICSSDecIntHolder.idl \
|
||||
inIFlasher.idl \
|
||||
inISearchProcess.idl \
|
||||
inISearchObserver.idl \
|
||||
inICSSValueSearch.idl \
|
||||
inIFileSearch.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "inISearchProcess.idl"
|
||||
|
||||
interface nsIDOMDocument;
|
||||
|
||||
[scriptable, uuid(e0d39e48-1dd1-11b2-81bd-9a0c117f0736)]
|
||||
interface inICSSValueSearch : inISearchProcess {
|
||||
|
||||
attribute nsIDOMDocument document;
|
||||
|
||||
// the base url for all returned URL results, if returnRelativeURLs is true
|
||||
attribute wstring baseURL;
|
||||
|
||||
// strip off the baseURL for all URL results if true
|
||||
attribute boolean returnRelativeURLs;
|
||||
|
||||
// correct the paths on a chrome url, such as turning global/skin/blah into global/blah
|
||||
attribute boolean normalizeChromeURLs;
|
||||
|
||||
// add a css property to search for
|
||||
void addPropertyCriteria(in wstring aPropName);
|
||||
|
||||
// set the text value to search for in the properties specified (optional)
|
||||
attribute wstring textCriteria;
|
||||
|
||||
};
|
|
@ -0,0 +1,50 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "inISearchProcess.idl"
|
||||
|
||||
interface nsIFile;
|
||||
interface nsISupportsArray;
|
||||
|
||||
[scriptable, uuid(EFA53257-526D-4350-9088-343A510346B8)]
|
||||
interface inIFileSearch : inISearchProcess {
|
||||
// the base url for all returned URL results, if returnRelativePaths is true
|
||||
attribute wstring basePath;
|
||||
|
||||
// strip off the basePath for all results through getStringResultAt if true
|
||||
attribute boolean returnRelativePaths;
|
||||
|
||||
unsigned long getDirectoryDepth(in nsIFile aDir);
|
||||
nsISupportsArray getSubDirectories(in nsIFile aDir);
|
||||
|
||||
// criteria
|
||||
attribute wstring filenameCriteria;
|
||||
attribute wstring textCriteria;
|
||||
attribute nsIFile searchPath;
|
||||
attribute boolean searchRecursive;
|
||||
|
||||
// results
|
||||
readonly attribute unsigned long directoriesSearched;
|
||||
readonly attribute nsIFile currentDirectory;
|
||||
|
||||
nsIFile getFileResultAt(in long aIndex);
|
||||
};
|
|
@ -0,0 +1,35 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIDOMDocument;
|
||||
interface nsIDOMElement;
|
||||
interface nsIDOMWindowInternal;
|
||||
|
||||
[scriptable, uuid(7B4A099F-6F6E-4565-977B-FB622ADBFF49)]
|
||||
interface inIFlasher : nsISupports
|
||||
{
|
||||
void drawElementOutline(in nsIDOMElement aElement, in nsIDOMWindowInternal aWindow, in wstring aColor, in long aThickness);
|
||||
void repaintElement(in nsIDOMElement aElement, in nsIDOMWindowInternal aWindow);
|
||||
};
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface inISearchProcess;
|
||||
|
||||
[scriptable, uuid(46226D9B-E398-4106-8D9B-225D4D0589F5)]
|
||||
interface inISearchObserver : nsISupports
|
||||
{
|
||||
// result codes which are sent to onSearchEnd
|
||||
const short SUCCESS = 1; // search completed successfully
|
||||
const short INTERRUPTED = 2; // search stopped due to user interruption
|
||||
const short ERROR = 3; // search stopped due to an error
|
||||
|
||||
void onSearchStart(in inISearchProcess aModule);
|
||||
void onSearchResult(in inISearchProcess aModule);
|
||||
void onSearchEnd(in inISearchProcess aModule, in short aResult);
|
||||
void onSearchError(in inISearchProcess aModule, in wstring aMessage);
|
||||
};
|
|
@ -0,0 +1,66 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface inISearchObserver;
|
||||
interface nsISupportsArray;
|
||||
|
||||
[scriptable, uuid(D5FA765B-2448-4686-B7C1-5FF13ACB0FC9)]
|
||||
interface inISearchProcess : nsISupports
|
||||
{
|
||||
// indicates if an asynchronous search is in progress
|
||||
readonly attribute boolean isActive;
|
||||
|
||||
// the number of results returned
|
||||
readonly attribute long resultCount;
|
||||
|
||||
// for optimization when doing an async search, this will optionally
|
||||
// destroy old results, assuming they will be fetched as soon as
|
||||
// the observer is notified of their presence. If true, then indices
|
||||
// pass to the get*ResultAt methods will return null for any index
|
||||
// other than the most recent one, and getResults will return null always.
|
||||
attribute boolean holdResults;
|
||||
|
||||
// start a synchronous search
|
||||
void searchSync();
|
||||
|
||||
// start an asynchronous search
|
||||
void searchAsync(in inISearchObserver aObserver);
|
||||
|
||||
// command an async process to stop immediately
|
||||
void searchStop();
|
||||
|
||||
// performs a step in the asynchronous search loop
|
||||
// return indicates true if loop is done, false if it should continue
|
||||
// This is there only for the benefit of asynchronous search controllers,
|
||||
// and is not for use by those who just wish to call searchAsync
|
||||
boolean searchStep();
|
||||
|
||||
// methods for getting results of specific types
|
||||
|
||||
wstring getStringResultAt(in long aIndex);
|
||||
|
||||
long getIntResultAt(in long aIndex);
|
||||
|
||||
unsigned long getUIntResultAt(in long aIndex);
|
||||
};
|
|
@ -0,0 +1,48 @@
|
|||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH=../../../..
|
||||
topsrcdir=@top_srcdir@
|
||||
srcdir=@srcdir@
|
||||
VPATH=@srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE=inspector
|
||||
LIBRARY_NAME=inspector_s
|
||||
SHORT_LIBNAME=inspector_s
|
||||
|
||||
CPPSRCS= \
|
||||
nsDOMDSResource.cpp \
|
||||
nsDOMDataSource.cpp \
|
||||
nsCSSRuleDataSource.cpp \
|
||||
nsCSSDecDataSource.cpp \
|
||||
nsCSSDecIntHolder.cpp \
|
||||
inFlasher.cpp \
|
||||
inSearchLoop.cpp \
|
||||
inCSSValueSearch.cpp \
|
||||
inFileSearch.cpp \
|
||||
$(NULL)
|
||||
|
||||
override NO_SHARED_LIB=1
|
||||
override NO_STATIC_LIB=
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,360 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "inCSSValueSearch.h"
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inCSSValueSearch::inCSSValueSearch()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
|
||||
mHoldResults = PR_TRUE;
|
||||
mReturnRelativeURLs = PR_FALSE;
|
||||
mNormalizeChromeURLs = PR_FALSE;
|
||||
mResultCount = 0;
|
||||
|
||||
mProperties = new nsCSSProperty[100];
|
||||
mPropertyCount = 0;
|
||||
nsCSSProps::AddRefTable();
|
||||
}
|
||||
|
||||
inCSSValueSearch::~inCSSValueSearch()
|
||||
{
|
||||
nsCSSProps::ReleaseTable();
|
||||
delete mProperties;
|
||||
delete mResults;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(inCSSValueSearch, inISearchProcess, inICSSValueSearch);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// inISearchProcess
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::GetIsActive(PRBool *aIsActive)
|
||||
{
|
||||
*aIsActive = mIsActive;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::GetResultCount(PRInt32 *aResultCount)
|
||||
{
|
||||
*aResultCount = mResultCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::GetHoldResults(PRBool *aHoldResults)
|
||||
{
|
||||
*aHoldResults = mHoldResults;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::SetHoldResults(PRBool aHoldResults)
|
||||
{
|
||||
mHoldResults = aHoldResults;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::SearchSync()
|
||||
{
|
||||
InitSearch();
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mDocument);
|
||||
if (doc) {
|
||||
PRInt32 count = doc->GetNumberOfStyleSheets();
|
||||
for (PRInt32 i = 0; i < count; i++) {
|
||||
nsIStyleSheet* sheet = doc->GetStyleSheetAt(i);
|
||||
SearchStyleSheet(sheet);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::SearchAsync(inISearchObserver *aObserver)
|
||||
{
|
||||
InitSearch();
|
||||
mObserver = aObserver;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::SearchStop()
|
||||
{
|
||||
KillSearch(inISearchObserver::INTERRUPTED);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::SearchStep(PRBool* _retval)
|
||||
{
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::GetStringResultAt(PRInt32 aIndex, PRUnichar **_retval)
|
||||
{
|
||||
if (mHoldResults) {
|
||||
nsAutoString* result = (nsAutoString*)mResults->ElementAt(aIndex);
|
||||
*_retval = result->ToNewUnicode();
|
||||
} else if (aIndex == mResultCount-1) {
|
||||
*_retval = mLastResult->ToNewUnicode();
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::GetIntResultAt(PRInt32 aIndex, PRInt32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::GetUIntResultAt(PRInt32 aIndex, PRUint32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// inICSSValueSearch
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::GetDocument(nsIDOMDocument** aDocument)
|
||||
{
|
||||
*aDocument = mDocument;
|
||||
NS_IF_ADDREF(*aDocument);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::SetDocument(nsIDOMDocument* aDocument)
|
||||
{
|
||||
mDocument = aDocument;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::GetBaseURL(PRUnichar** aBaseURL)
|
||||
{
|
||||
*aBaseURL = mBaseURL->ToNewUnicode();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::SetBaseURL(const PRUnichar* aBaseURL)
|
||||
{
|
||||
nsAutoString url;
|
||||
mBaseURL = &url;
|
||||
url.Assign(aBaseURL);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::GetReturnRelativeURLs(PRBool* aReturnRelativeURLs)
|
||||
{
|
||||
*aReturnRelativeURLs = mReturnRelativeURLs;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::SetReturnRelativeURLs(PRBool aReturnRelativeURLs)
|
||||
{
|
||||
mReturnRelativeURLs = aReturnRelativeURLs;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::GetNormalizeChromeURLs(PRBool *aNormalizeChromeURLs)
|
||||
{
|
||||
*aNormalizeChromeURLs = mNormalizeChromeURLs;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::SetNormalizeChromeURLs(PRBool aNormalizeChromeURLs)
|
||||
{
|
||||
mNormalizeChromeURLs = aNormalizeChromeURLs;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::AddPropertyCriteria(const PRUnichar *aPropName)
|
||||
{
|
||||
nsAutoString propName;
|
||||
propName.Assign(aPropName);
|
||||
nsCSSProperty prop = nsCSSProps::LookupProperty(propName);
|
||||
mProperties[mPropertyCount] = prop;
|
||||
mPropertyCount++;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::GetTextCriteria(PRUnichar** aTextCriteria)
|
||||
{
|
||||
*aTextCriteria = mTextCriteria->ToNewUnicode();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inCSSValueSearch::SetTextCriteria(const PRUnichar* aTextCriteria)
|
||||
{
|
||||
if (!mTextCriteria) mTextCriteria = new nsAutoString();
|
||||
mTextCriteria->Assign(aTextCriteria);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// inCSSValueSearch
|
||||
|
||||
nsresult
|
||||
inCSSValueSearch::InitSearch()
|
||||
{
|
||||
if (mHoldResults) {
|
||||
mResults = new nsVoidArray();
|
||||
}
|
||||
|
||||
mResultCount = 0;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
inCSSValueSearch::KillSearch(PRInt16 aResult)
|
||||
{
|
||||
mIsActive = PR_TRUE;
|
||||
mObserver->OnSearchEnd(this, aResult);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
inCSSValueSearch::SearchStyleSheet(nsIStyleSheet* aStyleSheet)
|
||||
{
|
||||
NS_IF_ADDREF(aStyleSheet);
|
||||
nsCOMPtr<nsICSSStyleSheet> cssSheet = do_QueryInterface(aStyleSheet);
|
||||
if (cssSheet) {
|
||||
// recurse downward through the stylesheet tree
|
||||
PRInt32 count;
|
||||
cssSheet->StyleSheetCount(count);
|
||||
for (PRInt32 i = 0; i < count; i++) {
|
||||
nsICSSStyleSheet* child;
|
||||
cssSheet->GetStyleSheetAt(i, child);
|
||||
SearchStyleSheet(child);
|
||||
}
|
||||
|
||||
cssSheet->StyleRuleCount(count);
|
||||
for (i = 0; i < count; i++) {
|
||||
nsICSSRule* rule;
|
||||
cssSheet->GetStyleRuleAt(i, rule);
|
||||
SearchStyleRule(rule);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(aStyleSheet);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
inCSSValueSearch::SearchStyleRule(nsIStyleRule* aStyleRule)
|
||||
{
|
||||
NS_IF_ADDREF(aStyleRule);
|
||||
|
||||
nsCOMPtr<nsICSSStyleRule> cssRule = do_QueryInterface(aStyleRule);
|
||||
if (cssRule) {
|
||||
nsCOMPtr<nsICSSDeclaration> aDec = cssRule->GetDeclaration();
|
||||
for (PRUint32 i = 0; i < mPropertyCount; i++) {
|
||||
nsCSSProperty prop = mProperties[i];
|
||||
SearchStyleValue(aDec, prop);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IF_RELEASE(aStyleRule);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
inCSSValueSearch::SearchStyleValue(nsICSSDeclaration* aDec, nsCSSProperty aProp)
|
||||
{
|
||||
nsCString cstring = nsCSSProps::GetStringValue(aProp);
|
||||
|
||||
nsCSSValue value;
|
||||
aDec->GetValue(aProp, value);
|
||||
|
||||
if (value.GetUnit() == eCSSUnit_URL) {
|
||||
nsAutoString* result = new nsAutoString();
|
||||
value.GetStringValue(*result);
|
||||
if (mReturnRelativeURLs)
|
||||
EqualizeURL(result);
|
||||
mResults->AppendElement((void*)result);
|
||||
mResultCount++;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
inCSSValueSearch::EqualizeURL(nsAutoString* aURL)
|
||||
{
|
||||
if (mNormalizeChromeURLs) {
|
||||
if (aURL->Find("chrome://", false, 0, 1) >= 0) {
|
||||
PRUint32 len = aURL->Length();
|
||||
char* result = new char[len-8];
|
||||
char* buffer = aURL->ToNewCString();
|
||||
PRUint32 i = 9;
|
||||
PRUint32 milestone = 0;
|
||||
PRUint32 s = 0;
|
||||
while (i < len) {
|
||||
if (buffer[i] == '/') {
|
||||
milestone += 1;
|
||||
}
|
||||
if (milestone == 0 || milestone > 1) {
|
||||
result[i-9-s] = (buffer[i] == '/') ? '/' : buffer[i];
|
||||
} else {
|
||||
s++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
result[i-9-s] = 0;
|
||||
|
||||
aURL->AssignWithConversion(result);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef __inCSSValueSearch_h__
|
||||
#define __inCSSValueSearch_h__
|
||||
|
||||
#include "inICSSValueSearch.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "inISearchObserver.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsICSSStyleSheet.h"
|
||||
#include "nsICSSStyleRule.h"
|
||||
#include "nsICSSDeclaration.h"
|
||||
#include "nsCSSValue.h"
|
||||
|
||||
class inCSSValueSearch : public inICSSValueSearch
|
||||
{
|
||||
public:
|
||||
inCSSValueSearch();
|
||||
~inCSSValueSearch();
|
||||
|
||||
protected:
|
||||
PRBool mIsActive;
|
||||
PRInt32 mResultCount;
|
||||
PRBool mHoldResults;
|
||||
nsVoidArray* mResults;
|
||||
nsAutoString* mLastResult;
|
||||
nsCOMPtr<inISearchObserver> mObserver;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> mDocument;
|
||||
nsAutoString* mBaseURL;
|
||||
PRBool mReturnRelativeURLs;
|
||||
PRBool mNormalizeChromeURLs;
|
||||
nsAutoString* mTextCriteria;
|
||||
nsCSSProperty* mProperties;
|
||||
PRUint32 mPropertyCount;
|
||||
|
||||
nsresult InitSearch();
|
||||
nsresult KillSearch(PRInt16 aResult);
|
||||
nsresult SearchStyleSheet(nsIStyleSheet* aStyleSheet);
|
||||
nsresult SearchStyleRule(nsIStyleRule* aStyleRule);
|
||||
nsresult SearchStyleValue(nsICSSDeclaration* aDec, nsCSSProperty aProp);
|
||||
nsresult EqualizeURL(nsAutoString* aURL);
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_INISEARCHPROCESS
|
||||
|
||||
NS_DECL_INICSSVALUESEARCH
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// {4D977F60-FBE7-4583-8CB7-F5ED882293EF}
|
||||
#define IN_CSSVALUESEARCH_CID \
|
||||
{ 0x4d977f60, 0xfbe7, 0x4583, { 0x8c, 0xb7, 0xf5, 0xed, 0x88, 0x22, 0x93, 0xef } }
|
||||
|
||||
#define IN_CSSVALUESEARCH_CONTRACTID \
|
||||
"@mozilla.org/inspector/search;1?type=cssvalue"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,638 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "inFileSearch.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inFileSearch::inFileSearch()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
|
||||
mSearchLoop = 0;
|
||||
}
|
||||
|
||||
inFileSearch::~inFileSearch()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(inFileSearch, inISearchProcess, inIFileSearch);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// inISearchProcess
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetIsActive(PRBool *aIsActive)
|
||||
{
|
||||
*aIsActive = mIsActive;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetResultCount(PRInt32 *aResultCount)
|
||||
{
|
||||
*aResultCount = mResultCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetHoldResults(PRBool *aHoldResults)
|
||||
{
|
||||
*aHoldResults = mHoldResults;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::SetHoldResults(PRBool aHoldResults)
|
||||
{
|
||||
mHoldResults = aHoldResults;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::SearchSync()
|
||||
{
|
||||
/* if (mSearchPath)
|
||||
SearchDirectory(mSearchPath, PR_TRUE);
|
||||
else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
*/
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::SearchAsync(inISearchObserver *aObserver)
|
||||
{
|
||||
mObserver = aObserver;
|
||||
mObserver->OnSearchStart(this);
|
||||
|
||||
InitSearch();
|
||||
InitSubDirectoryStack();
|
||||
InitSearchLoop();
|
||||
|
||||
if (mSearchPath) {
|
||||
// start off by searching the first directory
|
||||
SearchDirectory(mSearchPath, PR_FALSE);
|
||||
|
||||
if (mSearchRecursive) {
|
||||
// start the loop to continue searching
|
||||
mIsActive = PR_TRUE;
|
||||
mSearchLoop->Start();
|
||||
} else {
|
||||
KillSearch(inISearchObserver::SUCCESS);
|
||||
}
|
||||
} else {
|
||||
nsAutoString msg;
|
||||
msg.AssignWithConversion("No search path has been provided");
|
||||
mObserver->OnSearchError(this, msg.ToNewUnicode());
|
||||
KillSearch(inISearchObserver::ERROR);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::SearchStop()
|
||||
{
|
||||
KillSearch(inISearchObserver::INTERRUPTED);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::SearchStep(PRBool* _retval)
|
||||
{
|
||||
nsIFile* nextDir;
|
||||
PRBool more = GetNextSubDirectory(&nextDir);
|
||||
|
||||
if (more) {
|
||||
SearchDirectory(nextDir, PR_FALSE);
|
||||
} else {
|
||||
KillSearch(inISearchObserver::SUCCESS);
|
||||
*_retval = PR_TRUE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetStringResultAt(PRInt32 aIndex, PRUnichar **_retval)
|
||||
{
|
||||
nsCOMPtr<nsIFile> file;
|
||||
|
||||
if (mHoldResults) {
|
||||
nsCOMPtr<nsISupports> supports;
|
||||
mResults->GetElementAt(aIndex, getter_AddRefs(supports));
|
||||
file = do_QueryInterface(supports);
|
||||
} else if (aIndex == mResultCount-1 && mLastResult) {
|
||||
// get the path of the last result as an nsAutoString
|
||||
file = mLastResult;
|
||||
}
|
||||
|
||||
if (file) {
|
||||
char* temp;
|
||||
mLastResult->GetPath(&temp);
|
||||
nsAutoString path;
|
||||
path.AssignWithConversion(temp);
|
||||
if (mReturnRelativePaths)
|
||||
MakePathRelative(&path);
|
||||
*_retval = path.ToNewUnicode();
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetIntResultAt(PRInt32 aIndex, PRInt32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetUIntResultAt(PRInt32 aIndex, PRUint32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// inIFileSearch
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetBasePath(PRUnichar** aBasePath)
|
||||
{
|
||||
if (mBasePath) {
|
||||
*aBasePath = mBasePath->ToNewUnicode();
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::SetBasePath(const PRUnichar* aBasePath)
|
||||
{
|
||||
mBasePath = new nsAutoString();
|
||||
mBasePath->Assign(aBasePath);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetReturnRelativePaths(PRBool* aReturnRelativePaths)
|
||||
{
|
||||
*aReturnRelativePaths = mReturnRelativePaths;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::SetReturnRelativePaths(PRBool aReturnRelativePaths)
|
||||
{
|
||||
mReturnRelativePaths = aReturnRelativePaths;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetFilenameCriteria(PRUnichar** aFilenameCriteria)
|
||||
{
|
||||
// TODO: reconstruct parsed filename criteria into string
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::SetFilenameCriteria(const PRUnichar* aFilenameCriteria)
|
||||
{
|
||||
// first pass: scan for commas so we know how long to make array
|
||||
PRUint32 idx = 0;
|
||||
PRUint32 commas = 0;
|
||||
const PRUnichar* c = aFilenameCriteria;
|
||||
while (*c) {
|
||||
if (*c == ',')
|
||||
++commas;
|
||||
++c;
|
||||
}
|
||||
|
||||
mFilenameCriteria = new PRUnichar*[commas+1];
|
||||
mFilenameCriteriaCount = 0;
|
||||
|
||||
// second pass: split up at commas and insert into array
|
||||
idx = 0;
|
||||
PRUint32 lastComma = -1;
|
||||
PRUnichar* buf = new PRUnichar[257];
|
||||
c = aFilenameCriteria;
|
||||
PRBool going = PR_TRUE;
|
||||
while (going) {
|
||||
if (*c == ',' || !*c) {
|
||||
buf[idx-lastComma-1] = 0;
|
||||
lastComma = idx;
|
||||
mFilenameCriteria[mFilenameCriteriaCount] = buf;
|
||||
++mFilenameCriteriaCount;
|
||||
buf = new PRUnichar[257];
|
||||
if (!*c) going = PR_FALSE;
|
||||
} else {
|
||||
buf[idx-lastComma-1] = *c;
|
||||
}
|
||||
++c;
|
||||
++idx;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetTextCriteria(PRUnichar** aTextCriteria)
|
||||
{
|
||||
*aTextCriteria = mTextCriteria->ToNewUnicode();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::SetTextCriteria(const PRUnichar* aTextCriteria)
|
||||
{
|
||||
mTextCriteria = new nsAutoString();
|
||||
mTextCriteria->Assign(aTextCriteria);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetSearchPath(nsIFile** aSearchPath)
|
||||
{
|
||||
*aSearchPath = mSearchPath;
|
||||
NS_IF_ADDREF(*aSearchPath);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::SetSearchPath(nsIFile* aSearchPath)
|
||||
{
|
||||
mSearchPath = aSearchPath;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetSearchRecursive(PRBool* aSearchRecursive)
|
||||
{
|
||||
*aSearchRecursive = mSearchRecursive;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::SetSearchRecursive(PRBool aSearchRecursive)
|
||||
{
|
||||
mSearchRecursive = aSearchRecursive;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetDirectoriesSearched(PRUint32* aDirectoriesSearched)
|
||||
{
|
||||
*aDirectoriesSearched = mDirsSearched;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetCurrentDirectory(nsIFile** aCurrentDirectory)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetFileResultAt(PRInt32 aIndex, nsIFile** _retval)
|
||||
{
|
||||
if (mHoldResults && mResults) {
|
||||
nsCOMPtr<nsISupports> supports;
|
||||
mResults->GetElementAt(aIndex, getter_AddRefs(supports));
|
||||
nsCOMPtr<nsIFile> file = do_QueryInterface(supports);
|
||||
*_retval = file;
|
||||
} else if (aIndex == mResultCount-1 && mLastResult) {
|
||||
*_retval = mLastResult;
|
||||
NS_IF_ADDREF(*_retval);
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetDirectoryDepth(nsIFile* aDir, PRUint32* _retval)
|
||||
{
|
||||
*_retval = 0;
|
||||
return CountDirectoryDepth(aDir, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFileSearch::GetSubDirectories(nsIFile* aDir, nsISupportsArray** _retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// inFileSearch
|
||||
|
||||
nsresult
|
||||
inFileSearch::InitSearch()
|
||||
{
|
||||
if (mHoldResults) {
|
||||
mResults = do_CreateInstance("@mozilla.org/supports-array;1");
|
||||
} else {
|
||||
mResults = nsnull;
|
||||
}
|
||||
|
||||
mLastResult = nsnull;
|
||||
mResultCount = 0;
|
||||
mDirsSearched = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
inFileSearch::KillSearch(PRInt16 aResult)
|
||||
{
|
||||
mIsActive = PR_TRUE;
|
||||
mObserver->OnSearchEnd(this, aResult);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
inFileSearch::SearchDirectory(nsIFile* aDir, PRBool aIsSync)
|
||||
{
|
||||
++mDirsSearched;
|
||||
|
||||
// recurse through subdirectories
|
||||
nsISimpleEnumerator* entries;
|
||||
aDir->GetDirectoryEntries(&entries);
|
||||
|
||||
if (!aIsSync) {
|
||||
// store this directory for next step in async search
|
||||
PushSubDirectoryOnStack(aDir);
|
||||
}
|
||||
|
||||
PRBool hasMoreElements;
|
||||
PRBool isDirectory;
|
||||
nsCOMPtr<nsIFile> entry;
|
||||
|
||||
entries->HasMoreElements(&hasMoreElements);
|
||||
while (hasMoreElements) {
|
||||
entries->GetNext(getter_AddRefs(entry));
|
||||
entries->HasMoreElements(&hasMoreElements);
|
||||
|
||||
entry->IsDirectory(&isDirectory);
|
||||
if (isDirectory && aIsSync) {
|
||||
// this is a directory, so search it now (only if synchronous)
|
||||
if (aIsSync)
|
||||
SearchDirectory(entry, aIsSync);
|
||||
} else {
|
||||
// this is a file, so see if it matches
|
||||
if (MatchFile(entry)) {
|
||||
PrepareResult(entry, aIsSync);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
inFileSearch::PrepareResult(nsIFile* aFile, PRBool aIsSync)
|
||||
{
|
||||
if (aIsSync || mHoldResults) {
|
||||
mResults->AppendElement(aFile);
|
||||
}
|
||||
|
||||
if (!aIsSync) {
|
||||
++mResultCount;
|
||||
mLastResult = aFile;
|
||||
mObserver->OnSearchResult(this);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
inFileSearch::InitSearchLoop()
|
||||
{
|
||||
if (!mSearchLoop) {
|
||||
nsCOMPtr<inISearchProcess> process = do_QueryInterface(this);
|
||||
mSearchLoop = new inSearchLoop(process);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Subdirectory stack (for asynchronous searches)
|
||||
|
||||
nsresult
|
||||
inFileSearch::InitSubDirectoryStack()
|
||||
{
|
||||
mDirStack = do_CreateInstance("@mozilla.org/supports-array;1");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool
|
||||
inFileSearch::GetNextSubDirectory(nsIFile** aDir)
|
||||
{
|
||||
// get the enumerator on top of the stack
|
||||
nsCOMPtr<nsISupports> supports;
|
||||
nsCOMPtr<nsISimpleEnumerator> nextDirs;
|
||||
PRUint32 count;
|
||||
|
||||
while (true) {
|
||||
mDirStack->Count(&count);
|
||||
// the stack is empty, so our search must be complete
|
||||
if (count == 0) return PR_FALSE;
|
||||
|
||||
// get the next directory enumerator on the stack
|
||||
mDirStack->GetElementAt(count-1, getter_AddRefs(supports));
|
||||
nextDirs = do_QueryInterface(supports);
|
||||
|
||||
// get the next directory from the enumerator
|
||||
nsIFile* dir = GetNextDirectory(nextDirs);
|
||||
|
||||
if (dir) {
|
||||
// this enumerator is ready to rock, so let's move on
|
||||
*aDir = dir;
|
||||
return PR_TRUE;
|
||||
} else {
|
||||
// enumerator is done, so pop it off the stack
|
||||
mDirStack->RemoveElement(supports);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
inFileSearch::PushSubDirectoryOnStack(nsIFile* aDir)
|
||||
{
|
||||
nsISimpleEnumerator* entries;
|
||||
aDir->GetDirectoryEntries(&entries);
|
||||
mDirStack->AppendElement(entries);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIFile*
|
||||
inFileSearch::GetNextDirectory(nsISimpleEnumerator* aEnum)
|
||||
{
|
||||
nsCOMPtr<nsIFile> file;
|
||||
nsCOMPtr<nsISupports> supports;
|
||||
PRBool isDir;
|
||||
PRBool hasMoreElements;
|
||||
|
||||
while (true) {
|
||||
aEnum->HasMoreElements(&hasMoreElements);
|
||||
if (!hasMoreElements)
|
||||
break;
|
||||
aEnum->GetNext(getter_AddRefs(supports));
|
||||
file = do_QueryInterface(supports);
|
||||
file->IsDirectory(&isDir);
|
||||
if (isDir)
|
||||
break;
|
||||
}
|
||||
|
||||
nsIFile* f = file.get();
|
||||
NS_IF_ADDREF(f);
|
||||
|
||||
return isDir ? f : nsnull;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Pattern Matching
|
||||
|
||||
PRBool
|
||||
inFileSearch::MatchFile(nsIFile* aFile)
|
||||
{
|
||||
char* fileName;
|
||||
aFile->GetLeafName(&fileName);
|
||||
|
||||
nsAutoString temp;
|
||||
temp.AssignWithConversion(fileName);
|
||||
|
||||
PRUnichar* fileNameUnicode = temp.ToNewUnicode();
|
||||
|
||||
PRBool match;
|
||||
|
||||
for (PRUint32 i = 0; i < mFilenameCriteriaCount; ++i) {
|
||||
match = MatchPattern(mFilenameCriteria[i], fileNameUnicode);
|
||||
if (match) return PR_TRUE;
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
inFileSearch::MatchPattern(PRUnichar* aPattern, PRUnichar* aString)
|
||||
{
|
||||
PRInt32 index = 0;
|
||||
PRBool matching = true;
|
||||
char wildcard = '*';
|
||||
|
||||
PRUnichar* patternPtr = aPattern;
|
||||
PRUnichar* stringPtr = aString;
|
||||
|
||||
while (matching && *patternPtr && *stringPtr) {
|
||||
if (*patternPtr == wildcard) {
|
||||
matching = AdvanceWildcard(&stringPtr, patternPtr+1);
|
||||
} else {
|
||||
matching = *patternPtr == *stringPtr;
|
||||
++stringPtr;
|
||||
}
|
||||
if (!matching) return false;
|
||||
++patternPtr;
|
||||
++index;
|
||||
}
|
||||
|
||||
return matching;
|
||||
}
|
||||
|
||||
PRBool
|
||||
inFileSearch::AdvanceWildcard(PRUnichar** aString, PRUnichar* aNextChar)
|
||||
{
|
||||
PRUnichar* stringPtr = *aString;
|
||||
|
||||
while (1) {
|
||||
if (*stringPtr == *aNextChar) {
|
||||
// we have found the next char after the wildcard, so return with success
|
||||
*aString = stringPtr;
|
||||
return true;
|
||||
} else if (*stringPtr == 0)
|
||||
return false;
|
||||
++stringPtr;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// URL fixing
|
||||
|
||||
nsresult
|
||||
inFileSearch::MakePathRelative(nsAutoString* aPath)
|
||||
{
|
||||
nsAutoString result;
|
||||
|
||||
// get an nsAutoString version of the search path
|
||||
char* temp;
|
||||
mSearchPath->GetPath(&temp);
|
||||
nsAutoString searchPath;
|
||||
searchPath.AssignWithConversion(temp);
|
||||
|
||||
PRInt32 found = aPath->Find(searchPath, false, 0, 1);
|
||||
if (found == 0) {
|
||||
PRUint32 len = searchPath.Length();
|
||||
aPath->Mid(result, len+1, aPath->Length()-len);
|
||||
result.ReplaceChar('\\', '/');
|
||||
}
|
||||
aPath->Assign(result);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
inFileSearch::CountDirectoryDepth(nsIFile* aDir, PRUint32* aDepth)
|
||||
{
|
||||
++(*aDepth);
|
||||
|
||||
nsISimpleEnumerator* entries;
|
||||
aDir->GetDirectoryEntries(&entries);
|
||||
|
||||
PRBool hasMoreElements;
|
||||
PRBool isDirectory;
|
||||
nsCOMPtr<nsIFile> entry;
|
||||
|
||||
entries->HasMoreElements(&hasMoreElements);
|
||||
while (hasMoreElements) {
|
||||
entries->GetNext(getter_AddRefs(entry));
|
||||
entries->HasMoreElements(&hasMoreElements);
|
||||
|
||||
entry->IsDirectory(&isDirectory);
|
||||
if (isDirectory) {
|
||||
CountDirectoryDepth(entry, aDepth);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef __inFileSearch_h__
|
||||
#define __inFileSearch_h__
|
||||
|
||||
#include "inIFileSearch.h"
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "inISearchObserver.h"
|
||||
#include "nsIFile.h"
|
||||
#include "inSearchLoop.h"
|
||||
|
||||
class inFileSearch : public inIFileSearch
|
||||
{
|
||||
public:
|
||||
inFileSearch();
|
||||
~inFileSearch();
|
||||
|
||||
protected:
|
||||
// inISearchProcess related
|
||||
PRBool mIsActive;
|
||||
PRInt32 mResultCount;
|
||||
nsIFile* mLastResult;
|
||||
nsCOMPtr<nsISupportsArray> mResults;
|
||||
PRBool mHoldResults;
|
||||
nsAutoString* mBasePath;
|
||||
PRBool mReturnRelativePaths;
|
||||
nsCOMPtr<inISearchObserver> mObserver;
|
||||
|
||||
// inIFileSearch related
|
||||
nsCOMPtr<nsIFile> mSearchPath;
|
||||
nsAutoString* mTextCriteria;
|
||||
PRUnichar** mFilenameCriteria;
|
||||
PRUint32 mFilenameCriteriaCount;
|
||||
PRBool mSearchRecursive;
|
||||
PRUint32 mDirsSearched;
|
||||
|
||||
// asynchronous search related
|
||||
nsCOMPtr<nsISupportsArray> mDirStack;
|
||||
inSearchLoop* mSearchLoop;
|
||||
|
||||
// life cycle of search
|
||||
nsresult InitSearch();
|
||||
nsresult KillSearch(PRInt16 aResult);
|
||||
nsresult SearchDirectory(nsIFile* aDir, PRBool aIsSync);
|
||||
nsresult PrepareResult(nsIFile* aFile, PRBool aIsSync);
|
||||
|
||||
// asynchronous search helpers
|
||||
nsresult InitSearchLoop();
|
||||
nsresult InitSubDirectoryStack();
|
||||
PRBool GetNextSubDirectory(nsIFile** aDir);
|
||||
nsresult PushSubDirectoryOnStack(nsIFile* aDir);
|
||||
nsIFile* GetNextDirectory(nsISimpleEnumerator* aEnum);
|
||||
|
||||
// pattern matching
|
||||
PRBool MatchFile(nsIFile* aFile);
|
||||
static PRBool MatchPattern(PRUnichar* aPattern, PRUnichar* aString);
|
||||
static PRBool AdvanceWildcard(PRUnichar** aString, PRUnichar* aNextChar);
|
||||
|
||||
// misc
|
||||
nsresult MakePathRelative(nsAutoString* aPath);
|
||||
nsresult CountDirectoryDepth(nsIFile* aDir, PRUint32* aDepth);
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_INISEARCHPROCESS
|
||||
|
||||
NS_DECL_INIFILESEARCH
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// {D5636476-9F94-47f2-9CE9-69CDD9D7BBCD}
|
||||
#define IN_FILESEARCH_CID \
|
||||
{ 0xd5636476, 0x9f94, 0x47f2, { 0x9c, 0xe9, 0x69, 0xcd, 0xd9, 0xd7, 0xbb, 0xcd } }
|
||||
|
||||
#define IN_FILESEARCH_CONTRACTID \
|
||||
"@mozilla.org/inspector/search;1?type=file"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,182 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "inFlasher.h"
|
||||
#include "dsinfo.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIRenderingContext.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIView.h"
|
||||
#include "nsIViewManager.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inFlasher::inFlasher()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
inFlasher::~inFlasher()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(inFlasher, inIFlasher);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// inIFlasher
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFlasher::RepaintElement(nsIDOMElement* aElement, nsIDOMWindowInternal* aWindow)
|
||||
{
|
||||
nsIPresShell* presShell = GetPresShellFor(aWindow);
|
||||
nsIFrame* frame = GetFrameFor(aElement, presShell);
|
||||
if (!frame) return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIPresContext> pcontext;
|
||||
presShell->GetPresContext(getter_AddRefs(pcontext));
|
||||
|
||||
nsIFrame* parentWithView;
|
||||
frame->GetParentWithView(pcontext, &parentWithView);
|
||||
if (parentWithView) {
|
||||
nsIView* view;
|
||||
parentWithView->GetView(pcontext, &view);
|
||||
if (view) {
|
||||
nsIViewManager* viewManager;
|
||||
view->GetViewManager(viewManager);
|
||||
|
||||
nsRect rect;
|
||||
parentWithView->GetRect(rect);
|
||||
|
||||
viewManager->UpdateView(view, rect, NS_VMREFRESH_NO_SYNC);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFlasher::DrawElementOutline(nsIDOMElement* aElement, nsIDOMWindowInternal* aWindow, const PRUnichar* aColor, PRInt32 aThickness)
|
||||
{
|
||||
nsIPresShell* presShell = GetPresShellFor(aWindow);
|
||||
nsIFrame* frame = GetFrameFor(aElement, presShell);
|
||||
if (!frame) return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIPresContext> pcontext;
|
||||
presShell->GetPresContext(getter_AddRefs(pcontext));
|
||||
nsCOMPtr<nsIRenderingContext> rcontext;
|
||||
presShell->CreateRenderingContext(frame, getter_AddRefs(rcontext));
|
||||
|
||||
nsAutoString colorStr;
|
||||
colorStr.Assign(aColor);
|
||||
nscolor color;
|
||||
PRBool rv = NS_HexToRGB(colorStr, &color);
|
||||
|
||||
nsRect rect;
|
||||
frame->GetRect(rect);
|
||||
nsPoint origin(0,0);
|
||||
GetClientOrigin(frame, origin);
|
||||
|
||||
float p2t;
|
||||
pcontext->GetPixelsToTwips(&p2t);
|
||||
|
||||
DrawOutline(origin.x, origin.y, rect.width, rect.height, color, aThickness, p2t, rcontext);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// inFlasher
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFlasher::DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, nscolor aColor,
|
||||
PRUint32 aThickness, float aP2T, nsIRenderingContext* aRenderContext)
|
||||
{
|
||||
aRenderContext->SetColor(aColor);
|
||||
DrawLine(aX, aY, aWidth, aThickness, DIR_HORIZONTAL, BOUND_OUTER, aP2T, aRenderContext);
|
||||
DrawLine(aX, aY, aHeight, aThickness, DIR_VERTICAL, BOUND_OUTER, aP2T, aRenderContext);
|
||||
DrawLine(aX, aY+aHeight, aWidth, aThickness, DIR_HORIZONTAL, BOUND_INNER, aP2T, aRenderContext);
|
||||
DrawLine(aX+aWidth, aY, aHeight, aThickness, DIR_VERTICAL, BOUND_INNER, aP2T, aRenderContext);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFlasher::DrawLine(nscoord aX, nscoord aY, nscoord aLength, PRUint32 aThickness,
|
||||
PRBool aDir, PRBool aBounds, float aP2T, nsIRenderingContext* aRenderContext)
|
||||
{
|
||||
nscoord thickTwips = NSIntPixelsToTwips(aThickness, aP2T);
|
||||
if (aDir) { // horizontal
|
||||
aRenderContext->FillRect(aX, aY+(aBounds?0:-thickTwips), aLength, thickTwips);
|
||||
} else { // vertical
|
||||
aRenderContext->FillRect(aX+(aBounds?0:-thickTwips), aY, thickTwips, aLength);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inFlasher::GetClientOrigin(nsIFrame* aFrame, nsPoint& aPoint)
|
||||
{
|
||||
nsIFrame* parent = aFrame;
|
||||
while (parent) {
|
||||
nsPoint origin;
|
||||
parent->GetOrigin(origin);
|
||||
aPoint.x += origin.x;
|
||||
aPoint.y += origin.y;
|
||||
parent->GetParent(&parent);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIFrame*
|
||||
inFlasher::GetFrameFor(nsIDOMElement* aElement, nsIPresShell* aShell)
|
||||
{
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
|
||||
nsIFrame* frame;
|
||||
aShell->GetPrimaryFrameFor(content, &frame);
|
||||
return frame;
|
||||
}
|
||||
|
||||
nsIPresShell*
|
||||
inFlasher::GetPresShellFor(nsISupports* aThing)
|
||||
{
|
||||
nsCOMPtr<nsIScriptGlobalObject> so = do_QueryInterface(aThing);
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
so->GetDocShell(getter_AddRefs(docShell));
|
||||
|
||||
nsIPresShell* presShell;
|
||||
docShell->GetPresShell(&presShell);
|
||||
|
||||
return presShell;
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef __inFlasher_h__
|
||||
#define __inFlasher_h__
|
||||
|
||||
#include "inIFlasher.h"
|
||||
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsIRenderingContext.h"
|
||||
|
||||
#define BOUND_INNER 0
|
||||
#define BOUND_OUTER 1
|
||||
|
||||
#define DIR_VERTICAL 0
|
||||
#define DIR_HORIZONTAL 1
|
||||
|
||||
class inFlasher : public inIFlasher
|
||||
{
|
||||
public:
|
||||
inFlasher();
|
||||
~inFlasher();
|
||||
|
||||
protected:
|
||||
nsIFrame* GetFrameFor(nsIDOMElement* aElement, nsIPresShell* aShell);
|
||||
nsIPresShell* GetPresShellFor(nsISupports* aThing);
|
||||
|
||||
NS_IMETHOD DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, nscolor aColor,
|
||||
PRUint32 aThickness, float aP2T, nsIRenderingContext* aRenderContext);
|
||||
NS_IMETHOD DrawLine(nscoord aX, nscoord aY, nscoord aLength, PRUint32 aThickness,
|
||||
PRBool aDir, PRBool aBounds, float aP2T, nsIRenderingContext* aRenderContext);
|
||||
NS_IMETHOD GetClientOrigin(nsIFrame* aFrame, nsPoint& aPoint);
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_INIFLASHER
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// {9286E71A-621A-4b91-851E-9984C1A2E81A}
|
||||
#define IN_FLASHER_CID \
|
||||
{ 0x9286e71a, 0x621a, 0x4b91, { 0x85, 0x1e, 0x99, 0x84, 0xc1, 0xa2, 0xe8, 0x1a } }
|
||||
|
||||
#define IN_FLASHER_CONTRACTID \
|
||||
"@mozilla.org/inspector/flasher;1"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,76 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "inSearchLoop.h"
|
||||
|
||||
#include "nsITimer.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inSearchLoop::inSearchLoop(inISearchProcess* aSearchProcess)
|
||||
{
|
||||
mSearchProcess = aSearchProcess;
|
||||
nsresult rv;
|
||||
mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
|
||||
}
|
||||
|
||||
inSearchLoop::~inSearchLoop()
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// inSearchLoop
|
||||
|
||||
nsresult
|
||||
inSearchLoop::Start()
|
||||
{
|
||||
mTimer->Init(inSearchLoop::TimerCallback, (void*)this, 0, NS_PRIORITY_NORMAL, NS_TYPE_REPEATING_SLACK);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
inSearchLoop::Step()
|
||||
{
|
||||
PRBool done = PR_FALSE;
|
||||
mSearchProcess->SearchStep(&done);
|
||||
|
||||
if (done)
|
||||
Stop();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
inSearchLoop::Stop()
|
||||
{
|
||||
mTimer->Cancel();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
inSearchLoop::TimerCallback(nsITimer *aTimer, void *aClosure)
|
||||
{
|
||||
inSearchLoop* loop = (inSearchLoop*) aClosure;
|
||||
loop->Step();
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef __inSearchLoop_h__
|
||||
#define __inSearchLoop_h__
|
||||
|
||||
#include "nsITimer.h"
|
||||
#include "inISearchProcess.h"
|
||||
|
||||
class inSearchLoop
|
||||
{
|
||||
public:
|
||||
inSearchLoop(inISearchProcess* aSearchProcess);
|
||||
~inSearchLoop();
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsITimer> mTimer;
|
||||
nsCOMPtr<inISearchProcess> mSearchProcess;
|
||||
|
||||
public:
|
||||
nsresult Start();
|
||||
nsresult Step();
|
||||
nsresult Stop();
|
||||
static void TimerCallback(nsITimer *aTimer, void *aClosure);
|
||||
};
|
||||
|
||||
#endif
|
Загрузка…
Ссылка в новой задаче