1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_ContentEventHandler_h_
8 #define mozilla_ContentEventHandler_h_
11 #include "mozilla/Assertions.h"
12 #include "mozilla/EventForwards.h"
13 #include "mozilla/RangeBoundary.h"
14 #include "mozilla/dom/Selection.h"
15 #include "mozilla/dom/Text.h"
31 enum LineBreakType
{ LINE_BREAK_TYPE_NATIVE
, LINE_BREAK_TYPE_XP
};
34 * Query Content Event Handler
35 * ContentEventHandler is a helper class for EventStateManager.
36 * The platforms request some content informations, e.g., the selected text,
37 * the offset of the selected text and the text for specified range.
38 * This class answers to NS_QUERY_* events from actual contents.
41 class MOZ_STACK_CLASS ContentEventHandler
{
44 * SimpleRangeBase is a helper template class of ContentEventHandler class
45 * that stores 2 DOM points as a range without observing the mutation. I.e.,
46 * similar to dom::StaticRange, but can only be on the stack and does not have
47 * unnecessary features for ContentEventHandler so it is fast.
48 * Therefore, initializers are responsible for making sure the start/end nodes
49 * are in document order. This is enforced by assertions in DEBUG builds.
51 template <typename NodeType
, typename RangeBoundaryType
>
52 class MOZ_STACK_CLASS SimpleRangeBase final
{
55 SimpleRangeBase(SimpleRangeBase
<NodeType
, RangeBoundaryType
>&&) noexcept
;
56 template <typename OtherNodeType
, typename OtherRangeBoundaryType
>
57 explicit SimpleRangeBase(
58 const SimpleRangeBase
<OtherNodeType
, OtherRangeBoundaryType
>& aOther
);
59 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
69 bool IsPositioned() const { return mStart
.IsSet() && mEnd
.IsSet(); }
70 bool Collapsed() const { return mStart
== mEnd
&& IsPositioned(); }
71 nsINode
* GetStartContainer() const { return mStart
.Container(); }
72 nsINode
* GetEndContainer() const { return mEnd
.Container(); }
73 uint32_t StartOffset() const {
74 return *mStart
.Offset(
75 RangeBoundaryType::OffsetFilter::kValidOrInvalidOffsets
);
77 uint32_t EndOffset() const {
79 RangeBoundaryType::OffsetFilter::kValidOrInvalidOffsets
);
81 nsIContent
* StartRef() const { return mStart
.Ref(); }
82 nsIContent
* EndRef() const { return mEnd
.Ref(); }
84 const RangeBoundaryType
& Start() const { return mStart
; }
85 const RangeBoundaryType
& End() const { return mEnd
; }
87 nsINode
* GetRoot() const { return mRoot
; }
89 // XXX: Make these use RangeBoundaries...
90 nsresult
CollapseTo(const RawRangeBoundary
& aBoundary
) {
91 return SetStartAndEnd(aBoundary
, aBoundary
);
93 nsresult
SetStart(const RawRangeBoundary
& aStart
);
94 nsresult
SetEnd(const RawRangeBoundary
& aEnd
);
96 // NOTE: These helpers can hide performance problems, as they perform a
97 // search to find aStartOffset in aStartContainer.
98 nsresult
SetStart(nsINode
* aStartContainer
, uint32_t aStartOffset
) {
99 return SetStart(RawRangeBoundary(aStartContainer
, aStartOffset
));
101 nsresult
SetEnd(nsINode
* aEndContainer
, uint32_t aEndOffset
) {
102 return SetEnd(RawRangeBoundary(aEndContainer
, aEndOffset
));
105 nsresult
SetEndAfter(nsINode
* aEndContainer
);
106 void SetStartAndEnd(const nsRange
* aRange
);
107 nsresult
SetStartAndEnd(const RawRangeBoundary
& aStart
,
108 const RawRangeBoundary
& aEnd
);
110 nsresult
SelectNodeContents(const nsINode
* aNodeToSelectContents
);
113 inline void AssertStartIsBeforeOrEqualToEnd();
117 RangeBoundaryType mStart
;
118 RangeBoundaryType mEnd
;
120 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
121 nsMutationGuard mMutationGuard
;
122 Maybe
<JS::AutoAssertNoGC
> mAssertNoGC
;
126 using SimpleRange
= SimpleRangeBase
<RefPtr
<nsINode
>, RangeBoundary
>;
127 using UnsafeSimpleRange
= SimpleRangeBase
<nsINode
*, RawRangeBoundary
>;
130 using Element
= dom::Element
;
131 using Selection
= dom::Selection
;
133 explicit ContentEventHandler(nsPresContext
* aPresContext
);
135 // Handle aEvent in the current process.
136 MOZ_CAN_RUN_SCRIPT nsresult
137 HandleQueryContentEvent(WidgetQueryContentEvent
* aEvent
);
139 // eQuerySelectedText event handler
140 MOZ_CAN_RUN_SCRIPT nsresult
141 OnQuerySelectedText(WidgetQueryContentEvent
* aEvent
);
142 // eQueryTextContent event handler
143 MOZ_CAN_RUN_SCRIPT nsresult
144 OnQueryTextContent(WidgetQueryContentEvent
* aEvent
);
145 // eQueryCaretRect event handler
146 MOZ_CAN_RUN_SCRIPT nsresult
OnQueryCaretRect(WidgetQueryContentEvent
* aEvent
);
147 // eQueryTextRect event handler
148 MOZ_CAN_RUN_SCRIPT nsresult
OnQueryTextRect(WidgetQueryContentEvent
* aEvent
);
149 // eQueryTextRectArray event handler
150 MOZ_CAN_RUN_SCRIPT nsresult
151 OnQueryTextRectArray(WidgetQueryContentEvent
* aEvent
);
152 // eQueryEditorRect event handler
153 MOZ_CAN_RUN_SCRIPT nsresult
154 OnQueryEditorRect(WidgetQueryContentEvent
* aEvent
);
155 // eQueryContentState event handler
156 MOZ_CAN_RUN_SCRIPT nsresult
157 OnQueryContentState(WidgetQueryContentEvent
* aEvent
);
158 // eQuerySelectionAsTransferable event handler
159 MOZ_CAN_RUN_SCRIPT nsresult
160 OnQuerySelectionAsTransferable(WidgetQueryContentEvent
* aEvent
);
161 // eQueryCharacterAtPoint event handler
162 MOZ_CAN_RUN_SCRIPT nsresult
163 OnQueryCharacterAtPoint(WidgetQueryContentEvent
* aEvent
);
164 // eQueryDOMWidgetHittest event handler
165 MOZ_CAN_RUN_SCRIPT nsresult
166 OnQueryDOMWidgetHittest(WidgetQueryContentEvent
* aEvent
);
168 // NS_SELECTION_* event
169 MOZ_CAN_RUN_SCRIPT nsresult
OnSelectionEvent(WidgetSelectionEvent
* aEvent
);
172 RefPtr
<dom::Document
> mDocument
;
173 // mSelection is typically normal selection but if OnQuerySelectedText()
174 // is called, i.e., handling eQuerySelectedText, it's the specified selection
175 // by WidgetQueryContentEvent::mInput::mSelectionType.
176 RefPtr
<Selection
> mSelection
;
177 // mFirstSelectedSimpleRange is initialized from the first range of
178 // mSelection, if it exists. Otherwise, it is reset by Clear().
179 SimpleRange mFirstSelectedSimpleRange
;
180 RefPtr
<Element
> mRootElement
;
182 MOZ_CAN_RUN_SCRIPT nsresult
Init(WidgetQueryContentEvent
* aEvent
);
183 MOZ_CAN_RUN_SCRIPT nsresult
Init(WidgetSelectionEvent
* aEvent
);
185 nsresult
InitBasic(bool aRequireFlush
= true);
186 MOZ_CAN_RUN_SCRIPT nsresult
187 InitCommon(EventMessage aEventMessage
,
188 SelectionType aSelectionType
= SelectionType::eNormal
,
189 bool aRequireFlush
= true);
191 * InitRootContent() computes the root content of current focused editor.
193 * @param aNormalSelection This must be a Selection instance whose type is
194 * SelectionType::eNormal.
196 MOZ_CAN_RUN_SCRIPT nsresult
197 InitRootContent(const Selection
& aNormalSelection
);
200 // FlatText means the text that is generated from DOM tree. The BR elements
201 // are replaced to native linefeeds. Other elements are ignored.
203 // RawNodePosition stores a pair of node and offset in the node.
204 // When mNode is an element and mOffset is 0, the start position means after
205 // the open tag of mNode.
206 // This is useful to receive one or more sets of them instead of nsRange.
207 // This type is intended to be used for short-lived operations, and is thus
208 // marked MOZ_STACK_CLASS.
209 struct MOZ_STACK_CLASS RawNodePosition
: public RawRangeBoundary
{
210 // Only when mNode is an element node and mOffset is 0, mAfterOpenTag is
212 bool mAfterOpenTag
= true;
214 RawNodePosition() = default;
215 explicit RawNodePosition(const RawNodePosition
& aOther
)
216 : RawRangeBoundary(aOther
),
217 mAfterOpenTag(aOther
.mAfterOpenTag
)
218 // Don't use the copy constructor of mAssertNoGC.
221 RawNodePosition(nsINode
* aContainer
, uint32_t aOffset
)
222 : RawRangeBoundary(aContainer
, aOffset
) {}
224 RawNodePosition(nsINode
* aContainer
, nsIContent
* aRef
)
225 : RawRangeBoundary(aContainer
, aRef
) {}
227 explicit RawNodePosition(const nsIFrame::ContentOffsets
& aContentOffsets
)
228 : RawRangeBoundary(aContentOffsets
.content
, aContentOffsets
.offset
) {}
230 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
231 ~RawNodePosition() { MOZ_DIAGNOSTIC_ASSERT(!mMutationGuard
.Mutated(0)); }
232 #endif // #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
235 const RawNodePosition
& operator=(const RawNodePosition
& aOther
) {
236 if (this != &aOther
) {
237 RawRangeBoundary::operator=(aOther
);
238 mAfterOpenTag
= aOther
.mAfterOpenTag
;
243 bool operator==(const RawNodePosition
& aOther
) const {
244 return RawRangeBoundary::operator==(aOther
) &&
245 mAfterOpenTag
== aOther
.mAfterOpenTag
;
248 bool IsBeforeOpenTag() const {
249 return IsSet() && Container()->IsElement() && !Ref() && !mAfterOpenTag
;
251 bool IsImmediatelyAfterOpenTag() const {
252 return IsSet() && Container()->IsElement() && !Ref() && mAfterOpenTag
;
255 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
257 nsMutationGuard mMutationGuard
;
258 JS::AutoAssertNoGC mAssertNoGC
;
259 #endif // #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
262 // RawNodePositionBefore isn't good name if Container() isn't an element node
263 // nor Offset() is not 0, though, when Container() is an element node and
264 // mOffset is 0, this is treated as before the open tag of Container().
265 struct MOZ_STACK_CLASS RawNodePositionBefore final
: public RawNodePosition
{
266 RawNodePositionBefore(nsINode
* aContainer
, uint32_t aOffset
)
267 : RawNodePosition(aContainer
, aOffset
) {
268 mAfterOpenTag
= false;
271 RawNodePositionBefore(nsINode
* aContainer
, nsIContent
* aRef
)
272 : RawNodePosition(aContainer
, aRef
) {
273 mAfterOpenTag
= false;
277 // Get the flatten text length in the range.
278 // @param aStartPosition Start node and offset in the node of the range.
279 // @param aEndPosition End node and offset in the node of the range.
280 // @param aRootElement The root element of the editor or document.
281 // aRootElement won't cause any text including
283 // @param aLength The result of the flatten text length of the
285 // @param aLineBreakType Whether this computes flatten text length with
286 // native line breakers on the platform or
287 // with XP line breaker (\n).
288 // @param aIsRemovingNode Should be true only when this is called from
289 // nsIMutationObserver::ContentRemoved().
290 // When this is true, aStartPosition.mNode should
291 // be the root node of removing nodes and mOffset
292 // should be 0 and aEndPosition.mNode should be
293 // same as aStartPosition.mNode and mOffset should
294 // be number of the children of mNode.
295 static nsresult
GetFlatTextLengthInRange(
296 const RawNodePosition
& aStartPosition
,
297 const RawNodePosition
& aEndPosition
, const Element
* aRootElement
,
298 uint32_t* aLength
, LineBreakType aLineBreakType
,
299 bool aIsRemovingNode
= false);
300 // Computes the native text length between aStartOffset and aEndOffset of
302 static uint32_t GetNativeTextLength(const dom::Text
& aTextNode
,
303 uint32_t aStartOffset
,
304 uint32_t aEndOffset
);
305 // Get the native text length of aTextNode.
306 static uint32_t GetNativeTextLength(const dom::Text
& aTextNode
,
307 uint32_t aMaxLength
= UINT32_MAX
);
309 static uint32_t GetNativeTextLength(const nsAString
& aText
);
312 // Get the text length of aTextNode.
313 static uint32_t GetTextLength(const dom::Text
& aTextNode
,
314 LineBreakType aLineBreakType
,
315 uint32_t aMaxLength
= UINT32_MAX
);
316 // Get the text length of a given range of a content node in
317 // the given line break type.
318 static uint32_t GetTextLengthInRange(const dom::Text
& aTextNode
,
319 uint32_t aXPStartOffset
,
320 uint32_t aXPEndOffset
,
321 LineBreakType aLineBreakType
);
322 // Get the contents in aElement (meaning all children of aElement) as plain
323 // text. E.g., specifying mRootElement gets whole text in it.
324 // Note that the result is not same as .textContent. The result is
325 // optimized for native IMEs. For example, <br> element and some block
326 // elements causes "\n" (or "\r\n"), see also ShouldBreakLineBefore().
327 nsresult
GenerateFlatTextContent(const Element
* aElement
, nsString
& aString
,
328 LineBreakType aLineBreakType
);
329 // Get the contents of aRange as plain text.
330 template <typename NodeType
, typename RangeBoundaryType
>
331 nsresult
GenerateFlatTextContent(
332 const SimpleRangeBase
<NodeType
, RangeBoundaryType
>& aSimpleRange
,
333 nsString
& aString
, LineBreakType aLineBreakType
);
334 // Get offset of start of aRange. Note that the result includes the length
335 // of line breaker caused by the start of aContent because aRange never
336 // includes the line breaker caused by its start node.
337 template <typename SimpleRangeType
>
338 nsresult
GetStartOffset(const SimpleRangeType
& aSimpleRange
,
339 uint32_t* aOffset
, LineBreakType aLineBreakType
);
340 // Check if we should insert a line break before aContent.
341 // This should return false only when aContent is an html element which
342 // is typically used in a paragraph like <em>.
343 static bool ShouldBreakLineBefore(const nsIContent
& aContent
,
344 const Element
* aRootElement
);
345 // Get the line breaker length.
346 static inline uint32_t GetBRLength(LineBreakType aLineBreakType
);
347 static LineBreakType
GetLineBreakType(WidgetQueryContentEvent
* aEvent
);
348 static LineBreakType
GetLineBreakType(WidgetSelectionEvent
* aEvent
);
349 static LineBreakType
GetLineBreakType(bool aUseNativeLineBreak
);
350 // Returns focused content (including its descendant documents).
351 nsIContent
* GetFocusedContent();
352 // QueryContentRect() sets the rect of aContent's frame(s) to aEvent.
353 nsresult
QueryContentRect(nsIContent
* aContent
,
354 WidgetQueryContentEvent
* aEvent
);
356 template <typename RangeType
, typename TextNodeType
>
357 struct MOZ_STACK_CLASS DOMRangeAndAdjustedOffsetInFlattenedTextBase
{
358 bool RangeStartsFromLastTextNode() const {
359 return mLastTextNode
&& mRange
.GetStartContainer() == mLastTextNode
;
361 bool RangeStartsFromEndOfContainer() const {
362 return mRange
.GetStartContainer() &&
363 mRange
.GetStartContainer()->Length() == mRange
.StartOffset();
365 bool RangeStartsFromContent() const {
366 return mRange
.GetStartContainer() &&
367 mRange
.GetStartContainer()->IsContent();
370 // The range in the DOM tree.
372 // Actual start offset of the range in the flattened text. If aOffset
373 // of ConvertFlatTextOffsetToDOMRange() is middle of a surrogate pair,
374 // a CRLF or a complex character of some languages, this may be set to
376 uint32_t mAdjustedOffset
= 0;
377 // The last text node which is found while walking the tree.
378 // If the range ends in a text node, this is the text node. Otherwise,
379 // the last found text node before the end container of mRange.
380 TextNodeType mLastTextNode
= nullptr;
382 using DOMRangeAndAdjustedOffsetInFlattenedText
=
383 DOMRangeAndAdjustedOffsetInFlattenedTextBase
<SimpleRange
,
385 using UnsafeDOMRangeAndAdjustedOffsetInFlattenedText
=
386 DOMRangeAndAdjustedOffsetInFlattenedTextBase
<UnsafeSimpleRange
,
390 * Scans the DOM tree and set mRange as same as from aOffset to aOffset +
391 * aLength in the flattened text.
392 * NOTE: Use ConvertFlatTextOffsetToDOMRange() or
393 * ConvertFlatTextOffsetToUnsafeDOMRange() instead of
394 * ConvertFlatTextOffsetToDOMRangeBase<RangeType, TextNodeType>().
396 template <typename RangeType
, typename TextNodeType
>
397 Result
<DOMRangeAndAdjustedOffsetInFlattenedTextBase
<RangeType
, TextNodeType
>,
399 ConvertFlatTextOffsetToDOMRangeBase(uint32_t aOffset
, uint32_t aLength
,
400 LineBreakType aLineBreakType
,
401 bool aExpandToClusterBoundaries
);
402 MOZ_ALWAYS_INLINE Result
<DOMRangeAndAdjustedOffsetInFlattenedText
, nsresult
>
403 ConvertFlatTextOffsetToDOMRange(uint32_t aOffset
, uint32_t aLength
,
404 LineBreakType aLineBreakType
,
405 bool aExpandToClusterBoundaries
) {
406 return ConvertFlatTextOffsetToDOMRangeBase
<SimpleRange
, RefPtr
<dom::Text
>>(
407 aOffset
, aLength
, aLineBreakType
, aExpandToClusterBoundaries
);
410 Result
<UnsafeDOMRangeAndAdjustedOffsetInFlattenedText
, nsresult
>
411 ConvertFlatTextOffsetToUnsafeDOMRange(uint32_t aOffset
, uint32_t aLength
,
412 LineBreakType aLineBreakType
,
413 bool aExpandToClusterBoundaries
) {
414 return ConvertFlatTextOffsetToDOMRangeBase
<UnsafeSimpleRange
, dom::Text
*>(
415 aOffset
, aLength
, aLineBreakType
, aExpandToClusterBoundaries
);
418 // If the aSimpleRange isn't in text node but next to a text node,
419 // this method modifies it in the text node. Otherwise, not modified.
420 // Note that aSimpleRange must be collapsed.
421 nsresult
AdjustCollapsedRangeMaybeIntoTextNode(SimpleRange
& aSimpleRange
);
422 // Convert the frame relative offset to be relative to the root frame of the
423 // root presContext (but still measured in appUnits of aFrame's presContext).
424 nsresult
ConvertToRootRelativeOffset(nsIFrame
* aFrame
, nsRect
& aRect
);
425 // Expand aXPOffset to the nearest offset in cluster boundary. aForward is
426 // true, it is expanded to forward.
427 // FYI: Due to `nsFrameSelection::GetFrameForNodeOffset()`, this cannot
428 // take `const dom::Text&`.
429 nsresult
ExpandToClusterBoundary(dom::Text
& aTextNode
, bool aForward
,
430 uint32_t* aXPOffset
) const;
432 using FontRangeArray
= nsTArray
<mozilla::FontRange
>;
433 static void AppendFontRanges(FontRangeArray
& aFontRanges
,
434 const dom::Text
& aTextNode
, uint32_t aBaseOffset
,
435 uint32_t aXPStartOffset
, uint32_t aXPEndOffset
,
436 LineBreakType aLineBreakType
);
437 nsresult
GenerateFlatFontRanges(const UnsafeSimpleRange
& aSimpleRange
,
438 FontRangeArray
& aFontRanges
,
440 LineBreakType aLineBreakType
);
441 nsresult
QueryTextRectByRange(const SimpleRange
& aSimpleRange
,
442 LayoutDeviceIntRect
& aRect
,
443 WritingMode
& aWritingMode
);
445 struct MOZ_STACK_CLASS FrameAndNodeOffset final
{
446 // mFrame is safe since this can live in only stack class and
447 // ContentEventHandler doesn't modify layout after
448 // ContentEventHandler::Init() flushes pending layout. In other words,
449 // this struct shouldn't be used before calling
450 // ContentEventHandler::Init().
452 // offset in the node of mFrame
453 int32_t mOffsetInNode
;
455 FrameAndNodeOffset() : mFrame(nullptr), mOffsetInNode(-1) {}
457 FrameAndNodeOffset(nsIFrame
* aFrame
, int32_t aStartOffsetInNode
)
458 : mFrame(aFrame
), mOffsetInNode(aStartOffsetInNode
) {}
460 nsIFrame
* operator->() { return mFrame
; }
461 const nsIFrame
* operator->() const { return mFrame
; }
462 operator nsIFrame
*() { return mFrame
; }
463 operator const nsIFrame
*() const { return mFrame
; }
464 bool IsValid() const { return mFrame
&& mOffsetInNode
>= 0; }
466 // Get first frame after the start of the given range for computing text rect.
467 // This returns invalid FrameAndNodeOffset if there is no content which
468 // should affect to computing text rect in the range. mOffsetInNode is start
469 // offset in the frame.
470 template <typename NodeType
, typename RangeBoundaryType
>
471 FrameAndNodeOffset
GetFirstFrameInRangeForTextRect(
472 const SimpleRangeBase
<NodeType
, RangeBoundaryType
>& aSimpleRange
);
474 // Get last frame before the end of the given range for computing text rect.
475 // This returns invalid FrameAndNodeOffset if there is no content which
476 // should affect to computing text rect in the range. mOffsetInNode is end
477 // offset in the frame.
478 template <typename NodeType
, typename RangeBoundaryType
>
479 FrameAndNodeOffset
GetLastFrameInRangeForTextRect(
480 const SimpleRangeBase
<NodeType
, RangeBoundaryType
>& aSimpleRange
);
482 struct MOZ_STACK_CLASS FrameRelativeRect final
{
483 // mRect is relative to the mBaseFrame's position.
485 nsIFrame
* mBaseFrame
;
487 FrameRelativeRect() : mBaseFrame(nullptr) {}
489 explicit FrameRelativeRect(nsIFrame
* aBaseFrame
) : mBaseFrame(aBaseFrame
) {}
491 FrameRelativeRect(const nsRect
& aRect
, nsIFrame
* aBaseFrame
)
492 : mRect(aRect
), mBaseFrame(aBaseFrame
) {}
494 bool IsValid() const { return mBaseFrame
!= nullptr; }
496 // Returns an nsRect relative to aBaseFrame instead of mBaseFrame.
497 nsRect
RectRelativeTo(nsIFrame
* aBaseFrame
) const;
500 // Returns a rect for line breaker before the node of aFrame (If aFrame is
501 // a <br> frame or a block level frame, it causes a line break at its
502 // element's open tag, see also ShouldBreakLineBefore()). Note that this
503 // doesn't check if aFrame should cause line break in non-debug build.
504 FrameRelativeRect
GetLineBreakerRectBefore(nsIFrame
* aFrame
);
506 // Returns a line breaker rect after aTextNode as there is a line breaker
507 // immediately after aTextNode. This is useful when following block
508 // element causes a line break before it and it needs to compute the line
509 // breaker's rect. For example, if there is |<p>abc</p><p>def</p>|, the
510 // rect of 2nd <p>'s line breaker should be at right of "c" in the first
511 // <p>, not the start of 2nd <p>. The result is relative to the last text
512 // frame which represents the last character of aTextNode.
513 FrameRelativeRect
GuessLineBreakerRectAfter(const dom::Text
& aTextNode
);
515 // Returns a guessed first rect. I.e., it may be different from actual
516 // caret when selection is collapsed at start of aFrame. For example, this
517 // guess the caret rect only with the content box of aFrame and its font
519 // +-aFrame----------------- (border box)
521 // | +--------------------- (content box)
523 // ^ guessed caret rect
524 // However, actual caret is computed with more information like line-height,
525 // child frames of aFrame etc. But this does not emulate actual caret
526 // behavior exactly for simpler and faster code because it's difficult and
527 // we're not sure it's worthwhile to do it with complicated implementation.
528 FrameRelativeRect
GuessFirstCaretRectIn(nsIFrame
* aFrame
);
530 // Make aRect non-empty. If width and/or height is 0, these methods set them
531 // to 1. Note that it doesn't set nsRect's width nor height to one device
532 // pixel because using nsRect::ToOutsidePixels() makes actual width or height
533 // to 2 pixels because x and y may not be aligned to device pixels.
534 void EnsureNonEmptyRect(nsRect
& aRect
) const;
535 void EnsureNonEmptyRect(LayoutDeviceIntRect
& aRect
) const;
538 * Compute caret rect before or after a character rect.
540 static LayoutDeviceIntRect
GetCaretRectBefore(
541 const LayoutDeviceIntRect
& aCharRect
, const WritingMode
& aWritingMode
);
542 static LayoutDeviceIntRect
GetCaretRectAfter(
543 const LayoutDeviceIntRect
& aCharRect
, const WritingMode
& aWritingMode
);
544 static nsRect
GetCaretRectBefore(const nsRect
& aCharRect
,
545 const WritingMode
& aWritingMode
);
546 static nsRect
GetCaretRectAfter(nsPresContext
& aPresContext
,
547 const nsRect
& aCharRect
,
548 const WritingMode
& aWritingMode
);
551 } // namespace mozilla
553 #endif // mozilla_ContentEventHandler_h_