Skip to content

Commit

Permalink
Backed out changeset 572662b36c77 (bug 1302470)
Browse files Browse the repository at this point in the history
  • Loading branch information
Archaeopteryx committed Apr 21, 2017
1 parent 3e0e5a5 commit 0565ac8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 88 deletions.
5 changes: 1 addition & 4 deletions toolkit/components/typeaheadfind/nsITypeAheadFind.idl
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,9 @@ interface nsITypeAheadFind : nsISupports
* necessarily happen automatically. */
void collapseSelection();

/* Check if a range is visible using heuristics */
/* Check if a range is visible */
boolean isRangeVisible(in nsIDOMRange aRange, in boolean aMustBeInViewPort);

/* Check if a range is actually rendered (out of viewport always false) */
boolean isRangeRendered(in nsIDOMRange aRange);

/******************************* Attributes ******************************/

readonly attribute AString searchString;
Expand Down
80 changes: 0 additions & 80 deletions toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1308,86 +1308,6 @@ nsTypeAheadFind::IsRangeVisible(nsIPresShell *aPresShell,
return false;
}

NS_IMETHODIMP
nsTypeAheadFind::IsRangeRendered(nsIDOMRange *aRange,
bool *aResult)
{
// Jump through hoops to extract the docShell from the range.
nsCOMPtr<nsIDOMNode> node;
aRange->GetStartContainer(getter_AddRefs(node));
nsCOMPtr<nsIDOMDocument> document;
node->GetOwnerDocument(getter_AddRefs(document));
nsCOMPtr<mozIDOMWindowProxy> window;
document->GetDefaultView(getter_AddRefs(window));
nsCOMPtr<nsIWebNavigation> navNav (do_GetInterface(window));
nsCOMPtr<nsIDocShell> docShell (do_GetInterface(navNav));

// Set up the arguments needed to check if a range is visible.
nsCOMPtr<nsIPresShell> presShell (docShell->GetPresShell());
RefPtr<nsPresContext> presContext = presShell->GetPresContext();
*aResult = IsRangeRendered(presShell, presContext, aRange);
return NS_OK;
}

bool
nsTypeAheadFind::IsRangeRendered(nsIPresShell *aPresShell,
nsPresContext *aPresContext,
nsIDOMRange *aRange)
{
NS_ASSERTION(aPresShell && aPresContext && aRange,
"params are invalid");

nsCOMPtr<nsIDOMNode> node;
aRange->GetCommonAncestorContainer(getter_AddRefs(node));

nsCOMPtr<nsIContent> content(do_QueryInterface(node));
if (!content) {
return false;
}

nsIFrame *frame = content->GetPrimaryFrame();
if (!frame) {
return false; // No frame! Not visible then.
}

if (!frame->StyleVisibility()->IsVisible()) {
return false;
}

// Having a primary frame doesn't mean that the range is visible inside the
// viewport. Do a hit-test to determine that quickly and properly.
AutoTArray<nsIFrame*,8> frames;
nsIFrame *rootFrame = aPresShell->GetRootFrame();
RefPtr<nsRange> range = static_cast<nsRange*>(aRange);
RefPtr<mozilla::dom::DOMRectList> rects = range->GetClientRects(true, false);
for (uint32_t i = 0; i < rects->Length(); ++i) {
RefPtr<mozilla::dom::DOMRect> rect = rects->Item(i);
nsRect r(nsPresContext::CSSPixelsToAppUnits((float)rect->X()),
nsPresContext::CSSPixelsToAppUnits((float)rect->Y()),
nsPresContext::CSSPixelsToAppUnits((float)rect->Width()),
nsPresContext::CSSPixelsToAppUnits((float)rect->Height()));
// Append visible frames to frames array.
nsLayoutUtils::GetFramesForArea(rootFrame, r, frames,
nsLayoutUtils::IGNORE_PAINT_SUPPRESSION |
nsLayoutUtils::IGNORE_ROOT_SCROLL_FRAME |
nsLayoutUtils::ONLY_VISIBLE);

// See if any of the frames contain the content. If they do, then the range
// is visible. We search for the content rather than the original frame,
// because nsTextContinuation frames might be returned instead of the
// original frame.
for (const auto &f: frames) {
if (f->GetContent() == content) {
return true;
}
}

frames.ClearAndRetainStorage();
}

return false;
}

already_AddRefed<nsIPresShell>
nsTypeAheadFind::GetPresShell()
{
Expand Down
6 changes: 2 additions & 4 deletions toolkit/components/typeaheadfind/nsTypeAheadFind.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,17 @@ class nsTypeAheadFind : public nsITypeAheadFind,
nsresult GetWebBrowserFind(nsIDocShell *aDocShell,
nsIWebBrowserFind **aWebBrowserFind);

void RangeStartsInsideLink(nsIDOMRange *aRange, nsIPresShell *aPresShell,
void RangeStartsInsideLink(nsIDOMRange *aRange, nsIPresShell *aPresShell,
bool *aIsInsideLink, bool *aIsStartingLink);

void GetSelection(nsIPresShell *aPresShell, nsISelectionController **aSelCon,
void GetSelection(nsIPresShell *aPresShell, nsISelectionController **aSelCon,
nsISelection **aDomSel);
// *aNewRange may not be collapsed. If you want to collapse it in a
// particular way, you need to do it yourself.
bool IsRangeVisible(nsIPresShell *aPresShell, nsPresContext *aPresContext,
nsIDOMRange *aRange, bool aMustBeVisible,
bool aGetTopVisibleLeaf, nsIDOMRange **aNewRange,
bool *aUsesIndependentSelection);
bool IsRangeRendered(nsIPresShell *aPresShell, nsPresContext *aPresContext,
nsIDOMRange *aRange);
nsresult FindItNow(nsIPresShell *aPresShell, bool aIsLinksOnly,
bool aIsFirstVisiblePreferred, bool aFindPrev,
uint16_t* aResult);
Expand Down

0 comments on commit 0565ac8

Please sign in to comment.