mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-03 01:38:46 +02:00
This patch fixes multiple points which may cross independent selection boundaries which is element boundary of the native anonymous `<div>` for editable content in text controls. The reason why I don't split this patch is, fixing one of them leads another assertion failure. So, I couldn't pass all tests with separated patches. 1. `nsFrameTraversal` should take `Element` instead of `nsIFrame` for the limiter because e.g., inline editing host like `<span contenteditable>` may have multiple frames if it's wrapped. Therefore, we should make it take an element as the ancestor limiter, and check it when getting parent frame or after getting previous or next frame. 2. `nsIFrame::PeekBackwardAndForward` may cross the boundary because it does not take the anonymous `<div>` element as ancestor limiter of the selection. It's currently used only for extending selection. Therefore, I rename it to make it clearer. 3. `SelectionMovementUtils::GetPrevNextBidiLevel` to take the ancestor limiter for calling `nsIFrame::GetFrameFromDirection()`. 4. `nsINode` should have a method to return the `nsFrameSelection` instance which manages the selection in the node. This makes the check simpler, and this is not expensive. Then, for making it clearer, I rename `TextControlElement::GetConstFrameSelection()` to `GetIndependentFrameSelection()`. 5. `nsINode::GetSelectionRootContent()` should have an option to return independent selection root when the node is its host for `nsFrameSelection::ConstrainFrameAndPointToAnchorSubtree()` 6. `nsFrameSelection::ConstrainFrameAndPointToAnchorSubtree()` should not retrieve independent selection root when the given frame is a text control frame. 7. `RangeUtils` should get parent with checking the independent selection boundaries. 8. `Selection::Extend` should assert if the destination is managed by its frame selection to detect a bug. Differential Revision: https://phabricator.services.mozilla.com/D241587
132 lines
3.8 KiB
C++
132 lines
3.8 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 NSFRAMETRAVERSAL_H
|
|
#define NSFRAMETRAVERSAL_H
|
|
|
|
#include <cstdint>
|
|
#include "mozilla/Attributes.h"
|
|
|
|
class nsIFrame;
|
|
class nsPresContext;
|
|
|
|
namespace mozilla::dom {
|
|
class Element;
|
|
} // namespace mozilla::dom
|
|
|
|
class MOZ_STACK_CLASS nsFrameIterator final {
|
|
public:
|
|
using Element = mozilla::dom::Element;
|
|
|
|
void First();
|
|
void Next();
|
|
nsIFrame* CurrentItem();
|
|
bool IsDone();
|
|
|
|
void Last();
|
|
void Prev();
|
|
|
|
inline nsIFrame* Traverse(bool aForward) {
|
|
if (aForward) {
|
|
Next();
|
|
} else {
|
|
Prev();
|
|
}
|
|
return CurrentItem();
|
|
};
|
|
|
|
enum class Type : uint8_t {
|
|
// only leaf nodes
|
|
Leaf,
|
|
// "open tag" order
|
|
PreOrder,
|
|
// "close tag" order
|
|
PostOrder,
|
|
};
|
|
nsFrameIterator(nsPresContext* aPresContext, nsIFrame* aStart, Type aType,
|
|
bool aVisual, bool aLockInScrollView, bool aFollowOOFs,
|
|
bool aSkipPopupChecks, const Element* aLimiter = nullptr);
|
|
~nsFrameIterator() = default;
|
|
|
|
protected:
|
|
void SetCurrent(nsIFrame* aFrame) { mCurrent = aFrame; }
|
|
nsIFrame* GetCurrent() { return mCurrent; }
|
|
nsIFrame* GetStart() { return mStart; }
|
|
nsIFrame* GetLast() { return mLast; }
|
|
void SetLast(nsIFrame* aFrame) { mLast = aFrame; }
|
|
int8_t GetOffEdge() { return mOffEdge; }
|
|
void SetOffEdge(int8_t aOffEdge) { mOffEdge = aOffEdge; }
|
|
|
|
/*
|
|
Our own versions of the standard frame tree navigation
|
|
methods, which, if the iterator is following out-of-flows,
|
|
apply the following rules for placeholder frames:
|
|
|
|
- If a frame HAS a placeholder frame, getting its parent
|
|
gets the placeholder's parent.
|
|
|
|
- If a frame's first child or next/prev sibling IS a
|
|
placeholder frame, then we instead return the real frame.
|
|
|
|
- If a frame HAS a placeholder frame, getting its next/prev
|
|
sibling gets the placeholder frame's next/prev sibling.
|
|
|
|
These are all applied recursively to support multiple levels of
|
|
placeholders.
|
|
*/
|
|
|
|
nsIFrame* GetParentFrameInLimiter(nsIFrame* aFrame) {
|
|
return GetParentFrame(aFrame, mLimiter);
|
|
}
|
|
nsIFrame* GetParentFrame(nsIFrame* aFrame, const Element* aAncestorLimiter);
|
|
|
|
// like GetParentFrame but returns null once a popup frame is reached
|
|
nsIFrame* GetParentFrameNotPopup(nsIFrame* aFrame);
|
|
|
|
nsIFrame* GetFirstChild(nsIFrame* aFrame);
|
|
nsIFrame* GetLastChild(nsIFrame* aFrame);
|
|
|
|
nsIFrame* GetNextSibling(nsIFrame* aFrame);
|
|
nsIFrame* GetPrevSibling(nsIFrame* aFrame);
|
|
|
|
/*
|
|
These methods are overridden by the bidi visual iterator to have the
|
|
semantics of "get first child in visual order", "get last child in visual
|
|
order", "get next sibling in visual order" and "get previous sibling in
|
|
visual order".
|
|
*/
|
|
|
|
nsIFrame* GetFirstChildInner(nsIFrame* aFrame);
|
|
nsIFrame* GetLastChildInner(nsIFrame* aFrame);
|
|
|
|
nsIFrame* GetNextSiblingInner(nsIFrame* aFrame);
|
|
nsIFrame* GetPrevSiblingInner(nsIFrame* aFrame);
|
|
|
|
/**
|
|
* Return the placeholder frame for aFrame if it has one, otherwise return
|
|
* aFrame itself.
|
|
*/
|
|
nsIFrame* GetPlaceholderFrame(nsIFrame* aFrame);
|
|
bool IsPopupFrame(nsIFrame* aFrame);
|
|
|
|
bool IsInvokerOpenPopoverFrame(nsIFrame* aFrame);
|
|
|
|
nsPresContext* const mPresContext;
|
|
const bool mLockScroll;
|
|
const bool mFollowOOFs;
|
|
const bool mSkipPopupChecks;
|
|
const bool mVisual;
|
|
const Type mType;
|
|
|
|
private:
|
|
nsIFrame* const mStart;
|
|
nsIFrame* mCurrent;
|
|
nsIFrame* mLast; // the last one that was in current;
|
|
const Element* const mLimiter;
|
|
int8_t mOffEdge; // 0= no -1 to far prev, 1 to far next;
|
|
};
|
|
|
|
#endif // NSFRAMETRAVERSAL_H
|