From ccf8865c32d9cdf5bdd15943d6ee6103db4968bf Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Mon, 29 Nov 2021 18:49:29 -0500 Subject: Issue %3005 - Merge embedding/components/find with components/find --- components/find/moz.build | 10 +- components/find/nsFindService.cpp | 101 -- components/find/nsFindService.h | 46 - components/find/nsIFindService.idl | 26 - components/find/public/nsFind.cpp | 1388 ++++++++++++++++++++++++++ components/find/public/nsFind.h | 82 ++ components/find/public/nsIFind.idl | 34 + components/find/public/nsIFindService.idl | 26 + components/find/public/nsIWebBrowserFind.idl | 145 +++ components/find/public/nsWebBrowserFind.cpp | 867 ++++++++++++++++ components/find/public/nsWebBrowserFind.h | 94 ++ components/find/src/nsFindService.cpp | 101 ++ components/find/src/nsFindService.h | 46 + 13 files changed, 2790 insertions(+), 176 deletions(-) delete mode 100644 components/find/nsFindService.cpp delete mode 100644 components/find/nsFindService.h delete mode 100644 components/find/nsIFindService.idl create mode 100644 components/find/public/nsFind.cpp create mode 100644 components/find/public/nsFind.h create mode 100644 components/find/public/nsIFind.idl create mode 100644 components/find/public/nsIFindService.idl create mode 100644 components/find/public/nsIWebBrowserFind.idl create mode 100644 components/find/public/nsWebBrowserFind.cpp create mode 100644 components/find/public/nsWebBrowserFind.h create mode 100644 components/find/src/nsFindService.cpp create mode 100644 components/find/src/nsFindService.h (limited to 'components') diff --git a/components/find/moz.build b/components/find/moz.build index de83e39c3..7c43d8f52 100644 --- a/components/find/moz.build +++ b/components/find/moz.build @@ -4,13 +4,17 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. XPIDL_SOURCES += [ - 'nsIFindService.idl', + 'public/nsIFindService.idl', + 'public/nsIFind.idl', + 'public/nsIWebBrowserFind.idl', ] -XPIDL_MODULE = 'mozfind' SOURCES += [ - 'nsFindService.cpp', + 'src/nsFindService.cpp', + 'src/nsFind.cpp', + 'src/nsWebBrowserFind.cpp', ] +XPIDL_MODULE = 'mozfind' FINAL_LIBRARY = 'xul' diff --git a/components/find/nsFindService.cpp b/components/find/nsFindService.cpp deleted file mode 100644 index 3e80823ce..000000000 --- a/components/find/nsFindService.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* 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/. */ - -/* - * The sole purpose of the Find service is to store globally the - * last used Find settings - * - */ - - -#include "nsFindService.h" - - -nsFindService::nsFindService() -: mFindBackwards(false) -, mWrapFind(true) -, mEntireWord(false) -, mMatchCase(false) -{ -} - - -nsFindService::~nsFindService() -{ -} - -NS_IMPL_ISUPPORTS(nsFindService, nsIFindService) - -NS_IMETHODIMP nsFindService::GetSearchString(nsAString & aSearchString) -{ - aSearchString = mSearchString; - return NS_OK; -} - -NS_IMETHODIMP nsFindService::SetSearchString(const nsAString & aSearchString) -{ - mSearchString = aSearchString; - return NS_OK; -} - -NS_IMETHODIMP nsFindService::GetReplaceString(nsAString & aReplaceString) -{ - aReplaceString = mReplaceString; - return NS_OK; -} -NS_IMETHODIMP nsFindService::SetReplaceString(const nsAString & aReplaceString) -{ - mReplaceString = aReplaceString; - return NS_OK; -} - -NS_IMETHODIMP nsFindService::GetFindBackwards(bool *aFindBackwards) -{ - NS_ENSURE_ARG_POINTER(aFindBackwards); - *aFindBackwards = mFindBackwards; - return NS_OK; -} -NS_IMETHODIMP nsFindService::SetFindBackwards(bool aFindBackwards) -{ - mFindBackwards = aFindBackwards; - return NS_OK; -} - -NS_IMETHODIMP nsFindService::GetWrapFind(bool *aWrapFind) -{ - NS_ENSURE_ARG_POINTER(aWrapFind); - *aWrapFind = mWrapFind; - return NS_OK; -} -NS_IMETHODIMP nsFindService::SetWrapFind(bool aWrapFind) -{ - mWrapFind = aWrapFind; - return NS_OK; -} - -NS_IMETHODIMP nsFindService::GetEntireWord(bool *aEntireWord) -{ - NS_ENSURE_ARG_POINTER(aEntireWord); - *aEntireWord = mEntireWord; - return NS_OK; -} -NS_IMETHODIMP nsFindService::SetEntireWord(bool aEntireWord) -{ - mEntireWord = aEntireWord; - return NS_OK; -} - -NS_IMETHODIMP nsFindService::GetMatchCase(bool *aMatchCase) -{ - NS_ENSURE_ARG_POINTER(aMatchCase); - *aMatchCase = mMatchCase; - return NS_OK; -} -NS_IMETHODIMP nsFindService::SetMatchCase(bool aMatchCase) -{ - mMatchCase = aMatchCase; - return NS_OK; -} - diff --git a/components/find/nsFindService.h b/components/find/nsFindService.h deleted file mode 100644 index 6b391d5bf..000000000 --- a/components/find/nsFindService.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* 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/. */ - -/* - * The sole purpose of the Find service is to store globally the - * last used Find settings - * - */ - -#include "nsString.h" - -#include "nsIFindService.h" - - -// {5060b803-340e-11d5-be5b-b3e063ec6a3c} -#define NS_FIND_SERVICE_CID \ - {0x5060b803, 0x340e, 0x11d5, {0xbe, 0x5b, 0xb3, 0xe0, 0x63, 0xec, 0x6a, 0x3c}} - - -#define NS_FIND_SERVICE_CONTRACTID \ - "@mozilla.org/find/find_service;1" - - -class nsFindService : public nsIFindService -{ -public: - - nsFindService(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIFINDSERVICE - -protected: - - virtual ~nsFindService(); - - nsString mSearchString; - nsString mReplaceString; - - bool mFindBackwards; - bool mWrapFind; - bool mEntireWord; - bool mMatchCase; -}; diff --git a/components/find/nsIFindService.idl b/components/find/nsIFindService.idl deleted file mode 100644 index c5fb96f76..000000000 --- a/components/find/nsIFindService.idl +++ /dev/null @@ -1,26 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* 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" - -[scriptable, uuid(5060b801-340e-11d5-be5b-b3e063ec6a3c)] -interface nsIFindService : nsISupports -{ - - /* - * The sole purpose of the Find service is to store globally the - * last used Find settings - * - */ - - attribute AString searchString; - attribute AString replaceString; - - attribute boolean findBackwards; - attribute boolean wrapFind; - attribute boolean entireWord; - attribute boolean matchCase; - -}; diff --git a/components/find/public/nsFind.cpp b/components/find/public/nsFind.cpp new file mode 100644 index 000000000..82a928f49 --- /dev/null +++ b/components/find/public/nsFind.cpp @@ -0,0 +1,1388 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +//#define DEBUG_FIND 1 + +#include "nsFind.h" +#include "nsContentCID.h" +#include "nsIContent.h" +#include "nsIDOMNode.h" +#include "nsIDOMNodeList.h" +#include "nsISelection.h" +#include "nsISelectionController.h" +#include "nsIFrame.h" +#include "nsITextControlFrame.h" +#include "nsIFormControl.h" +#include "nsIEditor.h" +#include "nsIPlaintextEditor.h" +#include "nsTextFragment.h" +#include "nsString.h" +#include "nsIAtom.h" +#include "nsServiceManagerUtils.h" +#include "nsUnicharUtils.h" +#include "nsIDOMElement.h" +#include "nsIWordBreaker.h" +#include "nsCRT.h" +#include "nsRange.h" +#include "nsContentUtils.h" +#include "mozilla/DebugOnly.h" + +using namespace mozilla; + +// Yikes! Casting a char to unichar can fill with ones! +#define CHAR_TO_UNICHAR(c) ((char16_t)(unsigned char)c) + +static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID); +static NS_DEFINE_CID(kCPreContentIteratorCID, NS_PRECONTENTITERATOR_CID); + +#define CH_QUOTE ((char16_t)0x22) +#define CH_APOSTROPHE ((char16_t)0x27) +#define CH_LEFT_SINGLE_QUOTE ((char16_t)0x2018) +#define CH_RIGHT_SINGLE_QUOTE ((char16_t)0x2019) +#define CH_LEFT_DOUBLE_QUOTE ((char16_t)0x201C) +#define CH_RIGHT_DOUBLE_QUOTE ((char16_t)0x201D) + +#define CH_SHY ((char16_t)0xAD) + +// nsFind::Find casts CH_SHY to char before calling StripChars +// This works correctly if and only if CH_SHY <= 255 +static_assert(CH_SHY <= 255, "CH_SHY is not an ascii character"); + +// nsFindContentIterator is a special iterator that also goes through any +// existing