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 #include "nsILineIterator.h"
12 void LineFrameFinder::Scan(nsIFrame
* aFrame
) {
21 const LogicalRect rect
= aFrame
->GetLogicalRect(mWM
, mContainerSize
);
22 if (rect
.ISize(mWM
) == 0) {
25 // If pos.I() is inside this frame - this is it
26 if (rect
.IStart(mWM
) <= mPos
.I(mWM
) && rect
.IEnd(mWM
) > mPos
.I(mWM
)) {
27 mClosestFromStart
= mClosestFromEnd
= aFrame
;
31 if (rect
.IStart(mWM
) < mPos
.I(mWM
)) {
32 if (!mClosestFromStart
||
34 mClosestFromStart
->GetLogicalRect(mWM
, mContainerSize
).IEnd(mWM
)) {
35 mClosestFromStart
= aFrame
;
38 if (!mClosestFromEnd
||
40 mClosestFromEnd
->GetLogicalRect(mWM
, mContainerSize
).IStart(mWM
)) {
41 mClosestFromEnd
= aFrame
;
46 void LineFrameFinder::Finish(nsIFrame
** aFrameFound
,
47 bool* aPosIsBeforeFirstFrame
,
48 bool* aPosIsAfterLastFrame
) {
49 if (!mClosestFromStart
&& !mClosestFromEnd
) {
50 // All frames were zero-width. Just take the first one.
51 mClosestFromStart
= mClosestFromEnd
= mFirstFrame
;
53 *aPosIsBeforeFirstFrame
= mIsReversed
? !mClosestFromEnd
: !mClosestFromStart
;
54 *aPosIsAfterLastFrame
= mIsReversed
? !mClosestFromStart
: !mClosestFromEnd
;
55 if (mClosestFromStart
== mClosestFromEnd
) {
56 *aFrameFound
= mClosestFromStart
;
57 } else if (!mClosestFromStart
) {
58 *aFrameFound
= mClosestFromEnd
;
59 } else if (!mClosestFromEnd
) {
60 *aFrameFound
= mClosestFromStart
;
61 } else { // we're between two frames
63 mClosestFromEnd
->GetLogicalRect(mWM
, mContainerSize
).IStart(mWM
) -
64 mClosestFromStart
->GetLogicalRect(mWM
, mContainerSize
).IEnd(mWM
);
66 mClosestFromStart
->GetLogicalRect(mWM
, mContainerSize
).IEnd(mWM
) +
68 *aFrameFound
= mClosestFromStart
;
70 *aFrameFound
= mClosestFromEnd
;
75 } // namespace mozilla