Files
tubestation/toolkit/components/find/nsWebBrowserFind.h
Jan-Niklas Jaeschke 369be69fa0 Bug 1945862 - Make nsFind respect the end point correctly. r=emilio
This patch refactors the find functionality in a few ways:
- A C++-only method `FindFromRangeBoundaries()` is introduced,
  which uses `RangeBoundary`s instead of collapsed `nsRange`s
  to describe the search range.
- Use `nsContentUtils::ComparePoints()` to check whether the
  end of the search range has been reached. This is more robust
  than the previous check and finds the end point also when it's
  in a node which is being skipped (eg. a non-text-node).
- Clarify the interface: The search start and end points are now
  always in document read order, and independent of
  the search direction.
  Therefore, the start point must always be before the end
  (this is asserted). All usages of the find code are updated
  accordingly.
- Some bugs in the tests, which have surfaced because of
  the broken end point implementation have been fixed.

Differential Revision: https://phabricator.services.mozilla.com/D237497
2025-02-15 16:02:34 +00:00

96 lines
2.7 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 nsWebBrowserFindImpl_h__
#define nsWebBrowserFindImpl_h__
#include "nsIWebBrowserFind.h"
#include "nsCOMPtr.h"
#include "nsIWeakReferenceUtils.h"
#include "nsPIDOMWindow.h"
#include "nsString.h"
class nsIDOMWindow;
class nsIDocShell;
class nsRange;
namespace mozilla {
namespace dom {
class Document;
class Element;
class Selection;
} // namespace dom
} // namespace mozilla
//*****************************************************************************
// class nsWebBrowserFind
//*****************************************************************************
class nsWebBrowserFind : public nsIWebBrowserFind,
public nsIWebBrowserFindInFrames {
public:
nsWebBrowserFind();
// nsISupports
NS_DECL_ISUPPORTS
// nsIWebBrowserFind
NS_DECL_NSIWEBBROWSERFIND
// nsIWebBrowserFindInFrames
NS_DECL_NSIWEBBROWSERFINDINFRAMES
protected:
virtual ~nsWebBrowserFind();
bool CanFindNext() { return mSearchString.Length() != 0; }
MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult
SearchInFrame(nsPIDOMWindowOuter* aWindow, bool aWrapping, bool* aDidFind);
nsresult OnStartSearchFrame(nsPIDOMWindowOuter* aWindow);
nsresult OnEndSearchFrame(nsPIDOMWindowOuter* aWindow);
already_AddRefed<mozilla::dom::Selection> GetFrameSelection(
nsPIDOMWindowOuter* aWindow);
MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult
ClearFrameSelection(nsPIDOMWindowOuter* aWindow);
MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult OnFind(nsPIDOMWindowOuter* aFoundWindow);
MOZ_CAN_RUN_SCRIPT_BOUNDARY void SetSelectionAndScroll(
nsPIDOMWindowOuter* aWindow, nsRange* aRange);
nsresult GetSearchLimits(nsRange* aSearchRange, nsRange* aStartPt,
nsRange* aEndPt, mozilla::dom::Document* aDoc,
mozilla::dom::Selection* aSel, bool aWrap);
nsresult SetRangeAroundDocument(nsRange* aSearchRange, nsRange* aStartPt,
nsRange* aEndPt,
mozilla::dom::Document* aDoc);
protected:
nsString mSearchString;
bool mFindBackwards;
bool mWrapFind;
bool mEntireWord;
bool mMatchCase;
bool mMatchDiacritics;
bool mSearchSubFrames;
bool mSearchParentFrames;
// These are all weak because who knows if windows can go away during our
// lifetime.
nsWeakPtr mCurrentSearchFrame;
nsWeakPtr mRootSearchFrame;
nsWeakPtr mLastFocusedWindow;
};
#endif